Skip to content

Commit 278cfef

Browse files
authored
JavaScript (v3): Textract - Fix non-unique domain prefix in textract-react CFN template and some broke unit tests. (#7190)
* JavaScript (v3): Textract - Fix non-unique domain prefix in textract-react CFN template. * JavaScript (v3): Textract - Update to latest react scripts and declare working node engine. * JavaScript (v3): Add workaround for broken instanceof check [This PR](https://github.com/smithy-lang/smithy-typescript/pull/1490/files) overrode the default 'instanceof' implementation for ServiceException. It created a duck-type check that took priority over the prototype chain check. There's a [fix](https://github.com/smithy-lang/smithy-typescript/pull/1503/files) incoming, but in the meantime this makes it quack. * JavaScript (v3): Textract - Ensure unique LoginUrl is saved as a CFN output. * JavaScript (v3): Unit tests - Fix incorrect link in S3 unit tests comments.
1 parent 4494f37 commit 278cfef

29 files changed

+120
-22
lines changed

.github/workflows/lint-javascript.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
if: steps.changed-files.outputs.any_changed == 'true'
2727
uses: actions/setup-node@v3
2828
with:
29-
node-version: "20.x"
29+
node-version: "22.x"
3030
- name: Install dependencies
3131
if: steps.changed-files.outputs.any_changed == 'true'
3232
run: npm i --prefix javascriptv3

javascriptv3/example_code/cross-services/textract-react/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"bootstrap": "^5.0.0-beta3",
1414
"react": "^17.0.2",
1515
"react-dom": "^17.0.2",
16-
"react-scripts": "4.0.3",
16+
"react-scripts": "5.0.0",
1717
"web-vitals": "^1.1.1"
1818
},
1919
"scripts": {
@@ -31,10 +31,13 @@
3131
]
3232
},
3333
"devDependencies": {
34-
"canvas": "^2.7.0",
3534
"@testing-library/jest-dom": "^5.11.9",
3635
"@testing-library/react": "^11.2.5",
37-
"@testing-library/user-event": "^12.8.3"
36+
"@testing-library/user-event": "^12.8.3",
37+
"canvas": "^3.0.1"
3838
},
39-
"type": "module"
39+
"type": "module",
40+
"engines": {
41+
"node": ">=22 <23"
42+
}
4043
}

javascriptv3/example_code/cross-services/textract-react/setup.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,19 @@ Resources:
201201
textractcognitodemoidtextractcognitodemodomainEBB6899F:
202202
Type: AWS::Cognito::UserPoolDomain
203203
Properties:
204-
Domain: textract-demo
204+
Domain:
205+
Fn::Join:
206+
- '-'
207+
- - textract-react
208+
- Fn::Select:
209+
- 4
210+
- Fn::Split:
211+
- '-'
212+
- Fn::Select:
213+
- 2
214+
- Fn::Split:
215+
- /
216+
- Ref: AWS::StackId
205217
UserPoolId:
206218
Ref: textractcognitodemoidA350B90F
207219
Metadata:
@@ -332,7 +344,9 @@ Outputs:
332344
Value:
333345
Fn::Join:
334346
- ""
335-
- - https://textract-demo.auth.
347+
- - https://
348+
- Ref: textractcognitodemoidtextractcognitodemodomainEBB6899F
349+
- .auth.
336350
- Ref: AWS::Region
337351
- .amazoncognito.com/login?client_id=
338352
- Ref: textractcognitodemoidtextractcognitodemoclientidB9ABA9D2

javascriptv3/example_code/cross-services/textract-react/src/App.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import React, { useState, useEffect } from "react";
5-
import { ImageLoader } from "./ImageLoader";
6-
import { ImageDisplay } from "./ImageDisplay";
7-
import { ExtractButtons } from "./ExtractButtons";
8-
import { ExplorerCard } from "./ExplorerCard";
9-
import { LoginCard } from "./LoginCard";
5+
import { ImageLoader } from "./ImageLoader.js";
6+
import { ImageDisplay } from "./ImageDisplay.js";
7+
import { ExtractButtons } from "./ExtractButtons.js";
8+
import { ExplorerCard } from "./ExplorerCard.js";
9+
import { LoginCard } from "./LoginCard.js";
1010

1111
/**
1212
* Main React application element. Includes panels for signing in, loading and

javascriptv3/example_code/cross-services/textract-react/src/Config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
34
export const Config = {
45
ConfigError:
56
"Demo resources not initialized. You must deploy AWS resources and demo elements before running this application. See the README for details.",

javascriptv3/example_code/cross-services/textract-react/src/ExplorerCard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import React, { useRef } from "react";
5-
import { ExplorerTree } from "./ExplorerTree";
5+
import { ExplorerTree } from "./ExplorerTree.js";
66

77
/**
88
* Displays output from Amazon Textract as a hierarchical tree of checkboxes.

javascriptv3/example_code/cross-services/textract-react/src/ExplorerTree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import React from "react";
5-
import { ColorMap, FilterMap } from "./Utils";
5+
import { ColorMap, FilterMap } from "./Utils.js";
66

77
/**
88
* An individual node that displays a block item from Amazon Textract as a checkbox.

javascriptv3/example_code/cross-services/textract-react/src/ImageDisplay.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import React, { useRef, useLayoutEffect } from "react";
5-
import { ColorMap } from "./Utils";
5+
import { ColorMap } from "./Utils.js";
66

77
/**
88
* Displays a PNG image formatted as a Base64 string and draws polygons on top of

javascriptv3/example_code/cross-services/textract-react/src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
import "bootstrap/dist/css/bootstrap.css";
1717
import React from "react";
1818
import ReactDOM from "react-dom";
19-
import { Config } from "./Config";
20-
import { awsFactory } from "./AwsFactory";
21-
import App from "./App";
22-
import TextractModel from "./TextractModel";
19+
import { Config } from "./Config.js";
20+
import { awsFactory } from "./AwsFactory.js";
21+
import App from "./App.js";
22+
import TextractModel from "./TextractModel.js";
2323

2424
const params = new URLSearchParams(window.location.hash.slice(1));
2525
const idToken = params.get("id_token");

javascriptv3/example_code/s3/tests/copy-object.unit.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ describe("copy-object", () => {
3737
});
3838

3939
it("should log a relevant error message if the object is in an archive tier", async () => {
40-
send.mockRejectedValue(new ObjectNotInActiveTierError());
40+
const error = new ObjectNotInActiveTierError();
41+
error.$fault = "server"; // Workaround until PR is released. https://github.com/smithy-lang/smithy-typescript/pull/1503
42+
error.$metadata = "metadata"; // Workaround until PR is released. https://github.com/smithy-lang/smithy-typescript/pull/1503
43+
send.mockRejectedValue(error);
4144

4245
const spy = vi.spyOn(console, "error");
4346

0 commit comments

Comments
 (0)