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

Staging #9

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

25 changes: 13 additions & 12 deletions config/config_data.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"validator": [
{
"url": "https://www.casasbahia.com.br/addToCart",
"schema_name": [
"casasBahia-addToCart"
],
"dataLayer": "dataLayer",
"browserClose": true,
"time": 0
}
]
"validator": [
{
"url": ["https://www.casasbahia.com.br/"],
"schema_name": [
"schema"
],
"dataLayer": "dataLayer",
"browserClose": true,
"time": 0
}
]
}



59 changes: 59 additions & 0 deletions crawler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import puppeteer from 'puppeteer-extra';
import validation from './index.js';
import { readFileSync } from 'node:fs';
import AdblockerPlugin from 'puppeteer-extra-plugin-adblocker';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
import fs from "fs"
puppeteer.use(StealthPlugin());

let result = []
let [config_file, stopAdBlock] = process.argv.slice(2) // responsible for commands entered at the prompt

const config = JSON.parse( // this const import json configuration schema from config folder
await readFileSync(
new URL(`./config/${config_file}`, import.meta.url)
)
);

const schema = JSON.parse( // this const import json schema from config folder
await readFileSync(
new URL(`./schema/${config.validator[0].schema_name[0]}.json`, import.meta.url)
)
);

if(stopAdBlock !== "stopAdBlock"){ // to stop adblock functioning
puppeteer.use(AdblockerPlugin({ useCache: false }));
}

(async () => { // opening and validation function in the browser
const browser = await puppeteer.launch({headless: false}); // default is true;
const page = await browser.newPage();
await page.goto(config.validator[0].url[0]); // website to be opened
await page.setViewport({width: 1080, height: 1024}); // screen size
await page.exposeFunction('bowser', (elm) => { //intermediary function between machine and browser (injects the validation function into the browser)
result.push(validation(schema.items,elm))
fs.writeFile("dataLayer.json", JSON.stringify(result[0], null, 2), err =>{
if(err) throw new Error("Erro")
//console.log("Validação concluída!")
});
console.log(result)
});
await page.evaluate(async () => { //performs the validation process in the browser
for(let elem of window.dataLayer){ //get dataLayer events
if(elem.event !== "optimize.domChange"){ //
bowser(elem)} // validate
}
window.dataLayer.push_c = window.dataLayer.push; //change event push

window.dataLayer.push = function (obj) {
if(obj.event !== "optimize.domChange"){
window.dataLayer.push_c(obj);
bowser(obj)}} // validates the new dataLayer push
})
if (config.validator[0].browserClose) { // check the time and close the browser
config.validator[0].time ? await page.waitForTimeout(config.validator[0].time) : await page.waitForTimeout(0);
await browser.close();
}
})();


