From 4d829fb6d79982c652f77b0d2e9d5ffa9bfafa05 Mon Sep 17 00:00:00 2001 From: Corey Pyle Date: Mon, 14 Oct 2024 13:56:44 -0400 Subject: [PATCH 1/6] JavaScript (v3): Replace prettier and eslint with Biome Biome is the same tool used by the SDK team. It also has a much larger vocabulary of "fixable" items. It outperforms other linters and has TS/JSX support out of the box. It's error messaging is also much more helpful. --- javascriptv3/.eslintignore | 4 - javascriptv3/.eslintrc.json | 32 -- javascriptv3/.gitignore | 3 +- javascriptv3/biome.json | 48 +++ .../actions/invoke-agent.js | 4 +- .../bedrock-agent-runtime/vite.config.js | 8 +- .../bedrock-agent/actions/create-agent.js | 4 +- .../bedrock-agent/actions/delete-agent.js | 2 +- .../bedrock-agent/actions/get-agent.js | 2 +- .../actions/list-agent-action-groups.js | 2 +- .../bedrock-agent/actions/list-agents.js | 2 +- .../example_code/bedrock-agent/hello.js | 4 +- .../example_code/bedrock-agent/lib/utils.js | 4 +- .../example_code/bedrock-runtime/hello.js | 2 +- .../models/ai21LabsJurassic2/invoke_model.js | 2 +- .../models/amazonTitanText/invoke_model.js | 2 +- .../models/anthropicClaude/invoke_claude_2.js | 2 +- .../models/anthropicClaude/invoke_claude_3.js | 4 +- .../invoke_claude_instant_1.js | 2 +- .../models/mistral/invoke_mistral_7b.js | 2 +- .../models/mistral/invoke_mixtral_8x7b.js | 2 +- .../scenarios/cli_text_playground.js | 2 +- .../tests/converse.integration.test.js | 2 +- .../tests/converse_stream.integration.test.js | 4 +- .../bedrock/actions/get-foundation-model.js | 2 +- .../bedrock/actions/list-foundation-models.js | 2 +- javascriptv3/example_code/bedrock/hello.js | 6 +- .../get-foundation-model.integration.test.js | 2 +- ...list-foundation-models.integration.test.js | 2 +- .../actions/describe-log-groups.js | 4 +- .../cloudwatch-logs/libs/lambda-helper.js | 9 +- .../large-query/cloud-watch-query.js | 3 +- .../scenarios/large-query/index.js | 4 +- .../cloudwatch-logs/vite.config.js | 2 +- .../cloudwatch/actions/list-metrics.js | 2 +- .../codebuild/actions/create-project.js | 2 +- .../codecommit/src/createBranch.js | 2 +- .../codecommit/src/createCommit.js | 2 +- .../codecommit/src/createPullRequest.js | 2 +- .../codecommit/src/createRepository.js | 2 +- .../codecommit/src/deleteBranch.js | 2 +- .../codecommit/src/deleteRepository.js | 2 +- .../src/describePullRequestEvents.js | 2 +- .../codecommit/src/getMergeOptions.js | 2 +- .../codecommit/src/getPullRequest.js | 2 +- .../codecommit/src/getRepository.js | 2 +- .../codecommit/src/listRepositories.js | 2 +- .../codecommit/src/mergeBranches.js | 2 +- .../codepipeline/MyCodePipelineFunction.js | 40 +-- .../cognito-identity-provider/hello.js | 2 +- .../command-handlers/clean-up-handler.js | 2 +- .../confirm-sign-up-handler.js | 2 +- .../create-user-pool-handler.js | 4 +- .../basic/command-handlers/sign-up-handler.js | 2 +- .../scenarios/basic/index.js | 4 +- .../frontend-client/src/App.css | 6 +- .../frontend-client/src/App.tsx | 30 +- .../frontend-client/src/authService.ts | 19 +- .../frontend-client/src/config.json | 8 +- .../frontend-client/src/confirmUserPage.tsx | 69 +++-- .../frontend-client/src/homePage.tsx | 56 ++-- .../frontend-client/src/loginPage.tsx | 46 +-- .../frontend-client/src/main.tsx | 24 +- .../frontend-client/tsconfig.json | 2 +- .../frontend-client/vite.config.ts | 6 +- .../functions/auth-challenge-create.mjs | 2 +- .../functions/auth-challenge-define.mjs | 24 +- .../functions/auth-challenge-verify.mjs | 2 +- .../functions/authentication-post.mjs | 2 +- .../functions/confirmation-post.mjs | 2 +- .../functions/custom-message-admin-create.mjs | 2 +- .../functions/migrate-user.mjs | 10 +- .../sign-up-pre-auto-confirm-verify.mjs | 4 +- .../tests/confirmation-post.unit.test.js | 2 +- .../custom-message-admin-create.unit.test.js | 3 +- .../tests/custom-message-sign-up.unit.test.js | 3 +- .../src/handlers/get-items-handler.ts | 2 +- .../src/handlers/parse-item.ts | 2 +- .../src/handlers/post-items-handler.ts | 7 +- .../src/handlers/post-items-report-handler.ts | 4 +- .../src/handlers/put-items-archive-handler.ts | 2 +- .../src/middleware/validate-db.ts | 4 +- .../src/types/handler.d.ts | 2 +- .../src/types/sendable.d.ts | 3 +- .../tests/get-items-handler.unit.test.ts | 35 +-- .../post-items-report-handler.unit.test.ts | 4 +- .../tests/validate-db.unit.test.ts | 2 +- .../src/mylamdbafunction.js | 12 +- .../src/mylamdbafunction.js | 13 +- .../cross-services/lex-bot/src/index.js | 26 +- .../cross-services/lex-bot/src/style.css | 4 +- .../src/functions/download.js | 13 +- .../photo_analyzer/src/index.js | 25 +- .../photo_analyzer/webpack.config.js | 2 +- .../submit-data-app/src/dynamoApp/add_data.js | 12 +- .../textract-react/AddRemoveAssets.js | 12 +- .../textract-react/package.json | 6 +- .../textract-react/src/AwsFactory.js | 6 +- .../textract-react/src/ExplorerCard.js | 4 +- .../textract-react/src/ExplorerTree.js | 4 +- .../textract-react/src/ExtractButtons.js | 20 +- .../textract-react/src/ImageDisplay.js | 20 +- .../textract-react/src/ImageLoader.js | 5 +- .../textract-react/src/TextractModel.js | 34 +- .../src/__test__/ExplorerTree.test.js | 2 +- .../src/__test__/TextractModel.test.js | 143 +++++---- .../textract-react/src/index.js | 1 + .../transcribe-streaming-app/public/style.css | 2 +- .../transcribe-streaming-app/src/index.js | 8 +- .../src/libs/emailClient.js | 17 +- .../src/libs/transcribeClient.js | 6 +- .../webpack.config.js | 2 +- .../wkflw-resilient-service/constants.js | 2 +- .../wkflw-resilient-service/index.js | 3 +- .../wkflw-resilient-service/shared.js | 3 +- .../wkflw-resilient-service/steps-deploy.js | 9 +- .../wkflw-resilient-service/steps-destroy.js | 145 ++++----- .../wkflw-topics-queues/TopicsQueuesWkflw.js | 6 +- .../wkflw-topics-queues/index.js | 2 +- .../dynamodb/actions/batch-get-item.js | 4 +- .../dynamodb/actions/batch-write-item.js | 2 +- .../dynamodb/actions/create-table.js | 2 +- .../dynamodb/actions/delete-item.js | 2 +- .../dynamodb/actions/delete-table.js | 2 +- .../dynamodb/actions/describe-table.js | 2 +- .../actions/document-client/batch-get.js | 4 +- .../actions/document-client/batch-write.js | 6 +- .../actions/document-client/delete.js | 2 +- .../dynamodb/actions/document-client/get.js | 2 +- .../dynamodb/actions/document-client/put.js | 2 +- .../dynamodb/actions/document-client/query.js | 2 +- .../dynamodb/actions/document-client/scan.js | 2 +- .../actions/document-client/update.js | 2 +- .../example_code/dynamodb/actions/get-item.js | 2 +- .../dynamodb/actions/list-tables.js | 2 +- .../actions/partiql/partiql-batch-delete.js | 2 +- .../actions/partiql/partiql-batch-get.js | 2 +- .../actions/partiql/partiql-batch-put.js | 2 +- .../actions/partiql/partiql-batch-update.js | 2 +- .../actions/partiql/partiql-delete.js | 2 +- .../dynamodb/actions/partiql/partiql-get.js | 2 +- .../dynamodb/actions/partiql/partiql-put.js | 2 +- .../actions/partiql/partiql-update.js | 2 +- .../example_code/dynamodb/actions/put-item.js | 2 +- .../example_code/dynamodb/actions/query.js | 6 +- .../example_code/dynamodb/actions/scan.js | 6 +- .../dynamodb/actions/update-item.js | 2 +- javascriptv3/example_code/dynamodb/hello.js | 2 +- .../example_code/dynamodb/scenarios/basic.js | 6 +- .../dynamodb/scenarios/partiql-batch.js | 6 +- .../dynamodb/scenarios/partiql-single.js | 6 +- .../tests/batch-get-item.integration.test.js | 2 +- .../document-batch-get.integration.test.js | 2 +- .../tests/document-scan.integration.test.js | 6 +- .../tests/put-item.integration.test.js | 2 +- .../ec2/actions/allocate-address.js | 2 +- .../ec2/actions/associate-address.js | 4 +- .../authorize-security-group-ingress.js | 4 +- .../ec2/actions/create-key-pair.js | 4 +- .../ec2/actions/create-security-group.js | 4 +- .../ec2/actions/delete-key-pair.js | 4 +- .../ec2/actions/delete-security-group.js | 4 +- .../ec2/actions/describe-images.js | 9 +- .../ec2/actions/describe-instance-types.js | 2 +- .../ec2/actions/describe-instances.js | 10 +- .../ec2/actions/disassociate-address.js | 4 +- .../example_code/ec2/actions/run-instances.js | 4 +- .../ec2/actions/start-instances.js | 4 +- .../ec2/actions/stop-instances.js | 4 +- .../ec2/actions/terminate-instances.js | 5 +- .../ec2/actions/unmonitor-instances.js | 4 +- javascriptv3/example_code/ec2/hello.js | 2 +- .../example_code/ec2/scenarios/steps.js | 16 +- .../ec2/tests/allocate-address.unit.test.js | 2 +- .../ec2/tests/describe-images.unit.test.js | 4 +- .../describe-instance-types.unit.test.js | 4 +- .../ec2/tests/describe-instances.unit.test.js | 2 +- .../describe-security-groups.unit.test.js | 2 +- .../ec2/tests/run-instances.unit.test.js | 2 +- .../elastic-load-balancing-v2/hello.js | 2 +- .../eventbridge/actions/put-events.js | 2 +- .../eventbridge/actions/put-rule.js | 2 +- .../eventbridge/actions/put-targets.js | 2 +- javascriptv3/example_code/glue/hello.js | 2 +- .../scenarios/basic/steps/clean-up-crawler.js | 4 +- .../scenarios/basic/steps/validate-env.js | 4 +- .../basic/steps/validate-python-script.js | 7 +- .../tests/glue-actions.integration.test.js | 12 +- .../glue/tests/validate-env.unit.test.js | 8 +- .../iam/actions/attach-role-policy.js | 2 +- .../iam/actions/create-access-key.js | 2 +- .../iam/actions/create-account-alias.js | 2 +- .../example_code/iam/actions/create-group.js | 2 +- .../example_code/iam/actions/create-policy.js | 2 +- .../example_code/iam/actions/create-role.js | 2 +- .../iam/actions/create-saml-provider.js | 6 +- .../iam/actions/create-service-linked-role.js | 5 +- .../example_code/iam/actions/create-user.js | 2 +- .../iam/actions/delete-access-key.js | 2 +- .../iam/actions/delete-account-alias.js | 2 +- .../example_code/iam/actions/delete-group.js | 2 +- .../example_code/iam/actions/delete-policy.js | 2 +- .../iam/actions/delete-role-policy.js | 2 +- .../example_code/iam/actions/delete-role.js | 2 +- .../iam/actions/delete-saml-provider.js | 2 +- .../iam/actions/delete-server-certificate.js | 2 +- .../iam/actions/delete-service-linked-role.js | 2 +- .../example_code/iam/actions/delete-user.js | 2 +- .../iam/actions/detach-role-policy.js | 2 +- .../iam/actions/get-access-key-last-used.js | 2 +- .../actions/get-account-password-policy.js | 2 +- .../example_code/iam/actions/get-policy.js | 2 +- .../example_code/iam/actions/get-role.js | 2 +- .../iam/actions/get-server-certificate.js | 2 +- ...get-service-linked-role-deletion-status.js | 2 +- .../iam/actions/list-access-keys.js | 2 +- .../iam/actions/list-account-aliases.js | 2 +- .../actions/list-attached-role-policies.js | 2 +- .../example_code/iam/actions/list-groups.js | 2 +- .../example_code/iam/actions/list-policies.js | 2 +- .../iam/actions/list-role-policies.js | 2 +- .../example_code/iam/actions/list-roles.js | 2 +- .../iam/actions/list-saml-providers.js | 2 +- .../iam/actions/list-server-certificates.js | 2 +- .../example_code/iam/actions/list-users.js | 7 +- .../iam/actions/put-role-policy.js | 2 +- .../iam/actions/update-access-key.js | 2 +- .../iam/actions/update-server-certificate.js | 2 +- .../example_code/iam/actions/update-user.js | 2 +- .../iam/actions/upload-server-certificate.js | 6 +- javascriptv3/example_code/iam/hello.js | 8 +- .../example_code/iam/scenarios/basic.js | 5 +- .../tests/role-and-policy.integration.test.js | 2 +- .../service-linked-role.integration.test.js | 2 +- .../kinesis/actions/put-records.js | 4 +- .../example_code/kinesis/kinesis-cdk/cdk.json | 9 +- .../kinesis-cdk/lib/kinesis-cdk-stack.ts | 2 +- .../kinesis/kinesis-cdk/package.json | 2 +- .../kinesis/kinesis-cdk/tsconfig.json | 14 +- .../tests/kinesis-actions.integration.test.js | 2 +- .../lambda/actions/create-function.js | 2 +- .../lambda/actions/update-function-code.js | 2 +- .../actions/update-function-configuration.js | 2 +- .../guide-cdk-lambda-function.js | 2 +- javascriptv3/example_code/lambda/hello.js | 2 +- .../command-handlers/clean-up-handler.js | 2 +- .../create-function-handler.js | 2 +- .../list-functions-handler.js | 2 +- .../lambda/scenarios/basic/index.js | 4 +- javascriptv3/example_code/libs/cmd-runner.js | 2 +- javascriptv3/example_code/libs/logger.js | 3 +- javascriptv3/example_code/libs/prompter.js | 4 +- .../example_code/libs/scenario/scenario.js | 13 +- .../example_code/libs/sdk/cfn-outputs.js | 15 +- javascriptv3/example_code/libs/slow-logger.js | 2 +- .../libs/tests/util-csv.unit.test.js | 6 +- .../example_code/libs/utils/util-fs.js | 8 +- .../example_code/libs/utils/util-log.js | 2 +- .../example_code/libs/utils/util-node.js | 2 +- .../mediaconvert/src/emc_canceljob.js | 2 +- .../medical-imaging/actions/copy-image-set.js | 231 +++++++------- .../actions/create-datastore.js | 4 +- .../actions/delete-datastore.js | 4 +- .../actions/delete-image-set.js | 8 +- .../medical-imaging/actions/get-datastore.js | 6 +- .../actions/get-dicom-import-job.js | 6 +- .../actions/get-image-frame.js | 10 +- .../actions/get-image-set-metadata.js | 12 +- .../medical-imaging/actions/get-image-set.js | 8 +- .../actions/list-datastores.js | 4 +- .../actions/list-dicom-import-jobs.js | 8 +- .../actions/list-image-set-versions.js | 10 +- .../actions/list-tags-for-resource.js | 8 +- .../actions/search-image-sets.js | 290 +++++++++--------- .../actions/start-dicom-import-job.js | 6 +- .../medical-imaging/actions/tag-resource.js | 8 +- .../medical-imaging/actions/untag-resource.js | 8 +- .../actions/update-image-set-metadata.js | 260 ++++++++-------- .../example_code/medical-imaging/hello.js | 2 +- .../health-image-sets/dataset-steps.js | 2 +- .../health-image-sets/deploy-steps.js | 2 +- .../health-image-sets/image-frame-steps.js | 4 +- .../health-image-sets/image-set-steps.js | 11 +- .../scenarios/health-image-sets/index.js | 2 +- .../pixel-data-verification/index.js | 148 +++++---- .../pixel-data-verification/package.json | 26 +- .../scenarios/tagging-datastores.js | 2 +- .../scenarios/tagging-imagesets.js | 2 +- .../tests/copy-image-set.unit.test.js | 2 +- ...reate-delete-datastore.integration.test.js | 4 +- .../tests/get-datastore.integration.test.js | 2 +- .../tests/get-image-frame.unit.test.js | 4 +- .../tests/get-image-set-metadata.unit.test.js | 4 +- .../tests/hlth-img-dataset.unit.test.js | 6 +- .../tests/hlth-img-image-frame.unit.test.js | 4 +- .../tests/search-image-set.unit.test.js | 98 +++--- .../tests/start-dicom-import-job.unit.test.js | 2 +- .../update-image-set-metadata.unit.test.js | 112 +++---- .../example_code/nodegetstarted/index.js | 14 +- .../src/libs/personalizeClients.js | 10 +- .../personalize_createBatchInferenceJob.js | 33 +- .../src/personalize_createBatchSegmentJob.js | 35 +-- .../src/personalize_createCampaign.js | 15 +- .../src/personalize_createDataset.js | 19 +- .../src/personalize_createDatasetExportJob.js | 23 +- .../src/personalize_createDatasetImportJob.js | 22 +- .../personalize_createDomainDatasetGroup.js | 16 +- .../src/personalize_createDomainSchema.js | 22 +- .../src/personalize_createEventTracker.js | 15 +- .../src/personalize_createFilter.js | 17 +- .../src/personalize_createRecommender.js | 17 +- .../src/personalize_createSchema.js | 19 +- .../src/personalize_createSolution.js | 17 +- .../src/personalize_createSolutionVersion.js | 13 +- .../src/personalize_getPersonalizedRanking.js | 17 +- .../src/personalize_getRecommendations.js | 17 +- ...alize_getRecommendationsFromRecommender.js | 17 +- ...ersonalize_getRecommendationsWithFilter.js | 24 +- .../personalize/src/personalize_putEvents.js | 2 +- .../personalize/src/personalize_putItems.js | 2 +- .../personalize/src/personalize_putUsers.js | 2 +- .../src/pinpoint_send_email_message.js | 11 +- .../pinpoint/src/pinpoint_send_sms_message.js | 11 +- .../src/polly_synthesize_to_s3.js | 4 +- javascriptv3/example_code/polly/src/polly.js | 2 +- .../reactnative/ReactNativeApp/.eslintrc.js | 4 +- .../reactnative/ReactNativeApp/.prettierrc.js | 4 +- .../reactnative/ReactNativeApp/App.tsx | 59 ++-- .../ReactNativeApp/babel.config.js | 2 +- .../reactnative/ReactNativeApp/index.js | 6 +- .../AppIcon.appiconset/Contents.json | 62 ++-- .../Images.xcassets/Contents.json | 6 +- .../ReactNativeApp/metro.config.js | 6 +- .../redshift/src/redshift-create-cluster.js | 2 +- .../estimate-age-example/src/estimate-age.js | 75 ++--- .../example_code/s3/actions/copy-object.js | 2 +- .../example_code/s3/actions/create-bucket.js | 2 +- .../s3/actions/delete-bucket-policy.js | 2 +- .../s3/actions/delete-bucket-website.js | 2 +- .../example_code/s3/actions/delete-bucket.js | 4 +- .../example_code/s3/actions/delete-object.js | 2 +- .../example_code/s3/actions/delete-objects.js | 2 +- .../example_code/s3/actions/get-bucket-acl.js | 2 +- .../s3/actions/get-bucket-cors.js | 2 +- .../s3/actions/get-bucket-policy.js | 2 +- .../s3/actions/get-bucket-website.js | 2 +- .../s3/actions/get-object-legal-hold.js | 2 +- .../actions/get-object-lock-configuration.js | 2 +- .../s3/actions/get-object-retention.js | 2 +- .../example_code/s3/actions/get-object.js | 2 +- .../example_code/s3/actions/list-buckets.js | 2 +- .../example_code/s3/actions/list-objects.js | 4 +- .../example_code/s3/actions/put-bucket-acl.js | 2 +- .../s3/actions/put-bucket-cors.js | 2 +- .../s3/actions/put-bucket-policy.js | 2 +- .../s3/actions/put-bucket-website.js | 2 +- .../put-default-object-lock-configuration.js | 4 +- .../s3/actions/put-object-legal-hold.js | 2 +- .../actions/put-object-lock-configuration.js | 2 +- .../s3/actions/put-object-retention.js | 4 +- .../example_code/s3/actions/put-object.js | 4 +- javascriptv3/example_code/s3/hello.js | 2 +- .../example_code/s3/scenarios/basic.js | 69 ++--- .../s3/scenarios/create-list-delete-bucket.js | 8 +- .../s3/scenarios/delete-all-objects.js | 4 +- .../s3/scenarios/multipart-download.js | 12 +- .../s3/scenarios/multipart-upload.js | 2 +- .../scenarios/object-locking/clean.steps.js | 3 +- .../s3/scenarios/object-locking/index.js | 2 +- .../object-locking/index.unit.test.js | 14 +- .../s3/scenarios/object-locking/repl.steps.js | 2 +- .../object-locking/repl.steps.unit.test.js | 48 ++- .../scenarios/object-locking/setup.steps.js | 6 +- .../object-locking/setup.steps.unit.test.js | 4 +- .../scenarios/object-locking/welcome.steps.js | 2 +- .../s3/scenarios/presigned-url-download.js | 2 +- .../s3/scenarios/presigned-url-upload.js | 4 +- .../example_code/s3/tests/basic.unit.test.js | 2 +- .../s3/tests/delete-objects.unit.test.js | 2 +- .../s3/tests/get-bucket-cors.unit.test.js | 12 +- .../get-object-legal-hold.integration.test.js | 2 +- ...ect-lock-configuration.integration.test.js | 2 +- .../get-object-retention.integration.test.js | 2 +- .../s3/tests/list-buckets.unit.test.js | 4 +- .../s3/tests/list-objects.unit.test.js | 2 +- .../multipart-upload.integration.test.js | 2 +- .../s3/tests/put-bucket-cors.unit.test.js | 2 +- ...ect-lock-configuration.integration.test.js | 2 +- .../put-object-legal-hold.integration.test.js | 2 +- ...ect-lock-configuration.integration.test.js | 2 +- .../put-object-retention.integration.test.js | 2 +- .../s3/tests/s3-hello.integration.test.js | 2 +- javascriptv3/example_code/sagemaker/hello.js | 2 +- .../example_code/sagemaker/package.json | 2 +- .../index.js | 2 +- .../lambda/dist/index.mjs | 29 +- .../lib.js | 9 +- .../lib.unit.test.js | 60 ++-- .../messages.js | 3 +- .../actions/get-secret-value.js | 2 +- .../ses/src/send-with-attachments.js | 2 +- .../sfn/actions/start-execution.js | 4 +- .../sfn/tests/start-execution.unit.test.js | 2 +- .../check-if-phone-number-is-opted-out.js | 2 +- .../sns/actions/confirm-subscription.js | 2 +- .../example_code/sns/actions/create-topic.js | 2 +- .../example_code/sns/actions/delete-topic.js | 2 +- .../sns/actions/get-sms-attributes.js | 2 +- .../sns/actions/get-topic-attributes.js | 2 +- .../actions/list-phone-numbers-opted-out.js | 2 +- .../actions/list-subscriptions-by-topic.js | 2 +- .../example_code/sns/actions/list-topics.js | 2 +- .../example_code/sns/actions/publish-sms.js | 2 +- .../example_code/sns/actions/publish-topic.js | 2 +- .../sns/actions/set-sms-attribute-type.js | 2 +- .../sns/actions/set-topic-attributes.js | 2 +- .../example_code/sns/actions/subscribe-app.js | 2 +- .../sns/actions/subscribe-email.js | 2 +- .../sns/actions/subscribe-lambda.js | 2 +- .../sns/actions/subscribe-queue-filtered.js | 2 +- .../sns/actions/subscribe-queue.js | 2 +- .../example_code/sns/actions/unsubscribe.js | 2 +- javascriptv3/example_code/sns/hello.js | 2 +- .../tests/subscribe-queue.integration.test.js | 10 +- .../sqs/actions/change-message-visibility.js | 2 +- .../sqs/actions/create-queue-long-polling.js | 2 +- .../example_code/sqs/actions/create-queue.js | 4 +- .../example_code/sqs/actions/delete-queue.js | 2 +- .../sqs/actions/get-queue-attributes.js | 2 +- .../example_code/sqs/actions/get-queue-url.js | 2 +- .../example_code/sqs/actions/list-queues.js | 6 +- .../sqs/actions/receive-delete-message.js | 2 +- .../sqs/actions/receive-long-polling.js | 2 +- .../example_code/sqs/actions/send-message.js | 2 +- .../sqs/actions/set-attributes-dead-letter.js | 2 +- .../actions/set-attributes-long-polling.js | 2 +- .../sqs/actions/set-queue-attributes.js | 2 +- javascriptv3/example_code/sqs/hello.js | 2 +- .../ssm/actions/create-document.js | 4 +- .../ssm/actions/create-maintenance-window.js | 6 +- .../ssm/actions/create-ops-item.js | 6 +- .../ssm/actions/delete-document.js | 6 +- .../ssm/actions/delete-maintenance-window.js | 6 +- .../ssm/actions/describe-ops-items.js | 8 +- .../ssm/actions/list-command-invocations.js | 6 +- .../example_code/ssm/actions/send-command.js | 4 +- .../ssm/actions/update-maintenance-window.js | 4 +- .../ssm/actions/update-ops-item.js | 4 +- javascriptv3/example_code/ssm/hello.js | 9 +- .../example_code/ssm/scenarios/ssm-basics.js | 49 ++- .../ssm/tests/describe-ops-items.unit.test.js | 4 +- .../example_code/ssm/tests/hello.unit.test.js | 6 +- .../list-command-invocations.unit.test.js | 4 +- .../example_code/sts/actions/assume-role.js | 2 +- .../support/actions/add-attachments-to-set.js | 2 +- .../actions/add-communication-to-case.js | 2 +- .../support/actions/create-case.js | 2 +- .../support/actions/describe-attachment.js | 2 +- .../support/actions/describe-cases.js | 2 +- .../actions/describe-communications.js | 2 +- .../support/actions/describe-services.js | 2 +- .../actions/describe-severity-levels.js | 2 +- .../support/actions/resolve-case.js | 2 +- javascriptv3/example_code/support/hello.js | 5 +- .../example_code/support/scenarios/basic.js | 5 +- .../transcribe/src/transcribe_create_job.js | 4 +- .../src/transcribe_create_medical_job.js | 2 +- .../transcribe/src/transcribe_delete_job.js | 2 +- .../src/transcribe_delete_medical_job.js | 2 +- .../transcribe/src/transcribe_list_jobs.js | 2 +- .../src/transcribe_list_medical_jobs.js | 2 +- .../web/s3/list-objects/src/App.tsx | 2 +- javascriptv3/package.json | 20 +- 473 files changed, 2182 insertions(+), 2176 deletions(-) delete mode 100644 javascriptv3/.eslintignore delete mode 100644 javascriptv3/.eslintrc.json create mode 100644 javascriptv3/biome.json diff --git a/javascriptv3/.eslintignore b/javascriptv3/.eslintignore deleted file mode 100644 index cbb5a738ff2..00000000000 --- a/javascriptv3/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -/example_code/reactnative/ -/example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification -/example_code/kinesis/kinesis-cdk -**/dist \ No newline at end of file diff --git a/javascriptv3/.eslintrc.json b/javascriptv3/.eslintrc.json deleted file mode 100644 index 82980b4492e..00000000000 --- a/javascriptv3/.eslintrc.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "env": { - "es2021": true, - "node": true, - "browser": true - }, - "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], - "parser": "@typescript-eslint/parser", - "plugins": ["import", "@typescript-eslint"], - "overrides": [], - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module", - "project": ["./tsconfig.json"] - }, - "settings": { - "import/resolver": { "typescript": {} } - }, - "rules": { - "require-await": "error", - "import/no-unresolved": "error", - "@typescript-eslint/no-unused-vars": [ - "error", - { - "argsIgnorePattern": "^_", - "varsIgnorePattern": "^_", - "caughtErrorsIgnorePattern": "^_" - } - ], - "@typescript-eslint/no-unsafe-member-access": "error" - } -} diff --git a/javascriptv3/.gitignore b/javascriptv3/.gitignore index 18a26eadff0..ae26608ebf3 100644 --- a/javascriptv3/.gitignore +++ b/javascriptv3/.gitignore @@ -4,4 +4,5 @@ node_modules/ package-lock.json test_results/ test-results.xml -state.json \ No newline at end of file +state.json +.mypy_cache \ No newline at end of file diff --git a/javascriptv3/biome.json b/javascriptv3/biome.json new file mode 100644 index 00000000000..01380d4621a --- /dev/null +++ b/javascriptv3/biome.json @@ -0,0 +1,48 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.3/schema.json", + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + }, + "files": { + "ignoreUnknown": false, + "ignore": [ + "./example_code/reactnative/", + "./example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification", + "./example_code/kinesis/kinesis-cdk", + "./example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification/openjphjs/openjphjs.js", + "**/dist" + ] + }, + "formatter": { + "enabled": true, + "indentStyle": "tab" + }, + "organizeImports": { + "enabled": false + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "javascript": { + "formatter": { + "quoteStyle": "double", + "indentStyle": "space", + "trailingCommas": "all" + } + }, + "json": { + "formatter": { + "indentStyle": "space" + } + }, + "css": { + "formatter": { + "indentStyle": "space" + } + } +} diff --git a/javascriptv3/example_code/bedrock-agent-runtime/actions/invoke-agent.js b/javascriptv3/example_code/bedrock-agent-runtime/actions/invoke-agent.js index a24abb45343..0a5f03a84b0 100644 --- a/javascriptv3/example_code/bedrock-agent-runtime/actions/invoke-agent.js +++ b/javascriptv3/example_code/bedrock-agent-runtime/actions/invoke-agent.js @@ -46,7 +46,7 @@ export const invokeBedrockAgent = async (prompt, sessionId) => { throw new Error("Completion is undefined"); } - for await (let chunkEvent of response.completion) { + for await (const chunkEvent of response.completion) { const chunk = chunkEvent.chunk; console.log(chunk); const decodedResponse = new TextDecoder("utf-8").decode(chunk.bytes); @@ -60,7 +60,7 @@ export const invokeBedrockAgent = async (prompt, sessionId) => { }; // Call function if run directly -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { const result = await invokeBedrockAgent("I need help.", "123"); console.log(result); diff --git a/javascriptv3/example_code/bedrock-agent-runtime/vite.config.js b/javascriptv3/example_code/bedrock-agent-runtime/vite.config.js index b37db909158..1e2e2787cac 100644 --- a/javascriptv3/example_code/bedrock-agent-runtime/vite.config.js +++ b/javascriptv3/example_code/bedrock-agent-runtime/vite.config.js @@ -4,8 +4,8 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ - test: { - testTimeout: 50000, - threads: false, - }, + test: { + testTimeout: 50000, + threads: false, + }, }); diff --git a/javascriptv3/example_code/bedrock-agent/actions/create-agent.js b/javascriptv3/example_code/bedrock-agent/actions/create-agent.js index 866c9effaf8..2179a38579b 100644 --- a/javascriptv3/example_code/bedrock-agent/actions/create-agent.js +++ b/javascriptv3/example_code/bedrock-agent/actions/create-agent.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { checkForPlaceholders } from "../lib/utils.js"; import { @@ -61,7 +61,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { // Check for unresolved placeholders in agentName and roleArn. checkForPlaceholders([agentName, roleArn]); - console.log(`Creating a new agent...`); + console.log("Creating a new agent..."); const agent = await createAgent(agentName, foundationModel, roleArn); console.log(agent); diff --git a/javascriptv3/example_code/bedrock-agent/actions/delete-agent.js b/javascriptv3/example_code/bedrock-agent/actions/delete-agent.js index 9fb8741fead..64ceee01685 100644 --- a/javascriptv3/example_code/bedrock-agent/actions/delete-agent.js +++ b/javascriptv3/example_code/bedrock-agent/actions/delete-agent.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { checkForPlaceholders } from "../lib/utils.js"; import { diff --git a/javascriptv3/example_code/bedrock-agent/actions/get-agent.js b/javascriptv3/example_code/bedrock-agent/actions/get-agent.js index 9ed874bb1b6..e5607415d31 100644 --- a/javascriptv3/example_code/bedrock-agent/actions/get-agent.js +++ b/javascriptv3/example_code/bedrock-agent/actions/get-agent.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { checkForPlaceholders } from "../lib/utils.js"; import { diff --git a/javascriptv3/example_code/bedrock-agent/actions/list-agent-action-groups.js b/javascriptv3/example_code/bedrock-agent/actions/list-agent-action-groups.js index 7ba0af8641d..205062d8ea2 100644 --- a/javascriptv3/example_code/bedrock-agent/actions/list-agent-action-groups.js +++ b/javascriptv3/example_code/bedrock-agent/actions/list-agent-action-groups.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { checkForPlaceholders } from "../lib/utils.js"; import { diff --git a/javascriptv3/example_code/bedrock-agent/actions/list-agents.js b/javascriptv3/example_code/bedrock-agent/actions/list-agents.js index fd528d18a5a..7b02ea458ba 100644 --- a/javascriptv3/example_code/bedrock-agent/actions/list-agents.js +++ b/javascriptv3/example_code/bedrock-agent/actions/list-agents.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { BedrockAgentClient, diff --git a/javascriptv3/example_code/bedrock-agent/hello.js b/javascriptv3/example_code/bedrock-agent/hello.js index 569a8235e05..6c164295009 100644 --- a/javascriptv3/example_code/bedrock-agent/hello.js +++ b/javascriptv3/example_code/bedrock-agent/hello.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { BedrockAgentClient, @@ -35,7 +35,7 @@ export const main = async () => { console.log(`Initializing Amazon Bedrock Agents client for ${region}...`); const client = new BedrockAgentClient({ region }); - console.log(`Retrieving the list of existing agents...`); + console.log("Retrieving the list of existing agents..."); const paginatorConfig = { client }; const pages = paginateListAgents(paginatorConfig, {}); diff --git a/javascriptv3/example_code/bedrock-agent/lib/utils.js b/javascriptv3/example_code/bedrock-agent/lib/utils.js index 8c16fa6737b..1ab1bbaace2 100644 --- a/javascriptv3/example_code/bedrock-agent/lib/utils.js +++ b/javascriptv3/example_code/bedrock-agent/lib/utils.js @@ -6,7 +6,9 @@ */ export const checkForPlaceholders = (variables) => { if ( - variables.some((variable) => isNaN(+variable) && variable.includes("[")) + variables.some( + (variable) => Number.isNaN(+variable) && variable.includes("["), + ) ) { throw new Error( "Error: One or more variables contain unresolved placeholders. Please ensure all placeholders are replaced with valid data and the brackets have been removed before proceeding.", diff --git a/javascriptv3/example_code/bedrock-runtime/hello.js b/javascriptv3/example_code/bedrock-runtime/hello.js index d44b7c23447..fe4df272cbe 100644 --- a/javascriptv3/example_code/bedrock-runtime/hello.js +++ b/javascriptv3/example_code/bedrock-runtime/hello.js @@ -14,7 +14,7 @@ * @property {Usage} usage */ -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { BedrockRuntimeClient, InvokeModelCommand, diff --git a/javascriptv3/example_code/bedrock-runtime/models/ai21LabsJurassic2/invoke_model.js b/javascriptv3/example_code/bedrock-runtime/models/ai21LabsJurassic2/invoke_model.js index 98831202005..602cf938d36 100644 --- a/javascriptv3/example_code/bedrock-runtime/models/ai21LabsJurassic2/invoke_model.js +++ b/javascriptv3/example_code/bedrock-runtime/models/ai21LabsJurassic2/invoke_model.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { FoundationModels } from "../../config/foundation_models.js"; import { diff --git a/javascriptv3/example_code/bedrock-runtime/models/amazonTitanText/invoke_model.js b/javascriptv3/example_code/bedrock-runtime/models/amazonTitanText/invoke_model.js index fc88fc59ea0..d8aee0eb299 100644 --- a/javascriptv3/example_code/bedrock-runtime/models/amazonTitanText/invoke_model.js +++ b/javascriptv3/example_code/bedrock-runtime/models/amazonTitanText/invoke_model.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { FoundationModels } from "../../config/foundation_models.js"; import { diff --git a/javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_2.js b/javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_2.js index 1bf0f920a9b..37423ecc4db 100644 --- a/javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_2.js +++ b/javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_2.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { FoundationModels } from "../../config/foundation_models.js"; import { diff --git a/javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_3.js b/javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_3.js index b76f3441dda..8531e2734f8 100644 --- a/javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_3.js +++ b/javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_3.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { FoundationModels } from "../../config/foundation_models.js"; import { @@ -137,7 +137,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { try { console.log("-".repeat(53)); const response = await invokeModel(prompt, modelId); - console.log("\n" + "-".repeat(53)); + console.log(`\n${"-".repeat(53)}`); console.log("Final structured response:"); console.log(response); } catch (err) { diff --git a/javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_instant_1.js b/javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_instant_1.js index f87864b3851..23ed0598c0e 100644 --- a/javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_instant_1.js +++ b/javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_instant_1.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { FoundationModels } from "../../config/foundation_models.js"; import { diff --git a/javascriptv3/example_code/bedrock-runtime/models/mistral/invoke_mistral_7b.js b/javascriptv3/example_code/bedrock-runtime/models/mistral/invoke_mistral_7b.js index 616315f18d0..f182f1d284a 100644 --- a/javascriptv3/example_code/bedrock-runtime/models/mistral/invoke_mistral_7b.js +++ b/javascriptv3/example_code/bedrock-runtime/models/mistral/invoke_mistral_7b.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { FoundationModels } from "../../config/foundation_models.js"; import { diff --git a/javascriptv3/example_code/bedrock-runtime/models/mistral/invoke_mixtral_8x7b.js b/javascriptv3/example_code/bedrock-runtime/models/mistral/invoke_mixtral_8x7b.js index de112895cee..f11f35eb469 100644 --- a/javascriptv3/example_code/bedrock-runtime/models/mistral/invoke_mixtral_8x7b.js +++ b/javascriptv3/example_code/bedrock-runtime/models/mistral/invoke_mixtral_8x7b.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { FoundationModels } from "../../config/foundation_models.js"; import { diff --git a/javascriptv3/example_code/bedrock-runtime/scenarios/cli_text_playground.js b/javascriptv3/example_code/bedrock-runtime/scenarios/cli_text_playground.js index 0bdeade3c17..1763022bdb5 100644 --- a/javascriptv3/example_code/bedrock-runtime/scenarios/cli_text_playground.js +++ b/javascriptv3/example_code/bedrock-runtime/scenarios/cli_text_playground.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { Scenario, ScenarioAction, diff --git a/javascriptv3/example_code/bedrock-runtime/tests/converse.integration.test.js b/javascriptv3/example_code/bedrock-runtime/tests/converse.integration.test.js index 57ab1f3dd23..db5ac65d7c6 100644 --- a/javascriptv3/example_code/bedrock-runtime/tests/converse.integration.test.js +++ b/javascriptv3/example_code/bedrock-runtime/tests/converse.integration.test.js @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { describe, expect, test, vi } from "vitest"; -import path from "path"; +import path from "node:path"; describe("Converse with text generation models", () => { const baseDirectory = path.join(__dirname, "..", "models"); diff --git a/javascriptv3/example_code/bedrock-runtime/tests/converse_stream.integration.test.js b/javascriptv3/example_code/bedrock-runtime/tests/converse_stream.integration.test.js index c3f531c8984..64d964cccd0 100644 --- a/javascriptv3/example_code/bedrock-runtime/tests/converse_stream.integration.test.js +++ b/javascriptv3/example_code/bedrock-runtime/tests/converse_stream.integration.test.js @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import { describe, expect, test, vi } from "vitest"; -import path from "path"; -import { Writable } from "stream"; +import path from "node:path"; +import { Writable } from "node:stream"; describe("ConverseStream with text generation models", () => { const fileName = "converseStream.js"; diff --git a/javascriptv3/example_code/bedrock/actions/get-foundation-model.js b/javascriptv3/example_code/bedrock/actions/get-foundation-model.js index ac717ece3c1..dc2ac5781e0 100644 --- a/javascriptv3/example_code/bedrock/actions/get-foundation-model.js +++ b/javascriptv3/example_code/bedrock/actions/get-foundation-model.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { BedrockClient, diff --git a/javascriptv3/example_code/bedrock/actions/list-foundation-models.js b/javascriptv3/example_code/bedrock/actions/list-foundation-models.js index b25efe6b2bf..041cfea3fa5 100644 --- a/javascriptv3/example_code/bedrock/actions/list-foundation-models.js +++ b/javascriptv3/example_code/bedrock/actions/list-foundation-models.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { BedrockClient, diff --git a/javascriptv3/example_code/bedrock/hello.js b/javascriptv3/example_code/bedrock/hello.js index d897743385b..1ed2ff64024 100644 --- a/javascriptv3/example_code/bedrock/hello.js +++ b/javascriptv3/example_code/bedrock/hello.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { BedrockClient, @@ -19,7 +19,7 @@ export const main = async () => { console.log("Listing the available Bedrock foundation models:"); - for (let model of models) { + for (const model of models) { console.log("=".repeat(42)); console.log(` Model: ${model.modelId}`); console.log("-".repeat(42)); @@ -31,7 +31,7 @@ export const main = async () => { console.log(` Supported customizations: ${model.customizationsSupported}`); console.log(` Supported inference types: ${model.inferenceTypesSupported}`); console.log(` Lifecycle status: ${model.modelLifecycle.status}`); - console.log("=".repeat(42) + "\n"); + console.log(`${"=".repeat(42)}\n`); } const active = models.filter( diff --git a/javascriptv3/example_code/bedrock/tests/get-foundation-model.integration.test.js b/javascriptv3/example_code/bedrock/tests/get-foundation-model.integration.test.js index 15f6e5f18ef..64f5e884e22 100644 --- a/javascriptv3/example_code/bedrock/tests/get-foundation-model.integration.test.js +++ b/javascriptv3/example_code/bedrock/tests/get-foundation-model.integration.test.js @@ -13,7 +13,7 @@ const ExpectedSchema = z.object({ describe("get-foundation-model", () => { it("should return the model' details", async () => { - let modelDetails = await getFoundationModel(); + const modelDetails = await getFoundationModel(); expect(modelDetails).not.toBeNull(); const isModelDetails = ExpectedSchema.safeParse(modelDetails).success; diff --git a/javascriptv3/example_code/bedrock/tests/list-foundation-models.integration.test.js b/javascriptv3/example_code/bedrock/tests/list-foundation-models.integration.test.js index b39ee5a0269..e14be24c325 100644 --- a/javascriptv3/example_code/bedrock/tests/list-foundation-models.integration.test.js +++ b/javascriptv3/example_code/bedrock/tests/list-foundation-models.integration.test.js @@ -13,7 +13,7 @@ const ExpectedSchema = z.object({ describe("list-foundation-models", () => { it("should return model summaries", async () => { - let modelSummaries = await listFoundationModels(); + const modelSummaries = await listFoundationModels(); expect(modelSummaries.length).toBeGreaterThan(0); const isModelSummary = ExpectedSchema.safeParse(modelSummaries[0]).success; diff --git a/javascriptv3/example_code/cloudwatch-logs/actions/describe-log-groups.js b/javascriptv3/example_code/cloudwatch-logs/actions/describe-log-groups.js index c0606dfd1a1..0718c074498 100644 --- a/javascriptv3/example_code/cloudwatch-logs/actions/describe-log-groups.js +++ b/javascriptv3/example_code/cloudwatch-logs/actions/describe-log-groups.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.cloudwatchlogs.actions.DescribeLogGroups] import { @@ -16,7 +16,7 @@ export const main = async () => { const logGroups = []; for await (const page of paginatedLogGroups) { - if (page.logGroups && page.logGroups.every((lg) => !!lg)) { + if (page.logGroups?.every((lg) => !!lg)) { logGroups.push(...page.logGroups); } } diff --git a/javascriptv3/example_code/cloudwatch-logs/libs/lambda-helper.js b/javascriptv3/example_code/cloudwatch-logs/libs/lambda-helper.js index 00e878e3fb5..f83321cc442 100644 --- a/javascriptv3/example_code/cloudwatch-logs/libs/lambda-helper.js +++ b/javascriptv3/example_code/cloudwatch-logs/libs/lambda-helper.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { readFileSync } from "fs"; +import { readFileSync } from "node:fs"; import { CreateFunctionCommand, Architecture, @@ -24,7 +24,7 @@ const cloudWatchLogsClient = new CloudWatchLogsClient({}); * @param {string} roleArn */ export const createFunction = async (name, roleArn) => { - const lambdaFunctionBuffer = readFileSync(`./tests/data/lambda-function.zip`); + const lambdaFunctionBuffer = readFileSync("./tests/data/lambda-function.zip"); const command = new CreateFunctionCommand({ Code: { ZipFile: lambdaFunctionBuffer }, FunctionName: name, @@ -60,9 +60,8 @@ export const addPermissionLogsInvokeFunction = async ( let logGroup; for await (const page of logGroupPaginator) { - if ( - (logGroup = page.logGroups.find((lg) => lg.logGroupName === logGroupName)) - ) { + logGroup = page.logGroups.find((lg) => lg.logGroupName === logGroupName); + if (logGroup) { break; } } diff --git a/javascriptv3/example_code/cloudwatch-logs/scenarios/large-query/cloud-watch-query.js b/javascriptv3/example_code/cloudwatch-logs/scenarios/large-query/cloud-watch-query.js index b7866d56b82..1304aa9f20a 100644 --- a/javascriptv3/example_code/cloudwatch-logs/scenarios/large-query/cloud-watch-query.js +++ b/javascriptv3/example_code/cloudwatch-logs/scenarios/large-query/cloud-watch-query.js @@ -133,9 +133,8 @@ export class CloudWatchQuery { */ if (err instanceof DateOutOfBoundsError) { return []; - } else { - throw err; } + throw err; } } diff --git a/javascriptv3/example_code/cloudwatch-logs/scenarios/large-query/index.js b/javascriptv3/example_code/cloudwatch-logs/scenarios/large-query/index.js index c22f0326e51..73aef5aba48 100644 --- a/javascriptv3/example_code/cloudwatch-logs/scenarios/large-query/index.js +++ b/javascriptv3/example_code/cloudwatch-logs/scenarios/large-query/index.js @@ -14,8 +14,8 @@ if (!process.env.QUERY_START_DATE || !process.env.QUERY_END_DATE) { const cloudWatchQuery = new CloudWatchQuery(new CloudWatchLogsClient({}), { logGroupNames: ["/workflows/cloudwatch-logs/large-query"], dateRange: [ - new Date(parseInt(process.env.QUERY_START_DATE)), - new Date(parseInt(process.env.QUERY_END_DATE)), + new Date(Number.parseInt(process.env.QUERY_START_DATE)), + new Date(Number.parseInt(process.env.QUERY_END_DATE)), ], }); diff --git a/javascriptv3/example_code/cloudwatch-logs/vite.config.js b/javascriptv3/example_code/cloudwatch-logs/vite.config.js index a602c3bdcfe..c7696d09f37 100644 --- a/javascriptv3/example_code/cloudwatch-logs/vite.config.js +++ b/javascriptv3/example_code/cloudwatch-logs/vite.config.js @@ -1,4 +1,4 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { defineConfig } from "vitest/config"; diff --git a/javascriptv3/example_code/cloudwatch/actions/list-metrics.js b/javascriptv3/example_code/cloudwatch/actions/list-metrics.js index a0674040bdf..e5760628916 100644 --- a/javascriptv3/example_code/cloudwatch/actions/list-metrics.js +++ b/javascriptv3/example_code/cloudwatch/actions/list-metrics.js @@ -24,7 +24,7 @@ export const main = () => { // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codebuild/actions/create-project.js b/javascriptv3/example_code/codebuild/actions/create-project.js index 8c3f5a433a2..927aefd76de 100644 --- a/javascriptv3/example_code/codebuild/actions/create-project.js +++ b/javascriptv3/example_code/codebuild/actions/create-project.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.codebuild.actions.CreateProject] import { diff --git a/javascriptv3/example_code/codecommit/src/createBranch.js b/javascriptv3/example_code/codecommit/src/createBranch.js index 326fa0d3990..7ce86eb8b8b 100644 --- a/javascriptv3/example_code/codecommit/src/createBranch.js +++ b/javascriptv3/example_code/codecommit/src/createBranch.js @@ -43,7 +43,7 @@ export const main = async () => { }; // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codecommit/src/createCommit.js b/javascriptv3/example_code/codecommit/src/createCommit.js index 82a06ff5c6b..9ea4724841e 100644 --- a/javascriptv3/example_code/codecommit/src/createCommit.js +++ b/javascriptv3/example_code/codecommit/src/createCommit.js @@ -69,7 +69,7 @@ export const main = async () => { }; // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codecommit/src/createPullRequest.js b/javascriptv3/example_code/codecommit/src/createPullRequest.js index 36b5934444e..ed36da5906c 100644 --- a/javascriptv3/example_code/codecommit/src/createPullRequest.js +++ b/javascriptv3/example_code/codecommit/src/createPullRequest.js @@ -47,7 +47,7 @@ export const main = async () => { }; // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codecommit/src/createRepository.js b/javascriptv3/example_code/codecommit/src/createRepository.js index 73da3a102c8..1d955363e57 100644 --- a/javascriptv3/example_code/codecommit/src/createRepository.js +++ b/javascriptv3/example_code/codecommit/src/createRepository.js @@ -40,7 +40,7 @@ export const main = async () => { }; // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codecommit/src/deleteBranch.js b/javascriptv3/example_code/codecommit/src/deleteBranch.js index 9e59bd0d335..ce2fc8646bd 100644 --- a/javascriptv3/example_code/codecommit/src/deleteBranch.js +++ b/javascriptv3/example_code/codecommit/src/deleteBranch.js @@ -41,7 +41,7 @@ export const main = async () => { }; // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codecommit/src/deleteRepository.js b/javascriptv3/example_code/codecommit/src/deleteRepository.js index e5f571bc154..1710a7bdae9 100644 --- a/javascriptv3/example_code/codecommit/src/deleteRepository.js +++ b/javascriptv3/example_code/codecommit/src/deleteRepository.js @@ -39,7 +39,7 @@ export const main = async () => { }; // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codecommit/src/describePullRequestEvents.js b/javascriptv3/example_code/codecommit/src/describePullRequestEvents.js index 20a103ce5bc..5cd60031f84 100644 --- a/javascriptv3/example_code/codecommit/src/describePullRequestEvents.js +++ b/javascriptv3/example_code/codecommit/src/describePullRequestEvents.js @@ -45,7 +45,7 @@ export const main = async () => { }; // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codecommit/src/getMergeOptions.js b/javascriptv3/example_code/codecommit/src/getMergeOptions.js index 960328649df..75d8f9c8ef8 100644 --- a/javascriptv3/example_code/codecommit/src/getMergeOptions.js +++ b/javascriptv3/example_code/codecommit/src/getMergeOptions.js @@ -47,7 +47,7 @@ export const main = async () => { }; // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codecommit/src/getPullRequest.js b/javascriptv3/example_code/codecommit/src/getPullRequest.js index 9e4c0437266..2df64827027 100644 --- a/javascriptv3/example_code/codecommit/src/getPullRequest.js +++ b/javascriptv3/example_code/codecommit/src/getPullRequest.js @@ -38,7 +38,7 @@ export const main = async () => { }; // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codecommit/src/getRepository.js b/javascriptv3/example_code/codecommit/src/getRepository.js index ef55e18a727..34abfb8d691 100644 --- a/javascriptv3/example_code/codecommit/src/getRepository.js +++ b/javascriptv3/example_code/codecommit/src/getRepository.js @@ -38,7 +38,7 @@ export const main = async () => { }; // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codecommit/src/listRepositories.js b/javascriptv3/example_code/codecommit/src/listRepositories.js index 7d6801c1465..e392fb8be06 100644 --- a/javascriptv3/example_code/codecommit/src/listRepositories.js +++ b/javascriptv3/example_code/codecommit/src/listRepositories.js @@ -29,7 +29,7 @@ export const main = async () => { }; // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codecommit/src/mergeBranches.js b/javascriptv3/example_code/codecommit/src/mergeBranches.js index 6cbd4a623ec..93b5ea8e85f 100644 --- a/javascriptv3/example_code/codecommit/src/mergeBranches.js +++ b/javascriptv3/example_code/codecommit/src/mergeBranches.js @@ -50,7 +50,7 @@ export const main = async () => { }; // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/codepipeline/MyCodePipelineFunction.js b/javascriptv3/example_code/codepipeline/MyCodePipelineFunction.js index 6cf41cc57dc..058f5fb070c 100644 --- a/javascriptv3/example_code/codepipeline/MyCodePipelineFunction.js +++ b/javascriptv3/example_code/codepipeline/MyCodePipelineFunction.js @@ -4,28 +4,28 @@ // snippet-start:[codepipeline.javascript.MyCodePipelineFunction.complete] -var assert = require("assert"); -var AWS = require("aws-sdk"); -var http = require("http"); +const assert = require("node:assert"); +const AWS = require("aws-sdk"); +const http = require("node:http"); -exports.handler = function (event, context) { - var codepipeline = new AWS.CodePipeline(); +exports.handler = (event, context) => { + const codepipeline = new AWS.CodePipeline(); // Retrieve the Job ID from the Lambda action - var jobId = event["CodePipeline.job"].id; + const jobId = event["CodePipeline.job"].id; // Retrieve the value of UserParameters from the Lambda action configuration in AWS CodePipeline, in this case a URL which will be // health checked by this function. - var url = + const url = event["CodePipeline.job"].data.actionConfiguration.configuration .UserParameters; // Notify AWS CodePipeline of a successful job - var putJobSuccess = function (message) { - var params = { + const putJobSuccess = (message) => { + const params = { jobId: jobId, }; - codepipeline.putJobSuccessResult(params, function (err, data) { + codepipeline.putJobSuccessResult(params, (err, data) => { if (err) { context.fail(err); } else { @@ -35,8 +35,8 @@ exports.handler = function (event, context) { }; // Notify AWS CodePipeline of a failed job - var putJobFailure = function (message) { - var params = { + const putJobFailure = (message) => { + const params = { jobId: jobId, failureDetails: { message: JSON.stringify(message), @@ -44,7 +44,7 @@ exports.handler = function (event, context) { externalExecutionId: context.invokeid, }, }; - codepipeline.putJobFailureResult(params, function (err, data) { + codepipeline.putJobFailureResult(params, (err, data) => { context.fail(message); }); }; @@ -59,8 +59,8 @@ exports.handler = function (event, context) { // Helper function to make a HTTP GET request to the page. // The helper will test the response and succeed or fail the job accordingly - var getPage = function (url, callback) { - var pageObject = { + const getPage = (url, callback) => { + const pageObject = { body: "", statusCode: 0, contains: function (search) { @@ -68,27 +68,27 @@ exports.handler = function (event, context) { }, }; http - .get(url, function (response) { + .get(url, (response) => { pageObject.body = ""; pageObject.statusCode = response.statusCode; - response.on("data", function (chunk) { + response.on("data", (chunk) => { pageObject.body += chunk; }); - response.on("end", function () { + response.on("end", () => { callback(pageObject); }); response.resume(); }) - .on("error", function (error) { + .on("error", (error) => { // Fail the job if our request failed putJobFailure(error); }); }; - getPage(url, function (returnedPage) { + getPage(url, (returnedPage) => { try { // Check if the HTTP response has a 200 status assert(returnedPage.statusCode === 200); diff --git a/javascriptv3/example_code/cognito-identity-provider/hello.js b/javascriptv3/example_code/cognito-identity-provider/hello.js index f355e8297c5..684957e22ae 100644 --- a/javascriptv3/example_code/cognito-identity-provider/hello.js +++ b/javascriptv3/example_code/cognito-identity-provider/hello.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.cognito.hello] import { diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/clean-up-handler.js b/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/clean-up-handler.js index d108e2be0b9..3190ae364d8 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/clean-up-handler.js +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/clean-up-handler.js @@ -35,7 +35,7 @@ const cleanUpHandler = async () => { if (userPoolIds[0].length > 0) { log(`Deleting user pools: \n${createUserPoolList(userPoolIds)}`); await cleanUpUserPools(userPoolIds); - log(`User pools deleted.`); + log("User pools deleted."); } log("Removing temporary files."); diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/confirm-sign-up-handler.js b/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/confirm-sign-up-handler.js index 4bf4d7c0f9a..0d910b5fd10 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/confirm-sign-up-handler.js +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/confirm-sign-up-handler.js @@ -43,7 +43,7 @@ const confirmSignUpHandler = async (commands) => { const values = getSecondValuesFromEntries(FILE_USER_POOLS); const clientId = values[0]; validateClient(clientId); - log(`Confirming user.`); + log("Confirming user."); await confirmSignUp({ clientId, username, code }); log( `User confirmed. Run 'admin-initiate-auth ${username} ' to sign in.`, diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/create-user-pool-handler.js b/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/create-user-pool-handler.js index eba842bada1..93cd6a073d1 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/create-user-pool-handler.js +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/create-user-pool-handler.js @@ -41,7 +41,7 @@ const createUserPoolHandler = async (commands) => { const { UserPool: { Id }, } = await createUserPool(poolName); - log(`User pool created.`); + log("User pool created."); log("Configuring user pool to only allow MFA via an authenticator app."); await setUserPoolMfaConfig(Id); @@ -51,7 +51,7 @@ const createUserPoolHandler = async (commands) => { const { UserPoolClient: { ClientId }, } = await createUserPoolClient(NAME_CLIENT, Id); - log(`Client created.`); + log("Client created."); storeUserPoolMeta(Id, ClientId, poolName); } catch (err) { diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/sign-up-handler.js b/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/sign-up-handler.js index 35d661c283e..9e94964ecaa 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/sign-up-handler.js +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/command-handlers/sign-up-handler.js @@ -34,7 +34,7 @@ const signUpHandler = async (commands) => { const values = getSecondValuesFromEntries(FILE_USER_POOLS); const clientId = values[0]; validateClient(clientId); - log(`Signing up.`); + log("Signing up."); await signUp({ clientId, username, password, email }); log(`Signed up. A confirmation email has been sent to: ${email}.`); log(`Run 'confirm-sign-up ${username} ' to confirm your account.`); diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/index.js b/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/index.js index 63e97682ac7..9320c34366c 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/index.js +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/basic/index.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { createInterface } from "readline"; -import { stdin as input, stdout as output } from "process"; +import { createInterface } from "node:readline"; +import { stdin as input, stdout as output } from "node:process"; import { readCommands } from "@aws-doc-sdk-examples/lib/cmd-runner.js"; import { log } from "@aws-doc-sdk-examples/lib/utils/util-log.js"; diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/App.css b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/App.css index b8a9bfcec82..e9665ae87ee 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/App.css +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/App.css @@ -6,7 +6,7 @@ } .loginForm { - min-width: 18em + min-width: 18em; } .smallButton { @@ -15,9 +15,9 @@ .inputText { font-size: 1.3em; - width: 100% + width: 100%; } button { margin: 0.5em; -} \ No newline at end of file +} diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/App.tsx b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/App.tsx index b3b3369dbf6..36948973fe6 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/App.tsx +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/App.tsx @@ -1,25 +1,39 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'; -import LoginPage from './loginPage'; -import HomePage from './homePage'; -import ConfirmUserPage from './confirmUserPage'; -import './App.css' +import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom"; +import LoginPage from "./loginPage"; +import HomePage from "./homePage"; +import ConfirmUserPage from "./confirmUserPage"; +import "./App.css"; const App = () => { const isAuthenticated = () => { - const accessToken = sessionStorage.getItem('accessToken'); + const accessToken = sessionStorage.getItem("accessToken"); return !!accessToken; }; return ( - : } /> + + ) : ( + + ) + } + /> } /> } /> - : } /> + : + } + /> ); diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/authService.ts b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/authService.ts index 985a5d089e4..17e7124a942 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/authService.ts +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/authService.ts @@ -1,7 +1,12 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { CognitoIdentityProviderClient, InitiateAuthCommand, SignUpCommand, ConfirmSignUpCommand } from "@aws-sdk/client-cognito-identity-provider"; +import { + CognitoIdentityProviderClient, + InitiateAuthCommand, + SignUpCommand, + ConfirmSignUpCommand, +} from "@aws-sdk/client-cognito-identity-provider"; import config from "./config.json"; export const cognitoClient = new CognitoIdentityProviderClient({ @@ -21,9 +26,15 @@ export const signIn = async (username: string, password: string) => { const command = new InitiateAuthCommand(params); const { AuthenticationResult } = await cognitoClient.send(command); if (AuthenticationResult) { - sessionStorage.setItem("idToken", AuthenticationResult.IdToken || ''); - sessionStorage.setItem("accessToken", AuthenticationResult.AccessToken || ''); - sessionStorage.setItem("refreshToken", AuthenticationResult.RefreshToken || ''); + sessionStorage.setItem("idToken", AuthenticationResult.IdToken || ""); + sessionStorage.setItem( + "accessToken", + AuthenticationResult.AccessToken || "", + ); + sessionStorage.setItem( + "refreshToken", + AuthenticationResult.RefreshToken || "", + ); return AuthenticationResult; } } catch (error) { diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/config.json b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/config.json index 1a0c8dd67ac..451cd692d51 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/config.json +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/config.json @@ -1,5 +1,5 @@ { - "region": "YOUR_AWS_REGION", - "userPoolId": "YOUR_COGNITO_USER_POOL_ID", - "clientId": "YOUR_COGNITO_APP_CLIENT_ID" -} \ No newline at end of file + "region": "YOUR_AWS_REGION", + "userPoolId": "YOUR_COGNITO_USER_POOL_ID", + "clientId": "YOUR_COGNITO_APP_CLIENT_ID" +} diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/confirmUserPage.tsx b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/confirmUserPage.tsx index 35d88eea75e..7613c08e5a5 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/confirmUserPage.tsx +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/confirmUserPage.tsx @@ -1,56 +1,57 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import React, { useState } from 'react'; -import { useLocation, useNavigate } from 'react-router-dom'; -import { confirmSignUp } from './authService'; +import type React from "react"; +import { useState } from "react"; +import { useLocation, useNavigate } from "react-router-dom"; +import { confirmSignUp } from "./authService"; const ConfirmUserPage = () => { const navigate = useNavigate(); const location = useLocation(); // eslint-disable-next-line - const [email, setEmail] = useState(location.state?.email || ''); - const [confirmationCode, setConfirmationCode] = useState(''); + const [email, setEmail] = useState(location.state?.email || ""); + const [confirmationCode, setConfirmationCode] = useState(""); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { await confirmSignUp(email, confirmationCode); alert("Account confirmed successfully!\nSign in on next page."); - navigate('/login'); + navigate("/login"); } catch (error) { alert(`Failed to confirm account: ${error}`); } }; -return ( -
-

Confirm Account

-
-
- setEmail(e.target.value)} - placeholder="Email" - required - /> -
-
- setConfirmationCode(e.target.value)} - placeholder="Confirmation Code" - required /> -
- -
-
-); - + return ( +
+

Confirm Account

+
+
+ setEmail(e.target.value)} + placeholder="Email" + required + /> +
+
+ setConfirmationCode(e.target.value)} + placeholder="Confirmation Code" + required + /> +
+ +
+
+ ); }; export default ConfirmUserPage; diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/homePage.tsx b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/homePage.tsx index f80f72cb72c..2db3101d42b 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/homePage.tsx +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/homePage.tsx @@ -1,42 +1,54 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { useNavigate } from 'react-router-dom'; +import { useNavigate } from "react-router-dom"; /*eslint-disable*/ -function parseJwt (token) { - var base64Url = token.split('.')[1]; - var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); - var jsonPayload = decodeURIComponent(window.atob(base64).split('').map(function(c) { - return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); - }).join('')); - return JSON.parse(jsonPayload); +function parseJwt(token) { + const base64Url = token.split(".")[1]; + const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/"); + const jsonPayload = decodeURIComponent( + window + .atob(base64) + .split("") + .map((c) => `%${(`00${c.charCodeAt(0).toString(16)}`).slice(-2)}`) + .join(""), + ); + return JSON.parse(jsonPayload); } const HomePage = () => { const navigate = useNavigate(); - var idToken = parseJwt(sessionStorage.idToken.toString()); - var accessToken = parseJwt(sessionStorage.accessToken.toString()); - console.log ("Amazon Cognito ID token encoded: " + sessionStorage.idToken.toString()); - console.log ("Amazon Cognito ID token decoded: "); - console.log ( idToken ); - console.log ("Amazon Cognito access token encoded: " + sessionStorage.accessToken.toString()); - console.log ("Amazon Cognito access token decoded: "); - console.log ( accessToken ); - console.log ("Amazon Cognito refresh token: "); - console.log ( sessionStorage.refreshToken ); - console.log ("Amazon Cognito example application. Not for use in production applications."); + const idToken = parseJwt(sessionStorage.idToken.toString()); + const accessToken = parseJwt(sessionStorage.accessToken.toString()); + console.log( + `Amazon Cognito ID token encoded: ${sessionStorage.idToken.toString()}`, + ); + console.log("Amazon Cognito ID token decoded: "); + console.log(idToken); + console.log( + `Amazon Cognito access token encoded: ${sessionStorage.accessToken.toString()}`, + ); + console.log("Amazon Cognito access token decoded: "); + console.log(accessToken); + console.log("Amazon Cognito refresh token: "); + console.log(sessionStorage.refreshToken); + console.log( + "Amazon Cognito example application. Not for use in production applications.", + ); const handleLogout = () => { sessionStorage.clear(); - navigate('/login'); + navigate("/login"); }; -/*eslint-enable*/ + /*eslint-enable*/ return (

Hello World

See console log for Amazon Cognito user tokens.

- +
); }; diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/loginPage.tsx b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/loginPage.tsx index a698326fd0c..c2a8066deae 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/loginPage.tsx +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/loginPage.tsx @@ -1,46 +1,46 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { useState } from 'react'; -import { useNavigate } from 'react-router-dom'; -import { signIn, signUp } from './authService'; +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { signIn, signUp } from "./authService"; const LoginPage = () => { - const [email, setEmail] = useState(''); - const [password, setPassword] = useState(''); - const [confirmPassword, setConfirmPassword] = useState(''); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [confirmPassword, setConfirmPassword] = useState(""); const [isSignUp, setIsSignUp] = useState(false); const navigate = useNavigate(); - const handleSignIn = async (e: { preventDefault: () => void; }) => { + const handleSignIn = async (e: { preventDefault: () => void }) => { e.preventDefault(); try { const session = await signIn(email, password); - console.log('Sign in successful', session); - if (session && typeof session.AccessToken !== 'undefined') { - sessionStorage.setItem('accessToken', session.AccessToken); - if (sessionStorage.getItem('accessToken')) { - window.location.href = '/home'; + console.log("Sign in successful", session); + if (session && typeof session.AccessToken !== "undefined") { + sessionStorage.setItem("accessToken", session.AccessToken); + if (sessionStorage.getItem("accessToken")) { + window.location.href = "/home"; } else { - console.error('Session token was not set properly.'); + console.error("Session token was not set properly."); } } else { - console.error('SignIn session or AccessToken is undefined.'); + console.error("SignIn session or AccessToken is undefined."); } } catch (error) { alert(`Sign in failed: ${error}`); } }; - const handleSignUp = async (e: { preventDefault: () => void; }) => { + const handleSignUp = async (e: { preventDefault: () => void }) => { e.preventDefault(); if (password !== confirmPassword) { - alert('Passwords do not match'); + alert("Passwords do not match"); return; } try { await signUp(email, password); - navigate('/confirm', { state: { email } }); + navigate("/confirm", { state: { email } }); } catch (error) { alert(`Sign up failed: ${error}`); } @@ -49,7 +49,9 @@ const LoginPage = () => { return (

Welcome

-

{isSignUp ? 'Sign up to create an account' : 'Sign in to your account'}

+

+ {isSignUp ? "Sign up to create an account" : "Sign in to your account"} +

{ />
)} - +
-
); diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/main.tsx b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/main.tsx index c9ab7adb55d..cc46dd3f67e 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/main.tsx +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/src/main.tsx @@ -1,13 +1,19 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import React from 'react' -import ReactDOM from 'react-dom/client' -import App from './App.tsx' -import './index.css' +import React from "react"; +import ReactDOM from "react-dom/client"; +import App from "./App.tsx"; +import "./index.css"; -ReactDOM.createRoot(document.getElementById('root')!).render( - - - , -) \ No newline at end of file +const el = document.getElementById("root"); + +if (el) { + ReactDOM.createRoot(el).render( + + + , + ); +} else { + throw new Error("Could not find root element."); +} diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/tsconfig.json b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/tsconfig.json index 4c3913b5a6c..30bb891855a 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/tsconfig.json +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/tsconfig.json @@ -13,7 +13,7 @@ "esModuleInterop": true, "isolatedModules": true, "noEmit": true, - "jsx": "react-jsx", + "jsx": "react-jsx" }, "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/vite.config.ts b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/vite.config.ts index 2eadebed493..f326f988847 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/vite.config.ts +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/cognito-developer-guide-react-example/frontend-client/vite.config.ts @@ -1,10 +1,10 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], -}) +}); diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/auth-challenge-create.mjs b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/auth-challenge-create.mjs index 1d817c63f00..1b9f2045e51 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/auth-challenge-create.mjs +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/auth-challenge-create.mjs @@ -32,5 +32,5 @@ const handler = async (event) => { return event; }; -export { handler } +export { handler }; // snippet-end:[javascript.v3.cognito.scenarios.lambda-triggers.CreateAuthChallenge] diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/auth-challenge-define.mjs b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/auth-challenge-define.mjs index e8f6ed710de..33041619bbc 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/auth-challenge-define.mjs +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/auth-challenge-define.mjs @@ -11,32 +11,32 @@ Guidance on implementing this example is in the 'Amplify Docs' at https://docs.a // snippet-start:[javascript.v3.cognito.scenarios.lambda-triggers.DefineAuthChallenge] const handler = async (event) => { if ( - event.request.session.length == 1 && - event.request.session[0].challengeName == "SRP_A" + event.request.session.length === 1 && + event.request.session[0].challengeName === "SRP_A" ) { event.response.issueTokens = false; event.response.failAuthentication = false; event.response.challengeName = "PASSWORD_VERIFIER"; } else if ( - event.request.session.length == 2 && - event.request.session[1].challengeName == "PASSWORD_VERIFIER" && - event.request.session[1].challengeResult == true + event.request.session.length === 2 && + event.request.session[1].challengeName === "PASSWORD_VERIFIER" && + event.request.session[1].challengeResult === true ) { event.response.issueTokens = false; event.response.failAuthentication = false; event.response.challengeName = "CUSTOM_CHALLENGE"; } else if ( - event.request.session.length == 3 && - event.request.session[2].challengeName == "CUSTOM_CHALLENGE" && - event.request.session[2].challengeResult == true + event.request.session.length === 3 && + event.request.session[2].challengeName === "CUSTOM_CHALLENGE" && + event.request.session[2].challengeResult === true ) { event.response.issueTokens = false; event.response.failAuthentication = false; event.response.challengeName = "CUSTOM_CHALLENGE"; } else if ( - event.request.session.length == 4 && - event.request.session[3].challengeName == "CUSTOM_CHALLENGE" && - event.request.session[3].challengeResult == true + event.request.session.length === 4 && + event.request.session[3].challengeName === "CUSTOM_CHALLENGE" && + event.request.session[3].challengeResult === true ) { event.response.issueTokens = true; event.response.failAuthentication = false; @@ -48,5 +48,5 @@ const handler = async (event) => { return event; }; -export { handler } +export { handler }; // snippet-end:[javascript.v3.cognito.scenarios.lambda-triggers.DefineAuthChallenge] diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/auth-challenge-verify.mjs b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/auth-challenge-verify.mjs index 632038d6050..a45f2b5be47 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/auth-challenge-verify.mjs +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/auth-challenge-verify.mjs @@ -11,7 +11,7 @@ Guidance on implementing this example is in the 'Amplify Docs' at https://docs.a // snippet-start:[javascript.v3.cognito.scenarios.lambda-triggers.VerifyAuthChallenge] const handler = async (event) => { if ( - event.request.privateChallengeParameters.answer == + event.request.privateChallengeParameters.answer === event.request.challengeAnswer ) { event.response.answerCorrect = true; diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/authentication-post.mjs b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/authentication-post.mjs index a28bfe0baf0..71dba8e2756 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/authentication-post.mjs +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/authentication-post.mjs @@ -18,5 +18,5 @@ const handler = async (event) => { return event; }; -export { handler } +export { handler }; // snippet-end:[javascript.v3.cognito.scenarios.lambda-triggers.PostAuthentication] diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/confirmation-post.mjs b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/confirmation-post.mjs index 98ce79e7ac9..6464557fb31 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/confirmation-post.mjs +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/confirmation-post.mjs @@ -17,7 +17,7 @@ const handler = async (event) => { if (event.request.userAttributes.email) { await sendTheEmail( event.request.userAttributes.email, - `Congratulations ${event.userName}, you have been confirmed.` + `Congratulations ${event.userName}, you have been confirmed.`, ); } return event; diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/custom-message-admin-create.mjs b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/custom-message-admin-create.mjs index 4722d98f918..8ebd114f8c1 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/custom-message-admin-create.mjs +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/custom-message-admin-create.mjs @@ -17,5 +17,5 @@ const handler = async (event) => { return event; }; -export { handler } +export { handler }; // snippet-end:[javascript.v3.cognito.scenarios.lambda-triggers.CustomMessageAdminCreate] diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/migrate-user.mjs b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/migrate-user.mjs index a1a6c12058f..942005ecff3 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/migrate-user.mjs +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/migrate-user.mjs @@ -15,9 +15,8 @@ const validUsers = { const authenticateUser = (username, password) => { if (validUsers[username] && validUsers[username].password === password) { return validUsers[username]; - } else { - return null; } + return null; }; const lookupUser = (username) => { @@ -25,13 +24,12 @@ const lookupUser = (username) => { if (user) { return { emailAddress: user.emailAddress }; - } else { - return null; } + return null; }; const handler = async (event) => { - if (event.triggerSource == "UserMigration_Authentication") { + if (event.triggerSource === "UserMigration_Authentication") { // Authenticate the user with your existing user directory service const user = authenticateUser(event.userName, event.request.password); if (user) { @@ -42,7 +40,7 @@ const handler = async (event) => { event.response.finalUserStatus = "CONFIRMED"; event.response.messageAction = "SUPPRESS"; } - } else if (event.triggerSource == "UserMigration_ForgotPassword") { + } else if (event.triggerSource === "UserMigration_ForgotPassword") { // Look up the user in your existing user directory service const user = lookupUser(event.userName); if (user) { diff --git a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/sign-up-pre-auto-confirm-verify.mjs b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/sign-up-pre-auto-confirm-verify.mjs index 905aa97e22a..4af74d5178d 100644 --- a/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/sign-up-pre-auto-confirm-verify.mjs +++ b/javascriptv3/example_code/cognito-identity-provider/scenarios/lambda-triggers/functions/sign-up-pre-auto-confirm-verify.mjs @@ -11,12 +11,12 @@ const handler = async (event) => { // Confirm the user event.response.autoConfirmUser = true; // Set the email as verified if it is in the request - if (event.request.userAttributes.hasOwnProperty("email")) { + if (Object.hasOwn(event.request.userAttributes, "email")) { event.response.autoVerifyEmail = true; } // Set the phone number as verified if it is in the request - if (event.request.userAttributes.hasOwnProperty("phone_number")) { + if (Object.hasOwn(event.request.userAttributes, "phone_number")) { event.response.autoVerifyPhone = true; } diff --git a/javascriptv3/example_code/cognito-identity-provider/tests/confirmation-post.unit.test.js b/javascriptv3/example_code/cognito-identity-provider/tests/confirmation-post.unit.test.js index 95d234a5093..45073000a6d 100644 --- a/javascriptv3/example_code/cognito-identity-provider/tests/confirmation-post.unit.test.js +++ b/javascriptv3/example_code/cognito-identity-provider/tests/confirmation-post.unit.test.js @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { describe, it, expect, vi, beforeAll } from "vitest"; -let mockSendFn = vi.fn(async () => {}); +const mockSendFn = vi.fn(async () => {}); vi.mock("@aws-sdk/client-ses", () => { return { diff --git a/javascriptv3/example_code/cognito-identity-provider/tests/custom-message-admin-create.unit.test.js b/javascriptv3/example_code/cognito-identity-provider/tests/custom-message-admin-create.unit.test.js index f58844c5c1f..f52e1859ae3 100644 --- a/javascriptv3/example_code/cognito-identity-provider/tests/custom-message-admin-create.unit.test.js +++ b/javascriptv3/example_code/cognito-identity-provider/tests/custom-message-admin-create.unit.test.js @@ -21,7 +21,8 @@ describe("custom-message-admin-create", () => { expect(result).toEqual( expect.objectContaining({ response: expect.objectContaining({ - emailMessage: `Welcome to the service. Your user name is Peccy. Your temporary password is 123`, + emailMessage: + "Welcome to the service. Your user name is Peccy. Your temporary password is 123", }), }), ); diff --git a/javascriptv3/example_code/cognito-identity-provider/tests/custom-message-sign-up.unit.test.js b/javascriptv3/example_code/cognito-identity-provider/tests/custom-message-sign-up.unit.test.js index b8a7692b89d..c08eeec3ae8 100644 --- a/javascriptv3/example_code/cognito-identity-provider/tests/custom-message-sign-up.unit.test.js +++ b/javascriptv3/example_code/cognito-identity-provider/tests/custom-message-sign-up.unit.test.js @@ -21,7 +21,8 @@ describe("custom-message-sign-up", () => { expect(result).toEqual( expect.objectContaining({ response: expect.objectContaining({ - emailMessage: `Thank you for signing up. Your confirmation code is 123.`, + emailMessage: + "Thank you for signing up. Your confirmation code is 123.", }), }), ); diff --git a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/get-items-handler.ts b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/get-items-handler.ts index 9336200494e..c55208ddb7f 100644 --- a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/get-items-handler.ts +++ b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/get-items-handler.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 /* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */ -import { Handler } from "src/types/handler.js"; +import type { Handler } from "src/types/handler.js"; import { command as getAllItemsCommand } from "../statement-commands/get-all-items.js"; import { command as getArchivedItemsCommand } from "../statement-commands/get-archived-items.js"; import { command as getActiveItemsCommand } from "../statement-commands/get-active-items.js"; diff --git a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/parse-item.ts b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/parse-item.ts index 197233e102b..e39f954cb55 100644 --- a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/parse-item.ts +++ b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/parse-item.ts @@ -1,6 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { Item } from "../types/item.js"; +import type { Item } from "../types/item.js"; const parseItem = (record: DBRecord): Item => { return { diff --git a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/post-items-handler.ts b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/post-items-handler.ts index 31a062096a5..4aa93a5ecdd 100644 --- a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/post-items-handler.ts +++ b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/post-items-handler.ts @@ -3,8 +3,8 @@ /* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */ import { v4 as uuidv4 } from "uuid"; -import { Handler } from "src/types/handler.js"; -import { Item } from "src/types/item.js"; +import type { Handler } from "src/types/handler.js"; +import type { Item } from "src/types/item.js"; import { buildStatementCommand } from "../statement-commands/command-helper.js"; const postItemsHandler: Handler = { @@ -13,8 +13,7 @@ const postItemsHandler: Handler = { async (req, res) => { const { description, guide, status, name }: Item = req.body; const command = buildStatementCommand( - "insert into items (iditem, description, guide, status, username, archived)\n" + - `values ("${uuidv4()}", "${description}", "${guide}", "${status}", "${name}", 0)`, + `insert into items (iditem, description, guide, status, username, archived)\nvalues ("${uuidv4()}", "${description}", "${guide}", "${status}", "${name}", 0)`, ); await rdsDataClient.send(command); diff --git a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/post-items-report-handler.ts b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/post-items-report-handler.ts index d16aa15faac..a9727d07cc9 100644 --- a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/post-items-report-handler.ts +++ b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/post-items-report-handler.ts @@ -3,9 +3,9 @@ /* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */ import { SendRawEmailCommand } from "@aws-sdk/client-ses"; -import { createMimeMessage, TextFormat } from "mimetext"; +import { createMimeMessage, type TextFormat } from "mimetext"; import { format } from "prettier"; -import { Handler } from "src/types/handler.js"; +import type { Handler } from "src/types/handler.js"; import { command as getActiveItemsCommand } from "../statement-commands/get-active-items.js"; const makeCsv = (records: DBRecords) => { diff --git a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/put-items-archive-handler.ts b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/put-items-archive-handler.ts index 206b4fbd776..37a8ce58282 100644 --- a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/put-items-archive-handler.ts +++ b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/handlers/put-items-archive-handler.ts @@ -12,7 +12,7 @@ const putItemsArchiveHandler: Handler = { const { itemId } = req.params; const command = buildStatementCommand( - "update items\n" + "set archived = 1\n" + `where iditem = "${itemId}"`, + `update items\nset archived = 1\nwhere iditem = "${itemId}"`, ); await rdsDataClient.send(command); diff --git a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/middleware/validate-db.ts b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/middleware/validate-db.ts index 5054d4ce345..61319b45c86 100644 --- a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/middleware/validate-db.ts +++ b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/middleware/validate-db.ts @@ -2,10 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 /* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */ -import { RequestHandler } from "express"; +import type { RequestHandler } from "express"; import { command as createTableCommand } from "../statement-commands/create-table.js"; import { command as getAllItemsCommand } from "../statement-commands/get-all-items.js"; -import { Handler } from "src/types/handler.js"; +import type { Handler } from "src/types/handler.js"; const errorCodes = { TABLE_NOT_FOUND: "Error code: 1146", diff --git a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/types/handler.d.ts b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/types/handler.d.ts index 15912c193bb..7bcf2ddc365 100644 --- a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/types/handler.d.ts +++ b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/types/handler.d.ts @@ -1,6 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { RequestHandler } from "express"; +import type { RequestHandler } from "express"; declare type Handler = { withClient: ({ diff --git a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/types/sendable.d.ts b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/types/sendable.d.ts index 052afcfd867..3fe0d16c6d2 100644 --- a/javascriptv3/example_code/cross-services/aurora-serverless-app/src/types/sendable.d.ts +++ b/javascriptv3/example_code/cross-services/aurora-serverless-app/src/types/sendable.d.ts @@ -1,7 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */ declare interface Sendable { - send: (command: any) => Promise; + send: (command: unknown) => Promise; } diff --git a/javascriptv3/example_code/cross-services/aurora-serverless-app/tests/get-items-handler.unit.test.ts b/javascriptv3/example_code/cross-services/aurora-serverless-app/tests/get-items-handler.unit.test.ts index dc847d7037a..102f193e822 100644 --- a/javascriptv3/example_code/cross-services/aurora-serverless-app/tests/get-items-handler.unit.test.ts +++ b/javascriptv3/example_code/cross-services/aurora-serverless-app/tests/get-items-handler.unit.test.ts @@ -1,28 +1,25 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { describe, it, vi, expect } from "vitest"; -import { NextFunction, Request, Response } from "express"; -import QueryString from "qs"; +import type { NextFunction, Request, Response } from "express"; +import type QueryString from "qs"; import { getItemsHandler } from "../src/handlers/get-items-handler.js"; describe("getItemsHandler", () => { - it( - "should create a request handler that sends a response " + - "with the result of the call to the SDK client", - async () => { - // eslint-disable-next-line - const sendable = { send: async () => ({ records: [] }) as R }; - // eslint-disable-next-line - const handler = getItemsHandler.withClient({ rdsDataClient: sendable }); - const send: unknown = vi.fn(); + it("should create a request handler that sends a response " + + "with the result of the call to the SDK client", async () => { + // eslint-disable-next-line + const sendable = { send: async () => ({ records: [] }) as R }; + // eslint-disable-next-line + const handler = getItemsHandler.withClient({ rdsDataClient: sendable }); + const send: unknown = vi.fn(); - await handler( - { query: { archived: "false" } as QueryString.ParsedQs } as Request, - { send } as Response, - vi.fn() as unknown as NextFunction, - ); + await handler( + { query: { archived: "false" } as QueryString.ParsedQs } as Request, + { send } as Response, + vi.fn() as unknown as NextFunction, + ); - expect(send).toHaveBeenCalledWith([]); - }, - ); + expect(send).toHaveBeenCalledWith([]); + }); }); diff --git a/javascriptv3/example_code/cross-services/aurora-serverless-app/tests/post-items-report-handler.unit.test.ts b/javascriptv3/example_code/cross-services/aurora-serverless-app/tests/post-items-report-handler.unit.test.ts index bcfd9188645..f052848630c 100644 --- a/javascriptv3/example_code/cross-services/aurora-serverless-app/tests/post-items-report-handler.unit.test.ts +++ b/javascriptv3/example_code/cross-services/aurora-serverless-app/tests/post-items-report-handler.unit.test.ts @@ -31,9 +31,7 @@ describe("postItemsReportHandler", () => { it("should produce a valid csv with static headers from DBRecord content", () => { const result = makeCsv(records); expect(result).toBe( - "id,description,guide,status,name,archived" + - `\n${records[0][0].stringValue},${records[0][1].stringValue},${records[0][2].stringValue},${records[0][3].stringValue},${records[0][4].stringValue},${records[0][5].longValue}` + - `\n${records[1][0].stringValue},${records[1][1].stringValue},${records[1][2].stringValue},${records[1][3].stringValue},${records[1][4].stringValue},${records[1][5].longValue}`, + `id,description,guide,status,name,archived\n${records[0][0].stringValue},${records[0][1].stringValue},${records[0][2].stringValue},${records[0][3].stringValue},${records[0][4].stringValue},${records[0][5].longValue}\n${records[1][0].stringValue},${records[1][1].stringValue},${records[1][2].stringValue},${records[1][3].stringValue},${records[1][4].stringValue},${records[1][5].longValue}`, ); }); }); diff --git a/javascriptv3/example_code/cross-services/aurora-serverless-app/tests/validate-db.unit.test.ts b/javascriptv3/example_code/cross-services/aurora-serverless-app/tests/validate-db.unit.test.ts index c8e14aa2940..3b2f6b89a88 100644 --- a/javascriptv3/example_code/cross-services/aurora-serverless-app/tests/validate-db.unit.test.ts +++ b/javascriptv3/example_code/cross-services/aurora-serverless-app/tests/validate-db.unit.test.ts @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { describe, expect, it, vi } from "vitest"; -import { NextFunction, Request, Response } from "express"; +import type { NextFunction, Request, Response } from "express"; import { errorCodes, validateDb } from "../src/middleware/validate-db.js"; describe("validate-db", () => { diff --git a/javascriptv3/example_code/cross-services/lambda-api-gateway/src/mylamdbafunction.js b/javascriptv3/example_code/cross-services/lambda-api-gateway/src/mylamdbafunction.js index d45547335a3..3f27c548178 100644 --- a/javascriptv3/example_code/cross-services/lambda-api-gateway/src/mylamdbafunction.js +++ b/javascriptv3/example_code/cross-services/lambda-api-gateway/src/mylamdbafunction.js @@ -19,7 +19,6 @@ Inputs (replace in code): */ // snippet-start:[lambda.JavaScript.general-examples-dynamodb-lambda.scanAndPublishV3] // snippet-start:[lambda.JavaScript.general-examples-dynamodb-lambda.scanAndPublishV3.config] -"use strict"; const { ScanCommand } = require("@aws-sdk/client-dynamodb"); const { PublishCommand } = require("@aws-sdk/client-sns"); const { snsClient } = require("./libs/snsClient"); @@ -30,7 +29,7 @@ const today = new Date(); const dd = String(today.getDate()).padStart(2, "0"); const mm = String(today.getMonth() + 1).padStart(2, "0"); //January is 0! const yyyy = today.getFullYear(); -const date = yyyy + "-" + mm + "-" + dd; +const date = `${yyyy}-${mm}-${dd}`; // Set the parameters for the ScanCommand method. const params = { @@ -60,17 +59,14 @@ exports.handler = async () => { try { // Scan the table to identify employees with work anniversary today. const data = await dynamoClient.send(new ScanCommand(params)); - data.Items.forEach(function (element) { + for (const element of data.Items) { const textParams = { PhoneNumber: element.phone.N, - Message: - "Hi " + - element.firstName.S + - "; congratulations on your work anniversary!", + Message: `Hi ${element.firstName.S}; congratulations on your work anniversary!`, }; // Send message using Amazon SNS. sendText(textParams); - }); + } } catch (err) { console.log("Error, could not scan table ", err); } diff --git a/javascriptv3/example_code/cross-services/lambda-scheduled-events/src/mylamdbafunction.js b/javascriptv3/example_code/cross-services/lambda-scheduled-events/src/mylamdbafunction.js index 179dd342162..4773597e768 100644 --- a/javascriptv3/example_code/cross-services/lambda-scheduled-events/src/mylamdbafunction.js +++ b/javascriptv3/example_code/cross-services/lambda-scheduled-events/src/mylamdbafunction.js @@ -19,8 +19,6 @@ Inputs (replace in code): */ // snippet-start:[lambda.JavaScript.cross-service-examples.lambda-scheduled-events.scanAndPublishV3] // snippet-start:[lambda.JavaScript.cross-service-examples.lambda-scheduled-events.config] - -"use strict"; const { ScanCommand } = require("@aws-sdk/client-dynamodb"); const { PublishCommand } = require("@aws-sdk/client-sns"); const { snsClient } = require("./libs/snsClient"); @@ -31,7 +29,7 @@ const today = new Date(); const dd = String(today.getDate()).padStart(2, "0"); const mm = String(today.getMonth() + 1).padStart(2, "0"); //January is 0! const yyyy = today.getFullYear(); -const date = yyyy + "-" + mm + "-" + dd; +const date = `${yyyy}-${mm}-${dd}`; // Set the parameters for the ScanCommand method. const params = { @@ -61,17 +59,14 @@ exports.handler = async () => { try { // Scan the table to identify employees with work anniversary today. const data = await dynamoClient.send(new ScanCommand(params)); - data.Items.forEach(function (element) { + for (const element of data.Items) { const textParams = { PhoneNumber: element.phone.N, - Message: - "Hi " + - element.firstName.S + - "; congratulations on your work anniversary!", + Message: `Hi ${element.firstName.S}; congratulations on your work anniversary!`, }; // Send message using Amazon SNS. sendText(textParams); - }); + } } catch (err) { console.log("Error, could not scan table ", err); } diff --git a/javascriptv3/example_code/cross-services/lex-bot/src/index.js b/javascriptv3/example_code/cross-services/lex-bot/src/index.js index dfab7ca5d22..a290a4903bf 100644 --- a/javascriptv3/example_code/cross-services/lex-bot/src/index.js +++ b/javascriptv3/example_code/cross-services/lex-bot/src/index.js @@ -26,13 +26,13 @@ import { lexClient } from "./libs/lexClient.js"; import { translateClient } from "./libs/translateClient.js"; import { comprehendClient } from "./libs/comprehendClient.js"; -var g_text = ""; +let g_text = ""; // Set the focus to the input box. document.getElementById("wisdom").focus(); function showRequest() { - var conversationDiv = document.getElementById("conversation"); - var requestPara = document.createElement("P"); + const conversationDiv = document.getElementById("conversation"); + const requestPara = document.createElement("P"); requestPara.className = "userRequest"; requestPara.appendChild(document.createTextNode(g_text)); conversationDiv.appendChild(requestPara); @@ -40,11 +40,11 @@ function showRequest() { } function showResponse(lexResponse) { - var conversationDiv = document.getElementById("conversation"); - var responsePara = document.createElement("P"); + const conversationDiv = document.getElementById("conversation"); + const responsePara = document.createElement("P"); responsePara.className = "lexResponse"; - var lexTextResponse = lexResponse; + const lexTextResponse = lexResponse; responsePara.appendChild(document.createTextNode(lexTextResponse)); responsePara.appendChild(document.createElement("br")); @@ -54,18 +54,18 @@ function showResponse(lexResponse) { function handletext(text) { g_text = text; - var xhr = new XMLHttpRequest(); + const xhr = new XMLHttpRequest(); xhr.addEventListener("load", loadNewItems, false); xhr.open("POST", "../text", true); // A Spring MVC controller xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //necessary - xhr.send("text=" + text); + xhr.send(`text=${text}`); } function loadNewItems() { showRequest(); // Re-enable input. - var wisdomText = document.getElementById("wisdom"); + const wisdomText = document.getElementById("wisdom"); wisdomText.value = ""; wisdomText.locked = false; } @@ -73,10 +73,10 @@ function loadNewItems() { // Respond to user's input. const createResponse = async () => { // Confirm there is text to submit. - var wisdomText = document.getElementById("wisdom"); - if (wisdomText && wisdomText.value && wisdomText.value.trim().length > 0) { + const wisdomText = document.getElementById("wisdom"); + if (wisdomText?.value && wisdomText.value.trim().length > 0) { // Disable input to show it is being sent. - var wisdom = wisdomText.value.trim(); + const wisdom = wisdomText.value.trim(); wisdomText.value = "..."; wisdomText.locked = true; handletext(wisdom); @@ -111,7 +111,7 @@ const createResponse = async () => { try { const data = await lexClient.send(new PostTextCommand(lexParams)); console.log("Success. Response is: ", data.message); - var msg = data.message; + const msg = data.message; showResponse(msg); } catch (err) { console.log("Error responding to message. ", err); diff --git a/javascriptv3/example_code/cross-services/lex-bot/src/style.css b/javascriptv3/example_code/cross-services/lex-bot/src/style.css index 77c4bcf607b..9f10580d0fb 100644 --- a/javascriptv3/example_code/cross-services/lex-bot/src/style.css +++ b/javascriptv3/example_code/cross-services/lex-bot/src/style.css @@ -1,5 +1,5 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 +/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + SPDX-License-Identifier: Apache-2.0 */ /* ABOUT THIS NODE.JS EXAMPLE: This example works with the AWS SDK for JavaScript version 3 (v3), diff --git a/javascriptv3/example_code/cross-services/photo-asset-manager/src/functions/download.js b/javascriptv3/example_code/cross-services/photo-asset-manager/src/functions/download.js index 4b80c303bfe..7fab7f6a2bf 100644 --- a/javascriptv3/example_code/cross-services/photo-asset-manager/src/functions/download.js +++ b/javascriptv3/example_code/cross-services/photo-asset-manager/src/functions/download.js @@ -48,9 +48,11 @@ export const getImageKeysForLabels = async (labels) => { * @type {{ Images: string[]}[]} */ const labelsTableResponses = Responses[LABELS_TABLE_NAME]; - labelsTableResponses.forEach((response) => { - response.Images.forEach((image) => uniqueImageKeys.add(image)); - }); + for (const response of labelsTableResponses) { + for (const image of response.Images) { + uniqueImageKeys.add(image); + } + } return Array.from(uniqueImageKeys); }; @@ -118,10 +120,7 @@ const zipAndUpload = async (imageKeys) => { */ const publishMessage = async (url) => { const client = new SNSClient({}); - const message = - "Your images are ready for download at the following URL.\n" + - "Amazon SNS breaks up the long URL. Strip out the whitespace characters to get the correct link.\n" + - url; + const message = `Your images are ready for download at the following URL.\nAmazon SNS breaks up the long URL. Strip out the whitespace characters to get the correct link.\n${url}`; const command = new PublishCommand({ Message: message, TopicArn: NOTIFICATION_TOPIC, diff --git a/javascriptv3/example_code/cross-services/photo_analyzer/src/index.js b/javascriptv3/example_code/cross-services/photo_analyzer/src/index.js index 144072112a8..80f8166970c 100644 --- a/javascriptv3/example_code/cross-services/photo_analyzer/src/index.js +++ b/javascriptv3/example_code/cross-services/photo_analyzer/src/index.js @@ -16,10 +16,10 @@ import { SendEmailCommand, SESClient } from "@aws-sdk/client-ses"; import { outputNames } from "./constants.js"; -const email = process.env["VERIFIED_EMAIL_ADDRESS"]; -const region = process.env["REGION"]; +const email = process.env.VERIFIED_EMAIL_ADDRESS; +const region = process.env.REGION; /** @type {Record } */ -const outputs = JSON.parse(process.env["CFN_OUTPUTS"]); +const outputs = JSON.parse(process.env.CFN_OUTPUTS); const imagesBucketName = outputs[outputNames.IMAGES_BUCKET_OUTPUT]; const reportsBucketName = outputs[outputNames.REPORTS_BUCKET_OUTPUT]; @@ -159,7 +159,7 @@ window.processImages = async () => { * @param {{ headers: string[], rows: string[][], name: string }} */ const createCsv = async ({ headers, rows, name }) => { - let csv = `${headers.join(",")}\n${rows.map((row) => row.join(",")).join("\n")}`; + const csv = `${headers.join(",")}\n${rows.map((row) => row.join(",")).join("\n")}`; await uploadFile(csv, name); }; @@ -170,7 +170,7 @@ const uploadFile = async (csv, key) => { new PutObjectCommand({ Bucket: reportsBucketName, Body: csv, - Key: key + ".csv", + Key: `${key}.csv`, }), ); const region = await s3Client.config.region(); @@ -211,25 +211,16 @@ const sendEmail = async (key, linkToCSV) => { /* required */ Html: { Charset: "UTF-8", - Data: - "

Hello!

Please see the the analyzed video report for " + - key + - " here

", + Data: `

Hello!

Please see the the analyzed video report for ${key} here

`, }, Text: { Charset: "UTF-8", - Data: - "Hello,\\r\\n" + - "Please see the attached file for the analyzed video report at" + - linkToCSV + - "\n\n", + Data: `Hello,\\r\\nPlease see the attached file for the analyzed video report at${linkToCSV}\n\n`, }, }, Subject: { Charset: "UTF-8", - Data: key + " analyzed video report ready", + Data: `${key} analyzed video report ready`, }, }, Source: fromEmail, // SENDER_ADDRESS diff --git a/javascriptv3/example_code/cross-services/photo_analyzer/webpack.config.js b/javascriptv3/example_code/cross-services/photo_analyzer/webpack.config.js index af3836de4ec..9418889ace6 100644 --- a/javascriptv3/example_code/cross-services/photo_analyzer/webpack.config.js +++ b/javascriptv3/example_code/cross-services/photo_analyzer/webpack.config.js @@ -11,7 +11,7 @@ import { stackName } from "./src/constants.js"; const defaultRegion = "us-east-1"; const outputs = await getCfnOutputs( stackName, - process.env["REGION"] ?? defaultRegion, + process.env.REGION ?? defaultRegion, ); export default { diff --git a/javascriptv3/example_code/cross-services/submit-data-app/src/dynamoApp/add_data.js b/javascriptv3/example_code/cross-services/submit-data-app/src/dynamoApp/add_data.js index 8652eb76a51..b55b03fec5b 100644 --- a/javascriptv3/example_code/cross-services/submit-data-app/src/dynamoApp/add_data.js +++ b/javascriptv3/example_code/cross-services/submit-data-app/src/dynamoApp/add_data.js @@ -47,14 +47,14 @@ export const submitData = async () => { // Define the attributes and values of the item to be added. Adding ' + "" ' converts a value to // a string. Item: { - id: { N: id + "" }, - title: { S: title + "" }, - name: { S: name + "" }, - body: { S: body + "" }, + id: { N: `${id}` }, + title: { S: `${title}` }, + name: { S: `${name}` }, + body: { S: `${body}` }, }, }; // Check that all the fields are completed. - if (id != "" && title != "" && name != "" && body != "") { + if (id !== "" && title !== "" && name !== "" && body !== "") { try { //Upload the item to the table await dynamoClient.send(new PutItemCommand(params)); @@ -70,7 +70,7 @@ export const submitData = async () => { // Send the SNS message const data = await snsClient.send(new PublishCommand(messageParams)); console.log( - "Success, message published. MessageID is " + data.MessageId, + `Success, message published. MessageID is ${data.MessageId}`, ); } catch (err) { // Display error message if error is not sent diff --git a/javascriptv3/example_code/cross-services/textract-react/AddRemoveAssets.js b/javascriptv3/example_code/cross-services/textract-react/AddRemoveAssets.js index bf1c4840560..17e7132b3e1 100644 --- a/javascriptv3/example_code/cross-services/textract-react/AddRemoveAssets.js +++ b/javascriptv3/example_code/cross-services/textract-react/AddRemoveAssets.js @@ -28,7 +28,7 @@ * remove resources created for the demo. */ -import fs from "fs"; +import fs from "node:fs"; import { Config } from "./src/Config.js"; import { S3Client, @@ -71,10 +71,10 @@ if (mode === "add") { let configOutputs = ` StackName: '${stackName}',\n` + ` DefaultImageName: '${DefaultImageName}',\n`; - Stacks[0].Outputs.forEach((current) => { + for (const current of Stacks[0].Outputs) { configOutputs += ` ${current.OutputKey}: '${current.OutputValue}',\n`; Config[current.OutputKey] = current.OutputValue; - }); + } fs.writeFileSync( "src/Config.js", `export const Config = {\n${configOutputs}};`, @@ -122,7 +122,7 @@ if (mode === "add") { UserPoolId: Config.CognitoUserPoolId, }), ); - Users.forEach((user) => { + for (const user of Users) { console.log(`Deleting user ${user.Username}`); cogProvider.send( new AdminDeleteUserCommand({ @@ -130,7 +130,7 @@ if (mode === "add") { Username: user.Username, }), ); - }); + } } catch (error) { console.log(error.message); } @@ -159,7 +159,7 @@ if (mode === "add") { console.log(error.message); } - let configOutputs = ` ConfigError: '${ConfigError}'\n`; + const configOutputs = ` ConfigError: '${ConfigError}'\n`; fs.writeFileSync( "src/Config.js", `export const Config = {\n${configOutputs}};`, diff --git a/javascriptv3/example_code/cross-services/textract-react/package.json b/javascriptv3/example_code/cross-services/textract-react/package.json index b2a11520775..94e21d16ad5 100644 --- a/javascriptv3/example_code/cross-services/textract-react/package.json +++ b/javascriptv3/example_code/cross-services/textract-react/package.json @@ -23,11 +23,7 @@ "eject": "react-scripts eject" }, "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], + "production": [">0.2%", "not dead", "not op_mini all"], "development": [ "last 1 chrome version", "last 1 firefox version", diff --git a/javascriptv3/example_code/cross-services/textract-react/src/AwsFactory.js b/javascriptv3/example_code/cross-services/textract-react/src/AwsFactory.js index 404364a2432..b63908b5837 100644 --- a/javascriptv3/example_code/cross-services/textract-react/src/AwsFactory.js +++ b/javascriptv3/example_code/cross-services/textract-react/src/AwsFactory.js @@ -33,17 +33,17 @@ export const awsFactory = ({ }); const clients = {}; - clients["s3"] = new S3Client({ + clients.s3 = new S3Client({ region: deployRegion, credentials: creds, }); - clients["textract"] = new TextractClient({ + clients.textract = new TextractClient({ region: deployRegion, credentials: creds, }); - clients["sqs"] = new SQSClient({ + clients.sqs = new SQSClient({ region: deployRegion, credentials: creds, }); diff --git a/javascriptv3/example_code/cross-services/textract-react/src/ExplorerCard.js b/javascriptv3/example_code/cross-services/textract-react/src/ExplorerCard.js index 4e817f5ea8e..fbcdc1886ac 100644 --- a/javascriptv3/example_code/cross-services/textract-react/src/ExplorerCard.js +++ b/javascriptv3/example_code/cross-services/textract-react/src/ExplorerCard.js @@ -49,9 +49,9 @@ export const ExplorerCard = (props) => { props.extracting ? "" : "visually-hidden" }`} > -
+ Loading... -
+
{tree}
diff --git a/javascriptv3/example_code/cross-services/textract-react/src/ExplorerTree.js b/javascriptv3/example_code/cross-services/textract-react/src/ExplorerTree.js index ca0cf27d687..12bc48aa99a 100644 --- a/javascriptv3/example_code/cross-services/textract-react/src/ExplorerTree.js +++ b/javascriptv3/example_code/cross-services/textract-react/src/ExplorerTree.js @@ -64,7 +64,7 @@ const ExplorerNode = (props) => { * @returns {JSX.Element} */ const ExplorerList = (props) => { - let childNodes = props.Children + const childNodes = props.Children ? props.Children.filter((child) => { return FilterMap[props.extractType].includes(child.BlockType); }).map((child) => { @@ -102,7 +102,7 @@ export const ExplorerTree = (props) => { return (
{props.extraction.Name}
-
+
{ role="toolbar" aria-label="Toolbar with button groups" > -
+
{ -
-
+ +
{ -
-
+ +
-
+
); }; diff --git a/javascriptv3/example_code/cross-services/textract-react/src/ImageDisplay.js b/javascriptv3/example_code/cross-services/textract-react/src/ImageDisplay.js index c09111995c0..0903cd3da39 100644 --- a/javascriptv3/example_code/cross-services/textract-react/src/ImageDisplay.js +++ b/javascriptv3/example_code/cross-services/textract-react/src/ImageDisplay.js @@ -27,15 +27,15 @@ export const ImageDisplay = (props) => { if (img) { // Update the canvas position to match that of the image. canvas.style.position = "absolute"; - canvas.style.left = img.offsetLeft + "px"; - canvas.style.top = img.offsetTop + "px"; + canvas.style.left = `${img.offsetLeft}px`; + canvas.style.top = `${img.offsetTop}px`; canvas.width = img.offsetWidth; canvas.height = img.offsetHeight; // Polygon points are defined as fractions of the total height and width of // the image. const context = canvas.getContext("2d"); - props.shownPolygons.forEach((poly) => { + for (const poly of props.shownPolygons) { context.strokeStyle = ColorMap[poly.BlockType]; context.lineWidth = 2; const points = poly.Geometry.Polygon; @@ -44,14 +44,14 @@ export const ImageDisplay = (props) => { canvas.width * points[0].X, canvas.height * points[0].Y, ); - points - .slice(1) - .forEach((point) => - context.lineTo(canvas.width * point.X, canvas.height * point.Y), - ); + + for (const point of points.slice(1)) { + context.lineTo(canvas.width * point.X, canvas.height * point.Y); + } + context.closePath(); context.stroke(); - }); + } } }; @@ -64,7 +64,7 @@ export const ImageDisplay = (props) => {
Extraction source diff --git a/javascriptv3/example_code/cross-services/textract-react/src/ImageLoader.js b/javascriptv3/example_code/cross-services/textract-react/src/ImageLoader.js index cb68eeb0b43..d298a0eece4 100644 --- a/javascriptv3/example_code/cross-services/textract-react/src/ImageLoader.js +++ b/javascriptv3/example_code/cross-services/textract-react/src/ImageLoader.js @@ -58,14 +58,13 @@ export const ImageLoader = (props) => { Load
-
{props.modelError} -
+
diff --git a/javascriptv3/example_code/cross-services/textract-react/src/TextractModel.js b/javascriptv3/example_code/cross-services/textract-react/src/TextractModel.js index ba9c66d6b4e..961e329cd4a 100644 --- a/javascriptv3/example_code/cross-services/textract-react/src/TextractModel.js +++ b/javascriptv3/example_code/cross-services/textract-react/src/TextractModel.js @@ -75,7 +75,9 @@ export default class TextractModel { * Called when data changes to inform each subscriber of the change. */ inform() { - this.onChanges.forEach((sub) => sub()); + for (const sub of this.onChanges) { + sub(); + } } /** @@ -96,9 +98,7 @@ export default class TextractModel { return data; } - data += value.reduce(function (a, b) { - return a + String.fromCharCode(b); - }, ""); + data += value.reduce((a, b) => a + String.fromCharCode(b), ""); } } finally { reader.releaseLock(); @@ -164,7 +164,7 @@ export default class TextractModel { if (extractType === "text") { command = new DetectDocumentTextCommand(input); } else { - input["FeatureTypes"] = + input.FeatureTypes = extractType === "form" ? [FeatureType.FORMS] : [FeatureType.TABLES]; command = new AnalyzeDocumentCommand(input); } @@ -173,7 +173,7 @@ export default class TextractModel { this.extraction = { Name: this.imageData.objectKey, ExtractType: extractType, - Children: this._make_page_hierarchy(textractResponse["Blocks"]), + Children: this._make_page_hierarchy(textractResponse.Blocks), }; console.log(textractResponse); this.inform(); @@ -209,7 +209,7 @@ export default class TextractModel { if (extractType === "text") { command = new StartDocumentTextDetectionCommand(input); } else { - input["FeatureTypes"] = + input.FeatureTypes = extractType === "form" ? [FeatureType.FORMS] : [FeatureType.TABLES]; command = new StartDocumentAnalysisCommand(input); } @@ -296,16 +296,16 @@ export default class TextractModel { */ _add_children(block, block_dict) { const rels_list = block.Relationships || []; - rels_list.forEach((rels) => { + for (const rels of rels_list) { if (rels.Type === "CHILD") { - block["Children"] = []; - rels.Ids.forEach((relId) => { + block.Children = []; + for (const relId of rels.Ids) { const kid = block_dict[relId]; - block["Children"].push(kid); + block.Children.push(kid); this._add_children(kid, block_dict); - }); + } } - }); + } } /** @@ -317,15 +317,17 @@ export default class TextractModel { */ _make_page_hierarchy(blocks) { const block_dict = {}; - blocks.forEach((block) => (block_dict[block.Id] = block)); + for (const block of blocks) { + block_dict[block.Id] = block; + } const pages = []; - blocks.forEach((block) => { + for (const block of blocks) { if (block.BlockType === "PAGE") { pages.push(block); this._add_children(block, block_dict); } - }); + } return pages; } } diff --git a/javascriptv3/example_code/cross-services/textract-react/src/__test__/ExplorerTree.test.js b/javascriptv3/example_code/cross-services/textract-react/src/__test__/ExplorerTree.test.js index 6190def980e..bea95a639eb 100644 --- a/javascriptv3/example_code/cross-services/textract-react/src/__test__/ExplorerTree.test.js +++ b/javascriptv3/example_code/cross-services/textract-react/src/__test__/ExplorerTree.test.js @@ -34,7 +34,7 @@ describe("extraction props", () => { }); test("filter out text nodes when table type", () => { - let doc = {}; + const doc = {}; Object.assign(TestExtractDocument, doc); doc.ExtractType = "table"; render(); diff --git a/javascriptv3/example_code/cross-services/textract-react/src/__test__/TextractModel.test.js b/javascriptv3/example_code/cross-services/textract-react/src/__test__/TextractModel.test.js index e4e940fbdb1..419317f443b 100644 --- a/javascriptv3/example_code/cross-services/textract-react/src/__test__/TextractModel.test.js +++ b/javascriptv3/example_code/cross-services/textract-react/src/__test__/TextractModel.test.js @@ -141,83 +141,80 @@ describe("extractDocument", () => { expect(tm.modelError).toBe(testError); }); - test( - "asynchronous text type calls detect command, waits for sqs, returns " + - "expected document", - async () => { - const syncType = "async"; - const extractType = "text"; - const imageData = { - bucketName: "test-bucket", - objectKey: TestExtractDocument.Name, - }; - const snsTopicArn = "sns-topic-arn"; - const roleArn = "role-arn"; - const queueUrl = "queue-url"; - const jobId = "job-id"; - const textract = new TextractClient({}); - textract.send = jest - .fn() - .mockImplementationOnce((command) => { - expect(command).toBeInstanceOf(StartDocumentTextDetectionCommand); - expect(command.input).toEqual({ - DocumentLocation: { - S3Object: { - Bucket: imageData.bucketName, - Name: imageData.objectKey, - }, - }, - NotificationChannel: { - SNSTopicArn: snsTopicArn, - RoleArn: roleArn, + test("asynchronous text type calls detect command, waits for sqs, returns " + + "expected document", async () => { + const syncType = "async"; + const extractType = "text"; + const imageData = { + bucketName: "test-bucket", + objectKey: TestExtractDocument.Name, + }; + const snsTopicArn = "sns-topic-arn"; + const roleArn = "role-arn"; + const queueUrl = "queue-url"; + const jobId = "job-id"; + const textract = new TextractClient({}); + textract.send = jest + .fn() + .mockImplementationOnce((command) => { + expect(command).toBeInstanceOf(StartDocumentTextDetectionCommand); + expect(command.input).toEqual({ + DocumentLocation: { + S3Object: { + Bucket: imageData.bucketName, + Name: imageData.objectKey, }, - }); - return { JobId: jobId }; - }) - .mockImplementationOnce((command) => { - expect(command).toBeInstanceOf(GetDocumentTextDetectionCommand); - expect(command.input).toEqual({ JobId: jobId }); - return TestExtractResponse; + }, + NotificationChannel: { + SNSTopicArn: snsTopicArn, + RoleArn: roleArn, + }, }); - const sqs = new SQSClient({}); - sqs.send = jest - .fn() - .mockImplementationOnce((command) => { - expect(command).toBeInstanceOf(ReceiveMessageCommand); - expect(command.input).toEqual({ - QueueUrl: queueUrl, - MaxNumberOfMessages: 1, - }); - return { - Messages: [ - { - ReceiptHandle: "receipt-handle", - Body: JSON.stringify({ - Message: JSON.stringify({ Status: JobStatus.SUCCEEDED }), - }), - }, - ], - }; - }) - .mockImplementationOnce((command) => { - expect(command).toBeInstanceOf(DeleteMessageCommand); + return { JobId: jobId }; + }) + .mockImplementationOnce((command) => { + expect(command).toBeInstanceOf(GetDocumentTextDetectionCommand); + expect(command.input).toEqual({ JobId: jobId }); + return TestExtractResponse; + }); + const sqs = new SQSClient({}); + sqs.send = jest + .fn() + .mockImplementationOnce((command) => { + expect(command).toBeInstanceOf(ReceiveMessageCommand); + expect(command.input).toEqual({ + QueueUrl: queueUrl, + MaxNumberOfMessages: 1, }); - const tm = new TextractModel({ - textract: textract, - sqs: sqs, - snsTopicArn: snsTopicArn, - roleArn: roleArn, - queueUrl: queueUrl, + return { + Messages: [ + { + ReceiptHandle: "receipt-handle", + Body: JSON.stringify({ + Message: JSON.stringify({ Status: JobStatus.SUCCEEDED }), + }), + }, + ], + }; + }) + .mockImplementationOnce((command) => { + expect(command).toBeInstanceOf(DeleteMessageCommand); }); - tm.imageData = imageData; - tm.inform = jest.fn(); - await tm.extractDocument(syncType, extractType); - expect(textract.send).toHaveBeenCalled(); - expect(sqs.send).toHaveBeenCalledTimes(2); - expect(tm.extraction).toEqual(TestExtractDocument); - expect(tm.inform).toHaveBeenCalled(); - }, - ); + const tm = new TextractModel({ + textract: textract, + sqs: sqs, + snsTopicArn: snsTopicArn, + roleArn: roleArn, + queueUrl: queueUrl, + }); + tm.imageData = imageData; + tm.inform = jest.fn(); + await tm.extractDocument(syncType, extractType); + expect(textract.send).toHaveBeenCalled(); + expect(sqs.send).toHaveBeenCalledTimes(2); + expect(tm.extraction).toEqual(TestExtractDocument); + expect(tm.inform).toHaveBeenCalled(); + }); test("asynchronous form type calls analyze command", async () => { const syncType = "async"; diff --git a/javascriptv3/example_code/cross-services/textract-react/src/index.js b/javascriptv3/example_code/cross-services/textract-react/src/index.js index 1e5b554356d..1b7772da77d 100644 --- a/javascriptv3/example_code/cross-services/textract-react/src/index.js +++ b/javascriptv3/example_code/cross-services/textract-react/src/index.js @@ -39,6 +39,7 @@ const model = new TextractModel({ }); const render = () => + // biome-ignore lint/correctness/noRenderReturnValue: Only invalid in new react versions ReactDOM.render( diff --git a/javascriptv3/example_code/cross-services/transcribe-streaming-app/public/style.css b/javascriptv3/example_code/cross-services/transcribe-streaming-app/public/style.css index a82ee71272c..8e4ec54a714 100644 --- a/javascriptv3/example_code/cross-services/transcribe-streaming-app/public/style.css +++ b/javascriptv3/example_code/cross-services/transcribe-streaming-app/public/style.css @@ -63,7 +63,7 @@ #transcribedText, #translatedText { - width: 100%-20px; + width: 100% -20px; background-color: rgb(240, 240, 240); border: 1px solid darkgray; border-radius: 15px; diff --git a/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/index.js b/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/index.js index 74085fe9424..c227a89af34 100644 --- a/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/index.js +++ b/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/index.js @@ -44,7 +44,7 @@ const startRecording = async () => { const { startRecording } = await import("./libs/transcribeClient.js"); await startRecording(selectedLanguage, onTranscriptionDataReceived); } catch (error) { - alert("An error occurred while recording: " + error.message); + alert(`An error occurred while recording: ${error.message}`); await stopRecording(); } }; @@ -53,7 +53,7 @@ const onTranscriptionDataReceived = (data) => { transcribedText.insertAdjacentHTML("beforeend", data); }; -const stopRecording = async function () { +const stopRecording = async () => { inputLanguageList.disabled = false; recordButton.setAttribute("class", "recordInactive"); const { stopRecording } = await import("./libs/transcribeClient.js"); @@ -83,7 +83,7 @@ window.translateText = async () => { translatedText.innerHTML = translation; } } catch (error) { - alert("There was an error translating the text: " + error.message); + alert(`There was an error translating the text: ${error.message}`); } }; @@ -107,7 +107,7 @@ window.sendEmail = async () => { await sendEmail(sender, receiver, originalText, translation); alert("Success! Email sent!"); } catch (error) { - alert("There was an error sending the email: " + error); + alert(`There was an error sending the email: ${error}`); } }; // snippet-end:[transcribe.JavaScript.streaming.indexv3] diff --git a/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/libs/emailClient.js b/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/libs/emailClient.js index 5d7e5386aaa..5a62cb7f88e 100644 --- a/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/libs/emailClient.js +++ b/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/libs/emailClient.js @@ -41,27 +41,14 @@ const createSESClient = () => { const createHTMLBody = (originalText, translatedText) => { return { Charset: "UTF-8", - Data: - "

Hello!

Here is your Amazon Transcribe recording:

" + - "

Original

" + - "

" + - originalText + - "

" + - "

Translation (if available)

" + - "

" + - translatedText + - "

", + Data: `

Hello!

Here is your Amazon Transcribe recording:

Original

${originalText}

Translation (if available)

${translatedText}

`, }; }; const createTextBody = (originalText, translatedText) => { return { Charset: "UTF-8", - Data: - "Hello,\\r\\n" + - "Here is your Amazon Transcribe transcription:" + - "\n" + - translatedText, + Data: `Hello,\\r\\nHere is your Amazon Transcribe transcription:\n${translatedText}`, }; }; diff --git a/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/libs/transcribeClient.js b/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/libs/transcribeClient.js index 17ce31b745e..1d78269cd23 100644 --- a/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/libs/transcribeClient.js +++ b/javascriptv3/example_code/cross-services/transcribe-streaming-app/src/libs/transcribeClient.js @@ -38,7 +38,7 @@ export const startRecording = async (language, callback) => { await startStreaming(language, callback); }; -export const stopRecording = function () { +export const stopRecording = () => { if (microphoneStream) { microphoneStream.stop(); microphoneStream.destroy(); @@ -84,7 +84,7 @@ const startStreaming = async (language, callback) => { const noOfResults = result.Alternatives[0].Items.length; for (let i = 0; i < noOfResults; i++) { console.log(result.Alternatives[0].Items[i].Content); - callback(result.Alternatives[0].Items[i].Content + " "); + callback(`${result.Alternatives[0].Items[i].Content} `); } } } @@ -116,7 +116,7 @@ const encodePCMChunk = (chunk) => { const buffer = new ArrayBuffer(input.length * 2); const view = new DataView(buffer); for (let i = 0; i < input.length; i++, offset += 2) { - let s = Math.max(-1, Math.min(1, input[i])); + const s = Math.max(-1, Math.min(1, input[i])); view.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7fff, true); } return Buffer.from(buffer); diff --git a/javascriptv3/example_code/cross-services/transcribe-streaming-app/webpack.config.js b/javascriptv3/example_code/cross-services/transcribe-streaming-app/webpack.config.js index f838a364112..1a885fff93c 100644 --- a/javascriptv3/example_code/cross-services/transcribe-streaming-app/webpack.config.js +++ b/javascriptv3/example_code/cross-services/transcribe-streaming-app/webpack.config.js @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import webpack from "webpack"; -import path from "path"; +import path from "node:path"; import { dirnameFromMetaUrl } from "@aws-doc-sdk-examples/lib/utils/util-fs.js"; diff --git a/javascriptv3/example_code/cross-services/wkflw-resilient-service/constants.js b/javascriptv3/example_code/cross-services/wkflw-resilient-service/constants.js index 1663350fece..b07ac5393e9 100644 --- a/javascriptv3/example_code/cross-services/wkflw-resilient-service/constants.js +++ b/javascriptv3/example_code/cross-services/wkflw-resilient-service/constants.js @@ -181,7 +181,7 @@ export const PREFIX = "resilient-wkflw-"; export const NAMES = { autoScalingGroupName: `${PREFIX}auto-scaling-group`, - tableName: `doc-example-recommendation-service`, + tableName: "doc-example-recommendation-service", keyPairName: `${PREFIX}key-pair`, instancePolicyName: `${PREFIX}instance-policy`, instanceProfileName: `${PREFIX}instance-profile`, diff --git a/javascriptv3/example_code/cross-services/wkflw-resilient-service/index.js b/javascriptv3/example_code/cross-services/wkflw-resilient-service/index.js index 82dcf9261bf..ecf607db1ca 100755 --- a/javascriptv3/example_code/cross-services/wkflw-resilient-service/index.js +++ b/javascriptv3/example_code/cross-services/wkflw-resilient-service/index.js @@ -2,7 +2,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 - import { Scenario, parseScenarioArgs, @@ -40,7 +39,7 @@ export const scenarios = { }; // Call function if run directly -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { parseScenarioArgs(scenarios); diff --git a/javascriptv3/example_code/cross-services/wkflw-resilient-service/shared.js b/javascriptv3/example_code/cross-services/wkflw-resilient-service/shared.js index fa6f81822e2..f33b2f3ddcd 100644 --- a/javascriptv3/example_code/cross-services/wkflw-resilient-service/shared.js +++ b/javascriptv3/example_code/cross-services/wkflw-resilient-service/shared.js @@ -27,8 +27,7 @@ export async function findLoadBalancer(loadBalancerName) { } catch (e) { if (e.name === "LoadBalancerNotFoundException") { return undefined; - } else { - throw e; } + throw e; } } diff --git a/javascriptv3/example_code/cross-services/wkflw-resilient-service/steps-deploy.js b/javascriptv3/example_code/cross-services/wkflw-resilient-service/steps-deploy.js index bce679267cd..10092b3267b 100644 --- a/javascriptv3/example_code/cross-services/wkflw-resilient-service/steps-deploy.js +++ b/javascriptv3/example_code/cross-services/wkflw-resilient-service/steps-deploy.js @@ -552,9 +552,8 @@ export const deploySteps = [ "${IP_RULES}", JSON.stringify(state.myIpRules, null, 2), ); - } else { - return MESSAGES.noIpRules; } + return MESSAGES.noIpRules; }, ), new ScenarioInput( @@ -565,9 +564,8 @@ export const deploySteps = [ (state) => { if (state.myIpRules.length > 0) { return false; - } else { - return MESSAGES.noIpRules; } + return MESSAGES.noIpRules; }, { type: "confirm" }, ), @@ -596,9 +594,8 @@ export const deploySteps = [ new ScenarioOutput("addedInboundRule", (state) => { if (state.shouldAddInboundRule) { return MESSAGES.addedInboundRule.replace("${IP_ADDRESS}", state.myIp); - } else { - return false; } + return false; }), new ScenarioOutput("verifyingEndpoint", (state) => MESSAGES.verifyingEndpoint.replace("${DNS_NAME}", state.loadBalancerDns), diff --git a/javascriptv3/example_code/cross-services/wkflw-resilient-service/steps-destroy.js b/javascriptv3/example_code/cross-services/wkflw-resilient-service/steps-destroy.js index 0281a24bdf1..f5a4714dfb1 100644 --- a/javascriptv3/example_code/cross-services/wkflw-resilient-service/steps-destroy.js +++ b/javascriptv3/example_code/cross-services/wkflw-resilient-service/steps-destroy.js @@ -68,9 +68,8 @@ export const destroySteps = [ "${TABLE_NAME}", NAMES.tableName, ); - } else { - return MESSAGES.deletedTable.replace("${TABLE_NAME}", NAMES.tableName); } + return MESSAGES.deletedTable.replace("${TABLE_NAME}", NAMES.tableName); }), new ScenarioAction("deleteKeyPair", async (state) => { try { @@ -90,12 +89,11 @@ export const destroySteps = [ "${KEY_PAIR_NAME}", NAMES.keyPairName, ); - } else { - return MESSAGES.deletedKeyPair.replace( - "${KEY_PAIR_NAME}", - NAMES.keyPairName, - ); } + return MESSAGES.deletedKeyPair.replace( + "${KEY_PAIR_NAME}", + NAMES.keyPairName, + ); }), new ScenarioAction("detachPolicyFromRole", async (state) => { try { @@ -124,11 +122,10 @@ export const destroySteps = [ return MESSAGES.detachPolicyFromRoleError .replace("${INSTANCE_POLICY_NAME}", NAMES.instancePolicyName) .replace("${INSTANCE_ROLE_NAME}", NAMES.instanceRoleName); - } else { - return MESSAGES.detachedPolicyFromRole - .replace("${INSTANCE_POLICY_NAME}", NAMES.instancePolicyName) - .replace("${INSTANCE_ROLE_NAME}", NAMES.instanceRoleName); } + return MESSAGES.detachedPolicyFromRole + .replace("${INSTANCE_POLICY_NAME}", NAMES.instancePolicyName) + .replace("${INSTANCE_ROLE_NAME}", NAMES.instanceRoleName); }), new ScenarioAction("deleteInstancePolicy", async (state) => { const client = new IAMClient({}); @@ -153,12 +150,11 @@ export const destroySteps = [ "${INSTANCE_POLICY_NAME}", NAMES.instancePolicyName, ); - } else { - return MESSAGES.deletedPolicy.replace( - "${INSTANCE_POLICY_NAME}", - NAMES.instancePolicyName, - ); } + return MESSAGES.deletedPolicy.replace( + "${INSTANCE_POLICY_NAME}", + NAMES.instancePolicyName, + ); }), new ScenarioAction("removeRoleFromInstanceProfile", async (state) => { try { @@ -179,11 +175,10 @@ export const destroySteps = [ return MESSAGES.removeRoleFromInstanceProfileError .replace("${INSTANCE_PROFILE_NAME}", NAMES.instanceProfileName) .replace("${INSTANCE_ROLE_NAME}", NAMES.instanceRoleName); - } else { - return MESSAGES.removedRoleFromInstanceProfile - .replace("${INSTANCE_PROFILE_NAME}", NAMES.instanceProfileName) - .replace("${INSTANCE_ROLE_NAME}", NAMES.instanceRoleName); } + return MESSAGES.removedRoleFromInstanceProfile + .replace("${INSTANCE_PROFILE_NAME}", NAMES.instanceProfileName) + .replace("${INSTANCE_ROLE_NAME}", NAMES.instanceRoleName); }), new ScenarioAction("deleteInstanceRole", async (state) => { try { @@ -204,12 +199,11 @@ export const destroySteps = [ "${INSTANCE_ROLE_NAME}", NAMES.instanceRoleName, ); - } else { - return MESSAGES.deletedInstanceRole.replace( - "${INSTANCE_ROLE_NAME}", - NAMES.instanceRoleName, - ); } + return MESSAGES.deletedInstanceRole.replace( + "${INSTANCE_ROLE_NAME}", + NAMES.instanceRoleName, + ); }), new ScenarioAction("deleteInstanceProfile", async (state) => { try { @@ -232,12 +226,11 @@ export const destroySteps = [ "${INSTANCE_PROFILE_NAME}", NAMES.instanceProfileName, ); - } else { - return MESSAGES.deletedInstanceProfile.replace( - "${INSTANCE_PROFILE_NAME}", - NAMES.instanceProfileName, - ); } + return MESSAGES.deletedInstanceProfile.replace( + "${INSTANCE_PROFILE_NAME}", + NAMES.instanceProfileName, + ); }), new ScenarioAction("deleteAutoScalingGroup", async (state) => { try { @@ -256,12 +249,11 @@ export const destroySteps = [ "${AUTO_SCALING_GROUP_NAME}", NAMES.autoScalingGroupName, ); - } else { - return MESSAGES.deletedAutoScalingGroup.replace( - "${AUTO_SCALING_GROUP_NAME}", - NAMES.autoScalingGroupName, - ); } + return MESSAGES.deletedAutoScalingGroup.replace( + "${AUTO_SCALING_GROUP_NAME}", + NAMES.autoScalingGroupName, + ); }), new ScenarioAction("deleteLaunchTemplate", async (state) => { const client = new EC2Client({}); @@ -284,12 +276,11 @@ export const destroySteps = [ "${LAUNCH_TEMPLATE_NAME}", NAMES.launchTemplateName, ); - } else { - return MESSAGES.deletedLaunchTemplate.replace( - "${LAUNCH_TEMPLATE_NAME}", - NAMES.launchTemplateName, - ); } + return MESSAGES.deletedLaunchTemplate.replace( + "${LAUNCH_TEMPLATE_NAME}", + NAMES.launchTemplateName, + ); }), new ScenarioAction("deleteLoadBalancer", async (state) => { try { @@ -319,12 +310,11 @@ export const destroySteps = [ "${LB_NAME}", NAMES.loadBalancerName, ); - } else { - return MESSAGES.deletedLoadBalancer.replace( - "${LB_NAME}", - NAMES.loadBalancerName, - ); } + return MESSAGES.deletedLoadBalancer.replace( + "${LB_NAME}", + NAMES.loadBalancerName, + ); }), new ScenarioAction("deleteLoadBalancerTargetGroup", async (state) => { // snippet-start:[javascript.v3.wkflw.resilient.DeleteTargetGroup] @@ -355,12 +345,11 @@ export const destroySteps = [ "${TARGET_GROUP_NAME}", NAMES.loadBalancerTargetGroupName, ); - } else { - return MESSAGES.deletedLoadBalancerTargetGroup.replace( - "${TARGET_GROUP_NAME}", - NAMES.loadBalancerTargetGroupName, - ); } + return MESSAGES.deletedLoadBalancerTargetGroup.replace( + "${TARGET_GROUP_NAME}", + NAMES.loadBalancerTargetGroupName, + ); }), new ScenarioAction("detachSsmOnlyRoleFromProfile", async (state) => { try { @@ -381,11 +370,10 @@ export const destroySteps = [ return MESSAGES.detachSsmOnlyRoleFromProfileError .replace("${ROLE_NAME}", NAMES.ssmOnlyRoleName) .replace("${PROFILE_NAME}", NAMES.ssmOnlyInstanceProfileName); - } else { - return MESSAGES.detachedSsmOnlyRoleFromProfile - .replace("${ROLE_NAME}", NAMES.ssmOnlyRoleName) - .replace("${PROFILE_NAME}", NAMES.ssmOnlyInstanceProfileName); } + return MESSAGES.detachedSsmOnlyRoleFromProfile + .replace("${ROLE_NAME}", NAMES.ssmOnlyRoleName) + .replace("${PROFILE_NAME}", NAMES.ssmOnlyInstanceProfileName); }), new ScenarioAction("detachSsmOnlyCustomRolePolicy", async (state) => { try { @@ -407,11 +395,10 @@ export const destroySteps = [ return MESSAGES.detachSsmOnlyCustomRolePolicyError .replace("${ROLE_NAME}", NAMES.ssmOnlyRoleName) .replace("${POLICY_NAME}", NAMES.ssmOnlyPolicyName); - } else { - return MESSAGES.detachedSsmOnlyCustomRolePolicy - .replace("${ROLE_NAME}", NAMES.ssmOnlyRoleName) - .replace("${POLICY_NAME}", NAMES.ssmOnlyPolicyName); } + return MESSAGES.detachedSsmOnlyCustomRolePolicy + .replace("${ROLE_NAME}", NAMES.ssmOnlyRoleName) + .replace("${POLICY_NAME}", NAMES.ssmOnlyPolicyName); }), new ScenarioAction("detachSsmOnlyAWSRolePolicy", async (state) => { try { @@ -432,11 +419,10 @@ export const destroySteps = [ return MESSAGES.detachSsmOnlyAWSRolePolicyError .replace("${ROLE_NAME}", NAMES.ssmOnlyRoleName) .replace("${POLICY_NAME}", "AmazonSSMManagedInstanceCore"); - } else { - return MESSAGES.detachedSsmOnlyAWSRolePolicy - .replace("${ROLE_NAME}", NAMES.ssmOnlyRoleName) - .replace("${POLICY_NAME}", "AmazonSSMManagedInstanceCore"); } + return MESSAGES.detachedSsmOnlyAWSRolePolicy + .replace("${ROLE_NAME}", NAMES.ssmOnlyRoleName) + .replace("${POLICY_NAME}", "AmazonSSMManagedInstanceCore"); }), new ScenarioAction("deleteSsmOnlyInstanceProfile", async (state) => { try { @@ -457,12 +443,11 @@ export const destroySteps = [ "${INSTANCE_PROFILE_NAME}", NAMES.ssmOnlyInstanceProfileName, ); - } else { - return MESSAGES.deletedSsmOnlyInstanceProfile.replace( - "${INSTANCE_PROFILE_NAME}", - NAMES.ssmOnlyInstanceProfileName, - ); } + return MESSAGES.deletedSsmOnlyInstanceProfile.replace( + "${INSTANCE_PROFILE_NAME}", + NAMES.ssmOnlyInstanceProfileName, + ); }), new ScenarioAction("deleteSsmOnlyPolicy", async (state) => { try { @@ -484,12 +469,11 @@ export const destroySteps = [ "${POLICY_NAME}", NAMES.ssmOnlyPolicyName, ); - } else { - return MESSAGES.deletedSsmOnlyPolicy.replace( - "${POLICY_NAME}", - NAMES.ssmOnlyPolicyName, - ); } + return MESSAGES.deletedSsmOnlyPolicy.replace( + "${POLICY_NAME}", + NAMES.ssmOnlyPolicyName, + ); }), new ScenarioAction("deleteSsmOnlyRole", async (state) => { try { @@ -510,12 +494,11 @@ export const destroySteps = [ "${ROLE_NAME}", NAMES.ssmOnlyRoleName, ); - } else { - return MESSAGES.deletedSsmOnlyRole.replace( - "${ROLE_NAME}", - NAMES.ssmOnlyRoleName, - ); } + return MESSAGES.deletedSsmOnlyRole.replace( + "${ROLE_NAME}", + NAMES.ssmOnlyRoleName, + ); }), new ScenarioAction( "revokeSecurityGroupIngress", @@ -546,9 +529,8 @@ export const destroySteps = [ "${IP}", state.myIp, ); - } else { - return MESSAGES.revokedSecurityGroupIngress.replace("${IP}", state.myIp); } + return MESSAGES.revokedSecurityGroupIngress.replace("${IP}", state.myIp); }), ]; @@ -580,10 +562,9 @@ async function deleteAutoScalingGroup(groupName) { } catch (err) { if (!(err instanceof Error)) { throw err; - } else { - console.log(err.name); - throw err; } + console.log(err.name); + throw err; } } diff --git a/javascriptv3/example_code/cross-services/wkflw-topics-queues/TopicsQueuesWkflw.js b/javascriptv3/example_code/cross-services/wkflw-topics-queues/TopicsQueuesWkflw.js index 550a268d3ac..4fd6053119e 100644 --- a/javascriptv3/example_code/cross-services/wkflw-topics-queues/TopicsQueuesWkflw.js +++ b/javascriptv3/example_code/cross-services/wkflw-topics-queues/TopicsQueuesWkflw.js @@ -112,7 +112,7 @@ export class TopicsQueuesWkflw { async createQueues() { await this.logger.log(MESSAGES.createQueuesNotice); // Increase this number to add more queues. - let maxQueues = 2; + const maxQueues = 2; for (let i = 0; i < maxQueues; i++) { await this.logger.log(MESSAGES.queueCount.replace("${COUNT}", i + 1)); @@ -270,7 +270,9 @@ export class TopicsQueuesWkflw { message: MESSAGES.publishMessagePrompt, }); - let groupId, deduplicationId, choices; + let groupId; + let deduplicationId; + let choices; if (this.isFifo) { await this.logger.log(MESSAGES.groupIdNotice); diff --git a/javascriptv3/example_code/cross-services/wkflw-topics-queues/index.js b/javascriptv3/example_code/cross-services/wkflw-topics-queues/index.js index 804d2ed8fa2..3548fa3b98d 100644 --- a/javascriptv3/example_code/cross-services/wkflw-topics-queues/index.js +++ b/javascriptv3/example_code/cross-services/wkflw-topics-queues/index.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.wkflw.topicsandqueues.index] import { SNSClient } from "@aws-sdk/client-sns"; diff --git a/javascriptv3/example_code/dynamodb/actions/batch-get-item.js b/javascriptv3/example_code/dynamodb/actions/batch-get-item.js index a573284cc40..ec08e2b602c 100644 --- a/javascriptv3/example_code/dynamodb/actions/batch-get-item.js +++ b/javascriptv3/example_code/dynamodb/actions/batch-get-item.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.batch.GetItemV3] import { BatchGetItemCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb"; @@ -35,7 +35,7 @@ export const main = async () => { }); const response = await client.send(command); - console.log(response.Responses["PageAnalytics"]); + console.log(response.Responses.PageAnalytics); return response; }; // snippet-end:[dynamodb.JavaScript.batch.GetItemV3] diff --git a/javascriptv3/example_code/dynamodb/actions/batch-write-item.js b/javascriptv3/example_code/dynamodb/actions/batch-write-item.js index 21cfc1d74d3..66dbc3e9e5b 100644 --- a/javascriptv3/example_code/dynamodb/actions/batch-write-item.js +++ b/javascriptv3/example_code/dynamodb/actions/batch-write-item.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.batch.WriteItemV3] import { diff --git a/javascriptv3/example_code/dynamodb/actions/create-table.js b/javascriptv3/example_code/dynamodb/actions/create-table.js index 8d0d63cbe00..925c0103b02 100644 --- a/javascriptv3/example_code/dynamodb/actions/create-table.js +++ b/javascriptv3/example_code/dynamodb/actions/create-table.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.table.createTableV3] import { CreateTableCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/delete-item.js b/javascriptv3/example_code/dynamodb/actions/delete-item.js index 4f351e02285..167fe6997f6 100644 --- a/javascriptv3/example_code/dynamodb/actions/delete-item.js +++ b/javascriptv3/example_code/dynamodb/actions/delete-item.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.item.deleteItemV3] import { DeleteItemCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/delete-table.js b/javascriptv3/example_code/dynamodb/actions/delete-table.js index 8467866249a..a337450c35c 100644 --- a/javascriptv3/example_code/dynamodb/actions/delete-table.js +++ b/javascriptv3/example_code/dynamodb/actions/delete-table.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.item.deleteTableV3] import { DeleteTableCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/describe-table.js b/javascriptv3/example_code/dynamodb/actions/describe-table.js index b31bd4624a5..cb45d6d1d3a 100644 --- a/javascriptv3/example_code/dynamodb/actions/describe-table.js +++ b/javascriptv3/example_code/dynamodb/actions/describe-table.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.table.describeTableV3] import { DescribeTableCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/document-client/batch-get.js b/javascriptv3/example_code/dynamodb/actions/document-client/batch-get.js index 722105af62a..424c546a451 100644 --- a/javascriptv3/example_code/dynamodb/actions/document-client/batch-get.js +++ b/javascriptv3/example_code/dynamodb/actions/document-client/batch-get.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.dynamodb.doc-client.BatchGet] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; @@ -32,7 +32,7 @@ export const main = async () => { }); const response = await docClient.send(command); - console.log(response.Responses["Books"]); + console.log(response.Responses.Books); return response; }; // snippet-end:[javascript.v3.dynamodb.doc-client.BatchGet] diff --git a/javascriptv3/example_code/dynamodb/actions/document-client/batch-write.js b/javascriptv3/example_code/dynamodb/actions/document-client/batch-write.js index ff73126eb26..71432a683ac 100644 --- a/javascriptv3/example_code/dynamodb/actions/document-client/batch-write.js +++ b/javascriptv3/example_code/dynamodb/actions/document-client/batch-write.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.movies.batchwriteV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; @@ -9,7 +9,7 @@ import { BatchWriteCommand, DynamoDBDocumentClient, } from "@aws-sdk/lib-dynamodb"; -import { readFileSync } from "fs"; +import { readFileSync } from "node:fs"; // These modules are local to our GitHub repository. We recommend cloning // the project from GitHub if you want to run this example. @@ -45,7 +45,7 @@ export const main = async () => { RequestItems: { // An existing table is required. A composite key of 'title' and 'year' is recommended // to account for duplicate titles. - ["BatchWriteMoviesTable"]: putRequests, + BatchWriteMoviesTable: putRequests, }, }); diff --git a/javascriptv3/example_code/dynamodb/actions/document-client/delete.js b/javascriptv3/example_code/dynamodb/actions/document-client/delete.js index 12377a9ac9c..ba5a5652ef3 100644 --- a/javascriptv3/example_code/dynamodb/actions/document-client/delete.js +++ b/javascriptv3/example_code/dynamodb/actions/document-client/delete.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.docClient.deleteV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/document-client/get.js b/javascriptv3/example_code/dynamodb/actions/document-client/get.js index 202b86d593b..992f0695036 100644 --- a/javascriptv3/example_code/dynamodb/actions/document-client/get.js +++ b/javascriptv3/example_code/dynamodb/actions/document-client/get.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.docClient.getV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/document-client/put.js b/javascriptv3/example_code/dynamodb/actions/document-client/put.js index b9f86a9c014..d86b012034f 100644 --- a/javascriptv3/example_code/dynamodb/actions/document-client/put.js +++ b/javascriptv3/example_code/dynamodb/actions/document-client/put.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.docClient.putV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/document-client/query.js b/javascriptv3/example_code/dynamodb/actions/document-client/query.js index f2e04d4b66d..5b1875f0c19 100644 --- a/javascriptv3/example_code/dynamodb/actions/document-client/query.js +++ b/javascriptv3/example_code/dynamodb/actions/document-client/query.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.docClient.queryV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/document-client/scan.js b/javascriptv3/example_code/dynamodb/actions/document-client/scan.js index dae0d2f4546..4c64c19880a 100644 --- a/javascriptv3/example_code/dynamodb/actions/document-client/scan.js +++ b/javascriptv3/example_code/dynamodb/actions/document-client/scan.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.movies.scanV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/document-client/update.js b/javascriptv3/example_code/dynamodb/actions/document-client/update.js index 5c683fe8352..1644667cbc0 100644 --- a/javascriptv3/example_code/dynamodb/actions/document-client/update.js +++ b/javascriptv3/example_code/dynamodb/actions/document-client/update.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.docClient.updateV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/get-item.js b/javascriptv3/example_code/dynamodb/actions/get-item.js index 13f4c3a4ca0..778989b78c0 100644 --- a/javascriptv3/example_code/dynamodb/actions/get-item.js +++ b/javascriptv3/example_code/dynamodb/actions/get-item.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.item.getItemV3] import { GetItemCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/list-tables.js b/javascriptv3/example_code/dynamodb/actions/list-tables.js index dc47905807e..7a3e3bae15b 100644 --- a/javascriptv3/example_code/dynamodb/actions/list-tables.js +++ b/javascriptv3/example_code/dynamodb/actions/list-tables.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.table.listTablesV3] import { ListTablesCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-delete.js b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-delete.js index ca89133ce9c..36347a03d9f 100644 --- a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-delete.js +++ b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-delete.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.partiQL.deleteItemsV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-get.js b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-get.js index f82f4526096..1826635319d 100644 --- a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-get.js +++ b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-get.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.partiQL.getItemsV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-put.js b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-put.js index 6b57eb747a1..e8bd335b1dd 100644 --- a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-put.js +++ b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-put.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.partiQL.putItemsV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-update.js b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-update.js index 973666260ba..5b6414e146e 100644 --- a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-update.js +++ b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-batch-update.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.partiQL.updateItemsV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-delete.js b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-delete.js index fbb7af527aa..282ef0a743a 100644 --- a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-delete.js +++ b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-delete.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.partiQL.deleteItemV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-get.js b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-get.js index 2559a509c99..e55ad1f3f7d 100644 --- a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-get.js +++ b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-get.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.partiQL.getItemV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-put.js b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-put.js index 2d3ba406402..c340e966fbf 100644 --- a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-put.js +++ b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-put.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.partiQL.putItemV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-update.js b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-update.js index 78a0ec900f5..89778a40ea6 100644 --- a/javascriptv3/example_code/dynamodb/actions/partiql/partiql-update.js +++ b/javascriptv3/example_code/dynamodb/actions/partiql/partiql-update.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.partiQL.updateItemV3] import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/put-item.js b/javascriptv3/example_code/dynamodb/actions/put-item.js index 4de0d209045..2f1f7a32f2c 100644 --- a/javascriptv3/example_code/dynamodb/actions/put-item.js +++ b/javascriptv3/example_code/dynamodb/actions/put-item.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.item.putItemV3] import { PutItemCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/actions/query.js b/javascriptv3/example_code/dynamodb/actions/query.js index d6a0f9980b4..b785c4c7041 100644 --- a/javascriptv3/example_code/dynamodb/actions/query.js +++ b/javascriptv3/example_code/dynamodb/actions/query.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.table.queryV3] import { DynamoDBClient, QueryCommand } from "@aws-sdk/client-dynamodb"; @@ -24,9 +24,9 @@ export const main = async () => { }); const response = await client.send(command); - response.Items.forEach(function (pie) { + for (const pie of response.Items) { console.log(`${pie.Flavor.S} - ${pie.Description.S}\n`); - }); + } return response; }; // snippet-end:[dynamodb.JavaScript.table.queryV3] diff --git a/javascriptv3/example_code/dynamodb/actions/scan.js b/javascriptv3/example_code/dynamodb/actions/scan.js index 41c0ce01975..45dac3112da 100644 --- a/javascriptv3/example_code/dynamodb/actions/scan.js +++ b/javascriptv3/example_code/dynamodb/actions/scan.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.table.scanV3] import { DynamoDBClient, ScanCommand } from "@aws-sdk/client-dynamodb"; @@ -22,9 +22,9 @@ export const main = async () => { }); const response = await client.send(command); - response.Items.forEach(function (pie) { + for (const pie of response.Items) { console.log(`${pie.Flavor.S} - ${pie.Description.S}\n`); - }); + } return response; }; // snippet-end:[dynamodb.JavaScript.table.scanV3] diff --git a/javascriptv3/example_code/dynamodb/actions/update-item.js b/javascriptv3/example_code/dynamodb/actions/update-item.js index 4c344935d68..32575c771d4 100644 --- a/javascriptv3/example_code/dynamodb/actions/update-item.js +++ b/javascriptv3/example_code/dynamodb/actions/update-item.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[dynamodb.JavaScript.item.updateItemV3] import { UpdateItemCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/hello.js b/javascriptv3/example_code/dynamodb/hello.js index 5ed6971560c..598f448ac73 100644 --- a/javascriptv3/example_code/dynamodb/hello.js +++ b/javascriptv3/example_code/dynamodb/hello.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.dynamodb.hello] import { ListTablesCommand, DynamoDBClient } from "@aws-sdk/client-dynamodb"; diff --git a/javascriptv3/example_code/dynamodb/scenarios/basic.js b/javascriptv3/example_code/dynamodb/scenarios/basic.js index c6639f9d3a1..7d84994e9a3 100644 --- a/javascriptv3/example_code/dynamodb/scenarios/basic.js +++ b/javascriptv3/example_code/dynamodb/scenarios/basic.js @@ -1,10 +1,10 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.dynamodb_scenarios.dynamodb_basics] -import { readFileSync } from "fs"; +import { readFileSync } from "node:fs"; import { BillingMode, CreateTableCommand, @@ -227,7 +227,7 @@ export const main = async () => { * Scan the table for movies between 1980 and 1990. */ - log(`Scan for movies released between 1980 and 1990`); + log("Scan for movies released between 1980 and 1990"); // A 'Scan' operation always reads every item in the table. If your design requires // the use of 'Scan', consider indexing your table or changing your design. // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-query-scan.html diff --git a/javascriptv3/example_code/dynamodb/scenarios/partiql-batch.js b/javascriptv3/example_code/dynamodb/scenarios/partiql-batch.js index dea3d312e63..dab45f1efa6 100644 --- a/javascriptv3/example_code/dynamodb/scenarios/partiql-batch.js +++ b/javascriptv3/example_code/dynamodb/scenarios/partiql-batch.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.dynamodb_scenarios.partiQL_batch_basics] import { @@ -116,7 +116,7 @@ this table, the scenario cannot continue. Delete it?`, ], }); await docClient.send(addItemsStatementCommand); - log(`Cities inserted.`); + log("Cities inserted."); /** * Select items. @@ -162,7 +162,7 @@ this table, the scenario cannot continue. Delete it?`, ], }); await docClient.send(updateItemStatementCommand); - log(`Updated cities.`); + log("Updated cities."); /** * Delete the items. diff --git a/javascriptv3/example_code/dynamodb/scenarios/partiql-single.js b/javascriptv3/example_code/dynamodb/scenarios/partiql-single.js index 6ef0762c6bc..c7312684fab 100644 --- a/javascriptv3/example_code/dynamodb/scenarios/partiql-single.js +++ b/javascriptv3/example_code/dynamodb/scenarios/partiql-single.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.dynamodb_scenarios.partiQL_basics] import { @@ -108,7 +108,7 @@ this table, the scenario cannot continue. Delete it?`, Parameters: ["arabica", ["chocolate", "floral"]], }); await client.send(addItemStatementCommand); - log(`Coffee inserted.`); + log("Coffee inserted."); /** * Select an item. @@ -134,7 +134,7 @@ this table, the scenario cannot continue. Delete it?`, Parameters: [["fruity"], "arabica"], }); await client.send(updateItemStatementCommand); - log(`Updated coffee`); + log("Updated coffee"); /** * Delete the item. diff --git a/javascriptv3/example_code/dynamodb/tests/batch-get-item.integration.test.js b/javascriptv3/example_code/dynamodb/tests/batch-get-item.integration.test.js index 737000b13d0..023bd6b69f7 100644 --- a/javascriptv3/example_code/dynamodb/tests/batch-get-item.integration.test.js +++ b/javascriptv3/example_code/dynamodb/tests/batch-get-item.integration.test.js @@ -19,7 +19,7 @@ describe("batch-get-item", () => { it("should return a list of items", async () => { const { Responses } = await main(); - const pageAnalytics = Responses["PageAnalytics"]; + const pageAnalytics = Responses.PageAnalytics; expect(pageAnalytics).toEqual( expect.arrayContaining([ { PageViews: { N: "10" }, PageName: { S: "Home" } }, diff --git a/javascriptv3/example_code/dynamodb/tests/document-batch-get.integration.test.js b/javascriptv3/example_code/dynamodb/tests/document-batch-get.integration.test.js index 85dd45da9d3..ca415fc7a1b 100644 --- a/javascriptv3/example_code/dynamodb/tests/document-batch-get.integration.test.js +++ b/javascriptv3/example_code/dynamodb/tests/document-batch-get.integration.test.js @@ -19,7 +19,7 @@ describe("batch-get-item", () => { it("should return a list of items", async () => { const { Responses } = await main(); - const books = Responses["Books"]; + const books = Responses.Books; expect(books).toEqual( expect.arrayContaining([ { PageCount: 10, Title: "How to AWS" }, diff --git a/javascriptv3/example_code/dynamodb/tests/document-scan.integration.test.js b/javascriptv3/example_code/dynamodb/tests/document-scan.integration.test.js index 590be99128b..d25a29839cc 100644 --- a/javascriptv3/example_code/dynamodb/tests/document-scan.integration.test.js +++ b/javascriptv3/example_code/dynamodb/tests/document-scan.integration.test.js @@ -26,8 +26,8 @@ describe("document-scan", () => { const spy = vi.spyOn(console, "log"); await main(); - expect(spy).toHaveBeenCalledWith(`Owl - (Brown, 13)`); - expect(spy).toHaveBeenCalledWith(`Bluejay - (Blue, 9)`); - expect(spy).toHaveBeenCalledWith(`Parrot - (Green, 1250)`); + expect(spy).toHaveBeenCalledWith("Owl - (Brown, 13)"); + expect(spy).toHaveBeenCalledWith("Bluejay - (Blue, 9)"); + expect(spy).toHaveBeenCalledWith("Parrot - (Green, 1250)"); }); }); diff --git a/javascriptv3/example_code/dynamodb/tests/put-item.integration.test.js b/javascriptv3/example_code/dynamodb/tests/put-item.integration.test.js index d8d0a8415c7..acb99fe9f80 100644 --- a/javascriptv3/example_code/dynamodb/tests/put-item.integration.test.js +++ b/javascriptv3/example_code/dynamodb/tests/put-item.integration.test.js @@ -28,6 +28,6 @@ describe("put-item", () => { }); const { Item } = await client.send(command); - expect(Item["Flavor"]["S"]).toBe("Chocolate Chip"); + expect(Item.Flavor.S).toBe("Chocolate Chip"); }); }); diff --git a/javascriptv3/example_code/ec2/actions/allocate-address.js b/javascriptv3/example_code/ec2/actions/allocate-address.js index 324c6ab6044..cdbfe272947 100644 --- a/javascriptv3/example_code/ec2/actions/allocate-address.js +++ b/javascriptv3/example_code/ec2/actions/allocate-address.js @@ -27,7 +27,7 @@ export const main = async () => { } }; // snippet-end:[ec2.JavaScript.Addresses.allocateAddressV3] -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // Call function if run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); diff --git a/javascriptv3/example_code/ec2/actions/associate-address.js b/javascriptv3/example_code/ec2/actions/associate-address.js index f2a78b47230..4d984897035 100644 --- a/javascriptv3/example_code/ec2/actions/associate-address.js +++ b/javascriptv3/example_code/ec2/actions/associate-address.js @@ -42,8 +42,8 @@ export const main = async ({ instanceId, allocationId }) => { // snippet-end:[javascript.v3.ec2.actions.AssociateAddress] // Call function if run directly. -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; if (process.argv[1] === fileURLToPath(import.meta.url)) { const options = { allocationId: { diff --git a/javascriptv3/example_code/ec2/actions/authorize-security-group-ingress.js b/javascriptv3/example_code/ec2/actions/authorize-security-group-ingress.js index 4301799980b..036fe2b2ff7 100644 --- a/javascriptv3/example_code/ec2/actions/authorize-security-group-ingress.js +++ b/javascriptv3/example_code/ec2/actions/authorize-security-group-ingress.js @@ -44,8 +44,8 @@ export const main = async ({ groupId, ipAddress }) => { // snippet-end:[javascript.v3.ec2.actions.AuthorizeSecurityGroupIngress] // Call function if run directly. -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; if (process.argv[1] === fileURLToPath(import.meta.url)) { const options = { diff --git a/javascriptv3/example_code/ec2/actions/create-key-pair.js b/javascriptv3/example_code/ec2/actions/create-key-pair.js index ec09c60251f..9c4895d6e5a 100644 --- a/javascriptv3/example_code/ec2/actions/create-key-pair.js +++ b/javascriptv3/example_code/ec2/actions/create-key-pair.js @@ -30,8 +30,8 @@ export const main = async ({ keyName }) => { // snippet-end:[ec2.JavaScript.keypairs.createKeyPairV3] // Call function if run directly. -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; if (process.argv[1] === fileURLToPath(import.meta.url)) { const options = { diff --git a/javascriptv3/example_code/ec2/actions/create-security-group.js b/javascriptv3/example_code/ec2/actions/create-security-group.js index 1243120a7d1..b0f1ad54ae8 100644 --- a/javascriptv3/example_code/ec2/actions/create-security-group.js +++ b/javascriptv3/example_code/ec2/actions/create-security-group.js @@ -31,8 +31,8 @@ export const main = async ({ groupName, description }) => { // snippet-end:[ec2.JavaScript.SecurityGroups.createSecurityGroupV3] // Invoke main function if this file was run directly. -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; if (process.argv[1] === fileURLToPath(import.meta.url)) { const options = { groupName: { diff --git a/javascriptv3/example_code/ec2/actions/delete-key-pair.js b/javascriptv3/example_code/ec2/actions/delete-key-pair.js index 08900afe0f7..2877344a33c 100644 --- a/javascriptv3/example_code/ec2/actions/delete-key-pair.js +++ b/javascriptv3/example_code/ec2/actions/delete-key-pair.js @@ -28,8 +28,8 @@ export const main = async ({ keyName }) => { // snippet-end:[ec2.JavaScript.keypairs.deleteKeyPairV3] // Invoke main function if this file was run directly. -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; if (process.argv[1] === fileURLToPath(import.meta.url)) { const options = { keyName: { diff --git a/javascriptv3/example_code/ec2/actions/delete-security-group.js b/javascriptv3/example_code/ec2/actions/delete-security-group.js index 477e19d9f5b..30aecfb8864 100644 --- a/javascriptv3/example_code/ec2/actions/delete-security-group.js +++ b/javascriptv3/example_code/ec2/actions/delete-security-group.js @@ -28,8 +28,8 @@ export const main = async ({ groupId }) => { // snippet-end:[ec2.JavaScript.SecurityGroups.deleteSecurityGroupV3] // Invoke main function if this file was run directly. -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; if (process.argv[1] === fileURLToPath(import.meta.url)) { const options = { groupId: { diff --git a/javascriptv3/example_code/ec2/actions/describe-images.js b/javascriptv3/example_code/ec2/actions/describe-images.js index 1ba8fc4787c..45c36bc2103 100644 --- a/javascriptv3/example_code/ec2/actions/describe-images.js +++ b/javascriptv3/example_code/ec2/actions/describe-images.js @@ -9,7 +9,7 @@ import { EC2Client, paginateDescribeImages } from "@aws-sdk/client-ec2"; * @param {{ architecture: string, pageSize: number }} options */ export const main = async ({ architecture, pageSize }) => { - pageSize = parseInt(pageSize); + pageSize = Number.parseInt(pageSize); const client = new EC2Client({}); // The paginate function is a wrapper around the base command. @@ -37,11 +37,10 @@ export const main = async ({ architecture, pageSize }) => { if (page.Images.length) { images.push(...page.Images); break; - } else { - console.log( - `No matching image found yet. Searched ${recordsScanned} records.`, - ); } + console.log( + `No matching image found yet. Searched ${recordsScanned} records.`, + ); } if (images.length) { diff --git a/javascriptv3/example_code/ec2/actions/describe-instance-types.js b/javascriptv3/example_code/ec2/actions/describe-instance-types.js index b7c40b8d069..86dddefab30 100644 --- a/javascriptv3/example_code/ec2/actions/describe-instance-types.js +++ b/javascriptv3/example_code/ec2/actions/describe-instance-types.js @@ -10,7 +10,7 @@ import { EC2Client, paginateDescribeInstanceTypes } from "@aws-sdk/client-ec2"; * @param {{ pageSize: string, supportedArch: string[], freeTier: boolean }} options */ export const main = async ({ pageSize, supportedArch, freeTier }) => { - pageSize = parseInt(pageSize); + pageSize = Number.parseInt(pageSize); const client = new EC2Client({}); // The paginate function is a wrapper around the underlying command. diff --git a/javascriptv3/example_code/ec2/actions/describe-instances.js b/javascriptv3/example_code/ec2/actions/describe-instances.js index aaaffed1fd1..0b9a7c30e7e 100644 --- a/javascriptv3/example_code/ec2/actions/describe-instances.js +++ b/javascriptv3/example_code/ec2/actions/describe-instances.js @@ -10,7 +10,7 @@ import { EC2Client, paginateDescribeInstances } from "@aws-sdk/client-ec2"; * @param {{ pageSize: string, architectures: string[] }} options */ export const main = async ({ pageSize, architectures }) => { - pageSize = parseInt(pageSize); + pageSize = Number.parseInt(pageSize); const client = new EC2Client({}); const d = new Date(); const year = d.getFullYear(); @@ -41,7 +41,9 @@ export const main = async ({ pageSize, architectures }) => { const instanceList = []; for await (const page of paginator) { const { Reservations } = page; - Reservations.forEach((r) => instanceList.push(...r.Instances)); + for (const reservation of Reservations) { + instanceList.push(...reservation.Instances); + } } console.log( `Running instances launched this month:\n\n${instanceList.map((instance) => instance.InstanceId).join("\n")}`, @@ -57,8 +59,8 @@ export const main = async ({ pageSize, architectures }) => { // snippet-end:[ec2.JavaScript.Instances.describeInstancesV3] // Invoke main function if this file was run directly. -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; if (process.argv[1] === fileURLToPath(import.meta.url)) { const options = { architectures: { diff --git a/javascriptv3/example_code/ec2/actions/disassociate-address.js b/javascriptv3/example_code/ec2/actions/disassociate-address.js index bf7b9518f09..9358bc29b7e 100644 --- a/javascriptv3/example_code/ec2/actions/disassociate-address.js +++ b/javascriptv3/example_code/ec2/actions/disassociate-address.js @@ -32,8 +32,8 @@ export const main = async ({ associationId }) => { // snippet-end:[javascript.v3.ec2.actions.DisassociateAddress] // Invoke main function if this file was run directly. -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; if (process.argv[1] === fileURLToPath(import.meta.url)) { const options = { associationId: { diff --git a/javascriptv3/example_code/ec2/actions/run-instances.js b/javascriptv3/example_code/ec2/actions/run-instances.js index dab1a245b2b..920f19fa970 100644 --- a/javascriptv3/example_code/ec2/actions/run-instances.js +++ b/javascriptv3/example_code/ec2/actions/run-instances.js @@ -23,8 +23,8 @@ export const main = async ({ maxCount = "1", }) => { const client = new EC2Client({}); - minCount = parseInt(minCount); - maxCount = parseInt(maxCount); + minCount = Number.parseInt(minCount); + maxCount = Number.parseInt(maxCount); const command = new RunInstancesCommand({ // Your key pair name. KeyName: keyName, diff --git a/javascriptv3/example_code/ec2/actions/start-instances.js b/javascriptv3/example_code/ec2/actions/start-instances.js index 8ddb91e735e..504d05212e0 100644 --- a/javascriptv3/example_code/ec2/actions/start-instances.js +++ b/javascriptv3/example_code/ec2/actions/start-instances.js @@ -3,8 +3,8 @@ // snippet-start:[ec2.JavaScript.Instances.start_stopInstancesV3] import { EC2Client, StartInstancesCommand } from "@aws-sdk/client-ec2"; -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; /** * Starts an Amazon EBS-backed instance that you've previously stopped. diff --git a/javascriptv3/example_code/ec2/actions/stop-instances.js b/javascriptv3/example_code/ec2/actions/stop-instances.js index ec59a3e0c98..c1b333639d5 100644 --- a/javascriptv3/example_code/ec2/actions/stop-instances.js +++ b/javascriptv3/example_code/ec2/actions/stop-instances.js @@ -3,8 +3,8 @@ // snippet-start:[javascript.v3.ec2.actions.StopInstances] import { EC2Client, StopInstancesCommand } from "@aws-sdk/client-ec2"; -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; /** * Stop one or more EC2 instances. diff --git a/javascriptv3/example_code/ec2/actions/terminate-instances.js b/javascriptv3/example_code/ec2/actions/terminate-instances.js index 29574c9bc41..a27ec0b8d0b 100644 --- a/javascriptv3/example_code/ec2/actions/terminate-instances.js +++ b/javascriptv3/example_code/ec2/actions/terminate-instances.js @@ -3,8 +3,8 @@ // snippet-start:[javascript.v2.ec2.actions.TerminateInstances] import { EC2Client, TerminateInstancesCommand } from "@aws-sdk/client-ec2"; -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; /** * Terminate one or more EC2 instances. @@ -33,7 +33,6 @@ export const main = async ({ instanceIds }) => { throw caught; } } - ``; }; // snippet-end:[javascript.v2.ec2.actions.TerminateInstances] diff --git a/javascriptv3/example_code/ec2/actions/unmonitor-instances.js b/javascriptv3/example_code/ec2/actions/unmonitor-instances.js index 4be12fedc2a..d3a7033b396 100644 --- a/javascriptv3/example_code/ec2/actions/unmonitor-instances.js +++ b/javascriptv3/example_code/ec2/actions/unmonitor-instances.js @@ -3,8 +3,8 @@ // snippet-start:[javascript.v3.ec2.actions.UnmonitorInstances] import { EC2Client, UnmonitorInstancesCommand } from "@aws-sdk/client-ec2"; -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; /** * Turn off detailed monitoring for the selected instance. diff --git a/javascriptv3/example_code/ec2/hello.js b/javascriptv3/example_code/ec2/hello.js index da7b592f133..24829787fca 100644 --- a/javascriptv3/example_code/ec2/hello.js +++ b/javascriptv3/example_code/ec2/hello.js @@ -25,7 +25,7 @@ export const main = async () => { }; // Call function if run directly. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/ec2/scenarios/steps.js b/javascriptv3/example_code/ec2/scenarios/steps.js index ea4cb70345b..acb01402033 100644 --- a/javascriptv3/example_code/ec2/scenarios/steps.js +++ b/javascriptv3/example_code/ec2/scenarios/steps.js @@ -69,7 +69,7 @@ export const confirm = new ScenarioInput("confirmContinue", "Continue?", { }); export const exitOnNoConfirm = new ScenarioAction( - `exitOnConfirmContinueFalse`, + "exitOnConfirmContinueFalse", (/** @type { { earlyExit: boolean } & Record} */ state) => { if (!state[confirm.name]) { state.earlyExit = true; @@ -260,13 +260,15 @@ export const authorizeSecurityGroupIngress = new ScenarioAction( const ipAddress = await new Promise((res, rej) => { get("http://checkip.amazonaws.com", (response) => { let data = ""; - response.on("data", (chunk) => (data += chunk)); + response.on("data", (chunk) => { + data += chunk; + }); response.on("end", () => res(data.trim())); }).on("error", (err) => { rej(err); }); }); - state[`ipAddress`] = ipAddress; + state.ipAddress = ipAddress; // Allow ingress from the IP address above to the security group. // This will allow you to SSH into the EC2 instance. const command = new AuthorizeSecurityGroupIngressCommand({ @@ -326,12 +328,12 @@ export const getImages = new ScenarioAction( try { for await (const page of getParametersByPathPaginator) { - page.Parameters.forEach((param) => { + for (const param of page.Parameters) { // Filter by Amazon Linux 2 if (param.Name.includes("amzn2")) { AMIs.push(param.Value); } - }); + } } } catch (caught) { if (caught instanceof Error && caught.name === "InvalidFilterValue") { @@ -355,7 +357,7 @@ export const getImages = new ScenarioAction( } // Store the image details for later use. - state["images"] = imageDetails; + state.images = imageDetails; } catch (caught) { if (caught instanceof Error && caught.name === "InvalidAMIID.NotFound") { caught.message = `${caught.message}. Please provide a valid image id.`; @@ -424,7 +426,7 @@ export const getCompatibleInstanceTypes = new ScenarioAction( state.errors.push(caught); } - state["instanceTypes"] = instanceTypes; + state.instanceTypes = instanceTypes; }, { skipWhen: skipWhenErrors }, ); diff --git a/javascriptv3/example_code/ec2/tests/allocate-address.unit.test.js b/javascriptv3/example_code/ec2/tests/allocate-address.unit.test.js index a43c6041e9a..41b13c5dda6 100644 --- a/javascriptv3/example_code/ec2/tests/allocate-address.unit.test.js +++ b/javascriptv3/example_code/ec2/tests/allocate-address.unit.test.js @@ -29,7 +29,7 @@ describe("allocate-address", () => { await main(); - expect(logSpy).toHaveBeenNthCalledWith(2, `ID: bar Public IP: foo`); + expect(logSpy).toHaveBeenNthCalledWith(2, "ID: bar Public IP: foo"); }); it("should log MissingParameter errors", async () => { diff --git a/javascriptv3/example_code/ec2/tests/describe-images.unit.test.js b/javascriptv3/example_code/ec2/tests/describe-images.unit.test.js index b4c52a09979..4433ffec267 100644 --- a/javascriptv3/example_code/ec2/tests/describe-images.unit.test.js +++ b/javascriptv3/example_code/ec2/tests/describe-images.unit.test.js @@ -41,7 +41,7 @@ describe("describe-images", () => { error.name = "InvalidParameterValue"; paginateDescribeImages.mockReturnValueOnce( - // eslint-disable-next-line require-yield + // biome-ignore lint/correctness/useYield: Mock generator function (async function* () { throw error; })(), @@ -56,7 +56,7 @@ describe("describe-images", () => { const error = new Error("Retrieval failed"); paginateDescribeImages.mockReturnValueOnce( - // eslint-disable-next-line require-yield + // biome-ignore lint/correctness/useYield: Mock generator function (async function* () { throw error; })(), diff --git a/javascriptv3/example_code/ec2/tests/describe-instance-types.unit.test.js b/javascriptv3/example_code/ec2/tests/describe-instance-types.unit.test.js index 218f83b8459..5ff4c6523b4 100644 --- a/javascriptv3/example_code/ec2/tests/describe-instance-types.unit.test.js +++ b/javascriptv3/example_code/ec2/tests/describe-instance-types.unit.test.js @@ -42,7 +42,7 @@ describe("describe-instance-types", () => { error.name = "InvalidParameterValue"; paginateDescribeInstanceTypes.mockReturnValueOnce( - // eslint-disable-next-line require-yield + // biome-ignore lint/correctness/useYield: Mock generator (async function* () { throw error; })(), @@ -57,7 +57,7 @@ describe("describe-instance-types", () => { const error = new Error("Retrieval failed"); paginateDescribeInstanceTypes.mockReturnValueOnce( - // eslint-disable-next-line require-yield + // biome-ignore lint/correctness/useYield: Mock generator (async function* () { throw error; })(), diff --git a/javascriptv3/example_code/ec2/tests/describe-instances.unit.test.js b/javascriptv3/example_code/ec2/tests/describe-instances.unit.test.js index d0d9fe1e890..78ec7540ff4 100644 --- a/javascriptv3/example_code/ec2/tests/describe-instances.unit.test.js +++ b/javascriptv3/example_code/ec2/tests/describe-instances.unit.test.js @@ -57,7 +57,7 @@ describe("describe-instances", () => { error.name = "InvalidParameterName"; paginateDescribeInstances.mockReturnValueOnce( - // eslint-disable-next-line require-yield + // biome-ignore lint/correctness/useYield: Mock generator function (async function* () { throw error; })(), diff --git a/javascriptv3/example_code/ec2/tests/describe-security-groups.unit.test.js b/javascriptv3/example_code/ec2/tests/describe-security-groups.unit.test.js index bac82972184..6ba948bcc94 100644 --- a/javascriptv3/example_code/ec2/tests/describe-security-groups.unit.test.js +++ b/javascriptv3/example_code/ec2/tests/describe-security-groups.unit.test.js @@ -35,7 +35,7 @@ describe("describe-security-groups", () => { await main({}); expect(logSpy).toHaveBeenCalledWith( - `Security groups:\n• group (sg-1): My security group`, + "Security groups:\n• group (sg-1): My security group", ); }); diff --git a/javascriptv3/example_code/ec2/tests/run-instances.unit.test.js b/javascriptv3/example_code/ec2/tests/run-instances.unit.test.js index 857594d51fb..62e6f4d354b 100644 --- a/javascriptv3/example_code/ec2/tests/run-instances.unit.test.js +++ b/javascriptv3/example_code/ec2/tests/run-instances.unit.test.js @@ -36,7 +36,7 @@ describe("run-instances", () => { }); expect(logSpy).toHaveBeenCalledWith( - `Launched instances:\n• i-0e8810a92833675aa`, + "Launched instances:\n• i-0e8810a92833675aa", ); }); diff --git a/javascriptv3/example_code/elastic-load-balancing-v2/hello.js b/javascriptv3/example_code/elastic-load-balancing-v2/hello.js index 401123d7af3..f9ee89a653f 100644 --- a/javascriptv3/example_code/elastic-load-balancing-v2/hello.js +++ b/javascriptv3/example_code/elastic-load-balancing-v2/hello.js @@ -21,7 +21,7 @@ export async function main() { } // Call function if run directly -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/eventbridge/actions/put-events.js b/javascriptv3/example_code/eventbridge/actions/put-events.js index 4f316e5aae7..6525f8c0bc5 100644 --- a/javascriptv3/example_code/eventbridge/actions/put-events.js +++ b/javascriptv3/example_code/eventbridge/actions/put-events.js @@ -48,7 +48,7 @@ export const putEvents = async ( // snippet-end:[eventBridge.JavaScript.eb.putEventsV3] // Call function if run directly -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { putEvents(); } diff --git a/javascriptv3/example_code/eventbridge/actions/put-rule.js b/javascriptv3/example_code/eventbridge/actions/put-rule.js index dd33662ba3d..c3b94d54ac3 100644 --- a/javascriptv3/example_code/eventbridge/actions/put-rule.js +++ b/javascriptv3/example_code/eventbridge/actions/put-rule.js @@ -38,7 +38,7 @@ export const putRule = async ( // snippet-end:[eventBridge.JavaScript.eb.putRuleV3] // Call the function if run directly -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { putRule(); } diff --git a/javascriptv3/example_code/eventbridge/actions/put-targets.js b/javascriptv3/example_code/eventbridge/actions/put-targets.js index 361eca4a93f..96fbb0e4ef8 100644 --- a/javascriptv3/example_code/eventbridge/actions/put-targets.js +++ b/javascriptv3/example_code/eventbridge/actions/put-targets.js @@ -47,7 +47,7 @@ export const putTarget = async ( // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { putTarget(); } diff --git a/javascriptv3/example_code/glue/hello.js b/javascriptv3/example_code/glue/hello.js index 2c4a7f5f921..fc8ccab1ce6 100644 --- a/javascriptv3/example_code/glue/hello.js +++ b/javascriptv3/example_code/glue/hello.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.glue.hello] import { ListJobsCommand, GlueClient } from "@aws-sdk/client-glue"; diff --git a/javascriptv3/example_code/glue/scenarios/basic/steps/clean-up-crawler.js b/javascriptv3/example_code/glue/scenarios/basic/steps/clean-up-crawler.js index cf9aa063560..b08360ebac9 100644 --- a/javascriptv3/example_code/glue/scenarios/basic/steps/clean-up-crawler.js +++ b/javascriptv3/example_code/glue/scenarios/basic/steps/clean-up-crawler.js @@ -6,14 +6,14 @@ import { log } from "../log.js"; /** snippet-start:[javascript.v3.glue.scenarios.basic.CleanUpCrawler] */ const cleanUpCrawlerStep = async (context) => { - log(`Deleting crawler.`); + log("Deleting crawler."); try { await deleteCrawler(process.env.CRAWLER_NAME); log("Crawler deleted.", { type: "success" }); } catch (err) { if (err.name === "EntityNotFoundException") { - log(`Crawler is already deleted.`); + log("Crawler is already deleted."); } else { throw err; } diff --git a/javascriptv3/example_code/glue/scenarios/basic/steps/validate-env.js b/javascriptv3/example_code/glue/scenarios/basic/steps/validate-env.js index f25c37d1282..b9c3e536b02 100644 --- a/javascriptv3/example_code/glue/scenarios/basic/steps/validate-env.js +++ b/javascriptv3/example_code/glue/scenarios/basic/steps/validate-env.js @@ -22,11 +22,11 @@ const validateEnv = (context) => { reject(new Error("Missing context.")); } - keys.forEach((key) => { + for (const key of keys) { if (!process.env[key]) { reject(new Error(`Missing environment variable. No value for ${key}.`)); } - }); + } log("Variables exist.", { type: "success" }); resolve({ ...context }); diff --git a/javascriptv3/example_code/glue/scenarios/basic/steps/validate-python-script.js b/javascriptv3/example_code/glue/scenarios/basic/steps/validate-python-script.js index ae2a561d3dc..ff5d6926252 100644 --- a/javascriptv3/example_code/glue/scenarios/basic/steps/validate-python-script.js +++ b/javascriptv3/example_code/glue/scenarios/basic/steps/validate-python-script.js @@ -34,11 +34,10 @@ const makeValidatePythonScriptStep = if (scriptExists) { log("ETL python script exists.", { type: "success" }); return { ...context }; - } else { - throw new Error( - "Missing ETL python script. Did you run the setup steps in the readme?", - ); } + throw new Error( + "Missing ETL python script. Did you run the setup steps in the readme?", + ); }; export { makeValidatePythonScriptStep }; diff --git a/javascriptv3/example_code/glue/tests/glue-actions.integration.test.js b/javascriptv3/example_code/glue/tests/glue-actions.integration.test.js index 520f80abdfe..9bbe72ad531 100644 --- a/javascriptv3/example_code/glue/tests/glue-actions.integration.test.js +++ b/javascriptv3/example_code/glue/tests/glue-actions.integration.test.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { readFile } from "fs/promises"; +import { readFile } from "node:fs/promises"; import { describe, it, expect, beforeAll, afterAll } from "vitest"; import { config } from "dotenv"; import { @@ -43,7 +43,7 @@ config(); const dirname = dirnameFromMetaUrl(import.meta.url); const cdkAppPath = `${dirname}../../../../resources/cdk/glue_role_bucket/setup.yaml`; -const stackName = `glue-test-stack`; +const stackName = "glue-test-stack"; const fiveMinutesInMs = 5 * 60 * 1000; // 5 Minutes const fiveMinutesInSeconds = fiveMinutesInMs / 1000; @@ -54,10 +54,9 @@ const fiveMinutesInSeconds = fiveMinutesInMs / 1000; */ const getResourceNames = ({ Outputs }) => Outputs.reduce((resourceNameMap, nextOutput) => { - return { - ...resourceNameMap, + return Object.assign({}, resourceNameMap, { [nextOutput.OutputKey]: nextOutput.OutputValue, - }; + }); }, {}); const createStack = async () => { @@ -102,7 +101,8 @@ const deleteStack = async () => { }; describe("actions", () => { - let roleName, bucketName; + let roleName; + let bucketName; beforeAll(async () => { try { diff --git a/javascriptv3/example_code/glue/tests/validate-env.unit.test.js b/javascriptv3/example_code/glue/tests/validate-env.unit.test.js index 2c74777c0b3..e2d658a62d9 100644 --- a/javascriptv3/example_code/glue/tests/validate-env.unit.test.js +++ b/javascriptv3/example_code/glue/tests/validate-env.unit.test.js @@ -5,9 +5,9 @@ import { validateEnv, keys } from "../scenarios/basic/steps/validate-env.js"; describe("validateEnv", () => { beforeAll(() => { - keys.forEach((key) => { + for (const key of keys) { process.env[key] = ""; - }); + } }); it("should throw an error if no arguments are passed", () => { @@ -23,7 +23,9 @@ describe("validateEnv", () => { it("should return a copy of the context if all env vars are present", async () => { const context = {}; - keys.forEach((key) => (process.env[key] = "some value")); + for (const key of keys) { + process.env[key] = "some value"; + } console.log(process.env); await expect(validateEnv(context)).resolves.toEqual(context); return expect(validateEnv(context)).resolves.not.toBe(context); diff --git a/javascriptv3/example_code/iam/actions/attach-role-policy.js b/javascriptv3/example_code/iam/actions/attach-role-policy.js index 7f1ded15052..6e11d6d6353 100644 --- a/javascriptv3/example_code/iam/actions/attach-role-policy.js +++ b/javascriptv3/example_code/iam/actions/attach-role-policy.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.actions.AttachRolePolicy] import { AttachRolePolicyCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/create-access-key.js b/javascriptv3/example_code/iam/actions/create-access-key.js index 41f8ce36378..dc85ac94016 100644 --- a/javascriptv3/example_code/iam/actions/create-access-key.js +++ b/javascriptv3/example_code/iam/actions/create-access-key.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.keys.createAccessKeyV3] import { CreateAccessKeyCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/create-account-alias.js b/javascriptv3/example_code/iam/actions/create-account-alias.js index 8187aed0ba7..d8978502d68 100644 --- a/javascriptv3/example_code/iam/actions/create-account-alias.js +++ b/javascriptv3/example_code/iam/actions/create-account-alias.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.alias.createAccountAliasV3] import { CreateAccountAliasCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/create-group.js b/javascriptv3/example_code/iam/actions/create-group.js index 64f38d1ecc8..c970c49fcc7 100644 --- a/javascriptv3/example_code/iam/actions/create-group.js +++ b/javascriptv3/example_code/iam/actions/create-group.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.actions.CreateGroup] import { CreateGroupCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/create-policy.js b/javascriptv3/example_code/iam/actions/create-policy.js index 28562eab29c..87a236cf032 100644 --- a/javascriptv3/example_code/iam/actions/create-policy.js +++ b/javascriptv3/example_code/iam/actions/create-policy.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.policies.createPolicyV3] import { CreatePolicyCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/create-role.js b/javascriptv3/example_code/iam/actions/create-role.js index fcde0ea9c3c..8fba900e554 100644 --- a/javascriptv3/example_code/iam/actions/create-role.js +++ b/javascriptv3/example_code/iam/actions/create-role.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.users.createrolev3] import { CreateRoleCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/create-saml-provider.js b/javascriptv3/example_code/iam/actions/create-saml-provider.js index b8b43191274..55fa7d104c2 100644 --- a/javascriptv3/example_code/iam/actions/create-saml-provider.js +++ b/javascriptv3/example_code/iam/actions/create-saml-provider.js @@ -1,12 +1,12 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.actions.CreateSAMLProvider] import { CreateSAMLProviderCommand, IAMClient } from "@aws-sdk/client-iam"; -import { readFileSync } from "fs"; -import * as path from "path"; +import { readFileSync } from "node:fs"; +import * as path from "node:path"; import { dirnameFromMetaUrl } from "@aws-doc-sdk-examples/lib/utils/util-fs.js"; const client = new IAMClient({}); diff --git a/javascriptv3/example_code/iam/actions/create-service-linked-role.js b/javascriptv3/example_code/iam/actions/create-service-linked-role.js index 8f7b601a946..24d7ccc6d89 100644 --- a/javascriptv3/example_code/iam/actions/create-service-linked-role.js +++ b/javascriptv3/example_code/iam/actions/create-service-linked-role.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.createservicelinkedrolev3] import { @@ -40,9 +40,8 @@ export const createServiceLinkedRole = async (serviceName) => { return client.send( new GetRoleCommand({ RoleName: "AWSServiceRoleForElasticBeanstalk" }), ); - } else { - throw caught; } + throw caught; } }; // snippet-end:[iam.JavaScript.createservicelinkedrolev3] diff --git a/javascriptv3/example_code/iam/actions/create-user.js b/javascriptv3/example_code/iam/actions/create-user.js index 65a4a18a64f..6c4e6d0efbb 100644 --- a/javascriptv3/example_code/iam/actions/create-user.js +++ b/javascriptv3/example_code/iam/actions/create-user.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.actions.CreateUser] import { CreateUserCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/delete-access-key.js b/javascriptv3/example_code/iam/actions/delete-access-key.js index 37fd74f894d..f1428fbb543 100644 --- a/javascriptv3/example_code/iam/actions/delete-access-key.js +++ b/javascriptv3/example_code/iam/actions/delete-access-key.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.keys.deleteAccessKeyV3] import { DeleteAccessKeyCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/delete-account-alias.js b/javascriptv3/example_code/iam/actions/delete-account-alias.js index 45ba77d2bf4..ba3aa71c4be 100644 --- a/javascriptv3/example_code/iam/actions/delete-account-alias.js +++ b/javascriptv3/example_code/iam/actions/delete-account-alias.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.alias.deleteAccountAliasV3] import { DeleteAccountAliasCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/delete-group.js b/javascriptv3/example_code/iam/actions/delete-group.js index fb890d6036e..28c8b932989 100644 --- a/javascriptv3/example_code/iam/actions/delete-group.js +++ b/javascriptv3/example_code/iam/actions/delete-group.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.actions.DeleteGroup] import { DeleteGroupCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/delete-policy.js b/javascriptv3/example_code/iam/actions/delete-policy.js index 69810faad6e..95a97413174 100644 --- a/javascriptv3/example_code/iam/actions/delete-policy.js +++ b/javascriptv3/example_code/iam/actions/delete-policy.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.users.deletepolicyv3] import { DeletePolicyCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/delete-role-policy.js b/javascriptv3/example_code/iam/actions/delete-role-policy.js index 82201d3e202..532a4541928 100644 --- a/javascriptv3/example_code/iam/actions/delete-role-policy.js +++ b/javascriptv3/example_code/iam/actions/delete-role-policy.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.actions.DeleteRolePolicy] import { DeleteRolePolicyCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/delete-role.js b/javascriptv3/example_code/iam/actions/delete-role.js index 5db5278e5a4..253f4e5501b 100644 --- a/javascriptv3/example_code/iam/actions/delete-role.js +++ b/javascriptv3/example_code/iam/actions/delete-role.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.actions.DeleteRole] import { DeleteRoleCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/delete-saml-provider.js b/javascriptv3/example_code/iam/actions/delete-saml-provider.js index 61d32c882d5..2148388d6a9 100644 --- a/javascriptv3/example_code/iam/actions/delete-saml-provider.js +++ b/javascriptv3/example_code/iam/actions/delete-saml-provider.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.actions.DeleteSAMLProvider] import { DeleteSAMLProviderCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/delete-server-certificate.js b/javascriptv3/example_code/iam/actions/delete-server-certificate.js index 913df3ecda9..3288c06ed49 100644 --- a/javascriptv3/example_code/iam/actions/delete-server-certificate.js +++ b/javascriptv3/example_code/iam/actions/delete-server-certificate.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.certs.deleteServerCertificateV3] import { DeleteServerCertificateCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/delete-service-linked-role.js b/javascriptv3/example_code/iam/actions/delete-service-linked-role.js index 4dabda19143..e6908071d94 100644 --- a/javascriptv3/example_code/iam/actions/delete-service-linked-role.js +++ b/javascriptv3/example_code/iam/actions/delete-service-linked-role.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.actions.DeleteServiceLinkedRole] import { DeleteServiceLinkedRoleCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/delete-user.js b/javascriptv3/example_code/iam/actions/delete-user.js index ca4fda6d788..a10a35caf7e 100644 --- a/javascriptv3/example_code/iam/actions/delete-user.js +++ b/javascriptv3/example_code/iam/actions/delete-user.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.users.deleteUserV3] import { DeleteUserCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/detach-role-policy.js b/javascriptv3/example_code/iam/actions/detach-role-policy.js index c3da55d7aa2..f122a4611bf 100644 --- a/javascriptv3/example_code/iam/actions/detach-role-policy.js +++ b/javascriptv3/example_code/iam/actions/detach-role-policy.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.policies.detachRolePolicyV3] import { DetachRolePolicyCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/get-access-key-last-used.js b/javascriptv3/example_code/iam/actions/get-access-key-last-used.js index a1d6ba70c37..1fd98d5a84e 100644 --- a/javascriptv3/example_code/iam/actions/get-access-key-last-used.js +++ b/javascriptv3/example_code/iam/actions/get-access-key-last-used.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.keys.getAccessKeyLastUsedV3] import { GetAccessKeyLastUsedCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/get-account-password-policy.js b/javascriptv3/example_code/iam/actions/get-account-password-policy.js index 6aa34ad2072..f0823157db8 100644 --- a/javascriptv3/example_code/iam/actions/get-account-password-policy.js +++ b/javascriptv3/example_code/iam/actions/get-account-password-policy.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.getaccountpasswordpolicyV3] import { diff --git a/javascriptv3/example_code/iam/actions/get-policy.js b/javascriptv3/example_code/iam/actions/get-policy.js index c530193b209..a2e7e15a729 100644 --- a/javascriptv3/example_code/iam/actions/get-policy.js +++ b/javascriptv3/example_code/iam/actions/get-policy.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.policies.getPolicyV3] import { GetPolicyCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/get-role.js b/javascriptv3/example_code/iam/actions/get-role.js index b51a23867ca..3d5cfc13d63 100644 --- a/javascriptv3/example_code/iam/actions/get-role.js +++ b/javascriptv3/example_code/iam/actions/get-role.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.getRoleV3] import { GetRoleCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/get-server-certificate.js b/javascriptv3/example_code/iam/actions/get-server-certificate.js index 84e1de9435a..7337a8a939e 100644 --- a/javascriptv3/example_code/iam/actions/get-server-certificate.js +++ b/javascriptv3/example_code/iam/actions/get-server-certificate.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.certs.getServerCertificateV3] import { GetServerCertificateCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/get-service-linked-role-deletion-status.js b/javascriptv3/example_code/iam/actions/get-service-linked-role-deletion-status.js index f8022e64c0f..1f47837cb7d 100644 --- a/javascriptv3/example_code/iam/actions/get-service-linked-role-deletion-status.js +++ b/javascriptv3/example_code/iam/actions/get-service-linked-role-deletion-status.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.actions.GetServiceLinkedRoleDeletionStatus] import { diff --git a/javascriptv3/example_code/iam/actions/list-access-keys.js b/javascriptv3/example_code/iam/actions/list-access-keys.js index 57e78437ccc..51baf5e696e 100644 --- a/javascriptv3/example_code/iam/actions/list-access-keys.js +++ b/javascriptv3/example_code/iam/actions/list-access-keys.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.keys.listAccessKeysV3] import { ListAccessKeysCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/list-account-aliases.js b/javascriptv3/example_code/iam/actions/list-account-aliases.js index 7a16cb31420..d447e27b849 100644 --- a/javascriptv3/example_code/iam/actions/list-account-aliases.js +++ b/javascriptv3/example_code/iam/actions/list-account-aliases.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.alias.listAccountAliasesV3] import { ListAccountAliasesCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/list-attached-role-policies.js b/javascriptv3/example_code/iam/actions/list-attached-role-policies.js index d02e491be6c..5cbd32146ef 100644 --- a/javascriptv3/example_code/iam/actions/list-attached-role-policies.js +++ b/javascriptv3/example_code/iam/actions/list-attached-role-policies.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.listattachedrolepoliciesV3] import { diff --git a/javascriptv3/example_code/iam/actions/list-groups.js b/javascriptv3/example_code/iam/actions/list-groups.js index 3f328c0d85e..6c3c5f15485 100644 --- a/javascriptv3/example_code/iam/actions/list-groups.js +++ b/javascriptv3/example_code/iam/actions/list-groups.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.listgroupsV3] import { ListGroupsCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/list-policies.js b/javascriptv3/example_code/iam/actions/list-policies.js index f802143d82a..c7c8ba02f47 100644 --- a/javascriptv3/example_code/iam/actions/list-policies.js +++ b/javascriptv3/example_code/iam/actions/list-policies.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.listpoliciesv3] import { ListPoliciesCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/list-role-policies.js b/javascriptv3/example_code/iam/actions/list-role-policies.js index 1cf5edd01bc..59d768feb0d 100644 --- a/javascriptv3/example_code/iam/actions/list-role-policies.js +++ b/javascriptv3/example_code/iam/actions/list-role-policies.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.listrolepoliciesv3] import { ListRolePoliciesCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/list-roles.js b/javascriptv3/example_code/iam/actions/list-roles.js index 35265ecb116..eb20946373e 100644 --- a/javascriptv3/example_code/iam/actions/list-roles.js +++ b/javascriptv3/example_code/iam/actions/list-roles.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.listrolesV3] import { ListRolesCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/list-saml-providers.js b/javascriptv3/example_code/iam/actions/list-saml-providers.js index 39164315eb6..5dbd85b1761 100644 --- a/javascriptv3/example_code/iam/actions/list-saml-providers.js +++ b/javascriptv3/example_code/iam/actions/list-saml-providers.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.listsamlprovidersV3] import { ListSAMLProvidersCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/list-server-certificates.js b/javascriptv3/example_code/iam/actions/list-server-certificates.js index 49544b031d5..e0bc576e4bf 100644 --- a/javascriptv3/example_code/iam/actions/list-server-certificates.js +++ b/javascriptv3/example_code/iam/actions/list-server-certificates.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.certs.listServerCertificatesV3] import { ListServerCertificatesCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/list-users.js b/javascriptv3/example_code/iam/actions/list-users.js index 53cbc977ce4..c109cfbeec0 100644 --- a/javascriptv3/example_code/iam/actions/list-users.js +++ b/javascriptv3/example_code/iam/actions/list-users.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.users.listUsersV3] import { ListUsersCommand, IAMClient } from "@aws-sdk/client-iam"; @@ -12,9 +12,10 @@ export const listUsers = async () => { const command = new ListUsersCommand({ MaxItems: 10 }); const response = await client.send(command); - response.Users?.forEach(({ UserName, CreateDate }) => { + + for (const { UserName, CreateDate } of response.Users) { console.log(`${UserName} created on: ${CreateDate}`); - }); + } return response; }; // snippet-end:[iam.JavaScript.users.listUsersV3] diff --git a/javascriptv3/example_code/iam/actions/put-role-policy.js b/javascriptv3/example_code/iam/actions/put-role-policy.js index e208bfcfca8..fecfb960e86 100644 --- a/javascriptv3/example_code/iam/actions/put-role-policy.js +++ b/javascriptv3/example_code/iam/actions/put-role-policy.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.actions.PutRolePolicy] import { PutRolePolicyCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/update-access-key.js b/javascriptv3/example_code/iam/actions/update-access-key.js index 147e0eea202..505f7df44e0 100644 --- a/javascriptv3/example_code/iam/actions/update-access-key.js +++ b/javascriptv3/example_code/iam/actions/update-access-key.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.keys.updateAccessKeyV3] import { diff --git a/javascriptv3/example_code/iam/actions/update-server-certificate.js b/javascriptv3/example_code/iam/actions/update-server-certificate.js index 55203f6613a..22489393e05 100644 --- a/javascriptv3/example_code/iam/actions/update-server-certificate.js +++ b/javascriptv3/example_code/iam/actions/update-server-certificate.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.certs.updateServerCertificateV3] import { UpdateServerCertificateCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/update-user.js b/javascriptv3/example_code/iam/actions/update-user.js index 331fb163454..bd4c9330f2a 100644 --- a/javascriptv3/example_code/iam/actions/update-user.js +++ b/javascriptv3/example_code/iam/actions/update-user.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[iam.JavaScript.users.updateUserV3] import { UpdateUserCommand, IAMClient } from "@aws-sdk/client-iam"; diff --git a/javascriptv3/example_code/iam/actions/upload-server-certificate.js b/javascriptv3/example_code/iam/actions/upload-server-certificate.js index 79dba0b6620..32ccb455eae 100644 --- a/javascriptv3/example_code/iam/actions/upload-server-certificate.js +++ b/javascriptv3/example_code/iam/actions/upload-server-certificate.js @@ -1,13 +1,13 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.actions.UploadServerCertificate] import { UploadServerCertificateCommand, IAMClient } from "@aws-sdk/client-iam"; -import { readFileSync } from "fs"; +import { readFileSync } from "node:fs"; import { dirnameFromMetaUrl } from "@aws-doc-sdk-examples/lib/utils/util-fs.js"; -import * as path from "path"; +import * as path from "node:path"; const client = new IAMClient({}); diff --git a/javascriptv3/example_code/iam/hello.js b/javascriptv3/example_code/iam/hello.js index c24aa472e64..078d464479f 100644 --- a/javascriptv3/example_code/iam/hello.js +++ b/javascriptv3/example_code/iam/hello.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.iam.hello] import { IAMClient, paginateListPolicies } from "@aws-sdk/client-iam"; @@ -23,10 +23,10 @@ export const listLocalPolicies = async () => { let policyCount = 0; for await (const page of paginator) { if (page.Policies) { - page.Policies.forEach((p) => { - console.log(`${p.PolicyName}`); + for (const policy of page.Policies) { + console.log(`${policy.PolicyName}`); policyCount++; - }); + } } } console.log(`Found ${policyCount} policies.`); diff --git a/javascriptv3/example_code/iam/scenarios/basic.js b/javascriptv3/example_code/iam/scenarios/basic.js index 2a6f154e1f2..61f2f1db8e0 100644 --- a/javascriptv3/example_code/iam/scenarios/basic.js +++ b/javascriptv3/example_code/iam/scenarios/basic.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.iam_scenarios.iam_basics] import { @@ -63,9 +63,8 @@ export const createUser = async (name, confirmAll = false) => { new CreateUserCommand({ UserName: name }), ); return User; - } else { - throw caught; } + throw caught; } }; diff --git a/javascriptv3/example_code/iam/tests/role-and-policy.integration.test.js b/javascriptv3/example_code/iam/tests/role-and-policy.integration.test.js index 129d29d63ec..59d5e0cee9f 100644 --- a/javascriptv3/example_code/iam/tests/role-and-policy.integration.test.js +++ b/javascriptv3/example_code/iam/tests/role-and-policy.integration.test.js @@ -74,7 +74,7 @@ describe("Role and policy test", () => { const policyName = getUniqueName("create-policy-test"); await createPolicy(policyName); - let policy = await findPolicy(policyName); + const policy = await findPolicy(policyName); if (!policy?.Arn) { throw new Error("Policy not found"); diff --git a/javascriptv3/example_code/iam/tests/service-linked-role.integration.test.js b/javascriptv3/example_code/iam/tests/service-linked-role.integration.test.js index 7a1bde6b7e6..0ad3bd8b5df 100644 --- a/javascriptv3/example_code/iam/tests/service-linked-role.integration.test.js +++ b/javascriptv3/example_code/iam/tests/service-linked-role.integration.test.js @@ -21,7 +21,7 @@ describe("Service linked role", () => { const roleName = Role.RoleName; // Get the role. - let getRoleResponse = await getRole(roleName); + const getRoleResponse = await getRole(roleName); expect(getRoleResponse.Role?.RoleName).toEqual(roleName); // Delete the role. diff --git a/javascriptv3/example_code/kinesis/actions/put-records.js b/javascriptv3/example_code/kinesis/actions/put-records.js index 243b557e14d..db2ce3baba8 100644 --- a/javascriptv3/example_code/kinesis/actions/put-records.js +++ b/javascriptv3/example_code/kinesis/actions/put-records.js @@ -42,8 +42,8 @@ export const main = async ({ streamArn }) => { }; // Call function if run directly. -import { fileURLToPath } from "url"; -import { parseArgs } from "util"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; if (process.argv[1] === fileURLToPath(import.meta.url)) { const options = { diff --git a/javascriptv3/example_code/kinesis/kinesis-cdk/cdk.json b/javascriptv3/example_code/kinesis/kinesis-cdk/cdk.json index fec77a7e41e..7e4c589ff29 100644 --- a/javascriptv3/example_code/kinesis/kinesis-cdk/cdk.json +++ b/javascriptv3/example_code/kinesis/kinesis-cdk/cdk.json @@ -1,9 +1,7 @@ { "app": "npx ts-node --prefer-ts-exts bin/kinesis-cdk.ts", "watch": { - "include": [ - "**" - ], + "include": ["**"], "exclude": [ "README.md", "cdk*.json", @@ -18,10 +16,7 @@ "context": { "@aws-cdk/aws-lambda:recognizeLayerVersion": true, "@aws-cdk/core:checkSecretUsage": true, - "@aws-cdk/core:target-partitions": [ - "aws", - "aws-cn" - ], + "@aws-cdk/core:target-partitions": ["aws", "aws-cn"], "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true, diff --git a/javascriptv3/example_code/kinesis/kinesis-cdk/lib/kinesis-cdk-stack.ts b/javascriptv3/example_code/kinesis/kinesis-cdk/lib/kinesis-cdk-stack.ts index b981fc98446..c89aeb9741b 100644 --- a/javascriptv3/example_code/kinesis/kinesis-cdk/lib/kinesis-cdk-stack.ts +++ b/javascriptv3/example_code/kinesis/kinesis-cdk/lib/kinesis-cdk-stack.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import * as cdk from "aws-cdk-lib"; -import { Construct } from "constructs"; +import type { Construct } from "constructs"; import * as kinesis from "aws-cdk-lib/aws-kinesis"; export class KinesisCdkStack extends cdk.Stack { diff --git a/javascriptv3/example_code/kinesis/kinesis-cdk/package.json b/javascriptv3/example_code/kinesis/kinesis-cdk/package.json index 133feb52104..d2918bfa7c9 100644 --- a/javascriptv3/example_code/kinesis/kinesis-cdk/package.json +++ b/javascriptv3/example_code/kinesis/kinesis-cdk/package.json @@ -20,4 +20,4 @@ "constructs": "^10.0.0", "source-map-support": "^0.5.21" } -} \ No newline at end of file +} diff --git a/javascriptv3/example_code/kinesis/kinesis-cdk/tsconfig.json b/javascriptv3/example_code/kinesis/kinesis-cdk/tsconfig.json index aaa7dc510f1..464ed774ba8 100644 --- a/javascriptv3/example_code/kinesis/kinesis-cdk/tsconfig.json +++ b/javascriptv3/example_code/kinesis/kinesis-cdk/tsconfig.json @@ -2,10 +2,7 @@ "compilerOptions": { "target": "ES2020", "module": "commonjs", - "lib": [ - "es2020", - "dom" - ], + "lib": ["es2020", "dom"], "declaration": true, "strict": true, "noImplicitAny": true, @@ -20,12 +17,7 @@ "inlineSources": true, "experimentalDecorators": true, "strictPropertyInitialization": false, - "typeRoots": [ - "./node_modules/@types" - ] + "typeRoots": ["./node_modules/@types"] }, - "exclude": [ - "node_modules", - "cdk.out" - ] + "exclude": ["node_modules", "cdk.out"] } diff --git a/javascriptv3/example_code/kinesis/tests/kinesis-actions.integration.test.js b/javascriptv3/example_code/kinesis/tests/kinesis-actions.integration.test.js index 39ee0546f77..3017f1703db 100644 --- a/javascriptv3/example_code/kinesis/tests/kinesis-actions.integration.test.js +++ b/javascriptv3/example_code/kinesis/tests/kinesis-actions.integration.test.js @@ -51,6 +51,6 @@ describe("kinesis-actions", () => { it("should successfully use the PutRecords action", async () => { // Output key comes from stack.yaml in the kinesis directory. - await main({ streamArn: outputs["ExampleStreamArn"] }); + await main({ streamArn: outputs.ExampleStreamArn }); }); }); diff --git a/javascriptv3/example_code/lambda/actions/create-function.js b/javascriptv3/example_code/lambda/actions/create-function.js index f11cc36747e..1f2811441ee 100644 --- a/javascriptv3/example_code/lambda/actions/create-function.js +++ b/javascriptv3/example_code/lambda/actions/create-function.js @@ -7,7 +7,7 @@ import { PackageType, Runtime, } from "@aws-sdk/client-lambda"; -import { readFile } from "fs/promises"; +import { readFile } from "node:fs/promises"; import { dirnameFromMetaUrl } from "@aws-doc-sdk-examples/lib/utils/util-fs.js"; const dirname = dirnameFromMetaUrl(import.meta.url); diff --git a/javascriptv3/example_code/lambda/actions/update-function-code.js b/javascriptv3/example_code/lambda/actions/update-function-code.js index ab11896a1fc..0897e561151 100644 --- a/javascriptv3/example_code/lambda/actions/update-function-code.js +++ b/javascriptv3/example_code/lambda/actions/update-function-code.js @@ -7,7 +7,7 @@ import { Runtime, Architecture, } from "@aws-sdk/client-lambda"; -import { readFile } from "fs/promises"; +import { readFile } from "node:fs/promises"; import { dirnameFromMetaUrl } from "@aws-doc-sdk-examples/lib/utils/util-fs.js"; const dirname = dirnameFromMetaUrl(import.meta.url); diff --git a/javascriptv3/example_code/lambda/actions/update-function-configuration.js b/javascriptv3/example_code/lambda/actions/update-function-configuration.js index 2efef91d72e..da698a6077e 100644 --- a/javascriptv3/example_code/lambda/actions/update-function-configuration.js +++ b/javascriptv3/example_code/lambda/actions/update-function-configuration.js @@ -4,7 +4,7 @@ import { LambdaClient, UpdateFunctionConfigurationCommand, } from "@aws-sdk/client-lambda"; -import { readFileSync } from "fs"; +import { readFileSync } from "node:fs"; import { dirnameFromMetaUrl } from "@aws-doc-sdk-examples/lib/utils/util-fs.js"; const dirname = dirnameFromMetaUrl(import.meta.url); diff --git a/javascriptv3/example_code/lambda/guide_supplements/guide-cdk-lambda-function.js b/javascriptv3/example_code/lambda/guide_supplements/guide-cdk-lambda-function.js index 3d010d130e3..d74640c5800 100644 --- a/javascriptv3/example_code/lambda/guide_supplements/guide-cdk-lambda-function.js +++ b/javascriptv3/example_code/lambda/guide_supplements/guide-cdk-lambda-function.js @@ -48,7 +48,7 @@ const routeRequest = (lambdaEvent) => { const handleGetRequest = async () => { if (process.env.BUCKET === "undefined") { - const err = new Error(`No bucket name provided.`); + const err = new Error("No bucket name provided."); err.name = "MissingBucketName"; throw err; } diff --git a/javascriptv3/example_code/lambda/hello.js b/javascriptv3/example_code/lambda/hello.js index 765668284e7..429a0dc95d9 100644 --- a/javascriptv3/example_code/lambda/hello.js +++ b/javascriptv3/example_code/lambda/hello.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.lambda.hello] import { LambdaClient, paginateListFunctions } from "@aws-sdk/client-lambda"; diff --git a/javascriptv3/example_code/lambda/scenarios/basic/command-handlers/clean-up-handler.js b/javascriptv3/example_code/lambda/scenarios/basic/command-handlers/clean-up-handler.js index 68eb38b0e9a..64bda8684f3 100644 --- a/javascriptv3/example_code/lambda/scenarios/basic/command-handlers/clean-up-handler.js +++ b/javascriptv3/example_code/lambda/scenarios/basic/command-handlers/clean-up-handler.js @@ -1,6 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { readdirSync } from "fs"; +import { readdirSync } from "node:fs"; import { log } from "@aws-doc-sdk-examples/lib/utils/util-log.js"; import { deleteFiles, diff --git a/javascriptv3/example_code/lambda/scenarios/basic/command-handlers/create-function-handler.js b/javascriptv3/example_code/lambda/scenarios/basic/command-handlers/create-function-handler.js index 8ff6391d0b6..5a57df22e98 100644 --- a/javascriptv3/example_code/lambda/scenarios/basic/command-handlers/create-function-handler.js +++ b/javascriptv3/example_code/lambda/scenarios/basic/command-handlers/create-function-handler.js @@ -13,7 +13,7 @@ const createFunctionHandler = async (commands) => { if (!(funcName && roleArn)) { log( - `Either the function name or .tmp file is missing. Did you initialize?`, + "Either the function name or .tmp file is missing. Did you initialize?", ); return; } diff --git a/javascriptv3/example_code/lambda/scenarios/basic/command-handlers/list-functions-handler.js b/javascriptv3/example_code/lambda/scenarios/basic/command-handlers/list-functions-handler.js index 5ae850c9394..357d9afd78d 100644 --- a/javascriptv3/example_code/lambda/scenarios/basic/command-handlers/list-functions-handler.js +++ b/javascriptv3/example_code/lambda/scenarios/basic/command-handlers/list-functions-handler.js @@ -21,7 +21,7 @@ const getFunctionNames = (response) => const listFunctionsHandler = async () => { try { - log(`Getting function list...`); + log("Getting function list..."); const response = await listFunctions(); const functionList = getFunctionNames(response); diff --git a/javascriptv3/example_code/lambda/scenarios/basic/index.js b/javascriptv3/example_code/lambda/scenarios/basic/index.js index ddc87bb34ef..533b76b9f14 100644 --- a/javascriptv3/example_code/lambda/scenarios/basic/index.js +++ b/javascriptv3/example_code/lambda/scenarios/basic/index.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { createInterface } from "readline"; -import { stdin as input, stdout as output } from "process"; +import { createInterface } from "node:readline"; +import { stdin as input, stdout as output } from "node:process"; import { readCommands } from "@aws-doc-sdk-examples/lib/cmd-runner.js"; import { log } from "@aws-doc-sdk-examples/lib/utils/util-log.js"; diff --git a/javascriptv3/example_code/libs/cmd-runner.js b/javascriptv3/example_code/libs/cmd-runner.js index 9ec02f06e98..807995b0b78 100644 --- a/javascriptv3/example_code/libs/cmd-runner.js +++ b/javascriptv3/example_code/libs/cmd-runner.js @@ -31,7 +31,7 @@ function readCommands({ reader, handlers }) { reader.on("line", (input) => { const commands = getCommands(input); - for (let handler of handlers) { + for (const handler of handlers) { if (handler[0](commands)) { return handler[1](commands); } diff --git a/javascriptv3/example_code/libs/logger.js b/javascriptv3/example_code/libs/logger.js index 295e4817cb4..e6518f8f0d5 100644 --- a/javascriptv3/example_code/libs/logger.js +++ b/javascriptv3/example_code/libs/logger.js @@ -34,8 +34,7 @@ export class Logger { const maxContentLength = this.lineLength - (linePrefix + lineSuffix).length; const chunks = message .split("\n") - .map((l) => l && wrap(l, maxContentLength).split("\n")) - .flat(); + .flatMap((l) => l && wrap(l, maxContentLength).split("\n")); /** * @param {string} c diff --git a/javascriptv3/example_code/libs/prompter.js b/javascriptv3/example_code/libs/prompter.js index cd079357ebf..62374631b39 100644 --- a/javascriptv3/example_code/libs/prompter.js +++ b/javascriptv3/example_code/libs/prompter.js @@ -23,8 +23,8 @@ export class Prompter { * @param {string} prompt */ checkContinue = async (prompt = "") => { - const prefix = prompt && prompt + " "; - let ok = await this.confirm({ + const prefix = prompt && `${prompt} `; + const ok = await this.confirm({ message: `${prefix}Continue?`, }); if (!ok) throw new Error("Exiting..."); diff --git a/javascriptv3/example_code/libs/scenario/scenario.js b/javascriptv3/example_code/libs/scenario/scenario.js index ae8d1a5315b..1dde561f957 100644 --- a/javascriptv3/example_code/libs/scenario/scenario.js +++ b/javascriptv3/example_code/libs/scenario/scenario.js @@ -152,11 +152,12 @@ export class ScenarioInput extends Step { if ( stepHandlerOptions.confirmAll && - this.stepOptions.default != undefined + this.stepOptions.default !== undefined ) { state[this.name] = this.stepOptions.default; return state[this.name]; - } else if (stepHandlerOptions.confirmAll) { + } + if (stepHandlerOptions.confirmAll) { if (this.stepOptions?.type === "confirm") { state[this.name] = true; return true; @@ -223,7 +224,7 @@ export class ScenarioInput extends Step { typeof this.prompt === "function" ? this.prompt(state) : this.prompt; if (!message) { - throw new Error(`Error handling ScenarioInput. Missing prompt.`); + throw new Error("Error handling ScenarioInput. Missing prompt."); } const result = await this.prompter.checkbox({ @@ -250,7 +251,7 @@ export class ScenarioInput extends Step { typeof this.prompt === "function" ? this.prompt(state) : this.prompt; if (!message) { - throw new Error(`Error handling ScenarioInput. Missing prompt.`); + throw new Error("Error handling ScenarioInput. Missing prompt."); } if (this.stepOptions?.type === "select") { @@ -280,7 +281,7 @@ export class ScenarioInput extends Step { const message = this.default ? `${prompt} (${this.default})` : prompt; if (!message) { - throw new Error(`Error handling ScenarioInput. Missing prompt.`); + throw new Error("Error handling ScenarioInput. Missing prompt."); } const result = await this.prompter.input({ message }); @@ -304,7 +305,7 @@ export class ScenarioInput extends Step { typeof this.prompt === "function" ? this.prompt(state) : this.prompt; if (!message) { - throw new Error(`Error handling ScenarioInput. Missing prompt.`); + throw new Error("Error handling ScenarioInput. Missing prompt."); } const result = await this.prompter.confirm({ diff --git a/javascriptv3/example_code/libs/sdk/cfn-outputs.js b/javascriptv3/example_code/libs/sdk/cfn-outputs.js index 6d26a387f7b..923dfa550b4 100644 --- a/javascriptv3/example_code/libs/sdk/cfn-outputs.js +++ b/javascriptv3/example_code/libs/sdk/cfn-outputs.js @@ -21,15 +21,11 @@ export const getCfnOutputs = async (stackName, region) => { ); if (!Stacks.length === 1) { throw new Error("Error getting CFN outputs. No stacks found."); - } else { - const outputs = Stacks[0].Outputs ?? []; - return outputs.reduce((prev, { OutputKey, OutputValue }) => { - return { - ...prev, - [OutputKey]: OutputValue, - }; - }, {}); } + const outputs = Stacks[0].Outputs ?? []; + return outputs.reduce((prev, { OutputKey, OutputValue }) => { + return Object.assign({}, prev, { [OutputKey]: OutputValue }); + }, {}); } catch (caught) { if ( caught instanceof Error && @@ -38,8 +34,7 @@ export const getCfnOutputs = async (stackName, region) => { const error = new Error(`Stack with id ${stackName} was not found.`); error.name = "StackNotFound"; throw error; - } else { - throw caught; } + throw caught; } }; diff --git a/javascriptv3/example_code/libs/slow-logger.js b/javascriptv3/example_code/libs/slow-logger.js index 8a94930c848..0da3473ec4b 100644 --- a/javascriptv3/example_code/libs/slow-logger.js +++ b/javascriptv3/example_code/libs/slow-logger.js @@ -44,7 +44,7 @@ export class SlowLogger extends Logger { await this._logSlow(line); line = ""; } - line += word + " "; + line += `${word} `; } } await this._logSlow(line); diff --git a/javascriptv3/example_code/libs/tests/util-csv.unit.test.js b/javascriptv3/example_code/libs/tests/util-csv.unit.test.js index ef09d1950c6..ce35b03c365 100644 --- a/javascriptv3/example_code/libs/tests/util-csv.unit.test.js +++ b/javascriptv3/example_code/libs/tests/util-csv.unit.test.js @@ -23,7 +23,7 @@ describe("util-csv", () => { // it could interfere with other tests. const filename = getUniqueName("getFirstEntry-test"); files.push(`./${filename}.tmp`); - setTmp(filename, `a,b,c\nd,e,f\ng,h,i\n`); + setTmp(filename, "a,b,c\nd,e,f\ng,h,i\n"); expect(getFirstEntry(filename)).toEqual( expect.arrayContaining(["a", "b", "c"]), @@ -40,7 +40,7 @@ describe("util-csv", () => { it("should return an array of the first elements of each entry", () => { const filename = getUniqueName("getFirstValuesFromEntries-test"); files.push(`./${filename}.tmp`); - setTmp(filename, `a,b,c\nd,e,f\ng,h,i`); + setTmp(filename, "a,b,c\nd,e,f\ng,h,i"); expect(getFirstValuesFromEntries(filename)).toEqual( expect.arrayContaining(["a", "d", "g"]), @@ -52,7 +52,7 @@ describe("util-csv", () => { it("should return an array of the second elements of each entry", () => { const filename = getUniqueName("getSecondValuesFromEntries-test"); files.push(`./${filename}.tmp`); - setTmp(filename, `a,b,c\nd,e,f\ng,h,i`); + setTmp(filename, "a,b,c\nd,e,f\ng,h,i"); expect(getSecondValuesFromEntries(filename)).toEqual( expect.arrayContaining(["b", "e", "h"]), diff --git a/javascriptv3/example_code/libs/utils/util-fs.js b/javascriptv3/example_code/libs/utils/util-fs.js index 870789bc98d..f290e3f3b38 100644 --- a/javascriptv3/example_code/libs/utils/util-fs.js +++ b/javascriptv3/example_code/libs/utils/util-fs.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { unlink, readFile } from "fs/promises"; +import { unlink, readFile } from "node:fs/promises"; import { readdirSync, createWriteStream, @@ -9,9 +9,9 @@ import { writeFileSync, existsSync, mkdirSync, -} from "fs"; +} from "node:fs"; import archiver from "archiver"; -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; import { log } from "./util-log.js"; import { splitMapTrim } from "./util-string.js"; @@ -45,7 +45,7 @@ export const handleZipWarning = (resolve) => (w) => { }; export const handleZipEnd = (resolve, path) => async () => { - log(`Zipped successfully.`); + log("Zipped successfully."); const buffer = await readFile(path); resolve(buffer); }; diff --git a/javascriptv3/example_code/libs/utils/util-log.js b/javascriptv3/example_code/libs/utils/util-log.js index b266abed997..fd24cdbe9d1 100644 --- a/javascriptv3/example_code/libs/utils/util-log.js +++ b/javascriptv3/example_code/libs/utils/util-log.js @@ -1,6 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import readline from "readline"; +import readline from "node:readline"; import { parseString } from "@aws-doc-sdk-examples/lib/utils/util-string.js"; diff --git a/javascriptv3/example_code/libs/utils/util-node.js b/javascriptv3/example_code/libs/utils/util-node.js index d7b97d4d520..cb55a8827d0 100644 --- a/javascriptv3/example_code/libs/utils/util-node.js +++ b/javascriptv3/example_code/libs/utils/util-node.js @@ -1,6 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; export const getEnv = (/** @type {string} */ key) => process.env[key]; export const setEnv = (/** @type {string} */ key, value) => { diff --git a/javascriptv3/example_code/mediaconvert/src/emc_canceljob.js b/javascriptv3/example_code/mediaconvert/src/emc_canceljob.js index 7062a487ef9..06f0b700d7c 100644 --- a/javascriptv3/example_code/mediaconvert/src/emc_canceljob.js +++ b/javascriptv3/example_code/mediaconvert/src/emc_canceljob.js @@ -26,7 +26,7 @@ const params = { Id: "JOB_ID" }; //JOB_ID const run = async () => { try { const data = await emcClient.send(new CancelJobCommand(params)); - console.log("Job " + params.Id + " is canceled"); + console.log(`Job ${params.Id} is canceled`); return data; } catch (err) { console.log("Error", err); diff --git a/javascriptv3/example_code/medical-imaging/actions/copy-image-set.js b/javascriptv3/example_code/medical-imaging/actions/copy-image-set.js index 6a045332865..e786fffc436 100644 --- a/javascriptv3/example_code/medical-imaging/actions/copy-image-set.js +++ b/javascriptv3/example_code/medical-imaging/actions/copy-image-set.js @@ -1,11 +1,11 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import {fileURLToPath} from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.imageset.copyImageSetV3] -import {CopyImageSetCommand} from "@aws-sdk/client-medical-imaging"; -import {medicalImagingClient} from "../libs/medicalImagingClient.js"; +import { CopyImageSetCommand } from "@aws-sdk/client-medical-imaging"; +import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The ID of the data store. @@ -17,128 +17,125 @@ import {medicalImagingClient} from "../libs/medicalImagingClient.js"; * @param {[string]} copySubsets - A subset of instance IDs to copy. */ export const copyImageSet = async ( - datastoreId = "xxxxxxxxxxx", - imageSetId = "xxxxxxxxxxxx", - sourceVersionId = "1", - destinationImageSetId = "", - destinationVersionId = "", - force = false, - copySubsets = [] + datastoreId = "xxxxxxxxxxx", + imageSetId = "xxxxxxxxxxxx", + sourceVersionId = "1", + destinationImageSetId = "", + destinationVersionId = "", + force = false, + copySubsets = [], ) => { - try { - const params = { - datastoreId: datastoreId, - sourceImageSetId: imageSetId, - copyImageSetInformation: { - sourceImageSet: {latestVersionId: sourceVersionId}, - }, - force: force - }; - if (destinationImageSetId !== "" && destinationVersionId !== "") { - params.copyImageSetInformation.destinationImageSet = { - imageSetId: destinationImageSetId, - latestVersionId: destinationVersionId, - }; - } - - if (copySubsets.length > 0) { - let copySubsetsJson; - copySubsetsJson = { - SchemaVersion: 1.1, - Study: { - Series: { - imageSetId: { - Instances: {} - } - } - } - }; + try { + const params = { + datastoreId: datastoreId, + sourceImageSetId: imageSetId, + copyImageSetInformation: { + sourceImageSet: { latestVersionId: sourceVersionId }, + }, + force: force, + }; + if (destinationImageSetId !== "" && destinationVersionId !== "") { + params.copyImageSetInformation.destinationImageSet = { + imageSetId: destinationImageSetId, + latestVersionId: destinationVersionId, + }; + } - for (let i = 0; i < copySubsets.length; i++) { - copySubsetsJson.Study.Series.imageSetId.Instances[ - copySubsets[i] - ] = {}; - } + if (copySubsets.length > 0) { + let copySubsetsJson; + copySubsetsJson = { + SchemaVersion: 1.1, + Study: { + Series: { + imageSetId: { + Instances: {}, + }, + }, + }, + }; - params.copyImageSetInformation.dicomCopies = copySubsetsJson; - } + for (let i = 0; i < copySubsets.length; i++) { + copySubsetsJson.Study.Series.imageSetId.Instances[copySubsets[i]] = {}; + } - const response = await medicalImagingClient.send( - new CopyImageSetCommand(params) - ); - console.log(response); - // { - // '$metadata': { - // httpStatusCode: 200, - // requestId: 'd9b219ce-cc48-4a44-a5b2-c5c3068f1ee8', - // extendedRequestId: undefined, - // cfId: undefined, - // attempts: 1, - // totalRetryDelay: 0 - // }, - // datastoreId: 'xxxxxxxxxxxxxx', - // destinationImageSetProperties: { - // createdAt: 2023-09-27T19:46:21.824Z, - // imageSetArn: 'arn:aws:medical-imaging:us-east-1:xxxxxxxxxxx:datastore/xxxxxxxxxxxxx/imageset/xxxxxxxxxxxxxxxxxxx', - // imageSetId: 'xxxxxxxxxxxxxxx', - // imageSetState: 'LOCKED', - // imageSetWorkflowStatus: 'COPYING', - // latestVersionId: '1', - // updatedAt: 2023-09-27T19:46:21.824Z - // }, - // sourceImageSetProperties: { - // createdAt: 2023-09-22T14:49:26.427Z, - // imageSetArn: 'arn:aws:medical-imaging:us-east-1:xxxxxxxxxxx:datastore/xxxxxxxxxxxxx/imageset/xxxxxxxxxxxxxxxx', - // imageSetId: 'xxxxxxxxxxxxxxxx', - // imageSetState: 'LOCKED', - // imageSetWorkflowStatus: 'COPYING_WITH_READ_ONLY_ACCESS', - // latestVersionId: '4', - // updatedAt: 2023-09-27T19:46:21.824Z - // } - // } - return response; - } catch (err) { - console.error(err); + params.copyImageSetInformation.dicomCopies = copySubsetsJson; } + + const response = await medicalImagingClient.send( + new CopyImageSetCommand(params), + ); + console.log(response); + // { + // '$metadata': { + // httpStatusCode: 200, + // requestId: 'd9b219ce-cc48-4a44-a5b2-c5c3068f1ee8', + // extendedRequestId: undefined, + // cfId: undefined, + // attempts: 1, + // totalRetryDelay: 0 + // }, + // datastoreId: 'xxxxxxxxxxxxxx', + // destinationImageSetProperties: { + // createdAt: 2023-09-27T19:46:21.824Z, + // imageSetArn: 'arn:aws:medical-imaging:us-east-1:xxxxxxxxxxx:datastore/xxxxxxxxxxxxx/imageset/xxxxxxxxxxxxxxxxxxx', + // imageSetId: 'xxxxxxxxxxxxxxx', + // imageSetState: 'LOCKED', + // imageSetWorkflowStatus: 'COPYING', + // latestVersionId: '1', + // updatedAt: 2023-09-27T19:46:21.824Z + // }, + // sourceImageSetProperties: { + // createdAt: 2023-09-22T14:49:26.427Z, + // imageSetArn: 'arn:aws:medical-imaging:us-east-1:xxxxxxxxxxx:datastore/xxxxxxxxxxxxx/imageset/xxxxxxxxxxxxxxxx', + // imageSetId: 'xxxxxxxxxxxxxxxx', + // imageSetState: 'LOCKED', + // imageSetWorkflowStatus: 'COPYING_WITH_READ_ONLY_ACCESS', + // latestVersionId: '4', + // updatedAt: 2023-09-27T19:46:21.824Z + // } + // } + return response; + } catch (err) { + console.error(err); + } }; // snippet-end:[medical-imaging.JavaScript.imageset.copyImageSetV3] // Invoke the following code if this file is being run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { - // snippet-start:[medical-imaging.JavaScript.imageset.copyImageSetV3.without_destination] - - await copyImageSet( - "12345678901234567890123456789012", - "12345678901234567890123456789012", - "1" - ); - // snippet-end:[medical-imaging.JavaScript.imageset.copyImageSetV3.without_destination] - - // snippet-start:[medical-imaging.JavaScript.imageset.copyImageSetV3.with_destination] - - await copyImageSet( - "12345678901234567890123456789012", - "12345678901234567890123456789012", - "1", - "12345678901234567890123456789012", - "1", - false, - ); - - // snippet-end:[medical-imaging.JavaScript.imageset.copyImageSetV3.with_destination] - - // snippet-start:[medical-imaging.JavaScript.imageset.copyImageSetV3.with_destination_and_subsets] - - await copyImageSet( - "12345678901234567890123456789012", - "12345678901234567890123456789012", - "1", - "12345678901234567890123456789012", - "1", - true, - ["12345678901234567890123456789012", "11223344556677889900112233445566"] - ); - - // snippet-end:[medical-imaging.JavaScript.imageset.copyImageSetV3.with_destination_and_subsets] - + // snippet-start:[medical-imaging.JavaScript.imageset.copyImageSetV3.without_destination] + + await copyImageSet( + "12345678901234567890123456789012", + "12345678901234567890123456789012", + "1", + ); + // snippet-end:[medical-imaging.JavaScript.imageset.copyImageSetV3.without_destination] + + // snippet-start:[medical-imaging.JavaScript.imageset.copyImageSetV3.with_destination] + + await copyImageSet( + "12345678901234567890123456789012", + "12345678901234567890123456789012", + "1", + "12345678901234567890123456789012", + "1", + false, + ); + + // snippet-end:[medical-imaging.JavaScript.imageset.copyImageSetV3.with_destination] + + // snippet-start:[medical-imaging.JavaScript.imageset.copyImageSetV3.with_destination_and_subsets] + + await copyImageSet( + "12345678901234567890123456789012", + "12345678901234567890123456789012", + "1", + "12345678901234567890123456789012", + "1", + true, + ["12345678901234567890123456789012", "11223344556677889900112233445566"], + ); + + // snippet-end:[medical-imaging.JavaScript.imageset.copyImageSetV3.with_destination_and_subsets] } diff --git a/javascriptv3/example_code/medical-imaging/actions/create-datastore.js b/javascriptv3/example_code/medical-imaging/actions/create-datastore.js index bbfde78d472..323332c7fb1 100644 --- a/javascriptv3/example_code/medical-imaging/actions/create-datastore.js +++ b/javascriptv3/example_code/medical-imaging/actions/create-datastore.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.datastore.createDatastoreV3] import { CreateDatastoreCommand } from "@aws-sdk/client-medical-imaging"; @@ -12,7 +12,7 @@ import { medicalImagingClient } from "../libs/medicalImagingClient.js"; */ export const createDatastore = async (datastoreName = "DATASTORE_NAME") => { const response = await medicalImagingClient.send( - new CreateDatastoreCommand({ datastoreName: datastoreName }) + new CreateDatastoreCommand({ datastoreName: datastoreName }), ); console.log(response); // { diff --git a/javascriptv3/example_code/medical-imaging/actions/delete-datastore.js b/javascriptv3/example_code/medical-imaging/actions/delete-datastore.js index dcda6b288a2..558491c89a0 100644 --- a/javascriptv3/example_code/medical-imaging/actions/delete-datastore.js +++ b/javascriptv3/example_code/medical-imaging/actions/delete-datastore.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.datastore.deleteDatastoreV3] import { DeleteDatastoreCommand } from "@aws-sdk/client-medical-imaging"; @@ -12,7 +12,7 @@ import { medicalImagingClient } from "../libs/medicalImagingClient.js"; */ export const deleteDatastore = async (datastoreId = "DATASTORE_ID") => { const response = await medicalImagingClient.send( - new DeleteDatastoreCommand({ datastoreId }) + new DeleteDatastoreCommand({ datastoreId }), ); console.log(response); // { diff --git a/javascriptv3/example_code/medical-imaging/actions/delete-image-set.js b/javascriptv3/example_code/medical-imaging/actions/delete-image-set.js index e02aca5e251..c0cbeac23cd 100644 --- a/javascriptv3/example_code/medical-imaging/actions/delete-image-set.js +++ b/javascriptv3/example_code/medical-imaging/actions/delete-image-set.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.imageset.deleteImageSetV3] import { DeleteImageSetCommand } from "@aws-sdk/client-medical-imaging"; @@ -13,13 +13,13 @@ import { medicalImagingClient } from "../libs/medicalImagingClient.js"; */ export const deleteImageSet = async ( datastoreId = "xxxxxxxxxxxxxxxx", - imageSetId = "xxxxxxxxxxxxxxxx" + imageSetId = "xxxxxxxxxxxxxxxx", ) => { const response = await medicalImagingClient.send( new DeleteImageSetCommand({ datastoreId: datastoreId, imageSetId: imageSetId, - }) + }), ); console.log(response); // { @@ -44,6 +44,6 @@ export const deleteImageSet = async ( if (process.argv[1] === fileURLToPath(import.meta.url)) { await deleteImageSet( "12345678901234567890123456789012", - "12345678901234567890123456789012" + "12345678901234567890123456789012", ); } diff --git a/javascriptv3/example_code/medical-imaging/actions/get-datastore.js b/javascriptv3/example_code/medical-imaging/actions/get-datastore.js index 280353ece3e..b7440e84648 100644 --- a/javascriptv3/example_code/medical-imaging/actions/get-datastore.js +++ b/javascriptv3/example_code/medical-imaging/actions/get-datastore.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.datastore.getDatastoreV3] import { GetDatastoreCommand } from "@aws-sdk/client-medical-imaging"; @@ -12,7 +12,7 @@ import { medicalImagingClient } from "../libs/medicalImagingClient.js"; */ export const getDatastore = async (datastoreID = "DATASTORE_ID") => { const response = await medicalImagingClient.send( - new GetDatastoreCommand({ datastoreId: datastoreID }) + new GetDatastoreCommand({ datastoreId: datastoreID }), ); console.log(response); // { @@ -33,7 +33,7 @@ export const getDatastore = async (datastoreID = "DATASTORE_ID") => { // updatedAt: 2023-08-04T18:50:36.239Z // } // } - return response["datastoreProperties"]; + return response.datastoreProperties; }; // snippet-end:[medical-imaging.JavaScript.datastore.getDatastoreV3] diff --git a/javascriptv3/example_code/medical-imaging/actions/get-dicom-import-job.js b/javascriptv3/example_code/medical-imaging/actions/get-dicom-import-job.js index 0ed7f41d962..ed0525dc956 100644 --- a/javascriptv3/example_code/medical-imaging/actions/get-dicom-import-job.js +++ b/javascriptv3/example_code/medical-imaging/actions/get-dicom-import-job.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.dicom.getDICOMImportJobV3] import { GetDICOMImportJobCommand } from "@aws-sdk/client-medical-imaging"; @@ -13,10 +13,10 @@ import { medicalImagingClient } from "../libs/medicalImagingClient.js"; */ export const getDICOMImportJob = async ( datastoreId = "xxxxxxxxxxxxxxxxxxxx", - jobId = "xxxxxxxxxxxxxxxxxxxx" + jobId = "xxxxxxxxxxxxxxxxxxxx", ) => { const response = await medicalImagingClient.send( - new GetDICOMImportJobCommand({ datastoreId: datastoreId, jobId: jobId }) + new GetDICOMImportJobCommand({ datastoreId: datastoreId, jobId: jobId }), ); console.log(response); // { diff --git a/javascriptv3/example_code/medical-imaging/actions/get-image-frame.js b/javascriptv3/example_code/medical-imaging/actions/get-image-frame.js index 102038c272a..b5f009230b5 100644 --- a/javascriptv3/example_code/medical-imaging/actions/get-image-frame.js +++ b/javascriptv3/example_code/medical-imaging/actions/get-image-frame.js @@ -1,8 +1,8 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; -import { writeFileSync } from "fs"; +import { fileURLToPath } from "node:url"; +import { writeFileSync } from "node:fs"; // snippet-start:[medical-imaging.JavaScript.imageset.getImageFrameV3] import { GetImageFrameCommand } from "@aws-sdk/client-medical-imaging"; @@ -18,14 +18,14 @@ export const getImageFrame = async ( imageFrameFileName = "image.jph", datastoreID = "DATASTORE_ID", imageSetID = "IMAGE_SET_ID", - imageFrameID = "IMAGE_FRAME_ID" + imageFrameID = "IMAGE_FRAME_ID", ) => { const response = await medicalImagingClient.send( new GetImageFrameCommand({ datastoreId: datastoreID, imageSetId: imageSetID, imageFrameInformation: { imageFrameId: imageFrameID }, - }) + }), ); const buffer = await response.imageFrameBlob.transformToByteArray(); writeFileSync(imageFrameFileName, buffer); @@ -53,6 +53,6 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { "test.jph", "12345678901234567890123456789012", "12345678901234567890123456789012", - "12345678901234567890123456789012" + "12345678901234567890123456789012", ); } diff --git a/javascriptv3/example_code/medical-imaging/actions/get-image-set-metadata.js b/javascriptv3/example_code/medical-imaging/actions/get-image-set-metadata.js index 3805923d361..a0cacaccd6d 100644 --- a/javascriptv3/example_code/medical-imaging/actions/get-image-set-metadata.js +++ b/javascriptv3/example_code/medical-imaging/actions/get-image-set-metadata.js @@ -1,12 +1,12 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.imageset.getImageSetMetadataV3] import { GetImageSetMetadataCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; -import { writeFileSync } from "fs"; +import { writeFileSync } from "node:fs"; /** * @param {string} metadataFileName - The name of the file for the gzipped metadata. @@ -18,7 +18,7 @@ export const getImageSetMetadata = async ( metadataFileName = "metadata.json.gzip", datastoreId = "xxxxxxxxxxxxxx", imagesetId = "xxxxxxxxxxxxxx", - versionID = "" + versionID = "", ) => { const params = { datastoreId: datastoreId, imageSetId: imagesetId }; @@ -27,7 +27,7 @@ export const getImageSetMetadata = async ( } const response = await medicalImagingClient.send( - new GetImageSetMetadataCommand(params) + new GetImageSetMetadataCommand(params), ); const buffer = await response.imageSetMetadataBlob.transformToByteArray(); writeFileSync(metadataFileName, buffer); @@ -59,7 +59,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { await getImageSetMetadata( "metadata.json.gzip", "12345678901234567890123456789012", - "12345678901234567890123456789012" + "12345678901234567890123456789012", ); } catch (err) { console.log("Error", err); @@ -72,7 +72,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { "metadata2.json.gzip", "12345678901234567890123456789012", "12345678901234567890123456789012", - "1" + "1", ); } catch (err) { console.log("Error", err); diff --git a/javascriptv3/example_code/medical-imaging/actions/get-image-set.js b/javascriptv3/example_code/medical-imaging/actions/get-image-set.js index 9e8d57054f8..1b5115544d6 100644 --- a/javascriptv3/example_code/medical-imaging/actions/get-image-set.js +++ b/javascriptv3/example_code/medical-imaging/actions/get-image-set.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.imageset.getImageSetV3] import { GetImageSetCommand } from "@aws-sdk/client-medical-imaging"; @@ -16,14 +16,14 @@ import { medicalImagingClient } from "../libs/medicalImagingClient.js"; export const getImageSet = async ( datastoreId = "xxxxxxxxxxxxxxx", imageSetId = "xxxxxxxxxxxxxxx", - imageSetVersion = "" + imageSetVersion = "", ) => { - let params = { datastoreId: datastoreId, imageSetId: imageSetId }; + const params = { datastoreId: datastoreId, imageSetId: imageSetId }; if (imageSetVersion !== "") { params.imageSetVersion = imageSetVersion; } const response = await medicalImagingClient.send( - new GetImageSetCommand(params) + new GetImageSetCommand(params), ); console.log(response); // { diff --git a/javascriptv3/example_code/medical-imaging/actions/list-datastores.js b/javascriptv3/example_code/medical-imaging/actions/list-datastores.js index 81a4d60547f..1a3701147d8 100644 --- a/javascriptv3/example_code/medical-imaging/actions/list-datastores.js +++ b/javascriptv3/example_code/medical-imaging/actions/list-datastores.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.datastore.listDatastoresV3] import { paginateListDatastores } from "@aws-sdk/client-medical-imaging"; @@ -22,7 +22,7 @@ export const listDatastores = async () => { const datastoreSummaries = []; for await (const page of paginator) { // Each page contains a list of `jobSummaries`. The list is truncated if is larger than `pageSize`. - datastoreSummaries.push(...page["datastoreSummaries"]); + datastoreSummaries.push(...page.datastoreSummaries); console.log(page); } // { diff --git a/javascriptv3/example_code/medical-imaging/actions/list-dicom-import-jobs.js b/javascriptv3/example_code/medical-imaging/actions/list-dicom-import-jobs.js index 9edcd8d083d..bbd5d0bd393 100644 --- a/javascriptv3/example_code/medical-imaging/actions/list-dicom-import-jobs.js +++ b/javascriptv3/example_code/medical-imaging/actions/list-dicom-import-jobs.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.dicom.listDICOMImportJobsV3] import { paginateListDICOMImportJobs } from "@aws-sdk/client-medical-imaging"; @@ -11,7 +11,7 @@ import { medicalImagingClient } from "../libs/medicalImagingClient.js"; * @param {string} datastoreId - The ID of the data store. */ export const listDICOMImportJobs = async ( - datastoreId = "xxxxxxxxxxxxxxxxxx" + datastoreId = "xxxxxxxxxxxxxxxxxx", ) => { const paginatorConfig = { client: medicalImagingClient, @@ -21,10 +21,10 @@ export const listDICOMImportJobs = async ( const commandParams = { datastoreId: datastoreId }; const paginator = paginateListDICOMImportJobs(paginatorConfig, commandParams); - let jobSummaries = []; + const jobSummaries = []; for await (const page of paginator) { // Each page contains a list of `jobSummaries`. The list is truncated if is larger than `pageSize`. - jobSummaries.push(...page["jobSummaries"]); + jobSummaries.push(...page.jobSummaries); console.log(page); } // { diff --git a/javascriptv3/example_code/medical-imaging/actions/list-image-set-versions.js b/javascriptv3/example_code/medical-imaging/actions/list-image-set-versions.js index cb64e11540d..49dbe6691b7 100644 --- a/javascriptv3/example_code/medical-imaging/actions/list-image-set-versions.js +++ b/javascriptv3/example_code/medical-imaging/actions/list-image-set-versions.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.imageset.listImageSetVersionsV3] import { paginateListImageSetVersions } from "@aws-sdk/client-medical-imaging"; @@ -13,7 +13,7 @@ import { medicalImagingClient } from "../libs/medicalImagingClient.js"; */ export const listImageSetVersions = async ( datastoreId = "xxxxxxxxxxxx", - imageSetId = "xxxxxxxxxxxx" + imageSetId = "xxxxxxxxxxxx", ) => { const paginatorConfig = { client: medicalImagingClient, @@ -23,13 +23,13 @@ export const listImageSetVersions = async ( const commandParams = { datastoreId, imageSetId }; const paginator = paginateListImageSetVersions( paginatorConfig, - commandParams + commandParams, ); - let imageSetPropertiesList = []; + const imageSetPropertiesList = []; for await (const page of paginator) { // Each page contains a list of `jobSummaries`. The list is truncated if is larger than `pageSize`. - imageSetPropertiesList.push(...page["imageSetPropertiesList"]); + imageSetPropertiesList.push(...page.imageSetPropertiesList); console.log(page); } // { diff --git a/javascriptv3/example_code/medical-imaging/actions/list-tags-for-resource.js b/javascriptv3/example_code/medical-imaging/actions/list-tags-for-resource.js index 7e10692858e..d13d5176b36 100644 --- a/javascriptv3/example_code/medical-imaging/actions/list-tags-for-resource.js +++ b/javascriptv3/example_code/medical-imaging/actions/list-tags-for-resource.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.resource.listTagsForResourceV3] import { ListTagsForResourceCommand } from "@aws-sdk/client-medical-imaging"; @@ -11,10 +11,10 @@ import { medicalImagingClient } from "../libs/medicalImagingClient.js"; * @param {string} resourceArn - The Amazon Resource Name (ARN) for the data store or image set. */ export const listTagsForResource = async ( - resourceArn = "arn:aws:medical-imaging:us-east-1:abc:datastore/def/imageset/ghi" + resourceArn = "arn:aws:medical-imaging:us-east-1:abc:datastore/def/imageset/ghi", ) => { const response = await medicalImagingClient.send( - new ListTagsForResourceCommand({ resourceArn: resourceArn }) + new ListTagsForResourceCommand({ resourceArn: resourceArn }), ); console.log(response); // { @@ -36,6 +36,6 @@ export const listTagsForResource = async ( // Invoke the following code if this file is being run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { await listTagsForResource( - "arn:aws:medical-imaging:us-east-1:1234567890:datastore/123456789901234567890123456789012" + "arn:aws:medical-imaging:us-east-1:1234567890:datastore/123456789901234567890123456789012", ); } diff --git a/javascriptv3/example_code/medical-imaging/actions/search-image-sets.js b/javascriptv3/example_code/medical-imaging/actions/search-image-sets.js index 4f66bd10c49..64ab62c2152 100644 --- a/javascriptv3/example_code/medical-imaging/actions/search-image-sets.js +++ b/javascriptv3/example_code/medical-imaging/actions/search-image-sets.js @@ -1,11 +1,11 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import {fileURLToPath} from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.resource.searchImageSetV3] -import {paginateSearchImageSets} from "@aws-sdk/client-medical-imaging"; -import {medicalImagingClient} from "../libs/medicalImagingClient.js"; +import { paginateSearchImageSets } from "@aws-sdk/client-medical-imaging"; +import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The data store's ID. @@ -13,155 +13,157 @@ import {medicalImagingClient} from "../libs/medicalImagingClient.js"; * @param { import('@aws-sdk/client-medical-imaging').Sort } sort - The search criteria sort. */ export const searchImageSets = async ( - datastoreId = "xxxxxxxx", - searchCriteria = {} + datastoreId = "xxxxxxxx", + searchCriteria = {}, ) => { - const paginatorConfig = { - client: medicalImagingClient, - pageSize: 50, - }; - - const commandParams = { - datastoreId: datastoreId, - searchCriteria: searchCriteria, - }; - - const paginator = paginateSearchImageSets(paginatorConfig, commandParams); - - const imageSetsMetadataSummaries = []; - for await (const page of paginator) { - // Each page contains a list of `jobSummaries`. The list is truncated if is larger than `pageSize`. - imageSetsMetadataSummaries.push(...page["imageSetsMetadataSummaries"]); - console.log(page); - } - // { - // '$metadata': { - // httpStatusCode: 200, - // requestId: 'f009ea9c-84ca-4749-b5b6-7164f00a5ada', - // extendedRequestId: undefined, - // cfId: undefined, - // attempts: 1, - // totalRetryDelay: 0 - // }, - // imageSetsMetadataSummaries: [ - // { - // DICOMTags: [Object], - // createdAt: "2023-09-19T16:59:40.551Z", - // imageSetId: '7f75e1b5c0f40eac2b24cf712f485f50', - // updatedAt: "2023-09-19T16:59:40.551Z", - // version: 1 - // }] - // } - - return imageSetsMetadataSummaries; + const paginatorConfig = { + client: medicalImagingClient, + pageSize: 50, + }; + + const commandParams = { + datastoreId: datastoreId, + searchCriteria: searchCriteria, + }; + + const paginator = paginateSearchImageSets(paginatorConfig, commandParams); + + const imageSetsMetadataSummaries = []; + for await (const page of paginator) { + // Each page contains a list of `jobSummaries`. The list is truncated if is larger than `pageSize`. + imageSetsMetadataSummaries.push(...page.imageSetsMetadataSummaries); + console.log(page); + } + // { + // '$metadata': { + // httpStatusCode: 200, + // requestId: 'f009ea9c-84ca-4749-b5b6-7164f00a5ada', + // extendedRequestId: undefined, + // cfId: undefined, + // attempts: 1, + // totalRetryDelay: 0 + // }, + // imageSetsMetadataSummaries: [ + // { + // DICOMTags: [Object], + // createdAt: "2023-09-19T16:59:40.551Z", + // imageSetId: '7f75e1b5c0f40eac2b24cf712f485f50', + // updatedAt: "2023-09-19T16:59:40.551Z", + // version: 1 + // }] + // } + + return imageSetsMetadataSummaries; }; // snippet-end:[medical-imaging.JavaScript.resource.searchImageSetV3] // Invoke the following code if this file is being run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { - // snippet-start:[medical-imaging.JavaScript.resource.searchImageSetV3.datastoreID] - const datastoreId = "12345678901234567890123456789012"; - // snippet-end:[medical-imaging.JavaScript.resource.searchImageSetV3.datastoreID] - // Search using EQUAL operator. - // snippet-start:[medical-imaging.JavaScript.resource.searchImageSetV3.equalFilter] - try { - const searchCriteria = { - filters: [ - { - values: [{DICOMPatientId: "1234567"}], - operator: "EQUAL", - }, - ] - }; - - await searchImageSets(datastoreId, searchCriteria); - } catch (err) { - console.error(err); - } - // snippet-end:[medical-imaging.JavaScript.resource.searchImageSetV3.equalFilter] - - // Search with BETWEEN operator using DICOMStudyDate and DICOMStudyTime. - // snippet-start:[medical-imaging.JavaScript.resource.searchImageSetV3.betweenFilter1] - try { - const searchCriteria = { - filters: [ - { - values: [ - { - DICOMStudyDateAndTime: { - DICOMStudyDate: "19900101", - DICOMStudyTime: "000000", - }, - }, - { - DICOMStudyDateAndTime: { - DICOMStudyDate: "20230901", - DICOMStudyTime: "000000", - }, - }, - ], - operator: "BETWEEN", - }, - ] - }; - - await searchImageSets(datastoreId, searchCriteria); - } catch (err) { - console.error(err); - } - // snippet-end:[medical-imaging.JavaScript.resource.searchImageSetV3.betweenFilter1] - - // Search with BETWEEN operator and createdAt date. - // snippet-start:[medical-imaging.JavaScript.resource.searchImageSetV3.betweenFilter2] - try { - const searchCriteria = { - filters: [ - { - values: [ - {createdAt: new Date("1985-04-12T23:20:50.52Z")}, - {createdAt: new Date()}, - ], - operator: "BETWEEN", - }, - ] - }; + // snippet-start:[medical-imaging.JavaScript.resource.searchImageSetV3.datastoreID] + const datastoreId = "12345678901234567890123456789012"; + // snippet-end:[medical-imaging.JavaScript.resource.searchImageSetV3.datastoreID] + // Search using EQUAL operator. + // snippet-start:[medical-imaging.JavaScript.resource.searchImageSetV3.equalFilter] + try { + const searchCriteria = { + filters: [ + { + values: [{ DICOMPatientId: "1234567" }], + operator: "EQUAL", + }, + ], + }; - await searchImageSets(datastoreId, searchCriteria); - } catch (err) { - console.error(err); - } - // snippet-end:[medical-imaging.JavaScript.resource.searchImageSetV3.betweenFilter2] + await searchImageSets(datastoreId, searchCriteria); + } catch (err) { + console.error(err); + } + // snippet-end:[medical-imaging.JavaScript.resource.searchImageSetV3.equalFilter] + + // Search with BETWEEN operator using DICOMStudyDate and DICOMStudyTime. + // snippet-start:[medical-imaging.JavaScript.resource.searchImageSetV3.betweenFilter1] + try { + const searchCriteria = { + filters: [ + { + values: [ + { + DICOMStudyDateAndTime: { + DICOMStudyDate: "19900101", + DICOMStudyTime: "000000", + }, + }, + { + DICOMStudyDateAndTime: { + DICOMStudyDate: "20230901", + DICOMStudyTime: "000000", + }, + }, + ], + operator: "BETWEEN", + }, + ], + }; - // Search with EQUAL operator on DICOMSeriesInstanceUID and BETWEEN on updatedAt and sort response in ASC - // order on updatedAt field. - // snippet-start:[medical-imaging.JavaScript.resource.searchImageSetV3.sortAndFilter] - try { - const searchCriteria = { - filters: [ - { - values: [ - {updatedAt: new Date("1985-04-12T23:20:50.52Z")}, - {updatedAt: new Date()}, - ], - operator: "BETWEEN", - }, - { - values: [ - {DICOMSeriesInstanceUID: "1.1.123.123456.1.12.1.1234567890.1234.12345678.123"}, - ], - operator: "EQUAL", - }, - ], - sort: { - sortOrder: "ASC", - sortField: "updatedAt", - } - }; + await searchImageSets(datastoreId, searchCriteria); + } catch (err) { + console.error(err); + } + // snippet-end:[medical-imaging.JavaScript.resource.searchImageSetV3.betweenFilter1] + + // Search with BETWEEN operator and createdAt date. + // snippet-start:[medical-imaging.JavaScript.resource.searchImageSetV3.betweenFilter2] + try { + const searchCriteria = { + filters: [ + { + values: [ + { createdAt: new Date("1985-04-12T23:20:50.52Z") }, + { createdAt: new Date() }, + ], + operator: "BETWEEN", + }, + ], + }; - await searchImageSets(datastoreId, searchCriteria); - } catch (err) { - console.error(err); - } - // snippet-end:[medical-imaging.JavaScript.resource.searchImageSetV3.sortAndFilter] + await searchImageSets(datastoreId, searchCriteria); + } catch (err) { + console.error(err); + } + // snippet-end:[medical-imaging.JavaScript.resource.searchImageSetV3.betweenFilter2] + + // Search with EQUAL operator on DICOMSeriesInstanceUID and BETWEEN on updatedAt and sort response in ASC + // order on updatedAt field. + // snippet-start:[medical-imaging.JavaScript.resource.searchImageSetV3.sortAndFilter] + try { + const searchCriteria = { + filters: [ + { + values: [ + { updatedAt: new Date("1985-04-12T23:20:50.52Z") }, + { updatedAt: new Date() }, + ], + operator: "BETWEEN", + }, + { + values: [ + { + DICOMSeriesInstanceUID: + "1.1.123.123456.1.12.1.1234567890.1234.12345678.123", + }, + ], + operator: "EQUAL", + }, + ], + sort: { + sortOrder: "ASC", + sortField: "updatedAt", + }, + }; + await searchImageSets(datastoreId, searchCriteria); + } catch (err) { + console.error(err); + } + // snippet-end:[medical-imaging.JavaScript.resource.searchImageSetV3.sortAndFilter] } diff --git a/javascriptv3/example_code/medical-imaging/actions/start-dicom-import-job.js b/javascriptv3/example_code/medical-imaging/actions/start-dicom-import-job.js index d8562a880b0..692ed3cb11e 100644 --- a/javascriptv3/example_code/medical-imaging/actions/start-dicom-import-job.js +++ b/javascriptv3/example_code/medical-imaging/actions/start-dicom-import-job.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.dicom.startDicomImportJobV3] import { StartDICOMImportJobCommand } from "@aws-sdk/client-medical-imaging"; @@ -19,7 +19,7 @@ export const startDicomImportJob = async ( datastoreId = "12345678901234567890123456789012", dataAccessRoleArn = "arn:aws:iam::xxxxxxxxxxxx:role/ImportJobDataAccessRole", inputS3Uri = "s3://medical-imaging-dicom-input/dicom_input/", - outputS3Uri = "s3://medical-imaging-output/job_output/" + outputS3Uri = "s3://medical-imaging-output/job_output/", ) => { const response = await medicalImagingClient.send( new StartDICOMImportJobCommand({ @@ -28,7 +28,7 @@ export const startDicomImportJob = async ( dataAccessRoleArn: dataAccessRoleArn, inputS3Uri: inputS3Uri, outputS3Uri: outputS3Uri, - }) + }), ); console.log(response); // { diff --git a/javascriptv3/example_code/medical-imaging/actions/tag-resource.js b/javascriptv3/example_code/medical-imaging/actions/tag-resource.js index 85fb9d4c40a..f97654243ab 100644 --- a/javascriptv3/example_code/medical-imaging/actions/tag-resource.js +++ b/javascriptv3/example_code/medical-imaging/actions/tag-resource.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.resource.tagResourceV3] import { TagResourceCommand } from "@aws-sdk/client-medical-imaging"; @@ -14,10 +14,10 @@ import { medicalImagingClient } from "../libs/medicalImagingClient.js"; */ export const tagResource = async ( resourceArn = "arn:aws:medical-imaging:us-east-1:xxxxxx:datastore/xxxxx/imageset/xxx", - tags = {} + tags = {}, ) => { const response = await medicalImagingClient.send( - new TagResourceCommand({ resourceArn: resourceArn, tags: tags }) + new TagResourceCommand({ resourceArn: resourceArn, tags: tags }), ); console.log(response); // { @@ -39,6 +39,6 @@ export const tagResource = async ( if (process.argv[1] === fileURLToPath(import.meta.url)) { await tagResource( "arn:aws:medical-imaging:us-east-1:123502194722:datastore/728f13a131f748bf8d87a55d5ef6c5af", - { Deployment: "Development" } + { Deployment: "Development" }, ); } diff --git a/javascriptv3/example_code/medical-imaging/actions/untag-resource.js b/javascriptv3/example_code/medical-imaging/actions/untag-resource.js index c392d722dec..7161195f6a4 100644 --- a/javascriptv3/example_code/medical-imaging/actions/untag-resource.js +++ b/javascriptv3/example_code/medical-imaging/actions/untag-resource.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.resource.unTagResourceV3] import { UntagResourceCommand } from "@aws-sdk/client-medical-imaging"; @@ -13,10 +13,10 @@ import { medicalImagingClient } from "../libs/medicalImagingClient.js"; */ export const untagResource = async ( resourceArn = "arn:aws:medical-imaging:us-east-1:xxxxxx:datastore/xxxxx/imageset/xxx", - tagKeys = [] + tagKeys = [], ) => { const response = await medicalImagingClient.send( - new UntagResourceCommand({ resourceArn: resourceArn, tagKeys: tagKeys }) + new UntagResourceCommand({ resourceArn: resourceArn, tagKeys: tagKeys }), ); console.log(response); // { @@ -38,6 +38,6 @@ export const untagResource = async ( if (process.argv[1] === fileURLToPath(import.meta.url)) { await untagResource( "arn:aws:medical-imaging:us-east-1:123502194722:datastore/728f13a131f748bf8d87a55d5ef6c5af", - ["Deployment"] + ["Deployment"], ); } diff --git a/javascriptv3/example_code/medical-imaging/actions/update-image-set-metadata.js b/javascriptv3/example_code/medical-imaging/actions/update-image-set-metadata.js index c2133008006..c304a257453 100644 --- a/javascriptv3/example_code/medical-imaging/actions/update-image-set-metadata.js +++ b/javascriptv3/example_code/medical-imaging/actions/update-image-set-metadata.js @@ -1,15 +1,15 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 /* -* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -* SPDX-License-Identifier: Apache-2.0 -*/ + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ -import {fileURLToPath} from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3] -import {UpdateImageSetMetadataCommand} from "@aws-sdk/client-medical-imaging"; -import {medicalImagingClient} from "../libs/medicalImagingClient.js"; +import { UpdateImageSetMetadataCommand } from "@aws-sdk/client-medical-imaging"; +import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The ID of the HealthImaging data store. @@ -18,137 +18,149 @@ import {medicalImagingClient} from "../libs/medicalImagingClient.js"; * @param {{}} updateMetadata - The metadata to update. * @param {boolean} force - Force the update. */ -export const updateImageSetMetadata = async (datastoreId = "xxxxxxxxxx", - imageSetId = "xxxxxxxxxx", - latestVersionId = "1", - updateMetadata = '{}', - force = false) => { - try { - const response = await medicalImagingClient.send( - new UpdateImageSetMetadataCommand({ - datastoreId: datastoreId, - imageSetId: imageSetId, - latestVersionId: latestVersionId, - updateImageSetMetadataUpdates: updateMetadata, - force: force, - }) - ); - console.log(response); - // { - // '$metadata': { - // httpStatusCode: 200, - // requestId: '7966e869-e311-4bff-92ec-56a61d3003ea', - // extendedRequestId: undefined, - // cfId: undefined, - // attempts: 1, - // totalRetryDelay: 0 - // }, - // createdAt: 2023-09-22T14:49:26.427Z, - // datastoreId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', - // imageSetId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', - // imageSetState: 'LOCKED', - // imageSetWorkflowStatus: 'UPDATING', - // latestVersionId: '4', - // updatedAt: 2023-09-27T19:41:43.494Z - // } - return response; - } catch (err) { - console.error(err); - } +export const updateImageSetMetadata = async ( + datastoreId = "xxxxxxxxxx", + imageSetId = "xxxxxxxxxx", + latestVersionId = "1", + updateMetadata = "{}", + force = false, +) => { + try { + const response = await medicalImagingClient.send( + new UpdateImageSetMetadataCommand({ + datastoreId: datastoreId, + imageSetId: imageSetId, + latestVersionId: latestVersionId, + updateImageSetMetadataUpdates: updateMetadata, + force: force, + }), + ); + console.log(response); + // { + // '$metadata': { + // httpStatusCode: 200, + // requestId: '7966e869-e311-4bff-92ec-56a61d3003ea', + // extendedRequestId: undefined, + // cfId: undefined, + // attempts: 1, + // totalRetryDelay: 0 + // }, + // createdAt: 2023-09-22T14:49:26.427Z, + // datastoreId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', + // imageSetId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', + // imageSetState: 'LOCKED', + // imageSetWorkflowStatus: 'UPDATING', + // latestVersionId: '4', + // updatedAt: 2023-09-27T19:41:43.494Z + // } + return response; + } catch (err) { + console.error(err); + } }; // snippet-end:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3] // Invoke the following code if this file is being run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { - // Add a new attribute to the image set metadata. - const datastoreID = "12345678901234567890123456789012"; - const imageSetID = "12345678901234567890123456789012"; - const versionID = "1"; - const updateType = "insert"; // or "remove-attribute" or "remove_instance". - if (updateType === "insert") { - // Insert or update an attribute. -// snippet-start:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.insert_or_update_attributes] - const insertAttributes = - JSON.stringify({ - "SchemaVersion": 1.1, - "Study": { - "DICOM": { - "StudyDescription": "CT CHEST" - } - } - }); + // Add a new attribute to the image set metadata. + const datastoreID = "12345678901234567890123456789012"; + const imageSetID = "12345678901234567890123456789012"; + const versionID = "1"; + const updateType = "insert"; // or "remove-attribute" or "remove_instance". + if (updateType === "insert") { + // Insert or update an attribute. + // snippet-start:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.insert_or_update_attributes] + const insertAttributes = JSON.stringify({ + SchemaVersion: 1.1, + Study: { + DICOM: { + StudyDescription: "CT CHEST", + }, + }, + }); - const updateMetadata = { - "DICOMUpdates": { - "updatableAttributes": - new TextEncoder().encode(insertAttributes) - } - }; + const updateMetadata = { + DICOMUpdates: { + updatableAttributes: new TextEncoder().encode(insertAttributes), + }, + }; - await updateImageSetMetadata(datastoreID, imageSetID, - versionID, updateMetadata, true); -// snippet-end:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.insert_or_update_attributes] - } else if (updateType === "remove_attribute") { - // Remove an existing attribute. -// snippet-start:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.remove_attributes] - // Attribute key and value must match the existing attribute. - const remove_attribute = - JSON.stringify({ - "SchemaVersion": 1.1, - "Study": { - "DICOM": { - "StudyDescription": "CT CHEST" - } - } - }); + await updateImageSetMetadata( + datastoreID, + imageSetID, + versionID, + updateMetadata, + true, + ); + // snippet-end:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.insert_or_update_attributes] + } else if (updateType === "remove_attribute") { + // Remove an existing attribute. + // snippet-start:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.remove_attributes] + // Attribute key and value must match the existing attribute. + const remove_attribute = JSON.stringify({ + SchemaVersion: 1.1, + Study: { + DICOM: { + StudyDescription: "CT CHEST", + }, + }, + }); - const updateMetadata = { - "DICOMUpdates": { - "removableAttributes": - new TextEncoder().encode(remove_attribute) - } - }; + const updateMetadata = { + DICOMUpdates: { + removableAttributes: new TextEncoder().encode(remove_attribute), + }, + }; - await updateImageSetMetadata(datastoreID, imageSetID, - versionID, updateMetadata); -// snippet-end:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.remove_attributes] - } else if (updateType === "remove_instance") { - // Remove an existing instance. -// snippet-start:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.remove_instance] - const remove_instance = - JSON.stringify({ - "SchemaVersion": 1.1, - "Study": { - "Series": { - "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": { - "Instances": { - "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": {} - } - } - } - } - }); + await updateImageSetMetadata( + datastoreID, + imageSetID, + versionID, + updateMetadata, + ); + // snippet-end:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.remove_attributes] + } else if (updateType === "remove_instance") { + // Remove an existing instance. + // snippet-start:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.remove_instance] + const remove_instance = JSON.stringify({ + SchemaVersion: 1.1, + Study: { + Series: { + "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": { + Instances: { + "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": {}, + }, + }, + }, + }, + }); - const updateMetadata = { - "DICOMUpdates": { - "removableAttributes": - new TextEncoder().encode(remove_instance) - } - }; + const updateMetadata = { + DICOMUpdates: { + removableAttributes: new TextEncoder().encode(remove_instance), + }, + }; - await updateImageSetMetadata(datastoreID, imageSetID, - versionID, updateMetadata); -// snippet-end:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.remove_instance] - } else if (updateType === "revert") { + await updateImageSetMetadata( + datastoreID, + imageSetID, + versionID, + updateMetadata, + ); + // snippet-end:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.remove_instance] + } else if (updateType === "revert") { // Remove an existing instance. -// snippet-start:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.revert] + // snippet-start:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.revert] const updateMetadata = { - "revertToVersionId": "1" + revertToVersionId: "1", }; - await updateImageSetMetadata(datastoreID, imageSetID, - versionID, updateMetadata); -// snippet-end:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.revert] + await updateImageSetMetadata( + datastoreID, + imageSetID, + versionID, + updateMetadata, + ); + // snippet-end:[medical-imaging.JavaScript.datastore.updateImageSetMetadataV3.revert] + } } -} - diff --git a/javascriptv3/example_code/medical-imaging/hello.js b/javascriptv3/example_code/medical-imaging/hello.js index a682fa3bcfe..8543a04f90c 100644 --- a/javascriptv3/example_code/medical-imaging/hello.js +++ b/javascriptv3/example_code/medical-imaging/hello.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; // snippet-start:[javascript.v3.medical-imaging.hello] import { diff --git a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/dataset-steps.js b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/dataset-steps.js index cdb4b73f529..b40cbfdcde9 100644 --- a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/dataset-steps.js +++ b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/dataset-steps.js @@ -67,7 +67,7 @@ export const copyDataset = new ScenarioAction( "copyDataset", async (/** @type { State } */ state) => { const inputBucket = state.stackOutputs.BucketName; - const inputPrefix = `input/`; + const inputPrefix = "input/"; const selectedDatasetId = state.selectDataset; const sourceBucket = "idc-open-data"; diff --git a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/deploy-steps.js b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/deploy-steps.js index 3418554f157..ada044c3b41 100644 --- a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/deploy-steps.js +++ b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/deploy-steps.js @@ -95,7 +95,7 @@ export const waitForStackCreation = new ScenarioAction( await retry({ intervalInMs: 10000, maxRetries: 60 }, async () => { const response = await cfnClient.send(command); const stack = response.Stacks?.find( - (s) => s.StackName == state.getStackName, + (s) => s.StackName === state.getStackName, ); if (!stack || stack.StackStatus === "CREATE_IN_PROGRESS") { throw new Error("Stack creation is still in progress"); diff --git a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/image-frame-steps.js b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/image-frame-steps.js index 47081abf0f1..3584ed76513 100644 --- a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/image-frame-steps.js +++ b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/image-frame-steps.js @@ -4,8 +4,8 @@ import { MedicalImagingClient, GetImageSetMetadataCommand, } from "@aws-sdk/client-medical-imaging"; -import { gunzip } from "zlib"; -import { promisify } from "util"; +import { gunzip } from "node:zlib"; +import { promisify } from "node:util"; import { ScenarioAction, diff --git a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/image-set-steps.js b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/image-set-steps.js index 116e9438e7e..4ac3b72f2e1 100644 --- a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/image-set-steps.js +++ b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/image-set-steps.js @@ -43,12 +43,11 @@ export const parseManifestFile = new ScenarioAction( "parseManifestFile", (/** @type {State} */ state) => { const imageSetIds = - state.manifestContent.jobSummary.imageSetsSummary.reduce( - (imageSetIds, next) => { - return { ...imageSetIds, [next.imageSetId]: next.imageSetId }; - }, - {}, - ); + state.manifestContent.jobSummary.imageSetsSummary.reduce((ids, next) => { + return Object.assign({}, ids, { + [next.imageSetId]: next.imageSetId, + }); + }, {}); state.imageSetIds = Object.keys(imageSetIds); }, ); diff --git a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/index.js b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/index.js index 7eb0f5044fb..7903a30c2d2 100644 --- a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/index.js +++ b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/index.js @@ -95,7 +95,7 @@ const scenarios = { }; // Call function if run directly -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { parseScenarioArgs(scenarios); } diff --git a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification/index.js b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification/index.js index 62825c499ee..179c1e44a76 100644 --- a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification/index.js +++ b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification/index.js @@ -2,17 +2,21 @@ // SPDX-License-Identifier: MIT-0 // gunzip to decompress metadata response -const zlib = require('zlib'); -const util = require('util'); +const zlib = require("node:zlib"); +const util = require("node:util"); const gunzip = util.promisify(zlib.gunzip); -const CRC32 = require('crc-32'); +const CRC32 = require("crc-32"); // js/webassembly build of openjph -const openjphjs = require('./openjphjs/openjphjs.js'); +const openjphjs = require("./openjphjs/openjphjs.js"); // aws healthimaging js sdk v3 -const AHI_REGION = ''; -const { MedicalImagingClient, GetImageSetMetadataCommand, GetImageFrameCommand } = require('@aws-sdk/client-medical-imaging'); +const AHI_REGION = ""; +const { + MedicalImagingClient, + GetImageSetMetadataCommand, + GetImageFrameCommand, +} = require("@aws-sdk/client-medical-imaging"); let imagingClientConfig; if (AHI_REGION) imagingClientConfig.endpoint = AHI_REGION; const miClient = new MedicalImagingClient(imagingClientConfig); @@ -23,73 +27,87 @@ const miClient = new MedicalImagingClient(imagingClientConfig); * @param {string} sopInstanceUid - SOP instance UID * @return {Array} array of image frame IDs { ID: "imageFrameId" } */ -const getImageFrameForSopInstance = (metadata, seriesInstanceUid, sopInstanceUid) => { - try { - return metadata.Study.Series[seriesInstanceUid].Instances[sopInstanceUid].ImageFrames; - } - catch (e) { - throw 'Unable to get image frame ID from metadata. Check series and SOP instance UIDs.'; - } +const getImageFrameForSopInstance = ( + metadata, + seriesInstanceUid, + sopInstanceUid, +) => { + try { + return metadata.Study.Series[seriesInstanceUid].Instances[sopInstanceUid] + .ImageFrames; + } catch (e) { + throw "Unable to get image frame ID from metadata. Check series and SOP instance UIDs."; + } }; openjphjs.onRuntimeInitialized = async (_) => { - const decoder = new openjphjs.HTJ2KDecoder(); + const decoder = new openjphjs.HTJ2KDecoder(); - if (process.argv.length < 5) { - console.log('node index.js '); - process.exit(1); - } - const datastoreId = process.argv[2]; - const imageSetId = process.argv[3]; - const seriesInstanceUid = process.argv[4]; - const sopInstanceUid = process.argv[5]; + if (process.argv.length < 5) { + console.log( + "node index.js ", + ); + process.exit(1); + } + const datastoreId = process.argv[2]; + const imageSetId = process.argv[3]; + const seriesInstanceUid = process.argv[4]; + const sopInstanceUid = process.argv[5]; - // get the imageset metadata - const getImageSetMetadataInput = { - datastoreId: datastoreId, - imageSetId: imageSetId, - }; - const getImageSetMetadataCmd = new GetImageSetMetadataCommand(getImageSetMetadataInput); - const getImageSetMetadataRsp = await miClient.send(getImageSetMetadataCmd); - const imageSetMetadataBlobByteArray = await getImageSetMetadataRsp.imageSetMetadataBlob.transformToByteArray(); - const imageSetMetadataBuffer = await gunzip(imageSetMetadataBlobByteArray); - const imageSetMetadata = JSON.parse(imageSetMetadataBuffer); + // get the imageset metadata + const getImageSetMetadataInput = { + datastoreId: datastoreId, + imageSetId: imageSetId, + }; + const getImageSetMetadataCmd = new GetImageSetMetadataCommand( + getImageSetMetadataInput, + ); + const getImageSetMetadataRsp = await miClient.send(getImageSetMetadataCmd); + const imageSetMetadataBlobByteArray = + await getImageSetMetadataRsp.imageSetMetadataBlob.transformToByteArray(); + const imageSetMetadataBuffer = await gunzip(imageSetMetadataBlobByteArray); + const imageSetMetadata = JSON.parse(imageSetMetadataBuffer); - // lookup the ImageFrame for the sopInstanceUid - const imageFrameMeta = getImageFrameForSopInstance(imageSetMetadata, seriesInstanceUid, sopInstanceUid); - const imageFrameId = imageFrameMeta[0].ID; + // lookup the ImageFrame for the sopInstanceUid + const imageFrameMeta = getImageFrameForSopInstance( + imageSetMetadata, + seriesInstanceUid, + sopInstanceUid, + ); + const imageFrameId = imageFrameMeta[0].ID; - // get the image frame - const getImageFrameInput = { - datastoreId: datastoreId, - imageSetId: imageSetId, - imageFrameInformation: { - imageFrameId: imageFrameId, - }, - }; - const getImageFrameCmd = new GetImageFrameCommand(getImageFrameInput); - const getImageFrameRsp = await miClient.send(getImageFrameCmd); - const imageFrameData = await getImageFrameRsp.imageFrameBlob.transformToByteArray(); + // get the image frame + const getImageFrameInput = { + datastoreId: datastoreId, + imageSetId: imageSetId, + imageFrameInformation: { + imageFrameId: imageFrameId, + }, + }; + const getImageFrameCmd = new GetImageFrameCommand(getImageFrameInput); + const getImageFrameRsp = await miClient.send(getImageFrameCmd); + const imageFrameData = + await getImageFrameRsp.imageFrameBlob.transformToByteArray(); - // decode the image frame - const encodedBuffer = decoder.getEncodedBuffer(imageFrameData.length); - encodedBuffer.set(imageFrameData); - decoder.decode(); - const decodedBuffer = decoder.getDecodedBuffer(); + // decode the image frame + const encodedBuffer = decoder.getEncodedBuffer(imageFrameData.length); + encodedBuffer.set(imageFrameData); + decoder.decode(); + const decodedBuffer = decoder.getDecodedBuffer(); - // calculate the CRC32 for the image frame - const fullResCRC32Signed = CRC32.buf(decodedBuffer); - const fullResCRC32 = fullResCRC32Signed >>> 0; // convert to unsigned - - // compare it to the value in the metadata - const fullResCRC32FromMeta = - imageFrameMeta[0].PixelDataChecksumFromBaseToFullResolution[ - imageFrameMeta[0].PixelDataChecksumFromBaseToFullResolution.length - 1 - ].Checksum; + // calculate the CRC32 for the image frame + const fullResCRC32Signed = CRC32.buf(decodedBuffer); + const fullResCRC32 = fullResCRC32Signed >>> 0; // convert to unsigned - if (fullResCRC32 === fullResCRC32FromMeta) { - console.log('CRC32 match!'); - } else { - console.log('CRC32 does NOT match!'); - } + // compare it to the value in the metadata + const fullResCRC32FromMeta = + imageFrameMeta[0].PixelDataChecksumFromBaseToFullResolution[ + imageFrameMeta[0].PixelDataChecksumFromBaseToFullResolution.length - 1 + ].Checksum; + + if (fullResCRC32 === fullResCRC32FromMeta) { + console.log("CRC32 match!"); + } else { + console.log("CRC32 does NOT match!"); + } }; diff --git a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification/package.json b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification/package.json index e51f133a360..c8433d7cf63 100644 --- a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification/package.json +++ b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification/package.json @@ -1,15 +1,15 @@ { - "name": "@aws-doc-sdk-examples/pixel-data-verification", - "version": "1.0.0", - "description": "", - "main": "index.js", - "author": "", - "license": "MIT", - "dependencies": { - "@aws-sdk/client-medical-imaging": "^3.427.0", - "crc-32": "^1.2.2" - }, - "devDependencies": { - "vitest": "^1.6.0" - } + "name": "@aws-doc-sdk-examples/pixel-data-verification", + "version": "1.0.0", + "description": "", + "main": "index.js", + "author": "", + "license": "MIT", + "dependencies": { + "@aws-sdk/client-medical-imaging": "^3.427.0", + "crc-32": "^1.2.2" + }, + "devDependencies": { + "vitest": "^1.6.0" + } } diff --git a/javascriptv3/example_code/medical-imaging/scenarios/tagging-datastores.js b/javascriptv3/example_code/medical-imaging/scenarios/tagging-datastores.js index cd48e1a7d07..025e3a20e07 100644 --- a/javascriptv3/example_code/medical-imaging/scenarios/tagging-datastores.js +++ b/javascriptv3/example_code/medical-imaging/scenarios/tagging-datastores.js @@ -4,7 +4,7 @@ // snippet-start:[medical-imaging.JavaScript.medical-imaging_tagging_datastores.V3] // snippet-end:[medical-imaging.JavaScript.medical-imaging_tagging_datastores.V3] -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; const { tagResource } = await import("../actions/tag-resource.js"); const { untagResource } = await import("../actions/untag-resource.js"); diff --git a/javascriptv3/example_code/medical-imaging/scenarios/tagging-imagesets.js b/javascriptv3/example_code/medical-imaging/scenarios/tagging-imagesets.js index a021a0e2602..91a9d2f7102 100644 --- a/javascriptv3/example_code/medical-imaging/scenarios/tagging-imagesets.js +++ b/javascriptv3/example_code/medical-imaging/scenarios/tagging-imagesets.js @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; const { tagResource } = await import("../actions/tag-resource.js"); const { untagResource } = await import("../actions/untag-resource.js"); diff --git a/javascriptv3/example_code/medical-imaging/tests/copy-image-set.unit.test.js b/javascriptv3/example_code/medical-imaging/tests/copy-image-set.unit.test.js index 84a7656a9e2..1eb38d79ad4 100644 --- a/javascriptv3/example_code/medical-imaging/tests/copy-image-set.unit.test.js +++ b/javascriptv3/example_code/medical-imaging/tests/copy-image-set.unit.test.js @@ -78,7 +78,7 @@ describe("copy-image-set", () => { imageSetID, sourceVersionId, destinationImageSetID, - destinationVersionId + destinationVersionId, ); expect(logSpy).toHaveBeenCalledWith(response); diff --git a/javascriptv3/example_code/medical-imaging/tests/create-delete-datastore.integration.test.js b/javascriptv3/example_code/medical-imaging/tests/create-delete-datastore.integration.test.js index d2faaf2cd60..fa8b5e4dcde 100644 --- a/javascriptv3/example_code/medical-imaging/tests/create-delete-datastore.integration.test.js +++ b/javascriptv3/example_code/medical-imaging/tests/create-delete-datastore.integration.test.js @@ -11,7 +11,7 @@ import { listDatastores } from "../actions/list-datastores.js"; describe("createDatastore/deleteDatastore", () => { let datastoreID = ""; - const datastoreName = "jstest-" + Math.floor(Math.random() * 200000000); + const datastoreName = `jstest-${Math.floor(Math.random() * 200000000)}`; it("should create and delete a data store", async () => { // Create topic. @@ -26,7 +26,7 @@ describe("createDatastore/deleteDatastore", () => { // Redundant check with test timeout. await wait(1); const getDatastoreCommandOutput = await getDatastore(datastoreID); - status = getDatastoreCommandOutput["datastoreStatus"]; + status = getDatastoreCommandOutput.datastoreStatus; counter++; } diff --git a/javascriptv3/example_code/medical-imaging/tests/get-datastore.integration.test.js b/javascriptv3/example_code/medical-imaging/tests/get-datastore.integration.test.js index 705b3f3a827..34148a79e28 100644 --- a/javascriptv3/example_code/medical-imaging/tests/get-datastore.integration.test.js +++ b/javascriptv3/example_code/medical-imaging/tests/get-datastore.integration.test.js @@ -11,7 +11,7 @@ describe("getDatastore", () => { } catch (err) { console.log(err.message); expect(err.message).toEqual( - "1 validation error detected: Value 'DATASTORE_ID' at 'datastoreId' failed to satisfy constraint: Member must satisfy regular expression pattern: [0-9a-z]{32}" + "1 validation error detected: Value 'DATASTORE_ID' at 'datastoreId' failed to satisfy constraint: Member must satisfy regular expression pattern: [0-9a-z]{32}", ); } }); diff --git a/javascriptv3/example_code/medical-imaging/tests/get-image-frame.unit.test.js b/javascriptv3/example_code/medical-imaging/tests/get-image-frame.unit.test.js index ac0fb9d455d..9a8a0fb6399 100644 --- a/javascriptv3/example_code/medical-imaging/tests/get-image-frame.unit.test.js +++ b/javascriptv3/example_code/medical-imaging/tests/get-image-frame.unit.test.js @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { describe, it, expect, vi } from "vitest"; -import * as fs from "fs"; +import * as fs from "node:fs"; const send = vi.fn(); @@ -55,7 +55,7 @@ describe("get-image-set-metadata", () => { metadataFileName, datastoreId, imageSetId, - imageFrameID + imageFrameID, ); expect(logSpy).toHaveBeenCalledWith(response); diff --git a/javascriptv3/example_code/medical-imaging/tests/get-image-set-metadata.unit.test.js b/javascriptv3/example_code/medical-imaging/tests/get-image-set-metadata.unit.test.js index 2e020ebd7ca..925f9caf98f 100644 --- a/javascriptv3/example_code/medical-imaging/tests/get-image-set-metadata.unit.test.js +++ b/javascriptv3/example_code/medical-imaging/tests/get-image-set-metadata.unit.test.js @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { describe, it, expect, vi } from "vitest"; -import * as fs from "fs"; +import * as fs from "node:fs"; const send = vi.fn(); @@ -87,7 +87,7 @@ describe("get-image-set-metadata", () => { metadataFileName, datastoreId, imageSetId, - versionID + versionID, ); expect(logSpy).toHaveBeenCalledWith(response); diff --git a/javascriptv3/example_code/medical-imaging/tests/hlth-img-dataset.unit.test.js b/javascriptv3/example_code/medical-imaging/tests/hlth-img-dataset.unit.test.js index 76d1896395d..fe2f7667cdc 100644 --- a/javascriptv3/example_code/medical-imaging/tests/hlth-img-dataset.unit.test.js +++ b/javascriptv3/example_code/medical-imaging/tests/hlth-img-dataset.unit.test.js @@ -91,12 +91,12 @@ describe("dataset-steps", () => { Prefix: sourcePrefix, }); - objectKeys.forEach((key) => + for (const key of objectKeys) { expect(copyObjectCommand).toHaveBeenCalledWith({ Bucket: targetBucket, CopySource: `/${sourceBucket}/${sourcePrefix}/${key}`, Key: `${targetPrefix}${key}`, - }), - ); + }); + } }); }); diff --git a/javascriptv3/example_code/medical-imaging/tests/hlth-img-image-frame.unit.test.js b/javascriptv3/example_code/medical-imaging/tests/hlth-img-image-frame.unit.test.js index c84d7a82909..4df74d25916 100644 --- a/javascriptv3/example_code/medical-imaging/tests/hlth-img-image-frame.unit.test.js +++ b/javascriptv3/example_code/medical-imaging/tests/hlth-img-image-frame.unit.test.js @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import { expect, it, vi, describe, beforeEach } from "vitest"; -import { gzip } from "zlib"; -import { promisify } from "util"; +import { gzip } from "node:zlib"; +import { promisify } from "node:util"; import { Scenario } from "@aws-doc-sdk-examples/lib/scenario/scenario.js"; const gzipAsync = promisify(gzip); diff --git a/javascriptv3/example_code/medical-imaging/tests/search-image-set.unit.test.js b/javascriptv3/example_code/medical-imaging/tests/search-image-set.unit.test.js index e125cfba14d..140e40977b9 100644 --- a/javascriptv3/example_code/medical-imaging/tests/search-image-set.unit.test.js +++ b/javascriptv3/example_code/medical-imaging/tests/search-image-set.unit.test.js @@ -1,63 +1,63 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import {describe, it, expect, vi} from "vitest"; +import { describe, it, expect, vi } from "vitest"; const paginateSearchImageSets = vi.fn(); vi.doMock("@aws-sdk/client-medical-imaging", async () => { - const actual = await vi.importActual("@aws-sdk/client-medical-imaging"); + const actual = await vi.importActual("@aws-sdk/client-medical-imaging"); - return { - ...actual, - paginateSearchImageSets, - }; + return { + ...actual, + paginateSearchImageSets, + }; }); -const {searchImageSets} = await import("../actions/search-image-sets.js"); +const { searchImageSets } = await import("../actions/search-image-sets.js"); describe("search-image-sets", () => { - it("should log the response", async () => { - const logSpy = vi.spyOn(console, "log"); - const datastoreId = "12345678901234567890123456789012"; - const searchCriteria = { - filters: [ - { - values: [ - {createdAt: new Date("1985-04-12T23:20:50.52Z")}, - {createdAt: new Date()}, - ], - operator: "BETWEEN", - }, - ] - }; - - const response = { - $metadata: { - httpStatusCode: 200, - requestId: "f009ea9c-84ca-4749-b5b6-7164f00a5ada", - extendedRequestId: undefined, - cfId: undefined, - attempts: 1, - totalRetryDelay: 0, - }, - imageSetsMetadataSummaries: [ - { - DICOMTags: [Object], - createdAt: "2023-09-19T16:59:40.551Z", - imageSetId: "7f75e1b5c0f40eac2b24cf712f485f50", - updatedAt: "2023-09-19T16:59:40.551Z", - version: 1, - }, - ], - }; - - paginateSearchImageSets.mockImplementationOnce(async function* () { - yield response; - }); - - await searchImageSets(datastoreId, searchCriteria); - - expect(logSpy).toHaveBeenCalledWith(response); + it("should log the response", async () => { + const logSpy = vi.spyOn(console, "log"); + const datastoreId = "12345678901234567890123456789012"; + const searchCriteria = { + filters: [ + { + values: [ + { createdAt: new Date("1985-04-12T23:20:50.52Z") }, + { createdAt: new Date() }, + ], + operator: "BETWEEN", + }, + ], + }; + + const response = { + $metadata: { + httpStatusCode: 200, + requestId: "f009ea9c-84ca-4749-b5b6-7164f00a5ada", + extendedRequestId: undefined, + cfId: undefined, + attempts: 1, + totalRetryDelay: 0, + }, + imageSetsMetadataSummaries: [ + { + DICOMTags: [Object], + createdAt: "2023-09-19T16:59:40.551Z", + imageSetId: "7f75e1b5c0f40eac2b24cf712f485f50", + updatedAt: "2023-09-19T16:59:40.551Z", + version: 1, + }, + ], + }; + + paginateSearchImageSets.mockImplementationOnce(async function* () { + yield response; }); + + await searchImageSets(datastoreId, searchCriteria); + + expect(logSpy).toHaveBeenCalledWith(response); + }); }); diff --git a/javascriptv3/example_code/medical-imaging/tests/start-dicom-import-job.unit.test.js b/javascriptv3/example_code/medical-imaging/tests/start-dicom-import-job.unit.test.js index 347c0307c4b..bc353c21284 100644 --- a/javascriptv3/example_code/medical-imaging/tests/start-dicom-import-job.unit.test.js +++ b/javascriptv3/example_code/medical-imaging/tests/start-dicom-import-job.unit.test.js @@ -38,7 +38,7 @@ describe("start-dicom-import-job", () => { datastoreId, "arn:aws:iam::xxxxxxxxxxxx:role/ImportJobDataAccessRole", "s3://medical-imaging-dicom-input/dicom_input/", - "s3://medical-imaging-output/job_output/" + "s3://medical-imaging-output/job_output/", ); expect(logSpy).toHaveBeenCalledWith(response); diff --git a/javascriptv3/example_code/medical-imaging/tests/update-image-set-metadata.unit.test.js b/javascriptv3/example_code/medical-imaging/tests/update-image-set-metadata.unit.test.js index 7bab0b87059..c5adc1a6350 100644 --- a/javascriptv3/example_code/medical-imaging/tests/update-image-set-metadata.unit.test.js +++ b/javascriptv3/example_code/medical-imaging/tests/update-image-set-metadata.unit.test.js @@ -1,72 +1,72 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import {describe, it, expect, vi} from "vitest"; +import { describe, it, expect, vi } from "vitest"; const send = vi.fn(); vi.doMock("@aws-sdk/client-medical-imaging", async () => { - const actual = await vi.importActual("@aws-sdk/client-medical-imaging"); - return { - ...actual, - MedicalImagingClient: class { - send = send; - }, - }; + const actual = await vi.importActual("@aws-sdk/client-medical-imaging"); + return { + ...actual, + MedicalImagingClient: class { + send = send; + }, + }; }); -const {updateImageSetMetadata} = await import( - "../actions/update-image-set-metadata.js" - ); +const { updateImageSetMetadata } = await import( + "../actions/update-image-set-metadata.js" +); describe("update-image-set-metadata", () => { - it("should log the response", async () => { - const logSpy = vi.spyOn(console, "log"); - const datastoreId = "12345678901234567890123456789012"; - const imageSetId = "12345678901234567890123456789012"; - const versionID = "1"; - const updatableAttributes = JSON.stringify({ - SchemaVersion: 1.1, - Patient: { - DICOM: { - PatientName: "Garcia^Gloria", - }, - }, - }); + it("should log the response", async () => { + const logSpy = vi.spyOn(console, "log"); + const datastoreId = "12345678901234567890123456789012"; + const imageSetId = "12345678901234567890123456789012"; + const versionID = "1"; + const updatableAttributes = JSON.stringify({ + SchemaVersion: 1.1, + Patient: { + DICOM: { + PatientName: "Garcia^Gloria", + }, + }, + }); - const updateMetadata = { - DICOMUpdates: { - updatableAttributes: new TextEncoder().encode(updatableAttributes), - }, - }; - const response = { - $metadata: { - httpStatusCode: 200, - requestId: "7966e869-e311-4bff-92ec-56a61d3003ea", - extendedRequestId: undefined, - cfId: undefined, - attempts: 1, - totalRetryDelay: 0, - }, - createdAt: "2023-09-22T14:49:26.427Z", - datastoreId: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - imageSetId: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - imageSetState: "LOCKED", - imageSetWorkflowStatus: "UPDATING", - latestVersionId: "4", - updatedAt: "2023-09-27T19:41:43.494Z", - }; + const updateMetadata = { + DICOMUpdates: { + updatableAttributes: new TextEncoder().encode(updatableAttributes), + }, + }; + const response = { + $metadata: { + httpStatusCode: 200, + requestId: "7966e869-e311-4bff-92ec-56a61d3003ea", + extendedRequestId: undefined, + cfId: undefined, + attempts: 1, + totalRetryDelay: 0, + }, + createdAt: "2023-09-22T14:49:26.427Z", + datastoreId: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + imageSetId: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + imageSetState: "LOCKED", + imageSetWorkflowStatus: "UPDATING", + latestVersionId: "4", + updatedAt: "2023-09-27T19:41:43.494Z", + }; - send.mockResolvedValueOnce(response); + send.mockResolvedValueOnce(response); - await updateImageSetMetadata( - datastoreId, - imageSetId, - versionID, - updateMetadata, - true - ); + await updateImageSetMetadata( + datastoreId, + imageSetId, + versionID, + updateMetadata, + true, + ); - expect(logSpy).toHaveBeenCalledWith(response); - }); + expect(logSpy).toHaveBeenCalledWith(response); + }); }); diff --git a/javascriptv3/example_code/nodegetstarted/index.js b/javascriptv3/example_code/nodegetstarted/index.js index fddc638e8bd..e6482e89422 100644 --- a/javascriptv3/example_code/nodegetstarted/index.js +++ b/javascriptv3/example_code/nodegetstarted/index.js @@ -3,7 +3,7 @@ // snippet-start:[GettingStarted.JavaScript.NodeJS.sampleV3] // This is used for getting user input. -import { createInterface } from "readline/promises"; +import { createInterface } from "node:readline/promises"; import { S3Client, @@ -29,7 +29,7 @@ export async function main() { await s3Client.send( new CreateBucketCommand({ Bucket: bucketName, - }) + }), ); // Put an object into an Amazon S3 bucket. @@ -38,7 +38,7 @@ export async function main() { Bucket: bucketName, Key: "my-first-object.txt", Body: "Hello JavaScript SDK!", - }) + }), ); // Read the object. @@ -46,7 +46,7 @@ export async function main() { new GetObjectCommand({ Bucket: bucketName, Key: "my-first-object.txt", - }) + }), ); console.log(await Body.transformToString()); @@ -64,7 +64,7 @@ export async function main() { // Create an async iterator over lists of objects in a bucket. const paginator = paginateListObjectsV2( { client: s3Client }, - { Bucket: bucketName } + { Bucket: bucketName }, ); for await (const page of paginator) { const objects = page.Contents; @@ -72,7 +72,7 @@ export async function main() { // For every object in each page, delete it. for (const object of objects) { await s3Client.send( - new DeleteObjectCommand({ Bucket: bucketName, Key: object.Key }) + new DeleteObjectCommand({ Bucket: bucketName, Key: object.Key }), ); } } @@ -85,7 +85,7 @@ export async function main() { // Call a function if this file was run directly. This allows the file // to be runnable without running on import. -import { fileURLToPath } from "url"; +import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { main(); } diff --git a/javascriptv3/example_code/personalize/src/libs/personalizeClients.js b/javascriptv3/example_code/personalize/src/libs/personalizeClients.js index db3001545da..3d23cb4fd38 100644 --- a/javascriptv3/example_code/personalize/src/libs/personalizeClients.js +++ b/javascriptv3/example_code/personalize/src/libs/personalizeClients.js @@ -8,8 +8,10 @@ import { PersonalizeEventsClient } from "@aws-sdk/client-personalize-events"; const REGION = "REGION"; //e.g. "us-east-1" // Create an Amazon Personalize service client object. -const personalizeClient = new PersonalizeClient({ region: REGION}); -const personalizeEventsClient = new PersonalizeEventsClient({ region: REGION}); -const personalizeRuntimeClient = new PersonalizeRuntimeClient({ region: REGION}); +const personalizeClient = new PersonalizeClient({ region: REGION }); +const personalizeEventsClient = new PersonalizeEventsClient({ region: REGION }); +const personalizeRuntimeClient = new PersonalizeRuntimeClient({ + region: REGION, +}); -export { personalizeClient, personalizeEventsClient, personalizeRuntimeClient }; \ No newline at end of file +export { personalizeClient, personalizeEventsClient, personalizeRuntimeClient }; diff --git a/javascriptv3/example_code/personalize/src/personalize_createBatchInferenceJob.js b/javascriptv3/example_code/personalize/src/personalize_createBatchInferenceJob.js index 161c1e56d4b..b924516a594 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createBatchInferenceJob.js +++ b/javascriptv3/example_code/personalize/src/personalize_createBatchInferenceJob.js @@ -27,8 +27,7 @@ node createBatchInferenceJob.js // snippet-start:[personalize.JavaScript.createBatchInferenceJobV3] // Get service clients module and commands using ES6 syntax. -import { CreateBatchInferenceJobCommand } from - "@aws-sdk/client-personalize"; +import { CreateBatchInferenceJobCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. @@ -37,27 +36,27 @@ import { personalizeClient } from "./libs/personalizeClients.js"; // Set the batch inference job's parameters. export const createBatchInferenceJobParam = { - jobName: 'JOB_NAME', - jobInput: { /* required */ - s3DataSource: { /* required */ - path: 'INPUT_PATH', /* required */ - // kmsKeyArn: 'INPUT_KMS_KEY_ARN' /* optional */' - } + jobName: "JOB_NAME", + jobInput: { + s3DataSource: { + path: "INPUT_PATH", + }, }, - jobOutput: { /* required */ - s3DataDestination: { /* required */ - path: 'OUTPUT_PATH', /* required */ - // kmsKeyArn: 'OUTPUT_KMS_KEY_ARN' /* optional */' - } + jobOutput: { + s3DataDestination: { + path: "OUTPUT_PATH", + }, }, - roleArn: 'ROLE_ARN', /* required */ - solutionVersionArn: 'SOLUTION_VERSION_ARN', /* required */ - numResults: 20 /* optional integer*/ + roleArn: "ROLE_ARN", + solutionVersionArn: "SOLUTION_VERSION_ARN", + numResults: 20, }; export const run = async () => { try { - const response = await personalizeClient.send(new CreateBatchInferenceJobCommand(createBatchInferenceJobParam)); + const response = await personalizeClient.send( + new CreateBatchInferenceJobCommand(createBatchInferenceJobParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { diff --git a/javascriptv3/example_code/personalize/src/personalize_createBatchSegmentJob.js b/javascriptv3/example_code/personalize/src/personalize_createBatchSegmentJob.js index 1703b247de5..ea7da7d5c07 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createBatchSegmentJob.js +++ b/javascriptv3/example_code/personalize/src/personalize_createBatchSegmentJob.js @@ -26,8 +26,7 @@ node createBatchSegmentJob.js // snippet-start:[personalize.JavaScript.createBatchSegmentJobV3] // Get service clients module and commands using ES6 syntax. -import { CreateBatchSegmentJobCommand } from - "@aws-sdk/client-personalize"; +import { CreateBatchSegmentJobCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. @@ -36,27 +35,27 @@ import { personalizeClient } from "./libs/personalizeClients.js"; // Set the batch segment job's parameters. export const createBatchSegmentJobParam = { - jobName: 'NAME', - jobInput: { /* required */ - s3DataSource: { /* required */ - path: 'INPUT_PATH', /* required */ - // kmsKeyArn: 'INPUT_KMS_KEY_ARN' /* optional */' - } + jobName: "NAME", + jobInput: { + s3DataSource: { + path: "INPUT_PATH", + }, }, - jobOutput: { /* required */ - s3DataDestination: { /* required */ - path: 'OUTPUT_PATH', /* required */ - // kmsKeyArn: 'OUTPUT_KMS_KEY_ARN' /* optional */' - } + jobOutput: { + s3DataDestination: { + path: "OUTPUT_PATH", + }, }, - roleArn: 'ROLE_ARN', /* required */ - solutionVersionArn: 'SOLUTION_VERSION_ARN', /* required */ - numResults: 20 /* optional */ + roleArn: "ROLE_ARN", + solutionVersionArn: "SOLUTION_VERSION_ARN", + numResults: 20, }; export const run = async () => { try { - const response = await personalizeClient.send(new CreateBatchSegmentJobCommand(createBatchSegmentJobParam)); + const response = await personalizeClient.send( + new CreateBatchSegmentJobCommand(createBatchSegmentJobParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { @@ -66,4 +65,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.createBatchSegmentJobV3] // For unit tests only. -// module.exports ={run, createBatchSegmentJobParam}; \ No newline at end of file +// module.exports ={run, createBatchSegmentJobParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_createCampaign.js b/javascriptv3/example_code/personalize/src/personalize_createCampaign.js index 75ee4ba669c..50d8cadc037 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createCampaign.js +++ b/javascriptv3/example_code/personalize/src/personalize_createCampaign.js @@ -22,8 +22,7 @@ node createCampaign.js // snippet-start:[personalize.JavaScript.createCampaignV3] // Get service clients module and commands using ES6 syntax. -import { CreateCampaignCommand } from - "@aws-sdk/client-personalize"; +import { CreateCampaignCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. @@ -31,14 +30,16 @@ import { personalizeClient } from "./libs/personalizeClients.js"; // Set the campaign's parameters. export const createCampaignParam = { - solutionVersionArn: 'SOLUTION_VERSION_ARN', /* required */ - name: 'NAME', /* required */ - minProvisionedTPS: 1 /* optional integer */ -} + solutionVersionArn: "SOLUTION_VERSION_ARN" /* required */, + name: "NAME" /* required */, + minProvisionedTPS: 1 /* optional integer */, +}; export const run = async () => { try { - const response = await personalizeClient.send(new CreateCampaignCommand(createCampaignParam)); + const response = await personalizeClient.send( + new CreateCampaignCommand(createCampaignParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { diff --git a/javascriptv3/example_code/personalize/src/personalize_createDataset.js b/javascriptv3/example_code/personalize/src/personalize_createDataset.js index 5a821da8f27..ccd178f6038 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createDataset.js +++ b/javascriptv3/example_code/personalize/src/personalize_createDataset.js @@ -22,8 +22,7 @@ node createDataset.js // snippet-start:[personalize.JavaScript.createDatasetV3] // Get service clients module and commands using ES6 syntax. -import { CreateDatasetCommand } from - "@aws-sdk/client-personalize"; +import { CreateDatasetCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. @@ -31,15 +30,17 @@ import { personalizeClient } from "./libs/personalizeClients.js"; // Set the dataset's parameters. export const createDatasetParam = { - datasetGroupArn: 'DATASET_GROUP_ARN', /* required */ - datasetType: 'DATASET_TYPE', /* required */ - name: 'NAME', /* required */ - schemaArn: 'SCHEMA_ARN' /* required */ -} + datasetGroupArn: "DATASET_GROUP_ARN" /* required */, + datasetType: "DATASET_TYPE" /* required */, + name: "NAME" /* required */, + schemaArn: "SCHEMA_ARN" /* required */, +}; export const run = async () => { try { - const response = await personalizeClient.send(new CreateDatasetCommand(createDatasetParam)); + const response = await personalizeClient.send( + new CreateDatasetCommand(createDatasetParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { @@ -49,4 +50,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.createDatasetV3] // For unit tests only. -// module.exports ={run, createDatasetParam}; \ No newline at end of file +// module.exports ={run, createDatasetParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_createDatasetExportJob.js b/javascriptv3/example_code/personalize/src/personalize_createDatasetExportJob.js index f5695fc8249..0dffbca7282 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createDatasetExportJob.js +++ b/javascriptv3/example_code/personalize/src/personalize_createDatasetExportJob.js @@ -23,8 +23,7 @@ node createDatasetExportJob.js // snippet-start:[personalize.JavaScript.createDatasetExportJobV3] // Get service clients module and commands using ES6 syntax. -import { CreateDatasetExportJobCommand } from - "@aws-sdk/client-personalize"; +import { CreateDatasetExportJobCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. @@ -32,20 +31,22 @@ import { personalizeClient } from "./libs/personalizeClients.js"; // Set the export job parameters. export const datasetExportJobParam = { - datasetArn: 'DATASET_ARN', /* required */ + datasetArn: "DATASET_ARN" /* required */, jobOutput: { s3DataDestination: { - path: 'S3_DESTINATION_PATH' /* required */ - //kmsKeyArn: 'ARN' /* include if your bucket uses AWS KMS for encryption - } + path: "S3_DESTINATION_PATH" /* required */, + //kmsKeyArn: 'ARN' /* include if your bucket uses AWS KMS for encryption + }, }, - jobName: 'NAME',/* required */ - roleArn: 'ROLE_ARN' /* required */ -} + jobName: "NAME" /* required */, + roleArn: "ROLE_ARN" /* required */, +}; export const run = async () => { try { - const response = await personalizeClient.send(new CreateDatasetExportJobCommand(datasetExportJobParam)); + const response = await personalizeClient.send( + new CreateDatasetExportJobCommand(datasetExportJobParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { @@ -55,4 +56,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.createDatasetExportJobV3] // For unit tests only. -// module.exports ={run, createDatasetExportJobParam}; \ No newline at end of file +// module.exports ={run, createDatasetExportJobParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_createDatasetImportJob.js b/javascriptv3/example_code/personalize/src/personalize_createDatasetImportJob.js index 916db17f0fc..8575ad2a5cb 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createDatasetImportJob.js +++ b/javascriptv3/example_code/personalize/src/personalize_createDatasetImportJob.js @@ -22,8 +22,7 @@ node createDatasetImportJob.js // snippet-start:[personalize.JavaScript.createDatasetImportJobV3] // Get service clients module and commands using ES6 syntax. -import {CreateDatasetImportJobCommand } from - "@aws-sdk/client-personalize"; +import { CreateDatasetImportJobCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. @@ -31,17 +30,20 @@ import { personalizeClient } from "./libs/personalizeClients.js"; // Set the dataset import job parameters. export const datasetImportJobParam = { - datasetArn: 'DATASET_ARN', /* required */ - dataSource: { /* required */ - dataLocation: 'S3_PATH' + datasetArn: "DATASET_ARN" /* required */, + dataSource: { + /* required */ + dataLocation: "S3_PATH", }, - jobName: 'NAME',/* required */ - roleArn: 'ROLE_ARN' /* required */ -} + jobName: "NAME" /* required */, + roleArn: "ROLE_ARN" /* required */, +}; export const run = async () => { try { - const response = await personalizeClient.send(new CreateDatasetImportJobCommand(datasetImportJobParam)); + const response = await personalizeClient.send( + new CreateDatasetImportJobCommand(datasetImportJobParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { @@ -51,4 +53,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.createDatasetImportJobV3] // For unit tests only. -// module.exports ={run, createDatasetImportJobParam}; \ No newline at end of file +// module.exports ={run, createDatasetImportJobParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_createDomainDatasetGroup.js b/javascriptv3/example_code/personalize/src/personalize_createDomainDatasetGroup.js index d773d7f08ce..21b2af4e56d 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createDomainDatasetGroup.js +++ b/javascriptv3/example_code/personalize/src/personalize_createDomainDatasetGroup.js @@ -20,8 +20,7 @@ node createDomainDatasetGroup.js // snippet-start:[personalize.JavaScript.createDomainDatasetGroupV3] // Get service clients module and commands using ES6 syntax. -import { CreateDatasetGroupCommand } from - "@aws-sdk/client-personalize"; +import { CreateDatasetGroupCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. @@ -29,13 +28,16 @@ import { personalizeClient } from "./libs/personalizeClients.js"; // Set the domain dataset group parameters. export const domainDatasetGroupParams = { - name: 'NAME', /* required */ - domain: 'DOMAIN' /* required for a domain dsg, specify ECOMMERCE or VIDEO_ON_DEMAND */ -} + name: "NAME" /* required */, + domain: + "DOMAIN" /* required for a domain dsg, specify ECOMMERCE or VIDEO_ON_DEMAND */, +}; export const run = async () => { try { - const response = await personalizeClient.send(new CreateDatasetGroupCommand(domainDatasetGroupParams)); + const response = await personalizeClient.send( + new CreateDatasetGroupCommand(domainDatasetGroupParams), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { @@ -45,4 +47,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.createDomainDatasetGroupV3] // For unit tests only. -// module.exports ={run, createDomainDatasetGroupParam}; \ No newline at end of file +// module.exports ={run, createDomainDatasetGroupParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_createDomainSchema.js b/javascriptv3/example_code/personalize/src/personalize_createDomainSchema.js index 2f45e77f9eb..24a9f26605b 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createDomainSchema.js +++ b/javascriptv3/example_code/personalize/src/personalize_createDomainSchema.js @@ -21,34 +21,36 @@ node createDomanSchema.js // snippet-start:[personalize.JavaScript.createDomainSchemaV3] // Get service clients module and commands using ES6 syntax. -import { CreateSchemaCommand } from - "@aws-sdk/client-personalize"; +import { CreateSchemaCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeClient = new PersonalizeClient({ region: "REGION"}); -import fs from 'fs'; +import fs from "node:fs"; -let schemaFilePath = "SCHEMA_PATH"; +const schemaFilePath = "SCHEMA_PATH"; let mySchema = ""; try { mySchema = fs.readFileSync(schemaFilePath).toString(); } catch (err) { - mySchema = 'TEST' // for unit tests. + mySchema = "TEST"; // for unit tests. } // Set the domain schema parameters. export const createDomainSchemaParam = { - name: 'NAME', /* required */ - schema: mySchema, /* required */ - domain: 'DOMAIN' /* required for a domain dataset group, specify ECOMMERCE or VIDEO_ON_DEMAND */ + name: "NAME" /* required */, + schema: mySchema /* required */, + domain: + "DOMAIN" /* required for a domain dataset group, specify ECOMMERCE or VIDEO_ON_DEMAND */, }; export const run = async () => { try { - const response = await personalizeClient.send(new CreateSchemaCommand(createDomainSchemaParam)); + const response = await personalizeClient.send( + new CreateSchemaCommand(createDomainSchemaParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { @@ -58,4 +60,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.createDomainSchemaV3] // For unit tests only. -// module.exports ={run, createDomainSchemaParam}; \ No newline at end of file +// module.exports ={run, createDomainSchemaParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_createEventTracker.js b/javascriptv3/example_code/personalize/src/personalize_createEventTracker.js index 6bbefeb2e04..099ebf4a058 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createEventTracker.js +++ b/javascriptv3/example_code/personalize/src/personalize_createEventTracker.js @@ -20,8 +20,7 @@ node createEventTracker.js // snippet-start:[personalize.JavaScript.createEventTrackerV3] // Get service clients module and commands using ES6 syntax. -import { CreateEventTrackerCommand } from - "@aws-sdk/client-personalize"; +import { CreateEventTrackerCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. @@ -29,13 +28,15 @@ import { personalizeClient } from "./libs/personalizeClients.js"; // Set the event tracker's parameters. export const createEventTrackerParam = { - datasetGroupArn: 'DATASET_GROUP_ARN', /* required */ - name: 'NAME', /* required */ -} + datasetGroupArn: "DATASET_GROUP_ARN" /* required */, + name: "NAME" /* required */, +}; export const run = async () => { try { - const response = await personalizeClient.send(new CreateEventTrackerCommand(createEventTrackerParam)); + const response = await personalizeClient.send( + new CreateEventTrackerCommand(createEventTrackerParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { @@ -45,4 +46,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.createEventTrackerV3] // For unit tests only. -// module.exports ={run, createEventTrackerParam}; \ No newline at end of file +// module.exports ={run, createEventTrackerParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_createFilter.js b/javascriptv3/example_code/personalize/src/personalize_createFilter.js index 03e0a69df95..f2a438b7f15 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createFilter.js +++ b/javascriptv3/example_code/personalize/src/personalize_createFilter.js @@ -20,22 +20,23 @@ node createFilter.js // snippet-start:[personalize.JavaScript.createFilterV3] // Get service clients module and commands using ES6 syntax. -import { CreateFilterCommand } from - "@aws-sdk/client-personalize"; +import { CreateFilterCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeClient = new PersonalizeClient({ region: "REGION"}); // Set the filter's parameters. export const createFilterParam = { - datasetGroupArn: 'DATASET_GROUP_ARN', /* required */ - name: 'NAME', /* required */ - filterExpression: 'FILTER_EXPRESSION' /*required */ -} + datasetGroupArn: "DATASET_GROUP_ARN" /* required */, + name: "NAME" /* required */, + filterExpression: "FILTER_EXPRESSION" /*required */, +}; export const run = async () => { try { - const response = await personalizeClient.send(new CreateFilterCommand(createFilterParam)); + const response = await personalizeClient.send( + new CreateFilterCommand(createFilterParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { @@ -45,4 +46,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.createFilterV3] // For unit tests only. -// module.exports ={run, createFilterParam}; \ No newline at end of file +// module.exports ={run, createFilterParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_createRecommender.js b/javascriptv3/example_code/personalize/src/personalize_createRecommender.js index a1f927742b8..6331ad44e4b 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createRecommender.js +++ b/javascriptv3/example_code/personalize/src/personalize_createRecommender.js @@ -21,8 +21,7 @@ node createRecommender.js // snippet-start:[personalize.JavaScript.createRecommenderV3] // Get service clients module and commands using ES6 syntax. -import { CreateRecommenderCommand } from - "@aws-sdk/client-personalize"; +import { CreateRecommenderCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. @@ -30,14 +29,16 @@ import { personalizeClient } from "./libs/personalizeClients.js"; // Set the recommender's parameters. export const createRecommenderParam = { - name: 'NAME', /* required */ - recipeArn: 'RECIPE_ARN', /* required */ - datasetGroupArn: 'DATASET_GROUP_ARN' /* required */ -} + name: "NAME" /* required */, + recipeArn: "RECIPE_ARN" /* required */, + datasetGroupArn: "DATASET_GROUP_ARN" /* required */, +}; export const run = async () => { try { - const response = await personalizeClient.send(new CreateRecommenderCommand(createRecommenderParam)); + const response = await personalizeClient.send( + new CreateRecommenderCommand(createRecommenderParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { @@ -47,4 +48,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.createRecommenderV3] // For unit tests only. -// module.exports ={run, createRecommenderParam}; \ No newline at end of file +// module.exports ={run, createRecommenderParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_createSchema.js b/javascriptv3/example_code/personalize/src/personalize_createSchema.js index 9378c688985..2ea936690f8 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createSchema.js +++ b/javascriptv3/example_code/personalize/src/personalize_createSchema.js @@ -20,32 +20,33 @@ node createSchema.js // snippet-start:[personalize.JavaScript.createSchemaV3] // Get service clients module and commands using ES6 syntax. -import { CreateSchemaCommand } from - "@aws-sdk/client-personalize"; +import { CreateSchemaCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeClient = new PersonalizeClient({ region: "REGION"}); -import fs from 'fs'; +import fs from "node:fs"; -let schemaFilePath = "SCHEMA_PATH"; +const schemaFilePath = "SCHEMA_PATH"; let mySchema = ""; try { mySchema = fs.readFileSync(schemaFilePath).toString(); } catch (err) { - mySchema = 'TEST' // For unit tests. + mySchema = "TEST"; // For unit tests. } // Set the schema parameters. export const createSchemaParam = { - name: 'NAME', /* required */ - schema: mySchema /* required */ + name: "NAME" /* required */, + schema: mySchema /* required */, }; export const run = async () => { try { - const response = await personalizeClient.send(new CreateSchemaCommand(createSchemaParam)); + const response = await personalizeClient.send( + new CreateSchemaCommand(createSchemaParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { @@ -55,4 +56,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.createSchemaV3] // For unit tests only. -// module.exports ={run, createSchemaParam}; \ No newline at end of file +// module.exports ={run, createSchemaParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_createSolution.js b/javascriptv3/example_code/personalize/src/personalize_createSolution.js index 2409894e32e..2e15bc0737b 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createSolution.js +++ b/javascriptv3/example_code/personalize/src/personalize_createSolution.js @@ -21,22 +21,23 @@ node createSolution.js // snippet-start:[personalize.JavaScript.createSolutionV3] // Get service clients module and commands using ES6 syntax. -import { CreateSolutionCommand } from - "@aws-sdk/client-personalize"; +import { CreateSolutionCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeClient = new PersonalizeClient({ region: "REGION"}); // Set the solution parameters. export const createSolutionParam = { - datasetGroupArn: 'DATASET_GROUP_ARN', /* required */ - recipeArn: 'RECIPE_ARN', /* required */ - name: 'NAME' /* required */ -} + datasetGroupArn: "DATASET_GROUP_ARN" /* required */, + recipeArn: "RECIPE_ARN" /* required */, + name: "NAME" /* required */, +}; export const run = async () => { try { - const response = await personalizeClient.send(new CreateSolutionCommand(createSolutionParam)); + const response = await personalizeClient.send( + new CreateSolutionCommand(createSolutionParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { @@ -46,4 +47,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.createSolutionV3] // For unit tests only. -// module.exports ={run, createSolutionParam}; \ No newline at end of file +// module.exports ={run, createSolutionParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_createSolutionVersion.js b/javascriptv3/example_code/personalize/src/personalize_createSolutionVersion.js index 7ba55371ed5..4e9ede225f3 100644 --- a/javascriptv3/example_code/personalize/src/personalize_createSolutionVersion.js +++ b/javascriptv3/example_code/personalize/src/personalize_createSolutionVersion.js @@ -19,20 +19,21 @@ node createSolutionVersion.js // snippet-start:[personalize.JavaScript.createSolutionVersionV3] // Get service clients module and commands using ES6 syntax. -import { CreateSolutionVersionCommand } from - "@aws-sdk/client-personalize"; +import { CreateSolutionVersionCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeClient = new PersonalizeClient({ region: "REGION"}); // Set the solution version parameters. export const solutionVersionParam = { - solutionArn: 'SOLUTION_ARN' /* required */ -} + solutionArn: "SOLUTION_ARN" /* required */, +}; export const run = async () => { try { - const response = await personalizeClient.send(new CreateSolutionVersionCommand(solutionVersionParam)); + const response = await personalizeClient.send( + new CreateSolutionVersionCommand(solutionVersionParam), + ); console.log("Success", response); return response; // For unit tests. } catch (err) { @@ -42,4 +43,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.createSolutionVersionV3] // For unit tests only. -// module.exports ={run, solutionVersionParam}; \ No newline at end of file +// module.exports ={run, solutionVersionParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_getPersonalizedRanking.js b/javascriptv3/example_code/personalize/src/personalize_getPersonalizedRanking.js index 44814dbac5c..17dd46625ce 100644 --- a/javascriptv3/example_code/personalize/src/personalize_getPersonalizedRanking.js +++ b/javascriptv3/example_code/personalize/src/personalize_getPersonalizedRanking.js @@ -21,22 +21,23 @@ node getPersonalizedRanking.js // snippet-start:[personalize.JavaScript.getPersonalizedRankingV3] // Get service clients module and commands using ES6 syntax. -import { GetPersonalizedRankingCommand } from - "@aws-sdk/client-personalize-runtime"; +import { GetPersonalizedRankingCommand } from "@aws-sdk/client-personalize-runtime"; import { personalizeRuntimeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeRuntimeClient = new PersonalizeRuntimeClient({ region: "REGION"}); // Set the ranking request parameters. export const getPersonalizedRankingParam = { - campaignArn: "CAMPAIGN_ARN", /* required */ - userId: 'USER_ID', /* required */ - inputList: ["ITEM_ID_1", "ITEM_ID_2", "ITEM_ID_3", "ITEM_ID_4"] -} + campaignArn: "CAMPAIGN_ARN" /* required */, + userId: "USER_ID" /* required */, + inputList: ["ITEM_ID_1", "ITEM_ID_2", "ITEM_ID_3", "ITEM_ID_4"], +}; export const run = async () => { try { - const response = await personalizeRuntimeClient.send(new GetPersonalizedRankingCommand(getPersonalizedRankingParam)); + const response = await personalizeRuntimeClient.send( + new GetPersonalizedRankingCommand(getPersonalizedRankingParam), + ); console.log("Success!", response); return response; // For unit tests. } catch (err) { @@ -47,4 +48,4 @@ run(); // snippet-end:[personalize.JavaScript.getPersonalizedRankingV3] // For unit tests only. -// module.exports ={run, getPersonalizedRankingParam}; \ No newline at end of file +// module.exports ={run, getPersonalizedRankingParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_getRecommendations.js b/javascriptv3/example_code/personalize/src/personalize_getRecommendations.js index 91e4fe6fbaa..c5aec45a86f 100644 --- a/javascriptv3/example_code/personalize/src/personalize_getRecommendations.js +++ b/javascriptv3/example_code/personalize/src/personalize_getRecommendations.js @@ -20,8 +20,7 @@ node getRecommendations.js // snippet-start:[personalize.JavaScript.getRecommendationsV3] // Get service clients module and commands using ES6 syntax. -import { GetRecommendationsCommand } from - "@aws-sdk/client-personalize-runtime"; +import { GetRecommendationsCommand } from "@aws-sdk/client-personalize-runtime"; import { personalizeRuntimeClient } from "./libs/personalizeClients.js"; // Or, create the client here. @@ -29,14 +28,16 @@ import { personalizeRuntimeClient } from "./libs/personalizeClients.js"; // Set the recommendation request parameters. export const getRecommendationsParam = { - campaignArn: 'CAMPAIGN_ARN', /* required */ - userId: 'USER_ID', /* required */ - numResults: 15 /* optional */ -} + campaignArn: "CAMPAIGN_ARN" /* required */, + userId: "USER_ID" /* required */, + numResults: 15 /* optional */, +}; export const run = async () => { try { - const response = await personalizeRuntimeClient.send(new GetRecommendationsCommand(getRecommendationsParam)); + const response = await personalizeRuntimeClient.send( + new GetRecommendationsCommand(getRecommendationsParam), + ); console.log("Success!", response); return response; // For unit tests. } catch (err) { @@ -47,4 +48,4 @@ run(); // snippet-end:[personalize.JavaScript.getRecommendationsV3] // For unit tests only. -// module.exports ={run, getRecommendationsParam}; \ No newline at end of file +// module.exports ={run, getRecommendationsParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_getRecommendationsFromRecommender.js b/javascriptv3/example_code/personalize/src/personalize_getRecommendationsFromRecommender.js index fbaa97eb971..65b7f8e814e 100644 --- a/javascriptv3/example_code/personalize/src/personalize_getRecommendationsFromRecommender.js +++ b/javascriptv3/example_code/personalize/src/personalize_getRecommendationsFromRecommender.js @@ -20,22 +20,23 @@ node getRecommendationsFromRecommender.js // snippet-start:[personalize.JavaScript.getRecommendationsFromRecommenderV3] // Get service clients module and commands using ES6 syntax. -import { GetRecommendationsCommand } from - "@aws-sdk/client-personalize-runtime"; +import { GetRecommendationsCommand } from "@aws-sdk/client-personalize-runtime"; import { personalizeRuntimeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeRuntimeClient = new PersonalizeRuntimeClient({ region: "REGION"}); // Set the recommendation request parameters. export const getRecommendationsParam = { - recommenderArn: 'RECOMMENDER_ARN', /* required */ - userId: 'USER_ID', /* required */ - numResults: 15 /* optional */ -} + recommenderArn: "RECOMMENDER_ARN" /* required */, + userId: "USER_ID" /* required */, + numResults: 15 /* optional */, +}; export const run = async () => { try { - const response = await personalizeRuntimeClient.send(new GetRecommendationsCommand(getRecommendationsParam)); + const response = await personalizeRuntimeClient.send( + new GetRecommendationsCommand(getRecommendationsParam), + ); console.log("Success!", response); return response; // For unit tests. } catch (err) { @@ -45,4 +46,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.getRecommendationsFromRecommenderV3] // For unit tests only. -// module.exports ={run, getRecommendationsParam}; \ No newline at end of file +// module.exports ={run, getRecommendationsParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_getRecommendationsWithFilter.js b/javascriptv3/example_code/personalize/src/personalize_getRecommendationsWithFilter.js index 6577e569883..c8fc606780f 100644 --- a/javascriptv3/example_code/personalize/src/personalize_getRecommendationsWithFilter.js +++ b/javascriptv3/example_code/personalize/src/personalize_getRecommendationsWithFilter.js @@ -22,26 +22,28 @@ node getRecommendationsWithFilter.js // snippet-start:[personalize.JavaScript.getRecommendationsWithFilterV3] // Get service clients module and commands using ES6 syntax. -import { GetRecommendationsCommand } from - "@aws-sdk/client-personalize-runtime"; +import { GetRecommendationsCommand } from "@aws-sdk/client-personalize-runtime"; import { personalizeRuntimeClient } from "./libs/personalizeClients.js"; // Or, create the client here: // const personalizeRuntimeClient = new PersonalizeRuntimeClient({ region: "REGION"}); // Set recommendation request parameters. export const getRecommendationsParam = { - campaignArn: 'CAMPAIGN_ARN', /* required */ - userId: 'USER_ID', /* required */ - numResults: 15, /* optional */ - filterArn: 'FILTER_ARN', /* required to filter recommendations */ + campaignArn: "CAMPAIGN_ARN" /* required */, + userId: "USER_ID" /* required */, + numResults: 15 /* optional */, + filterArn: "FILTER_ARN" /* required to filter recommendations */, filterValues: { - "PROPERTY": "\"VALUE\"" /* Only required if your filter has a placeholder parameter */ - } -} + PROPERTY: + '"VALUE"' /* Only required if your filter has a placeholder parameter */, + }, +}; export const run = async () => { try { - const response = await personalizeRuntimeClient.send(new GetRecommendationsCommand(getRecommendationsParam)); + const response = await personalizeRuntimeClient.send( + new GetRecommendationsCommand(getRecommendationsParam), + ); console.log("Success!", response); return response; // For unit tests. } catch (err) { @@ -51,4 +53,4 @@ export const run = async () => { run(); // snippet-end:[personalize.JavaScript.getRecommendationsWithFilterV3] // For unit tests only. -// module.exports ={run, getRecommendationsParam}; \ No newline at end of file +// module.exports ={run, getRecommendationsParam}; diff --git a/javascriptv3/example_code/personalize/src/personalize_putEvents.js b/javascriptv3/example_code/personalize/src/personalize_putEvents.js index ac8c3fcf3e1..147cf0034bf 100644 --- a/javascriptv3/example_code/personalize/src/personalize_putEvents.js +++ b/javascriptv3/example_code/personalize/src/personalize_putEvents.js @@ -32,7 +32,7 @@ import { personalizeEventsClient } from "./libs/personalizeClients.js"; const sentAtDate = new Date(1613443801 * 1000); // 1613443801 is a testing value. Replace it with your sentAt timestamp in UNIX format. // Set put events parameters. -var putEventsParam = { +const putEventsParam = { eventList: [ /* required */ { diff --git a/javascriptv3/example_code/personalize/src/personalize_putItems.js b/javascriptv3/example_code/personalize/src/personalize_putItems.js index 1eef6b0202c..7d98a9c20db 100644 --- a/javascriptv3/example_code/personalize/src/personalize_putItems.js +++ b/javascriptv3/example_code/personalize/src/personalize_putItems.js @@ -31,7 +31,7 @@ import { personalizeEventsClient } from "./libs/personalizeClients.js"; // const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION"}); // Set the put items parameters. For string properties and values, use the \ character to escape quotes. -var putItemsParam = { +const putItemsParam = { datasetArn: "DATASET_ARN" /* required */, items: [ /* required */ diff --git a/javascriptv3/example_code/personalize/src/personalize_putUsers.js b/javascriptv3/example_code/personalize/src/personalize_putUsers.js index ed34662566d..85090d0d100 100644 --- a/javascriptv3/example_code/personalize/src/personalize_putUsers.js +++ b/javascriptv3/example_code/personalize/src/personalize_putUsers.js @@ -27,7 +27,7 @@ import { personalizeEventsClient } from "./libs/personalizeClients.js"; // const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION"}); // Set the put users parameters. For string properties and values, use the \ character to escape quotes. -var putUsersParam = { +const putUsersParam = { datasetArn: "DATASET_ARN", users: [ { diff --git a/javascriptv3/example_code/pinpoint/src/pinpoint_send_email_message.js b/javascriptv3/example_code/pinpoint/src/pinpoint_send_email_message.js index b5d06cd98fa..248413516ba 100644 --- a/javascriptv3/example_code/pinpoint/src/pinpoint_send_email_message.js +++ b/javascriptv3/example_code/pinpoint/src/pinpoint_send_email_message.js @@ -29,16 +29,16 @@ const toAddress = "TO_ADDRESS"; const projectId = "PINPOINT_PROJECT_ID"; // The subject line of the email. -var subject = "Amazon Pinpoint Test (AWS SDK for JavaScript in Node.js)"; +const subject = "Amazon Pinpoint Test (AWS SDK for JavaScript in Node.js)"; // The email body for recipients with non-HTML email clients. -var body_text = `Amazon Pinpoint Test (SDK for JavaScript in Node.js) +const body_text = `Amazon Pinpoint Test (SDK for JavaScript in Node.js) ---------------------------------------------------- This email was sent with Amazon Pinpoint using the AWS SDK for JavaScript in Node.js. For more information, see https://aws.amazon.com/sdk-for-node-js/`; // The body of the email for recipients whose email clients support HTML content. -var body_html = ` +const body_html = `

Amazon Pinpoint Test (SDK for JavaScript in Node.js)

@@ -50,7 +50,7 @@ var body_html = ` `; // The character encoding for the subject line and message body of the email. -var charset = "UTF-8"; +const charset = "UTF-8"; const params = { ApplicationId: projectId, @@ -100,9 +100,8 @@ const run = async () => { if (recipientResult.StatusCode !== 200) { throw new Error(recipientResult.StatusMessage); - } else { - console.log(recipientResult.MessageId); } + console.log(recipientResult.MessageId); } catch (err) { console.log(err.message); } diff --git a/javascriptv3/example_code/pinpoint/src/pinpoint_send_sms_message.js b/javascriptv3/example_code/pinpoint/src/pinpoint_send_sms_message.js index 2a0765dc677..74ca25614d0 100644 --- a/javascriptv3/example_code/pinpoint/src/pinpoint_send_sms_message.js +++ b/javascriptv3/example_code/pinpoint/src/pinpoint_send_sms_message.js @@ -44,19 +44,19 @@ const projectId = "PINPOINT_PROJECT_ID"; //e.g., XXXXXXXX66e4e9986478cXXXXXXXXX /* The type of SMS message that you want to send. If you plan to send time-sensitive content, specify TRANSACTIONAL. If you plan to send marketing-related content, specify PROMOTIONAL.*/ -var messageType = "TRANSACTIONAL"; +const messageType = "TRANSACTIONAL"; // The registered keyword associated with the originating short code. -var registeredKeyword = "myKeyword"; +const registeredKeyword = "myKeyword"; /* The sender ID to use when sending the message. Support for sender ID // varies by country or region. For more information, see https://docs.aws.amazon.com/pinpoint/latest/userguide/channels-sms-countries.html.*/ -var senderId = "MySenderID"; +const senderId = "MySenderID"; // Specify the parameters to pass to the API. -var params = { +const params = { ApplicationId: projectId, MessageRequest: { Addresses: { @@ -80,8 +80,7 @@ const run = async () => { try { const data = await pinClient.send(new SendMessagesCommand(params)); console.log( - "Message sent! " + - data["MessageResponse"]["Result"][destinationNumber]["StatusMessage"], + `Message sent! ${data.MessageResponse.Result[destinationNumber].StatusMessage}`, ); } catch (err) { console.log(err); diff --git a/javascriptv3/example_code/polly/general-examples/src/polly_synthesize_to_s3.js b/javascriptv3/example_code/polly/general-examples/src/polly_synthesize_to_s3.js index a683db0c17f..43e953baf4a 100644 --- a/javascriptv3/example_code/polly/general-examples/src/polly_synthesize_to_s3.js +++ b/javascriptv3/example_code/polly/general-examples/src/polly_synthesize_to_s3.js @@ -23,7 +23,7 @@ import { StartSpeechSynthesisTaskCommand } from "@aws-sdk/client-polly"; import { pollyClient } from "./libs/pollyClient.js"; // Create the parameters -var params = { +const params = { OutputFormat: "mp3", OutputS3BucketName: "videoanalyzerbucket", Text: "Hello David, How are you?", @@ -35,7 +35,7 @@ var params = { const run = async () => { try { await pollyClient.send(new StartSpeechSynthesisTaskCommand(params)); - console.log("Success, audio file added to " + params.OutputS3BucketName); + console.log(`Success, audio file added to ${params.OutputS3BucketName}`); } catch (err) { console.log("Error putting object", err); } diff --git a/javascriptv3/example_code/polly/src/polly.js b/javascriptv3/example_code/polly/src/polly.js index a91328f2052..2d5b7db5693 100644 --- a/javascriptv3/example_code/polly/src/polly.js +++ b/javascriptv3/example_code/polly/src/polly.js @@ -50,7 +50,7 @@ const speakText = async () => { // Update the Text parameter with the text entered by the user speechParams.Text = document.getElementById("textEntry").value; try { - let url = await getSynthesizeSpeechUrl({ + const url = await getSynthesizeSpeechUrl({ client, params: speechParams, }); diff --git a/javascriptv3/example_code/reactnative/ReactNativeApp/.eslintrc.js b/javascriptv3/example_code/reactnative/ReactNativeApp/.eslintrc.js index f0626fbd464..2c07519e81c 100644 --- a/javascriptv3/example_code/reactnative/ReactNativeApp/.eslintrc.js +++ b/javascriptv3/example_code/reactnative/ReactNativeApp/.eslintrc.js @@ -2,5 +2,5 @@ // SPDX-License-Identifier: Apache-2.0 module.exports = { root: true, - extends: '@react-native-community', -}; \ No newline at end of file + extends: "@react-native-community", +}; diff --git a/javascriptv3/example_code/reactnative/ReactNativeApp/.prettierrc.js b/javascriptv3/example_code/reactnative/ReactNativeApp/.prettierrc.js index c2cbf3a025c..934520749ae 100644 --- a/javascriptv3/example_code/reactnative/ReactNativeApp/.prettierrc.js +++ b/javascriptv3/example_code/reactnative/ReactNativeApp/.prettierrc.js @@ -1,9 +1,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 module.exports = { - arrowParens: 'avoid', + arrowParens: "avoid", bracketSameLine: true, bracketSpacing: false, singleQuote: true, - trailingComma: 'all', + trailingComma: "all", }; diff --git a/javascriptv3/example_code/reactnative/ReactNativeApp/App.tsx b/javascriptv3/example_code/reactnative/ReactNativeApp/App.tsx index bd3a6d1b450..f5d3d7812fe 100644 --- a/javascriptv3/example_code/reactnative/ReactNativeApp/App.tsx +++ b/javascriptv3/example_code/reactnative/ReactNativeApp/App.tsx @@ -1,47 +1,47 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 // snippet-start:[javascript.v3.reactnative.GettingStarted] -import React, {useCallback, useState} from 'react'; -import {Button, StyleSheet, Text, TextInput, View} from 'react-native'; -import 'react-native-get-random-values'; -import 'react-native-url-polyfill/auto'; +import React, { useCallback, useState } from "react"; +import { Button, StyleSheet, Text, TextInput, View } from "react-native"; +import "react-native-get-random-values"; +import "react-native-url-polyfill/auto"; import { S3Client, CreateBucketCommand, DeleteBucketCommand, -} from '@aws-sdk/client-s3'; -import {fromCognitoIdentityPool} from '@aws-sdk/credential-providers'; +} from "@aws-sdk/client-s3"; +import { fromCognitoIdentityPool } from "@aws-sdk/credential-providers"; const client = new S3Client({ // The AWS Region where the Amazon Simple Storage Service (Amazon S3) bucket will be created. Replace this with your Region. - region: 'us-east-1', + region: "us-east-1", credentials: fromCognitoIdentityPool({ // Replace the value of 'identityPoolId' with the ID of an Amazon Cognito identity pool in your Amazon Cognito Region. - identityPoolId: 'us-east-1:edbe2c04-7f5d-469b-85e5-98096bd75492', + identityPoolId: "us-east-1:edbe2c04-7f5d-469b-85e5-98096bd75492", // Replace the value of 'region' with your Amazon Cognito Region. - clientConfig: {region: 'us-east-1'}, + clientConfig: { region: "us-east-1" }, }), }); enum MessageType { - SUCCESS, - FAILURE, - EMPTY, + SUCCESS = 0, + FAILURE = 1, + EMPTY = 2, } const App = () => { - const [bucketName, setBucketName] = useState(''); - const [msg, setMsg] = useState<{message: string; type: MessageType}>({ - message: '', + const [bucketName, setBucketName] = useState(""); + const [msg, setMsg] = useState<{ message: string; type: MessageType }>({ + message: "", type: MessageType.EMPTY, }); const createBucket = useCallback(async () => { - setMsg({message: '', type: MessageType.EMPTY}); + setMsg({ message: "", type: MessageType.EMPTY }); try { - await client.send(new CreateBucketCommand({Bucket: bucketName})); + await client.send(new CreateBucketCommand({ Bucket: bucketName })); setMsg({ message: `Bucket "${bucketName}" created.`, type: MessageType.SUCCESS, @@ -49,24 +49,24 @@ const App = () => { } catch (e) { console.error(e); setMsg({ - message: e instanceof Error ? e.message : 'Unknown error', + message: e instanceof Error ? e.message : "Unknown error", type: MessageType.FAILURE, }); } }, [bucketName]); const deleteBucket = useCallback(async () => { - setMsg({message: '', type: MessageType.EMPTY}); + setMsg({ message: "", type: MessageType.EMPTY }); try { - await client.send(new DeleteBucketCommand({Bucket: bucketName})); + await client.send(new DeleteBucketCommand({ Bucket: bucketName })); setMsg({ message: `Bucket "${bucketName}" deleted.`, type: MessageType.SUCCESS, }); } catch (e) { setMsg({ - message: e instanceof Error ? e.message : 'Unknown error', + message: e instanceof Error ? e.message : "Unknown error", type: MessageType.FAILURE, }); } @@ -80,16 +80,17 @@ const App = () => { msg.type === MessageType.SUCCESS ? styles.successText : styles.failureText - }> + } + > {msg.message} )} setBucketName(text)} - autoCapitalize={'none'} + onChangeText={(text) => setBucketName(text)} + autoCapitalize={"none"} value={bucketName} - placeholder={'Enter Bucket Name'} + placeholder={"Enter Bucket Name"} />