This file contains 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 customerAccountCreatedEvent from '@events/customer-account-created'; | |
import * as customerAccountUpdatedEvent from '@events/customer-account-updated'; | |
import * as customerAccountUpgradedEvent from '@events/customer-account-upgraded'; | |
import { | |
CreateCustomerAccountProps, | |
NewCustomerAccountProps, | |
PaymentStatus, | |
SubscriptionType, | |
} from '@models/customer-account-types'; |
This file contains 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 type DomainEvent = { | |
source: string; | |
eventName: string; | |
event: Record<string, any>; | |
eventDateTime: string; | |
eventVersion: string; | |
}; | |
export interface ICreateDomainEvent { | |
source: string; |
This file contains 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 { DomainEvent } from './domain-event'; | |
import { Entity } from './entity'; | |
// denotes visually that this entity is the aggregate root | |
// and stores the overall domain events for publishing | |
export abstract class AggregateRoot<T> extends Entity<T> { | |
// aggregates which implement this must create this method | |
// to consolidate events from the full aggrgate root and children | |
abstract retrieveDomainEvents(): DomainEvent[]; | |
} |
This file contains 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'; | |
import { CustomerAccountProps } from '@models/types'; | |
import { config } from '@config/config'; | |
const dynamoDb = new AWS.DynamoDB.DocumentClient(); | |
// this is the secondary adapter which creates the account from the db | |
// Note: you would typically use a module or package here to interact | |
// with the database technology - for example dynamoose |
This file contains 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 { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'; | |
import { CreateCustomerAccountProps } from '@models/types'; | |
import { ValidationError } from '@errors/validation-error'; | |
import { createCustomerAccountUseCase } from '@use-cases/create-customer-account'; | |
import { errorHandler } from '@packages/apigw-error-handler'; | |
import { schema } from './create-customer-account.schema'; | |
import { schemaValidator } from '@packages/schema-validator'; | |
import { v4 as uuid } from 'uuid'; |
This file contains 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 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 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 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 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( |