@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.
@@ -1,11 +1,28 @@
1
1
  import { Mapping as Mapping$1, Destination as Destination$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
  type Config = {
51
70
  settings: Settings;
52
71
  } & DestinationServer.Config<Types>;
@@ -56,21 +75,27 @@ type Rule = Mapping$1.Rule<Mapping>;
56
75
  * https://developers.google.com/data-manager/api/reference/rest/v1/Destination
57
76
  */
58
77
  interface Destination {
59
- /** Operating account details */
60
- operatingAccount: OperatingAccount;
78
+ /** Reference identifier for this destination */
79
+ reference?: string;
80
+ /** Login account (account initiating the request) */
81
+ loginAccount?: ProductAccount;
82
+ /** Linked account (child account linked to login account) */
83
+ linkedAccount?: ProductAccount;
84
+ /** Operating account (account where data is sent) */
85
+ operatingAccount?: ProductAccount;
61
86
  /** Product-specific destination ID (conversion action or user list) */
62
- productDestinationId: string;
87
+ productDestinationId?: string;
63
88
  }
64
89
  /**
65
- * Operating account information
90
+ * Product account information
66
91
  */
67
- interface OperatingAccount {
92
+ interface ProductAccount {
68
93
  /** Account ID (e.g., "123-456-7890" for Google Ads) */
69
94
  accountId: string;
70
95
  /** Type of account */
71
96
  accountType: AccountType;
72
97
  }
73
- type AccountType = 'GOOGLE_ADS' | 'DISPLAY_VIDEO_ADVERTISER' | 'DISPLAY_VIDEO_PARTNER' | 'GOOGLE_ANALYTICS_PROPERTY';
98
+ type AccountType = 'ACCOUNT_TYPE_UNSPECIFIED' | 'GOOGLE_ADS' | 'DISPLAY_VIDEO_ADVERTISER' | 'DISPLAY_VIDEO_PARTNER' | 'GOOGLE_ANALYTICS_PROPERTY' | 'DATA_PARTNER';
74
99
  type EventSource = 'WEB' | 'APP' | 'IN_STORE' | 'PHONE' | 'OTHER';
75
100
  /**
76
101
  * Consent for Digital Markets Act (DMA) compliance
@@ -84,6 +109,75 @@ interface Consent {
84
109
  }
85
110
  type ConsentStatus = 'CONSENT_GRANTED' | 'CONSENT_DENIED';
86
111
 
112
+ /**
113
+ * AWS Lambda / Serverless Configuration
114
+ * Uses inline credentials from environment variables
115
+ * Best for: AWS Lambda, Docker, Kubernetes, any serverless environment
116
+ */
117
+ declare const awsLambda: Config;
118
+ /**
119
+ * GCP Cloud Functions / Cloud Run Configuration
120
+ * Uses Application Default Credentials (ADC) - no explicit auth config needed
121
+ * Best for: Google Cloud Functions, Cloud Run, GCE, GKE
122
+ */
123
+ declare const gcpCloudFunctions: Config;
124
+ /**
125
+ * Local Development Configuration
126
+ * Uses service account JSON file
127
+ * Best for: Local development, testing
128
+ */
129
+ declare const localDevelopment: Config;
130
+ /**
131
+ * Docker / Kubernetes Configuration
132
+ * Uses ADC via GOOGLE_APPLICATION_CREDENTIALS environment variable
133
+ * Best for: Docker containers, Kubernetes pods
134
+ *
135
+ * Setup:
136
+ * 1. Mount service account JSON as secret/configmap
137
+ * 2. Set GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
138
+ * 3. ADC will automatically use it
139
+ */
140
+ declare const dockerKubernetes: Config;
141
+ /**
142
+ * Custom Scopes Configuration
143
+ * For specific use cases requiring different OAuth scopes
144
+ */
145
+ declare const customScopes: Config;
146
+
147
+ declare const auth_awsLambda: typeof awsLambda;
148
+ declare const auth_customScopes: typeof customScopes;
149
+ declare const auth_dockerKubernetes: typeof dockerKubernetes;
150
+ declare const auth_gcpCloudFunctions: typeof gcpCloudFunctions;
151
+ declare const auth_localDevelopment: typeof localDevelopment;
152
+ declare namespace auth {
153
+ export { auth_awsLambda as awsLambda, auth_customScopes as customScopes, auth_dockerKubernetes as dockerKubernetes, auth_gcpCloudFunctions as gcpCloudFunctions, auth_localDevelopment as localDevelopment };
154
+ }
155
+
156
+ /**
157
+ * Minimal configuration for Google Data Manager with inline credentials
158
+ */
159
+ declare const minimal: Config;
160
+ /**
161
+ * Complete configuration with all options
162
+ */
163
+ declare const complete: Config;
164
+ /**
165
+ * GA4-specific configuration using Application Default Credentials
166
+ */
167
+ declare const ga4: Config;
168
+ /**
169
+ * Debug configuration with logging enabled using keyFilename
170
+ */
171
+ declare const debug: Config;
172
+
173
+ declare const basic_complete: typeof complete;
174
+ declare const basic_debug: typeof debug;
175
+ declare const basic_ga4: typeof ga4;
176
+ declare const basic_minimal: typeof minimal;
177
+ declare namespace basic {
178
+ export { basic_complete as complete, basic_debug as debug, basic_ga4 as ga4, basic_minimal as minimal };
179
+ }
180
+
87
181
  /**
88
182
  * Purchase event mapping for Google Ads conversion
89
183
  */
@@ -125,29 +219,4 @@ declare namespace mapping$1 {
125
219
  export { mapping$1_Lead as Lead, mapping$1_PageView as PageView, mapping$1_Purchase as Purchase, mapping$1_mapping as mapping, mapping$1_userDataMapping as userDataMapping };
126
220
  }
127
221
 
128
- /**
129
- * Minimal configuration for Google Data Manager
130
- */
131
- declare const minimal: Config;
132
- /**
133
- * Complete configuration with all options
134
- */
135
- declare const complete: Config;
136
- /**
137
- * GA4-specific configuration
138
- */
139
- declare const ga4: Config;
140
- /**
141
- * Debug configuration with logging enabled
142
- */
143
- declare const debug: Config;
144
-
145
- declare const basic_complete: typeof complete;
146
- declare const basic_debug: typeof debug;
147
- declare const basic_ga4: typeof ga4;
148
- declare const basic_minimal: typeof minimal;
149
- declare namespace basic {
150
- export { basic_complete as complete, basic_debug as debug, basic_ga4 as ga4, basic_minimal as minimal };
151
- }
152
-
153
- export { basic, mapping$1 as mapping };
222
+ export { auth, basic, mapping$1 as mapping };
@@ -20,94 +20,87 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/examples/index.ts
21
21
  var examples_exports = {};
22
22
  __export(examples_exports, {
23
+ auth: () => auth_exports,
23
24
  basic: () => basic_exports,
24
25
  mapping: () => mapping_exports
25
26
  });
26
27
  module.exports = __toCommonJS(examples_exports);
27
28
 
28
- // src/examples/mapping.ts
29
- var mapping_exports = {};
30
- __export(mapping_exports, {
31
- Lead: () => Lead,
32
- PageView: () => PageView,
33
- Purchase: () => Purchase,
34
- mapping: () => mapping,
35
- userDataMapping: () => userDataMapping
29
+ // src/examples/auth.ts
30
+ var auth_exports = {};
31
+ __export(auth_exports, {
32
+ awsLambda: () => awsLambda,
33
+ customScopes: () => customScopes,
34
+ dockerKubernetes: () => dockerKubernetes,
35
+ gcpCloudFunctions: () => gcpCloudFunctions,
36
+ localDevelopment: () => localDevelopment
36
37
  });
37
- var import_core = require("@walkeros/core");
38
- var Purchase = {
39
- name: "purchase",
40
- data: {
41
- map: {
42
- // Required fields
43
- transactionId: "data.id",
44
- conversionValue: "data.total",
45
- currency: { key: "data.currency", value: "USD" },
46
- eventName: { value: "purchase" },
47
- // User identification
48
- userId: "user.id",
49
- email: "user.id",
50
- // Will be hashed automatically
51
- // Attribution identifiers (captured by browser source from URL)
52
- gclid: "context.gclid",
53
- // Google Click ID
54
- gbraid: "context.gbraid",
55
- // iOS attribution
56
- wbraid: "context.wbraid",
57
- // Web-to-app
58
- // Shopping cart data
59
- cartData: {
60
- map: {
61
- items: {
62
- loop: [
63
- "nested",
64
- {
65
- condition: (entity) => (0, import_core.isObject)(entity) && entity.entity === "product",
66
- map: {
67
- merchantProductId: "data.id",
68
- price: "data.price",
69
- quantity: { key: "data.quantity", value: 1 }
70
- }
71
- }
72
- ]
73
- }
74
- }
38
+ var awsLambda = {
39
+ settings: {
40
+ credentials: {
41
+ client_email: process.env.GOOGLE_CLIENT_EMAIL,
42
+ private_key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, "\n")
43
+ },
44
+ destinations: [
45
+ {
46
+ operatingAccount: {
47
+ accountId: "123-456-7890",
48
+ accountType: "GOOGLE_ADS"
49
+ },
50
+ productDestinationId: "AW-CONVERSION-123"
75
51
  }
76
- }
52
+ ]
77
53
  }
78
54
  };
79
- var Lead = {
80
- name: "generate_lead",
81
- data: {
82
- map: {
83
- eventName: { value: "generate_lead" },
84
- conversionValue: { value: 10 },
85
- currency: { value: "USD" }
86
- }
55
+ var gcpCloudFunctions = {
56
+ settings: {
57
+ // No auth config needed - ADC works automatically on GCP!
58
+ destinations: [
59
+ {
60
+ operatingAccount: {
61
+ accountId: "123-456-7890",
62
+ accountType: "GOOGLE_ADS"
63
+ },
64
+ productDestinationId: "AW-CONVERSION-123"
65
+ }
66
+ ]
87
67
  }
88
68
  };
89
- var PageView = {
90
- name: "page_view",
91
- data: {
92
- map: {
93
- eventName: { value: "page_view" }
94
- }
69
+ var localDevelopment = {
70
+ settings: {
71
+ keyFilename: "./service-account.json",
72
+ destinations: [
73
+ {
74
+ operatingAccount: {
75
+ accountId: "123-456-7890",
76
+ accountType: "GOOGLE_ADS"
77
+ },
78
+ productDestinationId: "AW-CONVERSION-123"
79
+ }
80
+ ]
95
81
  }
96
82
  };
97
- var mapping = {
98
- order: {
99
- complete: Purchase
100
- },
101
- lead: {
102
- submit: Lead
103
- },
104
- page: {
105
- view: PageView
83
+ var dockerKubernetes = {
84
+ settings: {
85
+ // No explicit config - ADC uses GOOGLE_APPLICATION_CREDENTIALS env var
86
+ destinations: [
87
+ {
88
+ operatingAccount: {
89
+ accountId: "123-456-7890",
90
+ accountType: "GOOGLE_ADS"
91
+ },
92
+ productDestinationId: "AW-CONVERSION-123"
93
+ }
94
+ ]
106
95
  }
107
96
  };
108
- var userDataMapping = {
97
+ var customScopes = {
109
98
  settings: {
110
- accessToken: "ya29.c.xxx",
99
+ credentials: {
100
+ client_email: process.env.GOOGLE_CLIENT_EMAIL,
101
+ private_key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, "\n")
102
+ },
103
+ scopes: ["https://www.googleapis.com/auth/datamanager"],
111
104
  destinations: [
112
105
  {
113
106
  operatingAccount: {
@@ -117,18 +110,7 @@ var userDataMapping = {
117
110
  productDestinationId: "AW-CONVERSION-123"
118
111
  }
119
112
  ]
120
- },
121
- data: {
122
- map: {
123
- email: "user.id",
124
- phone: "data.phone",
125
- firstName: "data.firstName",
126
- lastName: "data.lastName",
127
- regionCode: "data.country",
128
- postalCode: "data.zip"
129
- }
130
- },
131
- mapping
113
+ }
132
114
  };
133
115
 
134
116
  // src/examples/basic.ts
@@ -141,7 +123,10 @@ __export(basic_exports, {
141
123
  });
142
124
  var minimal = {
143
125
  settings: {
144
- accessToken: "ya29.c.xxx",
126
+ credentials: {
127
+ client_email: "service-account@project.iam.gserviceaccount.com",
128
+ private_key: "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
129
+ },
145
130
  destinations: [
146
131
  {
147
132
  operatingAccount: {
@@ -155,7 +140,10 @@ var minimal = {
155
140
  };
156
141
  var complete = {
157
142
  settings: {
158
- accessToken: "ya29.c.xxx",
143
+ credentials: {
144
+ client_email: "service-account@project.iam.gserviceaccount.com",
145
+ private_key: "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
146
+ },
159
147
  destinations: [
160
148
  {
161
149
  operatingAccount: {
@@ -199,7 +187,6 @@ var complete = {
199
187
  };
200
188
  var ga4 = {
201
189
  settings: {
202
- accessToken: "ya29.c.xxx",
203
190
  destinations: [
204
191
  {
205
192
  operatingAccount: {
@@ -214,7 +201,7 @@ var ga4 = {
214
201
  };
215
202
  var debug = {
216
203
  settings: {
217
- accessToken: "ya29.c.xxx",
204
+ keyFilename: "./service-account.json",
218
205
  destinations: [
219
206
  {
220
207
  operatingAccount: {
@@ -228,8 +215,115 @@ var debug = {
228
215
  // Shows all API calls and responses
229
216
  }
230
217
  };
218
+
219
+ // src/examples/mapping.ts
220
+ var mapping_exports = {};
221
+ __export(mapping_exports, {
222
+ Lead: () => Lead,
223
+ PageView: () => PageView,
224
+ Purchase: () => Purchase,
225
+ mapping: () => mapping,
226
+ userDataMapping: () => userDataMapping
227
+ });
228
+ var import_core = require("@walkeros/core");
229
+ var Purchase = {
230
+ name: "purchase",
231
+ data: {
232
+ map: {
233
+ // Required fields
234
+ transactionId: "data.id",
235
+ conversionValue: "data.total",
236
+ currency: { key: "data.currency", value: "USD" },
237
+ eventName: { value: "purchase" },
238
+ // User identification
239
+ userId: "user.id",
240
+ email: "user.id",
241
+ // Will be hashed automatically
242
+ // Attribution identifiers (captured by browser source from URL)
243
+ gclid: "context.gclid",
244
+ // Google Click ID
245
+ gbraid: "context.gbraid",
246
+ // iOS attribution
247
+ wbraid: "context.wbraid",
248
+ // Web-to-app
249
+ // Shopping cart data
250
+ cartData: {
251
+ map: {
252
+ items: {
253
+ loop: [
254
+ "nested",
255
+ {
256
+ condition: (entity) => (0, import_core.isObject)(entity) && entity.entity === "product",
257
+ map: {
258
+ merchantProductId: "data.id",
259
+ price: "data.price",
260
+ quantity: { key: "data.quantity", value: 1 }
261
+ }
262
+ }
263
+ ]
264
+ }
265
+ }
266
+ }
267
+ }
268
+ }
269
+ };
270
+ var Lead = {
271
+ name: "generate_lead",
272
+ data: {
273
+ map: {
274
+ eventName: { value: "generate_lead" },
275
+ conversionValue: { value: 10 },
276
+ currency: { value: "USD" }
277
+ }
278
+ }
279
+ };
280
+ var PageView = {
281
+ name: "page_view",
282
+ data: {
283
+ map: {
284
+ eventName: { value: "page_view" }
285
+ }
286
+ }
287
+ };
288
+ var mapping = {
289
+ order: {
290
+ complete: Purchase
291
+ },
292
+ lead: {
293
+ submit: Lead
294
+ },
295
+ page: {
296
+ view: PageView
297
+ }
298
+ };
299
+ var userDataMapping = {
300
+ settings: {
301
+ keyFilename: "./service-account.json",
302
+ destinations: [
303
+ {
304
+ operatingAccount: {
305
+ accountId: "123-456-7890",
306
+ accountType: "GOOGLE_ADS"
307
+ },
308
+ productDestinationId: "AW-CONVERSION-123"
309
+ }
310
+ ]
311
+ },
312
+ data: {
313
+ map: {
314
+ email: "user.id",
315
+ phone: "data.phone",
316
+ firstName: "data.firstName",
317
+ lastName: "data.lastName",
318
+ regionCode: "data.country",
319
+ postalCode: "data.zip"
320
+ }
321
+ },
322
+ mapping
323
+ };
231
324
  // Annotate the CommonJS export names for ESM import in node:
232
325
  0 && (module.exports = {
326
+ auth,
233
327
  basic,
234
328
  mapping
235
329
  });