Skip to content

Commit 6323aaf

Browse files
committed
update to use enum for module names
1 parent d4fe62d commit 6323aaf

File tree

11 files changed

+35
-18
lines changed

11 files changed

+35
-18
lines changed

src/api/functions/auditLog.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { DynamoDBClient, PutItemCommand } from "@aws-sdk/client-dynamodb";
22
import { marshall } from "@aws-sdk/util-dynamodb";
33
import { genericConfig } from "common/config.js";
4+
import { Modules } from "common/modules.js";
45

56
export type AuditLogEntry = {
6-
module: string;
7+
module: Modules;
78
actor: string;
89
target: string;
910
requestId?: string;

src/api/functions/mobileWallet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
1818
import { RunEnvironment } from "common/roles.js";
1919
import pino from "pino";
2020
import { createAuditLogEntry } from "./auditLog.js";
21-
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
21+
import { Modules } from "common/modules.js";
2222

2323
function trim(s: string) {
2424
return (s || "").replace(/^\s+|\s+$/g, "");
@@ -120,7 +120,7 @@ export async function issueAppleWalletMembershipCard(
120120
const buffer = pkpass.getAsBuffer();
121121
await createAuditLogEntry({
122122
entry: {
123-
module: "mobileWallet",
123+
module: Modules.MOBILE_WALLET,
124124
actor: initiator,
125125
target: email,
126126
message: "Created membership verification pass",

src/api/routes/events.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
getCacheCounter,
3232
} from "api/functions/cache.js";
3333
import { createAuditLogEntry } from "api/functions/auditLog.js";
34+
import { Modules } from "common/modules.js";
3435

3536
const repeatOptions = ["weekly", "biweekly"] as const;
3637
export const CLIENT_HTTP_CACHE_POLICY = `public, max-age=${EVENT_CACHED_DURATION}, stale-while-revalidate=420, stale-if-error=3600`;
@@ -336,7 +337,7 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
336337
await createAuditLogEntry({
337338
dynamoClient: fastify.dynamoClient,
338339
entry: {
339-
module: "events",
340+
module: Modules.EVENTS,
340341
actor: request.username,
341342
target: entryUUID,
342343
message: `${verb} event "${entryUUID}"`,
@@ -396,7 +397,7 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
396397
await createAuditLogEntry({
397398
dynamoClient: fastify.dynamoClient,
398399
entry: {
399-
module: "events",
400+
module: Modules.EVENTS,
400401
actor: request.username,
401402
target: id,
402403
message: `Deleted event "${id}"`,

src/api/routes/iam.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
import { getRoleCredentials } from "api/functions/sts.js";
4141
import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
4242
import { createAuditLogEntry } from "api/functions/auditLog.js";
43+
import { Modules } from "common/modules.js";
4344

4445
const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
4546
const getAuthorizedClients = async () => {
@@ -185,7 +186,7 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
185186
const logPromise = createAuditLogEntry({
186187
dynamoClient: fastify.dynamoClient,
187188
entry: {
188-
module: "iam",
189+
module: Modules.IAM,
189190
actor: request.username!,
190191
target: groupId,
191192
message: `set target roles to ${request.body.roles.toString()}`,
@@ -252,7 +253,7 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
252253
createAuditLogEntry({
253254
dynamoClient: fastify.dynamoClient,
254255
entry: {
255-
module: "iam",
256+
module: Modules.IAM,
256257
actor: request.username!,
257258
target: emails[i],
258259
message: "Invited user to Entra ID tenant.",
@@ -266,7 +267,7 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
266267
createAuditLogEntry({
267268
dynamoClient: fastify.dynamoClient,
268269
entry: {
269-
module: "iam",
270+
module: Modules.IAM,
270271
actor: request.username!,
271272
target: emails[i],
272273
message: "Failed to invite user to Entra ID tenant.",
@@ -372,7 +373,7 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
372373
createAuditLogEntry({
373374
dynamoClient: fastify.dynamoClient,
374375
entry: {
375-
module: "iam",
376+
module: Modules.IAM,
376377
actor: request.username!,
377378
target: request.body.add[i],
378379
message: `added target to group ID ${groupId}`,
@@ -385,7 +386,7 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
385386
createAuditLogEntry({
386387
dynamoClient: fastify.dynamoClient,
387388
entry: {
388-
module: "iam",
389+
module: Modules.IAM,
389390
actor: request.username!,
390391
target: request.body.add[i],
391392
message: `failed to add target to group ID ${groupId}`,
@@ -414,7 +415,7 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
414415
createAuditLogEntry({
415416
dynamoClient: fastify.dynamoClient,
416417
entry: {
417-
module: "iam",
418+
module: Modules.IAM,
418419
actor: request.username!,
419420
target: request.body.add[i],
420421
message: `remove target from group ID ${groupId}`,
@@ -427,7 +428,7 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
427428
createAuditLogEntry({
428429
dynamoClient: fastify.dynamoClient,
429430
entry: {
430-
module: "iam",
431+
module: Modules.IAM,
431432
actor: request.username!,
432433
target: request.body.add[i],
433434
message: `failed to remove target from group ID ${groupId}`,

src/api/routes/stripe.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
InternalServerError,
1818
UnauthenticatedError,
1919
} from "common/errors/index.js";
20+
import { Modules } from "common/modules.js";
2021
import { AppRoles } from "common/roles.js";
2122
import {
2223
invoiceLinkPostResponseSchema,
@@ -140,7 +141,7 @@ const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => {
140141
const logPromise = createAuditLogEntry({
141142
dynamoClient: fastify.dynamoClient,
142143
entry: {
143-
module: "stripe",
144+
module: Modules.STRIPE,
144145
actor: request.username,
145146
target: `Link ${linkId} | Invoice ${invoiceId}`,
146147
message: "Created Stripe payment link",

src/api/routes/tickets.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { AppRoles } from "../../common/roles.js";
2424
import { zodToJsonSchema } from "zod-to-json-schema";
2525
import { ItemPostData } from "common/types/tickets.js";
2626
import { createAuditLogEntry } from "api/functions/auditLog.js";
27+
import { Modules } from "common/modules.js";
2728

2829
const postMerchSchema = z.object({
2930
type: z.literal("merch"),
@@ -478,7 +479,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
478479
await createAuditLogEntry({
479480
dynamoClient: fastify.dynamoClient,
480481
entry: {
481-
module: "tickets",
482+
module: Modules.TICKETS,
482483
actor: request.username!,
483484
target: ticketId,
484485
message: `checked in ticket of type "${request.body.type}" ${request.body.type === "merch" ? `purchased by email ${request.body.email}.` : "."}`,

src/api/sqs/emailNotifications.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { currentEnvironmentConfig, SQSHandlerFunction } from "./index.js";
33
import { SendEmailCommand, SESClient } from "@aws-sdk/client-ses";
44
import { genericConfig } from "common/config.js";
55
import { createAuditLogEntry } from "api/functions/auditLog.js";
6+
import { Modules } from "common/modules.js";
67

78
const stripHtml = (html: string): string => {
89
return html
@@ -44,7 +45,7 @@ export const emailNotificationsHandler: SQSHandlerFunction<
4445
});
4546
const logPromise = createAuditLogEntry({
4647
entry: {
47-
module: "emailNotification",
48+
module: Modules.EMAIL_NOTIFICATION,
4849
actor: metadata.initiator,
4950
target: to.join(";"),
5051
message: `Sent email notification with subject "${subject}".`,

src/api/sqs/handlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import pino from "pino";
2222
import { getRoleCredentials } from "api/functions/sts.js";
2323
import { setPaidMembership } from "api/functions/membership.js";
2424
import { createAuditLogEntry } from "api/functions/auditLog.js";
25+
import { Modules } from "common/modules.js";
2526

2627
const getAuthorizedClients = async (
2728
logger: pino.Logger,
@@ -111,7 +112,7 @@ export const provisionNewMemberHandler: SQSHandlerFunction<
111112
if (updated) {
112113
const logPromise = createAuditLogEntry({
113114
entry: {
114-
module: "provisionNewMember",
115+
module: Modules.PROVISION_NEW_MEMBER,
115116
actor: metadata.initiator,
116117
target: email,
117118
message: "Marked target as a paid member.",

src/common/modules.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export enum Modules {
2+
IAM = "iam",
3+
EVENTS = "events",
4+
STRIPE = "stripe",
5+
TICKETS = "tickets",
6+
EMAIL_NOTIFICATION = "emailNotification",
7+
PROVISION_NEW_MEMBER = "provisionNewMember",
8+
MOBILE_WALLET = "mobileWallet"
9+
}

tests/unit/functions/auditLog.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { mockClient } from "aws-sdk-client-mock";
44
import { DynamoDBClient, PutItemCommand } from "@aws-sdk/client-dynamodb";
55
import { afterEach, beforeEach } from "node:test";
66
import { genericConfig } from "../../../src/common/config";
7+
import { Modules } from "../../../src/common/modules.js";
78
import { marshall } from "@aws-sdk/util-dynamodb";
89

910

@@ -21,7 +22,7 @@ describe("Audit Log tests", () => {
2122
);
2223

2324
const payload = {
24-
module: 'iam',
25+
module: Modules.IAM,
2526
2627
target: '[email protected]',
2728
requestId: 'abcdef',

0 commit comments

Comments
 (0)