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

refactor(aws-lambda): merge custom-context into types #2889

Merged
merged 2 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions runtime_tests/lambda/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Readable } from 'stream'
import { handle, streamHandle } from '../../src/adapter/aws-lambda/handler'
import type { LambdaEvent } from '../../src/adapter/aws-lambda/handler'
import type {
ApiGatewayRequestContext,
ApiGatewayRequestContextV2,
} from '../../src/adapter/aws-lambda/custom-context'
import { handle, streamHandle } from '../../src/adapter/aws-lambda/handler'
import type { LambdaEvent } from '../../src/adapter/aws-lambda/handler'
import type { LambdaContext } from '../../src/adapter/aws-lambda/types'
LambdaContext,
} from '../../src/adapter/aws-lambda/types'
import { getCookie, setCookie } from '../../src/helper/cookie'
import { streamSSE } from '../../src/helper/streaming'
import { Hono } from '../../src/hono'
Expand Down
87 changes: 0 additions & 87 deletions src/adapter/aws-lambda/custom-context.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/adapter/aws-lambda/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import type {
ALBRequestContext,
ApiGatewayRequestContext,
ApiGatewayRequestContextV2,
} from './custom-context'
import type { Handler, LambdaContext } from './types'
Handler,
LambdaContext,
} from './types'

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions src/adapter/aws-lambda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
ApiGatewayRequestContext,
ApiGatewayRequestContextV2,
ALBRequestContext,
} from './custom-context'
export type { LambdaContext } from './types'
LambdaContext,
} from './types'

Check warning on line 13 in src/adapter/aws-lambda/index.ts

View check run for this annotation

Codecov / codecov/patch

src/adapter/aws-lambda/index.ts#L12-L13

Added lines #L12 - L13 were not covered by tests
88 changes: 88 additions & 0 deletions src/adapter/aws-lambda/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,91 @@ export type Handler<TEvent = any, TResult = any> = (
context: LambdaContext,
callback: Callback<TResult>
) => void | Promise<TResult>

interface ClientCert {
clientCertPem: string
subjectDN: string
issuerDN: string
serialNumber: string
validity: {
notBefore: string
notAfter: string
}
}

interface Identity {
accessKey?: string
accountId?: string
caller?: string
cognitoAuthenticationProvider?: string
cognitoAuthenticationType?: string
cognitoIdentityId?: string
cognitoIdentityPoolId?: string
principalOrgId?: string
sourceIp: string
user?: string
userAgent: string
userArn?: string
clientCert?: ClientCert
}

export interface ApiGatewayRequestContext {
accountId: string
apiId: string
authorizer: {
claims?: unknown
scopes?: unknown
}
domainName: string
domainPrefix: string
extendedRequestId: string
httpMethod: string
identity: Identity
path: string
protocol: string
requestId: string
requestTime: string
requestTimeEpoch: number
resourceId?: string
resourcePath: string
stage: string
}

interface Authorizer {
iam?: {
accessKey: string
accountId: string
callerId: string
cognitoIdentity: null
principalOrgId: null
userArn: string
userId: string
}
}

export interface ApiGatewayRequestContextV2 {
accountId: string
apiId: string
authentication: null
authorizer: Authorizer
domainName: string
domainPrefix: string
http: {
method: string
path: string
protocol: string
sourceIp: string
userAgent: string
}
requestId: string
routeKey: string
stage: string
time: string
timeEpoch: number
}

export interface ALBRequestContext {
elb: {
targetGroupArn: string
}
}