@walkeros/server-destination-datamanager 0.4.0 → 0.4.2

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/README.md CHANGED
@@ -23,7 +23,7 @@ npm install @walkeros/server-destination-datamanager
23
23
 
24
24
  ## Quick Start
25
25
 
26
- ### Minimal Configuration
26
+ ### Minimal Configuration (AWS Lambda / Serverless)
27
27
 
28
28
  ```typescript
29
29
  import { destinationDataManager } from '@walkeros/server-destination-datamanager';
@@ -35,8 +35,11 @@ const { collector, elb } = await startFlow({
35
35
  ...destinationDataManager,
36
36
  config: {
37
37
  settings: {
38
- // OAuth 2.0 access token with datamanager scope
39
- accessToken: 'ya29.c.xxx',
38
+ // Service account credentials from environment variables
39
+ credentials: {
40
+ client_email: process.env.GOOGLE_CLIENT_EMAIL!,
41
+ private_key: process.env.GOOGLE_PRIVATE_KEY!.replace(/\\n/g, '\n'),
42
+ },
40
43
 
41
44
  // Destination accounts
42
45
  destinations: [
@@ -62,7 +65,36 @@ await elb('order complete', {
62
65
  });
63
66
  ```
64
67
 
65
- ### Complete Configuration
68
+ ### GCP Cloud Functions (Application Default Credentials)
69
+
70
+ ```typescript
71
+ import { destinationDataManager } from '@walkeros/server-destination-datamanager';
72
+ import { startFlow } from '@walkeros/collector';
73
+
74
+ // No auth config needed - ADC works automatically on GCP!
75
+ const { collector, elb } = await startFlow({
76
+ destinations: {
77
+ datamanager: {
78
+ ...destinationDataManager,
79
+ config: {
80
+ settings: {
81
+ destinations: [
82
+ {
83
+ operatingAccount: {
84
+ accountId: '123-456-7890',
85
+ accountType: 'GOOGLE_ADS',
86
+ },
87
+ productDestinationId: 'AW-CONVERSION-123',
88
+ },
89
+ ],
90
+ },
91
+ },
92
+ },
93
+ },
94
+ });
95
+ ```
96
+
97
+ ### Local Development
66
98
 
