Upgrading to Root Node 24

Overview

We have launched the Product Module stack Root Node 24. This stack uses the current LTS version of Node.js and includes several quality-of-life improvements.

You can convert a draft version of a product module to Root Node 24 by updating the stack value in root-config to root-node-24. This change will only affect your draft version until you publish the product module.

Key Changes

  • Now using Node.js 24
  • Now using Joi v18
  • Replaced Moment with Day.js
  • Added support for Zod
  • Added optional optimisations using registered functions

Migrating to Root Node 24


These changes introduce certain backward incompatibilities. It is therefore strongly recommended that you thoroughly test your draft version before publishing your changes.

Notable incompatibilities include:

Moment → Day.js

  • All references to moment must be replaced with dayjs.
  • Day.js was designed as a lightweight alternative to Moment and is largely API-compatible. However, some incompatibilities may exist. Therefore it is recommended that you review the Day.js documentation to ensure correct usage.

Joi v18 Changes

The newer version of Joi introduces several API changes that must be addressed:

Removal of Joi.validate

Joi no longer exposes the static method validate. Validation must now be performed on a schema instance.

// Before
Joi.validate(schema, data)
//After
schema.validate(data)
📘

Please note:

A compatibility wrapper has been provided so that the old method will continue to work temporarily. However, this is not guaranteed to be supported in future versions. It is strongly recommended that you update your code to use the new API as part of your migration.

Changes to valid()

Joi no longer accepts an array directly in the valid() method. Instead, values must be spread as arguments.

// Before
Joi.valid(myArray)
// After
Joi.valid(...myArray)

isoDate Extension Rename

In previous versions, we added a custom Joi extension called isoDate. This has now been renamed to isoDateTZ due to a naming conflict with a newly introduced Joi method.

  • isoDateTZ converts the timestamp into the relevant timezone.
  • isoDate now refers to the standard Joi method and does not modify the input.

Registered functions

In order to further optimise code executions we have set up a new mechanism Registered Functions this will allow you to whitelist functions that the handler can execute, essentially any entry points in to your code execution and would include any lifecycle functions and scheduled functions. This is not currently mandatory and if the registeredFunctions object does not exist it will fall back to using the previous code execution handler.

In the future this will be extended to help us prevent unnecessary code executions, for example we will be able to detect that no afterPolicyCanceled hook is defined and therefore we will not attempt to invoke it.

In order to register a function you need to include a registeredFunctions object in the registered-functions.js and accordingly this should reflect as the final file in codeFileOrder found in .root-config.json this object should include the function name as a key and the function as the corresponding value.

registered-functions.js

const registeredFunctions = {
  // Quote hook functions
  validateQuoteRequest,
  getQuote,

  // Application hook functions
  validateApplicationRequest,
  getApplication,

  // Policy hook functions
  getPolicy,
  .
  .
  .
};

export default registeredFunctions;

.root-config.json

  "codeFileOrder": [
    "main.js",
...
    "02-quote-hook.js",
    "03-application-hook.js",
    "04-policy-hook.js",
...
    "registered-functions.js"
  ],