-
Notifications
You must be signed in to change notification settings - Fork 118
Conversation
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.
Nice work so far! Adding some comments for later today
plugins/@grouparoo/calculated-property/src/lib/profileProperty.ts
Outdated
Show resolved
Hide resolved
plugins/@grouparoo/calculated-property/public/templates/property/{{{id}}}.js.template
Outdated
Show resolved
Hide resolved
plugins/@grouparoo/calculated-property/src/lib/profileProperty.ts
Outdated
Show resolved
Hide resolved
plugins/@grouparoo/calculated-property/src/lib/propertyOptions.ts
Outdated
Show resolved
Hide resolved
c2f014d
to
3cf2682
Compare
|
plugins/@grouparoo/calculated-property/src/lib/profileProperty.ts
Outdated
Show resolved
Hide resolved
calculatedPropertyValue = vm.run( | ||
`const toRun = ${populatedFunction}; module.exports = toRun();` | ||
); |
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 method is being defined and run in the VM, not our 'real' code
prerequisiteIds.push( | ||
...mustachePrerequisiteIds.map((p) => `property:${p}`) | ||
); | ||
// - property with mustache dependency |
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.
now will sort ANY property with a mustache dependency, not just query source properties
): Promise<string> { | ||
if (string.indexOf("{{") < 0) return string; | ||
|
||
const data = await getProfileData(profile); | ||
return MustacheUtils.strictlyRender(string, data); | ||
if (strict === true) return MustacheUtils.strictlyRender(string, data); | ||
return MustacheUtils.render(string, data); |
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.
This allows non-strict renders for things like returning mustached properties for calculated properties. That means someone can now do things like calculate if ("{{last_purchase_category}}" !== ""){...}
]; | ||
} | ||
|
||
function customFunction () { |
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 function is written outside of the config object to allow for helpful, human-friendly formatting and is then parsed to a string in the template for the plugin to read.
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.
👍
We'll probably add a link to the docs here once they are ready too
sandbox: {}, | ||
argv: [], | ||
env: {}, | ||
}); |
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.
We're allowing console usage, but keeping everything else locked down. External libraries cannot be imported and neither can env variables.
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.
👍
test("it evaluates date strings as expected", async () => { | ||
const fn = `() => { | ||
const date = new Date("{{lastLoginAt.iso}}"); | ||
return date.toISOString(); |
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.
important to note in docs that we return date properties as an object with multiple date formats!
@@ -55,6 +55,7 @@ function getPluginManifest() { | |||
grouparoo: { plugins: [] }, | |||
}, | |||
plugins: [], | |||
missingPlugins: [], |
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.
for logging purposes
profile, | ||
false | ||
); | ||
//fail at every level if someone tries to require a library... this should never be allowed to hit vm.run |
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.
This means that running roo validate
or roo apply
will fail. It fails a bit more abruptly than with other config errors, but I think that's warranted. We don't want anything questionable attempting to be executed. This is one area not covered in our test suite because I couldn't get it to test without throwing the error straight to the console. Open to suggestions there or leaving as is!
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.
I think this can be tested! Wound't this throw in the way you are already testing in __tests__/import/import-property.ts
?
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.
To confirm - this check is to "fail fast" with grouparoo validate
if you try to require something or read process.env. Otherwise, the function would be valid, but produce results you don't expect as we block / null out those at runtime.
We can test that process.env
is empty with a test like
const fn = `() => { return process.env.DATABASE_URL }`;
and show that it's undefined
which might be a good idea.
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.
It wasn't throwing the exact same way, but I've changed it to now
Known limitation: if I generate a property, then |
That's interesting! Can you please write this up? I wonder if it works that way for all changed properties (and not just this new plugin). A changed Property does make an internal run... |
Hmm. Yeah, it's not a calculated properties only thing! Adding to tracker. |
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.
This is looking great! I think there are few things more to test and a little cleanup... and then this is ready to be merged 🎉!
plugins/@grouparoo/calculated-property/__tests__/import/import-property.ts
Outdated
Show resolved
Hide resolved
plugins/@grouparoo/calculated-property/__tests__/import/import-property.ts
Show resolved
Hide resolved
]; | ||
} | ||
|
||
function customFunction () { |
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.
👍
We'll probably add a link to the docs here once they are ready too
plugins/@grouparoo/calculated-property/src/lib/propertyOptions.ts
Outdated
Show resolved
Hide resolved
sandbox: {}, | ||
argv: [], | ||
env: {}, | ||
}); |
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.
👍
profile, | ||
false | ||
); | ||
//fail at every level if someone tries to require a library... this should never be allowed to hit vm.run |
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.
I think this can be tested! Wound't this throw in the way you are already testing in __tests__/import/import-property.ts
?
profile, | ||
false | ||
); | ||
//fail at every level if someone tries to require a library... this should never be allowed to hit vm.run |
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.
To confirm - this check is to "fail fast" with grouparoo validate
if you try to require something or read process.env. Otherwise, the function would be valid, but produce results you don't expect as we block / null out those at runtime.
We can test that process.env
is empty with a test like
const fn = `() => { return process.env.DATABASE_URL }`;
and show that it's undefined
which might be a good idea.
@@ -20,7 +20,7 @@ async function calculateProfilePropertyValue( | |||
); | |||
|
|||
//fail at every level if someone tries to require a library... this should never be allowed to hit vm.run | |||
const illegalStrings = [`require(`, `process.env`]; | |||
const illegalStrings = [`require(`, `process.env`, `async`]; |
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.
lol, that's one way to do it!
We will need to get async functions working in the next version of this (when we want to support fetch, etc) but I guess we don't need it now
DONE:
customFunction
string in aNode VM
instance per profilecustomFunction
as a newProfileProperty
profileProperties
)TO DO AFTER COMPLETE (www):
roo demo -c