67
99
  ```typescript
68
100
  import { destinationDataManager } from '@walkeros/server-destination-datamanager';
@@ -71,7 +103,8 @@ const config = {
71
103
  ...destinationDataManager,
72
104
  config: {
73
105
  settings: {
74
- accessToken: 'ya29.c.xxx',
106
+ // Service account JSON file
107
+ keyFilename: './service-account.json',
75
108
 
76
109
  // Multiple destinations (max 10)
77
110
  destinations: [
@@ -136,34 +169,141 @@ const config = {
136
169
 
137
170
  ## Authentication
138
171
 
139
- ### OAuth 2.0 Setup
172
+ The Data Manager destination uses Google Cloud service accounts with automatic
173
+ token refresh. The library handles token management automatically - you just
174
+ provide credentials and tokens are cached and refreshed as needed.
175
+
176
+ ### Authentication Methods
177
+
178
+ The destination supports three authentication methods (in priority order):
179
+
180
+ 1. **Inline Credentials** - Best for serverless (AWS Lambda, Docker, K8s)
181
+ 2. **Service Account File** - Best for local development
182
+ 3. **Application Default Credentials (ADC)** - Automatic on GCP
183
+
184
+ ### 1. Inline Credentials (Recommended for Serverless)
185
+
186
+ Best for AWS Lambda, Docker, Kubernetes, and other containerized environments
187
+ where you manage secrets via environment variables.
188
+
189
+ ```typescript
190
+ import { destinationDataManager } from '@walkeros/server-destination-datamanager';
191
+
192
+ const config = {
193
+ ...destinationDataManager,
194
+ config: {
195
+ settings: {
196
+ credentials: {
197
+ client_email: process.env.GOOGLE_CLIENT_EMAIL!,
198
+ private_key: process.env.GOOGLE_PRIVATE_KEY!.replace(/\\n/g, '\n'),
199
+ },
200
+ destinations: [
201
+ /* ... */
202
+ ],
203
+ },
204
+ },
205
+ };
206
+ ```
207
+
208
+ **Environment Variables:**
209
+
210
+ ```bash
211
+ GOOGLE_CLIENT_EMAIL=service-account@project.iam.gserviceaccount.com
212
+ GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIE...\n-----END PRIVATE KEY-----\n"
213
+ ```
214
+
215
+ **Note:** Use `.replace(/\\n/g, '\n')` to convert escaped newlines from
216
+ environment variables.
217
+
218
+ ### 2. Service Account File (Local Development)
219
+
220
+ Best for local development with filesystem access.
221
+
222
+ ```typescript
223
+ const config = {
224
+ ...destinationDataManager,
225
+ config: {
226
+ settings: {
227
+ keyFilename: './service-account.json',
228
+ destinations: [
229
+ /* ... */
230
+ ],
231
+ },
232
+ },
233
+ };
234
+ ```
235
+
236
+ ### 3. Application Default Credentials (GCP)
237
+
238
+ Automatic on Google Cloud Platform - no configuration needed!
140
239
 
141
- 1. **Create a Google Cloud Project**
142
- - Go to [Google Cloud Console](https://console.cloud.google.com/)
143
- - Create a new project or select existing
240
+ ```typescript
241
+ const config = {
242
+ ...destinationDataManager,
243
+ config: {
244
+ settings: {
245
+ // No auth config needed - ADC used automatically!
246
+ destinations: [
247
+ /* ... */
248
+ ],
249
+ },
250
+ },
251
+ };
252
+ ```
253
+
254
+ **Works automatically on:**
144
255
 
145
- 2. **Enable Data Manager API**
146
- - Navigate to APIs & Services > Library
147
- - Search for "Google Data Manager API"
148
- - Click Enable
256
+ - Google Cloud Functions
257
+ - Google Cloud Run
258
+ - Google Compute Engine
259
+ - Google Kubernetes Engine
260
+ - Any GCP environment with default service account
149
261
 
150
- 3. **Create Service Account**
151
- - Go to APIs & Services > Credentials
152
- - Click "Create Credentials" > "Service Account"
153
- - Grant necessary permissions
154
- - Download JSON key file
262
+ **Also works with:**
155
263
 
156
- 4. **Get Access Token**
157
- ```bash
158
- gcloud auth application-default print-access-token --scopes=https://www.googleapis.com/auth/datamanager
159
- ```
264
+ - `GOOGLE_APPLICATION_CREDENTIALS` environment variable
265
+ - gcloud CLI: `gcloud auth application-default login`
160
266
 
161
- ### Required Scope
267
+ ### Creating a Service Account
268
+
269
+ 1. Go to [Google Cloud Console](https://console.cloud.google.com/)
270
+ 2. Navigate to **IAM & Admin > Service Accounts**
271
+ 3. Click **Create Service Account**
272
+ 4. Name: `walkeros-datamanager` (or your choice)
273
+ 5. Grant role: **Data Manager Admin** or custom role with datamanager
274
+ permissions
275
+ 6. Click **Keys > Add Key > Create New Key**
276
+ 7. Select **JSON** format and download
277
+
278
+ **For inline credentials:**
279
+
280
+ - Extract `client_email` and `private_key` from the JSON
281
+ - Store in environment variables or secrets manager
282
+
283
+ **For keyFilename:**
284
+
285
+ - Set `keyFilename: '/path/to/downloaded-key.json'`
286
+
287
+ **For ADC:**
288
+
289
+ - Set `GOOGLE_APPLICATION_CREDENTIALS=/path/to/downloaded-key.json`
290
+ - Or deploy to GCP where ADC works automatically
291
+
292
+ ### Required OAuth Scope
162
293
 
163
294
  ```
164
295
  https://www.googleapis.com/auth/datamanager
165
296
  ```
166
297
 
298
+ This scope is automatically applied - no configuration needed.
299
+
300
+ ### Token Management
301
+
302
+ - **Lifetime:** 1 hour (3600 seconds)
303
+ - **Refresh:** Automatic - library handles expiration
304
+ - **Caching:** Tokens are cached and reused until expiration
305
+ - **Performance:** ~10-50ms overhead per request for token validation
306
+
167
307
  ## Guided Mapping Helpers
168
308
 
169
309
  Define common fields once in Settings instead of repeating them in every event
@@ -172,7 +312,7 @@ mapping:
172
312
  ```typescript
