2024-04-04 16:13:53 +00:00
module . exports = {
friendlyName : 'Save questionnaire progress and continue' ,
description : 'Saves the user\'s current progress in the get started questionnaire' ,
inputs : {
currentStep : {
type : 'string' ,
description : 'The step of the get started questionnaire that is being saved.' ,
isIn : [
'start' ,
'what-are-you-using-fleet-for' ,
'have-you-ever-used-fleet' ,
'how-many-hosts' ,
'will-you-be-self-hosting' ,
'what-are-you-working-on-eo-security' ,
2024-04-08 10:39:19 +00:00
'what-does-your-team-manage-eo-it' ,
'what-does-your-team-manage-vm' ,
'what-do-you-manage-mdm' ,
2024-04-04 16:13:53 +00:00
'is-it-any-good' ,
'what-did-you-think' ,
'deploy-fleet-in-your-environment' ,
'managed-cloud-for-growing-deployments' ,
'self-hosted-deploy' ,
2024-05-01 23:22:47 +00:00
'whats-left-to-get-you-set-up' ,
'how-was-your-deployment' ,
2024-04-04 16:13:53 +00:00
]
} ,
formData : {
type : { } ,
description : 'The formdata that will be saved for this step of the get started questionnaire'
2024-04-08 10:39:19 +00:00
} ,
2024-04-04 16:13:53 +00:00
} ,
exits : {
2024-04-08 10:39:19 +00:00
success : {
outputDescription : 'All get started questionnaire answers accumulated so far by this user.' ,
outputType : { }
} ,
2024-04-04 16:13:53 +00:00
} ,
fn : async function ( { currentStep , formData } ) {
// find this user's DB record.
2024-04-08 10:39:19 +00:00
let userRecord = this . req . me ;
2024-04-04 16:13:53 +00:00
let questionnaireProgress ;
// If this user doesn't have a lastSubmittedGetStartedQuestionnaireStep or getStartedQuestionnaireAnswers, create an empty dictionary to store their answers.
if ( ! userRecord . lastSubmittedGetStartedQuestionnaireStep || _ . isEmpty ( userRecord . getStartedQuestionnaireAnswers ) ) {
questionnaireProgress = { } ;
} else { // other wise clone it from the user record.
questionnaireProgress = _ . clone ( userRecord . getStartedQuestionnaireAnswers ) ;
}
2024-04-20 23:27:17 +00:00
// Tease out what liur buying situation will now be (or is and was, if it's not changing)
2024-04-21 00:02:06 +00:00
let primaryBuyingSituation = formData . primaryBuyingSituation === undefined ? this . req . me . primaryBuyingSituation : formData . primaryBuyingSituation ;
2024-04-20 23:27:17 +00:00
2024-04-04 16:13:53 +00:00
// When the 'what-are-you-using-fleet-for' is completed, update this user's DB record and session to include their answer.
if ( currentStep === 'what-are-you-using-fleet-for' ) {
2024-04-19 02:18:36 +00:00
await User . updateOne ( { id : this . req . me . id } )
. set ( {
2024-04-20 23:27:17 +00:00
primaryBuyingSituation : primaryBuyingSituation
2024-04-08 10:39:19 +00:00
} ) ;
2024-04-04 16:13:53 +00:00
// Set the primary buying situation in the user's session.
this . req . session . primaryBuyingSituation = primaryBuyingSituation ;
2024-04-20 23:27:17 +00:00
} //fi
2024-04-19 02:18:36 +00:00
// ┌─┐┌─┐┌┬┐ ┌─┐┌─┐┬ ┬┌─┐┬ ┬┌─┐┬ ┌─┐┌─┐┬┌─┐┌─┐┬ ┌─┐┌┬┐┌─┐┌─┐┌─┐
// └─┐├┤ │ ├─┘└─┐└┬┘│ ├─┤│ ││ │ ││ ┬││ ├─┤│ └─┐ │ ├─┤│ ┬├┤
// └─┘└─┘ ┴ ┴ └─┘ ┴ └─┘┴ ┴└─┘┴─┘└─┘└─┘┴└─┘┴ ┴┴─┘ └─┘ ┴ ┴ ┴└─┘└─┘
// This is how the questionnaire steps/options change a user's psychologicalStage value.
// 'start': No change
2024-04-20 23:27:17 +00:00
// 'what-are-you-using-fleet-for':
// - (any option) = stage 2
2024-04-19 02:18:36 +00:00
// 'have-you-ever-used-fleet':
// - yes-deployed: » Stage 6
2024-05-02 16:25:48 +00:00
// - yes-recently-deployed: » Stage 5
2024-04-20 23:27:17 +00:00
// - yes-deployed-local: » Stage 3 (Tried Fleet but might not have a use case)
// - yes-deployed-long-time: Stage 2 (Tried Fleet long ago but might not fully grasp)
// - no: Stage 2 (Never tried Fleet and might not fully grasp)
2024-05-02 16:25:48 +00:00
// 'how-many-hosts': Stage 4/5/6
// 'will-you-be-self-hosting': Stage 5/6
2024-04-19 02:18:36 +00:00
// 'what-are-you-working-on-eo-security'
2024-04-26 17:42:48 +00:00
// - no-use-case-yet: » Stage 2/3 (depends on answer from 'have-you-ever-used-fleet' step)
2024-04-19 02:18:36 +00:00
// - All other options » Stage 4
// 'what-does-your-team-manage-eo-it'
2024-04-26 17:42:48 +00:00
// - no-use-case-yet: » Stage 2/3 (depends on answer from 'have-you-ever-used-fleet' step)
2024-04-19 02:18:36 +00:00
// - All other options » Stage 4
// 'what-does-your-team-manage-vm'
2024-04-26 17:42:48 +00:00
// - no-use-case-yet: » Stage 2/3 (depends on answer from 'have-you-ever-used-fleet' step)
2024-04-19 02:18:36 +00:00
// - All other options » Stage 4
// 'what-do-you-manage-mdm'
2024-04-26 17:42:48 +00:00
// - no-use-case-yet: » Stage 2/3 (depends on answer from 'have-you-ever-used-fleet' step)
2024-04-19 02:18:36 +00:00
// - All other options » Stage 4
2024-04-26 17:42:48 +00:00
// 'is-it-any-good': Stage 2/3/4 (depends on answer from 'have-you-ever-used-fleet' & the buying situation specific step)
2024-04-19 02:18:36 +00:00
// 'what-did-you-think'
2024-05-02 16:25:48 +00:00
// - host-fleet-for-me » Stage 4
// - deploy-fleet-in-environment » Stage 4
2024-04-26 17:42:48 +00:00
// - let-me-think-about-it » Stage 2
2024-05-02 16:25:48 +00:00
// FUTURE: Should the step about deploying fleet in your env be here? (For same reason is-it-any-good is here: when navigating back then forwards?)
2024-05-01 23:22:47 +00:00
// 'how-was-your-deployment'
2024-05-02 16:25:48 +00:00
// - up-and-running » Stage 5
// - kinda-stuck » Stage 4 (...at best! Still got the use case.)
// - havent-gotten-to-it » Stage 4 (same as above)
// - changed-mind-want-managed-deployment » Stage 4 (same as above)
2024-05-01 23:22:47 +00:00
// - decided-to-not-use-fleet » Stage 2
// 'whats-left-to-get-you-set-up'
2024-05-02 16:25:48 +00:00
// - need-premium-license-key » No change (Stage ??)
// - help-show-fleet-to-my-team » No change (Stage ??)
// - procurement-wants-some-stuff » No change (Stage ??)
// - nothing » No change (Stage ??)
2024-05-01 23:22:47 +00:00
2024-04-19 02:18:36 +00:00
let psychologicalStage = userRecord . psychologicalStage ;
// Get the value of the submitted formData, we do this so we only need to check one variable, instead of (formData.attribute === 'foo');
let valueFromFormData = _ . values ( formData ) [ 0 ] ;
2024-04-26 17:42:48 +00:00
if ( currentStep === 'start' ) {
// There is change when the user completes the start step.
} else if ( currentStep === 'what-are-you-using-fleet-for' ) {
2024-04-20 23:27:17 +00:00
psychologicalStage = '2 - Aware' ;
} else if ( currentStep === 'have-you-ever-used-fleet' ) {
2024-05-02 16:25:48 +00:00
if ( [ 'yes-deployed' ] . includes ( valueFromFormData ) ) {
2024-04-19 02:18:36 +00:00
// If the user has Fleet deployed, set their stage to 6.
psychologicalStage = '6 - Has team buy-in' ;
2024-05-02 16:25:48 +00:00
} else if ( valueFromFormData === 'yes-recently-deployed' ) {
psychologicalStage = '5 - Personally confident' ;
2024-04-19 02:18:36 +00:00
} else if ( valueFromFormData === 'yes-deployed-local' ) {
// If they've tried Fleet locally, set their stage to 3.
psychologicalStage = '3 - Intrigued' ;
2024-04-20 23:27:17 +00:00
} else {
// Otherwise, we'll just assume liu're only aware. Maybe liu don't fully grasp what Fleet can do.
psychologicalStage = '2 - Aware' ;
2024-04-19 02:18:36 +00:00
}
2024-04-26 17:42:48 +00:00
} else {
// If the user submitted any other step, we'll set variables using the answers to the previous questions.
// Get the user's selected primaryBuyingSiutation.
let currentSelectedBuyingSituation = questionnaireProgress [ 'what-are-you-using-fleet-for' ] . primaryBuyingSituation ;
// Get the user's answer to the "Have you ever used Fleet?" question.
let hasUsedFleetAnswer = questionnaireProgress [ 'have-you-ever-used-fleet' ] . fleetUseStatus ;
if ( [ 'what-are-you-working-on-eo-security' , 'what-does-your-team-manage-eo-it' , 'what-does-your-team-manage-vm' , 'what-do-you-manage-mdm' ] . includes ( currentStep ) ) {
if ( valueFromFormData === 'no-use-case-yet' ) {
// Check the user's answer to the previous question
if ( hasUsedFleetAnswer === 'yes-deployed-local' ) {
// If they've tried Fleet locally, set their stage to 3.
psychologicalStage = '3 - Intrigued' ;
} else {
psychologicalStage = '2 - Aware' ;
}
} else { // Otherwise, they have a use case and will be set to stage 4.
psychologicalStage = '4 - Has use case' ;
}
} else if ( currentStep === 'is-it-any-good' ) {
if ( currentSelectedBuyingSituation === 'mdm' ) {
2024-05-02 16:25:48 +00:00
// Since the mdm use case question is the only buying situation-specific question where a use case can't
// be selected, we'll check the user's previous answers before changing their psyStage
2024-04-26 17:42:48 +00:00
if ( questionnaireProgress [ 'what-do-you-manage-mdm' ] . mdmUseCase === 'no-use-case-yet' ) {
// Check the user's answer to the have-you-ever-used-fleet question.
if ( hasUsedFleetAnswer === 'yes-deployed-local' ) {
// If they've tried Fleet locally, set their stage to 3.
psychologicalStage = '3 - Intrigued' ;
} else {
psychologicalStage = '2 - Aware' ;
}
} else {
psychologicalStage = '4 - Has use case' ;
}
} else { // For any other selected primary buying situation, since a use case will have been selected, set their psyStage to 4
psychologicalStage = '4 - Has use case' ;
// FUTURE: check previous answers for other selected buying situations.
}
2024-05-02 16:25:48 +00:00
} else if ( currentStep === 'what-did-you-think' ) { // (what did you think about [presumably after you actually did...] trying it locally)
2024-05-01 23:22:47 +00:00
// If the user selects "Let me think about it", set their psyStage to 2.
if ( valueFromFormData === 'let-me-think-about-it' ) {
2024-04-26 17:42:48 +00:00
psychologicalStage = '2 - Aware' ;
2024-05-02 16:25:48 +00:00
} else if ( [ 'deploy-fleet-in-environment' , 'host-fleet-for-me' ] . includes ( valueFromFormData ) ) {
psychologicalStage = '4 - Has use case' ;
} else { require ( 'assert' ) ( false , 'This should never happen.' ) ; }
2024-05-01 23:22:47 +00:00
} else if ( currentStep === 'how-was-your-deployment' ) {
if ( valueFromFormData === 'decided-to-not-use-fleet' ) {
psychologicalStage = '2 - Aware' ;
} else if ( valueFromFormData === 'up-and-running' ) {
2024-05-02 16:25:48 +00:00
psychologicalStage = '5 - Personally confident' ;
} else if ( [ 'kinda-stuck' , 'havent-gotten-to-it' , 'changed-mind-want-managed-deployment' ] . includes ( valueFromFormData ) ) {
psychologicalStage = '4 - Has use case' ;
} else { require ( 'assert' ) ( false , 'This should never happen.' ) ; }
} else if ( currentStep === 'whats-left-to-get-you-set-up' ) {
// FUTURE: do more stuff (for now this always acts like 'no change')
2024-04-26 17:42:48 +00:00
} else if ( currentStep === 'how-many-hosts' ) {
2024-05-02 16:25:48 +00:00
if ( [ 'yes-deployed' ] . includes ( hasUsedFleetAnswer ) ) {
2024-05-02 00:01:56 +00:00
psychologicalStage = '6 - Has team buy-in' ;
2024-05-07 21:46:00 +00:00
} else if ( [ 'yes-recently-deployed' ] . includes ( hasUsedFleetAnswer ) ) {
2024-05-02 00:01:56 +00:00
psychologicalStage = '5 - Personally confident' ;
2024-05-02 16:25:48 +00:00
} else {
// IWMIH then we want Fleet to host for us (either because we wanted that from the get-go, or we backtracked because deploying looked too time-consuming)
psychologicalStage = '4 - Has use case' ;
2024-05-02 00:01:56 +00:00
}
2024-04-26 17:42:48 +00:00
} else if ( currentStep === 'will-you-be-self-hosting' ) {
2024-05-02 16:25:48 +00:00
if ( [ 'yes-deployed' ] . includes ( hasUsedFleetAnswer ) ) {
2024-05-02 00:01:56 +00:00
psychologicalStage = '6 - Has team buy-in' ;
2024-05-07 21:46:00 +00:00
} else if ( [ 'yes-recently-deployed' ] . includes ( hasUsedFleetAnswer ) ) {
2024-05-02 00:01:56 +00:00
psychologicalStage = '5 - Personally confident' ;
2024-05-02 16:25:48 +00:00
} else { require ( 'assert' ) ( false , 'This should never happen.' ) ; }
2024-04-26 17:42:48 +00:00
} //fi
2024-04-19 02:18:36 +00:00
} //fi
2024-04-30 00:20:00 +00:00
// Only update CRM records if the user's psychological stage changes.
2024-05-03 22:23:05 +00:00
if ( psychologicalStage !== userRecord . psychologicalStage ) {
// Use setImmediate to queue CRM updates.
// [?]: https://nodejs.org/api/timers.html#setimmediatecallback-args
require ( 'timers' ) . setImmediate ( async ( ) => {
await sails . helpers . salesforce . updateOrCreateContactAndAccount . with ( {
emailAddress : this . req . me . emailAddress ,
firstName : this . req . me . firstName ,
lastName : this . req . me . lastName ,
primaryBuyingSituation : primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined ,
organization : this . req . me . organization ,
psychologicalStage ,
2024-05-03 22:29:56 +00:00
} ) . tolerate ( ( err ) => {
sails . log . warn ( ` Background task failed: When a user (email: ${ this . req . me . emailAddress } submitted a step of the get started questionnaire, a Contact and Account record could not be created/updated in the CRM. Full error: ` , err ) ;
2024-05-03 22:23:05 +00:00
} ) ;
2024-05-03 22:29:56 +00:00
} ) ; //_∏_ (Meanwhile...)
} //fi
2024-04-26 06:50:31 +00:00
// TODO: send all other answers to Salesforce (when there are fields for them)
// await sails.helpers.http.post.with({
// url: 'https://hooks.zapier.com/hooks/catch/3627242/3nltwbg/',
// data: {
// emailAddress: this.req.me.emailAddress,
// firstName: this.req.me.firstName,
// lastName: this.req.me.lastName,
// primaryBuyingSituation: primaryBuyingSituation,
// organization: this.req.me.organization,
// psychologicalStage,
// currentStep,
// webhookSecret: sails.config.custom.zapierSandboxWebhookSecret,
// }
// })
// .timeout(5000)
// .tolerate(['non200Response', 'requestFailed'], (err)=>{
// // Note that Zapier responds with a 2xx status code even if something goes wrong, so just because this message is not logged doesn't mean everything is hunky dory. More info: https://github.com/fleetdm/fleet/pull/6380#issuecomment-1204395762
// sails.log.warn(`When a user completed a questionnaire step, a lead/contact could not be updated in the CRM for this email address: ${this.req.me.emailAddress}. Raw error: ${err}`);
// return;
// });
2024-04-04 16:13:53 +00:00
// Set the user's answer to the current step.
questionnaireProgress [ currentStep ] = formData ;
// Clone the questionnaireProgress to prevent any mutations from sending it through the updateOne Waterline method.
let getStartedProgress = _ . clone ( questionnaireProgress ) ;
// Update the user's database model.
2024-04-19 02:18:36 +00:00
await User . updateOne ( { id : userRecord . id } )
. set ( {
2024-04-08 10:39:19 +00:00
getStartedQuestionnaireAnswers : questionnaireProgress ,
2024-04-19 02:18:36 +00:00
lastSubmittedGetStartedQuestionnaireStep : currentStep ,
psychologicalStage
2024-04-08 10:39:19 +00:00
} ) ;
2024-04-04 16:13:53 +00:00
// Return the JSON dictionary of form data submitted by this user.
return getStartedProgress ;
}
} ;