From 7032971bb55ba511011f6e63bc5a15feaf737ced Mon Sep 17 00:00:00 2001 From: Yummy-Yums Date: Mon, 16 Mar 2026 20:18:11 +0000 Subject: [PATCH 1/5] feature: added AppSynclambdaAuthroizer --- .../events/AppSyncLambdaAuthorizerEvent.scala | 105 ++++++++++++++++++ .../AppSyncLambdaAuthorizerEventSuite.scala | 55 +++++++++ 2 files changed, 160 insertions(+) create mode 100644 lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala create mode 100644 lambda/shared/src/test/scala/feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala diff --git a/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala b/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala new file mode 100644 index 00000000..90597c5f --- /dev/null +++ b/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala @@ -0,0 +1,105 @@ +/* + * Copyright 2021 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package feral.lambda +package events + +import io.circe.Decoder + +sealed abstract class AppSyncRequestContext { + def apiId: String + def accountId: String + def requestId: String + def operation: String + def channelNamespaceName: String + def channel: String +} + +object AppSyncRequestContext { + + def apply( + apiId: String, + accountId: String, + requestId: String, + operation: String, + channelNamespaceName: String, + channel: String + + ): AppSyncRequestContext = + new Impl( + apiId, + accountId, + requestId, + operation, + channelNamespaceName, + channel + ) + + implicit def decoder = Decoder.forProduct6( + "apiId", + "accountId", + "requestId", + "operation", + "channelNamespaceName", + "channel" + + )(AppSyncRequestContext.apply) + + private final case class Impl( + apiId: String, + accountId: String, + requestId: String, + operation: String, + channelNamespaceName: String, + channel: String + + ) extends AppSyncRequestContext { + override def productPrefix = "AppSyncRequestContext" + } +} + +sealed abstract class AppSyncLambdaAuthorizerEvent { + def authorizationToken: String + def requestContext: AppSyncRequestContext + def requestHeaders: Map[String, String] +} + +object AppSyncLambdaAuthorizerEvent { + def apply( + authorizationToken: String, + requestContext: AppSyncRequestContext, + requestHeaders: Map[String, String] + ): AppSyncLambdaAuthorizerEvent = + new Impl( + authorizationToken: String, + requestContext: AppSyncRequestContext, + requestHeaders: Map[String, String] + ) + + implicit def decoder = Decoder.forProduct3( + "authorizationToken", + "requestContext", + "requestHeaders" + )(AppSyncLambdaAuthorizerEvent.apply) + + private final case class Impl( + authorizationToken: String, + requestContext: AppSyncRequestContext, + requestHeaders: Map[String, String] + ) extends AppSyncLambdaAuthorizerEvent { + override def productPrefix = "AppSyncLambdaAuthorizerEvent" + } +} \ No newline at end of file diff --git a/lambda/shared/src/test/scala/feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala b/lambda/shared/src/test/scala/feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala new file mode 100644 index 00000000..1a6378cd --- /dev/null +++ b/lambda/shared/src/test/scala/feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala @@ -0,0 +1,55 @@ +/* + * Copyright 2021 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package feral.lambda.events + +import io.circe.literal._ +import munit.FunSuite + +class AppSyncLambdaAuthorizerEventSuite extends FunSuite { + + test("decoder") { + import AppSyncLambdaAuthorizerEventSuite._ + + val parsed_event = event.as[AppSyncLambdaAuthorizerEvent].toTry.get + + assertEquals(parsed_event.authorizationToken, "ExampleAUTHtoken123123123") + assertEquals(parsed_event.requestContext.accountId, "111122223333") + assertEquals(parsed_event.requestContext.apiId, "aaaaaa123123123example123") + assertEquals(parsed_event.requestContext.channel, "/news/latest") + assertEquals(parsed_event.requestHeaders("header"), "value") + } + +} + +object AppSyncLambdaAuthorizerEventSuite { + def event = json""" + { + "authorizationToken": "ExampleAUTHtoken123123123", + "requestContext": { + "apiId": "aaaaaa123123123example123", + "accountId": "111122223333", + "requestId": "f4081827-1111-4444-5555-5cf4695f339f", + "operation": "EVENT_PUBLISH", + "channelNamespaceName": "news", + "channel": "/news/latest" + }, + "requestHeaders": { + "header": "value" + } + } + """ +} From 8fdc34059a99789d8a9ca7c65770c76390d735d5 Mon Sep 17 00:00:00 2001 From: Yummy-Yums Date: Mon, 16 Mar 2026 20:24:17 +0000 Subject: [PATCH 2/5] fix: headers --- .../events/AppSyncLambdaAuthorizerEvent.scala | 135 +++++++++--------- 1 file changed, 66 insertions(+), 69 deletions(-) diff --git a/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala b/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala index 90597c5f..beee3b6f 100644 --- a/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala +++ b/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala @@ -20,86 +20,83 @@ package events import io.circe.Decoder sealed abstract class AppSyncRequestContext { - def apiId: String - def accountId: String - def requestId: String - def operation: String - def channelNamespaceName: String - def channel: String + def apiId: String + def accountId: String + def requestId: String + def operation: String + def channelNamespaceName: String + def channel: String } object AppSyncRequestContext { - def apply( - apiId: String, - accountId: String, - requestId: String, - operation: String, - channelNamespaceName: String, - channel: String + def apply( + apiId: String, + accountId: String, + requestId: String, + operation: String, + channelNamespaceName: String, + channel: String + ): AppSyncRequestContext = + new Impl( + apiId, + accountId, + requestId, + operation, + channelNamespaceName, + channel + ) - ): AppSyncRequestContext = - new Impl( - apiId, - accountId, - requestId, - operation, - channelNamespaceName, - channel - ) + implicit def decoder = Decoder.forProduct6( + "apiId", + "accountId", + "requestId", + "operation", + "channelNamespaceName", + "channel" + )(AppSyncRequestContext.apply) - implicit def decoder = Decoder.forProduct6( - "apiId", - "accountId", - "requestId", - "operation", - "channelNamespaceName", - "channel" - - )(AppSyncRequestContext.apply) - - private final case class Impl( - apiId: String, - accountId: String, - requestId: String, - operation: String, - channelNamespaceName: String, - channel: String - - ) extends AppSyncRequestContext { - override def productPrefix = "AppSyncRequestContext" - } + private final case class Impl( + apiId: String, + accountId: String, + requestId: String, + operation: String, + channelNamespaceName: String, + channel: String + ) extends AppSyncRequestContext { + override def productPrefix = "AppSyncRequestContext" + } } sealed abstract class AppSyncLambdaAuthorizerEvent { - def authorizationToken: String - def requestContext: AppSyncRequestContext - def requestHeaders: Map[String, String] + def authorizationToken: String + def requestContext: AppSyncRequestContext + def requestHeaders: Map[String, String] } object AppSyncLambdaAuthorizerEvent { - def apply( - authorizationToken: String, - requestContext: AppSyncRequestContext, - requestHeaders: Map[String, String] - ): AppSyncLambdaAuthorizerEvent = - new Impl( - authorizationToken: String, - requestContext: AppSyncRequestContext, - requestHeaders: Map[String, String] - ) + def apply( + authorizationToken: String, + requestContext: AppSyncRequestContext, + requestHeaders: Map[String, String] + ): AppSyncLambdaAuthorizerEvent = + new Impl( + authorizationToken: String, + requestContext: AppSyncRequestContext, + requestHeaders: Map[String, String] + ) - implicit def decoder = Decoder.forProduct3( - "authorizationToken", - "requestContext", - "requestHeaders" - )(AppSyncLambdaAuthorizerEvent.apply) + implicit def decoder = Decoder.forProduct3( + "authorizationToken", + "requestContext", + "requestHeaders" + )(AppSyncLambdaAuthorizerEvent.apply) - private final case class Impl( - authorizationToken: String, - requestContext: AppSyncRequestContext, - requestHeaders: Map[String, String] - ) extends AppSyncLambdaAuthorizerEvent { - override def productPrefix = "AppSyncLambdaAuthorizerEvent" - } -} \ No newline at end of file + private final case class Impl( + authorizationToken: String, + requestContext: AppSyncRequestContext, + requestHeaders: Map[String, String] + ) extends AppSyncLambdaAuthorizerEvent { + override def productPrefix = "AppSyncLambdaAuthorizerEvent" + } +} From 4ebf182cbad1139b10d33b2032f6a297b35b0475 Mon Sep 17 00:00:00 2001 From: Yummy-Yums Date: Mon, 16 Mar 2026 20:36:32 +0000 Subject: [PATCH 3/5] fix: CI errors resolved --- .../feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/shared/src/test/scala/feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala b/lambda/shared/src/test/scala/feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala index 1a6378cd..47e48da4 100644 --- a/lambda/shared/src/test/scala/feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala +++ b/lambda/shared/src/test/scala/feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala @@ -36,7 +36,7 @@ class AppSyncLambdaAuthorizerEventSuite extends FunSuite { } object AppSyncLambdaAuthorizerEventSuite { - def event = json""" + def event = json""" { "authorizationToken": "ExampleAUTHtoken123123123", "requestContext": { From 45eb1695267079bff9a8ddbf35caa0ff36d450d2 Mon Sep 17 00:00:00 2001 From: Yummy-Yums Date: Mon, 16 Mar 2026 21:18:14 +0000 Subject: [PATCH 4/5] fix: resolve scalaFixError --- .../feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala b/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala index beee3b6f..96b2cede 100644 --- a/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala +++ b/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala @@ -47,7 +47,7 @@ object AppSyncRequestContext { channel ) - implicit def decoder = Decoder.forProduct6( + implicit def decoder: Decoder[AppSyncRequestContext] = Decoder.forProduct6( "apiId", "accountId", "requestId", @@ -86,7 +86,7 @@ object AppSyncLambdaAuthorizerEvent { requestHeaders: Map[String, String] ) - implicit def decoder = Decoder.forProduct3( + implicit def decoder: Decoder[AppSyncLambdaAuthorizerEvent] = Decoder.forProduct3( "authorizationToken", "requestContext", "requestHeaders" From ae48723e9b872c49b61cfe142071524f0de6abe9 Mon Sep 17 00:00:00 2001 From: Yummy-Yums Date: Mon, 22 Jun 2026 15:12:42 +0000 Subject: [PATCH 5/5] removed wrong fields and used queryString convetion --- .../events/AppSyncLambdaAuthorizerEvent.scala | 31 ++++++++++--------- .../AppSyncLambdaAuthorizerEventSuite.scala | 16 +++++----- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala b/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala index 96b2cede..17a1b677 100644 --- a/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala +++ b/lambda/shared/src/main/scala/feral/lambda/events/AppSyncLambdaAuthorizerEvent.scala @@ -18,14 +18,15 @@ package feral.lambda package events import io.circe.Decoder +import io.circe.Json sealed abstract class AppSyncRequestContext { def apiId: String def accountId: String def requestId: String - def operation: String - def channelNamespaceName: String - def channel: String + def queryString: String + def operationName: String + def variables: Map[String, Json] } object AppSyncRequestContext { @@ -34,35 +35,35 @@ object AppSyncRequestContext { apiId: String, accountId: String, requestId: String, - operation: String, - channelNamespaceName: String, - channel: String + queryString: String, + operationName: String, + variables: Map[String, Json] ): AppSyncRequestContext = new Impl( apiId, accountId, requestId, - operation, - channelNamespaceName, - channel + queryString, + operationName, + variables ) implicit def decoder: Decoder[AppSyncRequestContext] = Decoder.forProduct6( "apiId", "accountId", "requestId", - "operation", - "channelNamespaceName", - "channel" + "queryString", + "operationName", + "variables" )(AppSyncRequestContext.apply) private final case class Impl( apiId: String, accountId: String, requestId: String, - operation: String, - channelNamespaceName: String, - channel: String + queryString: String, + operationName: String, + variables: Map[String, Json] ) extends AppSyncRequestContext { override def productPrefix = "AppSyncRequestContext" } diff --git a/lambda/shared/src/test/scala/feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala b/lambda/shared/src/test/scala/feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala index 47e48da4..f9e7cc0d 100644 --- a/lambda/shared/src/test/scala/feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala +++ b/lambda/shared/src/test/scala/feral/lambda/events/AppSyncLambdaAuthorizerEventSuite.scala @@ -29,7 +29,7 @@ class AppSyncLambdaAuthorizerEventSuite extends FunSuite { assertEquals(parsed_event.authorizationToken, "ExampleAUTHtoken123123123") assertEquals(parsed_event.requestContext.accountId, "111122223333") assertEquals(parsed_event.requestContext.apiId, "aaaaaa123123123example123") - assertEquals(parsed_event.requestContext.channel, "/news/latest") + assertEquals(parsed_event.requestContext.requestId, "f4081827-1111-4444-5555-5cf4695f339f") assertEquals(parsed_event.requestHeaders("header"), "value") } @@ -40,13 +40,13 @@ object AppSyncLambdaAuthorizerEventSuite { { "authorizationToken": "ExampleAUTHtoken123123123", "requestContext": { - "apiId": "aaaaaa123123123example123", - "accountId": "111122223333", - "requestId": "f4081827-1111-4444-5555-5cf4695f339f", - "operation": "EVENT_PUBLISH", - "channelNamespaceName": "news", - "channel": "/news/latest" - }, + "apiId": "aaaaaa123123123example123", + "accountId": "111122223333", + "requestId": "f4081827-1111-4444-5555-5cf4695f339f", + "queryString": "mutation CreateEvent {...}\n\nquery MyQuery {...}\n", + "operationName": "MyQuery", + "variables": {} + }, "requestHeaders": { "header": "value" }