Skip to content

Commit

Permalink
Merge pull request #51 from holidayextras/depsVersionUpForNode16
Browse files Browse the repository at this point in the history
Update to node 16 and hapi 21
  • Loading branch information
david-r-edgar authored May 3, 2023
2 parents 3971002 + 3ed29ed commit 6ef171a
Show file tree
Hide file tree
Showing 5 changed files with 7,308 additions and 2,105 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8
16
42 changes: 21 additions & 21 deletions lib/pluginTapestry.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint no-use-before-define:0 */
'use strict'

var Tapestry = require('tapestry')
var Q = require('q')
var _ = require('lodash')
const Tapestry = require('tapestry')
const Q = require('q')
const _ = require('lodash')
// get our code patterns
var codePatterns = require('../configuration/codePatterns')
var pluginName = 'pluginTapestry'
const codePatterns = require('../configuration/codePatterns')
const pluginName = 'pluginTapestry'

const register = function (server, pluginOptions) {
/*
Expand All @@ -15,17 +15,17 @@ const register = function (server, pluginOptions) {
*/
function extractCode (data) {
// If no code found will return null and be ignored by calling function
var code = null
let code = null

// So we have an array of code patterns that we want to check the data against so lets start looping over them
_.each(codePatterns, function (codePattern) {
// If it is an array of patterns we want to match each and every one of these sub patterns, building up the code as we go
if (_.isArray(codePattern)) {
// Start off with a blank string - we will test against an empty string below
var builtCode = ''
let builtCode = ''

// A count to keep track of how many codes we have matched. We will use this to compare to the codes requested.
var codesMatched = 0
let codesMatched = 0

// Loop over each sub code pattern and if the fieldName and the length match append the value of the key to the builtCode string
// and increment the codes matched
Expand Down Expand Up @@ -57,7 +57,7 @@ const register = function (server, pluginOptions) {
*/
function extractCodesAndCallTapestry (tapestryLookupDeferreds, data, identifier, brand) {
// Detect the code
var code = extractCode(data, codePatterns)
const code = extractCode(data, codePatterns)

// This function will recursively call itself if any of the child elements are arrays or objects.
// In which case the function will be called again with the child element becoming 'data'
Expand All @@ -71,10 +71,10 @@ const register = function (server, pluginOptions) {
// If we detected a code before then we want to make a call down to tapestry
if (code) {
// Create the deferred and add it to the array that will be checked below
var tapestryLookupDeferred = Q.defer()
const tapestryLookupDeferred = Q.defer()
tapestryLookupDeferreds.push(tapestryLookupDeferred.promise)
// Make a singular tapestry request with the found code
tapestry.get({ ids: [code], identifier: identifier, brand: brand }, function (tapestryError, result) {
tapestry.get({ ids: [code], identifier, brand }, function (tapestryError, result) {
// Add the returned result as a content object under the original detected node.
if (!_.isUndefined(result) && result.length > 0) {
data.content = _.first(result)
Expand All @@ -91,7 +91,7 @@ const register = function (server, pluginOptions) {
* Will resolve or reject the passed deferred once execution is complete.
*/
function makeItSo (options) {
var deferred = Q.defer()
const deferred = Q.defer()
try {
if (!options) {
throw new Error('invalid options')
Expand All @@ -107,7 +107,7 @@ const register = function (server, pluginOptions) {

if (options.ids.length) {
// Make a singular tapestry request with the ids
var cleanOptions = _.pick(options, ['brand', 'identifier', 'ids', 'lang', 'version'])
const cleanOptions = _.pick(options, ['brand', 'identifier', 'ids', 'lang', 'version'])
tapestry.get(cleanOptions, function (tapestryError, result) {
if (tapestryError) {
deferred.reject({
Expand All @@ -126,7 +126,7 @@ const register = function (server, pluginOptions) {
}
} catch (error) {
deferred.reject({
error: error,
error,
origin: pluginName,
data: options
})
Expand All @@ -140,7 +140,7 @@ const register = function (server, pluginOptions) {
* Will resolve or reject the passed deferred once execution is complete.
*/
function makeItSoComplex (options) {
var deferred = Q.defer()
const deferred = Q.defer()

try {
if (!options) {
Expand All @@ -160,7 +160,7 @@ const register = function (server, pluginOptions) {
}

// An array of deferreds that have to be completed for this help to resolve the main deferred
var tapestryLookupDeferreds = []
const tapestryLookupDeferreds = []

// Kick off the recursive extraction of the codes
extractCodesAndCallTapestry(tapestryLookupDeferreds, options.inputData, options.identifier, options.brand)
Expand All @@ -171,7 +171,7 @@ const register = function (server, pluginOptions) {
})
} catch (error) {
deferred.reject({
error: error,
error,
origin: pluginName,
data: options
})
Expand All @@ -181,14 +181,14 @@ const register = function (server, pluginOptions) {
}

// Create a variable with enough scope for the functions to see it
var tapestry
let tapestry
// Pull together the necessary service configuration, where the cache is and
// where to log messages
var config = server.methods.getService('tapestry')
const config = server.methods.getService('tapestry')
config.cache = server.methods.getConfig().cache

// Create a new Tapestry object based on the resulting configuration
var promise = new Tapestry(config)
const promise = new Tapestry(config)
// Notice we're not handling any errors here, if Tapestry doesn't resolve
// it's promise for some reason, we want things to blow up
promise.done(function (tapestryInstance) {
Expand All @@ -202,7 +202,7 @@ const register = function (server, pluginOptions) {
}

const pkg = require('../package.json')
const {version, name} = pkg
const { version, name } = pkg

exports.plugin = {
register,
Expand Down
Loading

0 comments on commit 6ef171a

Please sign in to comment.