Repository: sid88in/serverless-appsync-plugin (ts)

Issue:
[v2] - Error when using AMAZON_COGNITO_USER_POOLS as additionalAuthentications type
In my serverless.yml I have:

```
  authentication:
    type: AWS_IAM
  additionalAuthentications:
    - type: 'AMAZON_COGNITO_USER_POOLS'
      config:
        userPoolId: xxxx
```

Upon deploy this results in the error:

```
UPDATE_FAILED: GraphQlApi (AWS::AppSync::GraphQLApi)
Property validation failure: [Encountered unsupported properties in {/AdditionalAuthenticationProviders/0/UserPoolConfig}: [DefaultAction]]
```

Problem appears to be that DefaultAction is always set here, when it's only valid for authentication not additionalAuthentications

https://github.com/sid88in/serverless-appsync-plugin/blob/ded433996b31119d9a3bc17fb3a83a1ab5473aae/src/resources/Api.ts#L421





Pull request description:
fix(auth): Cognito additional auth
Fixes #552 

Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8d42319..12fb1fc 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -15,7 +15,7 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        node: [16]
+        node: [16, 18]
     steps:
       - uses: actions/setup-node@v3
         with:
diff --git a/src/resources/Api.ts b/src/resources/Api.ts
index cceaad3..691d108 100644
--- a/src/resources/Api.ts
+++ b/src/resources/Api.ts
@@ -88,7 +88,7 @@ export class Api {
       merge(endpointResource.Properties, {
         AdditionalAuthenticationProviders:
           this.config.additionalAuthentications?.map((provider) =>
-            this.compileAuthenticationProvider(provider),
+            this.compileAuthenticationProvider(provider, true),
           ),
       });
     }
@@ -411,14 +411,18 @@ export class Api {
     };
   }
 
-  getUserPoolConfig(auth: CognitoAuth) {
+  getUserPoolConfig(auth: CognitoAuth, isAdditionalAuth = false) {
     const userPoolConfig = {
       AwsRegion: auth.config.awsRegion || { 'Fn::Sub': '${AWS::Region}' },
       UserPoolId: auth.config.userPoolId,
       AppIdClientRegex: auth.config.appIdClientRegex,
-      // Default action is the one passed in the config
-      // or 'ALLOW'
-      DefaultAction: auth.config.defaultAction || 'ALLOW',
+      ...(!isAdditionalAuth
+        ? {
+            // Default action is the one passed in the config
+            // or 'ALLOW'
+            DefaultAction: auth.config.defaultAction || 'ALLOW',
+          }
+        : {}),
     };
 
     return userPoolConfig;
@@ -468,14 +472,16 @@ export class Api {
     }));
   }
 
-  compileAuthenticationProvider(provider: Auth) {
+  compileAuthenticationProvider(provider: Auth, isAdditionalAuth = false) {
     const { type } = provider;
     const authPrivider = {
       AuthenticationType: type,
     };
 
     if (type === 'AMAZON_COGNITO_USER_POOLS') {
-      merge(authPrivider, { UserPoolConfig: this.getUserPoolConfig(provider) });
+      merge(authPrivider, {
+        UserPoolConfig: this.getUserPoolConfig(provider, isAdditionalAuth),
+      });
     } else if (type === 'OPENID_CONNECT') {
       merge(authPrivider, {
         OpenIDConnectConfig: this.getOpenIDConnectConfig(provider),


Test patch:
diff --git a/src/__tests__/api.test.ts b/src/__tests__/api.test.ts
index 196f635..9f8c19b 100644
--- a/src/__tests__/api.test.ts
+++ b/src/__tests__/api.test.ts
@@ -74,6 +74,14 @@ describe('Api', () => {
     it('should compile the Api Resource with additional auths', () => {
       const api = new Api(
         given.appSyncConfig({
+          authentication: {
+            type: 'AMAZON_COGNITO_USER_POOLS',
+            config: {
+              userPoolId: 'pool123',
+              awsRegion: 'us-east-1',
+              appIdClientRegex: '[a-z]',
+            },
+          },
           additionalAuthentications: [
             {
               type: 'AMAZON_COGNITO_USER_POOLS',
@@ -117,7 +125,6 @@ describe('Api', () => {
                   "UserPoolConfig": Object {
                     "AppIdClientRegex": "[a-z]",
                     "AwsRegion": "us-east-1",
-                    "DefaultAction": "ALLOW",
                     "UserPoolId": "pool123",
                   },
                 },
@@ -147,7 +154,7 @@ describe('Api', () => {
                   },
                 },
               ],
-              "AuthenticationType": "API_KEY",
+              "AuthenticationType": "AMAZON_COGNITO_USER_POOLS",
               "Name": "MyApi",
               "Tags": Array [
                 Object {
@@ -155,6 +162,12 @@ describe('Api', () => {
                   "Value": "Dev",
                 },
               ],
+              "UserPoolConfig": Object {
+                "AppIdClientRegex": "[a-z]",
+                "AwsRegion": "us-east-1",
+                "DefaultAction": "ALLOW",
+                "UserPoolId": "pool123",
+              },
               "XrayEnabled": false,
             },
             "Type": "AWS::AppSync::GraphQLApi",