Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

feat: add mock proxy object #19

Merged
merged 12 commits into from
Nov 30, 2022
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Event Horizon CLI
# Event Horizon Dev

This is the accompanying CLI for the @skyleague/event-horizon package.
This is the accompanying dev package for @skyleague/event-horizon.

## How to run

```sh
event-horizon-cli start | npx pino-pretty -m message
event-horizon-dev start | npx pino-pretty -m message
```


## Support

SkyLeague provides Enterprise Support on this open-source library package at clients across industries. Please get in touch via [`https://skyleague.io`](https://skyleague.io).
Expand Down
6,278 changes: 3,155 additions & 3,123 deletions package-lock.json

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@skyleague/event-horizon-cli",
"description": "The accompanying CLI for the @skyleague/event-horizon package.",
"version": "0.0.1",
"name": "@skyleague/event-horizon-dev",
"description": "The accompanying development package for @skyleague/event-horizon.",
"version": "1.0.0",
"license": "MIT",
"author": "SkyLeague Technologies B.V. <technologies@skyleague.io> (https://skyleague.io)",
"main": ".main.js",
"types": "index.d.ts",
"bin": {
"event-horizon-cli": "./bin/run",
"event-horizon-dev": "./bin/run",
"event-horizon": "./bin/run"
},
"engines": {
Expand Down Expand Up @@ -47,25 +47,26 @@
"test": "npx jest"
},
"devDependencies": {
"@skyleague/node-standards": "^1.7.3",
"@types/aws-lambda": "^8.10.103",
"@skyleague/node-standards": "^1.10.0",
"@types/aws-lambda": "^8.10.109",
"@types/source-map-support": "^0.5.6",
"typescript": "^4.8.2"
"typescript": "^4.9.3"
},
"dependencies": {
"@skyleague/axioms": "^1.3.3",
"@skyleague/event-horizon": "^1.10.1",
"@skyleague/space-junk": "^1.0.0",
"@skyleague/axioms": "^1.9.0",
"@skyleague/event-horizon": "^1.26.2",
"@skyleague/space-junk": "^1.2.1",
"@skyleague/therefore": "^1.20.2",
"@types/express": "^4.17.14",
"express": "^4.18.1",
"express": "^4.18.2",
"express-list-endpoints": "^6.0.0",
"express-promise-router": "^4.1.1",
"source-map-support": "^0.5.21",
"tslib": "^2.4.0",
"yargs": "^17.5.1"
"tslib": "^2.4.1",
"yargs": "^17.6.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
}
}
}
98 changes: 98 additions & 0 deletions src/lib/aws/apigateway/apigateway.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import {
$array,
$boolean,
$const,
$dict,
$integer,
$null,
$object,
$optional,
$ref,
$string,
$union,
$unknown,
$validator,
} from '@skyleague/therefore'
import type { ThereforeSchema } from '@skyleague/therefore/src/lib/primitives/types'

export const APIGatewayProxyEventHeaders = $dict($string)
export const APIGatewayProxyEventMultiValueHeaders = $dict($array($string))
export const APIGatewayProxyEventPathParameters = $dict($string)
export const APIGatewayProxyEventQueryStringParameters = $dict($string)
export const APIGatewayProxyEventMultiValueQueryStringParameters = $dict($array($string))
export const APIGatewayProxyEventStageVariables = $dict($string)

export const APIGatewayEventDefaultAuthorizerContext = $union([$const(undefined), $null, $dict($unknown)])

export const APIGatewayEventClientCertificate = $object({
clientCertPem: $string,
serialNumber: $string,
subjectDN: $string,
issuerDN: $string,
validity: $object({
notAfter: $string,
notBefore: $string,
}),
})

export const APIGatewayEventIdentity = $object({
accessKey: $union([$string, $null]),
accountId: $union([$string, $null]),
apiKey: $union([$string, $null]),
apiKeyId: $union([$string, $null]),
caller: $union([$string, $null]),
clientCert: $union([$ref(APIGatewayEventClientCertificate), $null]),
cognitoAuthenticationProvider: $union([$string, $null]),
cognitoAuthenticationType: $union([$string, $null]),
cognitoIdentityId: $union([$string, $null]),
cognitoIdentityPoolId: $union([$string, $null]),
principalOrgId: $union([$string, $null]),
sourceIp: $string,
user: $union([$string, $null]),
userAgent: $union([$string, $null]),
userArn: $union([$string, $null]),
})

