From 2ce208b55b77c749437f33746faf8e6449fad535 Mon Sep 17 00:00:00 2001 From: Kevin Nennig Date: Mon, 2 Oct 2023 14:23:50 -0400 Subject: [PATCH 1/5] updated debugging --- importObjectUtil.js | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/importObjectUtil.js b/importObjectUtil.js index 46188bc..f2ec4bc 100644 --- a/importObjectUtil.js +++ b/importObjectUtil.js @@ -5,13 +5,13 @@ const yaml = require("js-yaml"); //Mac: DEBUG=* aep-tag-tool.... //WIN: set DEBUG=* & aep-tag-tool.... const debug = require("debug"); -const debugParser = debug("parser"); -const debugNewSettings = debug("new setting"); -const debugConfig = require("debug")("config"); +const debugImportObj = debug("import"); +const debugNewSettings = debug("import:setting"); +const debugConfig = debug("import:config"); exports.debugOptions = { - "json": "Messages on JSON obj creation from files", - "property": "messages related to the property file", - "config": "Messages related to config file" + "import": "checks if values have been found/replaces in import object", + "import:setting": "new settings displayed", + "import:config": "debug the web property created from the file" }; //Create an web property import object from a file @@ -39,18 +39,15 @@ async function updateSettings(importObj, newSettingsFile) { const yamlContent = await fs.readFile(newSettingsFile, "utf8"); const parsedYaml = yaml.loadAll(yamlContent); - debugParser("Parsing through replacement values"); + debugImportObj("Parsing through replacement values"); for (const tagResourceName in parsedYaml[0]) { const resourceObjects = parsedYaml[0][tagResourceName]; for (const objName in resourceObjects) { const newSettings = resourceObjects[objName]; - const found = replaceSettings(importObj, tagResourceName, objName, newSettings); - - if (!found) { - debugParser("'" + tagResourceName + ":" + objName + "' not found in import json"); - } + importObj = replaceSettings(importObj, tagResourceName, objName, newSettings); } } + if(debug.enabled("import")) await fs.writeFile("updatedImport.json", JSON.stringify(importObj, null, 2)); return importObj; } catch (error) { console.error("Error:", error); @@ -58,24 +55,28 @@ async function updateSettings(importObj, newSettingsFile) { } // Replaces a settings key/value pair in the objName if present in the importData -function replaceSettings(importData, tagResourceName, objName, newSettings) { - if (importData[tagResourceName]) { - for (const key of importData[tagResourceName]) { +function replaceSettings(importData, tagComponentName, objName, newSettings) { + let componentArr = importData[tagComponentName] + if (componentArr) { + for (const key of componentArr) { const keyName = key.attributes.name; if (keyName === objName) { - debugParser("Found '" + tagResourceName + ":" + objName + "'. Replacing old settings."); + debugImportObj("Found '" + tagComponentName + ":" + objName + "'. Replacing old settings."); debugNewSettings(newSettings); - const settings = JSON.parse(key.attributes.settings); + let settings = JSON.parse(key.attributes.settings); for (const setting in newSettings) { - parserUtil.replaceValueInJSON(settings, setting, newSettings[setting]); + settings = parserUtil.replaceValueInJSON(settings, setting, newSettings[setting]); } + debugNewSettings("Applying to settings JSON:") + debugNewSettings(settings); key.attributes.settings = JSON.stringify(settings); - return true; + return importData; } } } - return false; + debugImportObj("'" + tagComponentName + ":" + objName + "' not found in import json"); + return importData; } From f2bcab83396c8d967ae912744589a85265222d46 Mon Sep 17 00:00:00 2001 From: Kevin Nennig Date: Mon, 2 Oct 2023 14:24:05 -0400 Subject: [PATCH 2/5] fixed bug where replaceSettings wasn't working --- parserUtil.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/parserUtil.js b/parserUtil.js index d100be6..a737df9 100644 --- a/parserUtil.js +++ b/parserUtil.js @@ -2,13 +2,13 @@ const fs = require("fs"); const path = require("path"); const yaml = require("js-yaml"); const debug = require("debug"); -const debugJSON = debug("json"); -const debugReplace = debug("replace"); -const debugProperty = debug("property"); -const debugConfig = debug("config"); +const debugJSON = debug("parser:json"); +const debugReplace = debug("parser:replace"); +const debugVerbose = debug("parser:verbose"); exports.debugOptions = { - "json": "Messages on JSON obj creation from files", - "replace": "Messages on key/value replacement" + "parser:json": "Messages on JSON obj creation from files", + "parser:replace": "Messages on key/value replacement", + "parser:verbose": "" }; //Input yaml contents or JSON contents to return a valid JSON object @@ -40,21 +40,21 @@ function replaceValueInJSON(jsonObject, keyToFind, newValue) { if (typeof jsonObject !== "object" || jsonObject === null) { return jsonObject; } - + if (Array.isArray(jsonObject)) { + for (let i = 0; i < jsonObject.length; i++) { jsonObject[i] = replaceValueInJSON(jsonObject[i], keyToFind, newValue); } } else { for (const key in jsonObject) { - if (Object.prototype.hasOwnProperty.call(key)) { + debugReplace("replace: " + key); if (key === keyToFind) { debugReplace("Found key '" + keyToFind + "' with value '" + jsonObject[key] + "' and replacing with '" + newValue + "'"); jsonObject[key] = newValue; } else { jsonObject[key] = replaceValueInJSON(jsonObject[key], keyToFind, newValue); } - } } } return jsonObject; @@ -66,7 +66,6 @@ function replaceValueInJSON(jsonObject, keyToFind, newValue) { // workingDir: // } function getFileObjAndWorkingDir(file){ - debugProperty(getFileObjAndWorkingDir); let obj = {}; if(typeof file == "string"){ if(fs.lstatSync(file).isFile()){ @@ -99,7 +98,7 @@ function findNestedObj(entireObj, keyToFind) { let foundValue; JSON.stringify(entireObj, (curKey, curVal) => { if(curKey.toUpperCase().replace("-","_").replace(" ","_") == keyToFind){ - debugConfig("Found: " + keyToFind); + debugVerbose("Found: " + keyToFind); foundValue = curVal; } return curVal; From 7061762943948d60dcb001581ea5b802cda14391 Mon Sep 17 00:00:00 2001 From: Kevin Nennig Date: Mon, 2 Oct 2023 14:43:46 -0400 Subject: [PATCH 3/5] Update README.md --- README.md | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index cfb33be..e8cb9aa 100644 --- a/README.md +++ b/README.md @@ -11,20 +11,18 @@ This is a project to automates postman collections using the [Reactor API](https -- [AEP Tag Tool](#aep-tag-tool) - - [Overview](#overview) - - [Installation](#installation) - - [Command Line Tool](#command-line-tool) - - [Create config file for Authentication](#create-config-file-for-authentication) - - [Usage](#usage) - - [Export a Tag](#export-a-tag) - - [Import a Tag](#import-a-tag) - - [CEDRLP params](#cedrlp-params) - - [Import into other Adobe Organizations](#import-into-other-adobe-organizations) - - [newSettings.yml](#newsettingsyml) - - [Delete tag properties that contain a specific string](#delete-tag-properties-that-contain-a-specific-string) - - [Using this tool without NPM](#using-this-tool-without-npm) - - [Postman files](#postman-files) +- [Installation](#installation) +- [Command Line Tool](#command-line-tool) +- [Create config file for Authentication](#create-config-file-for-authentication) +- [Usage](#usage) +- [Export a Tag](#export-a-tag) +- [Import a Tag](#import-a-tag) + - [CEDRLP params](#cedrlp-params) + - [Import into other Adobe Organizations](#import-into-other-adobe-organizations) + - [newSettings.yml](#newsettingsyml) +- [Delete tag properties that contain a specific string](#delete-tag-properties-that-contain-a-specific-string) +- [Using this tool without NPM](#using-this-tool-without-npm) + - [Postman files](#postman-files) From 43e91efe99456637eecaa804485aabcec28ab414 Mon Sep 17 00:00:00 2001 From: Kevin Nennig Date: Mon, 2 Oct 2023 14:45:04 -0400 Subject: [PATCH 4/5] lint fix --- importObjectUtil.js | 4 ++-- parserUtil.js | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/importObjectUtil.js b/importObjectUtil.js index f2ec4bc..9d4f123 100644 --- a/importObjectUtil.js +++ b/importObjectUtil.js @@ -56,7 +56,7 @@ async function updateSettings(importObj, newSettingsFile) { // Replaces a settings key/value pair in the objName if present in the importData function replaceSettings(importData, tagComponentName, objName, newSettings) { - let componentArr = importData[tagComponentName] + let componentArr = importData[tagComponentName]; if (componentArr) { for (const key of componentArr) { const keyName = key.attributes.name; @@ -68,7 +68,7 @@ function replaceSettings(importData, tagComponentName, objName, newSettings) { for (const setting in newSettings) { settings = parserUtil.replaceValueInJSON(settings, setting, newSettings[setting]); } - debugNewSettings("Applying to settings JSON:") + debugNewSettings("Applying to settings JSON:"); debugNewSettings(settings); key.attributes.settings = JSON.stringify(settings); return importData; diff --git a/parserUtil.js b/parserUtil.js index a737df9..6de3b62 100644 --- a/parserUtil.js +++ b/parserUtil.js @@ -49,12 +49,12 @@ function replaceValueInJSON(jsonObject, keyToFind, newValue) { } else { for (const key in jsonObject) { debugReplace("replace: " + key); - if (key === keyToFind) { - debugReplace("Found key '" + keyToFind + "' with value '" + jsonObject[key] + "' and replacing with '" + newValue + "'"); - jsonObject[key] = newValue; - } else { - jsonObject[key] = replaceValueInJSON(jsonObject[key], keyToFind, newValue); - } + if (key === keyToFind) { + debugReplace("Found key '" + keyToFind + "' with value '" + jsonObject[key] + "' and replacing with '" + newValue + "'"); + jsonObject[key] = newValue; + } else { + jsonObject[key] = replaceValueInJSON(jsonObject[key], keyToFind, newValue); + } } } return jsonObject; From d1932486fbbea7e7d44cac928f8f9534c03c412a Mon Sep 17 00:00:00 2001 From: Kevin Nennig Date: Mon, 2 Oct 2023 14:45:20 -0400 Subject: [PATCH 5/5] 1.2.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3a24d64..f5b4365 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@knennigtri/aep-tag-tool", - "version": "1.2.0", + "version": "1.2.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@knennigtri/aep-tag-tool", - "version": "1.2.0", + "version": "1.2.1", "license": "ISC", "dependencies": { "debug": "^4.3.4", diff --git a/package.json b/package.json index c3ca8c0..f9bae10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@knennigtri/aep-tag-tool", - "version": "1.2.0", + "version": "1.2.1", "description": "Export and Import Adobe Experience Platform Tags (previously Launch) with optional variable updates based on Organzations", "repository": { "type": "git",