37 changes: 37 additions & 0 deletions dataLayer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{
"status": "Error",
"message": "The dataLayer event is not present in the schema",
"dlObject": "{\n \"gtm.start\": 1682454787280,\n \"event\": \"gtm.js\",\n \"gtm.uniqueEventId\": 1\n}"
},
{
"status": "Error",
"message": "The dataLayer event is not present in the schema",
"dlObject": "{\n \"event\": \"gtm.js\",\n \"gtm.uniqueEventId\": 2\n}"
},
{
"status": "Error",
"message": "The value at /aplicacao/dominio is an invalid string. The value at /aplicacao/ambiente must be one of: \"producaoteste\". The value at /aplicacao/servidor must be a number but it was a string.",
"dlObject": "{\n \"event\": \"update\",\n \"aplicacao\": {\n \"bandeira\": \"cb\",\n \"dominio\": \"casasbahia.com.br\",\n \"ambiente\": \"producao\",\n \"device\": \"desktop\",\n \"servidor\": \"vitrinecb118\"\n },\n \"gtm.uniqueEventId\": 3\n}"
},
{
"status": "Error",
"message": "The value at /usuario is missing the required field 'idUsuario'. The value at /usuario is missing the required field 'idUnicoVia'. The value at /usuario is missing the required field 'tipoUsuario'. The value at /usuario is missing the required field 'uf'. The value at /usuario is missing the required field 'email'. The value at /usuario is missing the required field 'nome'. The value at /usuario is missing the required field 'sobrenome'. The value at /usuario is missing the required field 'telefone'.",
"dlObject": "{\n \"event\": \"update\",\n \"usuario\": {\n \"statusLogin\": \"visitante\"\n },\n \"gtm.uniqueEventId\": 4\n}"
},
{
"status": "Error",
"message": "The value at /pagina is missing the required field 'navegacao'.",
"dlObject": "{\n \"event\": \"update\",\n \"pagina\": {\n \"url\": \"https://www.casasbahia.com.br/site/paginavitrinenew.aspx\",\n \"nomePagina\": \"/vitrine/home\",\n \"templatePagina\": \"home\",\n \"tituloPagina\": \"casas bahia cupom de 10 15 e 20 de desconto\"\n },\n \"gtm.uniqueEventId\": 5\n}"
},
{
"status": "Error",
"message": "The dataLayer event is not present in the schema",
"dlObject": "{\n \"event\": \"gtm.dom\",\n \"gtm.uniqueEventId\": 6\n}"
},
{
"status": "Error",
"message": "The dataLayer event is not present in the schema",
"dlObject": "{\n \"event\": \"gtm.load\",\n \"gtm.uniqueEventId\": 7\n}"
}
]
Binary file added document.pdf
Binary file not shown.
45 changes: 45 additions & 0 deletions export.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Error,The dataLayer event is not present in the schema,{
"gtm.start": 1682345065291,
"event": "gtm.js",
"gtm.uniqueEventId": 1
}
Error,The dataLayer event is not present in the schema,{
"event": "gtm.js",
"gtm.uniqueEventId": 2
}
Error,The value at /aplicacao/dominio is an invalid string. The value at /aplicacao/ambiente must be one of: "producaoteste". The value at /aplicacao/servidor must be a number but it was a string.,{
"event": "update",
"aplicacao": {
"bandeira": "cb",
"dominio": "casasbahia.com.br",
"ambiente": "producao",
"device": "desktop",
"servidor": "vitrinecb121"
},
"gtm.uniqueEventId": 3
}
Error,The value at /usuario is missing the required field 'idUsuario'. The value at /usuario is missing the required field 'idUnicoVia'. The value at /usuario is missing the required field 'tipoUsuario'. The value at /usuario is missing the required field 'uf'. The value at /usuario is missing the required field 'email'. The value at /usuario is missing the required field 'nome'. The value at /usuario is missing the required field 'sobrenome'. The value at /usuario is missing the required field 'telefone'.,{
"event": "update",
"usuario": {
"statusLogin": "visitante"
},
"gtm.uniqueEventId": 4
}
Error,The value at /pagina is missing the required field 'navegacao'.,{
"event": "update",
"pagina": {
"url": "https://www.casasbahia.com.br/site/paginavitrinenew.aspx",
"nomePagina": "/vitrine/home",
"templatePagina": "home",
"tituloPagina": "casas bahia cupom de 10 15 e 20 de desconto"
},
"gtm.uniqueEventId": 5
}
Error,The dataLayer event is not present in the schema,{
"event": "gtm.dom",
"gtm.uniqueEventId": 6
}
Error,The dataLayer event is not present in the schema,{
"event": "gtm.load",
"gtm.uniqueEventId": 7
}
18 changes: 18 additions & 0 deletions exportcsv/csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import dataLayer from '../dataLayer.json' assert {type: 'json'}


let dt = (obj, arr = []) => {
return Object.keys(obj).reduce((result, index) => {
if (typeof obj[index] !== "object") {
result[arr.concat(index).join("_")] = obj[index];
return result;
}
return Object.assign(result, dt(obj[index], arr.concat(index), result));
}, {});
}


let data = []
data.push(dt(dataLayer))
//console.log(data)
export default data
24 changes: 24 additions & 0 deletions exportcsv/export_csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fs from 'fs'
//import data from './csv.js'
import dataLayer from '../dataLayer.json' assert {type: 'json'}


