@walkeros/server-destination-mparticle 4.8.1 → 4.8.3-next-1793115089237
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 +46 -3
- package/README.md +6 -1
- package/dist/dev.d.mts +13 -3
- package/dist/dev.d.ts +13 -3
- 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 +11 -2
- package/dist/examples/index.d.ts +11 -2
- package/dist/examples/index.js +25 -9
- package/dist/examples/index.mjs +25 -10
- 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 +77 -8
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
1
1
|
# @walkeros/server-destination-mparticle
|
|
2
2
|
|
|
3
|
+
## 4.8.3-next-1793115089237
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5313635: Step example descriptions name the `settings.userIdentities` mapping
|
|
8
|
+
their output depends on (`customer_id` from `user.id`, plus `email` from
|
|
9
|
+
`user.email` where shown), so each example says where the batch's
|
|
10
|
+
`user_identities` come from.
|
|
11
|
+
- 5313635: The package publishes a minimal example: the API key and secret, read
|
|
12
|
+
as the `MPARTICLE_API_KEY` and `MPARTICLE_API_SECRET` secrets. The docs page
|
|
13
|
+
renders the install line, the integrated code and the flow from it, and the
|
|
14
|
+
package test runs the same settings.
|
|
15
|
+
- Updated dependencies [34fd225]
|
|
16
|
+
- Updated dependencies [5313635]
|
|
17
|
+
- Updated dependencies [5313635]
|
|
18
|
+
- Updated dependencies [5313635]
|
|
19
|
+
- Updated dependencies [5313635]
|
|
20
|
+
- Updated dependencies [5313635]
|
|
21
|
+
- Updated dependencies [34fd225]
|
|
22
|
+
- Updated dependencies [5313635]
|
|
23
|
+
- @walkeros/core@4.8.3-next-1793115089237
|
|
24
|
+
- @walkeros/server-core@4.8.3-next-1793115089237
|
|
25
|
+
|
|
26
|
+
## 4.8.2
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- 2374f54: A failed request is reported as a failed push (dead-letter queue, one
|
|
31
|
+
ERROR line with the status) instead of counting as delivered or being logged
|
|
32
|
+
at debug. Events a destination cannot send, such as a missing user identifier,
|
|
33
|
+
fail with `missing-input`. Rules with `silent: true` send no event of their
|
|
34
|
+
own.
|
|
35
|
+
- Updated dependencies [2374f54]
|
|
36
|
+
- Updated dependencies [7e5fc27]
|
|
37
|
+
- Updated dependencies [2374f54]
|
|
38
|
+
- Updated dependencies [964590a]
|
|
39
|
+
- Updated dependencies [4100ede]
|
|
40
|
+
- Updated dependencies [2374f54]
|
|
41
|
+
- Updated dependencies [2374f54]
|
|
42
|
+
- Updated dependencies [15eb7b2]
|
|
43
|
+
- Updated dependencies [33a2779]
|
|
44
|
+
- Updated dependencies [33a2779]
|
|
45
|
+
- Updated dependencies [2374f54]
|
|
46
|
+
- @walkeros/core@4.8.2
|
|
47
|
+
- @walkeros/server-core@4.8.2
|
|
48
|
+
|
|
3
49
|
## 4.8.1
|
|
4
50
|
|
|
5
51
|
### Patch Changes
|
|
@@ -239,9 +285,6 @@
|
|
|
239
285
|
and `event.context` remain required.
|
|
240
286
|
- Each source self-registers via TypeScript module augmentation of `SourceMap`
|
|
241
287
|
in `@walkeros/core`.
|
|
242
|
-
- App-side coordination (`/workspaces/developer/app`) is a follow-up plan, not
|
|
243
|
-
part of this release. Telemetry from v4 CLI/MCP will not validate against
|
|
244
|
-
the existing app schema until that follow-up ships.
|
|
245
288
|
- `Mapping.Rule.skip` is renamed to `Mapping.Rule.silent`. Customer flow.json
|
|
246
289
|
configs using `skip: true` in mapping rules must rename to `silent: true`.
|
|
247
290
|
Hard cut: no legacy alias, the field is gone.
|
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,19 +136,29 @@ 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
|
|
|
151
|
+
/**
|
|
152
|
+
* The settings mParticle needs to deliver: the API key and secret, read
|
|
153
|
+
* from the environment.
|
|
154
|
+
*/
|
|
155
|
+
declare const minimal: Flow.MinimalExample;
|
|
156
|
+
|
|
148
157
|
declare const index_env: typeof env;
|
|
158
|
+
declare const index_minimal: typeof minimal;
|
|
149
159
|
declare const index_step: typeof step;
|
|
150
160
|
declare namespace index {
|
|
151
|
-
export { index_env as env, index_step as step };
|
|
161
|
+
export { index_env as env, index_minimal as minimal, index_step as step };
|
|
152
162
|
}
|
|
153
163
|
|
|
154
164
|
export { index as examples, index$1 as schemas };
|
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,19 +136,29 @@ 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
|
|
|
151
|
+
/**
|
|
152
|
+
* The settings mParticle needs to deliver: the API key and secret, read
|
|
153
|
+
* from the environment.
|
|
154
|
+
*/
|
|
155
|
+
declare const minimal: Flow.MinimalExample;
|
|
156
|
+
|
|
148
157
|
declare const index_env: typeof env;
|
|
158
|
+
declare const index_minimal: typeof minimal;
|
|
149
159
|
declare const index_step: typeof step;
|
|
150
160
|
declare namespace index {
|
|
151
|
-
export { index_env as env, index_step as step };
|
|
161
|
+
export { index_env as env, index_minimal as minimal, index_step as step };
|
|
152
162
|
}
|
|
153
163
|
|
|
154
164
|
export { index as examples, index$1 as schemas };
|
package/dist/dev.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,n=(e,r)=>{for(var i in r)t(e,i,{get:r[i],enumerable:!0})},o={};n(o,{examples:()=>f,schemas:()=>a}),module.exports=(e=o,((e,n,o,a)=>{if(n&&"object"==typeof n||"function"==typeof n)for(let c of i(n))s.call(e,c)||c===o||t(e,c,{get:()=>n[c],enumerable:!(a=r(n,c))||a.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a={};n(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),f={};n(f,{env:()=>w,minimal:()=>M,step:()=>z});var w={};n(w,{push:()=>S,simulation:()=>P});var S={sendServer:async()=>({data:{}})},P=["sendServer"],z={};n(z,{commercePurchase:()=>O,customEvent:()=>I,identityAndAttributes:()=>q,screenView:()=>T,silentRule:()=>x});var k=require("@walkeros/core"),A="https://s2s.mparticle.com/v2/events",E={headers:{Authorization:"Basic a2V5OnNlY3JldA==","Content-Type":"application/json"}},I={title:"Custom event",description:"A walker event is sent to mParticle as a custom_event; with settings.userIdentities mapping customer_id to user.id, the batch carries the user id.",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",A,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"}),E]]},T={title:"Screen view",description:"A page view is mapped to an mParticle screen_view event with the event name as the screen name. The user identities come from settings.userIdentities (customer_id: user.id).",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",A,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"}),E]]},O={title:"Commerce purchase",description:"A completed order becomes an mParticle commerce_event with a purchase product_action block. The user identities come from settings.userIdentities (customer_id: user.id).",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",A,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"}),E]]},q={title:"User identities",description:"A form submission sends a custom_event whose batch carries user_identities resolved from settings.userIdentities (customer_id: user.id, email: user.email).",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",A,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"}),E]]},x={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:[]},M={settings:{apiKey:"key",apiSecret:"secret"},secrets:{apiKey:"MPARTICLE_API_KEY",apiSecret:"MPARTICLE_API_SECRET"}};//# 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,aAAE,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,iBAAiB,cAAE,OAAO;AAAA,EACrC,QAAQ,cACL,OAAO,EACP,IAAI,CAAC,EACL;AAAA,IACC;AAAA,EACF;AAAA,EACF,WAAW,cACR,OAAO,EACP,IAAI,CAAC,EACL;AAAA,IACC;AAAA,EACF;AAAA,EACF,KAAK,UAAU;AAAA,IACb;AAAA,EACF,EAAE,SAAS;AAAA,EACX,aAAa,kBAAkB;AAAA,IAC7B;AAAA,EACF,EAAE,SAAS;AAAA,EACX,gBAAgB,cACb,OAAO,cAAE,OAAO,GAAG,cAAE,QAAQ,CAAC,EAC9B;AAAA,IACC;AA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;AAAA,EACP,aACE;AAAA,EACF,QAAI,sBAAS,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":["import_dev","import_dev","import_dev"]}
|
|
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","../src/examples/minimal.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';\nexport { minimal } from './minimal';\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 settings.userIdentities mapping customer_id to user.id, the batch carries the user id.',\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. The user identities come from settings.userIdentities (customer_id: user.id).',\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. The user identities come from settings.userIdentities (customer_id: user.id).',\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 settings.userIdentities (customer_id: user.id, email: user.email).',\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","import type { Flow } from '@walkeros/core';\n\n/**\n * The settings mParticle needs to deliver: the API key and secret, read\n * from the environment.\n */\nexport const minimal: Flow.MinimalExample = {\n settings: { apiKey: 'key', apiSecret: 'secret' },\n secrets: { apiKey: 'MPARTICLE_API_KEY', apiSecret: 'MPARTICLE_API_SECRET' },\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,aAAE,KAAK;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AA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a,EAAE,WAAW,YAAc,CAAC;AAAA,EACtD,SAAS,EAAE,QAAQ,KAAK;AAAA,EACxB,KAAK,CAAC;AACR;;;AC5OO,IAAM,UAA+B;AAAA,EAC1C,UAAU,EAAE,QAAQ,OAAO,WAAW,SAAS;AAAA,EAC/C,SAAS,EAAE,QAAQ,qBAAqB,WAAW,uBAAuB;AAC5E;","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,i=(e,i)=>{for(var r in i)t(e,r,{get:i[r],enumerable:!0})},r={};i(r,{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={};i(h,{env:()=>g,minimal:()=>C,step:()=>f});var g={};i(g,{push:()=>b,simulation:()=>y});var b={sendServer:async()=>({data:{}})},y=["sendServer"],f={};i(f,{commercePurchase:()=>T,customEvent:()=>A,identityAndAttributes:()=>E,screenView:()=>I,silentRule:()=>x});import{createEvent as w,getEvent as S}from"@walkeros/core";var P="https://s2s.mparticle.com/v2/events",k={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 settings.userIdentities mapping customer_id to user.id, the batch carries the user id.",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",P,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"}),k]]},I={title:"Screen view",description:"A page view is mapped to an mParticle screen_view event with the event name as the screen name. The user identities come from settings.userIdentities (customer_id: user.id).",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",P,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"}),k]]},T={title:"Commerce purchase",description:"A completed order becomes an mParticle commerce_event with a purchase product_action block. The user identities come from settings.userIdentities (customer_id: user.id).",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",P,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"}),k]]},E={title:"User identities",description:"A form submission sends a custom_event whose batch carries user_identities resolved from settings.userIdentities (customer_id: user.id, email: user.email).",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",P,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"}),k]]},x={public:!1,description:"A rule with silent: true sends no request to mParticle.",in:S("page view",{timestamp:170000099e4}),mapping:{silent:!0},out:[]},C={settings:{apiKey:"key",apiSecret:"secret"},secrets:{apiKey:"MPARTICLE_API_KEY",apiSecret:"MPARTICLE_API_SECRET"}};export{h as examples,r 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;A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AK,UAAU;AAAA,QACb,QAAQ;AAAA,UACN;AAAA,YACE,YAAY;AAAA,YACZ,MAAM;AAAA,cACJ,eAAe;AAAA,cACf,gBAAgB;AAAA,gBACd,QAAQ;AAAA,gBACR,gBAAgB;AAAA,gBAChB,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","../src/examples/minimal.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';\nexport { minimal } from './minimal';\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 settings.userIdentities mapping customer_id to user.id, the batch carries the user id.',\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. The user identities come from settings.userIdentities (customer_id: user.id).',\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. The user identities come from settings.userIdentities (customer_id: user.id).',\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 settings.userIdentities (customer_id: user.id, email: user.email).',\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","import type { Flow } from '@walkeros/core';\n\n/**\n * The settings mParticle needs to deliver: the API key and secret, read\n * from the environment.\n */\nexport const minimal: Flow.MinimalExample = {\n settings: { apiKey: 'key', apiSecret: 'secret' },\n secrets: { apiKey: 'MPARTICLE_API_KEY', apiSecret: 'MPARTICLE_API_SECRET' },\n};\n"],"mappings":";;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAS,mBAAmB;;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,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;AAGO,IAAM,aAA+B;AAAA,EAC1C,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,IAAI,SAAS,aAAa,EAAE,WAAW,YAAc,CAAC;AAAA,EACtD,SAAS,EAAE,QAAQ,KAAK;AAAA,EACxB,KAAK,CAAC;AACR;;;AC5OO,IAAM,UAA+B;AAAA,EAC1C,UAAU,EAAE,QAAQ,OAAO,WAAW,SAAS;AAAA,EAC/C,SAAS,EAAE,QAAQ,qBAAqB,WAAW,uBAAuB;AAC5E;","names":["z","z","z","z"]}
|
|
@@ -40,13 +40,22 @@ 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
|
+
/**
|
|
56
|
+
* The settings mParticle needs to deliver: the API key and secret, read
|
|
57
|
+
* from the environment.
|
|
58
|
+
*/
|
|
59
|
+
declare const minimal: Flow.MinimalExample;
|
|
60
|
+
|
|
61
|
+
export { env, minimal, step };
|
package/dist/examples/index.d.ts
CHANGED
|
@@ -40,13 +40,22 @@ 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
|
+
/**
|
|
56
|
+
* The settings mParticle needs to deliver: the API key and secret, read
|
|
57
|
+
* from the environment.
|
|
58
|
+
*/
|
|
59
|
+
declare const minimal: Flow.MinimalExample;
|
|
60
|
+
|
|
61
|
+
export { env, minimal, step };
|
package/dist/examples/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var examples_exports = {};
|
|
22
22
|
__export(examples_exports, {
|
|
23
23
|
env: () => env_exports,
|
|
24
|
+
minimal: () => minimal,
|
|
24
25
|
step: () => step_exports
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(examples_exports);
|
|
@@ -33,7 +34,6 @@ __export(env_exports, {
|
|
|
33
34
|
});
|
|
34
35
|
var mockSendServer = async () => {
|
|
35
36
|
return {
|
|
36
|
-
ok: true,
|
|
37
37
|
data: {}
|
|
38
38
|
};
|
|
39
39
|
};
|
|
@@ -48,7 +48,8 @@ __export(step_exports, {
|
|
|
48
48
|
commercePurchase: () => commercePurchase,
|
|
49
49
|
customEvent: () => customEvent,
|
|
50
50
|
identityAndAttributes: () => identityAndAttributes,
|
|
51
|
-
screenView: () => screenView
|
|
51
|
+
screenView: () => screenView,
|
|
52
|
+
silentRule: () => silentRule
|
|
52
53
|
});
|
|
53
54
|
var import_core = require("@walkeros/core");
|
|
54
55
|
var ENDPOINT = "https://s2s.mparticle.com/v2/events";
|
|
@@ -61,7 +62,7 @@ var OPTIONS = {
|
|
|
61
62
|
};
|
|
62
63
|
var customEvent = {
|
|
63
64
|
title: "Custom event",
|
|
64
|
-
description: "A walker event is sent to mParticle as a custom_event with user
|
|
65
|
+
description: "A walker event is sent to mParticle as a custom_event; with settings.userIdentities mapping customer_id to user.id, the batch carries the user id.",
|
|
65
66
|
in: (0, import_core.getEvent)("product view", {
|
|
66
67
|
id: "ev-1700000100000",
|
|
67
68
|
timestamp: 17000001e5,
|
|
@@ -98,7 +99,7 @@ var customEvent = {
|
|
|
98
99
|
};
|
|
99
100
|
var screenView = {
|
|
100
101
|
title: "Screen view",
|
|
101
|
-
description: "A page view is mapped to an mParticle screen_view event with the event name as the screen name.",
|
|
102
|
+
description: "A page view is mapped to an mParticle screen_view event with the event name as the screen name. The user identities come from settings.userIdentities (customer_id: user.id).",
|
|
102
103
|
in: (0, import_core.getEvent)("page view", {
|
|
103
104
|
id: "ev-1700000200000",
|
|
104
105
|
timestamp: 17000002e5,
|
|
@@ -136,11 +137,11 @@ var screenView = {
|
|
|
136
137
|
};
|
|
137
138
|
var commercePurchase = {
|
|
138
139
|
title: "Commerce purchase",
|
|
139
|
-
description: "A completed order becomes an mParticle commerce_event with a purchase product_action block.",
|
|
140
|
+
description: "A completed order becomes an mParticle commerce_event with a purchase product_action block. The user identities come from settings.userIdentities (customer_id: user.id).",
|
|
140
141
|
in: (0, import_core.getEvent)("order complete", {
|
|
141
142
|
id: "ev-1700000300000",
|
|
142
143
|
timestamp: 17000003e5,
|
|
143
|
-
data: { id: "ORD-300",
|
|
144
|
+
data: { id: "ORD-300", value: 249.99, currency: "EUR" },
|
|
144
145
|
user: { id: "user-123" },
|
|
145
146
|
source: { type: "express", platform: "server" }
|
|
146
147
|
}),
|
|
@@ -154,7 +155,7 @@ var commercePurchase = {
|
|
|
154
155
|
map: {
|
|
155
156
|
action: { value: "purchase" },
|
|
156
157
|
transaction_id: "data.id",
|
|
157
|
-
total_amount: "data.
|
|
158
|
+
total_amount: "data.value"
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
}
|
|
@@ -193,8 +194,9 @@ var commercePurchase = {
|
|
|
193
194
|
};
|
|
194
195
|
var identityAndAttributes = {
|
|
195
196
|
title: "User identities",
|
|
196
|
-
description: "A form submission sends a custom_event whose batch carries user_identities resolved from
|
|
197
|
-
in: (0, import_core.
|
|
197
|
+
description: "A form submission sends a custom_event whose batch carries user_identities resolved from settings.userIdentities (customer_id: user.id, email: user.email).",
|
|
198
|
+
in: (0, import_core.createEvent)({
|
|
199
|
+
name: "form submit",
|
|
198
200
|
id: "ev-1700000400000",
|
|
199
201
|
timestamp: 17000004e5,
|
|
200
202
|
data: { type: "newsletter" },
|
|
@@ -232,8 +234,22 @@ var identityAndAttributes = {
|
|
|
232
234
|
]
|
|
233
235
|
]
|
|
234
236
|
};
|
|
237
|
+
var silentRule = {
|
|
238
|
+
public: false,
|
|
239
|
+
description: "A rule with silent: true sends no request to mParticle.",
|
|
240
|
+
in: (0, import_core.getEvent)("page view", { timestamp: 170000099e4 }),
|
|
241
|
+
mapping: { silent: true },
|
|
242
|
+
out: []
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// src/examples/minimal.ts
|
|
246
|
+
var minimal = {
|
|
247
|
+
settings: { apiKey: "key", apiSecret: "secret" },
|
|
248
|
+
secrets: { apiKey: "MPARTICLE_API_KEY", apiSecret: "MPARTICLE_API_SECRET" }
|
|
249
|
+
};
|
|
235
250
|
// Annotate the CommonJS export names for ESM import in node:
|
|
236
251
|
0 && (module.exports = {
|
|
237
252
|
env,
|
|
253
|
+
minimal,
|
|
238
254
|
step
|
|
239
255
|
});
|
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: {
|
|
@@ -40,7 +40,7 @@ var OPTIONS = {
|
|
|
40
40
|
};
|
|
41
41
|
var customEvent = {
|
|
42
42
|
title: "Custom event",
|
|
43
|
-
description: "A walker event is sent to mParticle as a custom_event with user
|
|
43
|
+
description: "A walker event is sent to mParticle as a custom_event; with settings.userIdentities mapping customer_id to user.id, the batch carries the user id.",
|
|
44
44
|
in: getEvent("product view", {
|
|
45
45
|
id: "ev-1700000100000",
|
|
46
46
|
timestamp: 17000001e5,
|
|
@@ -77,7 +77,7 @@ var customEvent = {
|
|
|
77
77
|
};
|
|
78
78
|
var screenView = {
|
|
79
79
|
title: "Screen view",
|
|
80
|
-
description: "A page view is mapped to an mParticle screen_view event with the event name as the screen name.",
|
|
80
|
+
description: "A page view is mapped to an mParticle screen_view event with the event name as the screen name. The user identities come from settings.userIdentities (customer_id: user.id).",
|
|
81
81
|
in: getEvent("page view", {
|
|
82
82
|
id: "ev-1700000200000",
|
|
83
83
|
timestamp: 17000002e5,
|
|
@@ -115,11 +115,11 @@ var screenView = {
|
|
|
115
115
|
};
|
|
116
116
|
var commercePurchase = {
|
|
117
117
|
title: "Commerce purchase",
|
|
118
|
-
description: "A completed order becomes an mParticle commerce_event with a purchase product_action block.",
|
|
118
|
+
description: "A completed order becomes an mParticle commerce_event with a purchase product_action block. The user identities come from settings.userIdentities (customer_id: user.id).",
|
|
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
|
}
|
|
@@ -172,8 +172,9 @@ var commercePurchase = {
|
|
|
172
172
|
};
|
|
173
173
|
var identityAndAttributes = {
|
|
174
174
|
title: "User identities",
|
|
175
|
-
description: "A form submission sends a custom_event whose batch carries user_identities resolved from
|
|
176
|
-
in:
|
|
175
|
+
description: "A form submission sends a custom_event whose batch carries user_identities resolved from settings.userIdentities (customer_id: user.id, email: user.email).",
|
|
176
|
+
in: createEvent({
|
|
177
|
+
name: "form submit",
|
|
177
178
|
id: "ev-1700000400000",
|
|
178
179
|
timestamp: 17000004e5,
|
|
179
180
|
data: { type: "newsletter" },
|
|
@@ -211,7 +212,21 @@ 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
|
+
};
|
|
222
|
+
|
|
223
|
+
// src/examples/minimal.ts
|
|
224
|
+
var minimal = {
|
|
225
|
+
settings: { apiKey: "key", apiSecret: "secret" },
|
|
226
|
+
secrets: { apiKey: "MPARTICLE_API_KEY", apiSecret: "MPARTICLE_API_SECRET" }
|
|
227
|
+
};
|
|
214
228
|
export {
|
|
215
229
|
env_exports as env,
|
|
230
|
+
minimal,
|
|
216
231
|
step_exports as step
|
|
217
232
|
};
|
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;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,kBAA0C;AAC1C,yBAA2B;;;ACWpB,SAAS,cAAc,MAAW,OAAe;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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,EAAE,GAAG,eAAe,UAAU,eAAe;AACtD;;;ACrBA,IAAAA,eAAqD;AACrD,yBAA2B;;;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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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};\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AC7C;AAEA,eAAe,sBACb,OACA,oBACA,gBACA,WAC8C;AAC9C,QAAM,mBAAmB,qBACrB,MAAM,gBAAgB,OAAO,oBAAoB,EAAE,UAAU,CAAC,IAC9D;AACJ,QAAM,eAAe,iBACjB,MAAM,gBAAgB,OAAO,gBAAgB,EAAE,UAAU,CAAC,IAC1D;AAEJ,QAAM,SAAkC;AAAA,IACtC,GAAI,SAAS,gBAAgB,IACxB,mBACD,CAAC;AAAA,IACL,GAAI,SAAS,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;;;ACOO,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/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,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,UAAU,mBAAmB,QAAQ,KAAK,IAAI,CAAC,YAAY;AAAA,MACnE,MAAM;AAA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AkC;AAAA,IACtC,GAAI,SAAS,gBAAgB,IACxB,mBACD,CAAC;AAAA,IACL,GAAI,SAAS,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;;;AEpNA;;;ACOO,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":["StepError","StepError"]}
|
package/dist/walkerOS.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$meta": {
|
|
3
3
|
"package": "@walkeros/server-destination-mparticle",
|
|
4
|
-
"version": "4.8.
|
|
4
|
+
"version": "4.8.3-next-1793115089237",
|
|
5
5
|
"type": "destination",
|
|
6
6
|
"platform": [
|
|
7
7
|
"server"
|
|
@@ -126,22 +126,32 @@
|
|
|
126
126
|
"env": {
|
|
127
127
|
"push": {
|
|
128
128
|
"sendServer": {
|
|
129
|
-
"$code": "async()=>({
|
|
129
|
+
"$code": "async()=>({data:{}})"
|
|
130
130
|
}
|
|
131
131
|
},
|
|
132
132
|
"simulation": [
|
|
133
133
|
"sendServer"
|
|
134
134
|
]
|
|
135
135
|
},
|
|
136
|
+
"minimal": {
|
|
137
|
+
"settings": {
|
|
138
|
+
"apiKey": "key",
|
|
139
|
+
"apiSecret": "secret"
|
|
140
|
+
},
|
|
141
|
+
"secrets": {
|
|
142
|
+
"apiKey": "MPARTICLE_API_KEY",
|
|
143
|
+
"apiSecret": "MPARTICLE_API_SECRET"
|
|
144
|
+
}
|
|
145
|
+
},
|
|
136
146
|
"step": {
|
|
137
147
|
"commercePurchase": {
|
|
138
148
|
"title": "Commerce purchase",
|
|
139
|
-
"description": "A completed order becomes an mParticle commerce_event with a purchase product_action block.",
|
|
149
|
+
"description": "A completed order becomes an mParticle commerce_event with a purchase product_action block. The user identities come from settings.userIdentities (customer_id: user.id).",
|
|
140
150
|
"in": {
|
|
141
151
|
"name": "order complete",
|
|
142
152
|
"data": {
|
|
143
153
|
"id": "ORD-300",
|
|
144
|
-
"
|
|
154
|
+
"value": 249.99,
|
|
145
155
|
"currency": "EUR"
|
|
146
156
|
},
|
|
147
157
|
"context": {
|
|
@@ -235,7 +245,7 @@
|
|
|
235
245
|
"value": "purchase"
|
|
236
246
|
},
|
|
237
247
|
"transaction_id": "data.id",
|
|
238
|
-
"total_amount": "data.
|
|
248
|
+
"total_amount": "data.value"
|
|
239
249
|
}
|
|
240
250
|
}
|
|
241
251
|
}
|
|
@@ -258,7 +268,7 @@
|
|
|
258
268
|
},
|
|
259
269
|
"customEvent": {
|
|
260
270
|
"title": "Custom event",
|
|
261
|
-
"description": "A walker event is sent to mParticle as a custom_event with user
|
|
271
|
+
"description": "A walker event is sent to mParticle as a custom_event; with settings.userIdentities mapping customer_id to user.id, the batch carries the user id.",
|
|
262
272
|
"in": {
|
|
263
273
|
"name": "product view",
|
|
264
274
|
"data": {
|
|
@@ -314,7 +324,7 @@
|
|
|
314
324
|
},
|
|
315
325
|
"identityAndAttributes": {
|
|
316
326
|
"title": "User identities",
|
|
317
|
-
"description": "A form submission sends a custom_event whose batch carries user_identities resolved from
|
|
327
|
+
"description": "A form submission sends a custom_event whose batch carries user_identities resolved from settings.userIdentities (customer_id: user.id, email: user.email).",
|
|
318
328
|
"in": {
|
|
319
329
|
"name": "form submit",
|
|
320
330
|
"data": {
|
|
@@ -376,7 +386,7 @@
|
|
|
376
386
|
},
|
|
377
387
|
"screenView": {
|
|
378
388
|
"title": "Screen view",
|
|
379
|
-
"description": "A page view is mapped to an mParticle screen_view event with the event name as the screen name.",
|
|
389
|
+
"description": "A page view is mapped to an mParticle screen_view event with the event name as the screen name. The user identities come from settings.userIdentities (customer_id: user.id).",
|
|
380
390
|
"in": {
|
|
381
391
|
"name": "page view",
|
|
382
392
|
"data": {
|
|
@@ -440,6 +450,65 @@
|
|
|
440
450
|
}
|
|
441
451
|
]
|
|
442
452
|
]
|
|
453
|
+
},
|
|
454
|
+
"silentRule": {
|
|
455
|
+
"public": false,
|
|
456
|
+
"description": "A rule with silent: true sends no request to mParticle.",
|
|
457
|
+
"in": {
|
|
458
|
+
"name": "page view",
|
|
459
|
+
"data": {
|
|
460
|
+
"domain": "www.example.com",
|
|
461
|
+
"title": "walkerOS documentation",
|
|
462
|
+
"referrer": "https://www.walkeros.io/",
|
|
463
|
+
"search": "?foo=bar",
|
|
464
|
+
"hash": "#hash",
|
|
465
|
+
"id": "/docs/"
|
|
466
|
+
},
|
|
467
|
+
"context": {
|
|
468
|
+
"dev": [
|
|
469
|
+
"test",
|
|
470
|
+
1
|
|
471
|
+
]
|
|
472
|
+
},
|
|
473
|
+
"globals": {
|
|
474
|
+
"pagegroup": "docs"
|
|
475
|
+
},
|
|
476
|
+
"custom": {
|
|
477
|
+
"completely": "random"
|
|
478
|
+
},
|
|
479
|
+
"user": {
|
|
480
|
+
"id": "us3r",
|
|
481
|
+
"device": "c00k13",
|
|
482
|
+
"session": "s3ss10n"
|
|
483
|
+
},
|
|
484
|
+
"nested": [
|
|
485
|
+
{
|
|
486
|
+
"entity": "child",
|
|
487
|
+
"data": {
|
|
488
|
+
"is": "subordinated"
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
],
|
|
492
|
+
"consent": {
|
|
493
|
+
"functional": true
|
|
494
|
+
},
|
|
495
|
+
"id": "f0cc5f6fec3d8eeb",
|
|
496
|
+
"trigger": "load",
|
|
497
|
+
"entity": "page",
|
|
498
|
+
"action": "view",
|
|
499
|
+
"timestamp": 1700000990000,
|
|
500
|
+
"timing": 3.14,
|
|
501
|
+
"source": {
|
|
502
|
+
"count": 1,
|
|
503
|
+
"trace": "0a1b2c3d4e5f60718293a4b5c6d7e8f9",
|
|
504
|
+
"type": "collector",
|
|
505
|
+
"schema": "4"
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
"mapping": {
|
|
509
|
+
"silent": true
|
|
510
|
+
},
|
|
511
|
+
"out": []
|
|
443
512
|
}
|
|
444
513
|
}
|
|
445
514
|
}
|
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.3-next-1793115089237",
|
|
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.3-next-1793115089237",
|
|
39
|
+
"@walkeros/server-core": "4.8.3-next-1793115089237"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@walkeros/collector": "4.8.
|
|
42
|
+
"@walkeros/collector": "4.8.3-next-1793115089237"
|
|
43
43
|
},
|
|
44
44
|
"repository": {
|
|
45
45
|
"url": "git+https://github.com/elbwalker/walkerOS.git",
|