Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #20

Merged
merged 5 commits into from
Oct 2, 2023
Merged

Dev #20

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ This is a project to automates postman collections using the [Reactor API](https
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [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)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down
41 changes: 21 additions & 20 deletions importObjectUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,43 +39,44 @@ 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);
}
}

// 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;
}


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
31 changes: 15 additions & 16 deletions parserUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -40,20 +40,20 @@ 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)) {
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);
}
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);
}
}
}
Expand All @@ -66,7 +66,6 @@ function replaceValueInJSON(jsonObject, keyToFind, newValue) {
// workingDir: <dir of file>
// }
function getFileObjAndWorkingDir(file){
debugProperty(getFileObjAndWorkingDir);
let obj = {};
if(typeof file == "string"){
if(fs.lstatSync(file).isFile()){
Expand Down Expand Up @@ -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;
Expand Down
Loading