@walkeros/server-destination-meta 0.3.1 → 0.4.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.d.mts CHANGED
@@ -1,34 +1,33 @@
1
- import * as _walkeros_core from '@walkeros/core';
2
- import { Destination as Destination$1, Mapping as Mapping$2, z } from '@walkeros/core';
1
+ import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
3
2
  import { DestinationServer, sendServer } from '@walkeros/server-core';
4
3
 
5
- interface Settings$1 {
4
+ interface Settings {
6
5
  accessToken: string;
7
6
  pixelId: string;
8
7
  action_source?: ActionSource;
9
8
  doNotHash?: string[];
10
9
  test_event_code?: string;
11
10
  url?: string;
12
- user_data?: Mapping$2.Map;
11
+ user_data?: Mapping$1.Map;
13
12
  }
14
- interface Mapping$1 {
13
+ interface Mapping {
15
14
  }
16
15
  interface Env extends DestinationServer.Env {
17
16
  sendServer?: typeof sendServer;
18
17
  }
19
- type Types = Destination$1.Types<Settings$1, Mapping$1, Env>;
18
+ type Types = Destination$1.Types<Settings, Mapping, Env>;
20
19
  interface Destination extends DestinationServer.Destination<Types> {
21
20
  init: DestinationServer.InitFn<Types>;
22
21
  }
23
22
  type Config = {
24
- settings: Settings$1;
23
+ settings: Settings;
25
24
  } & DestinationServer.Config<Types>;
26
25
  type InitFn = DestinationServer.InitFn<Types>;
27
26
  type PushFn = DestinationServer.PushFn<Types>;
28
27
  type PartialConfig = DestinationServer.PartialConfig<Types>;
29
- type PushEvents = DestinationServer.PushEvents<Mapping$1>;
30
- type Rule = Mapping$2.Rule<Mapping$1>;
31
- type Rules = Mapping$2.Rules<Rule>;
28
+ type PushEvents = DestinationServer.PushEvents<Mapping>;
29
+ type Rule = Mapping$1.Rule<Mapping>;
30
+ type Rules = Mapping$1.Rules<Rule>;
32
31
  interface BodyParameters {
33
32
  data: Array<ServerEventParameters>;
34
33
  test_event_code?: string;
@@ -286,156 +285,32 @@ interface OriginalEventDataParameters {
286
285
  event_id?: string;
287
286
  }
288
287
 
289
- type index$2_ActionSource = ActionSource;
290
- type index$2_AppData = AppData;
291
- type index$2_BodyParameters = BodyParameters;
292
- type index$2_Config = Config;
293
- type index$2_CustomerInformationParameters = CustomerInformationParameters;
294
- type index$2_CustomerSegmentation = CustomerSegmentation;
295
- type index$2_DataProcessingOption = DataProcessingOption;
296
- type index$2_Destination = Destination;
297
- type index$2_Env = Env;
298
- type index$2_EventName = EventName;
299
- type index$2_InitFn = InitFn;
300
- type index$2_OriginalEventDataParameters = OriginalEventDataParameters;
301
- type index$2_PartialConfig = PartialConfig;
302
- type index$2_PushEvents = PushEvents;
303
- type index$2_PushFn = PushFn;
304
- type index$2_Rule = Rule;
305
- type index$2_Rules = Rules;
306
- type index$2_ServerEventParameters = ServerEventParameters;
307
- type index$2_StandardParameters = StandardParameters;
308
- type index$2_Types = Types;
309
- declare namespace index$2 {
310
- export type { index$2_ActionSource as ActionSource, index$2_AppData as AppData, index$2_BodyParameters as BodyParameters, index$2_Config as Config, index$2_CustomerInformationParameters as CustomerInformationParameters, index$2_CustomerSegmentation as CustomerSegmentation, index$2_DataProcessingOption as DataProcessingOption, index$2_Destination as Destination, index$2_Env as Env, index$2_EventName as EventName, index$2_InitFn as InitFn, Mapping$1 as Mapping, index$2_OriginalEventDataParameters as OriginalEventDataParameters, index$2_PartialConfig as PartialConfig, index$2_PushEvents as PushEvents, index$2_PushFn as PushFn, index$2_Rule as Rule, index$2_Rules as Rules, index$2_ServerEventParameters as ServerEventParameters, Settings$1 as Settings, index$2_StandardParameters as StandardParameters, index$2_Types as Types };
311
- }
312
-
313
- /**
314
- * Standard mock environment for push operations
315
- *
316
- * Use this for testing Meta Conversions API events without making
317
- * actual HTTP requests to Facebook's servers.
318
- */
319
- declare const push: Env;
320
-
321
- declare const env_push: typeof push;
322
- declare namespace env {
323
- export { env_push as push };
324
- }
325
-
326
- declare function Purchase$1(): BodyParameters;
327
-
328
- declare namespace events {
329
- export { Purchase$1 as Purchase };
330
- }
331
-
332
- declare const InitUserData: Settings$1;
333
- declare const Purchase: Rule;
334
- declare const config: {
335
- order: {
336
- complete: Rule;
337
- };
338
- };
339
-
340
- declare const mapping$1_InitUserData: typeof InitUserData;
341
- declare const mapping$1_Purchase: typeof Purchase;
342
- declare const mapping$1_config: typeof config;
343
- declare namespace mapping$1 {
344
- export { mapping$1_InitUserData as InitUserData, mapping$1_Purchase as Purchase, mapping$1_config as config };
345
- }
346
-
347
- declare const index$1_env: typeof env;
348
- declare const index$1_events: typeof events;
349
- declare namespace index$1 {
350
- export { index$1_env as env, index$1_events as events, mapping$1 as mapping };
351
- }
352
-
353
- /**
354
- * Action Source Enum
355
- * Where the conversion event took place
356
- * https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/server-event
357
- */
358
- declare const ActionSourceSchema: z.ZodEnum<{
359
- email: "email";
360
- website: "website";
361
- app: "app";
362
- phone_call: "phone_call";
363
- chat: "chat";
364
- physical_store: "physical_store";
365
- system_generated: "system_generated";
366
- business_messaging: "business_messaging";
367
- other: "other";
368
- }>;
369
- /**
370
- * Event Name
371
- * Standard Meta event names or custom event identifiers
372
- */
373
- declare const EventNameSchema: z.ZodUnion<readonly [z.ZodEnum<{
374
- AddPaymentInfo: "AddPaymentInfo";
375
- AddToCart: "AddToCart";
376
- AddToWishlist: "AddToWishlist";
377
- CompleteRegistration: "CompleteRegistration";
378
- Contact: "Contact";
379
- CustomizeProduct: "CustomizeProduct";
380
- Donate: "Donate";
381
- FindLocation: "FindLocation";
382
- InitiateCheckout: "InitiateCheckout";
383
- Lead: "Lead";
384
- Purchase: "Purchase";
385
- Schedule: "Schedule";
386
- Search: "Search";
387
- StartTrial: "StartTrial";
388
- SubmitApplication: "SubmitApplication";
389
- Subscribe: "Subscribe";
390
- ViewContent: "ViewContent";
391
- }>, z.ZodString]>;
392
-
393
- declare const SettingsSchema: z.ZodObject<{
394
- accessToken: z.ZodString;
395
- pixelId: z.ZodString;
396
- action_source: z.ZodOptional<z.ZodEnum<{
397
- email: "email";
398
- website: "website";
399
- app: "app";
400
- phone_call: "phone_call";
401
- chat: "chat";
402
- physical_store: "physical_store";
403
- system_generated: "system_generated";
404
- business_messaging: "business_messaging";
405
- other: "other";
406
- }>>;
407
- doNotHash: z.ZodOptional<z.ZodArray<z.ZodString>>;
408
- test_event_code: z.ZodOptional<z.ZodString>;
409
- url: z.ZodOptional<z.ZodString>;
410
- user_data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
411
- }, z.core.$strip>;
412
- type Settings = z.infer<typeof SettingsSchema>;
413
-
414
- /**
415
- * Meta Conversions API Mapping Schema
416
- * Meta CAPI has no event-level mapping configuration
417
- */
418
- declare const MappingSchema: z.ZodObject<{}, z.core.$strip>;
419
- /**
420
- * Type inference from MappingSchema
421
- */
422
- type Mapping = z.infer<typeof MappingSchema>;
423
-
424
- declare const settings: _walkeros_core.JSONSchema;
425
- declare const mapping: _walkeros_core.JSONSchema;
426
-
427
- declare const index_ActionSourceSchema: typeof ActionSourceSchema;
428
- declare const index_EventNameSchema: typeof EventNameSchema;
288
+ type index_ActionSource = ActionSource;
289
+ type index_AppData = AppData;
290
+ type index_BodyParameters = BodyParameters;
291
+ type index_Config = Config;
292
+ type index_CustomerInformationParameters = CustomerInformationParameters;
293
+ type index_CustomerSegmentation = CustomerSegmentation;
294
+ type index_DataProcessingOption = DataProcessingOption;
295
+ type index_Destination = Destination;
296
+ type index_Env = Env;
297
+ type index_EventName = EventName;
298
+ type index_InitFn = InitFn;
429
299
  type index_Mapping = Mapping;
430
- declare const index_MappingSchema: typeof MappingSchema;
300
+ type index_OriginalEventDataParameters = OriginalEventDataParameters;
301
+ type index_PartialConfig = PartialConfig;
302
+ type index_PushEvents = PushEvents;
303
+ type index_PushFn = PushFn;
304
+ type index_Rule = Rule;
305
+ type index_Rules = Rules;
306
+ type index_ServerEventParameters = ServerEventParameters;
431
307
  type index_Settings = Settings;
432
- declare const index_SettingsSchema: typeof SettingsSchema;
433
- declare const index_mapping: typeof mapping;
434
- declare const index_settings: typeof settings;
308
+ type index_StandardParameters = StandardParameters;
309
+ type index_Types = Types;
435
310
  declare namespace index {
436
- export { index_ActionSourceSchema as ActionSourceSchema, index_EventNameSchema as EventNameSchema, type index_Mapping as Mapping, index_MappingSchema as MappingSchema, type index_Settings as Settings, index_SettingsSchema as SettingsSchema, index_mapping as mapping, index_settings as settings };
311
+ export type { index_ActionSource as ActionSource, index_AppData as AppData, index_BodyParameters as BodyParameters, index_Config as Config, index_CustomerInformationParameters as CustomerInformationParameters, index_CustomerSegmentation as CustomerSegmentation, index_DataProcessingOption as DataProcessingOption, index_Destination as Destination, index_Env as Env, index_EventName as EventName, index_InitFn as InitFn, index_Mapping as Mapping, index_OriginalEventDataParameters as OriginalEventDataParameters, index_PartialConfig as PartialConfig, index_PushEvents as PushEvents, index_PushFn as PushFn, index_Rule as Rule, index_Rules as Rules, index_ServerEventParameters as ServerEventParameters, index_Settings as Settings, index_StandardParameters as StandardParameters, index_Types as Types };
437
312
  }
438
313
 
439
314
  declare const destinationMeta: Destination;
440
315
 
441
- export { index$2 as DestinationMeta, destinationMeta as default, destinationMeta, index$1 as examples, index as schemas };
316
+ export { index as DestinationMeta, destinationMeta as default, destinationMeta };
package/dist/index.d.ts CHANGED
@@ -1,34 +1,33 @@
1
- import * as _walkeros_core from '@walkeros/core';
2
- import { Destination as Destination$1, Mapping as Mapping$2, z } from '@walkeros/core';
1
+ import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
3
2
  import { DestinationServer, sendServer } from '@walkeros/server-core';
4
3
 
5
- interface Settings$1 {
4
+ interface Settings {
6
5
  accessToken: string;
7
6
  pixelId: string;
8
7
  action_source?: ActionSource;
9
8
  doNotHash?: string[];
10
9
  test_event_code?: string;
11
10
  url?: string;
12
- user_data?: Mapping$2.Map;
11
+ user_data?: Mapping$1.Map;
13
12
  }
14
- interface Mapping$1 {
13
+ interface Mapping {
15
14
  }
16
15
  interface Env extends DestinationServer.Env {
17
16
  sendServer?: typeof sendServer;
18
17
  }
19
- type Types = Destination$1.Types<Settings$1, Mapping$1, Env>;
18
+ type Types = Destination$1.Types<Settings, Mapping, Env>;
20
19
  interface Destination extends DestinationServer.Destination<Types> {
21
20
  init: DestinationServer.InitFn<Types>;
22
21
  }
23
22
  type Config = {
24
- settings: Settings$1;
23
+ settings: Settings;
25
24
  } & DestinationServer.Config<Types>;
26
25
  type InitFn = DestinationServer.InitFn<Types>;
27
26
  type PushFn = DestinationServer.PushFn<Types>;
28
27
  type PartialConfig = DestinationServer.PartialConfig<Types>;
29
- type PushEvents = DestinationServer.PushEvents<Mapping$1>;
30
- type Rule = Mapping$2.Rule<Mapping$1>;
31
- type Rules = Mapping$2.Rules<Rule>;
28
+ type PushEvents = DestinationServer.PushEvents<Mapping>;
29
+ type Rule = Mapping$1.Rule<Mapping>;
30
+ type Rules = Mapping$1.Rules<Rule>;
32
31
  interface BodyParameters {
33
32
  data: Array<ServerEventParameters>;
34
33
  test_event_code?: string;
@@ -286,156 +285,32 @@ interface OriginalEventDataParameters {
286
285
  event_id?: string;
287
286
  }
288
287
 
289
- type index$2_ActionSource = ActionSource;
290
- type index$2_AppData = AppData;
291
- type index$2_BodyParameters = BodyParameters;
292
- type index$2_Config = Config;
293
- type index$2_CustomerInformationParameters = CustomerInformationParameters;
294
- type index$2_CustomerSegmentation = CustomerSegmentation;
295
- type index$2_DataProcessingOption = DataProcessingOption;
296
- type index$2_Destination = Destination;
297
- type index$2_Env = Env;
298
- type index$2_EventName = EventName;
299
- type index$2_InitFn = InitFn;
300
- type index$2_OriginalEventDataParameters = OriginalEventDataParameters;
301
- type index$2_PartialConfig = PartialConfig;
302
- type index$2_PushEvents = PushEvents;
303
- type index$2_PushFn = PushFn;
304
- type index$2_Rule = Rule;
305
- type index$2_Rules = Rules;
306
- type index$2_ServerEventParameters = ServerEventParameters;
307
- type index$2_StandardParameters = StandardParameters;
308
- type index$2_Types = Types;
309
- declare namespace index$2 {
310
- export type { index$2_ActionSource as ActionSource, index$2_AppData as AppData, index$2_BodyParameters as BodyParameters, index$2_Config as Config, index$2_CustomerInformationParameters as CustomerInformationParameters, index$2_CustomerSegmentation as CustomerSegmentation, index$2_DataProcessingOption as DataProcessingOption, index$2_Destination as Destination, index$2_Env as Env, index$2_EventName as EventName, index$2_InitFn as InitFn, Mapping$1 as Mapping, index$2_OriginalEventDataParameters as OriginalEventDataParameters, index$2_PartialConfig as PartialConfig, index$2_PushEvents as PushEvents, index$2_PushFn as PushFn, index$2_Rule as Rule, index$2_Rules as Rules, index$2_ServerEventParameters as ServerEventParameters, Settings$1 as Settings, index$2_StandardParameters as StandardParameters, index$2_Types as Types };
311
- }
312
-
313
- /**
314
- * Standard mock environment for push operations
315
- *
316
- * Use this for testing Meta Conversions API events without making
317
- * actual HTTP requests to Facebook's servers.
318
- */
319
- declare const push: Env;
320
-
321
- declare const env_push: typeof push;
322
- declare namespace env {
323
- export { env_push as push };
324
- }
325
-
326
- declare function Purchase$1(): BodyParameters;
327
-
328
- declare namespace events {
329
- export { Purchase$1 as Purchase };
330
- }
331
-
332
- declare const InitUserData: Settings$1;
333
- declare const Purchase: Rule;
334
- declare const config: {
335
- order: {
336
- complete: Rule;
337
- };
338
- };
339
-
340
- declare const mapping$1_InitUserData: typeof InitUserData;
341
- declare const mapping$1_Purchase: typeof Purchase;
342
- declare const mapping$1_config: typeof config;
343
- declare namespace mapping$1 {
344
- export { mapping$1_InitUserData as InitUserData, mapping$1_Purchase as Purchase, mapping$1_config as config };
345
- }
346
-
347
- declare const index$1_env: typeof env;
348
- declare const index$1_events: typeof events;
349
- declare namespace index$1 {
350
- export { index$1_env as env, index$1_events as events, mapping$1 as mapping };
351
- }
352
-
353
- /**
354
- * Action Source Enum
355
- * Where the conversion event took place
356
- * https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/server-event
357
- */
358
- declare const ActionSourceSchema: z.ZodEnum<{
359
- email: "email";
360
- website: "website";
361
- app: "app";
362
- phone_call: "phone_call";
363
- chat: "chat";
364
- physical_store: "physical_store";
365
- system_generated: "system_generated";
366
- business_messaging: "business_messaging";
367
- other: "other";
368
- }>;
369
- /**
370
- * Event Name
371
- * Standard Meta event names or custom event identifiers
372
- */
373
- declare const EventNameSchema: z.ZodUnion<readonly [z.ZodEnum<{
374
- AddPaymentInfo: "AddPaymentInfo";
375
- AddToCart: "AddToCart";
376
- AddToWishlist: "AddToWishlist";
377
- CompleteRegistration: "CompleteRegistration";
378
- Contact: "Contact";
379
- CustomizeProduct: "CustomizeProduct";
380
- Donate: "Donate";
381
- FindLocation: "FindLocation";
382
- InitiateCheckout: "InitiateCheckout";
383
- Lead: "Lead";
384
- Purchase: "Purchase";
385
- Schedule: "Schedule";
386
- Search: "Search";
387
- StartTrial: "StartTrial";
388
- SubmitApplication: "SubmitApplication";
389
- Subscribe: "Subscribe";
390
- ViewContent: "ViewContent";
391
- }>, z.ZodString]>;
392
-
393
- declare const SettingsSchema: z.ZodObject<{
394
- accessToken: z.ZodString;
395
- pixelId: z.ZodString;
396
- action_source: z.ZodOptional<z.ZodEnum<{
397
- email: "email";
398
- website: "website";
399
- app: "app";
400
- phone_call: "phone_call";
401
- chat: "chat";
402
- physical_store: "physical_store";
403
- system_generated: "system_generated";
404
- business_messaging: "business_messaging";
405
- other: "other";
406
- }>>;
407
- doNotHash: z.ZodOptional<z.ZodArray<z.ZodString>>;
408
- test_event_code: z.ZodOptional<z.ZodString>;
409
- url: z.ZodOptional<z.ZodString>;
410
- user_data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
411
- }, z.core.$strip>;
412
- type Settings = z.infer<typeof SettingsSchema>;
413
-
414
- /**
415
- * Meta Conversions API Mapping Schema
416
- * Meta CAPI has no event-level mapping configuration
417
- */
418
- declare const MappingSchema: z.ZodObject<{}, z.core.$strip>;
419
- /**
420
- * Type inference from MappingSchema
421
- */
422
- type Mapping = z.infer<typeof MappingSchema>;
423
-
424
- declare const settings: _walkeros_core.JSONSchema;
425
- declare const mapping: _walkeros_core.JSONSchema;
426
-
427
- declare const index_ActionSourceSchema: typeof ActionSourceSchema;
428
- declare const index_EventNameSchema: typeof EventNameSchema;
288
+ type index_ActionSource = ActionSource;
289
+ type index_AppData = AppData;
290
+ type index_BodyParameters = BodyParameters;
291
+ type index_Config = Config;
292
+ type index_CustomerInformationParameters = CustomerInformationParameters;
293
+ type index_CustomerSegmentation = CustomerSegmentation;
294
+ type index_DataProcessingOption = DataProcessingOption;
295
+ type index_Destination = Destination;
296
+ type index_Env = Env;
297
+ type index_EventName = EventName;
298
+ type index_InitFn = InitFn;
429
299
  type index_Mapping = Mapping;
430
- declare const index_MappingSchema: typeof MappingSchema;
300
+ type index_OriginalEventDataParameters = OriginalEventDataParameters;
301
+ type index_PartialConfig = PartialConfig;
302
+ type index_PushEvents = PushEvents;
303
+ type index_PushFn = PushFn;
304
+ type index_Rule = Rule;
305
+ type index_Rules = Rules;
306
+ type index_ServerEventParameters = ServerEventParameters;
431
307
  type index_Settings = Settings;
432
- declare const index_SettingsSchema: typeof SettingsSchema;
433
- declare const index_mapping: typeof mapping;
434
- declare const index_settings: typeof settings;
308
+ type index_StandardParameters = StandardParameters;
309
+ type index_Types = Types;
435
310
  declare namespace index {
436
- export { index_ActionSourceSchema as ActionSourceSchema, index_EventNameSchema as EventNameSchema, type index_Mapping as Mapping, index_MappingSchema as MappingSchema, type index_Settings as Settings, index_SettingsSchema as SettingsSchema, index_mapping as mapping, index_settings as settings };
311
+ export type { index_ActionSource as ActionSource, index_AppData as AppData, index_BodyParameters as BodyParameters, index_Config as Config, index_CustomerInformationParameters as CustomerInformationParameters, index_CustomerSegmentation as CustomerSegmentation, index_DataProcessingOption as DataProcessingOption, index_Destination as Destination, index_Env as Env, index_EventName as EventName, index_InitFn as InitFn, index_Mapping as Mapping, index_OriginalEventDataParameters as OriginalEventDataParameters, index_PartialConfig as PartialConfig, index_PushEvents as PushEvents, index_PushFn as PushFn, index_Rule as Rule, index_Rules as Rules, index_ServerEventParameters as ServerEventParameters, index_Settings as Settings, index_StandardParameters as StandardParameters, index_Types as Types };
437
312
  }
438
313
 
439
314
  declare const destinationMeta: Destination;
440
315
 
441
- export { index$2 as DestinationMeta, destinationMeta as default, destinationMeta, index$1 as examples, index as schemas };
316
+ export { index as DestinationMeta, destinationMeta as default, destinationMeta };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,i=(e,r)=>{for(var a in r)t(e,a,{get:r[a],enumerable:!0})},s={};i(s,{DestinationMeta:()=>f,default:()=>H,destinationMeta:()=>$,examples:()=>v,schemas:()=>q}),module.exports=(e=s,((e,i,s,o)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let c of a(i))n.call(e,c)||c===s||t(e,c,{get:()=>i[c],enumerable:!(o=r(i,c))||o.enumerable});return e})(t({},"__esModule",{value:!0}),e));var o=require("@walkeros/core");var c=require("@walkeros/core"),d=require("@walkeros/server-core"),u=require("@walkeros/core"),l=require("@walkeros/server-core"),p=["em","ph","fn","ln","db","ge","ct","st","zp","country","external_id"];function m(e,t=[]){return p.includes(e)&&!t.includes(e)}async function g(e,t){return t?(0,u.isArray)(e)?Promise.all(e.map(e=>(0,l.getHashServer)(String(e)))):(0,l.getHashServer)(String(e)):e}var b=async function(e,{config:t,mapping:r,data:a,collector:n,env:i}){var s;const{accessToken:o,pixelId:l,action_source:p="website",doNotHash:b,test_event_code:f,url:v="https://graph.facebook.com/v22.0/",user_data:_}=t.settings,h=(0,c.isObject)(a)?a:{},y=t.data?await(0,c.getMappingValue)(e,t.data):{},k=_?await(0,c.getMappingValue)(e,{map:_}):{},w={...(0,c.isObject)(y)&&(0,c.isObject)(y.user_data)?y.user_data:{},...(0,c.isObject)(k)?k:{},...(0,c.isObject)(h.user_data)?h.user_data:{}};w.fbclid&&(w.fbc=function(e,t){if(!e)return;const r="fb",a="1",n=t||Date.now();return`${r}.${a}.${n}.${e}`}(w.fbclid,(null==(s=null==n?void 0:n.session)?void 0:s.start)||e.timestamp),delete w.fbclid);const S={event_name:e.name,event_id:e.id,event_time:Math.round((e.timestamp||Date.now())/1e3),action_source:p,...h,user_data:w};"website"===p&&(S.event_source_url=e.source.id);const z=await async function(e,t=[]){if(!(0,u.isObject)(e))return e;const r="user_data"in e,a=r?e.user_data:e,n=(await Promise.all(Object.entries(a).map(async([e,a])=>[e,await g(a,r&&m(e,t))]))).reduce((e,[t,r])=>((0,u.isString)(t)&&(e[t]=r),e),{});return r?{...e,user_data:n}:n}(S,b),O={data:[z]};f&&(O.test_event_code=f);const P=(null==i?void 0:i.sendServer)||d.sendServer,j=await P(`${v}${l}/events?access_token=${o}`,JSON.stringify(O));if((0,c.isObject)(j)&&!1===j.ok)throw new Error(JSON.stringify(j))};var f={},v={};i(v,{env:()=>_,events:()=>y,mapping:()=>S});var _={};i(_,{push:()=>h});var h={sendServer:async function(e,t,r){return{ok:!0,data:{events_received:1,messages:[],fbtrace_id:"mock-trace-id"}}}},y={};i(y,{Purchase:()=>w});var k=require("@walkeros/core");function w(){const e=(0,k.getEvent)("order complete");return{data:[{event_name:"Purchase",event_time:e.timestamp/1e3,event_id:e.id,event_source_url:e.source.id,action_source:"website",user_data:{external_id:["cc8e27118413234d4297ed00a02711365312c79325df9b5b8f4199cbd0b96e7e","9176e6f336dbdb4f99b0e45cbd7e41e0e2323812b236822842a61ffbd362ac8c"]},order_id:String(e.data.id),currency:"EUR",value:Number(e.data.total),contents:e.nested.filter(e=>"product"===e.entity).map(e=>({id:String(e.data.id),quantity:Number(e.data.quantity)||1,item_price:Number(e.data.price)})),num_items:2}]}}var S={};i(S,{InitUserData:()=>O,Purchase:()=>P,config:()=>j});var z=require("@walkeros/core"),O={pixelId:"p1x3l1d",accessToken:"s3cr3t",user_data:{external_id:{set:["user.device","user.session"]}}},P={name:"Purchase",data:{map:{order_id:"data.id",currency:{key:"data.currency",value:"EUR"},value:"data.total",contents:{loop:["nested",{condition:e=>(0,z.isObject)(e)&&"product"===e.entity,map:{id:"data.id",item_price:"data.price",quantity:{key:"data.quantity",value:1}}}]},num_items:{fn:e=>e.nested.filter(e=>"product"===e.entity).length}}}},j={order:{complete:P}},q={};i(q,{ActionSourceSchema:()=>C,EventNameSchema:()=>M,MappingSchema:()=>N,SettingsSchema:()=>A,mapping:()=>E,settings:()=>D});var x=require("@walkeros/core"),I=require("@walkeros/core"),T=require("@walkeros/core"),C=T.z.enum(["email","website","app","phone_call","chat","physical_store","system_generated","business_messaging","other"]),M=T.z.union([T.z.enum(["AddPaymentInfo","AddToCart","AddToWishlist","CompleteRegistration","Contact","CustomizeProduct","Donate","FindLocation","InitiateCheckout","Lead","Purchase","Schedule","Search","StartTrial","SubmitApplication","Subscribe","ViewContent"]),T.z.string()]),A=I.z.object({accessToken:I.z.string().min(1).describe("Meta access token for Conversions API authentication (like your_access_token)"),pixelId:I.z.string().regex(/^[0-9]+$/,"Pixel ID must contain only digits").describe("Meta Pixel ID from your Facebook Business account (like 1234567890)"),action_source:C.describe("Source of the event (website, app, phone_call, etc.) (like website)").optional(),doNotHash:I.z.array(I.z.string()).describe("Array of user_data fields that should not be hashed (like ['client_ip_address', 'client_user_agent'])").optional(),test_event_code:I.z.string().describe("Test event code for debugging Meta Conversions API events (like TEST12345)").optional(),url:I.z.string().url().describe("Custom URL for Meta Conversions API endpoint (like https://graph.facebook.com/v17.0)").optional(),user_data:I.z.record(I.z.string(),I.z.string()).describe("Mapping configuration for user data fields (like { email: 'user.email', phone: 'user.phone' })").optional()}),N=require("@walkeros/core").z.object({}),D=(0,x.zodToSchema)(A),E=(0,x.zodToSchema)(N),$={type:"meta",config:{},async init({config:e}){const t=function(e={}){const t=e.settings||{},{accessToken:r,pixelId:a}=t;r||(0,o.throwError)("Config settings accessToken missing"),a||(0,o.throwError)("Config settings pixelId missing");const n={...t,accessToken:r,pixelId:a};return{...e,settings:n}}(e);return t},push:async(e,{config:t,mapping:r,data:a,collector:n,env:i})=>await b(e,{config:t,mapping:r,data:a,collector:n,env:i})},H=$;//# sourceMappingURL=index.js.map
1
+ "use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,s={};((e,r)=>{for(var n in r)t(e,n,{get:r[n],enumerable:!0})})(s,{DestinationMeta:()=>v,default:()=>m,destinationMeta:()=>b}),module.exports=(e=s,((e,s,i,o)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let c of n(s))a.call(e,c)||c===i||t(e,c,{get:()=>s[c],enumerable:!(o=r(s,c))||o.enumerable});return e})(t({},"__esModule",{value:!0}),e));var i=require("@walkeros/core");var o=require("@walkeros/core"),c=require("@walkeros/server-core"),u=require("@walkeros/core"),l=require("@walkeros/server-core"),d=["em","ph","fn","ln","db","ge","ct","st","zp","country","external_id"];function p(e,t=[]){return d.includes(e)&&!t.includes(e)}async function f(e,t){return t?(0,u.isArray)(e)?Promise.all(e.map(e=>(0,l.getHashServer)(String(e)))):(0,l.getHashServer)(String(e)):e}var g=async function(e,{config:t,mapping:r,data:n,collector:a,env:s}){var i;const{accessToken:l,pixelId:d,action_source:g="website",doNotHash:v,test_event_code:b,url:m="https://graph.facebook.com/v22.0/",user_data:_}=t.settings,w=(0,o.isObject)(n)?n:{},y=t.data?await(0,o.getMappingValue)(e,t.data):{},O=_?await(0,o.getMappingValue)(e,{map:_}):{},j={...(0,o.isObject)(y)&&(0,o.isObject)(y.user_data)?y.user_data:{},...(0,o.isObject)(O)?O:{},...(0,o.isObject)(w.user_data)?w.user_data:{}};j.fbclid&&(j.fbc=function(e,t){if(!e)return;const r="fb",n="1",a=t||Date.now();return`${r}.${n}.${a}.${e}`}(j.fbclid,(null==(i=null==a?void 0:a.session)?void 0:i.start)||e.timestamp),delete j.fbclid);const h={event_name:e.name,event_id:e.id,event_time:Math.round((e.timestamp||Date.now())/1e3),action_source:g,...w,user_data:j};"website"===g&&(h.event_source_url=e.source.id);const k=await async function(e,t=[]){if(!(0,u.isObject)(e))return e;const r="user_data"in e,n=r?e.user_data:e,a=(await Promise.all(Object.entries(n).map(async([e,n])=>[e,await f(n,r&&p(e,t))]))).reduce((e,[t,r])=>((0,u.isString)(t)&&(e[t]=r),e),{});return r?{...e,user_data:a}:a}(h,v),S={data:[k]};b&&(S.test_event_code=b);const $=(null==s?void 0:s.sendServer)||c.sendServer,x=await $(`${m}${d}/events?access_token=${l}`,JSON.stringify(S));if((0,o.isObject)(x)&&!1===x.ok)throw new Error(JSON.stringify(x))};var v={},b={type:"meta",config:{},async init({config:e}){const t=function(e={}){const t=e.settings||{},{accessToken:r,pixelId:n}=t;r||(0,i.throwError)("Config settings accessToken missing"),n||(0,i.throwError)("Config settings pixelId missing");const a={...t,accessToken:r,pixelId:n};return{...e,settings:a}}(e);return t},push:async(e,{config:t,mapping:r,data:n,collector:a,env:s})=>await g(e,{config:t,mapping:r,data:n,collector:a,env:s})},m=b;//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/config.ts","../src/push.ts","../src/hash.ts","../src/types/index.ts","../src/examples/index.ts","../src/examples/env.ts","../src/examples/events.ts","../src/examples/mapping.ts","../src/schemas/index.ts","../src/schemas/settings.ts","../src/schemas/primitives.ts","../src/schemas/mapping.ts"],"sourcesContent":["import type { Destination } from './types';\nimport { getConfig } from './config';\nimport { push } from './push';\n\n// Types\nexport * as DestinationMeta from './types';\n\n// Examples\nexport * as examples from './examples';\n\n// Schemas\nexport * as schemas from './schemas';\n\nexport const destinationMeta: Destination = {\n type: 'meta',\n\n config: {},\n\n async init({ config: partialConfig }) {\n const config = getConfig(partialConfig);\n return config;\n },\n\n async push(event, { config, mapping, data, collector, env }) {\n return await push(event, { config, mapping, data, collector, env });\n },\n};\n\nexport default destinationMeta;\n","import type { Config, Settings, PartialConfig } from './types';\nimport { throwError } from '@walkeros/core';\n\nexport function getConfig(partialConfig: PartialConfig = {}): Config {\n const settings = (partialConfig.settings || {}) as Partial<Settings>;\n const { accessToken, pixelId } = settings;\n\n if (!accessToken) throwError('Config settings accessToken missing');\n if (!pixelId) throwError('Config settings pixelId missing');\n\n const settingsConfig: Settings = {\n ...settings,\n accessToken,\n pixelId,\n };\n\n return { ...partialConfig, settings: settingsConfig };\n}\n","import type { WalkerOS } from '@walkeros/core';\nimport type {\n BodyParameters,\n CustomerInformationParameters,\n PushFn,\n ServerEventParameters,\n Env,\n} from './types';\nimport { getMappingValue, isObject } from '@walkeros/core';\nimport { sendServer } from '@walkeros/server-core';\nimport { hashEvent } from './hash';\n\nexport const push: PushFn = async function (\n event,\n { config, mapping, data, collector, env },\n) {\n const {\n accessToken,\n pixelId,\n action_source = 'website',\n doNotHash,\n test_event_code,\n url = 'https://graph.facebook.com/v22.0/',\n user_data,\n } = config.settings!;\n\n const eventData = isObject(data) ? data : {};\n const configData = config.data\n ? await getMappingValue(event, config.data)\n : {};\n const userDataCustom = user_data\n ? await getMappingValue(event, { map: user_data })\n : {};\n\n const userData: CustomerInformationParameters = {\n // Destination config\n ...(isObject(configData) && isObject(configData.user_data)\n ? configData.user_data\n : {}),\n // Custom user_data\n ...(isObject(userDataCustom) ? userDataCustom : {}),\n // Event mapping\n ...(isObject(eventData.user_data) ? eventData.user_data : {}),\n };\n\n if (userData.fbclid) {\n userData.fbc = formatClickId(\n userData.fbclid,\n collector?.session?.start || event.timestamp,\n );\n delete userData.fbclid;\n }\n const serverEvent: ServerEventParameters = {\n event_name: event.name,\n event_id: event.id,\n event_time: Math.round((event.timestamp || Date.now()) / 1000),\n action_source,\n ...eventData,\n user_data: userData,\n };\n\n if (action_source === 'website')\n serverEvent.event_source_url = event.source.id;\n\n const hashedServerEvent = await hashEvent(serverEvent, doNotHash);\n\n const body: BodyParameters = { data: [hashedServerEvent] };\n\n // Test event code\n if (test_event_code) body.test_event_code = test_event_code;\n\n const sendServerFn = env?.sendServer || sendServer;\n const result = await sendServerFn(\n `${url}${pixelId}/events?access_token=${accessToken}`,\n JSON.stringify(body),\n );\n\n if (isObject(result) && result.ok === false)\n throw new Error(JSON.stringify(result));\n};\n\nfunction formatClickId(clickId: unknown, time?: number): string | undefined {\n // https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/fbp-and-fbc#2--format-clickid\n\n if (!clickId) return;\n\n // Version is always \"fb\"\n const version = 'fb';\n\n // Subdomain ('com' = 0, 'example.com' = 1, 'www.example.com' = 2)\n const subdomainIndex = '1';\n\n // Get the current timestamp in milliseconds (or when the fbclid was observed)\n const creationTime = time || Date.now();\n\n return `${version}.${subdomainIndex}.${creationTime}.${clickId}`;\n}\n\nfunction lower(str: WalkerOS.Property): string {\n return String(str).toLocaleLowerCase();\n}\n","import { WalkerOS } from '@walkeros/core';\nimport { isArray, isObject, isString } from '@walkeros/core';\nimport { getHashServer } from '@walkeros/server-core';\n\nconst keysToHash = [\n 'em',\n 'ph',\n 'fn',\n 'ln',\n 'db',\n 'ge',\n 'ct',\n 'st',\n 'zp',\n 'country',\n 'external_id',\n];\n\nfunction shouldBeHashed(key: string, doNotHash: string[] = []): boolean {\n return keysToHash.includes(key) && !doNotHash.includes(key);\n}\n\ntype HashableValue = WalkerOS.AnyObject | unknown | unknown[];\n\nasync function processValue(\n value: unknown,\n shouldHash: boolean,\n): Promise<unknown> {\n if (!shouldHash) return value;\n if (isArray(value)) {\n return Promise.all(value.map((item) => getHashServer(String(item))));\n }\n return getHashServer(String(value));\n}\n\nexport async function hashEvent<T extends HashableValue>(\n value: T,\n doNotHash: string[] = [],\n): Promise<T> {\n if (!isObject(value)) return value;\n\n const isUserData = 'user_data' in value;\n const target = (isUserData ? value.user_data : value) as WalkerOS.AnyObject;\n\n const entries = await Promise.all(\n Object.entries(target).map(async ([k, v]) => [\n k,\n await processValue(v, isUserData && shouldBeHashed(k, doNotHash)),\n ]),\n );\n\n const result = entries.reduce((acc, [k, v]) => {\n if (isString(k)) acc[k] = v;\n return acc;\n }, {} as WalkerOS.AnyObject);\n\n return isUserData ? { ...value, user_data: result } : (result as T);\n}\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationServer, sendServer } from '@walkeros/server-core';\n\nexport interface Settings {\n accessToken: string;\n pixelId: string;\n action_source?: ActionSource;\n doNotHash?: string[];\n test_event_code?: string;\n url?: string;\n user_data?: WalkerOSMapping.Map;\n}\n\nexport interface Mapping {}\n\nexport interface Env extends DestinationServer.Env {\n sendServer?: typeof sendServer;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env>;\n\nexport interface Destination extends DestinationServer.Destination<Types> {\n init: DestinationServer.InitFn<Types>;\n}\n\nexport type Config = {\n settings: Settings;\n} & DestinationServer.Config<Types>;\n\nexport type InitFn = DestinationServer.InitFn<Types>;\nexport type PushFn = DestinationServer.PushFn<Types>;\n\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\n\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\n// https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/main-body\nexport interface BodyParameters {\n data: Array<ServerEventParameters>;\n test_event_code?: string;\n}\n\n/**\n * Represents the top‑level parameters for a server event sent via Meta's Conversions API.\n * https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/server-event\n */\nexport interface ServerEventParameters extends StandardParameters {\n /** The event name or custom event identifier. Required for deduplication. */\n event_name: EventName;\n\n /** Unix timestamp (in seconds) when the event actually occurred. GMT timezone. */\n event_time: number;\n\n /** Map of customer information for matching (emails, phone, etc.). */\n user_data: CustomerInformationParameters;\n\n /** Additional business data about the event. */\n custom_data?: Record<string, unknown>;\n\n /** URL of the page where the event occurred. */\n event_source_url?: string;\n\n /** If true, exclude this event from ads optimization (only attribution). */\n opt_out?: boolean;\n\n /** Unique ID for deduplication across Pixel and CAPI. */\n event_id?: string;\n\n /** Source of the event (e.g., website, app). */\n action_source: ActionSource;\n\n /** Processing options (e.g., ['LDU'] for CCPA limited data use). */\n data_processing_options?: DataProcessingOption[];\n\n /** Country code for data processing option (1 = USA, 0 = auto‑geolocate). */\n data_processing_options_country?: number;\n\n /** State code for data processing option (1000 = California, 0 = auto). */\n data_processing_options_state?: number;\n\n /** App‑specific data (required if action_source is 'app'). */\n app_data?: AppData;\n\n /** HTTP referrer header of the event. */\n referrer_url?: string;\n\n /** Metadata to link delayed events to past acquisition events. */\n original_event_data?: OriginalEventDataParameters;\n\n /** User segment for more context about the customer's relationship. */\n customer_segmentation?: CustomerSegmentation;\n}\n\nexport type EventName =\n | 'AddPaymentInfo'\n | 'AddToCart'\n | 'AddToWishlist'\n | 'CompleteRegistration'\n | 'Contact'\n | 'CustomizeProduct'\n | 'Donate'\n | 'FindLocation'\n | 'InitiateCheckout'\n | 'Lead'\n | 'Purchase'\n | 'Schedule'\n | 'Search'\n | 'StartTrial'\n | 'SubmitApplication'\n | 'Subscribe'\n | 'ViewContent'\n | string;\n\nexport type ActionSource =\n | 'email'\n | 'website'\n | 'app'\n | 'phone_call'\n | 'chat'\n | 'physical_store'\n | 'system_generated'\n | 'business_messaging'\n | 'other';\n\nexport type DataProcessingOption = 'LDU';\n\nexport type CustomerSegmentation =\n | 'new_customer_to_business'\n | 'new_customer_to_business_line'\n | 'new_customer_to_product_area'\n | 'new_customer_to_medium'\n | 'existing_customer_to_business'\n | 'existing_customer_to_business_line'\n | 'existing_customer_to_product_area'\n | 'existing_customer_to_medium'\n | 'customer_in_loyalty_program';\n\n/** Extended device info for app events (Android version 'a2', iOS 'i2') */\nexport interface AppData {\n /**\n * Comma-separated array of strings with fixed order:\n * [sdk_version, os_version, device_model, device_brand,\n * screen_width, screen_height, ...]\n */\n extinfo: string[];\n}\n\n// Customer Information Parameters\n// https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters\nexport interface CustomerInformationParameters {\n /** Email(s), SHA-256 hashed, lowercase and trimmed */\n em?: string | string[];\n\n /** Phone number(s), SHA-256 hashed, E.164 format (no leading 0s or symbols) */\n ph?: string | string[];\n\n /** First name(s), SHA-256 hashed, lowercase */\n fn?: string | string[];\n\n /** Last name(s), SHA-256 hashed, lowercase */\n ln?: string | string[];\n\n /** Date(s) of birth in YYYYMMDD, SHA-256 hashed */\n db?: string | string[];\n\n /** Gender(s) in lowercase single letter (\"m\", \"f\", etc.), SHA-256 hashed */\n ge?: string | string[];\n\n /** City name(s), SHA-256 hashed, lowercase */\n ct?: string | string[];\n\n /** State abbreviation(s), SHA-256 hashed, lowercase (e.g., \"ca\", \"ny\") */\n st?: string | string[];\n\n /** ZIP or postal code(s), SHA-256 hashed, lowercase */\n zp?: string | string[];\n\n /** Country code(s), SHA-256 hashed, lowercase (ISO 3166-1 alpha-2) */\n country?: string | string[];\n\n /** External IDs, unique per user. SHA-256 hash recommended */\n external_id?: string | string[];\n\n /** IPv4 or IPv6 address of client. Do NOT hash. */\n client_ip_address?: string;\n\n /** User agent string from browser. Do NOT hash. */\n client_user_agent?: string;\n\n /** fbclid parameter value from the URL. Do NOT hash. */\n fbclid?: string;\n\n /** Facebook click ID (_fbc cookie). Do NOT hash. */\n fbc?: string;\n\n /** Facebook browser ID (_fbp cookie). Do NOT hash. */\n fbp?: string;\n\n /** Subscription ID for the transaction. Do NOT hash. */\n subscription_id?: string;\n\n /** Facebook login ID (App-Scoped ID). Do NOT hash. */\n fb_login_id?: number;\n\n /** Meta Lead Ad lead ID. Do NOT hash. */\n lead_id?: number;\n\n /** Anonymous install ID. App events only. Do NOT hash. */\n anon_id?: string;\n\n /** Mobile advertiser ID (GAID/IDFA). Do NOT hash. */\n madid?: string;\n\n /** Facebook Page ID. Do NOT hash. */\n page_id?: string;\n\n /** Messenger Page-scoped user ID. Do NOT hash. */\n page_scoped_user_id?: string;\n\n /** Click to WhatsApp ad click ID. Do NOT hash. */\n ctwa_clid?: string;\n\n /** Instagram business account ID. Do NOT hash. */\n ig_account_id?: string;\n\n /** Instagram-scoped user ID. Do NOT hash. */\n ig_sid?: string;\n}\n\n// https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data\nexport interface StandardParameters {\n // Web and Offline parameters\n availability?: string;\n body_style?: string;\n checkin_date?: string;\n city?: string;\n condition_of_vehicle?: string;\n content_ids?: string[];\n content_type?: 'product' | 'product_group' | string;\n contents?: Array<{\n id: string;\n quantity?: number;\n item_price?: number;\n delivery_category?: string;\n }>;\n country?: string;\n currency?: string;\n delivery_category?: 'in_store' | 'curbside' | 'home_delivery' | string;\n departing_arrival_date?: string;\n departing_departure_date?: string;\n destination_airport?: string;\n destination_ids?: string[];\n dma_code?: string;\n drivetrain?: string;\n exterior_color?: string;\n fuel_type?: string;\n hotel_score?: number;\n interior_color?: string;\n lead_event_source?: string;\n lease_end_date?: string;\n lease_start_date?: string;\n listing_type?: string;\n make?: string;\n // @TODO is mileage an object?\n 'mileage.unit'?: string;\n 'mileage.value'?: number;\n model?: string;\n neighborhood?: string;\n net_revenue?: number;\n num_adults?: number;\n num_children?: number;\n num_infants?: number;\n num_items?: number;\n order_id?: string;\n origin_airport?: string;\n postal_code?: string;\n predicted_ltv?: number;\n preferred_baths_range?: string;\n preferred_beds_range?: string;\n preferred_neighborhoods?: string[];\n preferred_num_stops?: number;\n preferred_price_range?: string;\n preferred_star_ratings?: [number, number];\n price?: string;\n product_catalog_id?: string;\n property_type?: string;\n region?: string;\n returning_arrival_date?: string;\n returning_departure_date?: string;\n search_string?: string;\n state_of_vehicle?: string;\n suggested_destinations?: string[];\n suggested_home_listings?: string[];\n suggested_hotels?: string[];\n suggested_jobs?: string[];\n suggested_local_service_businesses?: string[];\n suggested_location_based_items?: string[];\n suggested_vehicles?: string[];\n transmission?: string;\n travel_class?: string;\n travel_end?: string;\n travel_start?: string;\n trim?: string;\n\n // App-specific parameters (with fb_ prefix)\n fb_availability?: string;\n fb_body_style?: string;\n fb_checkin_date?: string;\n fb_city?: string;\n fb_condition_of_vehicle?: string;\n fb_content_ids?: string[];\n fb_content_type?: string;\n fb_contents?: Array<{ id: string; quantity?: number; item_price?: number }>;\n fb_country?: string;\n fb_currency?: string;\n fb_delivery_category?: string;\n fb_departing_arrival_date?: string;\n fb_departing_departure_date?: string;\n fb_destination_airport?: string;\n fb_destination_ids?: string[];\n fb_dma_code?: string;\n fb_drivetrain?: string;\n fb_exterior_color?: string;\n fb_fuel_type?: string;\n fb_hotel_score?: number;\n fb_interior_color?: string;\n fb_lease_end_date?: string;\n fb_lease_start_date?: string;\n fb_listing_type?: string;\n fb_make?: string;\n // @TODO is fb_mileage an object?\n 'fb_mileage.unit'?: string;\n 'fb_mileage.value'?: number;\n fb_model?: string;\n fb_neighborhood?: string;\n fb_num_adults?: number;\n fb_num_children?: number;\n fb_num_infants?: number;\n fb_num_items?: number;\n fb_order_id?: string;\n fb_origin_airport?: string;\n fb_postal_code?: string;\n fb_predicted_ltv?: number;\n fb_preferred_baths_range?: string;\n fb_preferred_beds_range?: string;\n fb_preferred_neighborhoods?: string[];\n fb_preferred_num_stops?: number;\n fb_preferred_price_range?: string;\n fb_preferred_star_ratings?: [number, number];\n fb_price?: string;\n fb_product_catalog_id?: string;\n fb_property_type?: string;\n fb_region?: string;\n fb_returning_arrival_date?: string;\n fb_returning_departure_date?: string;\n fb_search_string?: string;\n fb_state_of_vehicle?: string;\n fb_suggested_destinations?: string[];\n fb_suggested_home_listings?: string[];\n fb_suggested_hotels?: string[];\n fb_suggested_jobs?: string[];\n fb_suggested_local_service_businesses?: string[];\n fb_suggested_location_based_items?: string[];\n fb_suggested_vehicles?: string[];\n fb_transmission?: string;\n fb_travel_class?: string;\n fb_travel_end?: string;\n fb_travel_start?: string;\n\n // Offline-specific parameters\n user_bucket?: string;\n value?: number;\n vin?: string;\n year?: number;\n item_number?: string;\n}\n\nexport interface OriginalEventDataParameters {\n event_name?: EventName;\n event_time?: number;\n order_id?: number;\n event_id?: string;\n}\n","export * as env from './env';\nexport * as events from './events';\nexport * as mapping from './mapping';\n","import type { SendDataValue, SendResponse } from '@walkeros/core';\nimport type { SendServerOptions } from '@walkeros/server-core';\nimport type { Env } from '../types';\n\n/**\n * Example environment configurations for Meta Conversions API destination\n *\n * These environments provide standardized mock structures for testing\n * and development without requiring actual HTTP requests.\n */\n\n/**\n * Mock sendServer function that simulates successful HTTP responses\n */\nasync function mockSendServer(\n url: string,\n data?: SendDataValue,\n options?: SendServerOptions,\n): Promise<SendResponse> {\n // Simulate successful Meta API response\n return {\n ok: true,\n data: {\n events_received: 1,\n messages: [],\n fbtrace_id: 'mock-trace-id',\n },\n };\n}\n\n/**\n * Standard mock environment for push operations\n *\n * Use this for testing Meta Conversions API events without making\n * actual HTTP requests to Facebook's servers.\n */\nexport const push: Env = {\n sendServer: mockSendServer,\n};\n","import type { BodyParameters } from '../types';\nimport { getEvent } from '@walkeros/core';\n\nexport function Purchase(): BodyParameters {\n const event = getEvent('order complete');\n\n return {\n data: [\n {\n event_name: 'Purchase',\n event_time: event.timestamp / 1000,\n event_id: event.id,\n event_source_url: event.source.id,\n action_source: 'website',\n user_data: {\n external_id: [\n 'cc8e27118413234d4297ed00a02711365312c79325df9b5b8f4199cbd0b96e7e',\n '9176e6f336dbdb4f99b0e45cbd7e41e0e2323812b236822842a61ffbd362ac8c',\n ],\n },\n order_id: String(event.data.id),\n currency: 'EUR',\n value: Number(event.data.total),\n contents: event.nested\n .filter((item) => item.entity === 'product')\n .map((item) => ({\n id: String(item.data.id),\n quantity: Number(item.data.quantity) || 1,\n item_price: Number(item.data.price),\n })),\n num_items: 2,\n },\n ],\n };\n}\n","import type { WalkerOS } from '@walkeros/core';\nimport type { DestinationMeta } from '..';\nimport { isObject } from '@walkeros/core';\n\nexport const InitUserData: DestinationMeta.Settings = {\n pixelId: 'p1x3l1d',\n accessToken: 's3cr3t',\n user_data: {\n external_id: { set: ['user.device', 'user.session'] },\n },\n};\n\nexport const Purchase: DestinationMeta.Rule = {\n name: 'Purchase',\n data: {\n map: {\n order_id: 'data.id',\n currency: { key: 'data.currency', value: 'EUR' },\n value: 'data.total',\n contents: {\n loop: [\n 'nested',\n {\n condition: (entity) =>\n isObject(entity) && entity.entity === 'product',\n map: {\n id: 'data.id',\n item_price: 'data.price',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n num_items: {\n fn: (event) =>\n (event as WalkerOS.Event).nested.filter(\n (item) => item.entity === 'product',\n ).length,\n },\n },\n },\n};\n\nexport const config = {\n order: { complete: Purchase },\n} satisfies DestinationMeta.Rules;\n","import { zodToSchema } from '@walkeros/core';\nimport { SettingsSchema } from './settings';\nimport { MappingSchema } from './mapping';\n\nexport * from './primitives';\n\nexport { SettingsSchema, type Settings } from './settings';\nexport { MappingSchema, type Mapping } from './mapping';\n\n// JSON Schema\nexport const settings = zodToSchema(SettingsSchema);\nexport const mapping = zodToSchema(MappingSchema);\n","import { z } from '@walkeros/core';\nimport { ActionSourceSchema } from './primitives';\n\nexport const SettingsSchema = z.object({\n accessToken: z\n .string()\n .min(1)\n .describe(\n 'Meta access token for Conversions API authentication (like your_access_token)',\n ),\n pixelId: z\n .string()\n .regex(/^[0-9]+$/, 'Pixel ID must contain only digits')\n .describe(\n 'Meta Pixel ID from your Facebook Business account (like 1234567890)',\n ),\n action_source: ActionSourceSchema.describe(\n 'Source of the event (website, app, phone_call, etc.) (like website)',\n ).optional(),\n doNotHash: z\n .array(z.string())\n .describe(\n \"Array of user_data fields that should not be hashed (like ['client_ip_address', 'client_user_agent'])\",\n )\n .optional(),\n test_event_code: z\n .string()\n .describe(\n 'Test event code for debugging Meta Conversions API events (like TEST12345)',\n )\n .optional(),\n url: z\n .string()\n .url()\n .describe(\n 'Custom URL for Meta Conversions API endpoint (like https://graph.facebook.com/v17.0)',\n )\n .optional(),\n user_data: z\n .record(z.string(), z.string())\n .describe(\n \"Mapping configuration for user data fields (like { email: 'user.email', phone: 'user.phone' })\",\n )\n .optional(),\n});\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import { z } from '@walkeros/core';\n\n/**\n * Action Source Enum\n * Where the conversion event took place\n * https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/server-event\n */\nexport const ActionSourceSchema = z.enum([\n 'email',\n 'website',\n 'app',\n 'phone_call',\n 'chat',\n 'physical_store',\n 'system_generated',\n 'business_messaging',\n 'other',\n]);\n\n/**\n * Event Name\n * Standard Meta event names or custom event identifiers\n */\nexport const EventNameSchema = z.union([\n z.enum([\n 'AddPaymentInfo',\n 'AddToCart',\n 'AddToWishlist',\n 'CompleteRegistration',\n 'Contact',\n 'CustomizeProduct',\n 'Donate',\n 'FindLocation',\n 'InitiateCheckout',\n 'Lead',\n 'Purchase',\n 'Schedule',\n 'Search',\n 'StartTrial',\n 'SubmitApplication',\n 'Subscribe',\n 'ViewContent',\n ]),\n z.string(), // Allow custom event names\n]);\n","import { z } from '@walkeros/core';\n\n/**\n * Meta Conversions API Mapping Schema\n * Meta CAPI has no event-level mapping configuration\n */\nexport const MappingSchema = z.object({});\n\n/**\n * Type inference from MappingSchema\n */\nexport type Mapping = z.infer<typeof MappingSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAA2B;AAEpB,SAAS,UAAU,gBAA+B,CAAC,GAAW;AACnE,QAAMA,YAAY,cAAc,YAAY,CAAC;AAC7C,QAAM,EAAE,aAAa,QAAQ,IAAIA;AAEjC,MAAI,CAAC,YAAa,6BAAW,qCAAqC;AAClE,MAAI,CAAC,QAAS,6BAAW,iCAAiC;AAE1D,QAAM,iBAA2B;AAAA,IAC/B,GAAGA;AAAA,IACH;AAAA,IACA;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,eAAe,UAAU,eAAe;AACtD;;;ACTA,IAAAC,eAA0C;AAC1C,IAAAC,sBAA2B;;;ACR3B,IAAAC,eAA4C;AAC5C,yBAA8B;AAE9B,IAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;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AAM,WAAW,IAAI,CAAC;AAAA,EACpE;AACF;AAEA,IAAO,gBAAQ;","names":["settings","import_core","import_server_core","import_core","config","mapping","push","import_core","Purchase","import_core","import_core","import_core","import_core","import_core","config","mapping"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/config.ts","../src/push.ts","../src/hash.ts","../src/types/index.ts"],"sourcesContent":["import type { Destination } from './types';\nimport { getConfig } from './config';\nimport { push } from './push';\n\n// Types\nexport * as DestinationMeta from './types';\n\nexport const destinationMeta: Destination = {\n type: 'meta',\n\n config: {},\n\n async init({ config: partialConfig }) {\n const config = getConfig(partialConfig);\n return config;\n },\n\n async push(event, { config, mapping, data, collector, env }) {\n return await push(event, { config, mapping, data, collector, env });\n },\n};\n\nexport default destinationMeta;\n","import type { Config, Settings, PartialConfig } from './types';\nimport { throwError } from '@walkeros/core';\n\nexport function getConfig(partialConfig: PartialConfig = {}): Config {\n const settings = (partialConfig.settings || {}) as Partial<Settings>;\n const { accessToken, pixelId } = settings;\n\n if (!accessToken) throwError('Config settings accessToken missing');\n if (!pixelId) throwError('Config settings pixelId missing');\n\n const settingsConfig: Settings = {\n ...settings,\n accessToken,\n pixelId,\n };\n\n return { ...partialConfig, settings: settingsConfig };\n}\n","import type { WalkerOS } from '@walkeros/core';\nimport type {\n BodyParameters,\n CustomerInformationParameters,\n PushFn,\n ServerEventParameters,\n Env,\n} from './types';\nimport { getMappingValue, isObject } from '@walkeros/core';\nimport { sendServer } from '@walkeros/server-core';\nimport { hashEvent } from './hash';\n\nexport const push: PushFn = async function (\n event,\n { config, mapping, data, collector, env },\n) {\n const {\n accessToken,\n pixelId,\n action_source = 'website',\n doNotHash,\n test_event_code,\n url = 'https://graph.facebook.com/v22.0/',\n user_data,\n } = config.settings!;\n\n const eventData = isObject(data) ? data : {};\n const configData = config.data\n ? await getMappingValue(event, config.data)\n : {};\n const userDataCustom = user_data\n ? await getMappingValue(event, { map: user_data })\n : {};\n\n const userData: CustomerInformationParameters = {\n // Destination config\n ...(isObject(configData) && isObject(configData.user_data)\n ? configData.user_data\n : {}),\n // Custom user_data\n ...(isObject(userDataCustom) ? userDataCustom : {}),\n // Event mapping\n ...(isObject(eventData.user_data) ? eventData.user_data : {}),\n };\n\n if (userData.fbclid) {\n userData.fbc = formatClickId(\n userData.fbclid,\n collector?.session?.start || event.timestamp,\n );\n delete userData.fbclid;\n }\n const serverEvent: ServerEventParameters = {\n event_name: event.name,\n event_id: event.id,\n event_time: Math.round((event.timestamp || Date.now()) / 1000),\n action_source,\n ...eventData,\n user_data: userData,\n };\n\n if (action_source === 'website')\n serverEvent.event_source_url = event.source.id;\n\n const hashedServerEvent = await hashEvent(serverEvent, doNotHash);\n\n const body: BodyParameters = { data: [hashedServerEvent] };\n\n // Test event code\n if (test_event_code) body.test_event_code = test_event_code;\n\n const sendServerFn = env?.sendServer || sendServer;\n const result = await sendServerFn(\n `${url}${pixelId}/events?access_token=${accessToken}`,\n JSON.stringify(body),\n );\n\n if (isObject(result) && result.ok === false)\n throw new Error(JSON.stringify(result));\n};\n\nfunction formatClickId(clickId: unknown, time?: number): string | undefined {\n // https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/fbp-and-fbc#2--format-clickid\n\n if (!clickId) return;\n\n // Version is always \"fb\"\n const version = 'fb';\n\n // Subdomain ('com' = 0, 'example.com' = 1, 'www.example.com' = 2)\n const subdomainIndex = '1';\n\n // Get the current timestamp in milliseconds (or when the fbclid was observed)\n const creationTime = time || Date.now();\n\n return `${version}.${subdomainIndex}.${creationTime}.${clickId}`;\n}\n\nfunction lower(str: WalkerOS.Property): string {\n return String(str).toLocaleLowerCase();\n}\n","import { WalkerOS } from '@walkeros/core';\nimport { isArray, isObject, isString } from '@walkeros/core';\nimport { getHashServer } from '@walkeros/server-core';\n\nconst keysToHash = [\n 'em',\n 'ph',\n 'fn',\n 'ln',\n 'db',\n 'ge',\n 'ct',\n 'st',\n 'zp',\n 'country',\n 'external_id',\n];\n\nfunction shouldBeHashed(key: string, doNotHash: string[] = []): boolean {\n return keysToHash.includes(key) && !doNotHash.includes(key);\n}\n\ntype HashableValue = WalkerOS.AnyObject | unknown | unknown[];\n\nasync function processValue(\n value: unknown,\n shouldHash: boolean,\n): Promise<unknown> {\n if (!shouldHash) return value;\n if (isArray(value)) {\n return Promise.all(value.map((item) => getHashServer(String(item))));\n }\n return getHashServer(String(value));\n}\n\nexport async function hashEvent<T extends HashableValue>(\n value: T,\n doNotHash: string[] = [],\n): Promise<T> {\n if (!isObject(value)) return value;\n\n const isUserData = 'user_data' in value;\n const target = (isUserData ? value.user_data : value) as WalkerOS.AnyObject;\n\n const entries = await Promise.all(\n Object.entries(target).map(async ([k, v]) => [\n k,\n await processValue(v, isUserData && shouldBeHashed(k, doNotHash)),\n ]),\n );\n\n const result = entries.reduce((acc, [k, v]) => {\n if (isString(k)) acc[k] = v;\n return acc;\n }, {} as WalkerOS.AnyObject);\n\n return isUserData ? { ...value, user_data: result } : (result as T);\n}\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationServer, sendServer } from '@walkeros/server-core';\n\nexport interface Settings {\n accessToken: string;\n pixelId: string;\n action_source?: ActionSource;\n doNotHash?: string[];\n test_event_code?: string;\n url?: string;\n user_data?: WalkerOSMapping.Map;\n}\n\nexport interface Mapping {}\n\nexport interface Env extends DestinationServer.Env {\n sendServer?: typeof sendServer;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env>;\n\nexport interface Destination extends DestinationServer.Destination<Types> {\n init: DestinationServer.InitFn<Types>;\n}\n\nexport type Config = {\n settings: Settings;\n} & DestinationServer.Config<Types>;\n\nexport type InitFn = DestinationServer.InitFn<Types>;\nexport type PushFn = DestinationServer.PushFn<Types>;\n\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\n\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\n// https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/main-body\nexport interface BodyParameters {\n data: Array<ServerEventParameters>;\n test_event_code?: string;\n}\n\n/**\n * Represents the top‑level parameters for a server event sent via Meta's Conversions API.\n * https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/server-event\n */\nexport interface ServerEventParameters extends StandardParameters {\n /** The event name or custom event identifier. Required for deduplication. */\n event_name: EventName;\n\n /** Unix timestamp (in seconds) when the event actually occurred. GMT timezone. */\n event_time: number;\n\n /** Map of customer information for matching (emails, phone, etc.). */\n user_data: CustomerInformationParameters;\n\n /** Additional business data about the event. */\n custom_data?: Record<string, unknown>;\n\n /** URL of the page where the event occurred. */\n event_source_url?: string;\n\n /** If true, exclude this event from ads optimization (only attribution). */\n opt_out?: boolean;\n\n /** Unique ID for deduplication across Pixel and CAPI. */\n event_id?: string;\n\n /** Source of the event (e.g., website, app). */\n action_source: ActionSource;\n\n /** Processing options (e.g., ['LDU'] for CCPA limited data use). */\n data_processing_options?: DataProcessingOption[];\n\n /** Country code for data processing option (1 = USA, 0 = auto‑geolocate). */\n data_processing_options_country?: number;\n\n /** State code for data processing option (1000 = California, 0 = auto). */\n data_processing_options_state?: number;\n\n /** App‑specific data (required if action_source is 'app'). */\n app_data?: AppData;\n\n /** HTTP referrer header of the event. */\n referrer_url?: string;\n\n /** Metadata to link delayed events to past acquisition events. */\n original_event_data?: OriginalEventDataParameters;\n\n /** User segment for more context about the customer's relationship. */\n customer_segmentation?: CustomerSegmentation;\n}\n\nexport type EventName =\n | 'AddPaymentInfo'\n | 'AddToCart'\n | 'AddToWishlist'\n | 'CompleteRegistration'\n | 'Contact'\n | 'CustomizeProduct'\n | 'Donate'\n | 'FindLocation'\n | 'InitiateCheckout'\n | 'Lead'\n | 'Purchase'\n | 'Schedule'\n | 'Search'\n | 'StartTrial'\n | 'SubmitApplication'\n | 'Subscribe'\n | 'ViewContent'\n | string;\n\nexport type ActionSource =\n | 'email'\n | 'website'\n | 'app'\n | 'phone_call'\n | 'chat'\n | 'physical_store'\n | 'system_generated'\n | 'business_messaging'\n | 'other';\n\nexport type DataProcessingOption = 'LDU';\n\nexport type CustomerSegmentation =\n | 'new_customer_to_business'\n | 'new_customer_to_business_line'\n | 'new_customer_to_product_area'\n | 'new_customer_to_medium'\n | 'existing_customer_to_business'\n | 'existing_customer_to_business_line'\n | 'existing_customer_to_product_area'\n | 'existing_customer_to_medium'\n | 'customer_in_loyalty_program';\n\n/** Extended device info for app events (Android version 'a2', iOS 'i2') */\nexport interface AppData {\n /**\n * Comma-separated array of strings with fixed order:\n * [sdk_version, os_version, device_model, device_brand,\n * screen_width, screen_height, ...]\n */\n extinfo: string[];\n}\n\n// Customer Information Parameters\n// https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters\nexport interface CustomerInformationParameters {\n /** Email(s), SHA-256 hashed, lowercase and trimmed */\n em?: string | string[];\n\n /** Phone number(s), SHA-256 hashed, E.164 format (no leading 0s or symbols) */\n ph?: string | string[];\n\n /** First name(s), SHA-256 hashed, lowercase */\n fn?: string | string[];\n\n /** Last name(s), SHA-256 hashed, lowercase */\n ln?: string | string[];\n\n /** Date(s) of birth in YYYYMMDD, SHA-256 hashed */\n db?: string | string[];\n\n /** Gender(s) in lowercase single letter (\"m\", \"f\", etc.), SHA-256 hashed */\n ge?: string | string[];\n\n /** City name(s), SHA-256 hashed, lowercase */\n ct?: string | string[];\n\n /** State abbreviation(s), SHA-256 hashed, lowercase (e.g., \"ca\", \"ny\") */\n st?: string | string[];\n\n /** ZIP or postal code(s), SHA-256 hashed, lowercase */\n zp?: string | string[];\n\n /** Country code(s), SHA-256 hashed, lowercase (ISO 3166-1 alpha-2) */\n country?: string | string[];\n\n /** External IDs, unique per user. SHA-256 hash recommended */\n external_id?: string | string[];\n\n /** IPv4 or IPv6 address of client. Do NOT hash. */\n client_ip_address?: string;\n\n /** User agent string from browser. Do NOT hash. */\n client_user_agent?: string;\n\n /** fbclid parameter value from the URL. Do NOT hash. */\n fbclid?: string;\n\n /** Facebook click ID (_fbc cookie). Do NOT hash. */\n fbc?: string;\n\n /** Facebook browser ID (_fbp cookie). Do NOT hash. */\n fbp?: string;\n\n /** Subscription ID for the transaction. Do NOT hash. */\n subscription_id?: string;\n\n /** Facebook login ID (App-Scoped ID). Do NOT hash. */\n fb_login_id?: number;\n\n /** Meta Lead Ad lead ID. Do NOT hash. */\n lead_id?: number;\n\n /** Anonymous install ID. App events only. Do NOT hash. */\n anon_id?: string;\n\n /** Mobile advertiser ID (GAID/IDFA). Do NOT hash. */\n madid?: string;\n\n /** Facebook Page ID. Do NOT hash. */\n page_id?: string;\n\n /** Messenger Page-scoped user ID. Do NOT hash. */\n page_scoped_user_id?: string;\n\n /** Click to WhatsApp ad click ID. Do NOT hash. */\n ctwa_clid?: string;\n\n /** Instagram business account ID. Do NOT hash. */\n ig_account_id?: string;\n\n /** Instagram-scoped user ID. Do NOT hash. */\n ig_sid?: string;\n}\n\n// https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data\nexport interface StandardParameters {\n // Web and Offline parameters\n availability?: string;\n body_style?: string;\n checkin_date?: string;\n city?: string;\n condition_of_vehicle?: string;\n content_ids?: string[];\n content_type?: 'product' | 'product_group' | string;\n contents?: Array<{\n id: string;\n quantity?: number;\n item_price?: number;\n delivery_category?: string;\n }>;\n country?: string;\n currency?: string;\n delivery_category?: 'in_store' | 'curbside' | 'home_delivery' | string;\n departing_arrival_date?: string;\n departing_departure_date?: string;\n destination_airport?: string;\n destination_ids?: string[];\n dma_code?: string;\n drivetrain?: string;\n exterior_color?: string;\n fuel_type?: string;\n hotel_score?: number;\n interior_color?: string;\n lead_event_source?: string;\n lease_end_date?: string;\n lease_start_date?: string;\n listing_type?: string;\n make?: string;\n // @TODO is mileage an object?\n 'mileage.unit'?: string;\n 'mileage.value'?: number;\n model?: string;\n neighborhood?: string;\n net_revenue?: number;\n num_adults?: number;\n num_children?: number;\n num_infants?: number;\n num_items?: number;\n order_id?: string;\n origin_airport?: string;\n postal_code?: string;\n predicted_ltv?: number;\n preferred_baths_range?: string;\n preferred_beds_range?: string;\n preferred_neighborhoods?: string[];\n preferred_num_stops?: number;\n preferred_price_range?: string;\n preferred_star_ratings?: [number, number];\n price?: string;\n product_catalog_id?: string;\n property_type?: string;\n region?: string;\n returning_arrival_date?: string;\n returning_departure_date?: string;\n search_string?: string;\n state_of_vehicle?: string;\n suggested_destinations?: string[];\n suggested_home_listings?: string[];\n suggested_hotels?: string[];\n suggested_jobs?: string[];\n suggested_local_service_businesses?: string[];\n suggested_location_based_items?: string[];\n suggested_vehicles?: string[];\n transmission?: string;\n travel_class?: string;\n travel_end?: string;\n travel_start?: string;\n trim?: string;\n\n // App-specific parameters (with fb_ prefix)\n fb_availability?: string;\n fb_body_style?: string;\n fb_checkin_date?: string;\n fb_city?: string;\n fb_condition_of_vehicle?: string;\n fb_content_ids?: string[];\n fb_content_type?: string;\n fb_contents?: Array<{ id: string; quantity?: number; item_price?: number }>;\n fb_country?: string;\n fb_currency?: string;\n fb_delivery_category?: string;\n fb_departing_arrival_date?: string;\n fb_departing_departure_date?: string;\n fb_destination_airport?: string;\n fb_destination_ids?: string[];\n fb_dma_code?: string;\n fb_drivetrain?: string;\n fb_exterior_color?: string;\n fb_fuel_type?: string;\n fb_hotel_score?: number;\n fb_interior_color?: string;\n fb_lease_end_date?: string;\n fb_lease_start_date?: string;\n fb_listing_type?: string;\n fb_make?: string;\n // @TODO is fb_mileage an object?\n 'fb_mileage.unit'?: string;\n 'fb_mileage.value'?: number;\n fb_model?: string;\n fb_neighborhood?: string;\n fb_num_adults?: number;\n fb_num_children?: number;\n fb_num_infants?: number;\n fb_num_items?: number;\n fb_order_id?: string;\n fb_origin_airport?: string;\n fb_postal_code?: string;\n fb_predicted_ltv?: number;\n fb_preferred_baths_range?: string;\n fb_preferred_beds_range?: string;\n fb_preferred_neighborhoods?: string[];\n fb_preferred_num_stops?: number;\n fb_preferred_price_range?: string;\n fb_preferred_star_ratings?: [number, number];\n fb_price?: string;\n fb_product_catalog_id?: string;\n fb_property_type?: string;\n fb_region?: string;\n fb_returning_arrival_date?: string;\n fb_returning_departure_date?: string;\n fb_search_string?: string;\n fb_state_of_vehicle?: string;\n fb_suggested_destinations?: string[];\n fb_suggested_home_listings?: string[];\n fb_suggested_hotels?: string[];\n fb_suggested_jobs?: string[];\n fb_suggested_local_service_businesses?: string[];\n fb_suggested_location_based_items?: string[];\n fb_suggested_vehicles?: string[];\n fb_transmission?: string;\n fb_travel_class?: string;\n fb_travel_end?: string;\n fb_travel_start?: string;\n\n // Offline-specific parameters\n user_bucket?: string;\n value?: number;\n vin?: string;\n year?: number;\n item_number?: string;\n}\n\nexport interface OriginalEventDataParameters {\n event_name?: EventName;\n event_time?: number;\n order_id?: number;\n event_id?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAA2B;AAEpB,SAAS,UAAU,gBAA+B,CAAC,GAAW;AACnE,QAAM,WAAY,cAAc,YAAY,CAAC;AAC7C,QAAM,EAAE,aAAa,QAAQ,IAAI;AAEjC,MAAI,CAAC,YAAa,6BAAW,qCAAqC;AAClE,MAAI,CAAC,QAAS,6BAAW,iCAAiC;AAE1D,QAAM,iBAA2B;AAAA,IAC/B,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,eAAe,UAAU,eAAe;AACtD;;;ACTA,IAAAA,eAA0C;AAC1C,IAAAC,sBAA2B;;;ACR3B,IAAAC,eAA4C;AAC5C,yBAA8B;AAE9B,IAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,eAAe,KAAa,YAAsB,CAAC,GAAY;AACtE,SAAO,WAAW,SAAS,GAAG,KAAK,CAAC,UAAU,SAAS,G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;;AEhGA;;;AJOO,IAAM,kBAA+B;AAAA,EAC1C,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,MAAM,KAAK,EAAE,QAAQ,cAAc,GAAG;AACpC,UAAM,SAAS,UAAU,aAAa;AACtC,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,KAAK,OAAO,EAAE,QAAQ,SAAS,MAAM,WAAW,IAAI,GAAG;AAC3D,WAAO,MAAM,KAAK,OAAO,EAAE,QAAQ,SAAS,MAAM,WAAW,IAAI,CAAC;AAAA,EACpE;AACF;AAEA,IAAO,gBAAQ;","names":["import_core","import_server_core","import_core"]}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var e=Object.defineProperty,t=(t,a)=>{for(var r in a)e(t,r,{get:a[r],enumerable:!0})};import{throwError as a}from"@walkeros/core";import{getMappingValue as r,isObject as n}from"@walkeros/core";import{sendServer as i}from"@walkeros/server-core";import{isArray as o,isObject as s,isString as c}from"@walkeros/core";import{getHashServer as d}from"@walkeros/server-core";var u=["em","ph","fn","ln","db","ge","ct","st","zp","country","external_id"];function l(e,t=[]){return u.includes(e)&&!t.includes(e)}async function m(e,t){return t?o(e)?Promise.all(e.map(e=>d(String(e)))):d(String(e)):e}var p=async function(e,{config:t,mapping:a,data:o,collector:d,env:u}){var p;const{accessToken:f,pixelId:_,action_source:g="website",doNotHash:v,test_event_code:b,url:h="https://graph.facebook.com/v22.0/",user_data:k}=t.settings,y=n(o)?o:{},w=t.data?await r(e,t.data):{},S=k?await r(e,{map:k}):{},x={...n(w)&&n(w.user_data)?w.user_data:{},...n(S)?S:{},...n(y.user_data)?y.user_data:{}};x.fbclid&&(x.fbc=function(e,t){if(!e)return;const a="fb",r="1",n=t||Date.now();return`${a}.${r}.${n}.${e}`}(x.fbclid,(null==(p=null==d?void 0:d.session)?void 0:p.start)||e.timestamp),delete x.fbclid);const P={event_name:e.name,event_id:e.id,event_time:Math.round((e.timestamp||Date.now())/1e3),action_source:g,...y,user_data:x};"website"===g&&(P.event_source_url=e.source.id);const I=await async function(e,t=[]){if(!s(e))return e;const a="user_data"in e,r=a?e.user_data:e,n=(await Promise.all(Object.entries(r).map(async([e,r])=>[e,await m(r,a&&l(e,t))]))).reduce((e,[t,a])=>(c(t)&&(e[t]=a),e),{});return a?{...e,user_data:n}:n}(P,v),C={data:[I]};b&&(C.test_event_code=b);const T=(null==u?void 0:u.sendServer)||i,A=await T(`${h}${_}/events?access_token=${f}`,JSON.stringify(C));if(n(A)&&!1===A.ok)throw new Error(JSON.stringify(A))};var f={},_={};t(_,{env:()=>g,events:()=>b,mapping:()=>y});var g={};t(g,{push:()=>v});var v={sendServer:async function(e,t,a){return{ok:!0,data:{events_received:1,messages:[],fbtrace_id:"mock-trace-id"}}}},b={};t(b,{Purchase:()=>k});import{getEvent as h}from"@walkeros/core";function k(){const e=h("order complete");return{data:[{event_name:"Purchase",event_time:e.timestamp/1e3,event_id:e.id,event_source_url:e.source.id,action_source:"website",user_data:{external_id:["cc8e27118413234d4297ed00a02711365312c79325df9b5b8f4199cbd0b96e7e","9176e6f336dbdb4f99b0e45cbd7e41e0e2323812b236822842a61ffbd362ac8c"]},order_id:String(e.data.id),currency:"EUR",value:Number(e.data.total),contents:e.nested.filter(e=>"product"===e.entity).map(e=>({id:String(e.data.id),quantity:Number(e.data.quantity)||1,item_price:Number(e.data.price)})),num_items:2}]}}var y={};t(y,{InitUserData:()=>S,Purchase:()=>x,config:()=>P});import{isObject as w}from"@walkeros/core";var S={pixelId:"p1x3l1d",accessToken:"s3cr3t",user_data:{external_id:{set:["user.device","user.session"]}}},x={name:"Purchase",data:{map:{order_id:"data.id",currency:{key:"data.currency",value:"EUR"},value:"data.total",contents:{loop:["nested",{condition:e=>w(e)&&"product"===e.entity,map:{id:"data.id",item_price:"data.price",quantity:{key:"data.quantity",value:1}}}]},num_items:{fn:e=>e.nested.filter(e=>"product"===e.entity).length}}}},P={order:{complete:x}},I={};t(I,{ActionSourceSchema:()=>M,EventNameSchema:()=>N,MappingSchema:()=>j,SettingsSchema:()=>$,mapping:()=>E,settings:()=>O});import{zodToSchema as C}from"@walkeros/core";import{z as T}from"@walkeros/core";import{z as A}from"@walkeros/core";var M=A.enum(["email","website","app","phone_call","chat","physical_store","system_generated","business_messaging","other"]),N=A.union([A.enum(["AddPaymentInfo","AddToCart","AddToWishlist","CompleteRegistration","Contact","CustomizeProduct","Donate","FindLocation","InitiateCheckout","Lead","Purchase","Schedule","Search","StartTrial","SubmitApplication","Subscribe","ViewContent"]),A.string()]),$=T.object({accessToken:T.string().min(1).describe("Meta access token for Conversions API authentication (like your_access_token)"),pixelId:T.string().regex(/^[0-9]+$/,"Pixel ID must contain only digits").describe("Meta Pixel ID from your Facebook Business account (like 1234567890)"),action_source:M.describe("Source of the event (website, app, phone_call, etc.) (like website)").optional(),doNotHash:T.array(T.string()).describe("Array of user_data fields that should not be hashed (like ['client_ip_address', 'client_user_agent'])").optional(),test_event_code:T.string().describe("Test event code for debugging Meta Conversions API events (like TEST12345)").optional(),url:T.string().url().describe("Custom URL for Meta Conversions API endpoint (like https://graph.facebook.com/v17.0)").optional(),user_data:T.record(T.string(),T.string()).describe("Mapping configuration for user data fields (like { email: 'user.email', phone: 'user.phone' })").optional()});import{z as D}from"@walkeros/core";var j=D.object({}),O=C($),E=C(j),q={type:"meta",config:{},async init({config:e}){const t=function(e={}){const t=e.settings||{},{accessToken:r,pixelId:n}=t;r||a("Config settings accessToken missing"),n||a("Config settings pixelId missing");const i={...t,accessToken:r,pixelId:n};return{...e,settings:i}}(e);return t},push:async(e,{config:t,mapping:a,data:r,collector:n,env:i})=>await p(e,{config:t,mapping:a,data:r,collector:n,env:i})},z=q;export{f as DestinationMeta,z as default,q as destinationMeta,_ as examples,I as schemas};//# sourceMappingURL=index.mjs.map
1
+ import{throwError as e}from"@walkeros/core";import{getMappingValue as t,isObject as n}from"@walkeros/core";import{sendServer as a}from"@walkeros/server-core";import{isArray as s,isObject as r,isString as o}from"@walkeros/core";import{getHashServer as i}from"@walkeros/server-core";var c=["em","ph","fn","ln","db","ge","ct","st","zp","country","external_id"];function d(e,t=[]){return c.includes(e)&&!t.includes(e)}async function u(e,t){return t?s(e)?Promise.all(e.map(e=>i(String(e)))):i(String(e)):e}var l=async function(e,{config:s,mapping:i,data:c,collector:l,env:f}){var m;const{accessToken:p,pixelId:g,action_source:_="website",doNotHash:v,test_event_code:w,url:k="https://graph.facebook.com/v22.0/",user_data:b}=s.settings,y=n(c)?c:{},h=s.data?await t(e,s.data):{},$=b?await t(e,{map:b}):{},x={...n(h)&&n(h.user_data)?h.user_data:{},...n($)?$:{},...n(y.user_data)?y.user_data:{}};x.fbclid&&(x.fbc=function(e,t){if(!e)return;const n="fb",a="1",s=t||Date.now();return`${n}.${a}.${s}.${e}`}(x.fbclid,(null==(m=null==l?void 0:l.session)?void 0:m.start)||e.timestamp),delete x.fbclid);const S={event_name:e.name,event_id:e.id,event_time:Math.round((e.timestamp||Date.now())/1e3),action_source:_,...y,user_data:x};"website"===_&&(S.event_source_url=e.source.id);const I=await async function(e,t=[]){if(!r(e))return e;const n="user_data"in e,a=n?e.user_data:e,s=(await Promise.all(Object.entries(a).map(async([e,a])=>[e,await u(a,n&&d(e,t))]))).reduce((e,[t,n])=>(o(t)&&(e[t]=n),e),{});return n?{...e,user_data:s}:s}(S,v),O={data:[I]};w&&(O.test_event_code=w);const T=(null==f?void 0:f.sendServer)||a,D=await T(`${k}${g}/events?access_token=${p}`,JSON.stringify(O));if(n(D)&&!1===D.ok)throw new Error(JSON.stringify(D))};var f={},m={type:"meta",config:{},async init({config:t}){const n=function(t={}){const n=t.settings||{},{accessToken:a,pixelId:s}=n;a||e("Config settings accessToken missing"),s||e("Config settings pixelId missing");const r={...n,accessToken:a,pixelId:s};return{...t,settings:r}}(t);return n},push:async(e,{config:t,mapping:n,data:a,collector:s,env:r})=>await l(e,{config:t,mapping:n,data:a,collector:s,env:r})},p=m;export{f as DestinationMeta,p as default,m as destinationMeta};//# sourceMappingURL=index.mjs.map