This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
CreateCustomerAccountProps, | |
CustomerAccountProps, | |
} from '@models/types'; | |
import { eventName, eventSource } from '@events/customer-account-created'; | |
import { CustomerAccount } from '@domain/customer-account'; | |
import { createCustomerAccount } from '@repositories/create-customer-account-repository'; | |
import { publishEvent } from '@repositories/publish-event-recipient'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
CreateCustomerAccountProps, | |
NewCustomerAccountProps, | |
PaymentStatus, | |
SubscriptionType, | |
UnmarshalledCustomerAccount, | |
} from '@models/types'; | |
import { Entity } from '@entity/entity'; | |
import { PaymentInvalidError } from '@errors/payment-invalid-error'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as AWS from 'aws-sdk'; // <-- service specific | |
// <-- lambda specific | |
import { | |
APIGatewayEvent, | |
APIGatewayProxyHandler, | |
APIGatewayProxyResult, | |
} from 'aws-lambda'; | |
import { OrderCreate } from '../../../../types'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// we get the order details from the event | |
const order: OrderCreated = JSON.parse(body); | |
// we generate an idempotency key | |
const idempotencyKey: string = uuidV5( | |
JSON.stringify(order), | |
namespaces.orders | |
); | |
// create the detail of the event |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ajv from 'ajv'; | |
import addFormats from 'ajv-formats'; | |
const ajvOptions = { | |
allErrors: true, | |
}; | |
// as this is not a monorepo and an example repo only we are using a typescript path alias | |
// whereas this would typically be published to npm and reused in all domain service | |
export function validate( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the order regexes can be used across our domain objects, | |
// events, api validation and more.. | |
export const orderRegexes = { | |
orderId: '^[A-Z]{3}-\\d{1,4}$', | |
addressLine: '^[a-zA-Z0-9 _.-]*$', | |
productId: '^[A-Z]{4}-\\d{1,4}$', | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { orderRegexes } from '@regexes/orders/order'; | |
export const schema = { | |
openapi: '3.0.0', | |
info: { version: '2.0.0', title: 'OrderCreated' }, | |
paths: {}, | |
components: { | |
schemas: { | |
AWSEvent: { | |
type: 'object', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const schema = { | |
openapi: '3.0.0', | |
info: { version: '1.0.0', title: 'OrderCreated' }, | |
paths: {}, | |
components: { | |
schemas: { | |
AWSEvent: { | |
type: 'object', | |
required: [ | |
'detail-type', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const eventBus: IEventBus = EventBus.fromEventBusName( | |
this, | |
"OnlineOrders", | |
"OnlineOrdersEventBus" | |
); | |
// event bridge options for the api gateway integration | |
const eventBridgeOptions: apigw.IntegrationOptions = { | |
credentialsRole: apigwRole, | |
requestParameters: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create the state machine defintion for cancelling an order | |
const cancelOrderStateMachineDefinition: sfn.TaskStateBase = | |
new tasks.LambdaInvoke(this, "CancelOrder", { | |
lambdaFunction: cancelOrderHandler, | |
resultPath: "$", | |
timeout: Duration.seconds(30), | |
comment: "Cancel order task", | |
retryOnServiceExceptions: true, | |
}).addCatch( | |
new tasks.SqsSendMessage(this, "SendSQSFailure", { |