Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: upgrade @smithy/util-base64 #5066

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion packages/react-liveness/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const config: Config = {
coverageThreshold: {
global: {
branches: 81,
functions: 81,
functions: 79,
lines: 90,
statements: 90,
},
Expand Down
10 changes: 5 additions & 5 deletions packages/react-liveness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
"dependencies": {
"@aws-amplify/ui": "6.0.12",
"@aws-amplify/ui-react": "6.1.6",
"@aws-sdk/client-rekognitionstreaming": "3.398.0",
"@aws-sdk/util-format-url": "^3.410.0",
"@smithy/eventstream-serde-browser": "^2.0.4",
"@smithy/fetch-http-handler": "^2.1.3",
"@smithy/protocol-http": "^3.0.3",
"@aws-sdk/client-rekognitionstreaming": "3.529.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we investigate what's happening here?

"@aws-sdk/util-format-url": "3.523.0",
"@smithy/eventstream-serde-browser": "2.1.4",
"@smithy/fetch-http-handler": "2.4.5",
"@smithy/protocol-http": "3.2.2",
"@mediapipe/face_detection": "~0.4.0",
"@tensorflow-models/face-detection": "1.0.2",
"@tensorflow/tfjs-backend-cpu": "4.11.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ export class CustomWebSocketFetchHandler {
public readonly metadata: RequestHandlerMetadata = {
handlerProtocol: 'websocket/h1.1',
};
private readonly configPromise: Promise<WebSocketFetchHandlerOptions>;
private config: WebSocketFetchHandlerOptions;
private configPromise: Promise<WebSocketFetchHandlerOptions>;
private readonly httpHandler: RequestHandler<any, any>;
private readonly sockets: Record<string, WebSocket[]> = {};
private readonly utf8decoder = new TextDecoder(); // default 'utf-8' or 'utf8'

constructor(
options?:
Expand All @@ -95,12 +95,39 @@ export class CustomWebSocketFetchHandler {
) {
this.httpHandler = httpHandler;
if (typeof options === 'function') {
this.configPromise = options().then((opts) => opts ?? {});
this.config = {};
this.configPromise = options().then((opts) => (this.config = opts ?? {}));
} else {
this.configPromise = Promise.resolve(options ?? {});
this.config = options ?? {};
this.configPromise = Promise.resolve(this.config);
}
}

/**
* @returns the input if it is an HttpHandler of any class,
* or instantiates a new instance of this handler.
*/
public static create(
instanceOrOptions?:
| CustomWebSocketFetchHandler
| WebSocketFetchHandlerOptions
| Provider<WebSocketFetchHandlerOptions | void>,
httpHandler: RequestHandler<any, any> = new FetchHttpHandler()
): CustomWebSocketFetchHandler {
if (typeof (instanceOrOptions as any)?.handle === 'function') {
// is already an instance of HttpHandler.
return instanceOrOptions as CustomWebSocketFetchHandler;
}
// input is ctor options or undefined.
return new CustomWebSocketFetchHandler(
instanceOrOptions as
| undefined
| WebSocketFetchHandlerOptions
| Provider<WebSocketFetchHandlerOptions>,
httpHandler
);
}

/**
* Destroys the WebSocketHandler.
* Closes all sockets from the socket pool.
Expand Down Expand Up @@ -128,8 +155,9 @@ export class CustomWebSocketFetchHandler {
this.sockets[url].push(socket);

socket.binaryType = 'arraybuffer';
this.config = await this.configPromise;
const { connectionTimeout = DEFAULT_WS_CONNECTION_TIMEOUT_MS } =
await this.configPromise;
this.config;
await this.waitForReady(socket, connectionTimeout);
const { body } = request;
const bodyStream = getIterator(body);
Expand All @@ -143,6 +171,20 @@ export class CustomWebSocketFetchHandler {
};
}

updateHttpClientConfig(
key: keyof WebSocketFetchHandlerOptions,
value: WebSocketFetchHandlerOptions[typeof key]
): void {
this.configPromise = this.configPromise.then((config) => {
(config as Record<typeof key, typeof value>)[key] = value;
return config;
});
}

httpHandlerConfigs(): WebSocketFetchHandlerOptions {
return this.config ?? {};
}

/**
* Removes all closing/closed sockets from the socket pool for URL.
*/
Expand Down Expand Up @@ -238,16 +280,6 @@ export class CustomWebSocketFetchHandler {
const send = async (): Promise<void> => {
try {
for await (const inputChunk of data) {
const decodedString = this.utf8decoder.decode(inputChunk);
if (decodedString.includes('closeCode')) {
const match = decodedString.match(/"closeCode":([0-9]*)/);
if (match) {
const closeCode = match[1];
socket.close(parseInt(closeCode));
}
continue;
}

socket.send(inputChunk);
}
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'jest-canvas-mock';

import { SessionInformation } from '@aws-sdk/client-rekognitionstreaming';

import {
drawLivenessOvalInCanvas,
estimateIllumination,
Expand Down Expand Up @@ -311,7 +314,7 @@ describe('Liveness Helper', () => {
});

it('should work even if there are no color sequences', async () => {
const mockSessionInfo = {
const mockSessionInfo: SessionInformation = {
Challenge: {
FaceMovementAndLightChallenge: {
ChallengeConfig: {
Expand Down Expand Up @@ -344,7 +347,7 @@ describe('Liveness Helper', () => {
});

it('should not return values if color sequences do not contain durations', async () => {
const mockSessionInfo = {
const mockSessionInfo: SessionInformation = {
Challenge: {
FaceMovementAndLightChallenge: {
ChallengeConfig: {
Expand Down
Loading
Loading