From 493f4232dfe5610f311c8be606173c7817c9b443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Thu, 17 Nov 2022 04:55:57 +0000 Subject: [PATCH 1/3] fix: remove typing from dynamic keyed triggersAutomation --- lib/graphql/resolvers.js | 2 ++ lib/graphql/types.js | 13 +++---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/graphql/resolvers.js b/lib/graphql/resolvers.js index d574565b..4b7d41a4 100644 --- a/lib/graphql/resolvers.js +++ b/lib/graphql/resolvers.js @@ -1,3 +1,4 @@ +const { GraphQLJSONObject } = require('graphql-type-json') const _ = require('lodash/fp') const nmd = require('nano-markdown') @@ -295,6 +296,7 @@ const terms = (parent, { currentConfigVersion, currentHash }, { deviceId, settin module.exports = { + JSONObject: GraphQLJSONObject, Query: { configs, terms, diff --git a/lib/graphql/types.js b/lib/graphql/types.js index e3278d64..1a59fea2 100644 --- a/lib/graphql/types.js +++ b/lib/graphql/types.js @@ -1,5 +1,7 @@ const { gql } = require('apollo-server-express') module.exports = gql` +scalar JSONObject + type Coin { cryptoCode: String! display: String! @@ -49,15 +51,6 @@ type SpeedtestFile { size: Int! } -# True if automatic, False otherwise -type TriggersAutomation { - sanctions: Boolean! - idCardPhoto: Boolean! - idCardData: Boolean! - facephoto: Boolean! - usSsn: Boolean! -} - type CustomScreen { text: String! title: String! @@ -129,7 +122,7 @@ type StaticConfig { speedtestFiles: [SpeedtestFile!]! urlsToPing: [String!]! - triggersAutomation: TriggersAutomation! + triggersAutomation: JSONObject! triggers: [Trigger!]! } From 2788962ac7c50b65736ba414022c829419e21228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Mon, 21 Nov 2022 00:28:44 +0000 Subject: [PATCH 2/3] fix: add CustomTriggersAutomation poller type --- lib/graphql/resolvers.js | 2 -- lib/graphql/types.js | 19 ++++++++++++++++--- lib/new-config-manager.js | 13 ++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/graphql/resolvers.js b/lib/graphql/resolvers.js index 4b7d41a4..d574565b 100644 --- a/lib/graphql/resolvers.js +++ b/lib/graphql/resolvers.js @@ -1,4 +1,3 @@ -const { GraphQLJSONObject } = require('graphql-type-json') const _ = require('lodash/fp') const nmd = require('nano-markdown') @@ -296,7 +295,6 @@ const terms = (parent, { currentConfigVersion, currentHash }, { deviceId, settin module.exports = { - JSONObject: GraphQLJSONObject, Query: { configs, terms, diff --git a/lib/graphql/types.js b/lib/graphql/types.js index 1a59fea2..49fb64bb 100644 --- a/lib/graphql/types.js +++ b/lib/graphql/types.js @@ -1,7 +1,5 @@ const { gql } = require('apollo-server-express') module.exports = gql` -scalar JSONObject - type Coin { cryptoCode: String! display: String! @@ -51,6 +49,21 @@ type SpeedtestFile { size: Int! } +# True if automatic, False otherwise +type TriggersAutomation { + sanctions: Boolean! + idCardPhoto: Boolean! + idCardData: Boolean! + facephoto: Boolean! + usSsn: Boolean! + custom: [CustomTriggersAutomation] +} + +type CustomTriggersAutomation { + id: ID! + type: String! +} + type CustomScreen { text: String! title: String! @@ -122,7 +135,7 @@ type StaticConfig { speedtestFiles: [SpeedtestFile!]! urlsToPing: [String!]! - triggersAutomation: JSONObject! + triggersAutomation: TriggersAutomation! triggers: [Trigger!]! } diff --git a/lib/new-config-manager.js b/lib/new-config-manager.js index 8428d6a6..978f1bed 100644 --- a/lib/new-config-manager.js +++ b/lib/new-config-manager.js @@ -1,4 +1,5 @@ const _ = require('lodash/fp') +const { validate } = require('uuid') const namespaces = { ADVANCED: 'advanced', @@ -126,17 +127,23 @@ const getTriggersAutomation = (customInfoRequests, config) => { idCardPhoto: defaultAutomation, idCardData: defaultAutomation, facephoto: defaultAutomation, - usSsn: defaultAutomation + usSsn: defaultAutomation, + custom: [] } _.forEach(it => { - requirements[it.id] = defaultAutomation + requirements.custom.push({ id: it.id, type: defaultAutomation }) }, infoRequests) const overrides = _.get('triggersConfig_overrides')(config) const requirementsOverrides = _.reduce((acc, override) => { - return _.assign(acc, { [override.requirement]: override.automation }) + return _.assign( + acc, + !validate(override.requirement) + ? { [override.requirement]: override.automation } + : { custom: [...acc.custom ?? [], { id: override.requirement, type: override.automation }] } + ) }, {}, overrides) return _.assign(requirements, requirementsOverrides) From cb6df3f86cddb3898a2db07c5582df55e16709fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Mon, 21 Nov 2022 19:12:49 +0000 Subject: [PATCH 3/3] fix: add backwards compatibility code --- lib/new-config-manager.js | 17 ++++++++++++----- lib/routes/pollingRoutes.js | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/new-config-manager.js b/lib/new-config-manager.js index 978f1bed..8c218d35 100644 --- a/lib/new-config-manager.js +++ b/lib/new-config-manager.js @@ -118,25 +118,32 @@ const getGlobalNotifications = config => getNotifications(null, null, config) const getTriggers = _.get('triggers') /* `customInfoRequests` is the result of a call to `getCustomInfoRequests` */ -const getTriggersAutomation = (customInfoRequests, config) => { +const getTriggersAutomation = (customInfoRequests, config, oldFormat = false) => { return customInfoRequests .then(infoRequests => { const defaultAutomation = _.get('triggersConfig_automation')(config) + const overrides = _.get('triggersConfig_overrides')(config) + const requirements = { sanctions: defaultAutomation, idCardPhoto: defaultAutomation, idCardData: defaultAutomation, facephoto: defaultAutomation, - usSsn: defaultAutomation, - custom: [] + usSsn: defaultAutomation } + if (oldFormat) { + _.forEach(it => { requirements[it.id] = defaultAutomation }, infoRequests) + const oldRequirementsOverrides = _.reduce((acc, override) => _.assign(acc, { [override.requirement]: override.automation }), {}, overrides) + return _.assign(requirements, oldRequirementsOverrides) + } + + requirements.custom = [] + _.forEach(it => { requirements.custom.push({ id: it.id, type: defaultAutomation }) }, infoRequests) - const overrides = _.get('triggersConfig_overrides')(config) - const requirementsOverrides = _.reduce((acc, override) => { return _.assign( acc, diff --git a/lib/routes/pollingRoutes.js b/lib/routes/pollingRoutes.js index e0f4b4c2..00aacd54 100644 --- a/lib/routes/pollingRoutes.js +++ b/lib/routes/pollingRoutes.js @@ -85,7 +85,7 @@ function poll (req, res, next) { pi.recordPing(deviceTime, machineVersion, machineModel), pi.pollQueries(), buildTriggers(configManager.getTriggers(settings.config)), - configManager.getTriggersAutomation(getCustomInfoRequests(true), settings.config), + configManager.getTriggersAutomation(getCustomInfoRequests(true), settings.config, true), ]) .then(([_pingRes, results, triggers, triggersAutomation]) => { const reboot = pid && state.reboots?.[operatorId]?.[deviceId] === pid