173
313
  {
174
314
  settings: {
175
- accessToken: 'ya29.c.xxx',
315
+ credentials: { /* ... */ },
176
316
  destinations: [...],
177
317
 
178
318
  // Guided helpers (apply to all events)
@@ -616,23 +756,28 @@ be rejected.
616
756
 
617
757
  ### Settings
618
758
 
619
- | Property | Type | Required | Description |
620
- | -------------------------- | -------------- | -------- | ------------------------------------------- |
621
- | `accessToken` | string | | OAuth 2.0 access token |
622
- | `destinations` | Destination[] | | Array of destination accounts (max 10) |
623
- | `eventSource` | EventSource | | Default event source (WEB, APP, etc.) |
624
- | `batchSize` | number | | Max events per batch (max 2000) |
625
- | `batchInterval` | number | | Batch flush interval in ms |
626
- | `validateOnly` | boolean | | Validate without ingestion |
627
- | `url` | string | | Override API endpoint |
628
- | `consent` | Consent | | Request-level consent |
629
- | `testEventCode` | string | | Test event code for debugging |
630
- | `userData` | object | | Guided helper: User data mapping |
631
- | `userId` | string | | Guided helper: First-party user ID |
632
- | `clientId` | string | | Guided helper: GA4 client ID |
633
- | `sessionAttributes` | string | | Guided helper: Privacy-safe attribution |
634
- | `consentAdUserData` | string/boolean | | Consent mapping: Field name or static value |
635
- | `consentAdPersonalization` | string/boolean | | Consent mapping: Field name or static value |
759
+ | Property | Type | Required | Description |
760
+ | -------------------------- | -------------- | -------- | -------------------------------------------- |
761
+ | `credentials` | object | \* | Service account (client_email + private_key) |
762
+ | `keyFilename` | string | \* | Path to service account JSON file |
763
+ | `scopes` | string[] | | OAuth scopes (default: datamanager scope) |
764
+ | `destinations` | Destination[] || Array of destination accounts (max 10) |
765
+ | `eventSource` | EventSource | | Default event source (WEB, APP, etc.) |
766
+ | `batchSize` | number | | Max events per batch (max 2000) |
767
+ | `batchInterval` | number | | Batch flush interval in ms |
768
+ | `validateOnly` | boolean | | Validate without ingestion |
769
+ | `url` | string | | Override API endpoint |
770
+ | `consent` | Consent | | Request-level consent |
771
+ | `testEventCode` | string | | Test event code for debugging |
772
+ | `userData` | object | | Guided helper: User data mapping |
773
+ | `userId` | string | | Guided helper: First-party user ID |
774
+ | `clientId` | string | | Guided helper: GA4 client ID |
775
+ | `sessionAttributes` | string | | Guided helper: Privacy-safe attribution |
776
+ | `consentAdUserData` | string/boolean | | Consent mapping: Field name or static value |
777
+ | `consentAdPersonalization` | string/boolean | | Consent mapping: Field name or static value |
778
+
779
+ **\* One of `credentials`, `keyFilename`, or ADC (automatic) required for
780
+ authentication**
636
781
 
637
782
  ### Event Fields
638
783
 
package/dist/dev.d.mts CHANGED
@@ -1,21 +1,38 @@
1
- import { JSONSchema } from '@walkeros/core/dev';
1
+ import * as _walkeros_core_dev from '@walkeros/core/dev';
2
2
  import { Mapping as Mapping$1, Destination as Destination$1 } from '@walkeros/core';
3
3
  import { DestinationServer } from '@walkeros/server-core';
4
+ import { OAuth2Client } from 'google-auth-library';
4
5
 
5
- declare const schemas$1: Record<string, JSONSchema>;
6
+ declare const settings: _walkeros_core_dev.JSONSchema;
7
+ declare const mapping$2: _walkeros_core_dev.JSONSchema;
6
8
 
9
+ declare const schemas_settings: typeof settings;
7
10
  declare namespace schemas {
8
- export { schemas$1 as schemas };
11
+ export { mapping$2 as mapping, schemas_settings as settings };
9
12
  }
10
13
 
11
- type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';
12
-
13
14
  interface Settings {
14
- /** OAuth 2.0 access token with datamanager scope */
15
- accessToken: string;
15
+ /**
16
+ * Service account credentials (client_email + private_key)
17
+ * Recommended for serverless environments (AWS Lambda, Docker, etc.)
18
+ */
19
+ credentials?: {
20
+ client_email: string;
21
+ private_key: string;
22
+ };
23
+ /**
24
+ * Path to service account JSON file
25
+ * For local development or environments with filesystem access
26
+ */
27
+ keyFilename?: string;
28
+ /**
29
+ * OAuth scopes for Data Manager API
30
+ * @default ['https://www.googleapis.com/auth/datamanager']
31
+ */
32
+ scopes?: string[];
16
33
  /** Array of destination accounts and conversion actions/user lists */
17
34
  destinations: Destination[];
18
- /** Default event source if not specified per event */
35
+ /** Event source for all events. Defaults to WEB if not specified */
19
36
  eventSource?: EventSource;
20
37
  /** Maximum number of events to batch before sending (max 2000) */
21
38
  batchSize?: number;
@@ -29,8 +46,6 @@ interface Settings {
29
46
  consent?: Consent;
30
47
  /** Test event code for debugging (optional) */
31
48
  testEventCode?: string;
32
- /** Log level for debugging (optional) */
33
- logLevel?: LogLevel;
34
49
  /** Guided helpers: User data mapping (applies to all events) */
35
50
  userData?: Mapping$1.Map;
36
51
  /** Guided helper: First-party user ID */
@@ -52,8 +67,10 @@ interface Mapping {
52
67
  }
53
68
  interface Env extends DestinationServer.Env {
54
69
  fetch?: typeof fetch;
70
+ authClient?: OAuth2Client | null;
55
71
  }
56
- type Types = Destination$1.Types<Settings, Mapping, Env>;
72
+ type InitSettings = Partial<Settings>;
73
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
57
74
  type Config = {
58
75
  settings: Settings;
59
76
  } & DestinationServer.Config<Types>;
@@ -63,21 +80,27 @@ type Rule = Mapping$1.Rule<Mapping>;
63
80
  * https://developers.google.com/data-manager/api/reference/rest/v1/Destination
64
81
  */
65
82
  interface Destination {
66
- /** Operating account details */
67
- operatingAccount: OperatingAccount;
83
+ /** Reference identifier for this destination */
84
+ reference?: string;
85
+ /** Login account (account initiating the request) */
86
+ loginAccount?: ProductAccount;
87
+ /** Linked account (child account linked to login account) */
88
+ linkedAccount?: ProductAccount;
89
+ /** Operating account (account where data is sent) */
90
+ operatingAccount?: ProductAccount;
68
91
  /** Product-specific destination ID (conversion action or user list) */
69
- productDestinationId: string;
92
+ productDestinationId?: string;
70
93
  }
71
94
  /**
72
- * Operating account information
95
+ * Product account information
73
96
  */
74
- interface OperatingAccount {
97
+ interface ProductAccount {
75
98
  /** Account ID (e.g., "123-456-7890" for Google Ads) */
76
99
  accountId: string;
77
100
  /** Type of account */
78
101
  accountType: AccountType;
79
102
  }
80
- type AccountType = 'GOOGLE_ADS' | 'DISPLAY_VIDEO_ADVERTISER' | 'DISPLAY_VIDEO_PARTNER' | 'GOOGLE_ANALYTICS_PROPERTY';
103
+ type AccountType = 'ACCOUNT_TYPE_UNSPECIFIED' | 'GOOGLE_ADS' | 'DISPLAY_VIDEO_ADVERTISER' | 'DISPLAY_VIDEO_PARTNER' | 'GOOGLE_ANALYTICS_PROPERTY' | 'DATA_PARTNER';
81
104
  type EventSource = 'WEB' | 'APP' | 'IN_STORE' | 'PHONE' | 'OTHER';
82
105
  /**
83
106
  * Consent for Digital Markets Act (DMA) compliance
@@ -91,6 +114,75 @@ interface Consent {
91
114
  }
92
115
  type ConsentStatus = 'CONSENT_GRANTED' | 'CONSENT_DENIED';
93
116
 
117
+ /**
118
+ * AWS Lambda / Serverless Configuration
119
+ * Uses inline credentials from environment variables
120
+ * Best for: AWS Lambda, Docker, Kubernetes, any serverless environment
121
+ */
122
+ declare const awsLambda: Config;
123
+ /**
124
+ * GCP Cloud Functions / Cloud Run Configuration
125
+ * Uses Application Default Credentials (ADC) - no explicit auth config needed
126
+ * Best for: Google Cloud Functions, Cloud Run, GCE, GKE
127
+ */
128
+ declare const gcpCloudFunctions: Config;
129
+ /**
130
+ * Local Development Configuration
131
+ * Uses service account JSON file
132
+ * Best for: Local development, testing
133
+ */
134
+ declare const localDevelopment: Config;
135
+ /**
136
+ * Docker / Kubernetes Configuration
137
+ * Uses ADC via GOOGLE_APPLICATION_CREDENTIALS environment variable
138
+ * Best for: Docker containers, Kubernetes pods
139
+ *
140
+ * Setup:
141
+ * 1. Mount service account JSON as secret/configmap
142
+ * 2. Set GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
143
+ * 3. ADC will automatically use it
144
+ */
145
+ declare const dockerKubernetes: Config;
146
+ /**
147
+ * Custom Scopes Configuration
148
+ * For specific use cases requiring different OAuth scopes
149
+ */
150
+ declare const customScopes: Config;
151
+
152
+ declare const auth_awsLambda: typeof awsLambda;
153
+ declare const auth_customScopes: typeof customScopes;
154
+ declare const auth_dockerKubernetes: typeof dockerKubernetes;
155
+ declare const auth_gcpCloudFunctions: typeof gcpCloudFunctions;
156
+ declare const auth_localDevelopment: typeof localDevelopment;
157
+ declare namespace auth {
158
+ export { auth_awsLambda as awsLambda, auth_customScopes as customScopes, auth_dockerKubernetes as dockerKubernetes, auth_gcpCloudFunctions as gcpCloudFunctions, auth_localDevelopment as localDevelopment };
159
+ }
160
+
161
+ /**
162
+ * Minimal configuration for Google Data Manager with inline credentials
163
+ */
164
+ declare const minimal: Config;
165
+ /**
166
+ * Complete configuration with all options
167
+ */
168
+ declare const complete: Config;
169
+ /**
170
+ * GA4-specific configuration using Application Default Credentials
171
+ */
172
+ declare const ga4: Config;
173
+ /**
174
+ * Debug configuration with logging enabled using keyFilename
175
+ */
176
+ declare const debug: Config;
177
+
178
+ declare const basic_complete: typeof complete;
179
+ declare const basic_debug: typeof debug;
180
+ declare const basic_ga4: typeof ga4;
181
+ declare const basic_minimal: typeof minimal;
182
+ declare namespace basic {
183
+ export { basic_complete as complete, basic_debug as debug, basic_ga4 as ga4, basic_minimal as minimal };
184
+ }
185
+
94
186
  /**
95
187
  * Purchase event mapping for Google Ads conversion
96
188
  */
@@ -132,34 +224,10 @@ declare namespace mapping$1 {
132
224
  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 };
133
225
  }
134
226
 
135
- /**
136
- * Minimal configuration for Google Data Manager
137
- */
138
- declare const minimal: Config;
139
- /**
140
- * Complete configuration with all options
141
- */
142
- declare const complete: Config;
143
- /**
144
- * GA4-specific configuration
145
- */
146
- declare const ga4: Config;
147
- /**
148
- * Debug configuration with logging enabled
149
- */
150
- declare const debug: Config;
151
-
152
- declare const basic_complete: typeof complete;
153
- declare const basic_debug: typeof debug;
154
- declare const basic_ga4: typeof ga4;
155
- declare const basic_minimal: typeof minimal;
156
- declare namespace basic {
157
- export { basic_complete as complete, basic_debug as debug, basic_ga4 as ga4, basic_minimal as minimal };
158
- }
159
-
227
+ declare const index_auth: typeof auth;
160
228
  declare const index_basic: typeof basic;
161
229
  declare namespace index {
162
- export { index_basic as basic, mapping$1 as mapping };
230
+ export { index_auth as auth, index_basic as basic, mapping$1 as mapping };
163
231
  }
164
232
 
165
233
  export { index as examples, schemas };