Skip to content

Commit

Permalink
fix(type reorganization) - Reorganize and standardize our action type…
Browse files Browse the repository at this point in the history
…s and transforms (#252)

* rename action

* update names for toggling to better reflect whats going on

* reorganize the actions a bit

* Update imports etc

* correct imports

* more naming and import fixes

* make names a bit more standard

* fix(api js file generation):  Fix the api deployment to only compile the layer during packaging.

* Add authority and origin to all events

* Update new submission types and heavy sink work

* Update tests to appropriately test onemac-legacy

* Fix submission struction... yikes

* Correct how we pass authority and origin INTO the sub service, whoops

* Add an action type index per ben
  • Loading branch information
mdial89f authored Dec 12, 2023
1 parent 0cbcc7e commit 2589794
Show file tree
Hide file tree
Showing 26 changed files with 465 additions and 282 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ tsconfig.tsbuildinfo
build_run
.build
.turbo
coverage
coverage
lambda_layer.zip
4 changes: 4 additions & 0 deletions src/packages/shared-types/action-types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./toggle-withdraw-rai-enabled";
export * from "./issue-rai";
export * from "./respond-to-rai";
export * from "./withdraw-rai";
34 changes: 34 additions & 0 deletions src/packages/shared-types/action-types/issue-rai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { z } from "zod";
import { onemacAttachmentSchema, handleAttachment } from "../attachments";

export const raiIssueSchema = z.object({
id: z.string(),
authority: z.string(),
origin: z.string(),
requestedDate: z.number(),
attachments: z.array(onemacAttachmentSchema).nullish(),
additionalInformation: z.string().nullable().default(null),
submitterName: z.string(),
submitterEmail: z.string(),
});
export type RaiIssue = z.infer<typeof raiIssueSchema>;

export const transformRaiIssue = (id: string) => {
return raiIssueSchema.transform((data) => ({
id,
rais: {
[data.requestedDate]: {
request: {
attachments:
data.attachments?.map((attachment) => {
return handleAttachment(attachment);
}) ?? null,
additionalInformation: data.additionalInformation,
submitterName: data.submitterName,
submitterEmail: data.submitterEmail,
},
},
},
}));
};
export type RaiIssueTransform = z.infer<ReturnType<typeof transformRaiIssue>>;
37 changes: 37 additions & 0 deletions src/packages/shared-types/action-types/respond-to-rai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { z } from "zod";
import { onemacAttachmentSchema, handleAttachment } from "../attachments";

export const raiResponseSchema = z.object({
id: z.string(),
authority: z.string(),
origin: z.string(),
requestedDate: z.number(),
responseDate: z.number(),
attachments: z.array(onemacAttachmentSchema).nullish(),
additionalInformation: z.string().nullable().default(null),
submitterName: z.string(),
submitterEmail: z.string(),
});
export type RaiResponse = z.infer<typeof raiResponseSchema>;

export const transformRaiResponse = (id: string) => {
return raiResponseSchema.transform((data) => ({
id,
rais: {
[data.requestedDate]: {
response: {
attachments:
data.attachments?.map((attachment) => {
return handleAttachment(attachment);
}) ?? null,
additionalInformation: data.additionalInformation,
submitterName: data.submitterName,
submitterEmail: data.submitterEmail,
},
},
},
}));
};
export type RaiResponseTransform = z.infer<
ReturnType<typeof transformRaiResponse>
>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { z } from "zod";

export const toggleWithdrawRaiEnabledSchema = z.object({
authority: z.string(),
origin: z.string(),
raiWithdrawEnabled: z.boolean(),
});
export type ToggleWithdrawRaiEnabled = z.infer<
typeof toggleWithdrawRaiEnabledSchema
>;
37 changes: 37 additions & 0 deletions src/packages/shared-types/action-types/withdraw-rai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { z } from "zod";
import { onemacAttachmentSchema, handleAttachment } from "../attachments";

export const raiWithdrawSchema = z.object({
id: z.string(),
authority: z.string(),
origin: z.string(),
requestedDate: z.number(),
withdrawnDate: z.number(),
attachments: z.array(onemacAttachmentSchema).nullish(),
additionalInformation: z.string().nullable().default(null),
submitterName: z.string(),
submitterEmail: z.string(),
});
export type RaiWithdraw = z.infer<typeof raiWithdrawSchema>;

export const transformRaiWithdraw = (id: string) => {
return raiWithdrawSchema.transform((data) => ({
id,
rais: {
[data.requestedDate]: {
withdraw: {
attachments:
data.attachments?.map((attachment) => {
return handleAttachment(attachment);
}) ?? null,
additionalInformation: data.additionalInformation,
submitterName: data.submitterName,
submitterEmail: data.submitterEmail,
},
},
},
}));
};
export type RaiWithdrawTransform = z.infer<
ReturnType<typeof transformRaiWithdraw>
>;
7 changes: 0 additions & 7 deletions src/packages/shared-types/action-types/withdraw-record.ts

This file was deleted.

45 changes: 45 additions & 0 deletions src/packages/shared-types/attachments.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { z } from "zod";
import { s3ParseUrl } from "shared-utils/s3-url-parser";

export const attachmentTitleMap: Record<string, string> = {
// SPA
cmsForm179: "CMS Form 179",
Expand All @@ -19,3 +22,45 @@ export const attachmentTitleMap: Record<string, string> = {
};
export type AttachmentKey = keyof typeof attachmentTitleMap;
export type AttachmentTitle = typeof attachmentTitleMap[AttachmentKey];

export const onemacAttachmentSchema = z.object({
s3Key: z.string().nullish(),
filename: z.string(),
title: z.string(),
contentType: z.string().nullish(),
url: z.string().url().nullish(),
bucket: z.string().nullish(),
key: z.string().nullish(),
uploadDate: z.number().nullish(),
});
export type OnemacAttachmentSchema = z.infer<typeof onemacAttachmentSchema>;

export function handleAttachment(attachment: OnemacAttachmentSchema) {
let bucket = "";
let key = "";
let uploadDate = 0;
if ("bucket" in attachment) {
bucket = attachment.bucket as string;
}
if ("key" in attachment) {
key = attachment.key as string;
}
if ("uploadDate" in attachment) {
uploadDate = attachment.uploadDate as number;
}
if (bucket == "") {
const parsedUrl = s3ParseUrl(attachment.url || "");
if (!parsedUrl) return null;
bucket = parsedUrl.bucket;
key = parsedUrl.key;
uploadDate = parseInt(attachment.s3Key?.split("/")[0] || "0");
}

return {
title: attachment.title,
filename: attachment.filename,
uploadDate,
bucket,
key,
};
}
3 changes: 2 additions & 1 deletion src/packages/shared-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ export * from "./user";
export * from "./errors";
export * from "./seatool";
export * from "./onemac";
export * from "./onemacLegacy";
export * from "./opensearch";
export * from "./uploads";
export * from "./actions";
export * from "./attachments";
export * from "./authority";
export * from "./action-types/withdraw-record";
export * from "./action-types";
export * from "./forms";
export * from "./inputs";
Loading

0 comments on commit 2589794

Please sign in to comment.