const chaves = Object.keys(dataLayer)
const cabecalio = chaves.join(',')

const data= dataLayer.map((elemento) => Object.values(elemento).join(',')).join('\n')

const conteudo = cabecalio + '\n' + data
const csv = conteudo.split('\n')
csv.shift();
const exportCsv = csv.join('\n')
//console.log(exportCsv)



try {
fs.writeFileSync('export.csv', exportCsv);
// file written successfully
} catch (err) {
console.error(err);
}
69 changes: 69 additions & 0 deletions exportpdf/docDefinition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"defaultStyle": {
"font": "Helvetica",
"fontSize": 8
},
"content": [
{
"text": "PeguinDataLayer Validation Results",
"style": "subheader"
},
"",
"",
{
"text": "",
"style": "subheader"
},
"",
"",
{
"style": "tableExample",
"table": {
"headerRows": 1,
"widths": [100, 200, 200],
"body": [
[
{
"text": "Status",
"style": "tableHeader"
},
{
"text": "Menssagem",
"style": "tableHeader"
},
{
"text": "Evento",
"style": "tableHeader"
}
]
]
}
},
"",
"",
"",
""
],
"styles": {
"header": {
"fontSize": 18,
"bold": true,
"margin": [0, 0, 100, 10]
},
"subheader": {
"fontSize": 16,
"bold": true,
"margin": [0, 10, 0, 5]
},
"tableExample": {
"margin": [0, 5, 0, 15]
},
"tableHeader": {
"bold": true,
"fontSize": 10,
"color": "black",
"alignment": "center"
}
}
}

59 changes: 59 additions & 0 deletions exportpdf/exportpdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import dataLayer from '../dataLayer.json' assert {type: 'json'};
import fs from 'fs';
import pdfMake from 'pdfmake';
import fonts from './pdfMake_fonts.json' assert {type: 'json'};
import docDefinition from './docDefinition.json' assert {type: 'json'};


const printer = new pdfMake(fonts);



dataLayer.forEach((dataObject) =>{
if(dataObject){
dataObject.dlObject = dataObject.dlObject.replace(/(\r\n|\n|\r)/gm, '').replace(/\s/g, '').split(',').join('');
}



docDefinition.content[6].table.body.push([
{
text: `${dataObject.status}`,
alignment: 'center',
},
{
text: `${dataObject.message}`,
alignment: 'center',
},
{
text: `${dataObject.dlObject}`
}
]);
pdfMake.tableLayouts = {
exampleLayout: {
hLineWidth: function (i, node) {
if (i === 0 || i === node.table.body.length) {
return 0;
}
return i === node.table.headerRows ? 2 : 1;
},
vLineWidth: function (i) {
return 0;
},
hLineColor: function (i) {
return i === 1 ? 'black' : '#aaa';
},
paddingLeft: function (i) {
return i === 0 ? 0 : 8;
},
paddingRight: function (i, node) {
return i === node.table.widths.length - 1 ? 0 : 8;
},
},
};
const pdfDoc = printer.createPdfKitDocument(docDefinition);
pdfDoc.pipe(fs.createWriteStream(`document.pdf`));
pdfDoc.end()


});
27 changes: 27 additions & 0 deletions exportpdf/pdfMake_fonts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"Courier": {
"normal": "Courier",
"bold": "Courier-Bold",
"italics": "Courier-Oblique",
"bolditalics": "Courier-BoldOblique"
},
"Helvetica": {
"normal": "Helvetica",
"bold": "Helvetica-Bold",
"italics": "Helvetica-Oblique",
"bolditalics": "Helvetica-BoldOblique"
},
"Times": {
"normal": "Times-Roman",
"bold": "Times-Bold",
"italics": "Times-Italic",
"bolditalics": "Times-BoldItalic"
},
"Symbol": {
"normal": "Symbol"
},
"ZapfDingbats": {
"normal": "ZapfDingbats"
}
}

Loading