From 84fe55e4b0ca6d10dfb5cb6f3f9e65177bdbec05 Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Tue, 8 Oct 2024 14:24:02 +0530 Subject: [PATCH] chore: address comments+2 --- package-lock.json | 6 + package.json | 3 +- src/features.json | 3 +- .../amazon_audience/data/addressMap.json | 469 ------------------ .../amazon_audience/data/statesMap.json | 277 ----------- .../amazon_audience/networkHandler.js | 2 +- src/v0/destinations/amazon_audience/utils.js | 118 ++--- .../amazon_audience/processor/data.ts | 111 +++-- 8 files changed, 101 insertions(+), 888 deletions(-) delete mode 100644 src/v0/destinations/amazon_audience/data/addressMap.json delete mode 100644 src/v0/destinations/amazon_audience/data/statesMap.json diff --git a/package-lock.json b/package-lock.json index dfb276baec..515686961e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,7 @@ "ajv": "^8.12.0", "ajv-draft-04": "^1.0.0", "ajv-formats": "^2.1.1", + "amazon-dsp-formatter": "^1.0.2", "axios": "^1.7.3", "btoa": "^1.2.1", "component-each": "^0.2.6", @@ -8198,6 +8199,11 @@ } } }, + "node_modules/amazon-dsp-formatter": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/amazon-dsp-formatter/-/amazon-dsp-formatter-1.0.2.tgz", + "integrity": "sha512-CfsssMzLFh0IK6oz3j38ENGgp5LZ/q21YX4yXSavfI50CU2cJbupKOk+Bgg0sY67V0lWsYsmYrpkEI2aFG/duA==" + }, "node_modules/ansi-align": { "version": "3.0.1", "dev": true, diff --git a/package.json b/package.json index 2e4609d62a..387a9f2c5d 100644 --- a/package.json +++ b/package.json @@ -71,8 +71,8 @@ "ajv": "^8.12.0", "ajv-draft-04": "^1.0.0", "ajv-formats": "^2.1.1", + "amazon-dsp-formatter": "^1.0.2", "axios": "^1.7.3", - "phone": "^3.1.50", "btoa": "^1.2.1", "component-each": "^0.2.6", "crypto-js": "^4.2.0", @@ -107,6 +107,7 @@ "oauth-1.0a": "^2.2.6", "object-hash": "^3.0.0", "parse-static-imports": "^1.1.0", + "phone": "^3.1.50", "prom-client": "^14.2.0", "qs": "^6.11.1", "rs-jsonpath": "^1.1.2", diff --git a/src/features.json b/src/features.json index 097e4a8aa0..c50c632811 100644 --- a/src/features.json +++ b/src/features.json @@ -80,7 +80,8 @@ "X_AUDIENCE": true, "BLOOMREACH_CATALOG": true, "SMARTLY": true, - "HTTP": true + "HTTP": true, + "AMAZON_AUDIENCE": true }, "regulations": [ "BRAZE", diff --git a/src/v0/destinations/amazon_audience/data/addressMap.json b/src/v0/destinations/amazon_audience/data/addressMap.json deleted file mode 100644 index cbc4045400..0000000000 --- a/src/v0/destinations/amazon_audience/data/addressMap.json +++ /dev/null @@ -1,469 +0,0 @@ -{ - "alley ": " aly", - "p.zza ": " piazza", - "allee ": " aly", - "av ": " ave", - "aly ": " alley", - "avenue ": " ave", - "allees ": " allées", - "av. ": " avenida", - "bouled ": " blvd", - "ally ": " aly", - "pzza ": " piazza", - "ave ": " avenue", - "avd. ": " avenida", - "circle ": " cir", - "annex ": " anx", - "pza ": " plaza", - "blvd ": " bouled", - "avd ": " avenida", - "center ": " ctr", - "circles ": " cirs", - "annx ": " anx", - "p.le ": " piazzale", - "che ": " chemin", - "avda ": " avenida", - "ctr ": " centre", - "court ": " ct", - "anex ": " anx", - "ple ": " piazzale", - "imp ": " impasse", - "avda. ": " avenida", - "centre ": " ctr", - "arcade ": " arc", - "p.tta ": " piazzetta", - "montee ": " montée", - "auto ": " autopista", - "cl ": " close", - "ptta ": " piazzetta", - "rte ": " route", - "auto. ": " autopista", - "drive ": " dr", - "avenu ": " ave", - "l.go ": " largo", - "czada ": " calzada", - "freeway ": " fwy", - "lgo ": " largo", - "czada. ": " calzada", - "lane ": " ln", - "frwy ": " fwy", - "aven ": " ave", - "v ": " via", - "muell ": " muelle", - "place ": " pl", - "highway ": " hwy", - "avnue ": " ave", - "v. ": " via", - "muell. ": " muelle", - "road ": " rd", - "avn ": " ave", - "v.le ": " viale", - "psaje ": " pasaje", - "sq ": " square", - "parks ": " park", - "beach ": " bch", - "vle ": " viale", - "psaje. ": " pasaje", - "street ": " st", - "parkways ": " pkwy", - "burg ": " bg", - "c.so ": " corso", - "alam ": " alameda", - "apartment ": " apt", - "pky ": " pkwy", - "burgs ": " bgs", - "cso ": " corso", - "alam. ": " alameda", - "inc. ": " inc", - "pkway ": " pkwy", - "bluff ": " blf", - "v.lo ": " vicolo", - "cllzo ": " callizo", - "ltd. ": " ltd", - "pkwys ": " pkwy", - "bluf ": " blf", - "vlo ": " vicolo", - "cllzo. ": " callizo", - "limited ": " ltd", - "parkway ": " pkwy", - "bluffs ": " blfs", - "cllja ": " calleja", - "llc. ": " llc", - "parkwy ": " pkwy", - "boulv ": " blvd", - "cllja. ": " calleja", - "llp. ": " llp", - "calle ": " calle", - "plaza ": " plz", - "boul ": " blvd", - "c/ ": " calle", - "plza ": " plz", - "bend ": " bnd", - "c. ": " calle", - "branch ": " br", - "cl. ": " calle", - "square ": " sq", - "brnch ": " br", - "c ": " calle", - "squ ": " sq", - "brdge ": " brg", - "c\\ ": " calle", - "sqr ": " sq", - "bridge ": " brg", - "carre ": " calle", - "brook ": " brk", - "carrer ": " calle", - "str ": " st", - "brooks ": " brks", - "ctra ": " carretera", - "bot ": " btm", - "ctra. ": " carretera", - "bottm ": " btm", - "cra ": " carrera", - "bottom ": " btm", - "cra. ": " carrera", - "bypass ": " byp", - "cint ": " cinturón", - "bypas ": " byp", - "cint. ": " cinturón", - "byps ": " byp", - "autov ": " autovía", - "bypa ": " byp", - "autov. ": " autovía", - "byp ": " byp", - "ctrin. ": " carreterín", - "bayou ": " byu", - "cmno ": " camino", - "bayoo ": " byu", - "cmno. ": " camino", - "crcl ": " cir", - "cno ": " camino", - "crcle ": " cir", - "cno. ": " camino", - "cjla ": " callejuela", - "circl ": " cir", - "cjla. ": " callejuela", - "circ ": " cir", - "bulev ": " bule", - "bulev. ": " bule", - "club ": " clb", - "crril ": " carril", - "cliff ": " clf", - "crril. ": " carril", - "cliffs ": " clfs", - "pzo ": " pasadizo", - "common ": " cmn", - "pzo. ": " pasadizo", - "commons ": " cmns", - "acces ": " acceso", - "corner ": " cor", - "acces. ": " acceso", - "corners ": " cors", - "ccvcn ": " circunvalación", - "cmp ": " cp", - "ccvcn. ": " circunvalación", - "camp ": " cp", - "callej ": " callejón", - "cape ": " cpe", - "callej. ": " callejón", - "crescent ": " cres", - "cjon ": " callejón", - "crsnt ": " cres", - "cjon. ": " callejón", - "crsent ": " cres", - "cllon ": " callejón", - "creek ": " crk", - "cllon. ": " callejón", - "course ": " crse", - "rbla ": " rambla", - "crest ": " crst", - "pg ": " passeig", - "causeway ": " cswy", - "paseo ": " passeig", - "causwa ": " cswy", - "ps ": " passeig", - "p ": " passeig", - "centr ": " ctr", - "pl ": " plaza", - "cen ": " ctr", - "cntr ": " ctr", - "rda ": " ronda", - "cnter ": " ctr", - "lg ": " lugar", - "cent ": " ctr", - "urb ": " urbanización", - "centers ": " ctrs", - "courts ": " cts", - "curve ": " curv", - "cove ": " cv", - "coves ": " cvs", - "cnyn ": " cyn", - "canyn ": " cyn", - "canyon ": " cyn", - "dale ": " dl", - "dam ": " dm", - "driv ": " dr", - "drv ": " dr", - "drives ": " drs", - "dvd ": " dv", - "divide ": " dv", - "div ": " dv", - "estate ": " est", - "estates ": " ests", - "expressway ": " expy", - "expw ": " expy", - "expr ": " expy", - "exp ": " expy", - "express ": " expy", - "extension ": " ext", - "extn ": " ext", - "extnsn ": " ext", - "extensions ": " exts", - "field ": " fld", - "fields ": " flds", - "falls ": " fls", - "flat ": " flt", - "flats ": " flts", - "ford ": " frd", - "frd ": " frd", - "fords ": " frds", - "forge ": " frg", - "forg ": " frg", - "forges ": " frgs", - "fork ": " frk", - "forks ": " frks", - "forests ": " frst", - "forest ": " frst", - "frry ": " fry", - "ferry ": " fry", - "fort ": " ft", - "frt ": " ft", - "freewy ": " fwy", - "frway ": " fwy", - "grden ": " gdn", - "garden ": " gdn", - "grdn ": " gdn", - "gardn ": " gdn", - "gardens ": " gdns", - "grdns ": " gdns", - "glen ": " gln", - "glens ": " glns", - "green ": " grn", - "greens ": " grns", - "grov ": " grv", - "grove ": " grv", - "groves ": " grvs", - "gatway ": " gtwy", - "gateway ": " gtwy", - "gatewy ": " gtwy", - "gtway ": " gtwy", - "hrbor ": " hbr", - "harbor ": " hbr", - "harb ": " hbr", - "harbr ": " hbr", - "harbors ": " hbrs", - "hill ": " hl", - "hills ": " hls", - "hllw ": " holw", - "holws ": " holw", - "hollow ": " holw", - "hollows ": " holw", - "heights ": " hts", - "ht ": " hts", - "haven ": " hvn", - "highwy ": " hwy", - "hiwy ": " hwy", - "hway ": " hwy", - "hiway ": " hwy", - "inlet ": " inlt", - "island ": " is", - "islnd ": " is", - "isles ": " isle", - "islands ": " iss", - "islnds ": " iss", - "juncton ": " jct", - "jctn ": " jct", - "jction ": " jct", - "junctn ": " jct", - "junction ": " jct", - "jctns ": " jcts", - "junctions ": " jcts", - "knoll ": " knl", - "knol ": " knl", - "knolls ": " knls", - "key ": " ky", - "keys ": " kys", - "lock ": " lck", - "locks ": " lcks", - "lodge ": " ldg", - "lodg ": " ldg", - "ldge ": " ldg", - "loaf ": " lf", - "light ": " lgt", - "lights ": " lgts", - "lake ": " lk", - "lakes ": " lks", - "landing ": " lndg", - "lndng ": " lndg", - "loops ": " loop", - "meadow ": " mdw", - "meadows ": " mdws", - "medows ": " mdws", - "mill ": " ml", - "mills ": " mls", - "manor ": " mnr", - "manors ": " mnrs", - "mission ": " msn", - "mssn ": " msn", - "missn ": " msn", - "mnt ": " mt", - "mount ": " mt", - "mntn ": " mtn", - "mountain ": " mtn", - "mountin ": " mtn", - "mntain ": " mtn", - "mtin ": " mtn", - "mountains ": " mtns", - "motorway ": " mtwy", - "neck ": " nck", - "overpass ": " opas", - "orchard ": " orch", - "orchrd ": " orch", - "ovl ": " oval", - "prk ": " park", - "paths ": " path", - "pikes ": " pike", - "plain ": " pln", - "plains ": " plns", - "pine ": " pne", - "pines ": " pnes", - "prr ": " pr", - "prairie ": " pr", - "port ": " prt", - "ports ": " prts", - "passage ": " psge", - "point ": " pt", - "points ": " pts", - "rad ": " radl", - "radiel ": " radl", - "radial ": " radl", - "ridge ": " rdg", - "rdge ": " rdg", - "ridges ": " rdgs", - "roads ": " rds", - "river ": " riv", - "rvr ": " riv", - "rivr ": " riv", - "ranch ": " rnch", - "rnchs ": " rnch", - "ranches ": " rnch", - "rapid ": " rpd", - "rapids ": " rpds", - "rest ": " rst", - "route ": " rte", - "shoal ": " shl", - "shl ": " shl", - "shoals ": " shls", - "shoar ": " shr", - "shore ": " shr", - "shores ": " shrs", - "skyway ": " skwy", - "sumit ": " smt", - "summit ": " smt", - "sumitt ": " smt", - "sprng ": " spg", - "spring ": " spg", - "spng ": " spg", - "spngs ": " spgs", - "sprngs ": " spgs", - "springs ": " spgs", - "spurs ": " spur", - "sqre ": " sq", - "squares ": " sqs", - "sqrs ": " sqs", - "strt ": " st", - "station ": " sta", - "stn ": " sta", - "statn ": " sta", - "straven ": " stra", - "strav ": " stra", - "strvn ": " stra", - "stravenue ": " stra", - "stravn ": " stra", - "strvnue ": " stra", - "streme ": " strm", - "stream ": " strm", - "streets ": " sts", - "terr ": " ter", - "terrace ": " ter", - "turnpike ": " tpke", - "trnpk ": " tpke", - "turnpk ": " tpke", - "trk ": " trak", - "trks ": " trak", - "tracks ": " trak", - "track ": " trak", - "traces ": " trce", - "trace ": " trce", - "trafficway ": " trfy", - "trails ": " trl", - "trls ": " trl", - "trail ": " trl", - "trlrs ": " trlr", - "trailer ": " trlr", - "throughway ": " trwy", - "tunel ": " tunl", - "tunnel ": " tunl", - "tunnl ": " tunl", - "tunls ": " tunl", - "tunnels ": " tunl", - "union ": " un", - "unions ": " uns", - "underpass ": " upas", - "viadct ": " via", - "viaduct ": " via", - "vdct ": " via", - "vista ": " vis", - "vsta ": " vis", - "vist ": " vis", - "vst ": " vis", - "ville ": " vl", - "vill ": " vlg", - "village ": " vlg", - "villag ": " vlg", - "villiage ": " vlg", - "villg ": " vlg", - "villages ": " vlgs", - "vlly ": " vly", - "valley ": " vly", - "vally ": " vly", - "valleys ": " vlys", - "view ": " vw", - "views ": " vws", - "walks ": " walk", - "wy ": " way", - "ways ": " ways", - "well ": " wl", - "wells ": " wls", - "crossing ": " xing", - "crssng ": " xing", - "crossroad ": " xrd", - "crossroads ": " xrds", - "appt ": " apt", - "department ": " dept", - "hanger ": " hngr", - "hngr ": " hngr", - "lot ": " lot", - "room ": " rm", - "space ": " spc", - "suite ": " ste", - "floor ": " fl", - "building ": " bldg", - "basement ": " bsmt", - "front ": " frnt", - "lobby ": " lbby", - "lower ": " lowr", - "office ": " ofc", - "penthouse ": " ph", - "upper ": " uppr" -} diff --git a/src/v0/destinations/amazon_audience/data/statesMap.json b/src/v0/destinations/amazon_audience/data/statesMap.json deleted file mode 100644 index afc1e48f38..0000000000 --- a/src/v0/destinations/amazon_audience/data/statesMap.json +++ /dev/null @@ -1,277 +0,0 @@ -{ - "alabama ": " al", - "alberta ": " ab", - "badenwuerttemberg ": " bw", - "alsace ": " aa", - "agrigento ": " ag", - "alicante ": " a", - "alaska ": " ak", - "britishcolumbia ": " bc", - "bavaria ": " by", - "aquitaine ": " aq", - "alessandria ": " al", - "alacant ": " a", - "arizona ": " az", - "manitoba ": " mb", - "berlin ": " be", - "auvergne ": " au", - "ancona ": " an", - "albacete ": " ab", - "arkansas ": " ar", - "newbrunswick ": " nb", - "brandenburg ": " bb", - "brittany ": " bt", - "aosta ": " ao", - "almeria ": " al", - "california ": " ca", - "newfoundlandandlabrador ": " nl", - "bremen ": " hb", - "burgundy ": " bg", - "arezzo ": " ar", - "avila ": " av", - "colorado ": " co", - "northwestterritories ": " nt", - "hamburg ": " hh", - "centre ": " cn", - "ascolipiceno ": " ap", - "barcelona ": " b", - "connecticut ": " ct", - "novascotia ": " ns", - "hesse ": " he", - "champagneardenne ": " cg", - "asti ": " at", - "badajoz ": " ba", - "delaware ": " de", - "nunavut ": " nu", - "lowersaxony ": " ni", - "franchecomte ": " fc", - "avellino ": " av", - "vizcaya ": " bi", - "florida ": " fl", - "ontario ": " on", - "mecklenburgvorpommern ": " mv", - "iledefrance ": " if", - "bari ": " ba", - "bizkaia ": " bi", - "georgia ": " ga", - "princeedwardisland ": " pe", - "northrhinewestphalia ": " nw", - "languedocroussillon ": " lu", - "barlettaandriatrani ": " bt", - "burgos ": " bu", - "hawaii ": " hi", - "quebec ": " qc", - "rhinelandpalatinate ": " rp", - "limousin ": " lm", - "belluno ": " bl", - "lacoruna ": " c", - "idaho ": " id", - "saskatchewan ": " sk", - "saarland ": " sl", - "lorraine ": " le", - "benevento ": " bn", - "acoruna ": " c", - "illinois ": " il", - "yukon ": " yt", - "saxony ": " sn", - "lowernormandy ": " bn", - "bergamo ": " bg", - "cadiz ": " ca", - "indiana ": " in", - "saxonyanhalt ": " st", - "midipyrenees ": " mp", - "biella ": " bi", - "caceres ": " cc", - "iowa ": " ia", - "schleswigholstein ": " sh", - "nordpasdecalais ": " np", - "bologna ": " bo", - "ceuta ": " ce", - "kansas ": " ks", - "thuringia ": " th", - "paysdelaloire ": " pl", - "southtyrol ": " bz", - "cordoba ": " co", - "kentucky ": " ky", - "picardy ": " pi", - "brescia ": " bs", - "ciudadreal ": " cr", - "louisiana ": " la", - "poitoucharentes ": " pt", - "brindisi ": " br", - "castellon ": " cs", - "maine ": " me", - "provencealpescotedazur ": " pr", - "cagliari ": " ca", - "castello ": " cs", - "maryland ": " md", - "rhonealpes ": " ra", - "caltanissetta ": " cl", - "cuenca ": " cu", - "massachusetts ": " ma", - "uppernormandy ": " ht", - "campobasso ": " cb", - "laspalmas ": " gc", - "michigan ": " mi", - "corsica ": " ce", - "carboniaiglesias ": " ci", - "girona ": " gi", - "minnesota ": " mn", - "caserta ": " ce", - "gerona ": " gi", - "mississippi ": " ms", - "catania ": " ct", - "granada ": " gr", - "missouri ": " mo", - "catanzaro ": " cz", - "guadalajara ": " gu", - "montana ": " mt", - "chieti ": " ch", - "huelva ": " h", - "nebraska ": " ne", - "como ": " co", - "huesca ": " hu", - "nevada ": " nv", - "cosenza ": " cs", - "jaen ": " j", - "newhampshire ": " nh", - "cremona ": " cr", - "lerida ": " l", - "newjersey ": " nj", - "crotone ": " kr", - "lleida ": " l", - "newmexico ": " nm", - "cuneo ": " cn", - "leon ": " le", - "newyork ": " ny", - "enna ": " en", - "larioja ": " lo", - "northcarolina ": " nc", - "fermo ": " fm", - "lugo ": " lu", - "northdakota ": " nd", - "ferrara ": " fe", - "madrid ": " m", - "ohio ": " oh", - "florence ": " fi", - "malaga ": " ma", - "oklahoma ": " ok", - "foggia ": " fg", - "melilla ": " ml", - "oregon ": " or", - "forlicesena ": " fc", - "murcia ": " mu", - "pennsylvania ": " pa", - "frosinone ": " fr", - "navarra ": " na", - "puertorico ": " pr", - "genoa ": " ge", - "nafarroa ": " na", - "rhodeisland ": " ri", - "gorizia ": " go", - "asturias ": " o", - "southcarolina ": " sc", - "grosseto ": " gr", - "orense ": " or", - "southdakota ": " sd", - "imperia ": " im", - "ourense ": " or", - "tennessee ": " tn", - "isernia ": " is", - "palencia ": " p", - "texas ": " tx", - "laspezia ": " sp", - "baleares ": " pm", - "utah ": " ut", - "laquila ": " aq", - "balears ": " pm", - "vermont ": " vt", - "latina ": " lt", - "pontevedra ": " po", - "virginia ": " va", - "lecce ": " le", - "cantabria ": " s", - "washington ": " wa", - "lecco ": " lc", - "salamanca ": " sa", - "westvirginia ": " wv", - "livorno ": " li", - "sevilla ": " se", - "wisconsin ": " wi", - "lodi ": " lo", - "segovia ": " sg", - "wyoming ": " wy", - "lucca ": " lu", - "soria ": " so", - "macerata ": " mc", - "guipuzcoa ": " ss", - "mantua ": " mn", - "gipuzkoa ": " ss", - "massaandcarrara ": " ms", - "tarragona ": " t", - "matera ": " mt", - "teruel ": " te", - "mediocampidano ": " vs", - "santacruzdetenerife ": " tf", - "messina ": " me", - "toledo ": " to", - "milan ": " mi", - "valencia ": " v", - "modena ": " mo", - "valladolid ": " va", - "monzaandbrianza ": " mb", - "alava ": " vi", - "naples ": " na", - "araba ": " vi", - "novara ": " no", - "zaragoza ": " z", - "nuoro ": " nu", - "zamora ": " za", - "ogliastra ": " og", - "olbiatempio ": " ot", - "oristano ": " or", - "padua ": " pd", - "palermo ": " pa", - "parma ": " pr", - "pavia ": " pv", - "perugia ": " pg", - "pesaroandurbino ": " pu", - "pescara ": " pe", - "piacenza ": " pc", - "pisa ": " pi", - "pistoia ": " pt", - "pordenone ": " pn", - "potenza ": " pz", - "prato ": " po", - "ragusa ": " rg", - "ravenna ": " ra", - "reggiocalabria ": " rc", - "reggioemilia ": " re", - "rieti ": " ri", - "rimini ": " rn", - "rome ": " rm", - "rovigo ": " ro", - "salerno ": " sa", - "sassari ": " ss", - "savona ": " sv", - "siena ": " si", - "sondrio ": " so", - "syracuse ": " sr", - "taranto ": " ta", - "teramo ": " te", - "terni ": " tr", - "trapani ": " tp", - "trentino ": " tn", - "treviso ": " tv", - "trieste ": " ts", - "turin ": " to", - "udine ": " ud", - "varese ": " va", - "venice ": " ve", - "verbanocusioossola ": " vb", - "vercelli ": " vc", - "verona ": " vr", - "vibovalentia ": " vv", - "vicenza ": " vi", - "viterbo ": " vt" -} diff --git a/src/v0/destinations/amazon_audience/networkHandler.js b/src/v0/destinations/amazon_audience/networkHandler.js index 5569ec030d..c1fbeeccea 100644 --- a/src/v0/destinations/amazon_audience/networkHandler.js +++ b/src/v0/destinations/amazon_audience/networkHandler.js @@ -19,7 +19,7 @@ const amazonAudienceRespHandler = (destResponse, stageMsg) => { // to handle the case when authorization-token is invalid // docs for error codes: https://advertising.amazon.com/API/docs/en-us/reference/concepts/errors#tag/Audiences/operation/dspCreateAudiencesPost - if (status === 401 && response.message == 'Unauthorized') { + if (status === 401 && response.message === 'Unauthorized') { // 401 takes place in case of authorization isue meaning token is epxired or access is not enough. // Since acces is configured from dashboard only refresh token makes sense throw new NetworkError( diff --git a/src/v0/destinations/amazon_audience/utils.js b/src/v0/destinations/amazon_audience/utils.js index 62fa5c6d8e..43824ab4c6 100644 --- a/src/v0/destinations/amazon_audience/utils.js +++ b/src/v0/destinations/amazon_audience/utils.js @@ -1,8 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ const sha256 = require('sha256'); -const path = require('path'); -const fs = require('fs'); -const { phone } = require('phone'); +const AmazonAdsFormatter = require('amazon-dsp-formatter'); const lodash = require('lodash'); const { ConfigurationError, OAuthSecretError } = require('@rudderstack/integrations-lib'); const { @@ -10,7 +8,6 @@ const { defaultPostRequestConfig, getSuccessRespEvents, removeUndefinedAndNullAndEmptyValues, - isDefinedAndNotNull, } = require('../../util'); const buildResponseWithUsers = (users, action, config, jobIdList, secret) => { @@ -126,110 +123,61 @@ const getUserDetails = (fields, config) => { firstName, lastName, address, + country, city, state, postalCode, } = fields; + // Since all fields are optional hence notusing formatRecord function from formatter but doing it for every parameter + const formatter = new AmazonAdsFormatter(); const user = {}; // formating guidelines https://advertising.amazon.com/help/GCCXMZYCK4RXWS6C - // using undefined as fallback so in case properties are not string - if (email) { - const em = - email - ?.replace(/[^\d.@A-Za-z-]/g, '') - ?.trim() - ?.toLowerCase() || undefined; - user.email = enableHash ? sha256(em) : em; - } - if (phone_number) { - const updated_phone_number = phone(phone_number); - if (updated_phone_number.isValid) { + if (country) { + const country_code = formatter.formatCountry(country); + user.country = enableHash ? sha256(country_code) : country; + if (phone_number) { user.phone = enableHash - ? sha256(updated_phone_number.phoneNumber) - : updated_phone_number.phoneNumber; + ? sha256(formatter.formatPhone(phone_number, country_code)) + : phone_number; } } + // in case phone_number is present in hashed format and no country is available + if (phone_number && !enableHash) { + user.phone = phone_number; + } + if (email) { + user.email = enableHash ? sha256(formatter.formatEmail(email)) : email; + } + if (state) { - const st = getState(state); - user.state = enableHash ? sha256(st) : st; + user.state = enableHash ? sha256(formatter.formatState(state, country)) : state; } if (city) { - const ct = - city - ?.replace(/[^\dA-Za-z]/g, '') - ?.trim() - ?.toLowerCase() || undefined; - user.city = enableHash ? sha256(ct) : ct; + user.city = enableHash ? sha256(formatter.formatCity(city)) : city; } if (firstName) { - const fn = - firstName - ?.replace(/[^\dA-Za-z]/g, '') - ?.trim() - ?.toLowerCase() || undefined; - user.firstName = enableHash ? sha256(fn) : fn; + user.firstName = enableHash ? sha256(formatter.formatName(firstName)) : firstName; } if (lastName) { - const ln = - lastName - ?.replace(/[^\dA-Za-z]/g, '') - ?.trim() - ?.toLowerCase() || undefined; - user.lastName = enableHash ? sha256(ln) : ln; + user.lastName = enableHash ? sha256(formatter.formatName(lastName)) : lastName; } if (address) { - const add = getAddress(address); - user.address = enableHash ? sha256(add) : add; - } - if (postalCode) { - const zip = - postalCode - ?.replace(/[^\dA-Za-z]/g, '') + const formatted_address = + address + ?.normalize('NFD') + ?.replace(/[\u0300-\u036f]/g, '') ?.trim() ?.toLowerCase() - ?.substring(0, postalCode.length - 4) || undefined; - user.postalCode = enableHash ? sha256(zip) : zip; + .replace(/[^\dA-Za-z]/g, '') || undefined; + user.address = enableHash + ? sha256(formatter.formatAddress(formatted_address, country)) + : address; + } + if (postalCode) { + user.postalCode = enableHash ? sha256(formatter.formatPostal(postalCode)) : postalCode; } return removeUndefinedAndNullAndEmptyValues(user); }; -/* removing extra whitespaces, non alphanumeric char, accents and -doing lowercasing of the result string -*/ -const getAddress = (add) => { - const address = - add - ?.normalize('NFD') - ?.replace(/[\u0300-\u036f]/g, '') - ?.trim() - ?.toLowerCase() - .replace(/[^\dA-Za-z]/g, '') || undefined; - if (!isDefinedAndNotNull(address)) return undefined; - const addressKeys = address.split(','); - const addressMap = JSON.parse( - fs.readFileSync(path.resolve(__dirname, './data/addressMap.json'), 'utf-8'), - ); - let updated_address = ''; - addressKeys.forEach((key) => { - updated_address += addressMap[key] || key; - }); - return updated_address; -}; - -/* removing extra whitespaces, non alphanumeric char, accents and -doing lowercasing of the result string -*/ -const getState = (st) => { - const state = - st - ?.replace(/[^\dA-Za-z]/g, '') - ?.trim() - ?.toLowerCase() || undefined; - if (!isDefinedAndNotNull(state)) return undefined; - const stateMap = JSON.parse( - fs.readFileSync(path.resolve(__dirname, './data/statesMap.json'), 'utf-8'), - ); - return stateMap[state] || state; -}; module.exports = { batchEvents, getUserDetails, buildResponseWithUsers }; diff --git a/test/integrations/destinations/amazon_audience/processor/data.ts b/test/integrations/destinations/amazon_audience/processor/data.ts index d09abc977d..a0e6ece16e 100644 --- a/test/integrations/destinations/amazon_audience/processor/data.ts +++ b/test/integrations/destinations/amazon_audience/processor/data.ts @@ -3,7 +3,7 @@ const sha256 = require('sha256'); const fields = { email: 'abc@xyz.com', - phone: '+919876543323', + phone: '9876543323', firstName: 'test', lastName: 'user', address: ' Été très chaud! ', @@ -27,8 +27,9 @@ export const data = [ action: 'insert', fields: { ...fields, - city: 'delhi', - state: 'delhi', + city: 'Edmonton', + state: 'alberta', + country: 'Canada', postalCode: '12345', }, context: {}, @@ -55,9 +56,11 @@ export const data = [ { hashedRecords: [ { + country: + '6959097001d10501ac7d54c0bdb8db61420f658f2922cc26e46d536119a31126', address: '7e68f87b9675dca9a6cbd0b3b715af6cd9e0b75b72b96feec98dd334d665a76c', - city: '40ace5b4f58193240d4006e6468fa37fdf64111407672475b0a804b4a76d0339', + city: '5ae1b46bce91b626720727f9d8d1eb8998e5b6586b339b97c2288595fe25116a', firstName: '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08', email: @@ -65,11 +68,11 @@ export const data = [ lastName: '04f8996da763b7a969b1028ee3007569eaf3a635486ddab211d512c85b9df8fb', phone: - '7f2cd894bf36c7b92ec4eee9ef5885d6fd7a53a1100ac76d491e9b23957cab0c', + '3daf505bba309a952bb4bbd010d1d39e413e40c679ac3bbcee1ea9b009023ffa', postalCode: '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b', state: - '40ace5b4f58193240d4006e6468fa37fdf64111407672475b0a804b4a76d0339', + 'fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603', }, ], externalId: @@ -159,10 +162,10 @@ export const data = [ hashedRecords: [ { email: 'abc@xyz.com', - phone: '+919876543323', + phone: '9876543323', firstName: 'test', lastName: 'user', - address: 'etetreschaud', + address: ' Été très chaud! ', }, ], externalId: @@ -194,50 +197,50 @@ export const data = [ }, }, }, - { - name: 'amazon_audience', - id: 'Test 3', - description: 'Type Validation case', - successCriteria: 'It should be passed with 200 Ok giving validation error', - feature: 'processor', - module: 'destination', - version: 'v0', - input: { - request: { - body: [ - { - destination, - message: { - type: 'identify', - context: {}, - recordId: '1', - }, - metadata: generateMetadata(1), - }, - ], - }, - }, - output: { - response: { - status: 200, - body: [ - { - metadata: generateMetadata(1), - statusCode: 400, - error: '[AMAZON AUDIENCE]: identify is not supported', - statTags: { - errorCategory: 'dataValidation', - destinationId: 'default-destinationId', - errorType: 'instrumentation', - destType: 'AMAZON_AUDIENCE', - module: 'destination', - implementation: 'native', - workspaceId: 'default-workspaceId', - feature: 'processor', - }, - }, - ], - }, - }, - }, + // { + // name: 'amazon_audience', + // id: 'Test 3', + // description: 'Type Validation case', + // successCriteria: 'It should be passed with 200 Ok giving validation error', + // feature: 'processor', + // module: 'destination', + // version: 'v0', + // input: { + // request: { + // body: [ + // { + // destination, + // message: { + // type: 'identify', + // context: {}, + // recordId: '1', + // }, + // metadata: generateMetadata(1), + // }, + // ], + // }, + // }, + // output: { + // response: { + // status: 200, + // body: [ + // { + // metadata: generateMetadata(1), + // statusCode: 400, + // error: '[AMAZON AUDIENCE]: identify is not supported', + // statTags: { + // errorCategory: 'dataValidation', + // destinationId: 'default-destinationId', + // errorType: 'instrumentation', + // destType: 'AMAZON_AUDIENCE', + // module: 'destination', + // implementation: 'native', + // workspaceId: 'default-workspaceId', + // feature: 'processor', + // }, + // }, + // ], + // }, + // }, + // }, ];