@walkeros/server-destination-mparticle 4.8.1 → 4.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +6 -1
- package/dist/dev.d.mts +5 -2
- package/dist/dev.d.ts +5 -2
- package/dist/dev.js +1 -1
- package/dist/dev.js.map +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/dev.mjs.map +1 -1
- package/dist/examples/index.d.mts +4 -1
- package/dist/examples/index.d.ts +4 -1
- package/dist/examples/index.js +13 -5
- package/dist/examples/index.mjs +14 -6
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/walkerOS.json +63 -4
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @walkeros/server-destination-mparticle
|
|
2
2
|
|
|
3
|
+
## 4.8.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2374f54: A failed request is reported as a failed push (dead-letter queue, one
|
|
8
|
+
ERROR line with the status) instead of counting as delivered or being logged
|
|
9
|
+
at debug. Events a destination cannot send, such as a missing user identifier,
|
|
10
|
+
fail with `missing-input`. Rules with `silent: true` send no event of their
|
|
11
|
+
own.
|
|
12
|
+
- Updated dependencies [2374f54]
|
|
13
|
+
- Updated dependencies [7e5fc27]
|
|
14
|
+
- Updated dependencies [2374f54]
|
|
15
|
+
- Updated dependencies [964590a]
|
|
16
|
+
- Updated dependencies [4100ede]
|
|
17
|
+
- Updated dependencies [2374f54]
|
|
18
|
+
- Updated dependencies [2374f54]
|
|
19
|
+
- Updated dependencies [15eb7b2]
|
|
20
|
+
- Updated dependencies [33a2779]
|
|
21
|
+
- Updated dependencies [33a2779]
|
|
22
|
+
- Updated dependencies [2374f54]
|
|
23
|
+
- @walkeros/core@4.8.2
|
|
24
|
+
- @walkeros/server-core@4.8.2
|
|
25
|
+
|
|
3
26
|
## 4.8.1
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -32,7 +32,12 @@ npm install @walkeros/server-destination-mparticle
|
|
|
32
32
|
"destinations": {
|
|
33
33
|
"mparticle": {
|
|
34
34
|
"package": "@walkeros/server-destination-mparticle",
|
|
35
|
-
"config": {
|
|
35
|
+
"config": {
|
|
36
|
+
"settings": {
|
|
37
|
+
"apiKey": "YOUR_API_KEY",
|
|
38
|
+
"apiSecret": "YOUR_API_SECRET"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
}
|
package/dist/dev.d.mts
CHANGED
|
@@ -53,7 +53,7 @@ declare const SettingsSchema: z.ZodObject<{
|
|
|
53
53
|
consent: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
54
54
|
ip: z.ZodOptional<z.ZodUnknown>;
|
|
55
55
|
sourceRequestId: z.ZodOptional<z.ZodUnknown>;
|
|
56
|
-
}, z.core.$
|
|
56
|
+
}, z.core.$strict>;
|
|
57
57
|
type Settings = z.infer<typeof SettingsSchema>;
|
|
58
58
|
|
|
59
59
|
declare const MappingSchema: z.ZodObject<{
|
|
@@ -136,13 +136,16 @@ declare const commercePurchase: Flow.StepExample;
|
|
|
136
136
|
* come from the batch-level settings mappings, not the event payload.
|
|
137
137
|
*/
|
|
138
138
|
declare const identityAndAttributes: Flow.StepExample;
|
|
139
|
+
/** A silent rule sends nothing to mParticle. */
|
|
140
|
+
declare const silentRule: Flow.StepExample;
|
|
139
141
|
|
|
140
142
|
declare const step_commercePurchase: typeof commercePurchase;
|
|
141
143
|
declare const step_customEvent: typeof customEvent;
|
|
142
144
|
declare const step_identityAndAttributes: typeof identityAndAttributes;
|
|
143
145
|
declare const step_screenView: typeof screenView;
|
|
146
|
+
declare const step_silentRule: typeof silentRule;
|
|
144
147
|
declare namespace step {
|
|
145
|
-
export { step_commercePurchase as commercePurchase, step_customEvent as customEvent, step_identityAndAttributes as identityAndAttributes, step_screenView as screenView };
|
|
148
|
+
export { step_commercePurchase as commercePurchase, step_customEvent as customEvent, step_identityAndAttributes as identityAndAttributes, step_screenView as screenView, step_silentRule as silentRule };
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
declare const index_env: typeof env;
|
package/dist/dev.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ declare const SettingsSchema: z.ZodObject<{
|
|
|
53
53
|
consent: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
54
54
|
ip: z.ZodOptional<z.ZodUnknown>;
|
|
55
55
|
sourceRequestId: z.ZodOptional<z.ZodUnknown>;
|
|
56
|
-
}, z.core.$
|
|
56
|
+
}, z.core.$strict>;
|
|
57
57
|
type Settings = z.infer<typeof SettingsSchema>;
|
|
58
58
|
|
|
59
59
|
declare const MappingSchema: z.ZodObject<{
|
|
@@ -136,13 +136,16 @@ declare const commercePurchase: Flow.StepExample;
|
|
|
136
136
|
* come from the batch-level settings mappings, not the event payload.
|
|
137
137
|
*/
|
|
138
138
|
declare const identityAndAttributes: Flow.StepExample;
|
|
139
|
+
/** A silent rule sends nothing to mParticle. */
|
|
140
|
+
declare const silentRule: Flow.StepExample;
|
|
139
141
|
|
|
140
142
|
declare const step_commercePurchase: typeof commercePurchase;
|
|
141
143
|
declare const step_customEvent: typeof customEvent;
|
|
142
144
|
declare const step_identityAndAttributes: typeof identityAndAttributes;
|
|
143
145
|
declare const step_screenView: typeof screenView;
|
|
146
|
+
declare const step_silentRule: typeof silentRule;
|
|
144
147
|
declare namespace step {
|
|
145
|
-
export { step_commercePurchase as commercePurchase, step_customEvent as customEvent, step_identityAndAttributes as identityAndAttributes, step_screenView as screenView };
|
|
148
|
+
export { step_commercePurchase as commercePurchase, step_customEvent as customEvent, step_identityAndAttributes as identityAndAttributes, step_screenView as screenView, step_silentRule as silentRule };
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
declare const index_env: typeof env;
|
package/dist/dev.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,s=(e,r)=>{for(var i in r)t(e,i,{get:r[i],enumerable:!0})},o={};s(o,{examples:()=>
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,s=(e,r)=>{for(var i in r)t(e,i,{get:r[i],enumerable:!0})},o={};s(o,{examples:()=>w,schemas:()=>a}),module.exports=(e=o,((e,s,o,a)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let c of i(s))n.call(e,c)||c===o||t(e,c,{get:()=>s[c],enumerable:!(a=r(s,c))||a.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a={};s(a,{CustomEventTypeSchema:()=>l,EnvironmentSchema:()=>d,EventTypeSchema:()=>v,MappingSchema:()=>g,PodSchema:()=>p,SettingsSchema:()=>_,mapping:()=>y,settings:()=>b});var c=require("@walkeros/core/dev"),u=require("@walkeros/core/dev"),m=require("@walkeros/core/dev"),p=m.z.enum(["us1","us2","eu1","au1"]),d=m.z.enum(["production","development"]),v=m.z.enum(["custom_event","screen_view","commerce_event"]),l=m.z.enum(["navigation","location","search","transaction","user_content","user_preference","social","media","attribution","other"]),_=u.z.object({apiKey:u.z.string().min(1).describe("mParticle input feed API key from the mParticle dashboard (Setup > Inputs > Feeds)."),apiSecret:u.z.string().min(1).describe("mParticle input feed API secret paired with apiKey. Used for HTTP Basic auth."),pod:p.describe("mParticle data pod selecting the regional endpoint. Default: 'us1'.").optional(),environment:d.describe("Environment the batch targets. Default: 'production'.").optional(),userIdentities:u.z.record(u.z.string(),u.z.unknown()).describe("Mapping that resolves to user_identities per batch. Keys are mParticle identity types (like customer_id, email); values are walkerOS mapping values.").optional(),userAttributes:u.z.unknown().describe("Mapping value that resolves to the user_attributes object placed on the batch.").optional(),consent:u.z.record(u.z.string(),u.z.unknown()).describe("Static consent_state envelope forwarded verbatim on the batch. See mParticle consent_state docs.").optional(),ip:u.z.unknown().describe("Mapping value resolving to the client IP for the batch.").optional(),sourceRequestId:u.z.unknown().describe("Mapping value resolving to the source_request_id for the batch. Falls back to event.id when unset.").optional()}).strict(),h=require("@walkeros/core/dev"),g=h.z.object({eventType:v.describe("Per-event mParticle event type. Default: 'custom_event'.").optional(),customEventType:l.describe("Custom event type category for 'custom_event'. Default: 'other'.").optional(),commerce:h.z.unknown().describe("Mapping value resolving to the commerce fields (product_action, currency_code, products, ...) for a commerce_event.").optional(),userIdentities:h.z.record(h.z.string(),h.z.unknown()).describe("Per-event override mapping for user_identities. Merged over settings.userIdentities.").optional(),userAttributes:h.z.unknown().describe("Per-event override mapping for user_attributes.").optional()}),b=(0,c.zodToSchema)(_),y=(0,c.zodToSchema)(g),w={};s(w,{env:()=>f,step:()=>P});var f={};s(f,{push:()=>S,simulation:()=>z});var S={sendServer:async()=>({data:{}})},z=["sendServer"],P={};s(P,{commercePurchase:()=>x,customEvent:()=>E,identityAndAttributes:()=>T,screenView:()=>q,silentRule:()=>j});var k=require("@walkeros/core"),O="https://s2s.mparticle.com/v2/events",A={headers:{Authorization:"Basic a2V5OnNlY3JldA==","Content-Type":"application/json"}},E={title:"Custom event",description:"A walker event is sent to mParticle as a custom_event with user identities resolved from destination settings.",in:(0,k.getEvent)("product view",{id:"ev-1700000100000",timestamp:17000001e5,data:{id:"SKU-A1",name:"Shoe",price:129.99},user:{id:"user-123"},source:{type:"express",platform:"server"}}),mapping:void 0,out:[["sendServer",O,JSON.stringify({events:[{event_type:"custom_event",data:{event_name:"product view",custom_event_type:"other",timestamp_unixtime_ms:17000001e5,source_message_id:"ev-1700000100000"}}],environment:"production",user_identities:{customer_id:"user-123"},source_request_id:"ev-1700000100000"}),A]]},q={title:"Screen view",description:"A page view is mapped to an mParticle screen_view event with the event name as the screen name.",in:(0,k.getEvent)("page view",{id:"ev-1700000200000",timestamp:17000002e5,data:{title:"Checkout",path:"/checkout"},user:{id:"user-123"},source:{type:"express",platform:"server"}}),mapping:{settings:{eventType:"screen_view"}},out:[["sendServer",O,JSON.stringify({events:[{event_type:"screen_view",data:{screen_name:"page view",timestamp_unixtime_ms:17000002e5,source_message_id:"ev-1700000200000"}}],environment:"production",user_identities:{customer_id:"user-123"},source_request_id:"ev-1700000200000"}),A]]},x={title:"Commerce purchase",description:"A completed order becomes an mParticle commerce_event with a purchase product_action block.",in:(0,k.getEvent)("order complete",{id:"ev-1700000300000",timestamp:17000003e5,data:{id:"ORD-300",value:249.99,currency:"EUR"},user:{id:"user-123"},source:{type:"express",platform:"server"}}),mapping:{settings:{eventType:"commerce_event",commerce:{map:{currency_code:"data.currency",product_action:{map:{action:{value:"purchase"},transaction_id:"data.id",total_amount:"data.value"}}}}}},out:[["sendServer",O,JSON.stringify({events:[{event_type:"commerce_event",data:{currency_code:"EUR",product_action:{action:"purchase",transaction_id:"ORD-300",total_amount:249.99},timestamp_unixtime_ms:17000003e5,source_message_id:"ev-1700000300000"}}],environment:"production",user_identities:{customer_id:"user-123"},source_request_id:"ev-1700000300000"}),A]]},T={title:"User identities",description:"A form submission sends a custom_event whose batch carries user_identities resolved from destination settings.",in:(0,k.createEvent)({name:"form submit",id:"ev-1700000400000",timestamp:17000004e5,data:{type:"newsletter"},user:{id:"user-123",email:"user@example.com"},source:{type:"express",platform:"server"}}),mapping:void 0,out:[["sendServer",O,JSON.stringify({events:[{event_type:"custom_event",data:{event_name:"form submit",custom_event_type:"other",timestamp_unixtime_ms:17000004e5,source_message_id:"ev-1700000400000"}}],environment:"production",user_identities:{customer_id:"user-123",email:"user@example.com"},source_request_id:"ev-1700000400000"}),A]]},j={public:!1,description:"A rule with silent: true sends no request to mParticle.",in:(0,k.getEvent)("page view",{timestamp:170000099e4}),mapping:{silent:!0},out:[]};//# sourceMappingURL=dev.js.map
|
package/dist/dev.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dev.ts","../src/schemas/index.ts","../src/schemas/settings.ts","../src/schemas/primitives.ts","../src/schemas/mapping.ts","../src/examples/index.ts","../src/examples/env.ts","../src/examples/step.ts"],"sourcesContent":["export * as schemas from './schemas';\nexport * as examples from './examples';\n","import { zodToSchema } from '@walkeros/core/dev';\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/dev';\nimport { EnvironmentSchema, PodSchema } from './primitives';\n\nexport const SettingsSchema = z.object({\n apiKey: z\n .string()\n .min(1)\n .describe(\n 'mParticle input feed API key from the mParticle dashboard (Setup > Inputs > Feeds).',\n ),\n apiSecret: z\n .string()\n .min(1)\n .describe(\n 'mParticle input feed API secret paired with apiKey. Used for HTTP Basic auth.',\n ),\n pod: PodSchema.describe(\n \"mParticle data pod selecting the regional endpoint. Default: 'us1'.\",\n ).optional(),\n environment: EnvironmentSchema.describe(\n \"Environment the batch targets. Default: 'production'.\",\n ).optional(),\n userIdentities: z\n .record(z.string(), z.unknown())\n .describe(\n 'Mapping that resolves to user_identities per batch. Keys are mParticle identity types (like customer_id, email); values are walkerOS mapping values.',\n )\n .optional(),\n userAttributes: z\n .unknown()\n .describe(\n 'Mapping value that resolves to the user_attributes object placed on the batch.',\n )\n .optional(),\n consent: z\n .record(z.string(), z.unknown())\n .describe(\n 'Static consent_state envelope forwarded verbatim on the batch. See mParticle consent_state docs.',\n )\n .optional(),\n ip: z\n .unknown()\n .describe('Mapping value resolving to the client IP for the batch.')\n .optional(),\n sourceRequestId: z\n .unknown()\n .describe(\n 'Mapping value resolving to the source_request_id for the batch. Falls back to event.id when unset.',\n )\n .optional(),\n});\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import { z } from '@walkeros/core/dev';\n\n/** mParticle data pod (regional endpoint selector). */\nexport const PodSchema = z.enum(['us1', 'us2', 'eu1', 'au1']);\n\n/** Target environment for the batch. */\nexport const EnvironmentSchema = z.enum(['production', 'development']);\n\n/** Supported mParticle event types emitted by this destination. */\nexport const EventTypeSchema = z.enum([\n 'custom_event',\n 'screen_view',\n 'commerce_event',\n]);\n\n/** mParticle custom event category for `custom_event`. */\nexport const CustomEventTypeSchema = z.enum([\n 'navigation',\n 'location',\n 'search',\n 'transaction',\n 'user_content',\n 'user_preference',\n 'social',\n 'media',\n 'attribution',\n 'other',\n]);\n","import { z } from '@walkeros/core/dev';\nimport { CustomEventTypeSchema, EventTypeSchema } from './primitives';\n\nexport const MappingSchema = z.object({\n eventType: EventTypeSchema.describe(\n \"Per-event mParticle event type. Default: 'custom_event'.\",\n ).optional(),\n customEventType: CustomEventTypeSchema.describe(\n \"Custom event type category for 'custom_event'. Default: 'other'.\",\n ).optional(),\n commerce: z\n .unknown()\n .describe(\n 'Mapping value resolving to the commerce fields (product_action, currency_code, products, ...) for a commerce_event.',\n )\n .optional(),\n userIdentities: z\n .record(z.string(), z.unknown())\n .describe(\n 'Per-event override mapping for user_identities. Merged over settings.userIdentities.',\n )\n .optional(),\n userAttributes: z\n .unknown()\n .describe('Per-event override mapping for user_attributes.')\n .optional(),\n});\n\nexport type Mapping = z.infer<typeof MappingSchema>;\n","export * as env from './env';\nexport * as step from './step';\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 mParticle Events API destination.\n *\n * Provides a standardized mock `sendServer` so tests and simulations can\n * run without making real HTTP calls to mParticle.\n */\n\ntype MockSendServer = (\n url: string,\n data?: SendDataValue,\n options?: SendServerOptions,\n) => Promise<SendResponse>;\n\nconst mockSendServer: MockSendServer = async () => {\n // Simulates mParticle's typical 202 Accepted response for the Events API.\n return {\n ok: true,\n data: {},\n };\n};\n\n/**\n * Standard mock environment for push operations.\n */\nexport const push: Env = {\n sendServer: mockSendServer,\n};\n\nexport const simulation = ['sendServer'];\n","import type { Flow } from '@walkeros/core';\nimport { getEvent } from '@walkeros/core';\n\n/**\n * mParticle Events API step examples.\n *\n * At push time, the destination calls\n * `env.sendServer(endpoint, JSON.stringify(batch), options)` where\n * endpoint = `buildEndpoint(pod)` (default pod `us1` → `https://s2s.mparticle.com/v2/events`)\n * batch = the mParticle v2 batch envelope\n *\n * Test fixture pins `apiKey = 'key'`, `apiSecret = 'secret'`, pod `us1`, so\n * every call targets that endpoint with `Authorization: Basic a2V5OnNlY3JldA==`.\n *\n * The batch keys appear in the order the destination constructs them:\n * 1. events (always a single-element array)\n * 2. environment ('production' by default)\n * 3. user_identities (only when resolved)\n * 4. user_attributes (only when resolved)\n * 5. ip (only when mapped)\n * 6. source_request_id (falls back to `event.id`)\n * 7. consent_state, context (unused here)\n *\n * `options` carries Authorization + Content-Type headers.\n */\nconst ENDPOINT = 'https://s2s.mparticle.com/v2/events';\nconst OPTIONS = {\n headers: {\n // Basic base64('key:secret')\n Authorization: 'Basic a2V5OnNlY3JldA==',\n 'Content-Type': 'application/json',\n },\n};\n\n/**\n * Default custom_event - a walkerOS event with no `eventType` mapping.\n * mParticle wraps it as a `custom_event` with the default `other` category.\n * user_identities are resolved at the batch level from\n * `settings.userIdentities`.\n */\nexport const customEvent: Flow.StepExample = {\n title: 'Custom event',\n description:\n 'A walker event is sent to mParticle as a custom_event with user identities resolved from destination settings.',\n in: getEvent('product view', {\n id: 'ev-1700000100000',\n timestamp: 1700000100000,\n data: { id: 'SKU-A1', name: 'Shoe', price: 129.99 },\n user: { id: 'user-123' },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: undefined,\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'custom_event',\n data: {\n event_name: 'product view',\n custom_event_type: 'other',\n timestamp_unixtime_ms: 1700000100000,\n source_message_id: 'ev-1700000100000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n },\n source_request_id: 'ev-1700000100000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/**\n * screen_view event - mapping.settings.eventType switches the mParticle\n * event shape. Uses event name as the `screen_name`.\n */\nexport const screenView: Flow.StepExample = {\n title: 'Screen view',\n description:\n 'A page view is mapped to an mParticle screen_view event with the event name as the screen name.',\n in: getEvent('page view', {\n id: 'ev-1700000200000',\n timestamp: 1700000200000,\n data: { title: 'Checkout', path: '/checkout' },\n user: { id: 'user-123' },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: {\n settings: { eventType: 'screen_view' },\n },\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'screen_view',\n data: {\n screen_name: 'page view',\n timestamp_unixtime_ms: 1700000200000,\n source_message_id: 'ev-1700000200000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n },\n source_request_id: 'ev-1700000200000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/**\n * commerce_event - mapping.settings.eventType: 'commerce_event' plus a\n * `commerce` mapping resolves a ProductAction block. Products, currency,\n * and transaction metadata are all driven by the commerce mapping value.\n */\nexport const commercePurchase: Flow.StepExample = {\n title: 'Commerce purchase',\n description:\n 'A completed order becomes an mParticle commerce_event with a purchase product_action block.',\n in: getEvent('order complete', {\n id: 'ev-1700000300000',\n timestamp: 1700000300000,\n data: { id: 'ORD-300', total: 249.99, currency: 'EUR' },\n user: { id: 'user-123' },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: {\n settings: {\n eventType: 'commerce_event',\n commerce: {\n map: {\n currency_code: 'data.currency',\n product_action: {\n map: {\n action: { value: 'purchase' },\n transaction_id: 'data.id',\n total_amount: 'data.total',\n },\n },\n },\n },\n },\n },\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'commerce_event',\n data: {\n currency_code: 'EUR',\n product_action: {\n action: 'purchase',\n transaction_id: 'ORD-300',\n total_amount: 249.99,\n },\n timestamp_unixtime_ms: 1700000300000,\n source_message_id: 'ev-1700000300000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n },\n source_request_id: 'ev-1700000300000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/**\n * Identity + attributes - verifies `user_identities` and `user_attributes`\n * come from the batch-level settings mappings, not the event payload.\n */\nexport const identityAndAttributes: Flow.StepExample = {\n title: 'User identities',\n description:\n 'A form submission sends a custom_event whose batch carries user_identities resolved from destination settings.',\n in: getEvent('form submit', {\n id: 'ev-1700000400000',\n timestamp: 1700000400000,\n data: { type: 'newsletter' },\n user: {\n id: 'user-123',\n email: 'user@example.com',\n },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: undefined,\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'custom_event',\n data: {\n event_name: 'form submit',\n custom_event_type: 'other',\n timestamp_unixtime_ms: 1700000400000,\n source_message_id: 'ev-1700000400000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n email: 'user@example.com',\n },\n source_request_id: 'ev-1700000400000',\n }),\n OPTIONS,\n ],\n ],\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAA4B;;;ACA5B,IAAAC,cAAkB;;;ACAlB,iBAAkB;AAGX,IAAM,YAAY,aAAE,KAAK,CAAC,OAAO,OAAO,OAAO,KAAK,CAAC;AAGrD,IAAM,oBAAoB,aAAE,KAAK,CAAC,cAAc,aAAa,CAAC;AAG9D,IAAM,kBAAkB,aAAE,KAAK;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,IAAM,wBAAwB,a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version":3,"sources":["../src/dev.ts","../src/schemas/index.ts","../src/schemas/settings.ts","../src/schemas/primitives.ts","../src/schemas/mapping.ts","../src/examples/index.ts","../src/examples/env.ts","../src/examples/step.ts"],"sourcesContent":["export * as schemas from './schemas';\nexport * as examples from './examples';\n","import { zodToSchema } from '@walkeros/core/dev';\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/dev';\nimport { EnvironmentSchema, PodSchema } from './primitives';\n\nexport const SettingsSchema = z\n .object({\n apiKey: z\n .string()\n .min(1)\n .describe(\n 'mParticle input feed API key from the mParticle dashboard (Setup > Inputs > Feeds).',\n ),\n apiSecret: z\n .string()\n .min(1)\n .describe(\n 'mParticle input feed API secret paired with apiKey. Used for HTTP Basic auth.',\n ),\n pod: PodSchema.describe(\n \"mParticle data pod selecting the regional endpoint. Default: 'us1'.\",\n ).optional(),\n environment: EnvironmentSchema.describe(\n \"Environment the batch targets. Default: 'production'.\",\n ).optional(),\n userIdentities: z\n .record(z.string(), z.unknown())\n .describe(\n 'Mapping that resolves to user_identities per batch. Keys are mParticle identity types (like customer_id, email); values are walkerOS mapping values.',\n )\n .optional(),\n userAttributes: z\n .unknown()\n .describe(\n 'Mapping value that resolves to the user_attributes object placed on the batch.',\n )\n .optional(),\n consent: z\n .record(z.string(), z.unknown())\n .describe(\n 'Static consent_state envelope forwarded verbatim on the batch. See mParticle consent_state docs.',\n )\n .optional(),\n ip: z\n .unknown()\n .describe('Mapping value resolving to the client IP for the batch.')\n .optional(),\n sourceRequestId: z\n .unknown()\n .describe(\n 'Mapping value resolving to the source_request_id for the batch. Falls back to event.id when unset.',\n )\n .optional(),\n })\n .strict();\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import { z } from '@walkeros/core/dev';\n\n/** mParticle data pod (regional endpoint selector). */\nexport const PodSchema = z.enum(['us1', 'us2', 'eu1', 'au1']);\n\n/** Target environment for the batch. */\nexport const EnvironmentSchema = z.enum(['production', 'development']);\n\n/** Supported mParticle event types emitted by this destination. */\nexport const EventTypeSchema = z.enum([\n 'custom_event',\n 'screen_view',\n 'commerce_event',\n]);\n\n/** mParticle custom event category for `custom_event`. */\nexport const CustomEventTypeSchema = z.enum([\n 'navigation',\n 'location',\n 'search',\n 'transaction',\n 'user_content',\n 'user_preference',\n 'social',\n 'media',\n 'attribution',\n 'other',\n]);\n","import { z } from '@walkeros/core/dev';\nimport { CustomEventTypeSchema, EventTypeSchema } from './primitives';\n\nexport const MappingSchema = z.object({\n eventType: EventTypeSchema.describe(\n \"Per-event mParticle event type. Default: 'custom_event'.\",\n ).optional(),\n customEventType: CustomEventTypeSchema.describe(\n \"Custom event type category for 'custom_event'. Default: 'other'.\",\n ).optional(),\n commerce: z\n .unknown()\n .describe(\n 'Mapping value resolving to the commerce fields (product_action, currency_code, products, ...) for a commerce_event.',\n )\n .optional(),\n userIdentities: z\n .record(z.string(), z.unknown())\n .describe(\n 'Per-event override mapping for user_identities. Merged over settings.userIdentities.',\n )\n .optional(),\n userAttributes: z\n .unknown()\n .describe('Per-event override mapping for user_attributes.')\n .optional(),\n});\n\nexport type Mapping = z.infer<typeof MappingSchema>;\n","export * as env from './env';\nexport * as step from './step';\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 mParticle Events API destination.\n *\n * Provides a standardized mock `sendServer` so tests and simulations can\n * run without making real HTTP calls to mParticle.\n */\n\ntype MockSendServer = (\n url: string,\n data?: SendDataValue,\n options?: SendServerOptions,\n) => Promise<SendResponse>;\n\nconst mockSendServer: MockSendServer = async () => {\n // Simulates mParticle's typical 202 Accepted response for the Events API.\n return {\n data: {},\n };\n};\n\n/**\n * Standard mock environment for push operations.\n */\nexport const push: Env = {\n sendServer: mockSendServer,\n};\n\nexport const simulation = ['sendServer'];\n","import type { Flow } from '@walkeros/core';\nimport { createEvent, getEvent } from '@walkeros/core';\n\n/**\n * mParticle Events API step examples.\n *\n * At push time, the destination calls\n * `env.sendServer(endpoint, JSON.stringify(batch), options)` where\n * endpoint = `buildEndpoint(pod)` (default pod `us1` → `https://s2s.mparticle.com/v2/events`)\n * batch = the mParticle v2 batch envelope\n *\n * Test fixture pins `apiKey = 'key'`, `apiSecret = 'secret'`, pod `us1`, so\n * every call targets that endpoint with `Authorization: Basic a2V5OnNlY3JldA==`.\n *\n * The batch keys appear in the order the destination constructs them:\n * 1. events (always a single-element array)\n * 2. environment ('production' by default)\n * 3. user_identities (only when resolved)\n * 4. user_attributes (only when resolved)\n * 5. ip (only when mapped)\n * 6. source_request_id (falls back to `event.id`)\n * 7. consent_state, context (unused here)\n *\n * `options` carries Authorization + Content-Type headers.\n */\nconst ENDPOINT = 'https://s2s.mparticle.com/v2/events';\nconst OPTIONS = {\n headers: {\n // Basic base64('key:secret')\n Authorization: 'Basic a2V5OnNlY3JldA==',\n 'Content-Type': 'application/json',\n },\n};\n\n/**\n * Default custom_event - a walkerOS event with no `eventType` mapping.\n * mParticle wraps it as a `custom_event` with the default `other` category.\n * user_identities are resolved at the batch level from\n * `settings.userIdentities`.\n */\nexport const customEvent: Flow.StepExample = {\n title: 'Custom event',\n description:\n 'A walker event is sent to mParticle as a custom_event with user identities resolved from destination settings.',\n in: getEvent('product view', {\n id: 'ev-1700000100000',\n timestamp: 1700000100000,\n data: { id: 'SKU-A1', name: 'Shoe', price: 129.99 },\n user: { id: 'user-123' },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: undefined,\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'custom_event',\n data: {\n event_name: 'product view',\n custom_event_type: 'other',\n timestamp_unixtime_ms: 1700000100000,\n source_message_id: 'ev-1700000100000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n },\n source_request_id: 'ev-1700000100000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/**\n * screen_view event - mapping.settings.eventType switches the mParticle\n * event shape. Uses event name as the `screen_name`.\n */\nexport const screenView: Flow.StepExample = {\n title: 'Screen view',\n description:\n 'A page view is mapped to an mParticle screen_view event with the event name as the screen name.',\n in: getEvent('page view', {\n id: 'ev-1700000200000',\n timestamp: 1700000200000,\n data: { title: 'Checkout', path: '/checkout' },\n user: { id: 'user-123' },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: {\n settings: { eventType: 'screen_view' },\n },\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'screen_view',\n data: {\n screen_name: 'page view',\n timestamp_unixtime_ms: 1700000200000,\n source_message_id: 'ev-1700000200000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n },\n source_request_id: 'ev-1700000200000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/**\n * commerce_event - mapping.settings.eventType: 'commerce_event' plus a\n * `commerce` mapping resolves a ProductAction block. Products, currency,\n * and transaction metadata are all driven by the commerce mapping value.\n */\nexport const commercePurchase: Flow.StepExample = {\n title: 'Commerce purchase',\n description:\n 'A completed order becomes an mParticle commerce_event with a purchase product_action block.',\n in: getEvent('order complete', {\n id: 'ev-1700000300000',\n timestamp: 1700000300000,\n data: { id: 'ORD-300', value: 249.99, currency: 'EUR' },\n user: { id: 'user-123' },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: {\n settings: {\n eventType: 'commerce_event',\n commerce: {\n map: {\n currency_code: 'data.currency',\n product_action: {\n map: {\n action: { value: 'purchase' },\n transaction_id: 'data.id',\n total_amount: 'data.value',\n },\n },\n },\n },\n },\n },\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'commerce_event',\n data: {\n currency_code: 'EUR',\n product_action: {\n action: 'purchase',\n transaction_id: 'ORD-300',\n total_amount: 249.99,\n },\n timestamp_unixtime_ms: 1700000300000,\n source_message_id: 'ev-1700000300000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n },\n source_request_id: 'ev-1700000300000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/**\n * Identity + attributes - verifies `user_identities` and `user_attributes`\n * come from the batch-level settings mappings, not the event payload.\n */\nexport const identityAndAttributes: Flow.StepExample = {\n title: 'User identities',\n description:\n 'A form submission sends a custom_event whose batch carries user_identities resolved from destination settings.',\n in: createEvent({\n name: 'form submit',\n id: 'ev-1700000400000',\n timestamp: 1700000400000,\n data: { type: 'newsletter' },\n user: {\n id: 'user-123',\n email: 'user@example.com',\n },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: undefined,\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'custom_event',\n data: {\n event_name: 'form submit',\n custom_event_type: 'other',\n timestamp_unixtime_ms: 1700000400000,\n source_message_id: 'ev-1700000400000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n email: 'user@example.com',\n },\n source_request_id: 'ev-1700000400000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/** A silent rule sends nothing to mParticle. */\nexport const silentRule: Flow.StepExample = {\n public: false,\n description: 'A rule with silent: true sends no request to mParticle.',\n in: getEvent('page view', { timestamp: 1700000990000 }),\n mapping: { silent: true },\n out: [],\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAA4B;;;ACA5B,IAAAC,cAAkB;;;ACAlB,iBAAkB;AAGX,IAAM,YAAY,aAAE,KAAK,CAAC,OAAO,OAAO,OAAO,KAAK,CAAC;AAGrD,IAAM,oBAAoB,aAAE,KAAK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b,OAAO;AAAA,QACT;AAAA,QACA,mBAAmB;AAAA,MACrB,CAAC;AAAA,MACD;AAAA,IACF;AAAA,EACF;AACF;AAGO,IAAM,aAA+B;AAAA,EAC1C,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,QAAI,sBAAS,aAAa,EAAE,WAAW,YAAc,CAAC;AAAA,EACtD,SAAS,EAAE,QAAQ,KAAK;AAAA,EACxB,KAAK,CAAC;AACR;","names":["import_dev","import_dev","import_dev"]}
|
package/dist/dev.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
import{createRequire as e}from"module";e(import.meta.url);var t=Object.defineProperty,r=(e,r)=>{for(var i in r)t(e,i,{get:r[i],enumerable:!0})},i={};r(i,{CustomEventTypeSchema:()=>u,EnvironmentSchema:()=>c,EventTypeSchema:()=>m,MappingSchema:()=>v,PodSchema:()=>a,SettingsSchema:()=>p,mapping:()=>_,settings:()=>l});import{zodToSchema as s}from"@walkeros/core/dev";import{z as n}from"@walkeros/core/dev";import{z as o}from"@walkeros/core/dev";var a=o.enum(["us1","us2","eu1","au1"]),c=o.enum(["production","development"]),m=o.enum(["custom_event","screen_view","commerce_event"]),u=o.enum(["navigation","location","search","transaction","user_content","user_preference","social","media","attribution","other"]),p=n.object({apiKey:n.string().min(1).describe("mParticle input feed API key from the mParticle dashboard (Setup > Inputs > Feeds)."),apiSecret:n.string().min(1).describe("mParticle input feed API secret paired with apiKey. Used for HTTP Basic auth."),pod:a.describe("mParticle data pod selecting the regional endpoint. Default: 'us1'.").optional(),environment:c.describe("Environment the batch targets. Default: 'production'.").optional(),userIdentities:n.record(n.string(),n.unknown()).describe("Mapping that resolves to user_identities per batch. Keys are mParticle identity types (like customer_id, email); values are walkerOS mapping values.").optional(),userAttributes:n.unknown().describe("Mapping value that resolves to the user_attributes object placed on the batch.").optional(),consent:n.record(n.string(),n.unknown()).describe("Static consent_state envelope forwarded verbatim on the batch. See mParticle consent_state docs.").optional(),ip:n.unknown().describe("Mapping value resolving to the client IP for the batch.").optional(),sourceRequestId:n.unknown().describe("Mapping value resolving to the source_request_id for the batch. Falls back to event.id when unset.").optional()}).strict();import{z as d}from"@walkeros/core/dev";var v=d.object({eventType:m.describe("Per-event mParticle event type. Default: 'custom_event'.").optional(),customEventType:u.describe("Custom event type category for 'custom_event'. Default: 'other'.").optional(),commerce:d.unknown().describe("Mapping value resolving to the commerce fields (product_action, currency_code, products, ...) for a commerce_event.").optional(),userIdentities:d.record(d.string(),d.unknown()).describe("Per-event override mapping for user_identities. Merged over settings.userIdentities.").optional(),userAttributes:d.unknown().describe("Per-event override mapping for user_attributes.").optional()}),l=s(p),_=s(v),h={};r(h,{env:()=>g,step:()=>f});var g={};r(g,{push:()=>b,simulation:()=>y});var b={sendServer:async()=>({data:{}})},y=["sendServer"],f={};r(f,{commercePurchase:()=>O,customEvent:()=>A,identityAndAttributes:()=>T,screenView:()=>x,silentRule:()=>E});import{createEvent as w,getEvent as S}from"@walkeros/core";var k="https://s2s.mparticle.com/v2/events",P={headers:{Authorization:"Basic a2V5OnNlY3JldA==","Content-Type":"application/json"}},A={title:"Custom event",description:"A walker event is sent to mParticle as a custom_event with user identities resolved from destination settings.",in:S("product view",{id:"ev-1700000100000",timestamp:17000001e5,data:{id:"SKU-A1",name:"Shoe",price:129.99},user:{id:"user-123"},source:{type:"express",platform:"server"}}),mapping:void 0,out:[["sendServer",k,JSON.stringify({events:[{event_type:"custom_event",data:{event_name:"product view",custom_event_type:"other",timestamp_unixtime_ms:17000001e5,source_message_id:"ev-1700000100000"}}],environment:"production",user_identities:{customer_id:"user-123"},source_request_id:"ev-1700000100000"}),P]]},x={title:"Screen view",description:"A page view is mapped to an mParticle screen_view event with the event name as the screen name.",in:S("page view",{id:"ev-1700000200000",timestamp:17000002e5,data:{title:"Checkout",path:"/checkout"},user:{id:"user-123"},source:{type:"express",platform:"server"}}),mapping:{settings:{eventType:"screen_view"}},out:[["sendServer",k,JSON.stringify({events:[{event_type:"screen_view",data:{screen_name:"page view",timestamp_unixtime_ms:17000002e5,source_message_id:"ev-1700000200000"}}],environment:"production",user_identities:{customer_id:"user-123"},source_request_id:"ev-1700000200000"}),P]]},O={title:"Commerce purchase",description:"A completed order becomes an mParticle commerce_event with a purchase product_action block.",in:S("order complete",{id:"ev-1700000300000",timestamp:17000003e5,data:{id:"ORD-300",value:249.99,currency:"EUR"},user:{id:"user-123"},source:{type:"express",platform:"server"}}),mapping:{settings:{eventType:"commerce_event",commerce:{map:{currency_code:"data.currency",product_action:{map:{action:{value:"purchase"},transaction_id:"data.id",total_amount:"data.value"}}}}}},out:[["sendServer",k,JSON.stringify({events:[{event_type:"commerce_event",data:{currency_code:"EUR",product_action:{action:"purchase",transaction_id:"ORD-300",total_amount:249.99},timestamp_unixtime_ms:17000003e5,source_message_id:"ev-1700000300000"}}],environment:"production",user_identities:{customer_id:"user-123"},source_request_id:"ev-1700000300000"}),P]]},T={title:"User identities",description:"A form submission sends a custom_event whose batch carries user_identities resolved from destination settings.",in:w({name:"form submit",id:"ev-1700000400000",timestamp:17000004e5,data:{type:"newsletter"},user:{id:"user-123",email:"user@example.com"},source:{type:"express",platform:"server"}}),mapping:void 0,out:[["sendServer",k,JSON.stringify({events:[{event_type:"custom_event",data:{event_name:"form submit",custom_event_type:"other",timestamp_unixtime_ms:17000004e5,source_message_id:"ev-1700000400000"}}],environment:"production",user_identities:{customer_id:"user-123",email:"user@example.com"},source_request_id:"ev-1700000400000"}),P]]},E={public:!1,description:"A rule with silent: true sends no request to mParticle.",in:S("page view",{timestamp:170000099e4}),mapping:{silent:!0},out:[]};export{h as examples,i as schemas};//# sourceMappingURL=dev.mjs.map
|
package/dist/dev.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schemas/index.ts","../src/schemas/settings.ts","../src/schemas/primitives.ts","../src/schemas/mapping.ts","../src/examples/index.ts","../src/examples/env.ts","../src/examples/step.ts"],"sourcesContent":["import { zodToSchema } from '@walkeros/core/dev';\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/dev';\nimport { EnvironmentSchema, PodSchema } from './primitives';\n\nexport const SettingsSchema = z.object({\n apiKey: z\n .string()\n .min(1)\n .describe(\n 'mParticle input feed API key from the mParticle dashboard (Setup > Inputs > Feeds).',\n ),\n apiSecret: z\n .string()\n .min(1)\n .describe(\n 'mParticle input feed API secret paired with apiKey. Used for HTTP Basic auth.',\n ),\n pod: PodSchema.describe(\n \"mParticle data pod selecting the regional endpoint. Default: 'us1'.\",\n ).optional(),\n environment: EnvironmentSchema.describe(\n \"Environment the batch targets. Default: 'production'.\",\n ).optional(),\n userIdentities: z\n .record(z.string(), z.unknown())\n .describe(\n 'Mapping that resolves to user_identities per batch. Keys are mParticle identity types (like customer_id, email); values are walkerOS mapping values.',\n )\n .optional(),\n userAttributes: z\n .unknown()\n .describe(\n 'Mapping value that resolves to the user_attributes object placed on the batch.',\n )\n .optional(),\n consent: z\n .record(z.string(), z.unknown())\n .describe(\n 'Static consent_state envelope forwarded verbatim on the batch. See mParticle consent_state docs.',\n )\n .optional(),\n ip: z\n .unknown()\n .describe('Mapping value resolving to the client IP for the batch.')\n .optional(),\n sourceRequestId: z\n .unknown()\n .describe(\n 'Mapping value resolving to the source_request_id for the batch. Falls back to event.id when unset.',\n )\n .optional(),\n});\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import { z } from '@walkeros/core/dev';\n\n/** mParticle data pod (regional endpoint selector). */\nexport const PodSchema = z.enum(['us1', 'us2', 'eu1', 'au1']);\n\n/** Target environment for the batch. */\nexport const EnvironmentSchema = z.enum(['production', 'development']);\n\n/** Supported mParticle event types emitted by this destination. */\nexport const EventTypeSchema = z.enum([\n 'custom_event',\n 'screen_view',\n 'commerce_event',\n]);\n\n/** mParticle custom event category for `custom_event`. */\nexport const CustomEventTypeSchema = z.enum([\n 'navigation',\n 'location',\n 'search',\n 'transaction',\n 'user_content',\n 'user_preference',\n 'social',\n 'media',\n 'attribution',\n 'other',\n]);\n","import { z } from '@walkeros/core/dev';\nimport { CustomEventTypeSchema, EventTypeSchema } from './primitives';\n\nexport const MappingSchema = z.object({\n eventType: EventTypeSchema.describe(\n \"Per-event mParticle event type. Default: 'custom_event'.\",\n ).optional(),\n customEventType: CustomEventTypeSchema.describe(\n \"Custom event type category for 'custom_event'. Default: 'other'.\",\n ).optional(),\n commerce: z\n .unknown()\n .describe(\n 'Mapping value resolving to the commerce fields (product_action, currency_code, products, ...) for a commerce_event.',\n )\n .optional(),\n userIdentities: z\n .record(z.string(), z.unknown())\n .describe(\n 'Per-event override mapping for user_identities. Merged over settings.userIdentities.',\n )\n .optional(),\n userAttributes: z\n .unknown()\n .describe('Per-event override mapping for user_attributes.')\n .optional(),\n});\n\nexport type Mapping = z.infer<typeof MappingSchema>;\n","export * as env from './env';\nexport * as step from './step';\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 mParticle Events API destination.\n *\n * Provides a standardized mock `sendServer` so tests and simulations can\n * run without making real HTTP calls to mParticle.\n */\n\ntype MockSendServer = (\n url: string,\n data?: SendDataValue,\n options?: SendServerOptions,\n) => Promise<SendResponse>;\n\nconst mockSendServer: MockSendServer = async () => {\n // Simulates mParticle's typical 202 Accepted response for the Events API.\n return {\n ok: true,\n data: {},\n };\n};\n\n/**\n * Standard mock environment for push operations.\n */\nexport const push: Env = {\n sendServer: mockSendServer,\n};\n\nexport const simulation = ['sendServer'];\n","import type { Flow } from '@walkeros/core';\nimport { getEvent } from '@walkeros/core';\n\n/**\n * mParticle Events API step examples.\n *\n * At push time, the destination calls\n * `env.sendServer(endpoint, JSON.stringify(batch), options)` where\n * endpoint = `buildEndpoint(pod)` (default pod `us1` → `https://s2s.mparticle.com/v2/events`)\n * batch = the mParticle v2 batch envelope\n *\n * Test fixture pins `apiKey = 'key'`, `apiSecret = 'secret'`, pod `us1`, so\n * every call targets that endpoint with `Authorization: Basic a2V5OnNlY3JldA==`.\n *\n * The batch keys appear in the order the destination constructs them:\n * 1. events (always a single-element array)\n * 2. environment ('production' by default)\n * 3. user_identities (only when resolved)\n * 4. user_attributes (only when resolved)\n * 5. ip (only when mapped)\n * 6. source_request_id (falls back to `event.id`)\n * 7. consent_state, context (unused here)\n *\n * `options` carries Authorization + Content-Type headers.\n */\nconst ENDPOINT = 'https://s2s.mparticle.com/v2/events';\nconst OPTIONS = {\n headers: {\n // Basic base64('key:secret')\n Authorization: 'Basic a2V5OnNlY3JldA==',\n 'Content-Type': 'application/json',\n },\n};\n\n/**\n * Default custom_event - a walkerOS event with no `eventType` mapping.\n * mParticle wraps it as a `custom_event` with the default `other` category.\n * user_identities are resolved at the batch level from\n * `settings.userIdentities`.\n */\nexport const customEvent: Flow.StepExample = {\n title: 'Custom event',\n description:\n 'A walker event is sent to mParticle as a custom_event with user identities resolved from destination settings.',\n in: getEvent('product view', {\n id: 'ev-1700000100000',\n timestamp: 1700000100000,\n data: { id: 'SKU-A1', name: 'Shoe', price: 129.99 },\n user: { id: 'user-123' },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: undefined,\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'custom_event',\n data: {\n event_name: 'product view',\n custom_event_type: 'other',\n timestamp_unixtime_ms: 1700000100000,\n source_message_id: 'ev-1700000100000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n },\n source_request_id: 'ev-1700000100000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/**\n * screen_view event - mapping.settings.eventType switches the mParticle\n * event shape. Uses event name as the `screen_name`.\n */\nexport const screenView: Flow.StepExample = {\n title: 'Screen view',\n description:\n 'A page view is mapped to an mParticle screen_view event with the event name as the screen name.',\n in: getEvent('page view', {\n id: 'ev-1700000200000',\n timestamp: 1700000200000,\n data: { title: 'Checkout', path: '/checkout' },\n user: { id: 'user-123' },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: {\n settings: { eventType: 'screen_view' },\n },\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'screen_view',\n data: {\n screen_name: 'page view',\n timestamp_unixtime_ms: 1700000200000,\n source_message_id: 'ev-1700000200000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n },\n source_request_id: 'ev-1700000200000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/**\n * commerce_event - mapping.settings.eventType: 'commerce_event' plus a\n * `commerce` mapping resolves a ProductAction block. Products, currency,\n * and transaction metadata are all driven by the commerce mapping value.\n */\nexport const commercePurchase: Flow.StepExample = {\n title: 'Commerce purchase',\n description:\n 'A completed order becomes an mParticle commerce_event with a purchase product_action block.',\n in: getEvent('order complete', {\n id: 'ev-1700000300000',\n timestamp: 1700000300000,\n data: { id: 'ORD-300', total: 249.99, currency: 'EUR' },\n user: { id: 'user-123' },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: {\n settings: {\n eventType: 'commerce_event',\n commerce: {\n map: {\n currency_code: 'data.currency',\n product_action: {\n map: {\n action: { value: 'purchase' },\n transaction_id: 'data.id',\n total_amount: 'data.total',\n },\n },\n },\n },\n },\n },\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'commerce_event',\n data: {\n currency_code: 'EUR',\n product_action: {\n action: 'purchase',\n transaction_id: 'ORD-300',\n total_amount: 249.99,\n },\n timestamp_unixtime_ms: 1700000300000,\n source_message_id: 'ev-1700000300000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n },\n source_request_id: 'ev-1700000300000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/**\n * Identity + attributes - verifies `user_identities` and `user_attributes`\n * come from the batch-level settings mappings, not the event payload.\n */\nexport const identityAndAttributes: Flow.StepExample = {\n title: 'User identities',\n description:\n 'A form submission sends a custom_event whose batch carries user_identities resolved from destination settings.',\n in: getEvent('form submit', {\n id: 'ev-1700000400000',\n timestamp: 1700000400000,\n data: { type: 'newsletter' },\n user: {\n id: 'user-123',\n email: 'user@example.com',\n },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: undefined,\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'custom_event',\n data: {\n event_name: 'form submit',\n custom_event_type: 'other',\n timestamp_unixtime_ms: 1700000400000,\n source_message_id: 'ev-1700000400000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n email: 'user@example.com',\n },\n source_request_id: 'ev-1700000400000',\n }),\n OPTIONS,\n ],\n ],\n};\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAS,mBAAmB;;;ACA5B,SAAS,KAAAA,UAAS;;;ACAlB,SAAS,SAAS;AAGX,IAAM,YAAY,EAAE,KAAK,CAAC,OAAO,OAAO,OAAO,KAAK,CAAC;AAGrD,IAAM,oBAAoB,EAAE,KAAK,CAAC,cAAc,aAAa,CAAC;AAG9D,IAAM,kBAAkB,EAAE,KAAK;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,IAAM,wBAAwB,EAAE,KAAK;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;;;ADxBM,IAAM,iBAAiBC,GAAE,OAAO;AAAA,EACrC,QAAQA,GACL,OAAO,EACP,IAAI,CAAC,EACL;AAAA,IACC;AAAA,EACF;AAAA,EACF,WAAWA,GACR,OAAO,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ChB,cAAc;AAAA,cAChB;AAAA,cACA,uBAAuB;AAAA,cACvB,mBAAmB;AAAA,YACrB;AAAA,UACF;AAAA,QACF;AAAA,QACA,aAAa;AAAA,QACb,iBAAiB;AAAA,UACf,aAAa;AAAA,QACf;AAAA,QACA,mBAAmB;AAAA,MACrB,CAAC;AAAA,MACD;AAAA,IACF;AAAA,EACF;AACF;AAMO,IAAM,wBAA0C;AAAA,EACrD,OAAO;AAAA,EACP,aACE;AAAA,EACF,IAAI,SAAS,eAAe;AAAA,IAC1B,IAAI;AAAA,IACJ,WAAW;AAAA,IACX,MAAM,EAAE,MAAM,aAAa;AAAA,IAC3B,MAAM;AAAA,MACJ,IAAI;AAAA,MACJ,OAAO;AAAA,IACT;AAAA,IACA,QAAQ,EAAE,MAAM,WAAW,UAAU,SAAS;AAAA,EAChD,CAAC;AAAA,EACD,SAAS;AAAA,EACT,KAAK;AAAA,IACH;AAAA,MACE;AAAA,MACA;AAAA,MACA,KAAK,UAAU;AAAA,QACb,QAAQ;AAAA,UACN;AAAA,YACE,YAAY;AAAA,YACZ,MAAM;AAAA,cACJ,YAAY;AAAA,cACZ,mBAAmB;AAAA,cACnB,uBAAuB;AAAA,cACvB,mBAAmB;AAAA,YACrB;AAAA,UACF;AAAA,QACF;AAAA,QACA,aAAa;AAAA,QACb,iBAAiB;AAAA,UACf,aAAa;AAAA,UACb,OAAO;AAAA,QACT;AAAA,QACA,mBAAmB;AAAA,MACrB,CAAC;AAAA,MACD;AAAA,IACF;AAAA,EACF;AACF;","names":["z","z","z","z"]}
|
|
1
|
+
{"version":3,"sources":["../src/schemas/index.ts","../src/schemas/settings.ts","../src/schemas/primitives.ts","../src/schemas/mapping.ts","../src/examples/index.ts","../src/examples/env.ts","../src/examples/step.ts"],"sourcesContent":["import { zodToSchema } from '@walkeros/core/dev';\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/dev';\nimport { EnvironmentSchema, PodSchema } from './primitives';\n\nexport const SettingsSchema = z\n .object({\n apiKey: z\n .string()\n .min(1)\n .describe(\n 'mParticle input feed API key from the mParticle dashboard (Setup > Inputs > Feeds).',\n ),\n apiSecret: z\n .string()\n .min(1)\n .describe(\n 'mParticle input feed API secret paired with apiKey. Used for HTTP Basic auth.',\n ),\n pod: PodSchema.describe(\n \"mParticle data pod selecting the regional endpoint. Default: 'us1'.\",\n ).optional(),\n environment: EnvironmentSchema.describe(\n \"Environment the batch targets. Default: 'production'.\",\n ).optional(),\n userIdentities: z\n .record(z.string(), z.unknown())\n .describe(\n 'Mapping that resolves to user_identities per batch. Keys are mParticle identity types (like customer_id, email); values are walkerOS mapping values.',\n )\n .optional(),\n userAttributes: z\n .unknown()\n .describe(\n 'Mapping value that resolves to the user_attributes object placed on the batch.',\n )\n .optional(),\n consent: z\n .record(z.string(), z.unknown())\n .describe(\n 'Static consent_state envelope forwarded verbatim on the batch. See mParticle consent_state docs.',\n )\n .optional(),\n ip: z\n .unknown()\n .describe('Mapping value resolving to the client IP for the batch.')\n .optional(),\n sourceRequestId: z\n .unknown()\n .describe(\n 'Mapping value resolving to the source_request_id for the batch. Falls back to event.id when unset.',\n )\n .optional(),\n })\n .strict();\n\nexport type Settings = z.infer<typeof SettingsSchema>;\n","import { z } from '@walkeros/core/dev';\n\n/** mParticle data pod (regional endpoint selector). */\nexport const PodSchema = z.enum(['us1', 'us2', 'eu1', 'au1']);\n\n/** Target environment for the batch. */\nexport const EnvironmentSchema = z.enum(['production', 'development']);\n\n/** Supported mParticle event types emitted by this destination. */\nexport const EventTypeSchema = z.enum([\n 'custom_event',\n 'screen_view',\n 'commerce_event',\n]);\n\n/** mParticle custom event category for `custom_event`. */\nexport const CustomEventTypeSchema = z.enum([\n 'navigation',\n 'location',\n 'search',\n 'transaction',\n 'user_content',\n 'user_preference',\n 'social',\n 'media',\n 'attribution',\n 'other',\n]);\n","import { z } from '@walkeros/core/dev';\nimport { CustomEventTypeSchema, EventTypeSchema } from './primitives';\n\nexport const MappingSchema = z.object({\n eventType: EventTypeSchema.describe(\n \"Per-event mParticle event type. Default: 'custom_event'.\",\n ).optional(),\n customEventType: CustomEventTypeSchema.describe(\n \"Custom event type category for 'custom_event'. Default: 'other'.\",\n ).optional(),\n commerce: z\n .unknown()\n .describe(\n 'Mapping value resolving to the commerce fields (product_action, currency_code, products, ...) for a commerce_event.',\n )\n .optional(),\n userIdentities: z\n .record(z.string(), z.unknown())\n .describe(\n 'Per-event override mapping for user_identities. Merged over settings.userIdentities.',\n )\n .optional(),\n userAttributes: z\n .unknown()\n .describe('Per-event override mapping for user_attributes.')\n .optional(),\n});\n\nexport type Mapping = z.infer<typeof MappingSchema>;\n","export * as env from './env';\nexport * as step from './step';\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 mParticle Events API destination.\n *\n * Provides a standardized mock `sendServer` so tests and simulations can\n * run without making real HTTP calls to mParticle.\n */\n\ntype MockSendServer = (\n url: string,\n data?: SendDataValue,\n options?: SendServerOptions,\n) => Promise<SendResponse>;\n\nconst mockSendServer: MockSendServer = async () => {\n // Simulates mParticle's typical 202 Accepted response for the Events API.\n return {\n data: {},\n };\n};\n\n/**\n * Standard mock environment for push operations.\n */\nexport const push: Env = {\n sendServer: mockSendServer,\n};\n\nexport const simulation = ['sendServer'];\n","import type { Flow } from '@walkeros/core';\nimport { createEvent, getEvent } from '@walkeros/core';\n\n/**\n * mParticle Events API step examples.\n *\n * At push time, the destination calls\n * `env.sendServer(endpoint, JSON.stringify(batch), options)` where\n * endpoint = `buildEndpoint(pod)` (default pod `us1` → `https://s2s.mparticle.com/v2/events`)\n * batch = the mParticle v2 batch envelope\n *\n * Test fixture pins `apiKey = 'key'`, `apiSecret = 'secret'`, pod `us1`, so\n * every call targets that endpoint with `Authorization: Basic a2V5OnNlY3JldA==`.\n *\n * The batch keys appear in the order the destination constructs them:\n * 1. events (always a single-element array)\n * 2. environment ('production' by default)\n * 3. user_identities (only when resolved)\n * 4. user_attributes (only when resolved)\n * 5. ip (only when mapped)\n * 6. source_request_id (falls back to `event.id`)\n * 7. consent_state, context (unused here)\n *\n * `options` carries Authorization + Content-Type headers.\n */\nconst ENDPOINT = 'https://s2s.mparticle.com/v2/events';\nconst OPTIONS = {\n headers: {\n // Basic base64('key:secret')\n Authorization: 'Basic a2V5OnNlY3JldA==',\n 'Content-Type': 'application/json',\n },\n};\n\n/**\n * Default custom_event - a walkerOS event with no `eventType` mapping.\n * mParticle wraps it as a `custom_event` with the default `other` category.\n * user_identities are resolved at the batch level from\n * `settings.userIdentities`.\n */\nexport const customEvent: Flow.StepExample = {\n title: 'Custom event',\n description:\n 'A walker event is sent to mParticle as a custom_event with user identities resolved from destination settings.',\n in: getEvent('product view', {\n id: 'ev-1700000100000',\n timestamp: 1700000100000,\n data: { id: 'SKU-A1', name: 'Shoe', price: 129.99 },\n user: { id: 'user-123' },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: undefined,\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'custom_event',\n data: {\n event_name: 'product view',\n custom_event_type: 'other',\n timestamp_unixtime_ms: 1700000100000,\n source_message_id: 'ev-1700000100000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n },\n source_request_id: 'ev-1700000100000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/**\n * screen_view event - mapping.settings.eventType switches the mParticle\n * event shape. Uses event name as the `screen_name`.\n */\nexport const screenView: Flow.StepExample = {\n title: 'Screen view',\n description:\n 'A page view is mapped to an mParticle screen_view event with the event name as the screen name.',\n in: getEvent('page view', {\n id: 'ev-1700000200000',\n timestamp: 1700000200000,\n data: { title: 'Checkout', path: '/checkout' },\n user: { id: 'user-123' },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: {\n settings: { eventType: 'screen_view' },\n },\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'screen_view',\n data: {\n screen_name: 'page view',\n timestamp_unixtime_ms: 1700000200000,\n source_message_id: 'ev-1700000200000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n },\n source_request_id: 'ev-1700000200000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/**\n * commerce_event - mapping.settings.eventType: 'commerce_event' plus a\n * `commerce` mapping resolves a ProductAction block. Products, currency,\n * and transaction metadata are all driven by the commerce mapping value.\n */\nexport const commercePurchase: Flow.StepExample = {\n title: 'Commerce purchase',\n description:\n 'A completed order becomes an mParticle commerce_event with a purchase product_action block.',\n in: getEvent('order complete', {\n id: 'ev-1700000300000',\n timestamp: 1700000300000,\n data: { id: 'ORD-300', value: 249.99, currency: 'EUR' },\n user: { id: 'user-123' },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: {\n settings: {\n eventType: 'commerce_event',\n commerce: {\n map: {\n currency_code: 'data.currency',\n product_action: {\n map: {\n action: { value: 'purchase' },\n transaction_id: 'data.id',\n total_amount: 'data.value',\n },\n },\n },\n },\n },\n },\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'commerce_event',\n data: {\n currency_code: 'EUR',\n product_action: {\n action: 'purchase',\n transaction_id: 'ORD-300',\n total_amount: 249.99,\n },\n timestamp_unixtime_ms: 1700000300000,\n source_message_id: 'ev-1700000300000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n },\n source_request_id: 'ev-1700000300000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/**\n * Identity + attributes - verifies `user_identities` and `user_attributes`\n * come from the batch-level settings mappings, not the event payload.\n */\nexport const identityAndAttributes: Flow.StepExample = {\n title: 'User identities',\n description:\n 'A form submission sends a custom_event whose batch carries user_identities resolved from destination settings.',\n in: createEvent({\n name: 'form submit',\n id: 'ev-1700000400000',\n timestamp: 1700000400000,\n data: { type: 'newsletter' },\n user: {\n id: 'user-123',\n email: 'user@example.com',\n },\n source: { type: 'express', platform: 'server' },\n }),\n mapping: undefined,\n out: [\n [\n 'sendServer',\n ENDPOINT,\n JSON.stringify({\n events: [\n {\n event_type: 'custom_event',\n data: {\n event_name: 'form submit',\n custom_event_type: 'other',\n timestamp_unixtime_ms: 1700000400000,\n source_message_id: 'ev-1700000400000',\n },\n },\n ],\n environment: 'production',\n user_identities: {\n customer_id: 'user-123',\n email: 'user@example.com',\n },\n source_request_id: 'ev-1700000400000',\n }),\n OPTIONS,\n ],\n ],\n};\n\n/** A silent rule sends nothing to mParticle. */\nexport const silentRule: Flow.StepExample = {\n public: false,\n description: 'A rule with silent: true sends no request to mParticle.',\n in: getEvent('page view', { timestamp: 1700000990000 }),\n mapping: { silent: true },\n out: [],\n};\n"],"mappings":";;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAS,mBAAmB;;;ACA5B,SAAS,KAAAA,UAAS;;;ACAlB,SAAS,SAAS;AAGX,IAAM,YAAY,EAAE,KAAK,CAAC,OAAO,OAAO,OAAO,KAAK,CAAC;AAGrD,IAAM,oBAAoB,EAAE,KAAK,CAAC,cAAc,aAAa,CAAC;AAG9D,IAAM,kBAAkB,EAAE,KAAK;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,IAAM,wBAAwB,EAAE,KAAK;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;;;ADxBM,IAAM,iBAAiBC,GAC3B,OAAO;AAAA,EACN,QAAQA,GACL,OAAO,EACP,IAAI,CAAC,EACL;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ePurchase: Flow.StepExample;
|
|
|
40
40
|
* come from the batch-level settings mappings, not the event payload.
|
|
41
41
|
*/
|
|
42
42
|
declare const identityAndAttributes: Flow.StepExample;
|
|
43
|
+
/** A silent rule sends nothing to mParticle. */
|
|
44
|
+
declare const silentRule: Flow.StepExample;
|
|
43
45
|
|
|
44
46
|
declare const step_commercePurchase: typeof commercePurchase;
|
|
45
47
|
declare const step_customEvent: typeof customEvent;
|
|
46
48
|
declare const step_identityAndAttributes: typeof identityAndAttributes;
|
|
47
49
|
declare const step_screenView: typeof screenView;
|
|
50
|
+
declare const step_silentRule: typeof silentRule;
|
|
48
51
|
declare namespace step {
|
|
49
|
-
export { step_commercePurchase as commercePurchase, step_customEvent as customEvent, step_identityAndAttributes as identityAndAttributes, step_screenView as screenView };
|
|
52
|
+
export { step_commercePurchase as commercePurchase, step_customEvent as customEvent, step_identityAndAttributes as identityAndAttributes, step_screenView as screenView, step_silentRule as silentRule };
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
export { env, step };
|
package/dist/examples/index.d.ts
CHANGED
|
@@ -40,13 +40,16 @@ declare const commercePurchase: Flow.StepExample;
|
|
|
40
40
|
* come from the batch-level settings mappings, not the event payload.
|
|
41
41
|
*/
|
|
42
42
|
declare const identityAndAttributes: Flow.StepExample;
|
|
43
|
+
/** A silent rule sends nothing to mParticle. */
|
|
44
|
+
declare const silentRule: Flow.StepExample;
|
|
43
45
|
|
|
44
46
|
declare const step_commercePurchase: typeof commercePurchase;
|
|
45
47
|
declare const step_customEvent: typeof customEvent;
|
|
46
48
|
declare const step_identityAndAttributes: typeof identityAndAttributes;
|
|
47
49
|
declare const step_screenView: typeof screenView;
|
|
50
|
+
declare const step_silentRule: typeof silentRule;
|
|
48
51
|
declare namespace step {
|
|
49
|
-
export { step_commercePurchase as commercePurchase, step_customEvent as customEvent, step_identityAndAttributes as identityAndAttributes, step_screenView as screenView };
|
|
52
|
+
export { step_commercePurchase as commercePurchase, step_customEvent as customEvent, step_identityAndAttributes as identityAndAttributes, step_screenView as screenView, step_silentRule as silentRule };
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
export { env, step };
|
package/dist/examples/index.js
CHANGED
|
@@ -33,7 +33,6 @@ __export(env_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
var mockSendServer = async () => {
|
|
35
35
|
return {
|
|
36
|
-
ok: true,
|
|
37
36
|
data: {}
|
|
38
37
|
};
|
|
39
38
|
};
|
|
@@ -48,7 +47,8 @@ __export(step_exports, {
|
|
|
48
47
|
commercePurchase: () => commercePurchase,
|
|
49
48
|
customEvent: () => customEvent,
|
|
50
49
|
identityAndAttributes: () => identityAndAttributes,
|
|
51
|
-
screenView: () => screenView
|
|
50
|
+
screenView: () => screenView,
|
|
51
|
+
silentRule: () => silentRule
|
|
52
52
|
});
|
|
53
53
|
var import_core = require("@walkeros/core");
|
|
54
54
|
var ENDPOINT = "https://s2s.mparticle.com/v2/events";
|
|
@@ -140,7 +140,7 @@ var commercePurchase = {
|
|
|
140
140
|
in: (0, import_core.getEvent)("order complete", {
|
|
141
141
|
id: "ev-1700000300000",
|
|
142
142
|
timestamp: 17000003e5,
|
|
143
|
-
data: { id: "ORD-300",
|
|
143
|
+
data: { id: "ORD-300", value: 249.99, currency: "EUR" },
|
|
144
144
|
user: { id: "user-123" },
|
|
145
145
|
source: { type: "express", platform: "server" }
|
|
146
146
|
}),
|
|
@@ -154,7 +154,7 @@ var commercePurchase = {
|
|
|
154
154
|
map: {
|
|
155
155
|
action: { value: "purchase" },
|
|
156
156
|
transaction_id: "data.id",
|
|
157
|
-
total_amount: "data.
|
|
157
|
+
total_amount: "data.value"
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
}
|
|
@@ -194,7 +194,8 @@ var commercePurchase = {
|
|
|
194
194
|
var identityAndAttributes = {
|
|
195
195
|
title: "User identities",
|
|
196
196
|
description: "A form submission sends a custom_event whose batch carries user_identities resolved from destination settings.",
|
|
197
|
-
in: (0, import_core.
|
|
197
|
+
in: (0, import_core.createEvent)({
|
|
198
|
+
name: "form submit",
|
|
198
199
|
id: "ev-1700000400000",
|
|
199
200
|
timestamp: 17000004e5,
|
|
200
201
|
data: { type: "newsletter" },
|
|
@@ -232,6 +233,13 @@ var identityAndAttributes = {
|
|
|
232
233
|
]
|
|
233
234
|
]
|
|
234
235
|
};
|
|
236
|
+
var silentRule = {
|
|
237
|
+
public: false,
|
|
238
|
+
description: "A rule with silent: true sends no request to mParticle.",
|
|
239
|
+
in: (0, import_core.getEvent)("page view", { timestamp: 170000099e4 }),
|
|
240
|
+
mapping: { silent: true },
|
|
241
|
+
out: []
|
|
242
|
+
};
|
|
235
243
|
// Annotate the CommonJS export names for ESM import in node:
|
|
236
244
|
0 && (module.exports = {
|
|
237
245
|
env,
|
package/dist/examples/index.mjs
CHANGED
|
@@ -12,7 +12,6 @@ __export(env_exports, {
|
|
|
12
12
|
});
|
|
13
13
|
var mockSendServer = async () => {
|
|
14
14
|
return {
|
|
15
|
-
ok: true,
|
|
16
15
|
data: {}
|
|
17
16
|
};
|
|
18
17
|
};
|
|
@@ -27,9 +26,10 @@ __export(step_exports, {
|
|
|
27
26
|
commercePurchase: () => commercePurchase,
|
|
28
27
|
customEvent: () => customEvent,
|
|
29
28
|
identityAndAttributes: () => identityAndAttributes,
|
|
30
|
-
screenView: () => screenView
|
|
29
|
+
screenView: () => screenView,
|
|
30
|
+
silentRule: () => silentRule
|
|
31
31
|
});
|
|
32
|
-
import { getEvent } from "@walkeros/core";
|
|
32
|
+
import { createEvent, getEvent } from "@walkeros/core";
|
|
33
33
|
var ENDPOINT = "https://s2s.mparticle.com/v2/events";
|
|
34
34
|
var OPTIONS = {
|
|
35
35
|
headers: {
|
|
@@ -119,7 +119,7 @@ var commercePurchase = {
|
|
|
119
119
|
in: getEvent("order complete", {
|
|
120
120
|
id: "ev-1700000300000",
|
|
121
121
|
timestamp: 17000003e5,
|
|
122
|
-
data: { id: "ORD-300",
|
|
122
|
+
data: { id: "ORD-300", value: 249.99, currency: "EUR" },
|
|
123
123
|
user: { id: "user-123" },
|
|
124
124
|
source: { type: "express", platform: "server" }
|
|
125
125
|
}),
|
|
@@ -133,7 +133,7 @@ var commercePurchase = {
|
|
|
133
133
|
map: {
|
|
134
134
|
action: { value: "purchase" },
|
|
135
135
|
transaction_id: "data.id",
|
|
136
|
-
total_amount: "data.
|
|
136
|
+
total_amount: "data.value"
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
}
|
|
@@ -173,7 +173,8 @@ var commercePurchase = {
|
|
|
173
173
|
var identityAndAttributes = {
|
|
174
174
|
title: "User identities",
|
|
175
175
|
description: "A form submission sends a custom_event whose batch carries user_identities resolved from destination settings.",
|
|
176
|
-
in:
|
|
176
|
+
in: createEvent({
|
|
177
|
+
name: "form submit",
|
|
177
178
|
id: "ev-1700000400000",
|
|
178
179
|
timestamp: 17000004e5,
|
|
179
180
|
data: { type: "newsletter" },
|
|
@@ -211,6 +212,13 @@ var identityAndAttributes = {
|
|
|
211
212
|
]
|
|
212
213
|
]
|
|
213
214
|
};
|
|
215
|
+
var silentRule = {
|
|
216
|
+
public: false,
|
|
217
|
+
description: "A rule with silent: true sends no request to mParticle.",
|
|
218
|
+
in: getEvent("page view", { timestamp: 170000099e4 }),
|
|
219
|
+
mapping: { silent: true },
|
|
220
|
+
out: []
|
|
221
|
+
};
|
|
214
222
|
export {
|
|
215
223
|
env_exports as env,
|
|
216
224
|
step_exports as step
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,s={};((e,n)=>{for(var i in n)t(e,i,{get:n[i],enumerable:!0})})(s,{DestinationMParticle:()=>
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,s={};((e,n)=>{for(var i in n)t(e,i,{get:n[i],enumerable:!0})})(s,{DestinationMParticle:()=>m,default:()=>v,destinationMParticle:()=>d}),module.exports=(e=s,((e,s,r,c)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let a of i(s))o.call(e,a)||a===r||t(e,a,{get:()=>s[a],enumerable:!(c=n(s,a))||c.enumerable});return e})(t({},"__esModule",{value:!0}),e));var r=require("@walkeros/core");var c=require("@walkeros/core"),a=require("@walkeros/server-core");var u=async function(e,{config:t,rule:n,data:i,env:o,logger:s,collector:r}){const{apiKey:u,apiSecret:m,pod:d="us1",environment:v="production",userIdentities:g,userAttributes:f,consent:y,ip:_,sourceRequestId:b}=t.settings??{};if(!u||!m)throw new c.StepError("Config settings missing, init() not run",{code:"not-ready"});const w=n?.settings||{},O=(0,c.isObject)(i)?i:{},j=await async function(e,t,n,i){const o={...(0,c.isObject)(t)?t:{},...(0,c.isObject)(n)?n:{}},s=Object.keys(o);if(0===s.length)return;const r={};for(const t of s){const n=l(await(0,c.getMappingValue)(e,o[t],{collector:i}));void 0!==n&&(r[t]=n)}return Object.keys(r).length>0?r:void 0}(e,g,w.userIdentities,r),h=await async function(e,t,n,i){const o=t?await(0,c.getMappingValue)(e,t,{collector:i}):void 0,s=n?await(0,c.getMappingValue)(e,n,{collector:i}):void 0,r={...(0,c.isObject)(o)?o:{},...(0,c.isObject)(s)?s:{}};return Object.keys(r).length>0?r:void 0}(e,f,w.userAttributes,r),S=_?p(await(0,c.getMappingValue)(e,_,{collector:r})):void 0,k=p(b?await(0,c.getMappingValue)(e,b,{collector:r}):void 0)??(e.id||void 0),M=n?.name||e.name,P=e.timestamp||Date.now(),q=e.id||void 0,I=w.eventType||"custom_event";let x;if("screen_view"===I)x=function(e,t,n,i){return{event_type:"screen_view",data:{...e?{screen_name:e}:{},...t&&Object.keys(t).length>0?{custom_attributes:t}:{},...void 0!==n?{timestamp_unixtime_ms:n}:{},...i?{source_message_id:i}:{}}}}(M,O,P,q);else if("commerce_event"===I){const t=w.commerce?await(0,c.getMappingValue)(e,w.commerce,{collector:r}):void 0;x=function(e,t,n,i){return{event_type:"commerce_event",data:{...e||{},...t&&Object.keys(t).length>0?{custom_attributes:t}:{},...void 0!==n?{timestamp_unixtime_ms:n}:{},...i?{source_message_id:i}:{}}}}((0,c.isObject)(t)?t:void 0,O,P,q)}else{x=function(e,t,n,i,o){return{event_type:"custom_event",data:{event_name:e,custom_event_type:t,...n&&Object.keys(n).length>0?{custom_attributes:n}:{},...void 0!==i?{timestamp_unixtime_ms:i}:{},...o?{source_message_id:o}:{}}}}(M,w.customEventType||"other",O,P,q)}const V=function(e,t,n,i,o={}){const s={events:e,environment:i};return t&&Object.keys(t).length>0&&(s.user_identities=t),n&&Object.keys(n).length>0&&(s.user_attributes=n),o.ip&&(s.ip=o.ip),o.sourceRequestId&&(s.source_request_id=o.sourceRequestId),o.consent&&(s.consent_state=o.consent),o.context&&(s.context=o.context),s}([x],j,h,v,{ip:S,sourceRequestId:k,consent:y}),T=function(e="us1"){return"us1"===e?"https://s2s.mparticle.com/v2/events":`https://s2s.${e}.mparticle.com/v2/events`}(d),$=function(e,t){return`Basic ${Buffer.from(`${e}:${t}`).toString("base64")}`}(u,m);s.debug("Calling mParticle Events API",{endpoint:T,method:"POST",eventType:x.event_type,eventName:M,eventId:e.id});const A=o?.sendServer||a.sendServer;await A(T,JSON.stringify(V),{headers:{Authorization:$,"Content-Type":"application/json"}})};function p(e){if(null!=e)return"string"==typeof e?e||void 0:"number"==typeof e||"boolean"==typeof e?String(e):void 0}function l(e){if(null!=e)return"string"==typeof e?e||void 0:"number"==typeof e?e:"boolean"==typeof e?String(e):void 0}var m={},d={type:"mparticle",config:{},async init({config:e}){const t=function(e={}){const t=e.settings||{},{apiKey:n,apiSecret:i}=t;if(!n||!i){const e=[...n?[]:["apiKey"],...i?[]:["apiSecret"]];throw new r.StepError(`Config settings ${e.join(", ")} missing`,{code:"config"})}const o={pod:"us1",environment:"production",...t,apiKey:n,apiSecret:i};return{...e,settings:o}}(e);return t},push:async(e,t)=>await async function(e,t){t.rule?.silent||await u(e,t)}(e,t)},v=d;//# 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/batch.ts","../src/types/index.ts"],"sourcesContent":["import type { Destination } from './types';\nimport { getConfig } from './config';\nimport { push } from './push';\n\n// Types\nexport * as DestinationMParticle from './types';\n\nexport const destinationMParticle: Destination = {\n type: 'mparticle',\n\n config: {},\n\n async init({ config: partialConfig, logger }) {\n const config = getConfig(partialConfig, logger);\n return config;\n },\n\n async push(event, context) {\n return await push(event, context);\n },\n};\n\nexport default destinationMParticle;\n","import type { Config, PartialConfig, Settings } from './types';\nimport type { Logger } from '@walkeros/core';\n\nexport function getConfig(\n partialConfig: PartialConfig = {},\n logger: Logger.Instance,\n): Config {\n const settings = (partialConfig.settings || {}) as Partial<Settings>;\n const { apiKey, apiSecret } = settings;\n\n if (!apiKey) logger.throw('Config settings apiKey missing');\n if (!apiSecret) logger.throw('Config settings apiSecret missing');\n\n const settingsConfig: Settings = {\n pod: 'us1',\n environment: 'production',\n ...settings,\n apiKey: apiKey as string,\n apiSecret: apiSecret as string,\n };\n\n return { ...partialConfig, settings: settingsConfig };\n}\n","import type {\n Collector,\n WalkerOS,\n Mapping as WalkerOSMapping,\n} from '@walkeros/core';\nimport { getMappingValue, isObject } from '@walkeros/core';\nimport { sendServer } from '@walkeros/server-core';\nimport type {\n CommerceEventData,\n ConsentState,\n CustomEventType,\n Mapping,\n MParticleEvent,\n PushFn,\n Settings,\n} from './types';\nimport {\n buildAuthHeader,\n buildBatch,\n buildCommerceEvent,\n buildCustomEvent,\n buildEndpoint,\n buildScreenViewEvent,\n} from './batch';\n\nexport const push: PushFn = async function (\n event,\n { config, rule, data, env, logger, collector },\n) {\n const settings = config.settings as Settings;\n const {\n apiKey,\n apiSecret,\n pod = 'us1',\n environment = 'production',\n userIdentities: settingsIdentities,\n userAttributes: settingsUserAttributes,\n consent,\n ip: ipSetting,\n sourceRequestId: sourceRequestIdSetting,\n } = settings;\n\n const ruleSettings: Mapping = (rule?.settings || {}) as Mapping;\n\n const customAttributes = isObject(data)\n ? (data as Record<string, unknown>)\n : {};\n\n const userIdentities = await resolveIdentities(\n event,\n settingsIdentities,\n ruleSettings.userIdentities,\n collector,\n );\n\n const userAttributes = await resolveUserAttributes(\n event,\n settingsUserAttributes,\n ruleSettings.userAttributes,\n collector,\n );\n\n const ip = ipSetting\n ? toStringValue(await getMappingValue(event, ipSetting, { collector }))\n : undefined;\n\n const sourceRequestIdRaw = sourceRequestIdSetting\n ? await getMappingValue(event, sourceRequestIdSetting, { collector })\n : undefined;\n const sourceRequestId =\n toStringValue(sourceRequestIdRaw) ?? (event.id || undefined);\n\n const eventName = rule?.name || event.name;\n const timestamp = event.timestamp || Date.now();\n const sourceMessageId = event.id || undefined;\n const eventType = ruleSettings.eventType || 'custom_event';\n\n let mpEvent: MParticleEvent;\n if (eventType === 'screen_view') {\n mpEvent = buildScreenViewEvent(\n eventName,\n customAttributes,\n timestamp,\n sourceMessageId,\n );\n } else if (eventType === 'commerce_event') {\n const commerceResolved = ruleSettings.commerce\n ? await getMappingValue(event, ruleSettings.commerce, { collector })\n : undefined;\n const commerceData = isObject(commerceResolved)\n ? (commerceResolved as Partial<CommerceEventData>)\n : undefined;\n mpEvent = buildCommerceEvent(\n commerceData,\n customAttributes,\n timestamp,\n sourceMessageId,\n );\n } else {\n const customEventType: CustomEventType =\n ruleSettings.customEventType || 'other';\n mpEvent = buildCustomEvent(\n eventName,\n customEventType,\n customAttributes,\n timestamp,\n sourceMessageId,\n );\n }\n\n const batch = buildBatch(\n [mpEvent],\n userIdentities,\n userAttributes,\n environment,\n {\n ip,\n sourceRequestId,\n consent: consent as ConsentState | undefined,\n },\n );\n\n const endpoint = buildEndpoint(pod);\n const authHeader = buildAuthHeader(apiKey, apiSecret);\n\n logger.debug('Calling mParticle Events API', {\n endpoint,\n method: 'POST',\n eventType: mpEvent.event_type,\n eventName,\n eventId: event.id,\n });\n\n const sendServerFn = env?.sendServer || sendServer;\n const result = await sendServerFn(endpoint, JSON.stringify(batch), {\n headers: {\n Authorization: authHeader,\n 'Content-Type': 'application/json',\n },\n });\n\n logger.debug('mParticle API response', {\n ok: isObject(result) ? result.ok : true,\n });\n\n if (isObject(result) && result.ok === false) {\n logger.throw(`mParticle API error: ${JSON.stringify(result)}`);\n }\n};\n\nasync function resolveIdentities(\n event: WalkerOS.Event,\n settingsIdentities: WalkerOSMapping.Map | undefined,\n ruleIdentities: WalkerOSMapping.Map | undefined,\n collector: Collector.Instance,\n): Promise<Record<string, string | number> | undefined> {\n const merged: WalkerOSMapping.Map = {\n ...(isObject(settingsIdentities) ? settingsIdentities : {}),\n ...(isObject(ruleIdentities) ? ruleIdentities : {}),\n };\n const keys = Object.keys(merged);\n if (keys.length === 0) return undefined;\n\n const out: Record<string, string | number> = {};\n for (const key of keys) {\n const raw = await getMappingValue(event, merged[key], { collector });\n const coerced = toIdentityValue(raw);\n if (coerced !== undefined) out[key] = coerced;\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\nasync function resolveUserAttributes(\n event: WalkerOS.Event,\n settingsAttributes: WalkerOSMapping.Value | undefined,\n ruleAttributes: WalkerOSMapping.Value | undefined,\n collector: Collector.Instance,\n): Promise<Record<string, unknown> | undefined> {\n const settingsResolved = settingsAttributes\n ? await getMappingValue(event, settingsAttributes, { collector })\n : undefined;\n const ruleResolved = ruleAttributes\n ? await getMappingValue(event, ruleAttributes, { collector })\n : undefined;\n\n const merged: Record<string, unknown> = {\n ...(isObject(settingsResolved)\n ? (settingsResolved as Record<string, unknown>)\n : {}),\n ...(isObject(ruleResolved)\n ? (ruleResolved as Record<string, unknown>)\n : {}),\n };\n return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\nfunction toStringValue(value: unknown): string | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value === 'string') return value || undefined;\n if (typeof value === 'number' || typeof value === 'boolean')\n return String(value);\n return undefined;\n}\n\nfunction toIdentityValue(value: unknown): string | number | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value === 'string') return value || undefined;\n if (typeof value === 'number') return value;\n if (typeof value === 'boolean') return String(value);\n return undefined;\n}\n","import type {\n CommerceEventData,\n ConsentState,\n CustomEventType,\n Environment,\n MParticleBatch,\n MParticleEvent,\n Pod,\n ScreenViewEventData,\n} from './types';\n\n/**\n * Returns the mParticle Events API endpoint for the given pod.\n * us1 resolves to the legacy host (`s2s.mparticle.com`); other pods use the\n * pod-qualified host.\n * https://docs.mparticle.com/developers/server/http/#endpoint\n */\nexport function buildEndpoint(pod: Pod = 'us1'): string {\n if (pod === 'us1') return 'https://s2s.mparticle.com/v2/events';\n return `https://s2s.${pod}.mparticle.com/v2/events`;\n}\n\n/**\n * Builds the HTTP Basic auth header value from an API key/secret pair.\n * Uses Buffer (Node) for base64 encoding to keep server semantics.\n */\nexport function buildAuthHeader(apiKey: string, apiSecret: string): string {\n const token = Buffer.from(`${apiKey}:${apiSecret}`).toString('base64');\n return `Basic ${token}`;\n}\n\n/**\n * Builds a custom_event payload.\n */\nexport function buildCustomEvent(\n eventName: string,\n customEventType: CustomEventType,\n customAttributes: Record<string, unknown> | undefined,\n timestamp: number | undefined,\n sourceMessageId: string | undefined,\n): MParticleEvent {\n return {\n event_type: 'custom_event',\n data: {\n event_name: eventName,\n custom_event_type: customEventType,\n ...(customAttributes && Object.keys(customAttributes).length > 0\n ? { custom_attributes: customAttributes }\n : {}),\n ...(timestamp !== undefined ? { timestamp_unixtime_ms: timestamp } : {}),\n ...(sourceMessageId ? { source_message_id: sourceMessageId } : {}),\n },\n };\n}\n\n/**\n * Builds a screen_view event payload.\n */\nexport function buildScreenViewEvent(\n screenName: string | undefined,\n customAttributes: Record<string, unknown> | undefined,\n timestamp: number | undefined,\n sourceMessageId: string | undefined,\n): MParticleEvent {\n const data: ScreenViewEventData = {\n ...(screenName ? { screen_name: screenName } : {}),\n ...(customAttributes && Object.keys(customAttributes).length > 0\n ? { custom_attributes: customAttributes }\n : {}),\n ...(timestamp !== undefined ? { timestamp_unixtime_ms: timestamp } : {}),\n ...(sourceMessageId ? { source_message_id: sourceMessageId } : {}),\n };\n return { event_type: 'screen_view', data };\n}\n\n/**\n * Builds a commerce_event payload. Commerce data is a loosely-shaped subset\n * of {@link CommerceEventData} (product_action, currency_code, ...) resolved\n * from the per-rule commerce mapping.\n */\nexport function buildCommerceEvent(\n commerceData: Partial<CommerceEventData> | undefined,\n customAttributes: Record<string, unknown> | undefined,\n timestamp: number | undefined,\n sourceMessageId: string | undefined,\n): MParticleEvent {\n const data: CommerceEventData = {\n ...(commerceData || {}),\n ...(customAttributes && Object.keys(customAttributes).length > 0\n ? { custom_attributes: customAttributes }\n : {}),\n ...(timestamp !== undefined ? { timestamp_unixtime_ms: timestamp } : {}),\n ...(sourceMessageId ? { source_message_id: sourceMessageId } : {}),\n };\n return { event_type: 'commerce_event', data };\n}\n\nexport interface BuildBatchOptions {\n ip?: string;\n sourceRequestId?: string;\n consent?: ConsentState;\n context?: Record<string, unknown>;\n}\n\n/**\n * Assembles the batch envelope wrapping events + identity + environment.\n */\nexport function buildBatch(\n events: MParticleEvent[],\n userIdentities: Record<string, string | number> | undefined,\n userAttributes: Record<string, unknown> | undefined,\n environment: Environment,\n options: BuildBatchOptions = {},\n): MParticleBatch {\n const batch: MParticleBatch = {\n events,\n environment,\n };\n if (userIdentities && Object.keys(userIdentities).length > 0)\n batch.user_identities = userIdentities;\n if (userAttributes && Object.keys(userAttributes).length > 0)\n batch.user_attributes = userAttributes;\n if (options.ip) batch.ip = options.ip;\n if (options.sourceRequestId)\n batch.source_request_id = options.sourceRequestId;\n if (options.consent) batch.consent_state = options.consent;\n if (options.context) batch.context = options.context;\n return batch;\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\n/**\n * mParticle data pod. Determines the regional endpoint used for the Events\n * API. Defaults to `us1`. See {@link buildEndpoint} in `batch.ts`.\n */\nexport type Pod = 'us1' | 'us2' | 'eu1' | 'au1';\n\n/**\n * mParticle environment for the batch. `production` routes to production\n * data streams; `development` sends to debug/verify streams.\n */\nexport type Environment = 'production' | 'development';\n\n/**\n * Event type used for the outgoing mParticle event. Defaults to\n * `custom_event` when not explicitly mapped via rule settings.\n */\nexport type EventType = 'custom_event' | 'screen_view' | 'commerce_event';\n\n/**\n * mParticle custom event type (category) for `custom_event`s. Defaults to\n * `other` when not specified.\n */\nexport type CustomEventType =\n | 'navigation'\n | 'location'\n | 'search'\n | 'transaction'\n | 'user_content'\n | 'user_preference'\n | 'social'\n | 'media'\n | 'attribution'\n | 'other';\n\n/**\n * mParticle product action verbs for commerce events.\n */\nexport type ProductActionType =\n | 'add_to_cart'\n | 'remove_from_cart'\n | 'checkout'\n | 'checkout_option'\n | 'click'\n | 'view_detail'\n | 'purchase'\n | 'refund'\n | 'add_to_wishlist'\n | 'remove_from_wishlist';\n\nexport interface Settings {\n /** mParticle input feed API key. */\n apiKey: string;\n /** mParticle input feed API secret. */\n apiSecret: string;\n /** Data pod selecting the regional endpoint. Default: `us1`. */\n pod?: Pod;\n /** Environment the batch targets. Default: `production`. */\n environment?: Environment;\n /**\n * Mapping that resolves to `user_identities` per batch. Each entry value\n * is a walkerOS mapping value; the resolved object is placed into the\n * mParticle batch `user_identities` envelope.\n */\n userIdentities?: WalkerOSMapping.Map;\n /**\n * Mapping that resolves to `user_attributes` per batch.\n */\n userAttributes?: WalkerOSMapping.Value;\n /**\n * Optional static consent state passthrough — shape is forwarded verbatim\n * to `consent_state` on the batch.\n */\n consent?: ConsentState;\n /** walkerOS mapping value resolving to the client IP for the batch. */\n ip?: WalkerOSMapping.Value;\n /**\n * Optional request correlation id. When omitted, falls back to `event.id`.\n */\n sourceRequestId?: WalkerOSMapping.Value;\n}\n\nexport type InitSettings = Partial<Settings>;\n\n/**\n * Per-rule mapping settings. Determines which mParticle event shape is\n * produced for this walkerOS event and allows per-event identity overrides.\n */\nexport interface Mapping {\n /** Event type. Default: `custom_event`. */\n eventType?: EventType;\n /** Custom event type category for `custom_event`. Default: `other`. */\n customEventType?: CustomEventType;\n /** Commerce mapping resolving to ProductAction and related fields. */\n commerce?: WalkerOSMapping.Value;\n /** Per-event override for `user_identities`. Merged over settings. */\n userIdentities?: WalkerOSMapping.Map;\n /** Per-event override for `user_attributes`. */\n userAttributes?: WalkerOSMapping.Value;\n}\n\nexport interface Env extends DestinationServer.Env {\n sendServer?: typeof sendServer;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\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>;\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\n/**\n * Top-level mParticle batch payload posted to\n * `https://s2s.{pod}.mparticle.com/v2/events`.\n * https://docs.mparticle.com/developers/server/http/\n */\nexport interface MParticleBatch {\n events: MParticleEvent[];\n user_identities?: Record<string, string | number>;\n user_attributes?: Record<string, unknown>;\n environment: Environment;\n schema_version?: number;\n ip?: string;\n source_request_id?: string;\n consent_state?: ConsentState;\n context?: Record<string, unknown>;\n}\n\nexport type MParticleEvent =\n | { event_type: 'custom_event'; data: CustomEventData }\n | { event_type: 'screen_view'; data: ScreenViewEventData }\n | { event_type: 'commerce_event'; data: CommerceEventData };\n\nexport interface CommonEventData {\n timestamp_unixtime_ms?: number;\n source_message_id?: string;\n session_uuid?: string;\n custom_attributes?: Record<string, unknown>;\n custom_flags?: Record<string, unknown>;\n location?: Record<string, unknown>;\n}\n\nexport interface CustomEventData extends CommonEventData {\n event_name: string;\n custom_event_type: CustomEventType;\n}\n\nexport interface ScreenViewEventData extends CommonEventData {\n screen_name?: string;\n}\n\nexport interface CommerceEventData extends CommonEventData {\n product_action?: ProductAction;\n promotion_action?: PromotionAction;\n product_impressions?: ProductImpression[];\n currency_code?: string;\n is_non_interactive?: boolean;\n}\n\nexport interface ProductAction {\n action: ProductActionType;\n transaction_id?: string;\n total_amount?: number;\n tax_amount?: number;\n shipping_amount?: number;\n coupon_code?: string;\n affiliation?: string;\n checkout_step?: number;\n checkout_options?: string;\n products?: Product[];\n}\n\nexport interface Product {\n id?: string;\n name?: string;\n brand?: string;\n category?: string;\n variant?: string;\n position?: number;\n price?: number;\n quantity?: number;\n coupon_code?: string;\n total_product_amount?: number;\n custom_attributes?: Record<string, unknown>;\n}\n\nexport interface PromotionAction {\n action: 'view' | 'click';\n promotions?: Array<{\n id?: string;\n name?: string;\n creative?: string;\n position?: string;\n }>;\n}\n\nexport interface ProductImpression {\n product_impression_list?: string;\n products?: Product[];\n}\n\n/**\n * mParticle consent state envelope forwarded verbatim on the batch.\n * https://docs.mparticle.com/developers/server/http/#consent-state\n */\nexport interface ConsentState {\n gdpr?: Record<string, GDPRConsentState>;\n ccpa?: { data_sale_opt_out?: CCPAConsentState };\n}\n\nexport interface GDPRConsentState {\n consented: boolean;\n document?: string;\n timestamp_unixtime_ms?: number;\n location?: string;\n hardware_id?: string;\n}\n\nexport interface CCPAConsentState {\n consented: boolean;\n document?: string;\n timestamp_unixtime_ms?: number;\n location?: string;\n hardware_id?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,SAAS,UACd,gBAA+B,CAAC,GAChC,QACQ;AACR,QAAM,WAAY,cAAc,YAAY,CAAC;AAC7C,QAAM,EAAE,QAAQ,UAAU,IAAI;AAE9B,MAAI,CAAC,OAAQ,QAAO,MAAM,gCAAgC;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AC1D;AAEJ,QAAM,SAAkC;AAAA,IACtC,OAAI,sBAAS,gBAAgB,IACxB,mBACD,CAAC;AAAA,IACL,OAAI,sBAAS,YAAY,IACpB,eACD,CAAC;AAAA,EACP;AACA,SAAO,OAAO,KAAK,MAAM,EAAE,SAAS,IAAI,SAAS;AACnD;AAEA,SAAS,cAAc,OAAoC;AACzD,MAAI,UAAU,UAAa,UAAU,KAAM,QAAO;AAClD,MAAI,OAAO,UAAU,SAAU,QAAO,SAAS;AAC/C,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU;AAChD,WAAO,OAAO,KAAK;AACrB,SAAO;AACT;AAEA,SAAS,gBAAgB,OAA6C;AACpE,MAAI,UAAU,UAAa,UAAU,KAAM,QAAO;AAClD,MAAI,OAAO,UAAU,SAAU,QAAO,SAAS;AAC/C,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,MAAI,OAAO,UAAU,UAAW,QAAO,OAAO,KAAK;AACnD,SAAO;AACT;;;AElNA;;;AJOO,IAAM,uBAAoC;AAAA,EAC/C,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,MAAM,KAAK,EAAE,QAAQ,eAAe,OAAO,GAAG;AAC5C,UAAM,SAAS,UAAU,eAAe,MAAM;AAC9C,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,KAAK,OAAO,SAAS;AACzB,WAAO,MAAM,KAAK,OAAO,OAAO;AAAA,EAClC;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/config.ts","../src/push.ts","../src/batch.ts","../src/types/index.ts"],"sourcesContent":["import type { Destination } from './types';\nimport { getConfig } from './config';\nimport { push } from './push';\n\n// Types\nexport * as DestinationMParticle from './types';\n\nexport const destinationMParticle: Destination = {\n type: 'mparticle',\n\n config: {},\n\n async init({ config: partialConfig }) {\n const config = getConfig(partialConfig);\n return config;\n },\n\n async push(event, context) {\n return await push(event, context);\n },\n};\n\nexport default destinationMParticle;\n","import type { Config, PartialConfig, Settings } from './types';\nimport { StepError } from '@walkeros/core';\n\nexport function getConfig(partialConfig: PartialConfig = {}): Config {\n const settings: Partial<Settings> = partialConfig.settings || {};\n const { apiKey, apiSecret } = settings;\n\n if (!apiKey || !apiSecret) {\n const missing = [\n ...(apiKey ? [] : ['apiKey']),\n ...(apiSecret ? [] : ['apiSecret']),\n ];\n throw new StepError(`Config settings ${missing.join(', ')} missing`, {\n code: 'config',\n });\n }\n\n const settingsConfig: Settings = {\n pod: 'us1',\n environment: 'production',\n ...settings,\n apiKey,\n apiSecret,\n };\n\n return { ...partialConfig, settings: settingsConfig };\n}\n","import type {\n Collector,\n WalkerOS,\n Mapping as WalkerOSMapping,\n} from '@walkeros/core';\nimport { getMappingValue, isObject, StepError } from '@walkeros/core';\nimport { sendServer } from '@walkeros/server-core';\nimport type {\n CommerceEventData,\n ConsentState,\n CustomEventType,\n Mapping,\n MParticleEvent,\n PushFn,\n Settings,\n} from './types';\nimport {\n buildAuthHeader,\n buildBatch,\n buildCommerceEvent,\n buildCustomEvent,\n buildEndpoint,\n buildScreenViewEvent,\n} from './batch';\n\n// A silent rule has no mparticle call of its own: nothing to send.\nexport const push: PushFn = async function (event, context) {\n if (!context.rule?.silent) await send(event, context);\n};\n\nconst send: PushFn = async function (\n event,\n { config, rule, data, env, logger, collector },\n) {\n const {\n apiKey,\n apiSecret,\n pod = 'us1',\n environment = 'production',\n userIdentities: settingsIdentities,\n userAttributes: settingsUserAttributes,\n consent,\n ip: ipSetting,\n sourceRequestId: sourceRequestIdSetting,\n } = config.settings ?? {};\n\n // init() validates these; a destination that skipped it is not ready.\n if (!apiKey || !apiSecret)\n throw new StepError('Config settings missing, init() not run', {\n code: 'not-ready',\n });\n\n const ruleSettings: Mapping = (rule?.settings || {}) as Mapping;\n\n const customAttributes = isObject(data)\n ? (data as Record<string, unknown>)\n : {};\n\n const userIdentities = await resolveIdentities(\n event,\n settingsIdentities,\n ruleSettings.userIdentities,\n collector,\n );\n\n const userAttributes = await resolveUserAttributes(\n event,\n settingsUserAttributes,\n ruleSettings.userAttributes,\n collector,\n );\n\n const ip = ipSetting\n ? toStringValue(await getMappingValue(event, ipSetting, { collector }))\n : undefined;\n\n const sourceRequestIdRaw = sourceRequestIdSetting\n ? await getMappingValue(event, sourceRequestIdSetting, { collector })\n : undefined;\n const sourceRequestId =\n toStringValue(sourceRequestIdRaw) ?? (event.id || undefined);\n\n const eventName = rule?.name || event.name;\n const timestamp = event.timestamp || Date.now();\n const sourceMessageId = event.id || undefined;\n const eventType = ruleSettings.eventType || 'custom_event';\n\n let mpEvent: MParticleEvent;\n if (eventType === 'screen_view') {\n mpEvent = buildScreenViewEvent(\n eventName,\n customAttributes,\n timestamp,\n sourceMessageId,\n );\n } else if (eventType === 'commerce_event') {\n const commerceResolved = ruleSettings.commerce\n ? await getMappingValue(event, ruleSettings.commerce, { collector })\n : undefined;\n const commerceData = isObject(commerceResolved)\n ? (commerceResolved as Partial<CommerceEventData>)\n : undefined;\n mpEvent = buildCommerceEvent(\n commerceData,\n customAttributes,\n timestamp,\n sourceMessageId,\n );\n } else {\n const customEventType: CustomEventType =\n ruleSettings.customEventType || 'other';\n mpEvent = buildCustomEvent(\n eventName,\n customEventType,\n customAttributes,\n timestamp,\n sourceMessageId,\n );\n }\n\n const batch = buildBatch(\n [mpEvent],\n userIdentities,\n userAttributes,\n environment,\n {\n ip,\n sourceRequestId,\n consent: consent as ConsentState | undefined,\n },\n );\n\n const endpoint = buildEndpoint(pod);\n const authHeader = buildAuthHeader(apiKey, apiSecret);\n\n logger.debug('Calling mParticle Events API', {\n endpoint,\n method: 'POST',\n eventType: mpEvent.event_type,\n eventName,\n eventId: event.id,\n });\n\n const sendServerFn = env?.sendServer || sendServer;\n await sendServerFn(endpoint, JSON.stringify(batch), {\n headers: {\n Authorization: authHeader,\n 'Content-Type': 'application/json',\n },\n });\n};\n\nasync function resolveIdentities(\n event: WalkerOS.Event,\n settingsIdentities: WalkerOSMapping.Map | undefined,\n ruleIdentities: WalkerOSMapping.Map | undefined,\n collector: Collector.Instance,\n): Promise<Record<string, string | number> | undefined> {\n const merged: WalkerOSMapping.Map = {\n ...(isObject(settingsIdentities) ? settingsIdentities : {}),\n ...(isObject(ruleIdentities) ? ruleIdentities : {}),\n };\n const keys = Object.keys(merged);\n if (keys.length === 0) return undefined;\n\n const out: Record<string, string | number> = {};\n for (const key of keys) {\n const raw = await getMappingValue(event, merged[key], { collector });\n const coerced = toIdentityValue(raw);\n if (coerced !== undefined) out[key] = coerced;\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\nasync function resolveUserAttributes(\n event: WalkerOS.Event,\n settingsAttributes: WalkerOSMapping.Value | undefined,\n ruleAttributes: WalkerOSMapping.Value | undefined,\n collector: Collector.Instance,\n): Promise<Record<string, unknown> | undefined> {\n const settingsResolved = settingsAttributes\n ? await getMappingValue(event, settingsAttributes, { collector })\n : undefined;\n const ruleResolved = ruleAttributes\n ? await getMappingValue(event, ruleAttributes, { collector })\n : undefined;\n\n const merged: Record<string, unknown> = {\n ...(isObject(settingsResolved)\n ? (settingsResolved as Record<string, unknown>)\n : {}),\n ...(isObject(ruleResolved)\n ? (ruleResolved as Record<string, unknown>)\n : {}),\n };\n return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\nfunction toStringValue(value: unknown): string | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value === 'string') return value || undefined;\n if (typeof value === 'number' || typeof value === 'boolean')\n return String(value);\n return undefined;\n}\n\nfunction toIdentityValue(value: unknown): string | number | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value === 'string') return value || undefined;\n if (typeof value === 'number') return value;\n if (typeof value === 'boolean') return String(value);\n return undefined;\n}\n","import type {\n CommerceEventData,\n ConsentState,\n CustomEventType,\n Environment,\n MParticleBatch,\n MParticleEvent,\n Pod,\n ScreenViewEventData,\n} from './types';\n\n/**\n * Returns the mParticle Events API endpoint for the given pod.\n * us1 resolves to the legacy host (`s2s.mparticle.com`); other pods use the\n * pod-qualified host.\n * https://docs.mparticle.com/developers/server/http/#endpoint\n */\nexport function buildEndpoint(pod: Pod = 'us1'): string {\n if (pod === 'us1') return 'https://s2s.mparticle.com/v2/events';\n return `https://s2s.${pod}.mparticle.com/v2/events`;\n}\n\n/**\n * Builds the HTTP Basic auth header value from an API key/secret pair.\n * Uses Buffer (Node) for base64 encoding to keep server semantics.\n */\nexport function buildAuthHeader(apiKey: string, apiSecret: string): string {\n const token = Buffer.from(`${apiKey}:${apiSecret}`).toString('base64');\n return `Basic ${token}`;\n}\n\n/**\n * Builds a custom_event payload.\n */\nexport function buildCustomEvent(\n eventName: string,\n customEventType: CustomEventType,\n customAttributes: Record<string, unknown> | undefined,\n timestamp: number | undefined,\n sourceMessageId: string | undefined,\n): MParticleEvent {\n return {\n event_type: 'custom_event',\n data: {\n event_name: eventName,\n custom_event_type: customEventType,\n ...(customAttributes && Object.keys(customAttributes).length > 0\n ? { custom_attributes: customAttributes }\n : {}),\n ...(timestamp !== undefined ? { timestamp_unixtime_ms: timestamp } : {}),\n ...(sourceMessageId ? { source_message_id: sourceMessageId } : {}),\n },\n };\n}\n\n/**\n * Builds a screen_view event payload.\n */\nexport function buildScreenViewEvent(\n screenName: string | undefined,\n customAttributes: Record<string, unknown> | undefined,\n timestamp: number | undefined,\n sourceMessageId: string | undefined,\n): MParticleEvent {\n const data: ScreenViewEventData = {\n ...(screenName ? { screen_name: screenName } : {}),\n ...(customAttributes && Object.keys(customAttributes).length > 0\n ? { custom_attributes: customAttributes }\n : {}),\n ...(timestamp !== undefined ? { timestamp_unixtime_ms: timestamp } : {}),\n ...(sourceMessageId ? { source_message_id: sourceMessageId } : {}),\n };\n return { event_type: 'screen_view', data };\n}\n\n/**\n * Builds a commerce_event payload. Commerce data is a loosely-shaped subset\n * of {@link CommerceEventData} (product_action, currency_code, ...) resolved\n * from the per-rule commerce mapping.\n */\nexport function buildCommerceEvent(\n commerceData: Partial<CommerceEventData> | undefined,\n customAttributes: Record<string, unknown> | undefined,\n timestamp: number | undefined,\n sourceMessageId: string | undefined,\n): MParticleEvent {\n const data: CommerceEventData = {\n ...(commerceData || {}),\n ...(customAttributes && Object.keys(customAttributes).length > 0\n ? { custom_attributes: customAttributes }\n : {}),\n ...(timestamp !== undefined ? { timestamp_unixtime_ms: timestamp } : {}),\n ...(sourceMessageId ? { source_message_id: sourceMessageId } : {}),\n };\n return { event_type: 'commerce_event', data };\n}\n\nexport interface BuildBatchOptions {\n ip?: string;\n sourceRequestId?: string;\n consent?: ConsentState;\n context?: Record<string, unknown>;\n}\n\n/**\n * Assembles the batch envelope wrapping events + identity + environment.\n */\nexport function buildBatch(\n events: MParticleEvent[],\n userIdentities: Record<string, string | number> | undefined,\n userAttributes: Record<string, unknown> | undefined,\n environment: Environment,\n options: BuildBatchOptions = {},\n): MParticleBatch {\n const batch: MParticleBatch = {\n events,\n environment,\n };\n if (userIdentities && Object.keys(userIdentities).length > 0)\n batch.user_identities = userIdentities;\n if (userAttributes && Object.keys(userAttributes).length > 0)\n batch.user_attributes = userAttributes;\n if (options.ip) batch.ip = options.ip;\n if (options.sourceRequestId)\n batch.source_request_id = options.sourceRequestId;\n if (options.consent) batch.consent_state = options.consent;\n if (options.context) batch.context = options.context;\n return batch;\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\n/**\n * mParticle data pod. Determines the regional endpoint used for the Events\n * API. Defaults to `us1`. See {@link buildEndpoint} in `batch.ts`.\n */\nexport type Pod = 'us1' | 'us2' | 'eu1' | 'au1';\n\n/**\n * mParticle environment for the batch. `production` routes to production\n * data streams; `development` sends to debug/verify streams.\n */\nexport type Environment = 'production' | 'development';\n\n/**\n * Event type used for the outgoing mParticle event. Defaults to\n * `custom_event` when not explicitly mapped via rule settings.\n */\nexport type EventType = 'custom_event' | 'screen_view' | 'commerce_event';\n\n/**\n * mParticle custom event type (category) for `custom_event`s. Defaults to\n * `other` when not specified.\n */\nexport type CustomEventType =\n | 'navigation'\n | 'location'\n | 'search'\n | 'transaction'\n | 'user_content'\n | 'user_preference'\n | 'social'\n | 'media'\n | 'attribution'\n | 'other';\n\n/**\n * mParticle product action verbs for commerce events.\n */\nexport type ProductActionType =\n | 'add_to_cart'\n | 'remove_from_cart'\n | 'checkout'\n | 'checkout_option'\n | 'click'\n | 'view_detail'\n | 'purchase'\n | 'refund'\n | 'add_to_wishlist'\n | 'remove_from_wishlist';\n\nexport interface Settings {\n /** mParticle input feed API key. */\n apiKey: string;\n /** mParticle input feed API secret. */\n apiSecret: string;\n /** Data pod selecting the regional endpoint. Default: `us1`. */\n pod?: Pod;\n /** Environment the batch targets. Default: `production`. */\n environment?: Environment;\n /**\n * Mapping that resolves to `user_identities` per batch. Each entry value\n * is a walkerOS mapping value; the resolved object is placed into the\n * mParticle batch `user_identities` envelope.\n */\n userIdentities?: WalkerOSMapping.Map;\n /**\n * Mapping that resolves to `user_attributes` per batch.\n */\n userAttributes?: WalkerOSMapping.Value;\n /**\n * Optional static consent state passthrough — shape is forwarded verbatim\n * to `consent_state` on the batch.\n */\n consent?: ConsentState;\n /** walkerOS mapping value resolving to the client IP for the batch. */\n ip?: WalkerOSMapping.Value;\n /**\n * Optional request correlation id. When omitted, falls back to `event.id`.\n */\n sourceRequestId?: WalkerOSMapping.Value;\n}\n\nexport type InitSettings = Partial<Settings>;\n\n/**\n * Per-rule mapping settings. Determines which mParticle event shape is\n * produced for this walkerOS event and allows per-event identity overrides.\n */\nexport interface Mapping {\n /** Event type. Default: `custom_event`. */\n eventType?: EventType;\n /** Custom event type category for `custom_event`. Default: `other`. */\n customEventType?: CustomEventType;\n /** Commerce mapping resolving to ProductAction and related fields. */\n commerce?: WalkerOSMapping.Value;\n /** Per-event override for `user_identities`. Merged over settings. */\n userIdentities?: WalkerOSMapping.Map;\n /** Per-event override for `user_attributes`. */\n userAttributes?: WalkerOSMapping.Value;\n}\n\nexport interface Env extends DestinationServer.Env {\n sendServer?: typeof sendServer;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\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>;\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\n/**\n * Top-level mParticle batch payload posted to\n * `https://s2s.{pod}.mparticle.com/v2/events`.\n * https://docs.mparticle.com/developers/server/http/\n */\nexport interface MParticleBatch {\n events: MParticleEvent[];\n user_identities?: Record<string, string | number>;\n user_attributes?: Record<string, unknown>;\n environment: Environment;\n schema_version?: number;\n ip?: string;\n source_request_id?: string;\n consent_state?: ConsentState;\n context?: Record<string, unknown>;\n}\n\nexport type MParticleEvent =\n | { event_type: 'custom_event'; data: CustomEventData }\n | { event_type: 'screen_view'; data: ScreenViewEventData }\n | { event_type: 'commerce_event'; data: CommerceEventData };\n\nexport interface CommonEventData {\n timestamp_unixtime_ms?: number;\n source_message_id?: string;\n session_uuid?: string;\n custom_attributes?: Record<string, unknown>;\n custom_flags?: Record<string, unknown>;\n location?: Record<string, unknown>;\n}\n\nexport interface CustomEventData extends CommonEventData {\n event_name: string;\n custom_event_type: CustomEventType;\n}\n\nexport interface ScreenViewEventData extends CommonEventData {\n screen_name?: string;\n}\n\nexport interface CommerceEventData extends CommonEventData {\n product_action?: ProductAction;\n promotion_action?: PromotionAction;\n product_impressions?: ProductImpression[];\n currency_code?: string;\n is_non_interactive?: boolean;\n}\n\nexport interface ProductAction {\n action: ProductActionType;\n transaction_id?: string;\n total_amount?: number;\n tax_amount?: number;\n shipping_amount?: number;\n coupon_code?: string;\n affiliation?: string;\n checkout_step?: number;\n checkout_options?: string;\n products?: Product[];\n}\n\nexport interface Product {\n id?: string;\n name?: string;\n brand?: string;\n category?: string;\n variant?: string;\n position?: number;\n price?: number;\n quantity?: number;\n coupon_code?: string;\n total_product_amount?: number;\n custom_attributes?: Record<string, unknown>;\n}\n\nexport interface PromotionAction {\n action: 'view' | 'click';\n promotions?: Array<{\n id?: string;\n name?: string;\n creative?: string;\n position?: string;\n }>;\n}\n\nexport interface ProductImpression {\n product_impression_list?: string;\n products?: Product[];\n}\n\n/**\n * mParticle consent state envelope forwarded verbatim on the batch.\n * https://docs.mparticle.com/developers/server/http/#consent-state\n */\nexport interface ConsentState {\n gdpr?: Record<string, GDPRConsentState>;\n ccpa?: { data_sale_opt_out?: CCPAConsentState };\n}\n\nexport interface GDPRConsentState {\n consented: boolean;\n document?: string;\n timestamp_unixtime_ms?: number;\n location?: string;\n hardware_id?: string;\n}\n\nexport interface CCPAConsentState {\n consented: boolean;\n document?: string;\n timestamp_unixtime_ms?: number;\n location?: string;\n hardware_id?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,kBAA0B;AAEnB,SAAS,UAAU,gBAA+B,CAAC,GAAW;AACnE,QAAM,WAA8B,cAAc,YAAY,CAAC;AAC/D,QAAM,EAAE,QAAQ,UAAU,IAAI;AAE9B,MAAI,CAAC,UAAU,CAAC,WAAW;AACzB,UAAM,UAAU;AAAA,MACd,GAAI,SAAS,CAAC,IAAI,CAAC,QAAQ;AAAA,MAC3B,GAAI,YAAY,CAAC,IAAI,CAAC,WAAW;AAAA,IACnC;AACA,UAAM,IAAI,sBAAU,mBAAmB,QAAQ,KAAK,IAAI,CAAC,YAAY;AAAA,MACnE,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AAEA,QAAM,iBAA2B;AAAA,IAC/B,KAAK;AAAA,IACL,aAAa;AAAA,IACb,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AAEA,SAAO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AAS;AACnD;AAEA,SAAS,cAAc,OAAoC;AACzD,MAAI,UAAU,UAAa,UAAU,KAAM,QAAO;AAClD,MAAI,OAAO,UAAU,SAAU,QAAO,SAAS;AAC/C,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU;AAChD,WAAO,OAAO,KAAK;AACrB,SAAO;AACT;AAEA,SAAS,gBAAgB,OAA6C;AACpE,MAAI,UAAU,UAAa,UAAU,KAAM,QAAO;AAClD,MAAI,OAAO,UAAU,SAAU,QAAO,SAAS;AAC/C,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,MAAI,OAAO,UAAU,UAAW,QAAO,OAAO,KAAK;AACnD,SAAO;AACT;;;AEpNA;;;AJOO,IAAM,uBAAoC;AAAA,EAC/C,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,SAAS;AACzB,WAAO,MAAM,KAAK,OAAO,OAAO;AAAA,EAClC;AACF;AAEA,IAAO,gBAAQ;","names":["import_core"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getMappingValue as
|
|
1
|
+
import{createRequire as e}from"module";e(import.meta.url);import{StepError as t}from"@walkeros/core";import{getMappingValue as n,isObject as o,StepError as i}from"@walkeros/core";import{sendServer as s}from"@walkeros/server-core";var r=async function(e,{config:t,rule:r,data:u,env:m,logger:p,collector:d}){const{apiKey:l,apiSecret:v,pod:f="us1",environment:y="production",userIdentities:g,userAttributes:_,consent:w,ip:b,sourceRequestId:h}=t.settings??{};if(!l||!v)throw new i("Config settings missing, init() not run",{code:"not-ready"});const k=r?.settings||{},S=o(u)?u:{},j=await async function(e,t,i,s){const r={...o(t)?t:{},...o(i)?i:{}},c=Object.keys(r);if(0===c.length)return;const u={};for(const t of c){const o=a(await n(e,r[t],{collector:s}));void 0!==o&&(u[t]=o)}return Object.keys(u).length>0?u:void 0}(e,g,k.userIdentities,d),O=await async function(e,t,i,s){const r=t?await n(e,t,{collector:s}):void 0,c=i?await n(e,i,{collector:s}):void 0,a={...o(r)?r:{},...o(c)?c:{}};return Object.keys(a).length>0?a:void 0}(e,_,k.userAttributes,d),I=b?c(await n(e,b,{collector:d})):void 0,x=c(h?await n(e,h,{collector:d}):void 0)??(e.id||void 0),q=r?.name||e.name,T=e.timestamp||Date.now(),$=e.id||void 0,A=k.eventType||"custom_event";let C;if("screen_view"===A)C=function(e,t,n,o){return{event_type:"screen_view",data:{...e?{screen_name:e}:{},...t&&Object.keys(t).length>0?{custom_attributes:t}:{},...void 0!==n?{timestamp_unixtime_ms:n}:{},...o?{source_message_id:o}:{}}}}(q,S,T,$);else if("commerce_event"===A){const t=k.commerce?await n(e,k.commerce,{collector:d}):void 0;C=function(e,t,n,o){return{event_type:"commerce_event",data:{...e||{},...t&&Object.keys(t).length>0?{custom_attributes:t}:{},...void 0!==n?{timestamp_unixtime_ms:n}:{},...o?{source_message_id:o}:{}}}}(o(t)?t:void 0,S,T,$)}else{C=function(e,t,n,o,i){return{event_type:"custom_event",data:{event_name:e,custom_event_type:t,...n&&Object.keys(n).length>0?{custom_attributes:n}:{},...void 0!==o?{timestamp_unixtime_ms:o}:{},...i?{source_message_id:i}:{}}}}(q,k.customEventType||"other",S,T,$)}const K=function(e,t,n,o,i={}){const s={events:e,environment:o};return t&&Object.keys(t).length>0&&(s.user_identities=t),n&&Object.keys(n).length>0&&(s.user_attributes=n),i.ip&&(s.ip=i.ip),i.sourceRequestId&&(s.source_request_id=i.sourceRequestId),i.consent&&(s.consent_state=i.consent),i.context&&(s.context=i.context),s}([C],j,O,y,{ip:I,sourceRequestId:x,consent:w}),P=function(e="us1"){return"us1"===e?"https://s2s.mparticle.com/v2/events":`https://s2s.${e}.mparticle.com/v2/events`}(f),R=function(e,t){return`Basic ${Buffer.from(`${e}:${t}`).toString("base64")}`}(l,v);p.debug("Calling mParticle Events API",{endpoint:P,method:"POST",eventType:C.event_type,eventName:q,eventId:e.id});const E=m?.sendServer||s;await E(P,JSON.stringify(K),{headers:{Authorization:R,"Content-Type":"application/json"}})};function c(e){if(null!=e)return"string"==typeof e?e||void 0:"number"==typeof e||"boolean"==typeof e?String(e):void 0}function a(e){if(null!=e)return"string"==typeof e?e||void 0:"number"==typeof e?e:"boolean"==typeof e?String(e):void 0}var u={},m={type:"mparticle",config:{},async init({config:e}){const n=function(e={}){const n=e.settings||{},{apiKey:o,apiSecret:i}=n;if(!o||!i){const e=[...o?[]:["apiKey"],...i?[]:["apiSecret"]];throw new t(`Config settings ${e.join(", ")} missing`,{code:"config"})}const s={pod:"us1",environment:"production",...n,apiKey:o,apiSecret:i};return{...e,settings:s}}(e);return n},push:async(e,t)=>await async function(e,t){t.rule?.silent||await r(e,t)}(e,t)},p=m;export{u as DestinationMParticle,p as default,m as destinationMParticle};//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.ts","../src/push.ts","../src/batch.ts","../src/types/index.ts","../src/index.ts"],"sourcesContent":["import type { Config, PartialConfig, Settings } from './types';\nimport type { Logger } from '@walkeros/core';\n\nexport function getConfig(\n partialConfig: PartialConfig = {},\n logger: Logger.Instance,\n): Config {\n const settings = (partialConfig.settings || {}) as Partial<Settings>;\n const { apiKey, apiSecret } = settings;\n\n if (!apiKey) logger.throw('Config settings apiKey missing');\n if (!apiSecret) logger.throw('Config settings apiSecret missing');\n\n const settingsConfig: Settings = {\n pod: 'us1',\n environment: 'production',\n ...settings,\n apiKey: apiKey as string,\n apiSecret: apiSecret as string,\n };\n\n return { ...partialConfig, settings: settingsConfig };\n}\n","import type {\n Collector,\n WalkerOS,\n Mapping as WalkerOSMapping,\n} from '@walkeros/core';\nimport { getMappingValue, isObject } from '@walkeros/core';\nimport { sendServer } from '@walkeros/server-core';\nimport type {\n CommerceEventData,\n ConsentState,\n CustomEventType,\n Mapping,\n MParticleEvent,\n PushFn,\n Settings,\n} from './types';\nimport {\n buildAuthHeader,\n buildBatch,\n buildCommerceEvent,\n buildCustomEvent,\n buildEndpoint,\n buildScreenViewEvent,\n} from './batch';\n\nexport const push: PushFn = async function (\n event,\n { config, rule, data, env, logger, collector },\n) {\n const settings = config.settings as Settings;\n const {\n apiKey,\n apiSecret,\n pod = 'us1',\n environment = 'production',\n userIdentities: settingsIdentities,\n userAttributes: settingsUserAttributes,\n consent,\n ip: ipSetting,\n sourceRequestId: sourceRequestIdSetting,\n } = settings;\n\n const ruleSettings: Mapping = (rule?.settings || {}) as Mapping;\n\n const customAttributes = isObject(data)\n ? (data as Record<string, unknown>)\n : {};\n\n const userIdentities = await resolveIdentities(\n event,\n settingsIdentities,\n ruleSettings.userIdentities,\n collector,\n );\n\n const userAttributes = await resolveUserAttributes(\n event,\n settingsUserAttributes,\n ruleSettings.userAttributes,\n collector,\n );\n\n const ip = ipSetting\n ? toStringValue(await getMappingValue(event, ipSetting, { collector }))\n : undefined;\n\n const sourceRequestIdRaw = sourceRequestIdSetting\n ? await getMappingValue(event, sourceRequestIdSetting, { collector })\n : undefined;\n const sourceRequestId =\n toStringValue(sourceRequestIdRaw) ?? (event.id || undefined);\n\n const eventName = rule?.name || event.name;\n const timestamp = event.timestamp || Date.now();\n const sourceMessageId = event.id || undefined;\n const eventType = ruleSettings.eventType || 'custom_event';\n\n let mpEvent: MParticleEvent;\n if (eventType === 'screen_view') {\n mpEvent = buildScreenViewEvent(\n eventName,\n customAttributes,\n timestamp,\n sourceMessageId,\n );\n } else if (eventType === 'commerce_event') {\n const commerceResolved = ruleSettings.commerce\n ? await getMappingValue(event, ruleSettings.commerce, { collector })\n : undefined;\n const commerceData = isObject(commerceResolved)\n ? (commerceResolved as Partial<CommerceEventData>)\n : undefined;\n mpEvent = buildCommerceEvent(\n commerceData,\n customAttributes,\n timestamp,\n sourceMessageId,\n );\n } else {\n const customEventType: CustomEventType =\n ruleSettings.customEventType || 'other';\n mpEvent = buildCustomEvent(\n eventName,\n customEventType,\n customAttributes,\n timestamp,\n sourceMessageId,\n );\n }\n\n const batch = buildBatch(\n [mpEvent],\n userIdentities,\n userAttributes,\n environment,\n {\n ip,\n sourceRequestId,\n consent: consent as ConsentState | undefined,\n },\n );\n\n const endpoint = buildEndpoint(pod);\n const authHeader = buildAuthHeader(apiKey, apiSecret);\n\n logger.debug('Calling mParticle Events API', {\n endpoint,\n method: 'POST',\n eventType: mpEvent.event_type,\n eventName,\n eventId: event.id,\n });\n\n const sendServerFn = env?.sendServer || sendServer;\n const result = await sendServerFn(endpoint, JSON.stringify(batch), {\n headers: {\n Authorization: authHeader,\n 'Content-Type': 'application/json',\n },\n });\n\n logger.debug('mParticle API response', {\n ok: isObject(result) ? result.ok : true,\n });\n\n if (isObject(result) && result.ok === false) {\n logger.throw(`mParticle API error: ${JSON.stringify(result)}`);\n }\n};\n\nasync function resolveIdentities(\n event: WalkerOS.Event,\n settingsIdentities: WalkerOSMapping.Map | undefined,\n ruleIdentities: WalkerOSMapping.Map | undefined,\n collector: Collector.Instance,\n): Promise<Record<string, string | number> | undefined> {\n const merged: WalkerOSMapping.Map = {\n ...(isObject(settingsIdentities) ? settingsIdentities : {}),\n ...(isObject(ruleIdentities) ? ruleIdentities : {}),\n };\n const keys = Object.keys(merged);\n if (keys.length === 0) return undefined;\n\n const out: Record<string, string | number> = {};\n for (const key of keys) {\n const raw = await getMappingValue(event, merged[key], { collector });\n const coerced = toIdentityValue(raw);\n if (coerced !== undefined) out[key] = coerced;\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\nasync function resolveUserAttributes(\n event: WalkerOS.Event,\n settingsAttributes: WalkerOSMapping.Value | undefined,\n ruleAttributes: WalkerOSMapping.Value | undefined,\n collector: Collector.Instance,\n): Promise<Record<string, unknown> | undefined> {\n const settingsResolved = settingsAttributes\n ? await getMappingValue(event, settingsAttributes, { collector })\n : undefined;\n const ruleResolved = ruleAttributes\n ? await getMappingValue(event, ruleAttributes, { collector })\n : undefined;\n\n const merged: Record<string, unknown> = {\n ...(isObject(settingsResolved)\n ? (settingsResolved as Record<string, unknown>)\n : {}),\n ...(isObject(ruleResolved)\n ? (ruleResolved as Record<string, unknown>)\n : {}),\n };\n return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\nfunction toStringValue(value: unknown): string | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value === 'string') return value || undefined;\n if (typeof value === 'number' || typeof value === 'boolean')\n return String(value);\n return undefined;\n}\n\nfunction toIdentityValue(value: unknown): string | number | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value === 'string') return value || undefined;\n if (typeof value === 'number') return value;\n if (typeof value === 'boolean') return String(value);\n return undefined;\n}\n","import type {\n CommerceEventData,\n ConsentState,\n CustomEventType,\n Environment,\n MParticleBatch,\n MParticleEvent,\n Pod,\n ScreenViewEventData,\n} from './types';\n\n/**\n * Returns the mParticle Events API endpoint for the given pod.\n * us1 resolves to the legacy host (`s2s.mparticle.com`); other pods use the\n * pod-qualified host.\n * https://docs.mparticle.com/developers/server/http/#endpoint\n */\nexport function buildEndpoint(pod: Pod = 'us1'): string {\n if (pod === 'us1') return 'https://s2s.mparticle.com/v2/events';\n return `https://s2s.${pod}.mparticle.com/v2/events`;\n}\n\n/**\n * Builds the HTTP Basic auth header value from an API key/secret pair.\n * Uses Buffer (Node) for base64 encoding to keep server semantics.\n */\nexport function buildAuthHeader(apiKey: string, apiSecret: string): string {\n const token = Buffer.from(`${apiKey}:${apiSecret}`).toString('base64');\n return `Basic ${token}`;\n}\n\n/**\n * Builds a custom_event payload.\n */\nexport function buildCustomEvent(\n eventName: string,\n customEventType: CustomEventType,\n customAttributes: Record<string, unknown> | undefined,\n timestamp: number | undefined,\n sourceMessageId: string | undefined,\n): MParticleEvent {\n return {\n event_type: 'custom_event',\n data: {\n event_name: eventName,\n custom_event_type: customEventType,\n ...(customAttributes && Object.keys(customAttributes).length > 0\n ? { custom_attributes: customAttributes }\n : {}),\n ...(timestamp !== undefined ? { timestamp_unixtime_ms: timestamp } : {}),\n ...(sourceMessageId ? { source_message_id: sourceMessageId } : {}),\n },\n };\n}\n\n/**\n * Builds a screen_view event payload.\n */\nexport function buildScreenViewEvent(\n screenName: string | undefined,\n customAttributes: Record<string, unknown> | undefined,\n timestamp: number | undefined,\n sourceMessageId: string | undefined,\n): MParticleEvent {\n const data: ScreenViewEventData = {\n ...(screenName ? { screen_name: screenName } : {}),\n ...(customAttributes && Object.keys(customAttributes).length > 0\n ? { custom_attributes: customAttributes }\n : {}),\n ...(timestamp !== undefined ? { timestamp_unixtime_ms: timestamp } : {}),\n ...(sourceMessageId ? { source_message_id: sourceMessageId } : {}),\n };\n return { event_type: 'screen_view', data };\n}\n\n/**\n * Builds a commerce_event payload. Commerce data is a loosely-shaped subset\n * of {@link CommerceEventData} (product_action, currency_code, ...) resolved\n * from the per-rule commerce mapping.\n */\nexport function buildCommerceEvent(\n commerceData: Partial<CommerceEventData> | undefined,\n customAttributes: Record<string, unknown> | undefined,\n timestamp: number | undefined,\n sourceMessageId: string | undefined,\n): MParticleEvent {\n const data: CommerceEventData = {\n ...(commerceData || {}),\n ...(customAttributes && Object.keys(customAttributes).length > 0\n ? { custom_attributes: customAttributes }\n : {}),\n ...(timestamp !== undefined ? { timestamp_unixtime_ms: timestamp } : {}),\n ...(sourceMessageId ? { source_message_id: sourceMessageId } : {}),\n };\n return { event_type: 'commerce_event', data };\n}\n\nexport interface BuildBatchOptions {\n ip?: string;\n sourceRequestId?: string;\n consent?: ConsentState;\n context?: Record<string, unknown>;\n}\n\n/**\n * Assembles the batch envelope wrapping events + identity + environment.\n */\nexport function buildBatch(\n events: MParticleEvent[],\n userIdentities: Record<string, string | number> | undefined,\n userAttributes: Record<string, unknown> | undefined,\n environment: Environment,\n options: BuildBatchOptions = {},\n): MParticleBatch {\n const batch: MParticleBatch = {\n events,\n environment,\n };\n if (userIdentities && Object.keys(userIdentities).length > 0)\n batch.user_identities = userIdentities;\n if (userAttributes && Object.keys(userAttributes).length > 0)\n batch.user_attributes = userAttributes;\n if (options.ip) batch.ip = options.ip;\n if (options.sourceRequestId)\n batch.source_request_id = options.sourceRequestId;\n if (options.consent) batch.consent_state = options.consent;\n if (options.context) batch.context = options.context;\n return batch;\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\n/**\n * mParticle data pod. Determines the regional endpoint used for the Events\n * API. Defaults to `us1`. See {@link buildEndpoint} in `batch.ts`.\n */\nexport type Pod = 'us1' | 'us2' | 'eu1' | 'au1';\n\n/**\n * mParticle environment for the batch. `production` routes to production\n * data streams; `development` sends to debug/verify streams.\n */\nexport type Environment = 'production' | 'development';\n\n/**\n * Event type used for the outgoing mParticle event. Defaults to\n * `custom_event` when not explicitly mapped via rule settings.\n */\nexport type EventType = 'custom_event' | 'screen_view' | 'commerce_event';\n\n/**\n * mParticle custom event type (category) for `custom_event`s. Defaults to\n * `other` when not specified.\n */\nexport type CustomEventType =\n | 'navigation'\n | 'location'\n | 'search'\n | 'transaction'\n | 'user_content'\n | 'user_preference'\n | 'social'\n | 'media'\n | 'attribution'\n | 'other';\n\n/**\n * mParticle product action verbs for commerce events.\n */\nexport type ProductActionType =\n | 'add_to_cart'\n | 'remove_from_cart'\n | 'checkout'\n | 'checkout_option'\n | 'click'\n | 'view_detail'\n | 'purchase'\n | 'refund'\n | 'add_to_wishlist'\n | 'remove_from_wishlist';\n\nexport interface Settings {\n /** mParticle input feed API key. */\n apiKey: string;\n /** mParticle input feed API secret. */\n apiSecret: string;\n /** Data pod selecting the regional endpoint. Default: `us1`. */\n pod?: Pod;\n /** Environment the batch targets. Default: `production`. */\n environment?: Environment;\n /**\n * Mapping that resolves to `user_identities` per batch. Each entry value\n * is a walkerOS mapping value; the resolved object is placed into the\n * mParticle batch `user_identities` envelope.\n */\n userIdentities?: WalkerOSMapping.Map;\n /**\n * Mapping that resolves to `user_attributes` per batch.\n */\n userAttributes?: WalkerOSMapping.Value;\n /**\n * Optional static consent state passthrough — shape is forwarded verbatim\n * to `consent_state` on the batch.\n */\n consent?: ConsentState;\n /** walkerOS mapping value resolving to the client IP for the batch. */\n ip?: WalkerOSMapping.Value;\n /**\n * Optional request correlation id. When omitted, falls back to `event.id`.\n */\n sourceRequestId?: WalkerOSMapping.Value;\n}\n\nexport type InitSettings = Partial<Settings>;\n\n/**\n * Per-rule mapping settings. Determines which mParticle event shape is\n * produced for this walkerOS event and allows per-event identity overrides.\n */\nexport interface Mapping {\n /** Event type. Default: `custom_event`. */\n eventType?: EventType;\n /** Custom event type category for `custom_event`. Default: `other`. */\n customEventType?: CustomEventType;\n /** Commerce mapping resolving to ProductAction and related fields. */\n commerce?: WalkerOSMapping.Value;\n /** Per-event override for `user_identities`. Merged over settings. */\n userIdentities?: WalkerOSMapping.Map;\n /** Per-event override for `user_attributes`. */\n userAttributes?: WalkerOSMapping.Value;\n}\n\nexport interface Env extends DestinationServer.Env {\n sendServer?: typeof sendServer;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\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>;\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\n/**\n * Top-level mParticle batch payload posted to\n * `https://s2s.{pod}.mparticle.com/v2/events`.\n * https://docs.mparticle.com/developers/server/http/\n */\nexport interface MParticleBatch {\n events: MParticleEvent[];\n user_identities?: Record<string, string | number>;\n user_attributes?: Record<string, unknown>;\n environment: Environment;\n schema_version?: number;\n ip?: string;\n source_request_id?: string;\n consent_state?: ConsentState;\n context?: Record<string, unknown>;\n}\n\nexport type MParticleEvent =\n | { event_type: 'custom_event'; data: CustomEventData }\n | { event_type: 'screen_view'; data: ScreenViewEventData }\n | { event_type: 'commerce_event'; data: CommerceEventData };\n\nexport interface CommonEventData {\n timestamp_unixtime_ms?: number;\n source_message_id?: string;\n session_uuid?: string;\n custom_attributes?: Record<string, unknown>;\n custom_flags?: Record<string, unknown>;\n location?: Record<string, unknown>;\n}\n\nexport interface CustomEventData extends CommonEventData {\n event_name: string;\n custom_event_type: CustomEventType;\n}\n\nexport interface ScreenViewEventData extends CommonEventData {\n screen_name?: string;\n}\n\nexport interface CommerceEventData extends CommonEventData {\n product_action?: ProductAction;\n promotion_action?: PromotionAction;\n product_impressions?: ProductImpression[];\n currency_code?: string;\n is_non_interactive?: boolean;\n}\n\nexport interface ProductAction {\n action: ProductActionType;\n transaction_id?: string;\n total_amount?: number;\n tax_amount?: number;\n shipping_amount?: number;\n coupon_code?: string;\n affiliation?: string;\n checkout_step?: number;\n checkout_options?: string;\n products?: Product[];\n}\n\nexport interface Product {\n id?: string;\n name?: string;\n brand?: string;\n category?: string;\n variant?: string;\n position?: number;\n price?: number;\n quantity?: number;\n coupon_code?: string;\n total_product_amount?: number;\n custom_attributes?: Record<string, unknown>;\n}\n\nexport interface PromotionAction {\n action: 'view' | 'click';\n promotions?: Array<{\n id?: string;\n name?: string;\n creative?: string;\n position?: string;\n }>;\n}\n\nexport interface ProductImpression {\n product_impression_list?: string;\n products?: Product[];\n}\n\n/**\n * mParticle consent state envelope forwarded verbatim on the batch.\n * https://docs.mparticle.com/developers/server/http/#consent-state\n */\nexport interface ConsentState {\n gdpr?: Record<string, GDPRConsentState>;\n ccpa?: { data_sale_opt_out?: CCPAConsentState };\n}\n\nexport interface GDPRConsentState {\n consented: boolean;\n document?: string;\n timestamp_unixtime_ms?: number;\n location?: string;\n hardware_id?: string;\n}\n\nexport interface CCPAConsentState {\n consented: boolean;\n document?: string;\n timestamp_unixtime_ms?: number;\n location?: string;\n hardware_id?: string;\n}\n","import type { Destination } from './types';\nimport { getConfig } from './config';\nimport { push } from './push';\n\n// Types\nexport * as DestinationMParticle from './types';\n\nexport const destinationMParticle: Destination = {\n type: 'mparticle',\n\n config: {},\n\n async init({ config: partialConfig, logger }) {\n const config = getConfig(partialConfig, logger);\n return config;\n },\n\n async push(event, context) {\n return await push(event, context);\n },\n};\n\nexport default destinationMParticle;\n"],"mappings":";AAGO,SAAS,UACd,gBAA+B,CAAC,GAChC,QACQ;AACR,QAAM,WAAY,cAAc,YAAY,CAAC;AAC7C,QAAM,EAAE,QAAQ,UAAU,IAAI;AAE9B,MAAI,CAAC,OAAQ,QAAO,MAAM,gCAAgC;AAC1D,MAAI,CAAC,UAAW,QAAO,MAAM,mCAAmC;AAEhE,QAAM,iBAA2B;AAAA,IAC/B,KAAK;AAAA,IACL,aAAa;AAAA,IACb,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,eAAe,UAAU,eAAe;AACtD;;;ACjBA,SAAS,iBAAiB,gBAAgB;AAC1C,SAAS,kBAAkB;;;ACWpB,SAAS,cAAc,MAAW,OAAe;AACtD,MAAI,QAAQ,MAAO,QAAO;AAC1B,SAAO,eAAe,GAAG;AAC3B;AAMO,SAAS,gBAAgB,QAAgB,WAA2B;AACzE,QAAM,QAAQ,OAAO,KAAK,GAAG,MAAM,IAAI,SAAS,EAAE,EAAE,SAAS,QAAQ;AACrE,SAAO,SAAS,KAAK;AACvB;AAKO,SAAS,iBACd,WACA,iBACA,kBACA,WACA,iBACgB;AAChB,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,MAAM;AAAA,MACJ,YAAY;AAAA,MACZ,mBAAmB;AAAA,MACnB,GAAI,oBAAoB,OAAO,KAAK,gBAAgB,EAAE,SAAS,IAC3D,EAAE,mBAAmB,iBAAiB,IACtC,CAAC;AAAA,MACL,GAAI,cAAc,SAAY,EAAE,uBAA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e,MAAM;AAC9C,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,KAAK,OAAO,SAAS;AACzB,WAAO,MAAM,KAAK,OAAO,OAAO;AAAA,EAClC;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/push.ts","../src/batch.ts","../src/types/index.ts","../src/index.ts"],"sourcesContent":["import type { Config, PartialConfig, Settings } from './types';\nimport { StepError } from '@walkeros/core';\n\nexport function getConfig(partialConfig: PartialConfig = {}): Config {\n const settings: Partial<Settings> = partialConfig.settings || {};\n const { apiKey, apiSecret } = settings;\n\n if (!apiKey || !apiSecret) {\n const missing = [\n ...(apiKey ? [] : ['apiKey']),\n ...(apiSecret ? [] : ['apiSecret']),\n ];\n throw new StepError(`Config settings ${missing.join(', ')} missing`, {\n code: 'config',\n });\n }\n\n const settingsConfig: Settings = {\n pod: 'us1',\n environment: 'production',\n ...settings,\n apiKey,\n apiSecret,\n };\n\n return { ...partialConfig, settings: settingsConfig };\n}\n","import type {\n Collector,\n WalkerOS,\n Mapping as WalkerOSMapping,\n} from '@walkeros/core';\nimport { getMappingValue, isObject, StepError } from '@walkeros/core';\nimport { sendServer } from '@walkeros/server-core';\nimport type {\n CommerceEventData,\n ConsentState,\n CustomEventType,\n Mapping,\n MParticleEvent,\n PushFn,\n Settings,\n} from './types';\nimport {\n buildAuthHeader,\n buildBatch,\n buildCommerceEvent,\n buildCustomEvent,\n buildEndpoint,\n buildScreenViewEvent,\n} from './batch';\n\n// A silent rule has no mparticle call of its own: nothing to send.\nexport const push: PushFn = async function (event, context) {\n if (!context.rule?.silent) await send(event, context);\n};\n\nconst send: PushFn = async function (\n event,\n { config, rule, data, env, logger, collector },\n) {\n const {\n apiKey,\n apiSecret,\n pod = 'us1',\n environment = 'production',\n userIdentities: settingsIdentities,\n userAttributes: settingsUserAttributes,\n consent,\n ip: ipSetting,\n sourceRequestId: sourceRequestIdSetting,\n } = config.settings ?? {};\n\n // init() validates these; a destination that skipped it is not ready.\n if (!apiKey || !apiSecret)\n throw new StepError('Config settings missing, init() not run', {\n code: 'not-ready',\n });\n\n const ruleSettings: Mapping = (rule?.settings || {}) as Mapping;\n\n const customAttributes = isObject(data)\n ? (data as Record<string, unknown>)\n : {};\n\n const userIdentities = await resolveIdentities(\n event,\n settingsIdentities,\n ruleSettings.userIdentities,\n collector,\n );\n\n const userAttributes = await resolveUserAttributes(\n event,\n settingsUserAttributes,\n ruleSettings.userAttributes,\n collector,\n );\n\n const ip = ipSetting\n ? toStringValue(await getMappingValue(event, ipSetting, { collector }))\n : undefined;\n\n const sourceRequestIdRaw = sourceRequestIdSetting\n ? await getMappingValue(event, sourceRequestIdSetting, { collector })\n : undefined;\n const sourceRequestId =\n toStringValue(sourceRequestIdRaw) ?? (event.id || undefined);\n\n const eventName = rule?.name || event.name;\n const timestamp = event.timestamp || Date.now();\n const sourceMessageId = event.id || undefined;\n const eventType = ruleSettings.eventType || 'custom_event';\n\n let mpEvent: MParticleEvent;\n if (eventType === 'screen_view') {\n mpEvent = buildScreenViewEvent(\n eventName,\n customAttributes,\n timestamp,\n sourceMessageId,\n );\n } else if (eventType === 'commerce_event') {\n const commerceResolved = ruleSettings.commerce\n ? await getMappingValue(event, ruleSettings.commerce, { collector })\n : undefined;\n const commerceData = isObject(commerceResolved)\n ? (commerceResolved as Partial<CommerceEventData>)\n : undefined;\n mpEvent = buildCommerceEvent(\n commerceData,\n customAttributes,\n timestamp,\n sourceMessageId,\n );\n } else {\n const customEventType: CustomEventType =\n ruleSettings.customEventType || 'other';\n mpEvent = buildCustomEvent(\n eventName,\n customEventType,\n customAttributes,\n timestamp,\n sourceMessageId,\n );\n }\n\n const batch = buildBatch(\n [mpEvent],\n userIdentities,\n userAttributes,\n environment,\n {\n ip,\n sourceRequestId,\n consent: consent as ConsentState | undefined,\n },\n );\n\n const endpoint = buildEndpoint(pod);\n const authHeader = buildAuthHeader(apiKey, apiSecret);\n\n logger.debug('Calling mParticle Events API', {\n endpoint,\n method: 'POST',\n eventType: mpEvent.event_type,\n eventName,\n eventId: event.id,\n });\n\n const sendServerFn = env?.sendServer || sendServer;\n await sendServerFn(endpoint, JSON.stringify(batch), {\n headers: {\n Authorization: authHeader,\n 'Content-Type': 'application/json',\n },\n });\n};\n\nasync function resolveIdentities(\n event: WalkerOS.Event,\n settingsIdentities: WalkerOSMapping.Map | undefined,\n ruleIdentities: WalkerOSMapping.Map | undefined,\n collector: Collector.Instance,\n): Promise<Record<string, string | number> | undefined> {\n const merged: WalkerOSMapping.Map = {\n ...(isObject(settingsIdentities) ? settingsIdentities : {}),\n ...(isObject(ruleIdentities) ? ruleIdentities : {}),\n };\n const keys = Object.keys(merged);\n if (keys.length === 0) return undefined;\n\n const out: Record<string, string | number> = {};\n for (const key of keys) {\n const raw = await getMappingValue(event, merged[key], { collector });\n const coerced = toIdentityValue(raw);\n if (coerced !== undefined) out[key] = coerced;\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\nasync function resolveUserAttributes(\n event: WalkerOS.Event,\n settingsAttributes: WalkerOSMapping.Value | undefined,\n ruleAttributes: WalkerOSMapping.Value | undefined,\n collector: Collector.Instance,\n): Promise<Record<string, unknown> | undefined> {\n const settingsResolved = settingsAttributes\n ? await getMappingValue(event, settingsAttributes, { collector })\n : undefined;\n const ruleResolved = ruleAttributes\n ? await getMappingValue(event, ruleAttributes, { collector })\n : undefined;\n\n const merged: Record<string, unknown> = {\n ...(isObject(settingsResolved)\n ? (settingsResolved as Record<string, unknown>)\n : {}),\n ...(isObject(ruleResolved)\n ? (ruleResolved as Record<string, unknown>)\n : {}),\n };\n return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\nfunction toStringValue(value: unknown): string | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value === 'string') return value || undefined;\n if (typeof value === 'number' || typeof value === 'boolean')\n return String(value);\n return undefined;\n}\n\nfunction toIdentityValue(value: unknown): string | number | undefined {\n if (value === undefined || value === null) return undefined;\n if (typeof value === 'string') return value || undefined;\n if (typeof value === 'number') return value;\n if (typeof value === 'boolean') return String(value);\n return undefined;\n}\n","import type {\n CommerceEventData,\n ConsentState,\n CustomEventType,\n Environment,\n MParticleBatch,\n MParticleEvent,\n Pod,\n ScreenViewEventData,\n} from './types';\n\n/**\n * Returns the mParticle Events API endpoint for the given pod.\n * us1 resolves to the legacy host (`s2s.mparticle.com`); other pods use the\n * pod-qualified host.\n * https://docs.mparticle.com/developers/server/http/#endpoint\n */\nexport function buildEndpoint(pod: Pod = 'us1'): string {\n if (pod === 'us1') return 'https://s2s.mparticle.com/v2/events';\n return `https://s2s.${pod}.mparticle.com/v2/events`;\n}\n\n/**\n * Builds the HTTP Basic auth header value from an API key/secret pair.\n * Uses Buffer (Node) for base64 encoding to keep server semantics.\n */\nexport function buildAuthHeader(apiKey: string, apiSecret: string): string {\n const token = Buffer.from(`${apiKey}:${apiSecret}`).toString('base64');\n return `Basic ${token}`;\n}\n\n/**\n * Builds a custom_event payload.\n */\nexport function buildCustomEvent(\n eventName: string,\n customEventType: CustomEventType,\n customAttributes: Record<string, unknown> | undefined,\n timestamp: number | undefined,\n sourceMessageId: string | undefined,\n): MParticleEvent {\n return {\n event_type: 'custom_event',\n data: {\n event_name: eventName,\n custom_event_type: customEventType,\n ...(customAttributes && Object.keys(customAttributes).length > 0\n ? { custom_attributes: customAttributes }\n : {}),\n ...(timestamp !== undefined ? { timestamp_unixtime_ms: timestamp } : {}),\n ...(sourceMessageId ? { source_message_id: sourceMessageId } : {}),\n },\n };\n}\n\n/**\n * Builds a screen_view event payload.\n */\nexport function buildScreenViewEvent(\n screenName: string | undefined,\n customAttributes: Record<string, unknown> | undefined,\n timestamp: number | undefined,\n sourceMessageId: string | undefined,\n): MParticleEvent {\n const data: ScreenViewEventData = {\n ...(screenName ? { screen_name: screenName } : {}),\n ...(customAttributes && Object.keys(customAttributes).length > 0\n ? { custom_attributes: customAttributes }\n : {}),\n ...(timestamp !== undefined ? { timestamp_unixtime_ms: timestamp } : {}),\n ...(sourceMessageId ? { source_message_id: sourceMessageId } : {}),\n };\n return { event_type: 'screen_view', data };\n}\n\n/**\n * Builds a commerce_event payload. Commerce data is a loosely-shaped subset\n * of {@link CommerceEventData} (product_action, currency_code, ...) resolved\n * from the per-rule commerce mapping.\n */\nexport function buildCommerceEvent(\n commerceData: Partial<CommerceEventData> | undefined,\n customAttributes: Record<string, unknown> | undefined,\n timestamp: number | undefined,\n sourceMessageId: string | undefined,\n): MParticleEvent {\n const data: CommerceEventData = {\n ...(commerceData || {}),\n ...(customAttributes && Object.keys(customAttributes).length > 0\n ? { custom_attributes: customAttributes }\n : {}),\n ...(timestamp !== undefined ? { timestamp_unixtime_ms: timestamp } : {}),\n ...(sourceMessageId ? { source_message_id: sourceMessageId } : {}),\n };\n return { event_type: 'commerce_event', data };\n}\n\nexport interface BuildBatchOptions {\n ip?: string;\n sourceRequestId?: string;\n consent?: ConsentState;\n context?: Record<string, unknown>;\n}\n\n/**\n * Assembles the batch envelope wrapping events + identity + environment.\n */\nexport function buildBatch(\n events: MParticleEvent[],\n userIdentities: Record<string, string | number> | undefined,\n userAttributes: Record<string, unknown> | undefined,\n environment: Environment,\n options: BuildBatchOptions = {},\n): MParticleBatch {\n const batch: MParticleBatch = {\n events,\n environment,\n };\n if (userIdentities && Object.keys(userIdentities).length > 0)\n batch.user_identities = userIdentities;\n if (userAttributes && Object.keys(userAttributes).length > 0)\n batch.user_attributes = userAttributes;\n if (options.ip) batch.ip = options.ip;\n if (options.sourceRequestId)\n batch.source_request_id = options.sourceRequestId;\n if (options.consent) batch.consent_state = options.consent;\n if (options.context) batch.context = options.context;\n return batch;\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\n/**\n * mParticle data pod. Determines the regional endpoint used for the Events\n * API. Defaults to `us1`. See {@link buildEndpoint} in `batch.ts`.\n */\nexport type Pod = 'us1' | 'us2' | 'eu1' | 'au1';\n\n/**\n * mParticle environment for the batch. `production` routes to production\n * data streams; `development` sends to debug/verify streams.\n */\nexport type Environment = 'production' | 'development';\n\n/**\n * Event type used for the outgoing mParticle event. Defaults to\n * `custom_event` when not explicitly mapped via rule settings.\n */\nexport type EventType = 'custom_event' | 'screen_view' | 'commerce_event';\n\n/**\n * mParticle custom event type (category) for `custom_event`s. Defaults to\n * `other` when not specified.\n */\nexport type CustomEventType =\n | 'navigation'\n | 'location'\n | 'search'\n | 'transaction'\n | 'user_content'\n | 'user_preference'\n | 'social'\n | 'media'\n | 'attribution'\n | 'other';\n\n/**\n * mParticle product action verbs for commerce events.\n */\nexport type ProductActionType =\n | 'add_to_cart'\n | 'remove_from_cart'\n | 'checkout'\n | 'checkout_option'\n | 'click'\n | 'view_detail'\n | 'purchase'\n | 'refund'\n | 'add_to_wishlist'\n | 'remove_from_wishlist';\n\nexport interface Settings {\n /** mParticle input feed API key. */\n apiKey: string;\n /** mParticle input feed API secret. */\n apiSecret: string;\n /** Data pod selecting the regional endpoint. Default: `us1`. */\n pod?: Pod;\n /** Environment the batch targets. Default: `production`. */\n environment?: Environment;\n /**\n * Mapping that resolves to `user_identities` per batch. Each entry value\n * is a walkerOS mapping value; the resolved object is placed into the\n * mParticle batch `user_identities` envelope.\n */\n userIdentities?: WalkerOSMapping.Map;\n /**\n * Mapping that resolves to `user_attributes` per batch.\n */\n userAttributes?: WalkerOSMapping.Value;\n /**\n * Optional static consent state passthrough — shape is forwarded verbatim\n * to `consent_state` on the batch.\n */\n consent?: ConsentState;\n /** walkerOS mapping value resolving to the client IP for the batch. */\n ip?: WalkerOSMapping.Value;\n /**\n * Optional request correlation id. When omitted, falls back to `event.id`.\n */\n sourceRequestId?: WalkerOSMapping.Value;\n}\n\nexport type InitSettings = Partial<Settings>;\n\n/**\n * Per-rule mapping settings. Determines which mParticle event shape is\n * produced for this walkerOS event and allows per-event identity overrides.\n */\nexport interface Mapping {\n /** Event type. Default: `custom_event`. */\n eventType?: EventType;\n /** Custom event type category for `custom_event`. Default: `other`. */\n customEventType?: CustomEventType;\n /** Commerce mapping resolving to ProductAction and related fields. */\n commerce?: WalkerOSMapping.Value;\n /** Per-event override for `user_identities`. Merged over settings. */\n userIdentities?: WalkerOSMapping.Map;\n /** Per-event override for `user_attributes`. */\n userAttributes?: WalkerOSMapping.Value;\n}\n\nexport interface Env extends DestinationServer.Env {\n sendServer?: typeof sendServer;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\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>;\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\n/**\n * Top-level mParticle batch payload posted to\n * `https://s2s.{pod}.mparticle.com/v2/events`.\n * https://docs.mparticle.com/developers/server/http/\n */\nexport interface MParticleBatch {\n events: MParticleEvent[];\n user_identities?: Record<string, string | number>;\n user_attributes?: Record<string, unknown>;\n environment: Environment;\n schema_version?: number;\n ip?: string;\n source_request_id?: string;\n consent_state?: ConsentState;\n context?: Record<string, unknown>;\n}\n\nexport type MParticleEvent =\n | { event_type: 'custom_event'; data: CustomEventData }\n | { event_type: 'screen_view'; data: ScreenViewEventData }\n | { event_type: 'commerce_event'; data: CommerceEventData };\n\nexport interface CommonEventData {\n timestamp_unixtime_ms?: number;\n source_message_id?: string;\n session_uuid?: string;\n custom_attributes?: Record<string, unknown>;\n custom_flags?: Record<string, unknown>;\n location?: Record<string, unknown>;\n}\n\nexport interface CustomEventData extends CommonEventData {\n event_name: string;\n custom_event_type: CustomEventType;\n}\n\nexport interface ScreenViewEventData extends CommonEventData {\n screen_name?: string;\n}\n\nexport interface CommerceEventData extends CommonEventData {\n product_action?: ProductAction;\n promotion_action?: PromotionAction;\n product_impressions?: ProductImpression[];\n currency_code?: string;\n is_non_interactive?: boolean;\n}\n\nexport interface ProductAction {\n action: ProductActionType;\n transaction_id?: string;\n total_amount?: number;\n tax_amount?: number;\n shipping_amount?: number;\n coupon_code?: string;\n affiliation?: string;\n checkout_step?: number;\n checkout_options?: string;\n products?: Product[];\n}\n\nexport interface Product {\n id?: string;\n name?: string;\n brand?: string;\n category?: string;\n variant?: string;\n position?: number;\n price?: number;\n quantity?: number;\n coupon_code?: string;\n total_product_amount?: number;\n custom_attributes?: Record<string, unknown>;\n}\n\nexport interface PromotionAction {\n action: 'view' | 'click';\n promotions?: Array<{\n id?: string;\n name?: string;\n creative?: string;\n position?: string;\n }>;\n}\n\nexport interface ProductImpression {\n product_impression_list?: string;\n products?: Product[];\n}\n\n/**\n * mParticle consent state envelope forwarded verbatim on the batch.\n * https://docs.mparticle.com/developers/server/http/#consent-state\n */\nexport interface ConsentState {\n gdpr?: Record<string, GDPRConsentState>;\n ccpa?: { data_sale_opt_out?: CCPAConsentState };\n}\n\nexport interface GDPRConsentState {\n consented: boolean;\n document?: string;\n timestamp_unixtime_ms?: number;\n location?: string;\n hardware_id?: string;\n}\n\nexport interface CCPAConsentState {\n consented: boolean;\n document?: string;\n timestamp_unixtime_ms?: number;\n location?: string;\n hardware_id?: string;\n}\n","import type { Destination } from './types';\nimport { getConfig } from './config';\nimport { push } from './push';\n\n// Types\nexport * as DestinationMParticle from './types';\n\nexport const destinationMParticle: Destination = {\n type: 'mparticle',\n\n config: {},\n\n async init({ config: partialConfig }) {\n const config = getConfig(partialConfig);\n return config;\n },\n\n async push(event, context) {\n return await push(event, context);\n },\n};\n\nexport default destinationMParticle;\n"],"mappings":";;;AACA,SAAS,iBAAiB;AAEnB,SAAS,UAAU,gBAA+B,CAAC,GAAW;AACnE,QAAM,WAA8B,cAAc,YAAY,CAAC;AAC/D,QAAM,EAAE,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ta": {
|
|
3
3
|
"package": "@walkeros/server-destination-mparticle",
|
|
4
|
-
"version": "4.8.
|
|
4
|
+
"version": "4.8.2",
|
|
5
5
|
"type": "destination",
|
|
6
6
|
"platform": [
|
|
7
7
|
"server"
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
"env": {
|
|
127
127
|
"push": {
|
|
128
128
|
"sendServer": {
|
|
129
|
-
"$code": "async()=>({
|
|
129
|
+
"$code": "async()=>({data:{}})"
|
|
130
130
|
}
|
|
131
131
|
},
|
|
132
132
|
"simulation": [
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
"name": "order complete",
|
|
142
142
|
"data": {
|
|
143
143
|
"id": "ORD-300",
|
|
144
|
-
"
|
|
144
|
+
"value": 249.99,
|
|
145
145
|
"currency": "EUR"
|
|
146
146
|
},
|
|
147
147
|
"context": {
|
|
@@ -235,7 +235,7 @@
|
|
|
235
235
|
"value": "purchase"
|
|
236
236
|
},
|
|
237
237
|
"transaction_id": "data.id",
|
|
238
|
-
"total_amount": "data.
|
|
238
|
+
"total_amount": "data.value"
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
}
|
|
@@ -440,6 +440,65 @@
|
|
|
440
440
|
}
|
|
441
441
|
]
|
|
442
442
|
]
|
|
443
|
+
},
|
|
444
|
+
"silentRule": {
|
|
445
|
+
"public": false,
|
|
446
|
+
"description": "A rule with silent: true sends no request to mParticle.",
|
|
447
|
+
"in": {
|
|
448
|
+
"name": "page view",
|
|
449
|
+
"data": {
|
|
450
|
+
"domain": "www.example.com",
|
|
451
|
+
"title": "walkerOS documentation",
|
|
452
|
+
"referrer": "https://www.walkeros.io/",
|
|
453
|
+
"search": "?foo=bar",
|
|
454
|
+
"hash": "#hash",
|
|
455
|
+
"id": "/docs/"
|
|
456
|
+
},
|
|
457
|
+
"context": {
|
|
458
|
+
"dev": [
|
|
459
|
+
"test",
|
|
460
|
+
1
|
|
461
|
+
]
|
|
462
|
+
},
|
|
463
|
+
"globals": {
|
|
464
|
+
"pagegroup": "docs"
|
|
465
|
+
},
|
|
466
|
+
"custom": {
|
|
467
|
+
"completely": "random"
|
|
468
|
+
},
|
|
469
|
+
"user": {
|
|
470
|
+
"id": "us3r",
|
|
471
|
+
"device": "c00k13",
|
|
472
|
+
"session": "s3ss10n"
|
|
473
|
+
},
|
|
474
|
+
"nested": [
|
|
475
|
+
{
|
|
476
|
+
"entity": "child",
|
|
477
|
+
"data": {
|
|
478
|
+
"is": "subordinated"
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
],
|
|
482
|
+
"consent": {
|
|
483
|
+
"functional": true
|
|
484
|
+
},
|
|
485
|
+
"id": "f0cc5f6fec3d8eeb",
|
|
486
|
+
"trigger": "load",
|
|
487
|
+
"entity": "page",
|
|
488
|
+
"action": "view",
|
|
489
|
+
"timestamp": 1700000990000,
|
|
490
|
+
"timing": 3.14,
|
|
491
|
+
"source": {
|
|
492
|
+
"count": 1,
|
|
493
|
+
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
|
|
494
|
+
"type": "collector",
|
|
495
|
+
"schema": "4"
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
"mapping": {
|
|
499
|
+
"silent": true
|
|
500
|
+
},
|
|
501
|
+
"out": []
|
|
443
502
|
}
|
|
444
503
|
}
|
|
445
504
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@walkeros/server-destination-mparticle",
|
|
3
3
|
"description": "mParticle server destination for walkerOS",
|
|
4
|
-
"version": "4.8.
|
|
4
|
+
"version": "4.8.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"update": "npx npm-check-updates -u && npm update"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@walkeros/core": "4.8.
|
|
39
|
-
"@walkeros/server-core": "4.8.
|
|
38
|
+
"@walkeros/core": "4.8.2",
|
|
39
|
+
"@walkeros/server-core": "4.8.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@walkeros/collector": "4.8.
|
|
42
|
+
"@walkeros/collector": "4.8.2"
|
|
43
43
|
},
|
|
44
44
|
"repository": {
|
|
45
45
|
"url": "git+https://github.com/elbwalker/walkerOS.git",
|