From ad246de64c10dc86d23da50cd514e6df8a6a2a71 Mon Sep 17 00:00:00 2001 From: Natay Aberra Date: Tue, 7 Jan 2025 13:51:09 -0500 Subject: [PATCH 1/5] add function to clean args --- packages/cli/src/utils/analytics.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/cli/src/utils/analytics.js b/packages/cli/src/utils/analytics.js index 79f0c50d5..d966656b8 100644 --- a/packages/cli/src/utils/analytics.js +++ b/packages/cli/src/utils/analytics.js @@ -21,6 +21,24 @@ const shouldSkipAnalytics = (mode) => process.env.DISABLE_ZAPIER_ANALYTICS || mode === ANALYTICS_MODES.disabled; +const cleanArgs = (args) => { + // Do not record "arguments" for following commands + const BLACKLISTED_ARGS = [ + 'key-value pairs...', + 'keys...', + 'path', + 'email', + 'message', + ]; + const cleanedArgs = Object.keys(args) + .filter((key) => !BLACKLISTED_ARGS.includes(key)) + .reduce((obj, key) => { + obj[key] = args[key]; + return obj; + }, {}); + return cleanedArgs; +}; + const recordAnalytics = async (command, isValidCommand, args, flags) => { const analyticsMode = await currentAnalyticsMode(); @@ -28,6 +46,9 @@ const recordAnalytics = async (command, isValidCommand, args, flags) => { debug('skipping analytics'); return; } + debug('args...', args); + const cleanedArgs = cleanArgs(args); + debug('cleaned args...', cleanedArgs); const argKeys = Object.keys(args); const shouldRecordAnonymously = analyticsMode === ANALYTICS_MODES.anonymous; From 0856a4553c8aa63c51fbcaf39e261c716a186d57 Mon Sep 17 00:00:00 2001 From: Natay Aberra Date: Tue, 7 Jan 2025 16:46:38 -0500 Subject: [PATCH 2/5] refactor to cleanValues and use on flags as well --- packages/cli/src/utils/analytics.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/utils/analytics.js b/packages/cli/src/utils/analytics.js index d966656b8..40c097955 100644 --- a/packages/cli/src/utils/analytics.js +++ b/packages/cli/src/utils/analytics.js @@ -21,22 +21,25 @@ const shouldSkipAnalytics = (mode) => process.env.DISABLE_ZAPIER_ANALYTICS || mode === ANALYTICS_MODES.disabled; -const cleanArgs = (args) => { - // Do not record "arguments" for following commands - const BLACKLISTED_ARGS = [ +const cleanValues = (args) => { + // List of arguments we don't want to record. + const doNotRecord = [ 'key-value pairs...', 'keys...', 'path', 'email', 'message', + 'user', + 'account', + 'redirect-uri', + 'inputData', ]; - const cleanedArgs = Object.keys(args) - .filter((key) => !BLACKLISTED_ARGS.includes(key)) + return Object.keys(args) + .filter((key) => !doNotRecord.includes(key)) .reduce((obj, key) => { obj[key] = args[key]; return obj; }, {}); - return cleanedArgs; }; const recordAnalytics = async (command, isValidCommand, args, flags) => { @@ -46,9 +49,8 @@ const recordAnalytics = async (command, isValidCommand, args, flags) => { debug('skipping analytics'); return; } - debug('args...', args); - const cleanedArgs = cleanArgs(args); - debug('cleaned args...', cleanedArgs); + const cleanedArgs = cleanValues(args); + const cleanedFlags = cleanValues(flags); const argKeys = Object.keys(args); const shouldRecordAnonymously = analyticsMode === ANALYTICS_MODES.anonymous; @@ -72,9 +74,10 @@ const recordAnalytics = async (command, isValidCommand, args, flags) => { numArgs: argKeys.length, appId: linkedAppId, flags: { - ...flags, + ...cleanedFlags, ...(command === 'help' ? { helpCommand: argKeys[0] } : {}), // include the beginning of args so we know what they want help on }, + args: shouldRecordAnonymously ? undefined : cleanedArgs, cliVersion: pkg.version, os: shouldRecordAnonymously ? undefined : process.platform, }; From 1731bb481530e2e71d9f60804d0e38497cb3d8b9 Mon Sep 17 00:00:00 2001 From: Natay Aberra Date: Wed, 8 Jan 2025 11:42:24 -0500 Subject: [PATCH 3/5] PDE-5641 only select keys --- packages/cli/src/utils/analytics.js | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/packages/cli/src/utils/analytics.js b/packages/cli/src/utils/analytics.js index 40c097955..95e756f76 100644 --- a/packages/cli/src/utils/analytics.js +++ b/packages/cli/src/utils/analytics.js @@ -21,27 +21,6 @@ const shouldSkipAnalytics = (mode) => process.env.DISABLE_ZAPIER_ANALYTICS || mode === ANALYTICS_MODES.disabled; -const cleanValues = (args) => { - // List of arguments we don't want to record. - const doNotRecord = [ - 'key-value pairs...', - 'keys...', - 'path', - 'email', - 'message', - 'user', - 'account', - 'redirect-uri', - 'inputData', - ]; - return Object.keys(args) - .filter((key) => !doNotRecord.includes(key)) - .reduce((obj, key) => { - obj[key] = args[key]; - return obj; - }, {}); -}; - const recordAnalytics = async (command, isValidCommand, args, flags) => { const analyticsMode = await currentAnalyticsMode(); @@ -49,10 +28,8 @@ const recordAnalytics = async (command, isValidCommand, args, flags) => { debug('skipping analytics'); return; } - const cleanedArgs = cleanValues(args); - const cleanedFlags = cleanValues(flags); const argKeys = Object.keys(args); - + const flagKeys = Object.keys(flags); const shouldRecordAnonymously = analyticsMode === ANALYTICS_MODES.anonymous; const integrationIDKey = argKeys.find( @@ -74,10 +51,10 @@ const recordAnalytics = async (command, isValidCommand, args, flags) => { numArgs: argKeys.length, appId: linkedAppId, flags: { - ...cleanedFlags, + ...flagKeys, ...(command === 'help' ? { helpCommand: argKeys[0] } : {}), // include the beginning of args so we know what they want help on }, - args: shouldRecordAnonymously ? undefined : cleanedArgs, + argsKeys: argKeys, cliVersion: pkg.version, os: shouldRecordAnonymously ? undefined : process.platform, }; From 20ac09475a49282a84344a5bce862f58a871cc5a Mon Sep 17 00:00:00 2001 From: Natay Aberra Date: Wed, 8 Jan 2025 11:50:03 -0500 Subject: [PATCH 4/5] PDE-5641 update flagKeys --- packages/cli/src/utils/analytics.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/utils/analytics.js b/packages/cli/src/utils/analytics.js index 95e756f76..c420f4789 100644 --- a/packages/cli/src/utils/analytics.js +++ b/packages/cli/src/utils/analytics.js @@ -51,10 +51,11 @@ const recordAnalytics = async (command, isValidCommand, args, flags) => { numArgs: argKeys.length, appId: linkedAppId, flags: { - ...flagKeys, + ...flags, ...(command === 'help' ? { helpCommand: argKeys[0] } : {}), // include the beginning of args so we know what they want help on }, argsKeys: argKeys, + flagKeys: flagKeys, cliVersion: pkg.version, os: shouldRecordAnonymously ? undefined : process.platform, }; From a01801efdc5d3c079468456780c9f5c8a3eab877 Mon Sep 17 00:00:00 2001 From: Natay Aberra Date: Wed, 8 Jan 2025 12:09:18 -0500 Subject: [PATCH 5/5] remove flags args since it's unused in backend --- packages/cli/src/utils/analytics.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/cli/src/utils/analytics.js b/packages/cli/src/utils/analytics.js index c420f4789..255fc4d82 100644 --- a/packages/cli/src/utils/analytics.js +++ b/packages/cli/src/utils/analytics.js @@ -50,10 +50,6 @@ const recordAnalytics = async (command, isValidCommand, args, flags) => { isValidCommand, numArgs: argKeys.length, appId: linkedAppId, - flags: { - ...flags, - ...(command === 'help' ? { helpCommand: argKeys[0] } : {}), // include the beginning of args so we know what they want help on - }, argsKeys: argKeys, flagKeys: flagKeys, cliVersion: pkg.version,