skuba 9.0.0 → 9.0.1-upgrade-cdk-template-20241002233314

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/package.json +1 -1
  2. package/template/greeter/package.json +1 -1
  3. package/template/lambda-sqs-worker/serverless.yml +1 -1
  4. package/template/lambda-sqs-worker-cdk/.env +1 -0
  5. package/template/lambda-sqs-worker-cdk/README.md +145 -0
  6. package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +102 -134
  7. package/template/lambda-sqs-worker-cdk/infra/appStack.test.ts +13 -2
  8. package/template/lambda-sqs-worker-cdk/infra/appStack.ts +52 -6
  9. package/template/lambda-sqs-worker-cdk/infra/config.ts +3 -0
  10. package/template/lambda-sqs-worker-cdk/package.json +8 -1
  11. package/template/lambda-sqs-worker-cdk/src/app.test.ts +116 -0
  12. package/template/lambda-sqs-worker-cdk/src/app.ts +43 -21
  13. package/template/lambda-sqs-worker-cdk/src/config.ts +15 -0
  14. package/template/lambda-sqs-worker-cdk/src/framework/handler.test.ts +61 -0
  15. package/template/lambda-sqs-worker-cdk/src/framework/handler.ts +43 -0
  16. package/template/lambda-sqs-worker-cdk/src/framework/logging.ts +27 -0
  17. package/template/lambda-sqs-worker-cdk/src/framework/metrics.ts +14 -0
  18. package/template/lambda-sqs-worker-cdk/src/framework/validation.test.ts +84 -0
  19. package/template/lambda-sqs-worker-cdk/src/framework/validation.ts +10 -0
  20. package/template/lambda-sqs-worker-cdk/src/mapping/jobScorer.ts +22 -0
  21. package/template/lambda-sqs-worker-cdk/src/services/aws.ts +5 -0
  22. package/template/lambda-sqs-worker-cdk/src/services/jobScorer.test.ts +44 -0
  23. package/template/lambda-sqs-worker-cdk/src/services/jobScorer.ts +59 -0
  24. package/template/lambda-sqs-worker-cdk/src/services/pipelineEventSender.test.ts +40 -0
  25. package/template/lambda-sqs-worker-cdk/src/services/pipelineEventSender.ts +33 -0
  26. package/template/lambda-sqs-worker-cdk/src/testing/handler.ts +13 -0
  27. package/template/lambda-sqs-worker-cdk/src/testing/logging.ts +19 -0
  28. package/template/lambda-sqs-worker-cdk/src/testing/services.ts +28 -0
  29. package/template/lambda-sqs-worker-cdk/src/testing/types.ts +33 -0
  30. package/template/lambda-sqs-worker-cdk/src/types/jobScorer.ts +15 -0
  31. package/template/lambda-sqs-worker-cdk/src/types/pipelineEvents.ts +21 -0