export const APIGatewayEventRequestContextWithAuthorizer = (context: ThereforeSchema) =>
$object({
accountId: $string,
apiId: $string,
authorizer: context,
connectedAt: $optional($integer, 'explicit'),
connectionId: $optional($string, 'explicit'),
domainName: $optional($string, 'explicit'),
domainPrefix: $optional($string, 'explicit'),
eventType: $optional($string, 'explicit'),
extendedRequestId: $optional($string, 'explicit'),
protocol: $string,
httpMethod: $string,
identity: $ref(APIGatewayEventIdentity),
messageDirection: $optional($string, 'explicit'),
messageId: $union([$string, $null, $const(undefined)]),
path: $string,
stage: $string,
requestId: $string,
requestTime: $optional($string, 'explicit'),
requestTimeEpoch: $integer,
resourceId: $string,
resourcePath: $string,
routeKey: $optional($string, 'explicit'),
})

export const APIGatewayProxyEventBase = (context: ThereforeSchema) =>
$object({
body: $union([$string, $null]),
headers: $ref(APIGatewayProxyEventHeaders),
multiValueHeaders: $ref(APIGatewayProxyEventMultiValueHeaders),
httpMethod: $string,
isBase64Encoded: $boolean,
path: $string,
pathParameters: $union([$ref(APIGatewayProxyEventPathParameters), $null]),
queryStringParameters: $union([$ref(APIGatewayProxyEventQueryStringParameters), $null]),
multiValueQueryStringParameters: $union([$ref(APIGatewayProxyEventMultiValueQueryStringParameters), $null]),
stageVariables: $union([$ref(APIGatewayProxyEventStageVariables), $null]),
requestContext: APIGatewayEventRequestContextWithAuthorizer(context),
resource: $string,
})

export const APIGatewayProxyEvent = $validator(APIGatewayProxyEventBase(APIGatewayEventDefaultAuthorizerContext))
120 changes: 120 additions & 0 deletions src/lib/aws/apigateway/apigateway.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* Generated by @skyleague/therefore@v1.0.0-local
* Do not manually touch this
*/
/* eslint-disable */
import AjvValidator from 'ajv'
import type { ValidateFunction } from 'ajv'

export interface APIGatewayProxyEventHeaders {
[k: string]: string | undefined
}

export interface APIGatewayProxyEventMultiValueHeaders {
[k: string]: string[] | undefined
}

export interface APIGatewayProxyEventPathParameters {
[k: string]: string | undefined
}

export interface APIGatewayProxyEventQueryStringParameters {
[k: string]: string | undefined
}

export interface APIGatewayProxyEventMultiValueQueryStringParameters {
[k: string]: string[] | undefined
}

export interface APIGatewayProxyEventStageVariables {
[k: string]: string | undefined
}

export type APIGatewayEventDefaultAuthorizerContext = null | null | {
[k: string]: unknown | undefined
}

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

export interface APIGatewayEventIdentity {
accessKey: string | null
accountId: string | null
apiKey: string | null
apiKeyId: string | null
caller: string | null
clientCert: APIGatewayEventClientCertificate | null
cognitoAuthenticationProvider: string | null
cognitoAuthenticationType: string | null
cognitoIdentityId: string | null
cognitoIdentityPoolId: string | null
principalOrgId: string | null
sourceIp: string
user: string | null
userAgent: string | null
userArn: string | null
}

