@walkeros/server-destination-datamanager 0.3.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.
@@ -0,0 +1,213 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
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
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
+ }
54
+ }
55
+ }
56
+ }
57
+ };
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
+ }
66
+ }
67
+ };
68
+ var PageView = {
69
+ name: "page_view",
70
+ data: {
71
+ map: {
72
+ eventName: { value: "page_view" }
73
+ }
74
+ }
75
+ };
76
+ var mapping = {
77
+ order: {
78
+ complete: Purchase
79
+ },
80
+ lead: {
81
+ submit: Lead
82
+ },
83
+ page: {
84
+ view: PageView
85
+ }
86
+ };
87
+ var userDataMapping = {
88
+ settings: {
89
+ accessToken: "ya29.c.xxx",
90
+ destinations: [
91
+ {
92
+ operatingAccount: {
93
+ accountId: "123-456-7890",
94
+ accountType: "GOOGLE_ADS"
95
+ },
96
+ productDestinationId: "AW-CONVERSION-123"
97
+ }
98
+ ]
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
111
+ };
112
+
113
+ // src/examples/basic.ts
114
+ var basic_exports = {};
115
+ __export(basic_exports, {
116
+ complete: () => complete,
117
+ debug: () => debug,
118
+ ga4: () => ga4,
119
+ minimal: () => minimal
120
+ });
121
+ var minimal = {
122
+ settings: {
123
+ accessToken: "ya29.c.xxx",
124
+ destinations: [
125
+ {
126
+ operatingAccount: {
127
+ accountId: "123-456-7890",
128
+ accountType: "GOOGLE_ADS"
129
+ },
130
+ productDestinationId: "AW-CONVERSION-123"
131
+ }
132
+ ]
133
+ }
134
+ };
135
+ var complete = {
136
+ settings: {
137
+ accessToken: "ya29.c.xxx",
138
+ destinations: [
139
+ {
140
+ operatingAccount: {
141
+ accountId: "123-456-7890",
142
+ accountType: "GOOGLE_ADS"
143
+ },
144
+ productDestinationId: "AW-CONVERSION-123"
145
+ },
146
+ {
147
+ operatingAccount: {
148
+ accountId: "987654321",
149
+ accountType: "GOOGLE_ANALYTICS_PROPERTY"
150
+ },
151
+ productDestinationId: "G-XXXXXXXXXX"
152
+ }
153
+ ],
154
+ eventSource: "WEB",
155
+ batchSize: 100,
156
+ batchInterval: 5e3,
157
+ validateOnly: false,
158
+ consent: {
159
+ adUserData: "CONSENT_GRANTED",
160
+ adPersonalization: "CONSENT_GRANTED"
161
+ },
162
+ // Guided helpers (apply to all events)
163
+ userData: {
164
+ email: "user.id",
165
+ phone: "data.phone",
166
+ firstName: "data.firstName",
167
+ lastName: "data.lastName"
168
+ },
169
+ userId: "user.id",
170
+ clientId: "user.device",
171
+ sessionAttributes: "context.sessionAttributes"
172
+ },
173
+ data: {
174
+ map: {
175
+ eventSource: { value: "WEB" }
176
+ }
177
+ }
178
+ };
179
+ var ga4 = {
180
+ settings: {
181
+ accessToken: "ya29.c.xxx",
182
+ destinations: [
183
+ {
184
+ operatingAccount: {
185
+ accountId: "123456789",
186
+ accountType: "GOOGLE_ANALYTICS_PROPERTY"
187
+ },
188
+ productDestinationId: "G-XXXXXXXXXX"
189
+ }
190
+ ],
191
+ eventSource: "WEB"
192
+ }
193
+ };
194
+ var debug = {
195
+ settings: {
196
+ accessToken: "ya29.c.xxx",
197
+ destinations: [
198
+ {
199
+ operatingAccount: {
200
+ accountId: "123-456-7890",
201
+ accountType: "GOOGLE_ADS"
202
+ },
203
+ productDestinationId: "AW-CONVERSION-123"
204
+ }
205
+ ],
206
+ logLevel: "debug"
207
+ // Shows all API calls and responses
208
+ }
209
+ };
210
+ export {
211
+ basic_exports as basic,
212
+ mapping_exports as mapping
213
+ };
@@ -0,0 +1,372 @@
1
+ import { Destination as Destination$1, Mapping as Mapping$1, JSONSchema } from '@walkeros/core';
2
+ import { DestinationServer } from '@walkeros/server-core';
3
+
4
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';
5
+
6
+ interface Settings {
7
+ /** OAuth 2.0 access token with datamanager scope */
8
+ accessToken: string;
9
+ /** Array of destination accounts and conversion actions/user lists */
10
+ destinations: Destination[];
11
+ /** Default event source if not specified per event */
12
+ eventSource?: EventSource;
13
+ /** Maximum number of events to batch before sending (max 2000) */
14
+ batchSize?: number;
15
+ /** Time in milliseconds to wait before auto-flushing batch */
16
+ batchInterval?: number;
17
+ /** If true, validate request without ingestion (testing mode) */
18
+ validateOnly?: boolean;
19
+ /** Override API endpoint (for testing) */
20
+ url?: string;
21
+ /** Request-level consent for all events */
22
+ consent?: Consent;
23
+ /** Test event code for debugging (optional) */
24
+ testEventCode?: string;
25
+ /** Log level for debugging (optional) */
26
+ logLevel?: LogLevel;
27
+ /** Guided helpers: User data mapping (applies to all events) */
28
+ userData?: Mapping$1.Map;
29
+ /** Guided helper: First-party user ID */
30
+ userId?: Mapping$1.Value;
31
+ /** Guided helper: GA4 client ID */
32
+ clientId?: Mapping$1.Value;
33
+ /** Guided helper: Privacy-safe attribution (Google's sessionAttributes) */
34
+ sessionAttributes?: Mapping$1.Value;
35
+ /** Consent mapping: Map consent field to adUserData (string = field name, boolean = static value) */
36
+ consentAdUserData?: string | boolean;
37
+ /** Consent mapping: Map consent field to adPersonalization (string = field name, boolean = static value) */
38
+ consentAdPersonalization?: string | boolean;
39
+ }
40
+ interface Mapping {
41
+ gclid?: Mapping$1.Value;
42
+ gbraid?: Mapping$1.Value;
43
+ wbraid?: Mapping$1.Value;
44
+ sessionAttributes?: Mapping$1.Value;
45
+ }
46
+ interface Env extends DestinationServer.Env {
47
+ fetch?: typeof fetch;
48
+ }
49
+ type Types = Destination$1.Types<Settings, Mapping, Env>;
50
+ interface DestinationInterface extends DestinationServer.Destination<Types> {
51
+ init: DestinationServer.InitFn<Types>;
52
+ }
53
+ type Config = {
54
+ settings: Settings;
55
+ } & DestinationServer.Config<Types>;
56
+ type InitFn = DestinationServer.InitFn<Types>;
57
+ type PushFn = DestinationServer.PushFn<Types>;
58
+ type PartialConfig = DestinationServer.PartialConfig<Types>;
59
+ type PushEvents = DestinationServer.PushEvents<Mapping>;
60
+ type Rule = Mapping$1.Rule<Mapping>;
61
+ type Rules = Mapping$1.Rules<Rule>;
62
+ /**
63
+ * Destination account and product identifier
64
+ * https://developers.google.com/data-manager/api/reference/rest/v1/Destination
65
+ */
66
+ interface Destination {
67
+ /** Operating account details */
68
+ operatingAccount: OperatingAccount;
69
+ /** Product-specific destination ID (conversion action or user list) */
70
+ productDestinationId: string;
71
+ }
72
+ /**
73
+ * Operating account information
74
+ */
75
+ interface OperatingAccount {
76
+ /** Account ID (e.g., "123-456-7890" for Google Ads) */
77
+ accountId: string;
78
+ /** Type of account */
79
+ accountType: AccountType;
80
+ }
81
+ type AccountType = 'GOOGLE_ADS' | 'DISPLAY_VIDEO_ADVERTISER' | 'DISPLAY_VIDEO_PARTNER' | 'GOOGLE_ANALYTICS_PROPERTY';
82
+ type EventSource = 'WEB' | 'APP' | 'IN_STORE' | 'PHONE' | 'OTHER';
83
+ /**
84
+ * Consent for Digital Markets Act (DMA) compliance
85
+ * https://developers.google.com/data-manager/api/devguides/concepts/dma
86
+ */
87
+ interface Consent {
88
+ /** Consent for data collection and use */
89
+ adUserData?: ConsentStatus;
90
+ /** Consent for ad personalization */
91
+ adPersonalization?: ConsentStatus;
92
+ }
93
+ type ConsentStatus = 'CONSENT_GRANTED' | 'CONSENT_DENIED';
94
+ /**
95
+ * Request body for events.ingest API
96
+ * https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest
97
+ */
98
+ interface IngestEventsRequest {
99
+ /** OAuth 2.0 access token */
100
+ access_token?: string;
101
+ /** Array of events to ingest (max 2000) */
102
+ events: Event[];
103
+ /** Array of destinations for these events (max 10) */
104
+ destinations: Destination[];
105
+ /** Request-level consent (overridden by event-level) */
106
+ consent?: Consent;
107
+ /** If true, validate without ingestion */
108
+ validateOnly?: boolean;
109
+ /** Test event code for debugging */
110
+ testEventCode?: string;
111
+ }
112
+ /**
113
+ * Single event for ingestion
114
+ * https://developers.google.com/data-manager/api/reference/rest/v1/Event
115
+ */
116
+ interface Event {
117
+ /** Event timestamp in RFC 3339 format */
118
+ eventTimestamp: string;
119
+ /** Transaction ID for deduplication (max 512 chars) */
120
+ transactionId?: string;
121
+ /** Google Analytics client ID (max 255 chars) */
122
+ clientId?: string;
123
+ /** First-party user ID (max 256 chars) */
124
+ userId?: string;
125
+ /** User data with identifiers (max 10 identifiers) */
126
+ userData?: UserData;
127
+ /** Attribution identifiers */
128
+ adIdentifiers?: AdIdentifiers;
129
+ /** Conversion value */
130
+ conversionValue?: number;
131
+ /** Currency code (ISO 4217, 3 chars) */
132
+ currency?: string;
133
+ /** Shopping cart data */
134
+ cartData?: CartData;
135
+ /** Event name for GA4 (max 40 chars, required for GA4) */
136
+ eventName?: string;
137
+ /** Source of the event */
138
+ eventSource?: EventSource;
139
+ /** Event-level consent (overrides request-level) */
140
+ consent?: Consent;
141
+ }
142
+ /**
143
+ * User data with identifiers
144
+ * https://developers.google.com/data-manager/api/reference/rest/v1/UserData
145
+ */
146
+ interface UserData {
147
+ /** Array of user identifiers (max 10) */
148
+ userIdentifiers: UserIdentifier[];
149
+ }
150
+ /**
151
+ * User identifier (email, phone, or address)
152
+ */
153
+ type UserIdentifier = {
154
+ emailAddress: string;
155
+ } | {
156
+ phoneNumber: string;
157
+ } | {
158
+ address: Address;
159
+ };
160
+ /**
161
+ * Address for user identification
162
+ * https://developers.google.com/data-manager/api/reference/rest/v1/Address
163
+ */
164
+ interface Address {
165
+ /** Given name (first name) - SHA-256 hashed */
166
+ givenName?: string;
167
+ /** Family name (last name) - SHA-256 hashed */
168
+ familyName?: string;
169
+ /** ISO-3166-1 alpha-2 country code - NOT hashed (e.g., "US", "GB") */
170
+ regionCode?: string;
171
+ /** Postal code - NOT hashed */
172
+ postalCode?: string;
173
+ }
174
+ /**
175
+ * Attribution identifiers
176
+ * https://developers.google.com/data-manager/api/reference/rest/v1/AdIdentifiers
177
+ */
178
+ interface AdIdentifiers {
179
+ /** Google Click ID (primary attribution) */
180
+ gclid?: string;
181
+ /** iOS attribution identifier (post-ATT) */
182
+ gbraid?: string;
183
+ /** Web-to-app attribution identifier */
184
+ wbraid?: string;
185
+ /** Session attributes (privacy-safe attribution) */
186
+ sessionAttributes?: string;
187
+ }
188
+ /**
189
+ * Shopping cart data
190
+ * https://developers.google.com/data-manager/api/reference/rest/v1/CartData
191
+ */
192
+ interface CartData {
193
+ /** Array of cart items (max 200) */
194
+ items: CartItem[];
195
+ }
196
+ /**
197
+ * Single cart item
198
+ * https://developers.google.com/data-manager/api/reference/rest/v1/CartItem
199
+ */
200
+ interface CartItem {
201
+ /** Merchant product ID (max 127 chars) */
202
+ merchantProductId?: string;
203
+ /** Item price */
204
+ price?: number;
205
+ /** Item quantity */
206
+ quantity?: number;
207
+ }
208
+ /**
209
+ * Response from events.ingest API
210
+ * https://developers.google.com/data-manager/api/reference/rest/v1/IngestEventsResponse
211
+ */
212
+ interface IngestEventsResponse {
213
+ /** Unique request ID for status checking */
214
+ requestId: string;
215
+ /** Validation errors (only if validateOnly=true) */
216
+ validationErrors?: ValidationError[];
217
+ }
218
+ /**
219
+ * Validation error
220
+ */
221
+ interface ValidationError {
222
+ /** Error code */
223
+ code: string;
224
+ /** Human-readable error message */
225
+ message: string;
226
+ /** Field path that caused the error */
227
+ fieldPath?: string;
228
+ }
229
+ /**
230
+ * Request status response
231
+ * https://developers.google.com/data-manager/api/reference/rest/v1/requestStatus/retrieve
232
+ */
233
+ interface RequestStatusResponse {
234
+ /** Unique request ID */
235
+ requestId: string;
236
+ /** Processing state */
237
+ state: RequestState;
238
+ /** Number of events successfully ingested */
239
+ eventsIngested?: number;
240
+ /** Number of events that failed */
241
+ eventsFailed?: number;
242
+ /** Array of errors (if any) */
243
+ errors?: RequestError[];
244
+ }
245
+ type RequestState = 'STATE_UNSPECIFIED' | 'PENDING' | 'PROCESSING' | 'SUCCEEDED' | 'FAILED' | 'PARTIALLY_SUCCEEDED';
246
+ /**
247
+ * Request error
248
+ */
249
+ interface RequestError {
250
+ /** Error code */
251
+ code: string;
252
+ /** Human-readable error message */
253
+ message: string;
254
+ /** Number of events affected by this error */
255
+ eventCount?: number;
256
+ }
257
+
258
+ type index$1_AccountType = AccountType;
259
+ type index$1_AdIdentifiers = AdIdentifiers;
260
+ type index$1_Address = Address;
261
+ type index$1_CartData = CartData;
262
+ type index$1_CartItem = CartItem;
263
+ type index$1_Config = Config;
264
+ type index$1_Consent = Consent;
265
+ type index$1_ConsentStatus = ConsentStatus;
266
+ type index$1_Destination = Destination;
267
+ type index$1_DestinationInterface = DestinationInterface;
268
+ type index$1_Env = Env;
269
+ type index$1_Event = Event;
270
+ type index$1_EventSource = EventSource;
271
+ type index$1_IngestEventsRequest = IngestEventsRequest;
272
+ type index$1_IngestEventsResponse = IngestEventsResponse;
273
+ type index$1_InitFn = InitFn;
274
+ type index$1_Mapping = Mapping;
275
+ type index$1_OperatingAccount = OperatingAccount;
276
+ type index$1_PartialConfig = PartialConfig;
277
+ type index$1_PushEvents = PushEvents;
278
+ type index$1_PushFn = PushFn;
279
+ type index$1_RequestError = RequestError;
280
+ type index$1_RequestState = RequestState;
281
+ type index$1_RequestStatusResponse = RequestStatusResponse;
282
+ type index$1_Rule = Rule;
283
+ type index$1_Rules = Rules;
284
+ type index$1_Settings = Settings;
285
+ type index$1_Types = Types;
286
+ type index$1_UserData = UserData;
287
+ type index$1_UserIdentifier = UserIdentifier;
288
+ type index$1_ValidationError = ValidationError;
289
+ declare namespace index$1 {
290
+ export type { index$1_AccountType as AccountType, index$1_AdIdentifiers as AdIdentifiers, index$1_Address as Address, index$1_CartData as CartData, index$1_CartItem as CartItem, index$1_Config as Config, index$1_Consent as Consent, index$1_ConsentStatus as ConsentStatus, index$1_Destination as Destination, index$1_DestinationInterface as DestinationInterface, index$1_Env as Env, index$1_Event as Event, index$1_EventSource as EventSource, index$1_IngestEventsRequest as IngestEventsRequest, index$1_IngestEventsResponse as IngestEventsResponse, index$1_InitFn as InitFn, index$1_Mapping as Mapping, index$1_OperatingAccount as OperatingAccount, index$1_PartialConfig as PartialConfig, index$1_PushEvents as PushEvents, index$1_PushFn as PushFn, index$1_RequestError as RequestError, index$1_RequestState as RequestState, index$1_RequestStatusResponse as RequestStatusResponse, index$1_Rule as Rule, index$1_Rules as Rules, index$1_Settings as Settings, index$1_Types as Types, index$1_UserData as UserData, index$1_UserIdentifier as UserIdentifier, index$1_ValidationError as ValidationError };
291
+ }
292
+
293
+ /**
294
+ * Purchase event mapping for Google Ads conversion
295
+ */
296
+ declare const Purchase: Rule;
297
+ /**
298
+ * Lead event mapping
299
+ */
300
+ declare const Lead: Rule;
301
+ /**
302
+ * Page view mapping for GA4
303
+ */
304
+ declare const PageView: Rule;
305
+ /**
306
+ * Complete mapping configuration
307
+ */
308
+ declare const mapping: {
309
+ order: {
310
+ complete: Rule;
311
+ };
312
+ lead: {
313
+ submit: Rule;
314
+ };
315
+ page: {
316
+ view: Rule;
317
+ };
318
+ };
319
+ /**
320
+ * User data mapping configuration
321
+ * Maps walkerOS user properties to Data Manager user identifiers
322
+ */
323
+ declare const userDataMapping: Config;
324
+
325
+ declare const mapping$1_Lead: typeof Lead;
326
+ declare const mapping$1_PageView: typeof PageView;
327
+ declare const mapping$1_Purchase: typeof Purchase;
328
+ declare const mapping$1_mapping: typeof mapping;
329
+ declare const mapping$1_userDataMapping: typeof userDataMapping;
330
+ declare namespace mapping$1 {
331
+ 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 };
332
+ }
333
+
334
+ /**
335
+ * Minimal configuration for Google Data Manager
336
+ */
337
+ declare const minimal: Config;
338
+ /**
339
+ * Complete configuration with all options
340
+ */
341
+ declare const complete: Config;
342
+ /**
343
+ * GA4-specific configuration
344
+ */
345
+ declare const ga4: Config;
346
+ /**
347
+ * Debug configuration with logging enabled
348
+ */
349
+ declare const debug: Config;
350
+
351
+ declare const basic_complete: typeof complete;
352
+ declare const basic_debug: typeof debug;
353
+ declare const basic_ga4: typeof ga4;
354
+ declare const basic_minimal: typeof minimal;
355
+ declare namespace basic {
356
+ export { basic_complete as complete, basic_debug as debug, basic_ga4 as ga4, basic_minimal as minimal };
357
+ }
358
+
359
+ declare const index_basic: typeof basic;
360
+ declare namespace index {
361
+ export { index_basic as basic, mapping$1 as mapping };
362
+ }
363
+
364
+ declare const schemas$1: Record<string, JSONSchema>;
365
+
366
+ declare namespace schemas {
367
+ export { schemas$1 as schemas };
368
+ }
369
+
370
+ declare const destinationDataManager: DestinationInterface;
371
+
372
+ export { index$1 as DestinationDataManager, destinationDataManager as default, destinationDataManager, index as examples, schemas };