@walkeros/server-destination-datamanager 0.4.0 → 0.4.1

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.
@@ -4,89 +4,81 @@ var __export = (target, all) => {
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
5
5
  };
6
6
 
7
- // src/examples/mapping.ts
8
- var mapping_exports = {};
9
- __export(mapping_exports, {
10
- Lead: () => Lead,
11
- PageView: () => PageView,
12
- Purchase: () => Purchase,
13
- mapping: () => mapping,
14
- userDataMapping: () => userDataMapping
7
+ // src/examples/auth.ts
8
+ var auth_exports = {};
9
+ __export(auth_exports, {
10
+ awsLambda: () => awsLambda,
11
+ customScopes: () => customScopes,
12
+ dockerKubernetes: () => dockerKubernetes,
13
+ gcpCloudFunctions: () => gcpCloudFunctions,
14
+ localDevelopment: () => localDevelopment
15
15
  });
16
- import { isObject } from "@walkeros/core";
17
- var Purchase = {
18
- name: "purchase",
19
- data: {
20
- map: {
21
- // Required fields
22
- transactionId: "data.id",
23
- conversionValue: "data.total",
24
- currency: { key: "data.currency", value: "USD" },
25
- eventName: { value: "purchase" },
26
- // User identification
27
- userId: "user.id",
28
- email: "user.id",
29
- // Will be hashed automatically
30
- // Attribution identifiers (captured by browser source from URL)
31
- gclid: "context.gclid",
32
- // Google Click ID
33
- gbraid: "context.gbraid",
34
- // iOS attribution
35
- wbraid: "context.wbraid",
36
- // Web-to-app
37
- // Shopping cart data
38
- cartData: {
39
- map: {
40
- items: {
41
- loop: [
42
- "nested",
43
- {
44
- condition: (entity) => isObject(entity) && entity.entity === "product",
45
- map: {
46
- merchantProductId: "data.id",
47
- price: "data.price",
48
- quantity: { key: "data.quantity", value: 1 }
49
- }
50
- }
51
- ]
52
- }
53
- }
16
+ var awsLambda = {
17
+ settings: {
18
+ credentials: {
19
+ client_email: process.env.GOOGLE_CLIENT_EMAIL,
20
+ private_key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, "\n")
21
+ },
22
+ destinations: [
23
+ {
24
+ operatingAccount: {
25
+ accountId: "123-456-7890",
26
+ accountType: "GOOGLE_ADS"
27
+ },
28
+ productDestinationId: "AW-CONVERSION-123"
54
29
  }
55
- }
30
+ ]
56
31
  }
57
32
  };
58
- var Lead = {
59
- name: "generate_lead",
60
- data: {
61
- map: {
62
- eventName: { value: "generate_lead" },
63
- conversionValue: { value: 10 },
64
- currency: { value: "USD" }
65
- }
33
+ var gcpCloudFunctions = {
34
+ settings: {
35
+ // No auth config needed - ADC works automatically on GCP!
36
+ destinations: [
37
+ {
38
+ operatingAccount: {
39
+ accountId: "123-456-7890",
40
+ accountType: "GOOGLE_ADS"
41
+ },
42
+ productDestinationId: "AW-CONVERSION-123"
43
+ }
44
+ ]
66
45
  }
67
46
  };
68
- var PageView = {
69
- name: "page_view",
70
- data: {
71
- map: {
72
- eventName: { value: "page_view" }
73
- }
47
+ var localDevelopment = {
48
+ settings: {
49
+ keyFilename: "./service-account.json",
50
+ destinations: [
51
+ {
52
+ operatingAccount: {
53
+ accountId: "123-456-7890",
54
+ accountType: "GOOGLE_ADS"
55
+ },
56
+ productDestinationId: "AW-CONVERSION-123"
57
+ }
58
+ ]
74
59
  }
75
60
  };
76
- var mapping = {
77
- order: {
78
- complete: Purchase
79
- },
80
- lead: {
81
- submit: Lead
82
- },
83
- page: {
84
- view: PageView
61
+ var dockerKubernetes = {
62
+ settings: {
63
+ // No explicit config - ADC uses GOOGLE_APPLICATION_CREDENTIALS env var
64
+ destinations: [
65
+ {
66
+ operatingAccount: {
67
+ accountId: "123-456-7890",
68
+ accountType: "GOOGLE_ADS"
69
+ },
70
+ productDestinationId: "AW-CONVERSION-123"
71
+ }
72
+ ]
85
73
  }
86
74
  };
87
- var userDataMapping = {
75
+ var customScopes = {
88
76
  settings: {
89
- accessToken: "ya29.c.xxx",
77
+ credentials: {
78
+ client_email: process.env.GOOGLE_CLIENT_EMAIL,
79
+ private_key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, "\n")
80
+ },
81
+ scopes: ["https://www.googleapis.com/auth/datamanager"],
90
82
  destinations: [
91
83
  {
92
84
  operatingAccount: {
@@ -96,18 +88,7 @@ var userDataMapping = {
96
88
  productDestinationId: "AW-CONVERSION-123"
97
89
  }
98
90
  ]
99
- },
100
- data: {
101
- map: {
102
- email: "user.id",
103
- phone: "data.phone",
104
- firstName: "data.firstName",
105
- lastName: "data.lastName",
106
- regionCode: "data.country",
107
- postalCode: "data.zip"
108
- }
109
- },
110
- mapping
91
+ }
111
92
  };
112
93
 
113
94
  // src/examples/basic.ts
@@ -120,7 +101,10 @@ __export(basic_exports, {
120
101
  });
121
102
  var minimal = {
122
103
  settings: {
123
- accessToken: "ya29.c.xxx",
104
+ credentials: {
105
+ client_email: "service-account@project.iam.gserviceaccount.com",
106
+ private_key: "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
107
+ },
124
108
  destinations: [
125
109
  {
126
110
  operatingAccount: {
@@ -134,7 +118,10 @@ var minimal = {
134
118
  };
135
119
  var complete = {
136
120
  settings: {
137
- accessToken: "ya29.c.xxx",
121
+ credentials: {
122
+ client_email: "service-account@project.iam.gserviceaccount.com",
123
+ private_key: "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
124
+ },
138
125
  destinations: [
139
126
  {
140
127
  operatingAccount: {
@@ -178,7 +165,6 @@ var complete = {
178
165
  };
179
166
  var ga4 = {
180
167
  settings: {
181
- accessToken: "ya29.c.xxx",
182
168
  destinations: [
183
169
  {
184
170
  operatingAccount: {
@@ -193,7 +179,7 @@ var ga4 = {
193
179
  };
194
180
  var debug = {
195
181
  settings: {
196
- accessToken: "ya29.c.xxx",
182
+ keyFilename: "./service-account.json",
197
183
  destinations: [
198
184
  {
199
185
  operatingAccount: {
@@ -207,7 +193,114 @@ var debug = {
207
193
  // Shows all API calls and responses
208
194
  }
209
195
  };
196
+
197
+ // src/examples/mapping.ts
198
+ var mapping_exports = {};
199
+ __export(mapping_exports, {
200
+ Lead: () => Lead,
201
+ PageView: () => PageView,
202
+ Purchase: () => Purchase,
203
+ mapping: () => mapping,
204
+ userDataMapping: () => userDataMapping
205
+ });
206
+ import { isObject } from "@walkeros/core";
207
+ var Purchase = {
208
+ name: "purchase",
209
+ data: {
210
+ map: {
211
+ // Required fields
212
+ transactionId: "data.id",
213
+ conversionValue: "data.total",
214
+ currency: { key: "data.currency", value: "USD" },
215
+ eventName: { value: "purchase" },
216
+ // User identification
217
+ userId: "user.id",
218
+ email: "user.id",
219
+ // Will be hashed automatically
220
+ // Attribution identifiers (captured by browser source from URL)
221
+ gclid: "context.gclid",
222
+ // Google Click ID
223
+ gbraid: "context.gbraid",
224
+ // iOS attribution
225
+ wbraid: "context.wbraid",
226
+ // Web-to-app
227
+ // Shopping cart data
228
+ cartData: {
229
+ map: {
230
+ items: {
231
+ loop: [
232
+ "nested",
233
+ {
234
+ condition: (entity) => isObject(entity) && entity.entity === "product",
235
+ map: {
236
+ merchantProductId: "data.id",
237
+ price: "data.price",
238
+ quantity: { key: "data.quantity", value: 1 }
239
+ }
240
+ }
241
+ ]
242
+ }
243
+ }
244
+ }
245
+ }
246
+ }
247
+ };
248
+ var Lead = {
249
+ name: "generate_lead",
250
+ data: {
251
+ map: {
252
+ eventName: { value: "generate_lead" },
253
+ conversionValue: { value: 10 },
254
+ currency: { value: "USD" }
255
+ }
256
+ }
257
+ };
258
+ var PageView = {
259
+ name: "page_view",
260
+ data: {
261
+ map: {
262
+ eventName: { value: "page_view" }
263
+ }
264
+ }
265
+ };
266
+ var mapping = {
267
+ order: {
268
+ complete: Purchase
269
+ },
270
+ lead: {
271
+ submit: Lead
272
+ },
273
+ page: {
274
+ view: PageView
275
+ }
276
+ };
277
+ var userDataMapping = {
278
+ settings: {
279
+ keyFilename: "./service-account.json",
280
+ destinations: [
281
+ {
282
+ operatingAccount: {
283
+ accountId: "123-456-7890",
284
+ accountType: "GOOGLE_ADS"
285
+ },
286
+ productDestinationId: "AW-CONVERSION-123"
287
+ }
288
+ ]
289
+ },
290
+ data: {
291
+ map: {
292
+ email: "user.id",
293
+ phone: "data.phone",
294
+ firstName: "data.firstName",
295
+ lastName: "data.lastName",
296
+ regionCode: "data.country",
297
+ postalCode: "data.zip"
298
+ }
299
+ },
300
+ mapping
301
+ };
210
302
  export {
303
+ auth_exports as auth,
211
304
  basic_exports as basic,
212
305
  mapping_exports as mapping
213
306
  };
package/dist/index.d.mts CHANGED
@@ -1,11 +1,28 @@
1
1
  import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
2
2
  import { DestinationServer } from '@walkeros/server-core';
3
+ import { OAuth2Client } from 'google-auth-library';
3
4
 
4
5
  type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';
5
6
 
6
7
  interface Settings {
7
- /** OAuth 2.0 access token with datamanager scope */
8
- accessToken: string;
8
+ /**
9
+ * Service account credentials (client_email + private_key)
10
+ * Recommended for serverless environments (AWS Lambda, Docker, etc.)
11
+ */
12
+ credentials?: {
13
+ client_email: string;
14
+ private_key: string;
15
+ };
16
+ /**
17
+ * Path to service account JSON file
18
+ * For local development or environments with filesystem access
19
+ */
20
+ keyFilename?: string;
21
+ /**
22
+ * OAuth scopes for Data Manager API
23
+ * @default ['https://www.googleapis.com/auth/datamanager']
24
+ */
25
+ scopes?: string[];
9
26
  /** Array of destination accounts and conversion actions/user lists */
10
27
  destinations: Destination[];
11
28
  /** Default event source if not specified per event */
@@ -45,8 +62,10 @@ interface Mapping {
45
62
  }
46
63
  interface Env extends DestinationServer.Env {
47
64
  fetch?: typeof fetch;
65
+ authClient?: OAuth2Client | null;
48
66
  }
49
- type Types = Destination$1.Types<Settings, Mapping, Env>;
67
+ type InitSettings = Partial<Settings>;
68
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
50
69
  interface DestinationInterface extends DestinationServer.Destination<Types> {
51
70
  init: DestinationServer.InitFn<Types>;
52
71
  }
@@ -64,21 +83,27 @@ type Rules = Mapping$1.Rules<Rule>;
64
83
  * https://developers.google.com/data-manager/api/reference/rest/v1/Destination
65
84
  */
66
85
  interface Destination {
67
- /** Operating account details */
68
- operatingAccount: OperatingAccount;
86
+ /** Reference identifier for this destination */
87
+ reference?: string;
88
+ /** Login account (account initiating the request) */
89
+ loginAccount?: ProductAccount;
90
+ /** Linked account (child account linked to login account) */
91
+ linkedAccount?: ProductAccount;
92
+ /** Operating account (account where data is sent) */
93
+ operatingAccount?: ProductAccount;
69
94
  /** Product-specific destination ID (conversion action or user list) */
70
- productDestinationId: string;
95
+ productDestinationId?: string;
71
96
  }
72
97
  /**
73
- * Operating account information
98
+ * Product account information
74
99
  */
75
- interface OperatingAccount {
100
+ interface ProductAccount {
76
101
  /** Account ID (e.g., "123-456-7890" for Google Ads) */
77
102
  accountId: string;
78
103
  /** Type of account */
79
104
  accountType: AccountType;
80
105
  }
81
- type AccountType = 'GOOGLE_ADS' | 'DISPLAY_VIDEO_ADVERTISER' | 'DISPLAY_VIDEO_PARTNER' | 'GOOGLE_ANALYTICS_PROPERTY';
106
+ type AccountType = 'ACCOUNT_TYPE_UNSPECIFIED' | 'GOOGLE_ADS' | 'DISPLAY_VIDEO_ADVERTISER' | 'DISPLAY_VIDEO_PARTNER' | 'GOOGLE_ANALYTICS_PROPERTY' | 'DATA_PARTNER';
82
107
  type EventSource = 'WEB' | 'APP' | 'IN_STORE' | 'PHONE' | 'OTHER';
83
108
  /**
84
109
  * Consent for Digital Markets Act (DMA) compliance
@@ -96,12 +121,10 @@ type ConsentStatus = 'CONSENT_GRANTED' | 'CONSENT_DENIED';
96
121
  * https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest
97
122
  */
98
123
  interface IngestEventsRequest {
99
- /** OAuth 2.0 access token */
100
- access_token?: string;
101
- /** Array of events to ingest (max 2000) */
102
- events: Event[];
103
124
  /** Array of destinations for these events (max 10) */
104
125
  destinations: Destination[];
126
+ /** Array of events to ingest (max 2000) */
127
+ events: Event[];
105
128
  /** Request-level consent (overridden by event-level) */
106
129
  consent?: Consent;
107
130
  /** If true, validate without ingestion */
@@ -114,30 +137,85 @@ interface IngestEventsRequest {
114
137
  * https://developers.google.com/data-manager/api/reference/rest/v1/Event
115
138
  */
116
139
  interface Event {
117
- /** Event timestamp in RFC 3339 format */
118
- eventTimestamp: string;
140
+ /** Destination references for routing */
141
+ destinationReferences?: string[];
119
142
  /** Transaction ID for deduplication (max 512 chars) */
120
143
  transactionId?: string;
121
- /** Google Analytics client ID (max 255 chars) */
122
- clientId?: string;
123
- /** First-party user ID (max 256 chars) */
124
- userId?: string;
144
+ /** Event timestamp in RFC 3339 format */
145
+ eventTimestamp?: string;
146
+ /** Last updated timestamp in RFC 3339 format */
147
+ lastUpdatedTimestamp?: string;
125
148
  /** User data with identifiers (max 10 identifiers) */
126
149
  userData?: UserData;
150
+ /** Event-level consent (overrides request-level) */
151
+ consent?: Consent;
127
152
  /** Attribution identifiers */
128
153
  adIdentifiers?: AdIdentifiers;
129
- /** Conversion value */
130
- conversionValue?: number;
131
154
  /** Currency code (ISO 4217, 3 chars) */
132
155
  currency?: string;
156
+ /** Conversion value */
157
+ conversionValue?: number;
158
+ /** Source of the event */
159
+ eventSource?: EventSource;
160
+ /** Device information for the event */
161
+ eventDeviceInfo?: DeviceInfo;
133
162
  /** Shopping cart data */
134
163
  cartData?: CartData;
164
+ /** Custom variables for the event */
165
+ customVariables?: CustomVariable[];
166
+ /** Experimental fields (subject to change) */
167
+ experimentalFields?: ExperimentalField[];
168
+ /** User properties */
169
+ userProperties?: UserProperties;
135
170
  /** Event name for GA4 (max 40 chars, required for GA4) */
136
171
  eventName?: string;
137
- /** Source of the event */
138
- eventSource?: EventSource;
139
- /** Event-level consent (overrides request-level) */
140
- consent?: Consent;
172
+ /** Google Analytics client ID (max 255 chars) */
173
+ clientId?: string;
174
+ /** First-party user ID (max 256 chars) */
175
+ userId?: string;
176
+ /** Additional event parameters */
177
+ additionalEventParameters?: EventParameter[];
178
+ }
179
+ /**
180
+ * Device information
181
+ */
182
+ interface DeviceInfo {
183
+ /** User agent string */
184
+ userAgent?: string;
185
+ }
186
+ /**
187
+ * Custom variable
188
+ */
189
+ interface CustomVariable {
190
+ /** Variable name */
191
+ name?: string;
192
+ /** Variable value */
193
+ value?: string;
194
+ }
195
+ /**
196
+ * Experimental field
197
+ */
198
+ interface ExperimentalField {
199
+ /** Field name */
200
+ name?: string;
201
+ /** Field value */
202
+ value?: string;
203
+ }
204
+ /**
205
+ * User properties
206
+ */
207
+ interface UserProperties {
208
+ /** Property values */
209
+ [key: string]: string | number | boolean | undefined;
210
+ }
211
+ /**
212
+ * Event parameter
213
+ */
214
+ interface EventParameter {
215
+ /** Parameter name */
216
+ name?: string;
217
+ /** Parameter value */
218
+ value?: string | number;
141
219
  }
142
220
  /**
143
221
  * User data with identifiers
@@ -176,14 +254,16 @@ interface Address {
176
254
  * https://developers.google.com/data-manager/api/reference/rest/v1/AdIdentifiers
177
255
  */
178
256
  interface AdIdentifiers {
257
+ /** Session attributes (privacy-safe attribution) */
258
+ sessionAttributes?: string;
179
259
  /** Google Click ID (primary attribution) */
180
260
  gclid?: string;
181
261
  /** iOS attribution identifier (post-ATT) */
182
262
  gbraid?: string;
183
263
  /** Web-to-app attribution identifier */
184
264
  wbraid?: string;
185
- /** Session attributes (privacy-safe attribution) */
186
- sessionAttributes?: string;
265
+ /** Device information for landing page */
266
+ landingPageDeviceInfo?: DeviceInfo;
187
267
  }
188
268
  /**
189
269
  * Shopping cart data
@@ -263,17 +343,22 @@ type index_CartItem = CartItem;
263
343
  type index_Config = Config;
264
344
  type index_Consent = Consent;
265
345
  type index_ConsentStatus = ConsentStatus;
346
+ type index_CustomVariable = CustomVariable;
266
347
  type index_Destination = Destination;
267
348
  type index_DestinationInterface = DestinationInterface;
349
+ type index_DeviceInfo = DeviceInfo;
268
350
  type index_Env = Env;
269
351
  type index_Event = Event;
352
+ type index_EventParameter = EventParameter;
270
353
  type index_EventSource = EventSource;
354
+ type index_ExperimentalField = ExperimentalField;
271
355
  type index_IngestEventsRequest = IngestEventsRequest;
272
356
  type index_IngestEventsResponse = IngestEventsResponse;
273
357
  type index_InitFn = InitFn;
358
+ type index_InitSettings = InitSettings;
274
359
  type index_Mapping = Mapping;
275
- type index_OperatingAccount = OperatingAccount;
276
360
  type index_PartialConfig = PartialConfig;
361
+ type index_ProductAccount = ProductAccount;
277
362
  type index_PushEvents = PushEvents;
278
363
  type index_PushFn = PushFn;
279
364
  type index_RequestError = RequestError;
@@ -285,9 +370,10 @@ type index_Settings = Settings;
285
370
  type index_Types = Types;
286
371
  type index_UserData = UserData;
287
372
  type index_UserIdentifier = UserIdentifier;
373
+ type index_UserProperties = UserProperties;
288
374
  type index_ValidationError = ValidationError;
289
375
  declare namespace index {
290
- export type { index_AccountType as AccountType, index_AdIdentifiers as AdIdentifiers, index_Address as Address, index_CartData as CartData, index_CartItem as CartItem, index_Config as Config, index_Consent as Consent, index_ConsentStatus as ConsentStatus, index_Destination as Destination, index_DestinationInterface as DestinationInterface, index_Env as Env, index_Event as Event, index_EventSource as EventSource, index_IngestEventsRequest as IngestEventsRequest, index_IngestEventsResponse as IngestEventsResponse, index_InitFn as InitFn, index_Mapping as Mapping, index_OperatingAccount as OperatingAccount, index_PartialConfig as PartialConfig, index_PushEvents as PushEvents, index_PushFn as PushFn, index_RequestError as RequestError, index_RequestState as RequestState, index_RequestStatusResponse as RequestStatusResponse, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types, index_UserData as UserData, index_UserIdentifier as UserIdentifier, index_ValidationError as ValidationError };
376
+ export type { index_AccountType as AccountType, index_AdIdentifiers as AdIdentifiers, index_Address as Address, index_CartData as CartData, index_CartItem as CartItem, index_Config as Config, index_Consent as Consent, index_ConsentStatus as ConsentStatus, index_CustomVariable as CustomVariable, index_Destination as Destination, index_DestinationInterface as DestinationInterface, index_DeviceInfo as DeviceInfo, index_Env as Env, index_Event as Event, index_EventParameter as EventParameter, index_EventSource as EventSource, index_ExperimentalField as ExperimentalField, index_IngestEventsRequest as IngestEventsRequest, index_IngestEventsResponse as IngestEventsResponse, index_InitFn as InitFn, index_InitSettings as InitSettings, index_Mapping as Mapping, index_PartialConfig as PartialConfig, index_ProductAccount as ProductAccount, index_PushEvents as PushEvents, index_PushFn as PushFn, index_RequestError as RequestError, index_RequestState as RequestState, index_RequestStatusResponse as RequestStatusResponse, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types, index_UserData as UserData, index_UserIdentifier as UserIdentifier, index_UserProperties as UserProperties, index_ValidationError as ValidationError };
291
377
  }
292
378
 
293
379
  declare const destinationDataManager: DestinationInterface;