From 7cff9df6cf7917adc4753aab8dabacf5fb82946f Mon Sep 17 00:00:00 2001 From: Chris Fang Date: Mon, 18 Mar 2024 10:18:48 -0700 Subject: [PATCH] chore: Small cleanup to internal core utils --- packages/core/src/libraryUtils.ts | 7 ++++--- packages/core/src/singleton/Auth/types.ts | 7 +------ packages/core/src/singleton/Auth/utils/index.ts | 2 +- packages/core/src/types/index.ts | 1 + packages/core/src/types/utils.ts | 10 ++++++++++ packages/core/src/utils/WordArray.ts | 2 +- 6 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 packages/core/src/types/utils.ts diff --git a/packages/core/src/libraryUtils.ts b/packages/core/src/libraryUtils.ts index 583d7e95d6b..a11eb0cf1c4 100644 --- a/packages/core/src/libraryUtils.ts +++ b/packages/core/src/libraryUtils.ts @@ -1,10 +1,11 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import WordArray from './utils/WordArray'; + /* This file maps top-level exports from `@aws-amplify/core/internals/utils`. These are intended to be internal utils for use throughout the library. */ + // Core utilities export { generateRandomString, @@ -57,7 +58,6 @@ export { export { Signer } from './Signer'; export { JWT, - StrictUnion, CognitoIdentityPoolConfig, JwtPayload, AuthStandardAttributeKey, @@ -119,10 +119,11 @@ export { Reachability } from './Reachability'; export { USER_AGENT_HEADER } from './constants'; export { fetchAuthSession } from './singleton/apis/internal/fetchAuthSession'; export { AMPLIFY_SYMBOL } from './Hub'; +export { StrictUnion } from './types'; export { base64Decoder, base64Encoder } from './utils/convert'; export { getCrypto } from './utils/globalHelpers'; export { cryptoSecureRandomInt } from './utils/cryptoSecureRandomInt'; -export { WordArray }; +export { WordArray } from './utils/WordArray'; // Hub export { HubInternal } from './Hub'; diff --git a/packages/core/src/singleton/Auth/types.ts b/packages/core/src/singleton/Auth/types.ts index 6d61ba01055..f449e1f08e3 100644 --- a/packages/core/src/singleton/Auth/types.ts +++ b/packages/core/src/singleton/Auth/types.ts @@ -1,6 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +import { StrictUnion } from '../../types'; import { AtLeastOne } from '../types'; // From https://github.com/awslabs/aws-jwt-verify/blob/main/src/safe-json-parse.ts @@ -119,12 +120,6 @@ export type CognitoProviderConfig = StrictUnion< | AuthUserPoolAndIdentityPoolConfig >; -type UnionKeys = T extends T ? keyof T : never; -type StrictUnionHelper = T extends any - ? T & Partial, keyof T>, never>> - : never; -export type StrictUnion = StrictUnionHelper; - export interface AuthIdentityPoolConfig { Cognito: CognitoIdentityPoolConfig & { userPoolClientId?: never; diff --git a/packages/core/src/singleton/Auth/utils/index.ts b/packages/core/src/singleton/Auth/utils/index.ts index e12c3e7a052..c710e64a1ee 100644 --- a/packages/core/src/singleton/Auth/utils/index.ts +++ b/packages/core/src/singleton/Auth/utils/index.ts @@ -1,6 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { base64Decoder } from '../../../utils/convert'; +import { StrictUnion } from '../../../types'; import { AuthConfig, CognitoIdentityPoolConfig, @@ -8,7 +9,6 @@ import { CognitoUserPoolConfig, JWT, OAuthConfig, - StrictUnion, } from '../types'; import { AuthConfigurationErrorCode, assert } from './errorHelpers'; diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts index 582907f7acd..e1f382423cb 100644 --- a/packages/core/src/types/index.ts +++ b/packages/core/src/types/index.ts @@ -4,3 +4,4 @@ export * from './core'; export * from './errors'; export * from './storage'; +export * from './utils'; diff --git a/packages/core/src/types/utils.ts b/packages/core/src/types/utils.ts new file mode 100644 index 00000000000..42542945986 --- /dev/null +++ b/packages/core/src/types/utils.ts @@ -0,0 +1,10 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +type UnionKeys = T extends T ? keyof T : never; + +type StrictUnionHelper = T extends any + ? T & Partial, keyof T>, never>> + : never; + +export type StrictUnion = StrictUnionHelper; diff --git a/packages/core/src/utils/WordArray.ts b/packages/core/src/utils/WordArray.ts index 653609887e3..871c9389a71 100644 --- a/packages/core/src/utils/WordArray.ts +++ b/packages/core/src/utils/WordArray.ts @@ -26,7 +26,7 @@ function hexStringify(wordArray: WordArray): string { return hexChars.join(''); } -export default class WordArray { +export class WordArray { words: number[] = []; sigBytes: number;