-
Notifications
You must be signed in to change notification settings - Fork 1
Exposing functions to independently apply actions pre-request and post-response #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -83,7 +86,7 @@ class TestContext extends RecaptchaContext { | |||
log_messages: Array<[LogLevel, string[]]> = []; | |||
|
|||
constructor(config: RecaptchaConfig) { | |||
super(config); | |||
super(JSON.parse(JSON.stringify(config))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the config should already be a JS object? why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config needed to be deep-copied. It's global and there are tests that modify it so I had failures when making new tests. We can also have a function that creates a new literal. Do you have a preference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wild that there is no good way to do a deep copy.
I've been using the spread operator {...config}
for stuff like this. though in cases where the object is nested (not here) it doesn't work.
Object.assign({}, config) would also work here (though (not relevant) strips methods and prototypes)
or consider just adding a comment so the motivation for the serialization is clear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a comment for now. We can always revisit.
src/index.test.ts
Outdated
name: "test-policy", | ||
description: "test-description", | ||
path: "/teste2e", | ||
// 'type' isn't a part of the interface, but is added for testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't think the 'type' addition is required anymore; was previously helpful with Zod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will remove.
src/policy.ts
Outdated
*/ | ||
export async function processRequest(context: RecaptchaContext, req: EdgeRequest): Promise<EdgeResponse> { | ||
export async function getActions(context: RecaptchaContext, req: EdgeRequest): Promise<action.Action[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'getActions' sounds like a lightweight operation, where this can actually call 2 RPCs (ListFirewallPolicies (cachable) and CreateAssessment).
consider something like:
FetchActions, RetrieveActions, AcquireActions, ProduceActions, EvaluatePolicyProduceActions....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good idea. Will do.
- getActions => fetchActions - removing type field from actions in tests - deep copy is clear when copying the config in tests
No description provided.