Using a function in multiple rules

We have multiple rules and some of the rules use functions that is assigned to the global object. This is done in a rule running first in the “rule chain”, like so:

if (!global.foo) {
  global.foo = function () { };
}

This used to be recommended approach according to the Auth0 rules documentation:

However, in the current rules documentation, this section has been removed.

Are there any other (and better) ways to accomplish this? E.g. require-ing the functions instead?

The legacy approach will continue to work for the time being (at least 6 months), though there currently is not a better alternative for rules at this time.

Thanks! And from the wording of your response I assume that the support for this approach might be phased out at some time?

Not exactly - as we migrate the platform for Rules this approach may or may not work - we don’t know right now. However, in the new world for rules/hooks all npm modules should be available so that would be the preferred option.