From 05e84a1cab91ef3b13887dd03a7a7825a0e44121 Mon Sep 17 00:00:00 2001 From: James Jarvis Date: Tue, 26 Nov 2024 11:04:41 -0800 Subject: [PATCH 1/8] feat(auth): enable parallel otp runs (#14034) * enable e2e tests * reset tmp test updates --- .github/integ-config/integ-all.yml | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/.github/integ-config/integ-all.yml b/.github/integ-config/integ-all.yml index 3c37683608b..b20a0cc45e1 100644 --- a/.github/integ-config/integ-all.yml +++ b/.github/integ-config/integ-all.yml @@ -890,7 +890,7 @@ tests: category: auth sample_name: [mfa] spec: mfa-req-email - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: mfa-req-email - test_name: integ_next_mfa_req_phone @@ -899,7 +899,7 @@ tests: category: auth sample_name: [mfa] spec: mfa-req-phone - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: mfa-req-phone - test_name: integ_next_mfa_opt_email @@ -908,7 +908,7 @@ tests: category: auth sample_name: [mfa] spec: mfa-opt-email - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: mfa-opt-email - test_name: integ_next_mfa_opt_phone @@ -917,7 +917,7 @@ tests: category: auth sample_name: [mfa] spec: mfa-opt-phone - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: mfa-opt-phone - test_name: integ_next_mfa_setup @@ -926,7 +926,7 @@ tests: category: auth sample_name: [mfa] spec: mfa-setup - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: mfa-setup - test_name: integ_next_passwordless_auto_sign_in @@ -935,8 +935,7 @@ tests: category: auth sample_name: [mfa] spec: passwordless/auto-sign-in - # browser: *minimal_browser_list - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: pwl-autosignin - test_name: integ_next_passwordless_first_factor_selection @@ -945,8 +944,7 @@ tests: category: auth sample_name: [mfa] spec: passwordless/first-factor-selection - # browser: *minimal_browser_list - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: pwl-ffselect - test_name: integ_next_passwordless_preferred_challenge @@ -955,8 +953,7 @@ tests: category: auth sample_name: [mfa] spec: passwordless/preferred-challenge - # browser: *minimal_browser_list - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: pwl-prefchal - test_name: integ_next_passwordless_sign_up @@ -965,8 +962,7 @@ tests: category: auth sample_name: [mfa] spec: passwordless/sign-up - # browser: *minimal_browser_list - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: pwl-signup - test_name: integ_next_passwordless_misc @@ -975,8 +971,7 @@ tests: category: auth sample_name: [mfa] spec: passwordless/miscellaneous - # browser: *minimal_browser_list - browser: [chrome] + browser: *minimal_browser_list env: NEXT_PUBLIC_BACKEND_CONFIG: pwl-misc - test_name: integ_next_passwordless_webauthn From fb8dadbfb77aecd9fe07571d1ccbd0db3b5d0c94 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Mon, 2 Dec 2024 17:55:36 -0500 Subject: [PATCH 2/8] fix: amplify configure with auth userGroups (#14046) Co-authored-by: Ashwin Kumar --- packages/core/__tests__/parseAmplifyOutputs.test.ts | 2 ++ packages/core/src/singleton/AmplifyOutputs/types.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/__tests__/parseAmplifyOutputs.test.ts b/packages/core/__tests__/parseAmplifyOutputs.test.ts index 38a8fa141c4..9ae814334c1 100644 --- a/packages/core/__tests__/parseAmplifyOutputs.test.ts +++ b/packages/core/__tests__/parseAmplifyOutputs.test.ts @@ -133,6 +133,7 @@ describe('parseAmplifyOutputs tests', () => { unauthenticated_identities_enabled: true, mfa_configuration: 'OPTIONAL', mfa_methods: ['SMS'], + groups: [{ ADMIN: { precedence: 0 }, USER: { precedence: 0 } }], }, }; @@ -174,6 +175,7 @@ describe('parseAmplifyOutputs tests', () => { scopes: ['profile', '...'], }, }, + groups: [{ ADMIN: { precedence: 0 }, USER: { precedence: 0 } }], }, }, }); diff --git a/packages/core/src/singleton/AmplifyOutputs/types.ts b/packages/core/src/singleton/AmplifyOutputs/types.ts index a862d4e4efe..4146037a9ce 100644 --- a/packages/core/src/singleton/AmplifyOutputs/types.ts +++ b/packages/core/src/singleton/AmplifyOutputs/types.ts @@ -42,7 +42,7 @@ export interface AmplifyOutputsAuthProperties { unauthenticated_identities_enabled?: boolean; mfa_configuration?: string; mfa_methods?: string[]; - groups?: Record[]; + groups?: Partial>[]; } export interface AmplifyOutputsStorageBucketProperties { From 3c1cc8f9c46d5f7444f790792dcdbd74b88e07e6 Mon Sep 17 00:00:00 2001 From: Zhi Zhou Date: Wed, 4 Dec 2024 16:59:12 +0800 Subject: [PATCH 3/8] refactor: clean signIn state after all relevant async works finish --- packages/auth/src/providers/cognito/apis/confirmSignIn.ts | 4 ++-- .../auth/src/providers/cognito/apis/signInWithCustomAuth.ts | 5 ++--- packages/auth/src/providers/cognito/apis/signInWithSRP.ts | 4 ++-- .../auth/src/providers/cognito/apis/signInWithUserAuth.ts | 3 ++- .../src/providers/cognito/apis/signInWithUserPassword.ts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts index ea2582a6d47..34eab302ef9 100644 --- a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts +++ b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts @@ -109,7 +109,6 @@ export async function confirmSignIn( }); if (AuthenticationResult) { - cleanActiveSignInState(); await cacheCognitoTokens({ username, ...AuthenticationResult, @@ -121,7 +120,8 @@ export async function confirmSignIn( }), signInDetails, }); - + cleanActiveSignInState(); + await dispatchSignedInHubEvent(); return { diff --git a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts index 348c60870ae..d82b28f3ead 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts @@ -84,8 +84,6 @@ export async function signInWithCustomAuth( signInDetails, }); if (AuthenticationResult) { - cleanActiveSignInState(); - await cacheCognitoTokens({ username: activeUsername, ...AuthenticationResult, @@ -97,7 +95,8 @@ export async function signInWithCustomAuth( }), signInDetails, }); - + cleanActiveSignInState(); + await dispatchSignedInHubEvent(); return { diff --git a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts index 4cff40e7cd7..46e8fc7dcb3 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts @@ -91,7 +91,6 @@ export async function signInWithSRP( signInDetails, }); if (AuthenticationResult) { - cleanActiveSignInState(); await cacheCognitoTokens({ username: activeUsername, ...AuthenticationResult, @@ -103,7 +102,8 @@ export async function signInWithSRP( }), signInDetails, }); - + cleanActiveSignInState(); + await dispatchSignedInHubEvent(); resetAutoSignIn(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts index 9ac1223a105..7c182cf22bd 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts @@ -100,7 +100,6 @@ export async function signInWithUserAuth( }); if (response.AuthenticationResult) { - cleanActiveSignInState(); await cacheCognitoTokens({ username: activeUsername, ...response.AuthenticationResult, @@ -112,6 +111,8 @@ export async function signInWithUserAuth( }), signInDetails, }); + cleanActiveSignInState(); + await dispatchSignedInHubEvent(); resetAutoSignIn(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts index 0cd3acd88d3..c5386b7d6d7 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts @@ -86,7 +86,6 @@ export async function signInWithUserPassword( signInDetails, }); if (AuthenticationResult) { - cleanActiveSignInState(); await cacheCognitoTokens({ ...AuthenticationResult, username: activeUsername, @@ -98,7 +97,8 @@ export async function signInWithUserPassword( }), signInDetails, }); - + cleanActiveSignInState(); + await dispatchSignedInHubEvent(); resetAutoSignIn(); From c72e72ad038bb436287b984a98ad7eb992664be6 Mon Sep 17 00:00:00 2001 From: "Aaron S." <94858815+stocaaro@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:01:08 -0600 Subject: [PATCH 4/8] fix: Typescript errors (#14037) * fix: Typescript errors * Fix test errors --- packages/api-graphql/src/internals/v6.ts | 4 +++- packages/api-graphql/src/types/index.ts | 2 +- packages/datastore/src/types.ts | 12 ++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/api-graphql/src/internals/v6.ts b/packages/api-graphql/src/internals/v6.ts index c5d362908c8..553707be092 100644 --- a/packages/api-graphql/src/internals/v6.ts +++ b/packages/api-graphql/src/internals/v6.ts @@ -4,6 +4,7 @@ import { CustomHeaders } from '@aws-amplify/data-schema/runtime'; import { GraphQLAPI } from '../GraphQLAPI'; import { + GraphQLOptions, GraphQLOptionsV6, GraphQLResponseV6, V6Client, @@ -113,10 +114,11 @@ export function graphql< * Neither of these can actually be validated at runtime. Hence, we don't perform * any validation or type-guarding here. */ + const result = GraphQLAPI.graphql( // TODO: move V6Client back into this package? internals.amplify as any, - options, + options as GraphQLOptions, headers, ); diff --git a/packages/api-graphql/src/types/index.ts b/packages/api-graphql/src/types/index.ts index 0ecac34369a..d642fff3bd1 100644 --- a/packages/api-graphql/src/types/index.ts +++ b/packages/api-graphql/src/types/index.ts @@ -212,7 +212,7 @@ export type GraphQLOperation = Source | string; export interface GraphQLOptionsV6< FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string, -> { +> extends Record { query: TYPED_GQL_STRING | DocumentNode; variables?: GraphQLVariablesV6; authMode?: GraphQLAuthMode; diff --git a/packages/datastore/src/types.ts b/packages/datastore/src/types.ts index abc92322cc7..a36cad59ca1 100644 --- a/packages/datastore/src/types.ts +++ b/packages/datastore/src/types.ts @@ -506,6 +506,10 @@ export type TypeConstructorMap = Record< export declare const __identifierBrand__: unique symbol; export type IdentifierBrand = T & { [__identifierBrand__]: K }; +interface GenericIdentifier { + field: any; +} + // datastore generates a uuid for you export type ManagedIdentifier = IdentifierBrand< { field: F extends string ? F : never; type: T }, @@ -548,7 +552,9 @@ export type IdentifierFields< infer B > ? B[number] // B[number] - : MetadataOrDefault['identifier']['field']) & + : MetadataOrDefault['identifier'] extends GenericIdentifier + ? MetadataOrDefault['identifier']['field'] + : unknown) & string; export type IdentifierFieldsForInit< @@ -710,7 +716,9 @@ export type IdentifierFieldValue< ? MetadataOrDefault['identifier']['fields'] extends [any] ? T[MetadataOrDefault['identifier']['fields'][0]] : never - : T[MetadataOrDefault['identifier']['field']]; + : MetadataOrDefault['identifier'] extends GenericIdentifier + ? T[MetadataOrDefault['identifier']['field']] + : unknown; export type IdentifierFieldOrIdentifierObject< T extends PersistentModel, From 2283e4b424d9958935586ea609d3b7863848650e Mon Sep 17 00:00:00 2001 From: Hui Zhao <10602282+HuiSF@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:27:42 -0800 Subject: [PATCH 5/8] chore: update CODEOWNER (#14054) --- .github/CODEOWNERS | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a24f7b2ebbb..b6574c0fc16 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -15,24 +15,24 @@ # The following paths involve server-side use cases, token/user session management. # Changes made to these paths requires additional reviews and approvals. -/packages/auth @haverchuck @cshfang @HuiSF @pranavosu -/packages/aws-amplify/src/adapter-core @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/adapterCore @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/singleton @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/utils/convert @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/utils/WordArray.ts @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/storage @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/utils/generateRandomString.ts @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/utils/globalHelpers @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/utils/urlSafeDecode.ts @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/awsClients/cognitoIdentity @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/clients/internal @haverchuck @cshfang @HuiSF @pranavosu -/packages/core/src/Hub @haverchuck @cshfang @HuiSF @pranavosu -/packages/adapter-nextjs @haverchuck @cshfang @HuiSF @pranavosu -/packages/rtn-web-browser @haverchuck @cshfang @HuiSF @pranavosu -/packages/storage/src/providers/s3/apis/internal @haverchuck @cshfang @HuiSF @pranavosu -/packages/storage/src/providers/s3/apis/server @haverchuck @cshfang @HuiSF @pranavosu -/packages/api-rest/src/apis/server.ts @haverchuck @cshfang @HuiSF @pranavosu -/packages/api-rest/src/apis/common/internalPost.ts @haverchuck @cshfang @HuiSF @pranavosu -/packages/api-graphql/src/server @haverchuck @cshfang @HuiSF @pranavosu -/packages/api-graphql/src/internals/server @haverchuck @cshfang @HuiSF @pranavosu +/packages/auth @sktimalsina @cshfang @HuiSF @pranavosu +/packages/aws-amplify/src/adapter-core @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/adapterCore @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/singleton @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/utils/convert @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/utils/WordArray.ts @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/storage @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/utils/generateRandomString.ts @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/utils/globalHelpers @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/utils/urlSafeDecode.ts @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/awsClients/cognitoIdentity @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/clients/internal @sktimalsina @cshfang @HuiSF @pranavosu +/packages/core/src/Hub @sktimalsina @cshfang @HuiSF @pranavosu +/packages/adapter-nextjs @sktimalsina @cshfang @HuiSF @pranavosu +/packages/rtn-web-browser @sktimalsina @cshfang @HuiSF @pranavosu +/packages/storage/src/providers/s3/apis/internal @sktimalsina @cshfang @HuiSF @pranavosu +/packages/storage/src/providers/s3/apis/server @sktimalsina @cshfang @HuiSF @pranavosu +/packages/api-rest/src/apis/server.ts @sktimalsina @cshfang @HuiSF @pranavosu +/packages/api-rest/src/apis/common/internalPost.ts @sktimalsina @cshfang @HuiSF @pranavosu +/packages/api-graphql/src/server @sktimalsina @cshfang @HuiSF @pranavosu +/packages/api-graphql/src/internals/server @sktimalsina @cshfang @HuiSF @pranavosu From 07798249fbdbdf6720e85bdce1ce10bf9485a4d5 Mon Sep 17 00:00:00 2001 From: James Jarvis Date: Fri, 6 Dec 2024 10:06:41 -0800 Subject: [PATCH 6/8] chore: lint code changes --- packages/auth/src/providers/cognito/apis/confirmSignIn.ts | 2 +- .../auth/src/providers/cognito/apis/signInWithCustomAuth.ts | 2 +- packages/auth/src/providers/cognito/apis/signInWithSRP.ts | 2 +- packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts | 2 +- .../auth/src/providers/cognito/apis/signInWithUserPassword.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts index 34eab302ef9..ae62578be5e 100644 --- a/packages/auth/src/providers/cognito/apis/confirmSignIn.ts +++ b/packages/auth/src/providers/cognito/apis/confirmSignIn.ts @@ -121,7 +121,7 @@ export async function confirmSignIn( signInDetails, }); cleanActiveSignInState(); - + await dispatchSignedInHubEvent(); return { diff --git a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts index d82b28f3ead..5911266475b 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithCustomAuth.ts @@ -96,7 +96,7 @@ export async function signInWithCustomAuth( signInDetails, }); cleanActiveSignInState(); - + await dispatchSignedInHubEvent(); return { diff --git a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts index 46e8fc7dcb3..aa92e3e6012 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithSRP.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithSRP.ts @@ -103,7 +103,7 @@ export async function signInWithSRP( signInDetails, }); cleanActiveSignInState(); - + await dispatchSignedInHubEvent(); resetAutoSignIn(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts index 7c182cf22bd..94165046864 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserAuth.ts @@ -112,7 +112,7 @@ export async function signInWithUserAuth( signInDetails, }); cleanActiveSignInState(); - + await dispatchSignedInHubEvent(); resetAutoSignIn(); diff --git a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts index c5386b7d6d7..8027af90c71 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithUserPassword.ts @@ -98,7 +98,7 @@ export async function signInWithUserPassword( signInDetails, }); cleanActiveSignInState(); - + await dispatchSignedInHubEvent(); resetAutoSignIn(); From 341eee293b772f0c71e667ccce4ebdca993513ff Mon Sep 17 00:00:00 2001 From: Hui Zhao <10602282+HuiSF@users.noreply.github.com> Date: Wed, 11 Dec 2024 15:20:06 -0800 Subject: [PATCH 7/8] feat(adapter-nextjs): support next.js 15 (#13947) * feat(adapter-nextjs): support next.js 15 * chore: run e2e tests aginst the changes * chore: publish next-15 tag * chore: enable next.js tests against v14 and v15 * chore: run e2e tests * chore: remove e2e run trigger for merging --- .github/integ-config/integ-all.yml | 22 ++-- .github/workflows/callable-e2e-test.yml | 6 +- .github/workflows/callable-e2e-tests.yml | 1 + .../__tests__/createServerRunner.test.ts | 4 +- ...torageAdapterFromNextServerContext.test.ts | 102 ++++++++++-------- packages/adapter-nextjs/package.json | 2 +- ...okieStorageAdapterFromNextServerContext.ts | 10 +- .../createRunWithAmplifyServerContext.ts | 2 +- 8 files changed, 89 insertions(+), 60 deletions(-) diff --git a/.github/integ-config/integ-all.yml b/.github/integ-config/integ-all.yml index b20a0cc45e1..4759997ee29 100644 --- a/.github/integ-config/integ-all.yml +++ b/.github/integ-config/integ-all.yml @@ -875,14 +875,24 @@ tests: # spec: duplicate-packages # browser: *minimal_browser_list - # SSR context isolation - - test_name: integ_ssr_context_isolation - desc: 'SSR Context Isolation' + # Next.js use cases + - test_name: integ_next-use-cases-14 + desc: 'Next.js use cases tests with v14' framework: next category: ssr-adapter - sample_name: ssr-context-isolation - spec: ssr-context-isolation - yarn_script: ci:ssr-context-isolation + sample_name: next-use-cases-14 + spec: next-use-cases + yarn_script: ci:next-use-cases-test + yarn_script_args: 14 + browser: [chrome] + - test_name: integ_next-use-cases-15 + desc: 'Next.js use cases tests with v15' + framework: next + category: ssr-adapter + sample_name: next-use-cases-15 + spec: next-use-cases + yarn_script: ci:next-use-cases-test + yarn_script_args: 15 browser: [chrome] - test_name: integ_next_mfa_req_email desc: 'mfa required with email sign in attribute' diff --git a/.github/workflows/callable-e2e-test.yml b/.github/workflows/callable-e2e-test.yml index ee02150baa3..a0bfd77d22f 100644 --- a/.github/workflows/callable-e2e-test.yml +++ b/.github/workflows/callable-e2e-test.yml @@ -37,6 +37,9 @@ on: yarn_script: required: false type: string + yarn_script_args: + required: false + type: number env: required: false type: string @@ -124,6 +127,7 @@ jobs: E2E_RETRY_COUNT: ${{ inputs.retry_count }} E2E_TEST_NAME: ${{ inputs.test_name }} E2E_YARN_SCRIPT: ${{ inputs.yarn_script }} + E2E_YARN_SCRIPT_ARGS: ${{ inputs.yarn_script_args }} E2E_ENV: ${{ inputs.env }} run: | if [ -z "$E2E_YARN_SCRIPT" ]; then @@ -141,7 +145,7 @@ jobs: $E2E_YARN_SCRIPT \ -n $E2E_RETRY_COUNT else - yarn "$E2E_YARN_SCRIPT" + yarn "$E2E_YARN_SCRIPT" "$E2E_YARN_SCRIPT_ARGS" fi - name: Upload artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 https://github.com/actions/upload-artifact/commit/0b7f8abb1508181956e8e162db84b466c27e18ce diff --git a/.github/workflows/callable-e2e-tests.yml b/.github/workflows/callable-e2e-tests.yml index 2b7604b1215..bdb174e32a7 100644 --- a/.github/workflows/callable-e2e-tests.yml +++ b/.github/workflows/callable-e2e-tests.yml @@ -44,6 +44,7 @@ jobs: timeout_minutes: ${{ matrix.integ-config.timeout_minutes || 35 }} retry_count: ${{ matrix.integ-config.retry_count || 3 }} yarn_script: ${{ matrix.integ-config.yarn_script || '' }} + yarn_script_args: ${{ matrix.integ-config.yarn_script_args || 15 }} env: ${{ matrix.integ-config.env && toJSON(matrix.integ-config.env) || '{}' }} # e2e-test-runner-headless: diff --git a/packages/adapter-nextjs/__tests__/createServerRunner.test.ts b/packages/adapter-nextjs/__tests__/createServerRunner.test.ts index 5dbaa9e0071..3509a4b49c3 100644 --- a/packages/adapter-nextjs/__tests__/createServerRunner.test.ts +++ b/packages/adapter-nextjs/__tests__/createServerRunner.test.ts @@ -124,7 +124,7 @@ describe('createServerRunner', () => { }); describe('when nextServerContext is not null', () => { - it('should create auth providers with cookie storage adapter', () => { + it('should create auth providers with cookie storage adapter', async () => { const operation = jest.fn(); const mockCookieStorageAdapter = { get: jest.fn(), @@ -147,7 +147,7 @@ describe('createServerRunner', () => { const { runWithAmplifyServerContext } = createServerRunner({ config: mockAmplifyConfig, }); - runWithAmplifyServerContext({ + await runWithAmplifyServerContext({ operation, nextServerContext: mockNextServerContext as unknown as NextServer.Context, diff --git a/packages/adapter-nextjs/__tests__/utils/createCookieStorageAdapterFromNextServerContext.test.ts b/packages/adapter-nextjs/__tests__/utils/createCookieStorageAdapterFromNextServerContext.test.ts index a42ec085e9c..c81383ea804 100644 --- a/packages/adapter-nextjs/__tests__/utils/createCookieStorageAdapterFromNextServerContext.test.ts +++ b/packages/adapter-nextjs/__tests__/utils/createCookieStorageAdapterFromNextServerContext.test.ts @@ -7,6 +7,7 @@ import { Socket } from 'net'; import { enableFetchMocks } from 'jest-fetch-mock'; import { NextRequest, NextResponse } from 'next/server.js'; import { cookies } from 'next/headers.js'; +import { CookieStorage } from 'aws-amplify/adapter-core'; import { DATE_IN_THE_PAST, @@ -46,29 +47,32 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { describe('cookieStorageAdapter created from NextRequest and NextResponse', () => { const request = new NextRequest(new URL('https://example.com')); const response = NextResponse.next(); - - jest.spyOn(request, 'cookies', 'get').mockImplementation( - () => - ({ - get: mockGetFunc, - getAll: mockGetAllFunc, - }) as any, - ); - - jest.spyOn(response, 'cookies', 'get').mockImplementation(() => ({ - set: mockSetFunc, - delete: mockDeleteFunc, - get: jest.fn(), - getAll: jest.fn(), - has: jest.fn(), - })); - const mockContext = { request, response, } as any; + let result: CookieStorage.Adapter; + + beforeAll(async () => { + jest.spyOn(request, 'cookies', 'get').mockImplementation( + () => + ({ + get: mockGetFunc, + getAll: mockGetAllFunc, + }) as any, + ); - const result = createCookieStorageAdapterFromNextServerContext(mockContext); + jest.spyOn(response, 'cookies', 'get').mockImplementation(() => ({ + set: mockSetFunc, + delete: mockDeleteFunc, + get: jest.fn(), + getAll: jest.fn(), + has: jest.fn(), + })); + + result = + await createCookieStorageAdapterFromNextServerContext(mockContext); + }); it('gets cookie by calling `get` method of the underlying cookie store', () => { result.get(mockKey); @@ -121,26 +125,32 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { describe('cookieStorageAdapter created from NextRequest and Response', () => { const request = new NextRequest(new URL('https://example.com')); const response = new Response(); - - jest.spyOn(request, 'cookies', 'get').mockImplementation( - () => - ({ - get: mockGetFunc, - getAll: mockGetAllFunc, - }) as any, - ); - jest.spyOn(response, 'headers', 'get').mockImplementation( - () => - ({ - append: mockAppend, - }) as any, - ); - const mockContext = { request, response, } as any; + let result: CookieStorage.Adapter; + + beforeAll(async () => { + jest.spyOn(request, 'cookies', 'get').mockImplementation( + () => + ({ + get: mockGetFunc, + getAll: mockGetAllFunc, + }) as any, + ); + jest.spyOn(response, 'headers', 'get').mockImplementation( + () => + ({ + append: mockAppend, + }) as any, + ); + + result = + await createCookieStorageAdapterFromNextServerContext(mockContext); + }); + const mockSerializeOptions = { domain: 'example.com', expires: new Date('2023-08-22'), @@ -150,8 +160,6 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { path: '/a-path', }; - const result = createCookieStorageAdapterFromNextServerContext(mockContext); - it('gets cookie by calling `get` method of the underlying cookie store', () => { result.get(mockKey); expect(mockGetFunc).toHaveBeenCalledWith(mockKey); @@ -233,9 +241,15 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { }); describe('cookieStorageAdapter created from Next cookies function', () => { - mockNextCookiesFunc.mockReturnValueOnce(mockNextCookiesFuncReturn); + let result: CookieStorage.Adapter; + + beforeAll(async () => { + mockNextCookiesFunc.mockReturnValueOnce(mockNextCookiesFuncReturn); - const result = createCookieStorageAdapterFromNextServerContext({ cookies }); + result = await createCookieStorageAdapterFromNextServerContext({ + cookies, + }); + }); it('gets cookie by calling `get` method of the underlying cookie store', () => { result.get(mockKey); @@ -286,7 +300,7 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { }); describe('cookieStorageAdapter created from IncomingMessage and ServerResponse as the Pages Router context', () => { - it('operates with the underlying cookie store', () => { + it('operates with the underlying cookie store', async () => { const mockCookies = { key1: 'value1', key2: 'value2', @@ -302,7 +316,7 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { }, }); - const result = createCookieStorageAdapterFromNextServerContext({ + const result = await createCookieStorageAdapterFromNextServerContext({ request: request as any, response, }); @@ -341,7 +355,7 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { ]); }); - it('operates with the underlying cookie store with encoded cookie names', () => { + it('operates with the underlying cookie store with encoded cookie names', async () => { // these the auth keys generated by Amplify const encodedCookieName1 = encodeURIComponent('test@email.com.idToken'); const encodedCookieName2 = encodeURIComponent( @@ -364,7 +378,7 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { }, }); - const result = createCookieStorageAdapterFromNextServerContext({ + const result = await createCookieStorageAdapterFromNextServerContext({ request: request as any, response, }); @@ -413,7 +427,7 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { ]); }); - it('does not add duplicate cookies when the cookies are defined in the response Set-Cookie headers', () => { + it('does not add duplicate cookies when the cookies are defined in the response Set-Cookie headers', async () => { const mockExistingSetCookieValues = [ 'CognitoIdentityServiceProvider.1234.accessToken=1234;Path=/', 'CognitoIdentityServiceProvider.1234.refreshToken=1234;Path=/', @@ -433,7 +447,7 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { getHeaderSpy.mockReturnValue(mockExistingSetCookieValues); - const result = createCookieStorageAdapterFromNextServerContext({ + const result = await createCookieStorageAdapterFromNextServerContext({ request: request as any, response, }); @@ -455,6 +469,6 @@ describe('createCookieStorageAdapterFromNextServerContext', () => { request: undefined, response: new ServerResponse({} as any), } as any), - ).toThrow(); + ).rejects.toThrow(); }); }); diff --git a/packages/adapter-nextjs/package.json b/packages/adapter-nextjs/package.json index e56ca3d05c0..8c00508ecfd 100644 --- a/packages/adapter-nextjs/package.json +++ b/packages/adapter-nextjs/package.json @@ -5,7 +5,7 @@ "description": "The adapter for the supporting of using Amplify APIs in Next.js.", "peerDependencies": { "aws-amplify": "^6.0.7", - "next": ">=13.5.0 <15.0.0" + "next": ">=13.5.0 <16.0.0" }, "dependencies": { "aws-jwt-verify": "^4.0.1", diff --git a/packages/adapter-nextjs/src/utils/createCookieStorageAdapterFromNextServerContext.ts b/packages/adapter-nextjs/src/utils/createCookieStorageAdapterFromNextServerContext.ts index e3f99cbf96c..c36776d3ad1 100644 --- a/packages/adapter-nextjs/src/utils/createCookieStorageAdapterFromNextServerContext.ts +++ b/packages/adapter-nextjs/src/utils/createCookieStorageAdapterFromNextServerContext.ts @@ -11,9 +11,9 @@ import { NextServer } from '../types'; export const DATE_IN_THE_PAST = new Date(0); -export const createCookieStorageAdapterFromNextServerContext = ( +export const createCookieStorageAdapterFromNextServerContext = async ( context: NextServer.Context, -): CookieStorage.Adapter => { +): Promise => { const { request: req, response: res } = context as Partial; @@ -110,10 +110,10 @@ const createCookieStorageAdapterFromNextRequestAndHttpResponse = ( }; }; -const createCookieStorageAdapterFromNextCookies = ( +const createCookieStorageAdapterFromNextCookies = async ( cookies: NextServer.ServerComponentContext['cookies'], -): CookieStorage.Adapter => { - const cookieStore = cookies(); +): Promise => { + const cookieStore = await cookies(); // When Next cookies() is called in a server component, it returns a readonly // cookie store. Hence calling set and delete throws an error. However, diff --git a/packages/adapter-nextjs/src/utils/createRunWithAmplifyServerContext.ts b/packages/adapter-nextjs/src/utils/createRunWithAmplifyServerContext.ts index 3d20f19cd67..497f56f33dc 100644 --- a/packages/adapter-nextjs/src/utils/createRunWithAmplifyServerContext.ts +++ b/packages/adapter-nextjs/src/utils/createRunWithAmplifyServerContext.ts @@ -32,7 +32,7 @@ export const createRunWithAmplifyServerContext = ({ nextServerContext === null ? sharedInMemoryStorage : createKeyValueStorageFromCookieStorageAdapter( - createCookieStorageAdapterFromNextServerContext( + await createCookieStorageAdapterFromNextServerContext( nextServerContext, ), createTokenValidator({ From 112cb1e76b91045f3233452ff256fb3dd8da1b3d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 23:21:56 +0000 Subject: [PATCH 8/8] chore(deps): bump nanoid from 3.3.7 to 3.3.8 Bumps [nanoid](https://github.com/ai/nanoid) from 3.3.7 to 3.3.8. - [Release notes](https://github.com/ai/nanoid/releases) - [Changelog](https://github.com/ai/nanoid/blob/main/CHANGELOG.md) - [Commits](https://github.com/ai/nanoid/compare/3.3.7...3.3.8) --- updated-dependencies: - dependency-name: nanoid dependency-type: indirect ... Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index d24a3ecba52..d86004d054c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11926,9 +11926,9 @@ mute-stream@^1.0.0, mute-stream@~1.0.0: integrity sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA== nanoid@^3.3.6: - version "3.3.7" - resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8" - integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g== + version "3.3.8" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.8.tgz#b1be3030bee36aaff18bacb375e5cce521684baf" + integrity sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w== nanospinner@^1.1.0: version "1.1.0"