Skip to content
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

feat(apply-context): Support MongoDB ObjectId as context variables #88

Merged
merged 2 commits into from
Aug 18, 2022

Conversation

Hybrid-Force
Copy link
Contributor

Add MongoDB ObjectId support as context variables, and hopefully other types of objects with toJSON methods returning strings.

@@ -36,7 +39,10 @@ export function applyContext<T extends object>(
str.replace(reDelimiters, (_, path: string) => {
const value = getValueFromPath(context, path);
if (Array.isArray(value)) return `{${value}}`;
if (value instanceof Object) return 'undefined';
if (value instanceof Object) {
const json = value.toJSON?.();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing that the error is coming from this line because of the .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Optional chaining is not supported in Node 13 and below. I will fix it.

Copy link
Owner

@roggervalf roggervalf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Hybrid-Force, just for curiosity, how are you using this package?

@roggervalf roggervalf merged commit ecb3dbc into roggervalf:master Aug 18, 2022
github-actions bot pushed a commit that referenced this pull request Aug 18, 2022
# [4.17.0](v4.16.0...v4.17.0) (2022-08-18)

### Features

* **apply-context:** support objects with toJSON method as context variables ([#88](#88)) ([ecb3dbc](ecb3dbc))
@github-actions
Copy link

🎉 This PR is included in version 4.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Hybrid-Force Hybrid-Force deleted the object-id-context-variable branch August 19, 2022 14:12
@Hybrid-Force
Copy link
Contributor Author

Thank you @Hybrid-Force, just for curiosity, how are you using this package?

Thanks for this great lib! I am using it for API access control of a multi-tenant app that I am working on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants