-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lambda): functionality for updating ID, values, and deleting pac…
…kages (#923) * wip * check sinkmain * remove deleted code * rename to handler * add env config * fix parse * fix event body type * add origin * add logs * log * fix test and add log * temp bypass record event * change order of sinkmain if * push into sinkmain * add id into doc * log in sinkmain * format deleted package * add sink change log * change order of sinklog changelog * fix schema * add logs changelog * try adding delete property * fix property * log query * change term * letter s * must not * wip update package fields * add log * omg * try fix test and changelog update fields * transform updated values? * typo * again * try * remove origin * add timestamp? * fix changelog not showing * edit changelog text * meg * changelog admin changes updates, language TBD * edit schema parsing for sinkmain * change schema parsing in changelog * rm commented out code * fix eslint * clean up * remove more logs * readd comment * cleanup zod schema logic * change event name * test adminchange for delete * attachments is undefined for soft deleted packages, add optional * wip * revert safeparse * remove empty test * set default attachments value * move default attachments default value * delete test, will be handled by sinkmain tests * edit todo msg * rm unused code * remove origin property * test * check for existing package id * add update id schema * add admin change type * typo * again * add log * edit log * edit changelog * exclude _index * fix destructuring * source? * test log * hide changelog * ew test * add changemade and types to Document type * add zod to event body * update response status codes * merge and rm console log * rm comment * wip id validation * test logs * again * add logs * logs * fix * test format * log * test moving responses into funcs * test * fix punctuation * wip address comments * rm old code * add comment * rm eslint ignore * move topicname logic * test package event type in changelog * log * logs * fix * move event * move logic * logs * typo * what * log * add mako origin to get to transforms * umm touching opensearch * typo * logs * revert * try * revert * revert changelog * hi * logs * add old id to changelog * offset stuff * logs * logs * duplicate offset * fix * log hits * logs * test * fix * fix * idToBeUpdated * add onemac * fix * clean * move around * clean * remove casting * casting throws type error * fix import and add test --------- Co-authored-by: asharonbaltazar <58940073+asharonbaltazar@users.noreply.github.com>
- Loading branch information
1 parent
75dfb41
commit d0b74dd
Showing
12 changed files
with
502 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { z } from "zod"; | ||
|
||
export const deleteAdminChangeSchema = z | ||
.object({ | ||
id: z.string(), | ||
deleted: z.boolean(), | ||
adminChangeType: z.literal("delete"), | ||
}) | ||
.and(z.record(z.string(), z.any())); | ||
|
||
export const updateValuesAdminChangeSchema = z | ||
.object({ | ||
id: z.string(), | ||
adminChangeType: z.literal("update-values"), | ||
}) | ||
.and(z.record(z.string(), z.any())); | ||
|
||
export const updateIdAdminChangeSchema = z | ||
.object({ | ||
id: z.string(), | ||
adminChangeType: z.literal("update-id"), | ||
idToBeUpdated: z.string(), | ||
}) | ||
.and(z.record(z.string(), z.any())); | ||
|
||
export const transformDeleteSchema = (offset: number) => | ||
deleteAdminChangeSchema.transform((data) => ({ | ||
...data, | ||
event: "delete", | ||
packageId: data.id, | ||
id: `${data.id}-${offset}`, | ||
timestamp: Date.now(), | ||
})); | ||
|
||
export const transformUpdateValuesSchema = (offset: number) => | ||
updateValuesAdminChangeSchema.transform((data) => ({ | ||
...data, | ||
event: "update-values", | ||
packageId: data.id, | ||
id: `${data.id}-${offset}`, | ||
timestamp: Date.now(), | ||
})); | ||
|
||
export const transformedUpdateIdSchema = updateIdAdminChangeSchema.transform((data) => ({ | ||
...data, | ||
event: "update-id", | ||
packageId: data.id, | ||
id: `${data.id}`, | ||
timestamp: Date.now(), | ||
})); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { response } from "lib/libs/handler-lib"; | ||
import { events } from "lib/packages/shared-types"; | ||
import { getPackageChangelog } from "lib/libs/api/package"; | ||
|
||
export const getPackageType = async (packageId: string) => { | ||
// use event of current package to determine how ID should be formatted | ||
try { | ||
const packageChangelog = await getPackageChangelog(packageId); | ||
const packageSubmissionType = packageChangelog.hits.hits.find( | ||
(pkg) => pkg._source.event in events, | ||
); | ||
|
||
if (!packageSubmissionType) { | ||
throw new Error("The type of package could not be determined."); | ||
} | ||
|
||
return packageSubmissionType._source.event; | ||
} catch (error) { | ||
return response({ | ||
statusCode: 500, | ||
body: { | ||
message: error.message || "An error occurred determining the package submission type.", | ||
}, | ||
}); | ||
} | ||
}; |
Oops, something went wrong.