@walkeros/server-destination-datamanager 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/schemas.js +1 -1
- package/dist/schemas.mjs +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,r={};function s(e={},t){const n=e.settings||{},{destinations:i,eventSource:a="WEB"}=n;i&&0!==i.length||t.throw("Config settings destinations missing or empty");const r={...n,destinations:i,eventSource:a};return{...e,settings:r}}((e,n)=>{for(var i in n)t(e,i,{get:n[i],enumerable:!0})})(r,{DestinationDataManager:()=>w,default:()=>b,destinationDataManager:()=>y}),module.exports=(e=r,((e,r,s,o)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let c of i(r))a.call(e,c)||c===s||t(e,c,{get:()=>r[c],enumerable:!(o=n(r,c))||o.enumerable});return e})(t({},"__esModule",{value:!0}),e));var o=require("@walkeros/core"),c=require("@walkeros/core"),l=require("@walkeros/core"),g=require("@walkeros/server-core");async function d(e,t="given"){if(!(0,l.isString)(e)||!e)return"";let n=e.trim().toLowerCase();if("given"===t){const e=["mr.","mrs.","ms.","miss.","dr.","prof."];for(const t of e)if(n.startsWith(t)){n=n.substring(t.length).trim();break}}if("family"===t){const e=["jr.","sr.","iii","ii","iv","v"];for(const t of e){const e=` ${t}`;if(n.endsWith(e)){n=n.substring(0,n.length-e.length).trim();break}if(n.endsWith(t)){n=n.substring(0,n.length-t.length).trim();break}}}return(0,g.getHashServer)(n)}async function u(e){const t=[];if((0,c.isString)(e.email)&&e.email){const n=await async function(e){if(!(0,l.isString)(e)||!e)return"";let t=e.trim().toLowerCase();if(t.endsWith("@gmail.com")||t.endsWith("@googlemail.com")){const[e,n]=t.split("@");t=`${e.replace(/\./g,"")}@${n}`}return(0,g.getHashServer)(t)}(e.email);n&&t.push({emailAddress:n})}if((0,c.isString)(e.phone)&&e.phone){const n=await async function(e){if(!(0,l.isString)(e)||!e)return"";let t=e.trim();const n=t.startsWith("+");return t=t.replace(/\D/g,""),t=n||t.length>10?`+${t}`:`+1${t}`,(0,g.getHashServer)(t)}(e.phone);n&&t.push({phoneNumber:n})}if(e.firstName||e.lastName||e.regionCode||e.postalCode){const n={};(0,c.isString)(e.firstName)&&e.firstName&&(n.givenName=await d(e.firstName,"given")),(0,c.isString)(e.lastName)&&e.lastName&&(n.familyName=await d(e.lastName,"family")),(0,c.isString)(e.regionCode)&&e.regionCode&&(n.regionCode=e.regionCode.toUpperCase()),(0,c.isString)(e.postalCode)&&e.postalCode&&(n.postalCode=e.postalCode),Object.keys(n).length>0&&t.push({address:n})}if(0!==t.length)return{userIdentifiers:t.slice(0,10)}}async function f(e,t){const n={eventTimestamp:(i=e.timestamp,new Date(i).toISOString())};var i;const a=t||{};(0,c.isString)(a.transactionId)&&a.transactionId&&(n.transactionId=a.transactionId.substring(0,512)),(0,c.isString)(a.clientId)&&a.clientId&&(n.clientId=a.clientId.substring(0,255)),(0,c.isString)(a.userId)&&a.userId&&(n.userId=a.userId.substring(0,256));const r=await u(a);r&&(n.userData=r);const s=function(e){const t={};return(0,c.isString)(e.gclid)&&e.gclid&&(t.gclid=e.gclid),(0,c.isString)(e.gbraid)&&e.gbraid&&(t.gbraid=e.gbraid),(0,c.isString)(e.wbraid)&&e.wbraid&&(t.wbraid=e.wbraid),(0,c.isString)(e.sessionAttributes)&&e.sessionAttributes&&(t.sessionAttributes=e.sessionAttributes),Object.keys(t).length>0?t:void 0}(a);s&&(n.adIdentifiers=s),"number"==typeof a.conversionValue&&(n.conversionValue=a.conversionValue),(0,c.isString)(a.currency)&&a.currency&&(n.currency=a.currency.substring(0,3).toUpperCase()),a.cartData&&"object"==typeof a.cartData&&(n.cartData=a.cartData),(0,c.isString)(a.eventName)&&a.eventName&&(n.eventName=a.eventName.substring(0,40)),(0,c.isString)(a.eventSource)&&a.eventSource&&(n.eventSource=a.eventSource);const o={};if("boolean"==typeof a.adUserData&&(o.adUserData=a.adUserData?"CONSENT_GRANTED":"CONSENT_DENIED"),"boolean"==typeof a.adPersonalization&&(o.adPersonalization=a.adPersonalization?"CONSENT_GRANTED":"CONSENT_DENIED"),0===Object.keys(o).length){const t=function(e){if(!e)return;const t={};return(0,c.isDefined)(e.marketing)&&(t.adUserData=e.marketing?"CONSENT_GRANTED":"CONSENT_DENIED"),(0,c.isDefined)(e.personalization)&&(t.adPersonalization=e.personalization?"CONSENT_GRANTED":"CONSENT_DENIED"),Object.keys(t).length>0?t:void 0}(e.consent);t&&(n.consent=t)}else n.consent=o;return n}var p=require("google-auth-library"),h=["https://www.googleapis.com/auth/datamanager"],v=class extends Error{constructor(e,t){super(e),this.cause=t,this.name="DataManagerAuthError"}};var m=async function(e,{config:t,mapping:n,data:i,collector:a,env:r,logger:c}){const l=s(t,c),{destinations:g,eventSource:d,validateOnly:u=!1,url:p="https://datamanager.googleapis.com/v1",consent:h,testEventCode:m,userData:w,userId:y,clientId:b,sessionAttributes:N,consentAdUserData:S,consentAdPersonalization:D}=l.settings,E=w?await(0,o.getMappingValue)(e,{map:w}):{},C=y?await(0,o.getMappingValue)(e,y):void 0,O=b?await(0,o.getMappingValue)(e,b):void 0,I=N?await(0,o.getMappingValue)(e,N):void 0,A="boolean"==typeof S?S:"string"==typeof S&&e.consent?e.consent[S]:void 0,k="boolean"==typeof D?D:"string"==typeof D&&e.consent?e.consent[D]:void 0,T={};(0,o.isObject)(E)&&Object.assign(T,E),void 0!==C&&(T.userId=C),void 0!==O&&(T.clientId=O),void 0!==I&&(T.sessionAttributes=I),void 0!==A&&(T.adUserData=A),void 0!==k&&(T.adPersonalization=k);const P=l.data?await(0,o.getMappingValue)(e,l.data):{},j=(0,o.isObject)(i)?i:{},_={...T,...(0,o.isObject)(P)?P:{},...j},G=await f(e,_);G.eventSource||(G.eventSource=d),!G.consent&&h&&(G.consent=h),G.transactionId||c.throw("transactionId is required");g.some(e=>{var t;return"GOOGLE_ANALYTICS_PROPERTY"===(null==(t=e.operatingAccount)?void 0:t.accountType)})&&!G.eventName&&c.throw("eventName is required for GA4 destinations");const M={events:[G],destinations:g};h&&(M.consent=h),u&&(M.validateOnly=!0),m&&(M.testEventCode=m);const $=null==r?void 0:r.authClient;if(!$)return c.throw("Auth client not initialized. Ensure init() was called successfully.");let z;try{z=await async function(e){try{const t=await e.getAccessToken();if(!t.token)throw new v("Auth client returned empty token");return t.token}catch(e){throw new v("Failed to obtain access token",e instanceof Error?e:void 0)}}($)}catch(e){throw c.error("Authentication failed",{error:e}),e}const q=(null==r?void 0:r.fetch)||fetch,U=`${p}/events:ingest`;c.debug("Sending to Data Manager API",{endpoint:U,eventCount:M.events.length,destinations:g.length,validateOnly:u});const V=await q(U,{method:"POST",headers:{Authorization:`Bearer ${z}`,"Content-Type":"application/json"},body:JSON.stringify(M)});if(!V.ok){const e=await V.text();c.throw(`Data Manager API error (${V.status}): ${e}`)}const L=await V.json();c.debug("API response",{status:V.status,requestId:L.requestId}),L.validationErrors&&L.validationErrors.length>0&&c.throw(`Validation errors: ${JSON.stringify(L.validationErrors)}`)},w={},y={type:"datamanager",config:{},async init({config:e,env:t,logger:n}){const i=s(e,n);try{const e=await async function(e){const{credentials:t,keyFilename:n,scopes:i=h}=e;try{if(t){const e=new p.GoogleAuth({credentials:t,scopes:i});return await e.getClient()}if(n){const e=new p.GoogleAuth({keyFilename:n,scopes:i});return await e.getClient()}const e=new p.GoogleAuth({scopes:i});return await e.getClient()}catch(e){throw new v("Failed to create auth client. Check credentials configuration or ensure GOOGLE_APPLICATION_CREDENTIALS is set.",e instanceof Error?e:void 0)}}(i.settings);return n.debug("Auth client created"),{...i,env:{...t,authClient:e}}}catch(e){n.throw(`Data Manager authentication failed: ${e instanceof Error?e.message:"Unknown error"}`)}},push:async(e,{config:t,mapping:n,data:i,collector:a,env:r,logger:s})=>await m(e,{config:t,mapping:n,data:i,collector:a,env:r,logger:s})},b=y;//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";var mod,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,index_exports={};function getConfig(partialConfig={},logger){const settings=partialConfig.settings||{},{destinations:destinations,eventSource:eventSource="WEB"}=settings;destinations&&0!==destinations.length||logger.throw("Config settings destinations missing or empty");const settingsConfig={...settings,destinations:destinations,eventSource:eventSource};return{...partialConfig,settings:settingsConfig}}((target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})})(index_exports,{DestinationDataManager:()=>types_exports,default:()=>index_default,destinationDataManager:()=>destinationDataManager}),module.exports=(mod=index_exports,((to,from,except,desc)=>{if(from&&"object"==typeof from||"function"==typeof from)for(let key of __getOwnPropNames(from))__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to})(__defProp({},"__esModule",{value:!0}),mod));var import_core3=require("@walkeros/core"),import_core2=require("@walkeros/core"),import_core=require("@walkeros/core"),import_server_core=require("@walkeros/server-core");async function hashName(name,type="given"){if(!(0,import_core.isString)(name)||!name)return"";let normalized=name.trim().toLowerCase();if("given"===type){const prefixes=["mr.","mrs.","ms.","miss.","dr.","prof."];for(const prefix of prefixes)if(normalized.startsWith(prefix)){normalized=normalized.substring(prefix.length).trim();break}}if("family"===type){const suffixes=["jr.","sr.","iii","ii","iv","v"];for(const suffix of suffixes){const suffixWithSpace=` ${suffix}`;if(normalized.endsWith(suffixWithSpace)){normalized=normalized.substring(0,normalized.length-suffixWithSpace.length).trim();break}if(normalized.endsWith(suffix)){normalized=normalized.substring(0,normalized.length-suffix.length).trim();break}}}return(0,import_server_core.getHashServer)(normalized)}async function formatUserData(data){const identifiers=[];if((0,import_core2.isString)(data.email)&&data.email){const hashedEmail=await async function(email){if(!(0,import_core.isString)(email)||!email)return"";let normalized=email.trim().toLowerCase();if(normalized.endsWith("@gmail.com")||normalized.endsWith("@googlemail.com")){const[localPart,domain]=normalized.split("@");normalized=`${localPart.replace(/\./g,"")}@${domain}`}return(0,import_server_core.getHashServer)(normalized)}(data.email);hashedEmail&&identifiers.push({emailAddress:hashedEmail})}if((0,import_core2.isString)(data.phone)&&data.phone){const hashedPhone=await async function(phone){if(!(0,import_core.isString)(phone)||!phone)return"";let normalized=phone.trim();const hasPlus=normalized.startsWith("+");return normalized=normalized.replace(/\D/g,""),normalized=hasPlus||normalized.length>10?`+${normalized}`:`+1${normalized}`,(0,import_server_core.getHashServer)(normalized)}(data.phone);hashedPhone&&identifiers.push({phoneNumber:hashedPhone})}if(data.firstName||data.lastName||data.regionCode||data.postalCode){const address={};(0,import_core2.isString)(data.firstName)&&data.firstName&&(address.givenName=await hashName(data.firstName,"given")),(0,import_core2.isString)(data.lastName)&&data.lastName&&(address.familyName=await hashName(data.lastName,"family")),(0,import_core2.isString)(data.regionCode)&&data.regionCode&&(address.regionCode=data.regionCode.toUpperCase()),(0,import_core2.isString)(data.postalCode)&&data.postalCode&&(address.postalCode=data.postalCode),Object.keys(address).length>0&&identifiers.push({address:address})}if(0!==identifiers.length)return{userIdentifiers:identifiers.slice(0,10)}}async function formatEvent(event,mappedData){const dataManagerEvent={eventTimestamp:(timestamp=event.timestamp,new Date(timestamp).toISOString())};var timestamp;const data=mappedData||{};(0,import_core2.isString)(data.transactionId)&&data.transactionId&&(dataManagerEvent.transactionId=data.transactionId.substring(0,512)),(0,import_core2.isString)(data.clientId)&&data.clientId&&(dataManagerEvent.clientId=data.clientId.substring(0,255)),(0,import_core2.isString)(data.userId)&&data.userId&&(dataManagerEvent.userId=data.userId.substring(0,256));const userData=await formatUserData(data);userData&&(dataManagerEvent.userData=userData);const adIdentifiers=function(data){const identifiers={};return(0,import_core2.isString)(data.gclid)&&data.gclid&&(identifiers.gclid=data.gclid),(0,import_core2.isString)(data.gbraid)&&data.gbraid&&(identifiers.gbraid=data.gbraid),(0,import_core2.isString)(data.wbraid)&&data.wbraid&&(identifiers.wbraid=data.wbraid),(0,import_core2.isString)(data.sessionAttributes)&&data.sessionAttributes&&(identifiers.sessionAttributes=data.sessionAttributes),Object.keys(identifiers).length>0?identifiers:void 0}(data);adIdentifiers&&(dataManagerEvent.adIdentifiers=adIdentifiers),"number"==typeof data.conversionValue&&(dataManagerEvent.conversionValue=data.conversionValue),(0,import_core2.isString)(data.currency)&&data.currency&&(dataManagerEvent.currency=data.currency.substring(0,3).toUpperCase()),data.cartData&&"object"==typeof data.cartData&&(dataManagerEvent.cartData=data.cartData),(0,import_core2.isString)(data.eventName)&&data.eventName&&(dataManagerEvent.eventName=data.eventName.substring(0,40)),(0,import_core2.isString)(data.eventSource)&&data.eventSource&&(dataManagerEvent.eventSource=data.eventSource);const mappedConsent={};if("boolean"==typeof data.adUserData&&(mappedConsent.adUserData=data.adUserData?"CONSENT_GRANTED":"CONSENT_DENIED"),"boolean"==typeof data.adPersonalization&&(mappedConsent.adPersonalization=data.adPersonalization?"CONSENT_GRANTED":"CONSENT_DENIED"),0===Object.keys(mappedConsent).length){const eventConsent=function(walkerOSConsent){if(!walkerOSConsent)return;const consent={};return(0,import_core2.isDefined)(walkerOSConsent.marketing)&&(consent.adUserData=walkerOSConsent.marketing?"CONSENT_GRANTED":"CONSENT_DENIED"),(0,import_core2.isDefined)(walkerOSConsent.personalization)&&(consent.adPersonalization=walkerOSConsent.personalization?"CONSENT_GRANTED":"CONSENT_DENIED"),Object.keys(consent).length>0?consent:void 0}(event.consent);eventConsent&&(dataManagerEvent.consent=eventConsent)}else dataManagerEvent.consent=mappedConsent;return dataManagerEvent}var import_google_auth_library=require("google-auth-library"),DEFAULT_SCOPES=["https://www.googleapis.com/auth/datamanager"],AuthError=class extends Error{constructor(message,cause){super(message),this.cause=cause,this.name="DataManagerAuthError"}};var push=async function(event,{config:config,mapping:mapping,data:data,collector:collector,env:env,logger:logger}){const validatedConfig=getConfig(config,logger),{destinations:destinations,eventSource:eventSource,validateOnly:validateOnly=!1,url:url="https://datamanager.googleapis.com/v1",consent:requestConsent,testEventCode:testEventCode,userData:userData,userId:userId,clientId:clientId,sessionAttributes:sessionAttributes,consentAdUserData:consentAdUserData,consentAdPersonalization:consentAdPersonalization}=validatedConfig.settings,userDataMapped=userData?await(0,import_core3.getMappingValue)(event,{map:userData}):{},userIdMapped=userId?await(0,import_core3.getMappingValue)(event,userId):void 0,clientIdMapped=clientId?await(0,import_core3.getMappingValue)(event,clientId):void 0,sessionAttributesMapped=sessionAttributes?await(0,import_core3.getMappingValue)(event,sessionAttributes):void 0,consentAdUserDataValue="boolean"==typeof consentAdUserData?consentAdUserData:"string"==typeof consentAdUserData&&event.consent?event.consent[consentAdUserData]:void 0,consentAdPersonalizationValue="boolean"==typeof consentAdPersonalization?consentAdPersonalization:"string"==typeof consentAdPersonalization&&event.consent?event.consent[consentAdPersonalization]:void 0,settingsHelpers={};(0,import_core3.isObject)(userDataMapped)&&Object.assign(settingsHelpers,userDataMapped),void 0!==userIdMapped&&(settingsHelpers.userId=userIdMapped),void 0!==clientIdMapped&&(settingsHelpers.clientId=clientIdMapped),void 0!==sessionAttributesMapped&&(settingsHelpers.sessionAttributes=sessionAttributesMapped),void 0!==consentAdUserDataValue&&(settingsHelpers.adUserData=consentAdUserDataValue),void 0!==consentAdPersonalizationValue&&(settingsHelpers.adPersonalization=consentAdPersonalizationValue);const configData=validatedConfig.data?await(0,import_core3.getMappingValue)(event,validatedConfig.data):{},eventData=(0,import_core3.isObject)(data)?data:{},finalData={...settingsHelpers,...(0,import_core3.isObject)(configData)?configData:{},...eventData},dataManagerEvent=await formatEvent(event,finalData);dataManagerEvent.eventSource||(dataManagerEvent.eventSource=eventSource),!dataManagerEvent.consent&&requestConsent&&(dataManagerEvent.consent=requestConsent),dataManagerEvent.transactionId||logger.throw("transactionId is required");destinations.some(d=>{var _a;return"GOOGLE_ANALYTICS_PROPERTY"===(null==(_a=d.operatingAccount)?void 0:_a.accountType)})&&!dataManagerEvent.eventName&&logger.throw("eventName is required for GA4 destinations");const requestBody={events:[dataManagerEvent],destinations:destinations};requestConsent&&(requestBody.consent=requestConsent),validateOnly&&(requestBody.validateOnly=!0),testEventCode&&(requestBody.testEventCode=testEventCode);const authClient=null==env?void 0:env.authClient;if(!authClient)return logger.throw("Auth client not initialized. Ensure init() was called successfully.");let accessToken;try{accessToken=await async function(authClient){try{const tokenResponse=await authClient.getAccessToken();if(!tokenResponse.token)throw new AuthError("Auth client returned empty token");return tokenResponse.token}catch(error){throw new AuthError("Failed to obtain access token",error instanceof Error?error:void 0)}}(authClient)}catch(error){throw logger.error("Authentication failed",{error:error}),error}const fetchFn=(null==env?void 0:env.fetch)||fetch,endpoint=`${url}/events:ingest`;logger.debug("Sending to Data Manager API",{endpoint:endpoint,eventCount:requestBody.events.length,destinations:destinations.length,validateOnly:validateOnly});const response=await fetchFn(endpoint,{method:"POST",headers:{Authorization:`Bearer ${accessToken}`,"Content-Type":"application/json"},body:JSON.stringify(requestBody)});if(!response.ok){const errorText=await response.text();logger.throw(`Data Manager API error (${response.status}): ${errorText}`)}const result=await response.json();logger.debug("API response",{status:response.status,requestId:result.requestId}),result.validationErrors&&result.validationErrors.length>0&&logger.throw(`Validation errors: ${JSON.stringify(result.validationErrors)}`)},types_exports={},destinationDataManager={type:"datamanager",config:{},async init({config:partialConfig,env:env,logger:logger}){const config=getConfig(partialConfig,logger);try{const authClient=await async function(settings){const{credentials:credentials,keyFilename:keyFilename,scopes:scopes=DEFAULT_SCOPES}=settings;try{if(credentials){const auth2=new import_google_auth_library.GoogleAuth({credentials:credentials,scopes:scopes});return await auth2.getClient()}if(keyFilename){const auth2=new import_google_auth_library.GoogleAuth({keyFilename:keyFilename,scopes:scopes});return await auth2.getClient()}const auth=new import_google_auth_library.GoogleAuth({scopes:scopes});return await auth.getClient()}catch(error){throw new AuthError("Failed to create auth client. Check credentials configuration or ensure GOOGLE_APPLICATION_CREDENTIALS is set.",error instanceof Error?error:void 0)}}(config.settings);return logger.debug("Auth client created"),{...config,env:{...env,authClient:authClient}}}catch(error){logger.throw(`Data Manager authentication failed: ${error instanceof Error?error.message:"Unknown error"}`)}},push:async(event,{config:config,mapping:mapping,data:data,collector:collector,env:env,logger:logger})=>await push(event,{config:config,mapping:mapping,data:data,collector:collector,env:env,logger:logger})},index_default=destinationDataManager;//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t={},e){const n=t.settings||{},{destinations:a,eventSource:o="WEB"}=n;a&&0!==a.length||e.throw("Config settings destinations missing or empty");const i={...n,destinations:a,eventSource:o};return{...t,settings:i}}import{getMappingValue as e,isObject as n}from"@walkeros/core";import{isString as a,isDefined as o}from"@walkeros/core";import{isString as i}from"@walkeros/core";import{getHashServer as s}from"@walkeros/server-core";async function r(t,e="given"){if(!i(t)||!t)return"";let n=t.trim().toLowerCase();if("given"===e){const t=["mr.","mrs.","ms.","miss.","dr.","prof."];for(const e of t)if(n.startsWith(e)){n=n.substring(e.length).trim();break}}if("family"===e){const t=["jr.","sr.","iii","ii","iv","v"];for(const e of t){const t=` ${e}`;if(n.endsWith(t)){n=n.substring(0,n.length-t.length).trim();break}if(n.endsWith(e)){n=n.substring(0,n.length-e.length).trim();break}}}return s(n)}async function c(t){const e=[];if(a(t.email)&&t.email){const n=await async function(t){if(!i(t)||!t)return"";let e=t.trim().toLowerCase();if(e.endsWith("@gmail.com")||e.endsWith("@googlemail.com")){const[t,n]=e.split("@");e=`${t.replace(/\./g,"")}@${n}`}return s(e)}(t.email);n&&e.push({emailAddress:n})}if(a(t.phone)&&t.phone){const n=await async function(t){if(!i(t)||!t)return"";let e=t.trim();const n=e.startsWith("+");return e=e.replace(/\D/g,""),e=n||e.length>10?`+${e}`:`+1${e}`,s(e)}(t.phone);n&&e.push({phoneNumber:n})}if(t.firstName||t.lastName||t.regionCode||t.postalCode){const n={};a(t.firstName)&&t.firstName&&(n.givenName=await r(t.firstName,"given")),a(t.lastName)&&t.lastName&&(n.familyName=await r(t.lastName,"family")),a(t.regionCode)&&t.regionCode&&(n.regionCode=t.regionCode.toUpperCase()),a(t.postalCode)&&t.postalCode&&(n.postalCode=t.postalCode),Object.keys(n).length>0&&e.push({address:n})}if(0!==e.length)return{userIdentifiers:e.slice(0,10)}}async function d(t,e){const n={eventTimestamp:(i=t.timestamp,new Date(i).toISOString())};var i;const s=e||{};a(s.transactionId)&&s.transactionId&&(n.transactionId=s.transactionId.substring(0,512)),a(s.clientId)&&s.clientId&&(n.clientId=s.clientId.substring(0,255)),a(s.userId)&&s.userId&&(n.userId=s.userId.substring(0,256));const r=await c(s);r&&(n.userData=r);const d=function(t){const e={};return a(t.gclid)&&t.gclid&&(e.gclid=t.gclid),a(t.gbraid)&&t.gbraid&&(e.gbraid=t.gbraid),a(t.wbraid)&&t.wbraid&&(e.wbraid=t.wbraid),a(t.sessionAttributes)&&t.sessionAttributes&&(e.sessionAttributes=t.sessionAttributes),Object.keys(e).length>0?e:void 0}(s);d&&(n.adIdentifiers=d),"number"==typeof s.conversionValue&&(n.conversionValue=s.conversionValue),a(s.currency)&&s.currency&&(n.currency=s.currency.substring(0,3).toUpperCase()),s.cartData&&"object"==typeof s.cartData&&(n.cartData=s.cartData),a(s.eventName)&&s.eventName&&(n.eventName=s.eventName.substring(0,40)),a(s.eventSource)&&s.eventSource&&(n.eventSource=s.eventSource);const l={};if("boolean"==typeof s.adUserData&&(l.adUserData=s.adUserData?"CONSENT_GRANTED":"CONSENT_DENIED"),"boolean"==typeof s.adPersonalization&&(l.adPersonalization=s.adPersonalization?"CONSENT_GRANTED":"CONSENT_DENIED"),0===Object.keys(l).length){const e=function(t){if(!t)return;const e={};return o(t.marketing)&&(e.adUserData=t.marketing?"CONSENT_GRANTED":"CONSENT_DENIED"),o(t.personalization)&&(e.adPersonalization=t.personalization?"CONSENT_GRANTED":"CONSENT_DENIED"),Object.keys(e).length>0?e:void 0}(t.consent);e&&(n.consent=e)}else n.consent=l;return n}import{GoogleAuth as l}from"google-auth-library";var u=["https://www.googleapis.com/auth/datamanager"],g=class extends Error{constructor(t,e){super(t),this.cause=e,this.name="DataManagerAuthError"}};var f=async function(a,{config:o,mapping:i,data:s,collector:r,env:c,logger:l}){const u=t(o,l),{destinations:f,eventSource:m,validateOnly:h=!1,url:p="https://datamanager.googleapis.com/v1",consent:v,testEventCode:w,userData:y,userId:N,clientId:b,sessionAttributes:E,consentAdUserData:C,consentAdPersonalization:I}=u.settings,D=y?await e(a,{map:y}):{},A=N?await e(a,N):void 0,O=b?await e(a,b):void 0,S=E?await e(a,E):void 0,k="boolean"==typeof C?C:"string"==typeof C&&a.consent?a.consent[C]:void 0,T="boolean"==typeof I?I:"string"==typeof I&&a.consent?a.consent[I]:void 0,P={};n(D)&&Object.assign(P,D),void 0!==A&&(P.userId=A),void 0!==O&&(P.clientId=O),void 0!==S&&(P.sessionAttributes=S),void 0!==k&&(P.adUserData=k),void 0!==T&&(P.adPersonalization=T);const _=u.data?await e(a,u.data):{},$=n(s)?s:{},z={...P,...n(_)?_:{},...$},j=await d(a,z);j.eventSource||(j.eventSource=m),!j.consent&&v&&(j.consent=v),j.transactionId||l.throw("transactionId is required");f.some(t=>{var e;return"GOOGLE_ANALYTICS_PROPERTY"===(null==(e=t.operatingAccount)?void 0:e.accountType)})&&!j.eventName&&l.throw("eventName is required for GA4 destinations");const G={events:[j],destinations:f};v&&(G.consent=v),h&&(G.validateOnly=!0),w&&(G.testEventCode=w);const U=null==c?void 0:c.authClient;if(!U)return l.throw("Auth client not initialized. Ensure init() was called successfully.");let L;try{L=await async function(t){try{const e=await t.getAccessToken();if(!e.token)throw new g("Auth client returned empty token");return e.token}catch(t){throw new g("Failed to obtain access token",t instanceof Error?t:void 0)}}(U)}catch(t){throw l.error("Authentication failed",{error:t}),t}const R=(null==c?void 0:c.fetch)||fetch,W=`${p}/events:ingest`;l.debug("Sending to Data Manager API",{endpoint:W,eventCount:G.events.length,destinations:f.length,validateOnly:h});const M=await R(W,{method:"POST",headers:{Authorization:`Bearer ${L}`,"Content-Type":"application/json"},body:JSON.stringify(G)});if(!M.ok){const t=await M.text();l.throw(`Data Manager API error (${M.status}): ${t}`)}const q=await M.json();l.debug("API response",{status:M.status,requestId:q.requestId}),q.validationErrors&&q.validationErrors.length>0&&l.throw(`Validation errors: ${JSON.stringify(q.validationErrors)}`)},m={},h={type:"datamanager",config:{},async init({config:e,env:n,logger:a}){const o=t(e,a);try{const t=await async function(t){const{credentials:e,keyFilename:n,scopes:a=u}=t;try{if(e){const t=new l({credentials:e,scopes:a});return await t.getClient()}if(n){const t=new l({keyFilename:n,scopes:a});return await t.getClient()}const t=new l({scopes:a});return await t.getClient()}catch(t){throw new g("Failed to create auth client. Check credentials configuration or ensure GOOGLE_APPLICATION_CREDENTIALS is set.",t instanceof Error?t:void 0)}}(o.settings);return a.debug("Auth client created"),{...o,env:{...n,authClient:t}}}catch(t){a.throw(`Data Manager authentication failed: ${t instanceof Error?t.message:"Unknown error"}`)}},push:async(t,{config:e,mapping:n,data:a,collector:o,env:i,logger:s})=>await f(t,{config:e,mapping:n,data:a,collector:o,env:i,logger:s})},p=h;export{m as DestinationDataManager,p as default,h as destinationDataManager};//# sourceMappingURL=index.mjs.map
|
|
1
|
+
function getConfig(partialConfig={},logger){const settings=partialConfig.settings||{},{destinations:destinations,eventSource:eventSource="WEB"}=settings;destinations&&0!==destinations.length||logger.throw("Config settings destinations missing or empty");const settingsConfig={...settings,destinations:destinations,eventSource:eventSource};return{...partialConfig,settings:settingsConfig}}import{getMappingValue,isObject}from"@walkeros/core";import{isString as isString2,isDefined}from"@walkeros/core";import{isString}from"@walkeros/core";import{getHashServer}from"@walkeros/server-core";async function hashName(name,type="given"){if(!isString(name)||!name)return"";let normalized=name.trim().toLowerCase();if("given"===type){const prefixes=["mr.","mrs.","ms.","miss.","dr.","prof."];for(const prefix of prefixes)if(normalized.startsWith(prefix)){normalized=normalized.substring(prefix.length).trim();break}}if("family"===type){const suffixes=["jr.","sr.","iii","ii","iv","v"];for(const suffix of suffixes){const suffixWithSpace=` ${suffix}`;if(normalized.endsWith(suffixWithSpace)){normalized=normalized.substring(0,normalized.length-suffixWithSpace.length).trim();break}if(normalized.endsWith(suffix)){normalized=normalized.substring(0,normalized.length-suffix.length).trim();break}}}return getHashServer(normalized)}async function formatUserData(data){const identifiers=[];if(isString2(data.email)&&data.email){const hashedEmail=await async function(email){if(!isString(email)||!email)return"";let normalized=email.trim().toLowerCase();if(normalized.endsWith("@gmail.com")||normalized.endsWith("@googlemail.com")){const[localPart,domain]=normalized.split("@");normalized=`${localPart.replace(/\./g,"")}@${domain}`}return getHashServer(normalized)}(data.email);hashedEmail&&identifiers.push({emailAddress:hashedEmail})}if(isString2(data.phone)&&data.phone){const hashedPhone=await async function(phone){if(!isString(phone)||!phone)return"";let normalized=phone.trim();const hasPlus=normalized.startsWith("+");return normalized=normalized.replace(/\D/g,""),normalized=hasPlus||normalized.length>10?`+${normalized}`:`+1${normalized}`,getHashServer(normalized)}(data.phone);hashedPhone&&identifiers.push({phoneNumber:hashedPhone})}if(data.firstName||data.lastName||data.regionCode||data.postalCode){const address={};isString2(data.firstName)&&data.firstName&&(address.givenName=await hashName(data.firstName,"given")),isString2(data.lastName)&&data.lastName&&(address.familyName=await hashName(data.lastName,"family")),isString2(data.regionCode)&&data.regionCode&&(address.regionCode=data.regionCode.toUpperCase()),isString2(data.postalCode)&&data.postalCode&&(address.postalCode=data.postalCode),Object.keys(address).length>0&&identifiers.push({address:address})}if(0!==identifiers.length)return{userIdentifiers:identifiers.slice(0,10)}}async function formatEvent(event,mappedData){const dataManagerEvent={eventTimestamp:(timestamp=event.timestamp,new Date(timestamp).toISOString())};var timestamp;const data=mappedData||{};isString2(data.transactionId)&&data.transactionId&&(dataManagerEvent.transactionId=data.transactionId.substring(0,512)),isString2(data.clientId)&&data.clientId&&(dataManagerEvent.clientId=data.clientId.substring(0,255)),isString2(data.userId)&&data.userId&&(dataManagerEvent.userId=data.userId.substring(0,256));const userData=await formatUserData(data);userData&&(dataManagerEvent.userData=userData);const adIdentifiers=function(data){const identifiers={};return isString2(data.gclid)&&data.gclid&&(identifiers.gclid=data.gclid),isString2(data.gbraid)&&data.gbraid&&(identifiers.gbraid=data.gbraid),isString2(data.wbraid)&&data.wbraid&&(identifiers.wbraid=data.wbraid),isString2(data.sessionAttributes)&&data.sessionAttributes&&(identifiers.sessionAttributes=data.sessionAttributes),Object.keys(identifiers).length>0?identifiers:void 0}(data);adIdentifiers&&(dataManagerEvent.adIdentifiers=adIdentifiers),"number"==typeof data.conversionValue&&(dataManagerEvent.conversionValue=data.conversionValue),isString2(data.currency)&&data.currency&&(dataManagerEvent.currency=data.currency.substring(0,3).toUpperCase()),data.cartData&&"object"==typeof data.cartData&&(dataManagerEvent.cartData=data.cartData),isString2(data.eventName)&&data.eventName&&(dataManagerEvent.eventName=data.eventName.substring(0,40)),isString2(data.eventSource)&&data.eventSource&&(dataManagerEvent.eventSource=data.eventSource);const mappedConsent={};if("boolean"==typeof data.adUserData&&(mappedConsent.adUserData=data.adUserData?"CONSENT_GRANTED":"CONSENT_DENIED"),"boolean"==typeof data.adPersonalization&&(mappedConsent.adPersonalization=data.adPersonalization?"CONSENT_GRANTED":"CONSENT_DENIED"),0===Object.keys(mappedConsent).length){const eventConsent=function(walkerOSConsent){if(!walkerOSConsent)return;const consent={};return isDefined(walkerOSConsent.marketing)&&(consent.adUserData=walkerOSConsent.marketing?"CONSENT_GRANTED":"CONSENT_DENIED"),isDefined(walkerOSConsent.personalization)&&(consent.adPersonalization=walkerOSConsent.personalization?"CONSENT_GRANTED":"CONSENT_DENIED"),Object.keys(consent).length>0?consent:void 0}(event.consent);eventConsent&&(dataManagerEvent.consent=eventConsent)}else dataManagerEvent.consent=mappedConsent;return dataManagerEvent}import{GoogleAuth}from"google-auth-library";var DEFAULT_SCOPES=["https://www.googleapis.com/auth/datamanager"],AuthError=class extends Error{constructor(message,cause){super(message),this.cause=cause,this.name="DataManagerAuthError"}};var push=async function(event,{config:config,mapping:mapping,data:data,collector:collector,env:env,logger:logger}){const validatedConfig=getConfig(config,logger),{destinations:destinations,eventSource:eventSource,validateOnly:validateOnly=!1,url:url="https://datamanager.googleapis.com/v1",consent:requestConsent,testEventCode:testEventCode,userData:userData,userId:userId,clientId:clientId,sessionAttributes:sessionAttributes,consentAdUserData:consentAdUserData,consentAdPersonalization:consentAdPersonalization}=validatedConfig.settings,userDataMapped=userData?await getMappingValue(event,{map:userData}):{},userIdMapped=userId?await getMappingValue(event,userId):void 0,clientIdMapped=clientId?await getMappingValue(event,clientId):void 0,sessionAttributesMapped=sessionAttributes?await getMappingValue(event,sessionAttributes):void 0,consentAdUserDataValue="boolean"==typeof consentAdUserData?consentAdUserData:"string"==typeof consentAdUserData&&event.consent?event.consent[consentAdUserData]:void 0,consentAdPersonalizationValue="boolean"==typeof consentAdPersonalization?consentAdPersonalization:"string"==typeof consentAdPersonalization&&event.consent?event.consent[consentAdPersonalization]:void 0,settingsHelpers={};isObject(userDataMapped)&&Object.assign(settingsHelpers,userDataMapped),void 0!==userIdMapped&&(settingsHelpers.userId=userIdMapped),void 0!==clientIdMapped&&(settingsHelpers.clientId=clientIdMapped),void 0!==sessionAttributesMapped&&(settingsHelpers.sessionAttributes=sessionAttributesMapped),void 0!==consentAdUserDataValue&&(settingsHelpers.adUserData=consentAdUserDataValue),void 0!==consentAdPersonalizationValue&&(settingsHelpers.adPersonalization=consentAdPersonalizationValue);const configData=validatedConfig.data?await getMappingValue(event,validatedConfig.data):{},eventData=isObject(data)?data:{},finalData={...settingsHelpers,...isObject(configData)?configData:{},...eventData},dataManagerEvent=await formatEvent(event,finalData);dataManagerEvent.eventSource||(dataManagerEvent.eventSource=eventSource),!dataManagerEvent.consent&&requestConsent&&(dataManagerEvent.consent=requestConsent),dataManagerEvent.transactionId||logger.throw("transactionId is required");destinations.some(d=>{var _a;return"GOOGLE_ANALYTICS_PROPERTY"===(null==(_a=d.operatingAccount)?void 0:_a.accountType)})&&!dataManagerEvent.eventName&&logger.throw("eventName is required for GA4 destinations");const requestBody={events:[dataManagerEvent],destinations:destinations};requestConsent&&(requestBody.consent=requestConsent),validateOnly&&(requestBody.validateOnly=!0),testEventCode&&(requestBody.testEventCode=testEventCode);const authClient=null==env?void 0:env.authClient;if(!authClient)return logger.throw("Auth client not initialized. Ensure init() was called successfully.");let accessToken;try{accessToken=await async function(authClient){try{const tokenResponse=await authClient.getAccessToken();if(!tokenResponse.token)throw new AuthError("Auth client returned empty token");return tokenResponse.token}catch(error){throw new AuthError("Failed to obtain access token",error instanceof Error?error:void 0)}}(authClient)}catch(error){throw logger.error("Authentication failed",{error:error}),error}const fetchFn=(null==env?void 0:env.fetch)||fetch,endpoint=`${url}/events:ingest`;logger.debug("Sending to Data Manager API",{endpoint:endpoint,eventCount:requestBody.events.length,destinations:destinations.length,validateOnly:validateOnly});const response=await fetchFn(endpoint,{method:"POST",headers:{Authorization:`Bearer ${accessToken}`,"Content-Type":"application/json"},body:JSON.stringify(requestBody)});if(!response.ok){const errorText=await response.text();logger.throw(`Data Manager API error (${response.status}): ${errorText}`)}const result=await response.json();logger.debug("API response",{status:response.status,requestId:result.requestId}),result.validationErrors&&result.validationErrors.length>0&&logger.throw(`Validation errors: ${JSON.stringify(result.validationErrors)}`)},types_exports={},destinationDataManager={type:"datamanager",config:{},async init({config:partialConfig,env:env,logger:logger}){const config=getConfig(partialConfig,logger);try{const authClient=await async function(settings){const{credentials:credentials,keyFilename:keyFilename,scopes:scopes=DEFAULT_SCOPES}=settings;try{if(credentials){const auth2=new GoogleAuth({credentials:credentials,scopes:scopes});return await auth2.getClient()}if(keyFilename){const auth2=new GoogleAuth({keyFilename:keyFilename,scopes:scopes});return await auth2.getClient()}const auth=new GoogleAuth({scopes:scopes});return await auth.getClient()}catch(error){throw new AuthError("Failed to create auth client. Check credentials configuration or ensure GOOGLE_APPLICATION_CREDENTIALS is set.",error instanceof Error?error:void 0)}}(config.settings);return logger.debug("Auth client created"),{...config,env:{...env,authClient:authClient}}}catch(error){logger.throw(`Data Manager authentication failed: ${error instanceof Error?error.message:"Unknown error"}`)}},push:async(event,{config:config,mapping:mapping,data:data,collector:collector,env:env,logger:logger})=>await push(event,{config:config,mapping:mapping,data:data,collector:collector,env:env,logger:logger})},index_default=destinationDataManager;export{types_exports as DestinationDataManager,index_default as default,destinationDataManager};//# sourceMappingURL=index.mjs.map
|
package/dist/schemas.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var mod,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,schemas_exports={};((target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})})(schemas_exports,{mapping:()=>mapping,settings:()=>settings}),module.exports=(mod=schemas_exports,((to,from,except,desc)=>{if(from&&"object"==typeof from||"function"==typeof from)for(let key of __getOwnPropNames(from))__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to})(__defProp({},"__esModule",{value:!0}),mod));var import_dev=require("@walkeros/core/dev"),AccountTypeSchema=import_dev.z.enum(["GOOGLE_ADS","DISPLAY_VIDEO_ADVERTISER","DISPLAY_VIDEO_PARTNER","GOOGLE_ANALYTICS_PROPERTY"]),EventSourceSchema=import_dev.z.enum(["WEB","APP","IN_STORE","PHONE","OTHER"]),ConsentStatusSchema=import_dev.z.enum(["CONSENT_GRANTED","CONSENT_DENIED"]),ConsentSchema=import_dev.z.object({adUserData:ConsentStatusSchema.describe("Consent for data collection and use").optional(),adPersonalization:ConsentStatusSchema.describe("Consent for ad personalization").optional()}),OperatingAccountSchema=import_dev.z.object({accountId:import_dev.z.string().min(1).describe('Account ID (e.g., "123-456-7890" for Google Ads)'),accountType:AccountTypeSchema.describe("Type of account")}),DestinationSchema=import_dev.z.object({operatingAccount:OperatingAccountSchema.describe("Operating account details"),productDestinationId:import_dev.z.string().min(1).describe("Product-specific destination ID (conversion action or user list)")}),import_dev2=require("@walkeros/core/dev"),CredentialsSchema=import_dev2.z.object({client_email:import_dev2.z.string().email().describe("Service account email"),private_key:import_dev2.z.string().min(1).describe("Service account private key (PEM format)")}),SettingsSchema=import_dev2.z.object({credentials:CredentialsSchema.optional().describe("Service account credentials (client_email + private_key). Recommended for serverless environments."),keyFilename:import_dev2.z.string().optional().describe("Path to service account JSON file. For local development or environments with filesystem access."),scopes:import_dev2.z.array(import_dev2.z.string()).optional().describe("OAuth scopes for Data Manager API. Defaults to datamanager scope."),destinations:import_dev2.z.array(DestinationSchema).min(1).max(10).describe("Array of destination accounts and conversion actions/user lists (max 10)"),eventSource:EventSourceSchema.optional().default("WEB").describe("Event source for all events. Defaults to WEB. Values: WEB, APP, IN_STORE, PHONE, OTHER"),batchSize:import_dev2.z.number().int().min(1).max(2e3).describe("Maximum number of events to batch before sending (max 2000, like 100)").optional(),batchInterval:import_dev2.z.number().int().min(0).describe("Time in milliseconds to wait before auto-flushing batch (like 5000)").optional(),validateOnly:import_dev2.z.boolean().describe("If true, validate request without ingestion (testing mode)").optional(),url:import_dev2.z.string().url().describe("Override API endpoint for testing (like https://datamanager.googleapis.com/v1)").optional(),consent:ConsentSchema.describe("Request-level consent for all events").optional(),testEventCode:import_dev2.z.string().describe("Test event code for debugging (like TEST12345)").optional(),logLevel:import_dev2.z.enum(["debug","info","warn","error","none"]).describe("Log level for debugging (debug shows all API calls)").optional(),userData:import_dev2.z.record(import_dev2.z.string(),import_dev2.z.unknown()).describe("Guided helper: User data mapping for all events (like { email: 'user.id', phone: 'data.phone' })").optional(),userId:import_dev2.z.any().describe("Guided helper: First-party user ID for all events (like 'user.id')").optional(),clientId:import_dev2.z.any().describe("Guided helper: GA4 client ID for all events (like 'user.device')").optional(),sessionAttributes:import_dev2.z.any().describe("Guided helper: Privacy-safe attribution for all events (like 'context.sessionAttributes')").optional(),consentAdUserData:import_dev2.z.union([import_dev2.z.string(),import_dev2.z.boolean()]).describe("Consent mapping: Field name from event.consent (like 'marketing') or static boolean value").optional(),consentAdPersonalization:import_dev2.z.union([import_dev2.z.string(),import_dev2.z.boolean()]).describe("Consent mapping: Field name from event.consent (like 'targeting') or static boolean value").optional()}),MappingSchema=require("@walkeros/core/dev").z.object({}),import_dev4=require("@walkeros/core/dev"),settings=(0,import_dev4.zodToSchema)(SettingsSchema),mapping=(0,import_dev4.zodToSchema)(MappingSchema);//# sourceMappingURL=schemas.js.map
|
package/dist/schemas.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z
|
|
1
|
+
import{z}from"@walkeros/core/dev";var AccountTypeSchema=z.enum(["GOOGLE_ADS","DISPLAY_VIDEO_ADVERTISER","DISPLAY_VIDEO_PARTNER","GOOGLE_ANALYTICS_PROPERTY"]),EventSourceSchema=z.enum(["WEB","APP","IN_STORE","PHONE","OTHER"]),ConsentStatusSchema=z.enum(["CONSENT_GRANTED","CONSENT_DENIED"]),ConsentSchema=z.object({adUserData:ConsentStatusSchema.describe("Consent for data collection and use").optional(),adPersonalization:ConsentStatusSchema.describe("Consent for ad personalization").optional()}),OperatingAccountSchema=z.object({accountId:z.string().min(1).describe('Account ID (e.g., "123-456-7890" for Google Ads)'),accountType:AccountTypeSchema.describe("Type of account")}),DestinationSchema=z.object({operatingAccount:OperatingAccountSchema.describe("Operating account details"),productDestinationId:z.string().min(1).describe("Product-specific destination ID (conversion action or user list)")});import{z as z2}from"@walkeros/core/dev";var CredentialsSchema=z2.object({client_email:z2.string().email().describe("Service account email"),private_key:z2.string().min(1).describe("Service account private key (PEM format)")}),SettingsSchema=z2.object({credentials:CredentialsSchema.optional().describe("Service account credentials (client_email + private_key). Recommended for serverless environments."),keyFilename:z2.string().optional().describe("Path to service account JSON file. For local development or environments with filesystem access."),scopes:z2.array(z2.string()).optional().describe("OAuth scopes for Data Manager API. Defaults to datamanager scope."),destinations:z2.array(DestinationSchema).min(1).max(10).describe("Array of destination accounts and conversion actions/user lists (max 10)"),eventSource:EventSourceSchema.optional().default("WEB").describe("Event source for all events. Defaults to WEB. Values: WEB, APP, IN_STORE, PHONE, OTHER"),batchSize:z2.number().int().min(1).max(2e3).describe("Maximum number of events to batch before sending (max 2000, like 100)").optional(),batchInterval:z2.number().int().min(0).describe("Time in milliseconds to wait before auto-flushing batch (like 5000)").optional(),validateOnly:z2.boolean().describe("If true, validate request without ingestion (testing mode)").optional(),url:z2.string().url().describe("Override API endpoint for testing (like https://datamanager.googleapis.com/v1)").optional(),consent:ConsentSchema.describe("Request-level consent for all events").optional(),testEventCode:z2.string().describe("Test event code for debugging (like TEST12345)").optional(),logLevel:z2.enum(["debug","info","warn","error","none"]).describe("Log level for debugging (debug shows all API calls)").optional(),userData:z2.record(z2.string(),z2.unknown()).describe("Guided helper: User data mapping for all events (like { email: 'user.id', phone: 'data.phone' })").optional(),userId:z2.any().describe("Guided helper: First-party user ID for all events (like 'user.id')").optional(),clientId:z2.any().describe("Guided helper: GA4 client ID for all events (like 'user.device')").optional(),sessionAttributes:z2.any().describe("Guided helper: Privacy-safe attribution for all events (like 'context.sessionAttributes')").optional(),consentAdUserData:z2.union([z2.string(),z2.boolean()]).describe("Consent mapping: Field name from event.consent (like 'marketing') or static boolean value").optional(),consentAdPersonalization:z2.union([z2.string(),z2.boolean()]).describe("Consent mapping: Field name from event.consent (like 'targeting') or static boolean value").optional()});import{z as z3}from"@walkeros/core/dev";var MappingSchema=z3.object({});import{zodToSchema}from"@walkeros/core/dev";var settings=zodToSchema(SettingsSchema),mapping=zodToSchema(MappingSchema);export{mapping,settings};//# sourceMappingURL=schemas.mjs.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@walkeros/server-destination-datamanager",
|
|
3
3
|
"description": "Google Data Manager server destination for walkerOS",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"update": "npx npm-check-updates -u && npm update"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@walkeros/core": "0.
|
|
36
|
-
"@walkeros/server-core": "0.
|
|
35
|
+
"@walkeros/core": "0.6.0",
|
|
36
|
+
"@walkeros/server-core": "0.6.0",
|
|
37
37
|
"google-auth-library": "^10.5.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {},
|