Skip to content

Commit 2c27c5e

Browse files
authored
feat(parser): add TransferFamilySchema for AWS Transfer Family events (#3575)
1 parent 66364b5 commit 2c27c5e

File tree

8 files changed

+87
-0
lines changed

8 files changed

+87
-0
lines changed

Diff for: docs/utilities/parser.md

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Parser comes with the following built-in schemas:
8585
| **SesSchema** | Lambda Event Source payload for Amazon Simple Email Service |
8686
| **SnsSchema** | Lambda Event Source payload for Amazon Simple Notification Service |
8787
| **SqsSchema** | Lambda Event Source payload for Amazon SQS |
88+
| **TransferFamilySchema** | Lambda Event Source payload for AWS Transfer Family events |
8889
| **VpcLatticeSchema** | Lambda Event Source payload for Amazon VPC Lattice |
8990
| **VpcLatticeV2Schema** | Lambda Event Source payload for Amazon VPC Lattice v2 payload |
9091

Diff for: packages/parser/package.json

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
"require": "./lib/cjs/schemas/sqs.js",
113113
"import": "./lib/esm/schemas/sqs.js"
114114
},
115+
"./schemas/transfer-family": {
116+
"require": "./lib/cjs/schemas/transfer-family.js",
117+
"import": "./lib/esm/schemas/transfer-family.js"
118+
},
115119
"./schemas/vpc-lattice": {
116120
"require": "./lib/cjs/schemas/vpc-lattice.js",
117121
"import": "./lib/esm/schemas/vpc-lattice.js"
@@ -323,6 +327,10 @@
323327
"./lib/cjs/envelopes/sqs.d.ts",
324328
"./lib/esm/envelopes/sqs.d.ts"
325329
],
330+
"schemas/transfer-family": [
331+
"./lib/cjs/schemas/transfer-family.d.ts",
332+
"./lib/esm/schemas/transfer-family.d.ts"
333+
],
326334
"envelopes/vpc-lattice": [
327335
"./lib/cjs/envelopes/vpc-lattice.d.ts",
328336
"./lib/esm/envelopes/vpc-lattice.d.ts"

Diff for: packages/parser/src/schemas/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,6 @@ export {
6161
SnsNotificationSchema,
6262
} from './sns.js';
6363
export { SqsSchema, SqsRecordSchema } from './sqs.js';
64+
export { TransferFamilySchema } from './transfer-family.js';
6465
export { VpcLatticeSchema } from './vpc-lattice.js';
6566
export { VpcLatticeV2Schema } from './vpc-latticev2.js';

Diff for: packages/parser/src/schemas/transfer-family.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { z } from 'zod';
2+
3+
/**
4+
*
5+
* Zod schema for AWS Transfer Family events.
6+
*
7+
* @example
8+
* ```json
9+
* {
10+
* "username": "testUser",
11+
* "password": "testPass",
12+
* "protocol": "SFTP",
13+
* "serverId": "s-abcd123456",
14+
* "sourceIp": "192.168.0.100"
15+
* }
16+
* ```
17+
*
18+
* TransferFamilySchema validates events coming from AWS Transfer Family.
19+
*
20+
*/
21+
const TransferFamilySchema = z.object({
22+
username: z.string(),
23+
password: z.string(),
24+
protocol: z.string(),
25+
serverId: z.string(),
26+
sourceIp: z.string().ip(),
27+
});
28+
29+
export { TransferFamilySchema };

Diff for: packages/parser/src/types/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type {
3838
SnsEvent,
3939
SnsSqsNotification,
4040
SqsEvent,
41+
TransferFamilyEvent,
4142
VpcLatticeEvent,
4243
VpcLatticeEventV2,
4344
} from './schema.js';

Diff for: packages/parser/src/types/schema.ts

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import type {
3737
SnsSqsNotificationSchema,
3838
SqsRecordSchema,
3939
SqsSchema,
40+
TransferFamilySchema,
4041
VpcLatticeSchema,
4142
VpcLatticeV2Schema,
4243
} from '../schemas/index.js';
@@ -129,6 +130,8 @@ type SqsEvent = z.infer<typeof SqsSchema>;
129130

130131
type SqsRecord = z.infer<typeof SqsRecordSchema>;
131132

133+
type TransferFamilyEvent = z.infer<typeof TransferFamilySchema>;
134+
132135
type VpcLatticeEvent = z.infer<typeof VpcLatticeSchema>;
133136

134137
type VpcLatticeEventV2 = z.infer<typeof VpcLatticeV2Schema>;
@@ -171,6 +174,7 @@ export type {
171174
SnsRecord,
172175
SqsEvent,
173176
SqsRecord,
177+
TransferFamilyEvent,
174178
VpcLatticeEvent,
175179
VpcLatticeEventV2,
176180
};
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"username": "value",
3+
"password": "value",
4+
"protocol": "SFTP",
5+
"serverId": "s-abcd123456",
6+
"sourceIp": "192.168.0.100"
7+
}
8+
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { TransferFamilySchema } from '../../../src/schemas/transfer-family';
3+
import type { TransferFamilyEvent } from '../../../src/types/schema.js';
4+
import { getTestEvent } from '../helpers/utils';
5+
6+
describe('Schema: TransferFamily', () => {
7+
const baseEvent = getTestEvent<TransferFamilyEvent>({
8+
eventsPath: 'transfer-family',
9+
filename: 'base',
10+
});
11+
12+
it('parses a valid TransferFamily event', () => {
13+
// Prepare
14+
const event = structuredClone(baseEvent);
15+
16+
// Act
17+
const result = TransferFamilySchema.parse(event);
18+
19+
// Assess
20+
expect(result).toStrictEqual(event);
21+
});
22+
23+
it('throws if the event is not a valid TransferFamily event', () => {
24+
// Prepare
25+
const invalidEvent = {
26+
username: 'testUser',
27+
protocol: 'SFTP',
28+
serverId: 's-abcd123456',
29+
sourceIp: 'invalid-ip',
30+
};
31+
32+
// Act & Assess
33+
expect(() => TransferFamilySchema.parse(invalidEvent)).toThrow();
34+
});
35+
});

0 commit comments

Comments
 (0)