@@ -0,0 +1,33 @@
1
+ import { PublishCommand } from '@aws-sdk/client-sns';
2
+
3
+ import { config } from 'src/config';
4
+
5
+ import { sns } from './aws';
6
+
7
+ export const sendPipelineEvent = async (
8
+ event: unknown,
9
+ smokeTest: boolean = false,
10
+ ): Promise<string> => {
11
+ const snsResponse = await sns.send(
12
+ new PublishCommand({
13
+ Message: JSON.stringify(event),
14
+ ...(smokeTest && {
15
+ MessageAttributes: {
16
+ // Used for connectivity tests.
17
+ // Subscribers should filter out messages containing this attribute.
18
+ SmokeTest: {
19
+ DataType: 'String',
20
+ StringValue: 'true',
21
+ },
22
+ },
23
+ }),
24
+ TopicArn: config.destinationSnsTopicArn,
25
+ }),
26
+ );
27
+
28
+ if (snsResponse.MessageId === undefined) {
29
+ throw Error('SNS did not return a message ID');
30
+ }
31
+
32
+ return snsResponse.MessageId;
33
+ };
@@ -0,0 +1,13 @@
1
+ import type { Context, SQSEvent } from 'aws-lambda';
2
+
3
+ import { chance } from './types';
4
+
5
+ export const createCtx = () =>
6
+ ({
7
+ awsRequestId: chance.guid({ version: 4 }),
8
+ }) as Context;
9
+
10
+ export const createSqsEvent = (bodies: string[]) =>
11
+ ({
12
+ Records: bodies.map((body) => ({ body })),
13
+ }) as SQSEvent;
@@ -0,0 +1,19 @@
1
+ import * as logging from 'src/framework/logging';
2
+
3
+ export const logger = {
4
+ error: jest.fn(),
5
+ info: jest.fn(),
6
+ debug: jest.fn(),
7
+
8
+ clear: () => {
9
+ logger.error.mockClear();
10
+ logger.info.mockClear();
11
+ logger.debug.mockClear();
12
+ },
13
+
14
+ spy: () => {
15
+ jest.spyOn(logging.logger, 'error').mockImplementation(logger.error);
16
+ jest.spyOn(logging.logger, 'info').mockImplementation(logger.info);
17
+ jest.spyOn(logging.logger, 'debug').mockImplementation(logger.debug);
18
+ },
19
+ };
@@ -0,0 +1,28 @@
1
+ import 'aws-sdk-client-mock-jest';
2
+
3
+ import { PublishCommand } from '@aws-sdk/client-sns';
4
+ import { mockClient } from 'aws-sdk-client-mock';
5
+
6
+ import { sns as snsClient } from 'src/services/aws';
7
+ import * as jobScorer from 'src/services/jobScorer';
8
+
9
+ export const scoringService = {
10
+ request: jest.fn(),
11
+
12
+ clear: () => scoringService.request.mockClear(),
13
+
14
+ spy: () =>
15
+ jest
16
+ .spyOn(jobScorer.scoringService, 'request')
17
+ .mockImplementation(scoringService.request),
18
+ };
19
+
20
+ const snsMock = mockClient(snsClient);
21
+
22
+ export const sns = {
23
+ publish: snsMock.on(PublishCommand),
24
+
25
+ clear: () => snsMock.resetHistory(),
26
+
27
+ client: snsMock,
28
+ };
@@ -0,0 +1,33 @@
1
+ import { Chance } from 'chance';
2
+ import { z } from 'zod';
3
+
4
+ import type { JobPublishedEvent } from 'src/types/pipelineEvents';
5
+
6
+ export type IdDescription = z.infer<typeof IdDescriptionSchema>;
7
+
8
+ export const IdDescriptionSchema = z.object({
9
+ id: z.string(),
10
+ description: z.string(),
11
+ });
12
+
13
+ export const chance = new Chance();
14
+
15
+ export const mockIdDescription = (): IdDescription => ({
16
+ id: chance.guid({ version: 4 }),
17
+ description: chance.sentence(),
18
+ });
19
+
20
+ export const mockIdDescriptionJson = (): string =>
21
+ JSON.stringify(mockIdDescription());
22
+
23
+ export const mockJobPublishedEvent = ({
24
+ entityId,
25
+ }: {
26
+ entityId: string;
27
+ }): JobPublishedEvent => ({
28
+ data: {
29
+ details: chance.paragraph(),
30
+ },
31
+ entityId,
32
+ eventType: 'JobPublished',
33
+ });
@@ -0,0 +1,15 @@
1
+ import { z } from 'zod';
2
+
3
+ export type JobScorerInput = z.infer<typeof JobScorerInputSchema>;
4
+
5
+ export const JobScorerInputSchema = z.object({
6
+ id: z.string(),
7
+ details: z.string(),
8
+ });
9
+
10
+ export type JobScorerOutput = z.infer<typeof JobScorerOutputSchema>;
11
+
12
+ export const JobScorerOutputSchema = z.object({
13
+ id: z.string(),
14
+ score: z.number(),
15
+ });
@@ -0,0 +1,21 @@
1
+ import { z } from 'zod';
2
+
3
+ export type JobPublishedEvent = z.infer<typeof JobPublishedEventSchema>;
4
+
5
+ export const JobPublishedEventSchema = z.object({
6
+ data: z.object({
7
+ details: z.string(),
8
+ }),
9
+ entityId: z.string(),
10
+ eventType: z.literal('JobPublished'),
11
+ });
12
+
13
+ export type JobScoredEvent = z.infer<typeof JobScoredEventSchema>;
14
+
15
+ export const JobScoredEventSchema = z.object({
16
+ data: z.object({
17
+ score: z.number(),
18
+ }),
19
+ entityId: z.string(),
20
+ eventType: z.literal('JobScored'),
21
+ });