export interface APIGatewayProxyEvent {
body: string | null
headers: APIGatewayProxyEventHeaders
multiValueHeaders: APIGatewayProxyEventMultiValueHeaders
httpMethod: string
isBase64Encoded: boolean
path: string
pathParameters: APIGatewayProxyEventPathParameters | null
queryStringParameters: APIGatewayProxyEventQueryStringParameters | null
multiValueQueryStringParameters: APIGatewayProxyEventMultiValueQueryStringParameters | null
stageVariables: APIGatewayProxyEventStageVariables | null
requestContext: {
accountId: string
apiId: string
authorizer: null | null | {
[k: string]: unknown | undefined
}
connectedAt?: number | undefined
connectionId?: string | undefined
domainName?: string | undefined
domainPrefix?: string | undefined
eventType?: string | undefined
extendedRequestId?: string | undefined
protocol: string
httpMethod: string
identity: APIGatewayEventIdentity
messageDirection?: string | undefined
messageId: string | null | null
path: string
stage: string
requestId: string
requestTime?: string | undefined
requestTimeEpoch: number
resourceId: string
resourcePath: string
routeKey?: string | undefined
}
resource: string
}

export const APIGatewayProxyEvent = {
validate: require('./schemas/api-gateway-proxy-event.schema.js') as ValidateFunction<APIGatewayProxyEvent>,
get schema() {
return APIGatewayProxyEvent.validate.schema
},
get errors() {
return APIGatewayProxyEvent.validate.errors ?? undefined
},
is: (o: unknown): o is APIGatewayProxyEvent => APIGatewayProxyEvent.validate(o) === true,
assert: (o: unknown) => {
if (!APIGatewayProxyEvent.validate(o)) {
throw new AjvValidator.ValidationError(APIGatewayProxyEvent.errors ?? [])
}
},
} as const
1 change: 1 addition & 0 deletions src/lib/aws/apigateway/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './apigateway.type'

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/lib/aws/eventbridge/eventbridge.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { $eventBridge } from './eventbridge'

export const eventBridgeEvent = $eventBridge()
8 changes: 8 additions & 0 deletions src/lib/aws/eventbridge/eventbridge.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { EventBridgeEvent } from './eventbridge.type'

import type { EventBridgeEvent as LambdaEventBridgeEvent } from 'aws-lambda'

test('type is compatible', () => {
const _test: EventBridgeEvent = {} as unknown as LambdaEventBridgeEvent<string, unknown>
const _test2: LambdaEventBridgeEvent<string, unknown> = {} as unknown as EventBridgeEvent
})
25 changes: 25 additions & 0 deletions src/lib/aws/eventbridge/eventbridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { $unknown, $object, $string, $array, $optional, $validator } from '@skyleague/therefore'
import type { ThereforeSchema } from '@skyleague/therefore/src/lib/primitives/types'

export function $eventBridge({
detailType = $string(),
detail = $unknown(),
}: {
detailType?: ThereforeSchema
detail?: ThereforeSchema
} = {}) {
return $validator(
$object({
id: $string,
version: $string,
account: $string,
time: $string,
region: $string,
resources: $array($string()),
source: $string,
'detail-type': detailType,
detail: detail,
'replay-name': $optional($string),
})
)
}
36 changes: 36 additions & 0 deletions src/lib/aws/eventbridge/eventbridge.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Generated by @skyleague/therefore@v1.0.0-local
* Do not manually touch this
*/
/* eslint-disable */
import AjvValidator from 'ajv'
import type { ValidateFunction } from 'ajv'

export interface EventBridgeEvent {
id: string
version: string
account: string
time: string
region: string
resources: string[]
source: string
'detail-type': string
detail: unknown
'replay-name'?: string
}

export const EventBridgeEvent = {
validate: require('./schemas/event-bridge-event.schema.js') as ValidateFunction<EventBridgeEvent>,
get schema() {
return EventBridgeEvent.validate.schema
},
get errors() {
return EventBridgeEvent.validate.errors ?? undefined
},
is: (o: unknown): o is EventBridgeEvent => EventBridgeEvent.validate(o) === true,
assert: (o: unknown) => {
if (!EventBridgeEvent.validate(o)) {
throw new AjvValidator.ValidationError(EventBridgeEvent.errors ?? [])
}
},
} as const
2 changes: 2 additions & 0 deletions src/lib/aws/eventbridge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { $eventBridge } from './eventbridge'
export * from './eventbridge.type'

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading