Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions forge/ee/lib/bom/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports.init = async function (app) {
app.config.features.register('autoNodeUpdate', true, true)

app.housekeeper.registerTask(require('./tasks/cache-catalogues'))
}
49 changes: 49 additions & 0 deletions forge/ee/lib/bom/tasks/cache-catalogues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const axios = require('axios')

const { decodeCertifiedNodesToken } = require('../../../../lib/npm')

const NODE_VERSION_CACHE = 'nodes-latestVersion'

module.exports = {
name: 'cacheCatalogues',
startup: 1000 * 90, // 90 seconds after start up to ensure cache populated
schedule: '47 21 * * *', // Update at 21:47 every day (if not done with a restart)
run: async function (app) {
app.caches.createCache(NODE_VERSION_CACHE)
const cache = app.caches.getCache(NODE_VERSION_CACHE)
// Starting list of catalogues
const cataloguesList = [
'https://catalogue.nodered.org/catalogue.json'
]

const platformNPMEnabled = !!app.config.features.enabled('certifiedNodes', false) &&
!!app.config.features.enabled('ffNodes', false) &&
!!app.settings.get('platform:ff-npm-registry:token')
if (platformNPMEnabled) {
// gets platform wide certified nodes catalogues but not per team override
const { catalogues } = decodeCertifiedNodesToken(app.settings.get('platform:ff-npm-registry:token'), 'placeholder')
cataloguesList.push(...catalogues)
}

for (const cat of cataloguesList) {
app.log.debug(`Checking catalogue ${cat} for latest node versions`)
try {
const res = await axios.get(cat, {
headers: {
Accept: 'application/json'
}
})
if (res.status === 200) {
const modules = res.data.modules
for (const mod of modules) {
const name = mod.id
const version = mod.version
cache.set(name, version)
}
}
} catch (err) {
app.log.debug(`Problem reading catalogue ${cat}, ${err.toString()}`)
}
}
}
}
4 changes: 3 additions & 1 deletion forge/ee/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ module.exports = fp(async function (app, opts) {

// Set the Expert Insights flag
const isInsightsEnabled = isAiEnabled && app.config?.expert?.enabled && app.config?.expert?.insights?.enabled
app.config.features.register('expertInsights', isInsightsEnabled ?? false, true)
app.config.features.register('expertInsights', isInsightsEnabled ?? false, false)

require('./bom').init(app)
}

// Set the Team Library Feature Flag
Expand Down
Loading