@walkeros/server-destination-posthog 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.
@@ -11,8 +11,6 @@ interface Settings {
11
11
  identify?: Mapping.Value;
12
12
  /** Destination-level group mapping */
13
13
  group?: Mapping.Value;
14
- /** Event sections to flatten into capture properties */
15
- include?: string[];
16
14
  host?: string;
17
15
  flushAt?: number;
18
16
  flushInterval?: number;
@@ -25,6 +23,8 @@ interface Settings {
25
23
  fetchRetryDelay?: number;
26
24
  debug?: boolean;
27
25
  disabled?: boolean;
26
+ /** The running send; the next one waits for it. Runtime only. */
27
+ _sending?: Promise<void>;
28
28
  }
29
29
  /**
30
30
  * The part of a PostHog client this destination calls. `PostHog` from
@@ -35,6 +35,10 @@ interface PostHogClient {
35
35
  capture(props: Parameters<PostHog['capture']>[0]): void;
36
36
  identify(props: Parameters<PostHog['identify']>[0]): void;
37
37
  groupIdentify(props: Parameters<PostHog['groupIdentify']>[0]): void;
38
+ /** Sends the queued calls; rejects when the request failed. */
39
+ flush(): Promise<void>;
40
+ /** The SDK reports a failed send as an `error` event; returns its remover. */
41
+ on?(event: 'error', listener: (error: unknown) => void): () => void;
38
42
  shutdown(): Promise<void> | void;
39
43
  enable(): Promise<void> | void;
40
44
  disable(): Promise<void> | void;
@@ -109,6 +113,14 @@ declare const consentRevoke: PostHogStepExample;
109
113
  * Consent granted - client.enable() is called.
110
114
  */
111
115
  declare const consentGrant: PostHogStepExample;
116
+ /** A silent rule without identify or group mappings calls nothing. */
117
+ declare const silentRule: PostHogStepExample;
118
+ /**
119
+ * The silent group identify rule of groupIdentifyWithProperties on an event
120
+ * without data: no group key resolves and the rule suppresses the capture,
121
+ * so nothing is sent.
122
+ */
123
+ declare const groupIdentifyWithoutData: PostHogStepExample;
112
124
 
113
125
  type step_PostHogStepExample = PostHogStepExample;
114
126
  declare const step_captureWithGroupContext: typeof captureWithGroupContext;
@@ -117,9 +129,17 @@ declare const step_consentGrant: typeof consentGrant;
117
129
  declare const step_consentRevoke: typeof consentRevoke;
118
130
  declare const step_defaultCapture: typeof defaultCapture;
119
131
  declare const step_groupIdentifyWithProperties: typeof groupIdentifyWithProperties;
132
+ declare const step_groupIdentifyWithoutData: typeof groupIdentifyWithoutData;
120
133
  declare const step_identifyWithSetAndSetOnce: typeof identifyWithSetAndSetOnce;
134
+ declare const step_silentRule: typeof silentRule;
121
135
  declare namespace step {
122
- export { type step_PostHogStepExample as PostHogStepExample, step_captureWithGroupContext as captureWithGroupContext, step_captureWithInclude as captureWithInclude, step_consentGrant as consentGrant, step_consentRevoke as consentRevoke, step_defaultCapture as defaultCapture, step_groupIdentifyWithProperties as groupIdentifyWithProperties, step_identifyWithSetAndSetOnce as identifyWithSetAndSetOnce };
136
+ export { type step_PostHogStepExample as PostHogStepExample, step_captureWithGroupContext as captureWithGroupContext, step_captureWithInclude as captureWithInclude, step_consentGrant as consentGrant, step_consentRevoke as consentRevoke, step_defaultCapture as defaultCapture, step_groupIdentifyWithProperties as groupIdentifyWithProperties, step_groupIdentifyWithoutData as groupIdentifyWithoutData, step_identifyWithSetAndSetOnce as identifyWithSetAndSetOnce, step_silentRule as silentRule };
123
137
  }
124
138
 
125
- export { env, step };
139
+ /**
140
+ * The setting PostHog needs to deliver: the project API key, read from the
141
+ * environment.
142
+ */
143
+ declare const minimal: Flow.MinimalExample;
144
+
145
+ export { env, minimal, step };
@@ -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);
@@ -86,17 +87,20 @@ __export(step_exports, {
86
87
  consentRevoke: () => consentRevoke,
87
88
  defaultCapture: () => defaultCapture,
88
89
  groupIdentifyWithProperties: () => groupIdentifyWithProperties,
89
- identifyWithSetAndSetOnce: () => identifyWithSetAndSetOnce
90
+ groupIdentifyWithoutData: () => groupIdentifyWithoutData,
91
+ identifyWithSetAndSetOnce: () => identifyWithSetAndSetOnce,
92
+ silentRule: () => silentRule
90
93
  });
91
94
  var import_core = require("@walkeros/core");
92
95
  var defaultCapture = {
93
96
  title: "Default capture",
94
97
  description: "A walker event becomes a PostHog capture call with the user id as distinctId and no extra properties.",
95
- in: (0, import_core.getEvent)("product view", { timestamp: 1700000100 }),
98
+ in: (0, import_core.getEvent)("product view", { id: "ev1700000100", timestamp: 1700000100 }),
96
99
  out: [
97
100
  [
98
101
  "client.capture",
99
102
  {
103
+ uuid: "b8a7f21f-1a9f-8aa7-8480-8d16fb64c44c",
100
104
  distinctId: "us3r",
101
105
  event: "product view",
102
106
  properties: {}
@@ -106,21 +110,23 @@ var defaultCapture = {
106
110
  };
107
111
  var captureWithInclude = {
108
112
  title: "Capture with include",
109
- description: "Destination-level include flattens data and globals sections into prefixed PostHog event properties.",
110
- in: (0, import_core.getEvent)("order complete", { timestamp: 1700000101 }),
113
+ description: "With include: ['data', 'globals'] in the destination config, the data and globals sections are flattened into prefixed PostHog event properties.",
114
+ in: (0, import_core.getEvent)("order complete", { id: "ev1700000101", timestamp: 1700000101 }),
111
115
  configInclude: ["data", "globals"],
112
116
  out: [
113
117
  [
114
118
  "client.capture",
115
119
  {
120
+ uuid: "a5a5ede9-4f3b-85f4-b30f-3da8773fabfa",
116
121
  distinctId: "us3r",
117
122
  event: "order complete",
118
123
  properties: {
119
124
  data_id: "0rd3r1d",
120
125
  data_currency: "EUR",
126
+ data_value: 462,
127
+ data_tax: 73.76,
121
128
  data_shipping: 5.22,
122
- data_taxes: 73.76,
123
- data_total: 555,
129
+ data_total: 467.22,
124
130
  globals_pagegroup: "shop"
125
131
  }
126
132
  }
@@ -130,8 +136,9 @@ var captureWithInclude = {
130
136
  var identifyWithSetAndSetOnce = {
131
137
  title: "Identify with $set",
132
138
  description: "A user login fires PostHog identify with $set and $set_once person properties and skips the capture.",
133
- in: (0, import_core.getEvent)("user login", {
134
- timestamp: 1700000102,
139
+ in: (0, import_core.createEvent)({
140
+ name: "user login",
141
+ timestamp: 1700000102e3,
135
142
  data: {
136
143
  user_id: "new-user-123",
137
144
  email: "user@acme.com",
@@ -170,7 +177,7 @@ var identifyWithSetAndSetOnce = {
170
177
  plan: "premium"
171
178
  },
172
179
  $set_once: {
173
- first_login: 1700000102
180
+ first_login: 1700000102e3
174
181
  }
175
182
  }
176
183
  }
@@ -180,7 +187,8 @@ var identifyWithSetAndSetOnce = {
180
187
  var groupIdentifyWithProperties = {
181
188
  title: "Group identify",
182
189
  description: "A company update fires PostHog groupIdentify with group type, key, and associated group properties.",
183
- in: (0, import_core.getEvent)("company update", {
190
+ in: (0, import_core.createEvent)({
191
+ name: "company update",
184
192
  timestamp: 1700000103,
185
193
  data: {
186
194
  company_id: "company_123",
@@ -221,8 +229,9 @@ var groupIdentifyWithProperties = {
221
229
  };
222
230
  var captureWithGroupContext = {
223
231
  title: "Capture with group",
224
- description: "A destination-level group mapping attaches the resolved group context to every PostHog capture call.",
232
+ description: "With settings.group mapping type to 'company' and key to 'globals.company_id', every PostHog capture call carries the resolved group.",
225
233
  in: (0, import_core.getEvent)("page view", {
234
+ id: "ev1700000104",
226
235
  timestamp: 1700000104,
227
236
  globals: { pagegroup: "docs", company_id: "company_123" }
228
237
  }),
@@ -238,6 +247,7 @@ var captureWithGroupContext = {
238
247
  [
239
248
  "client.capture",
240
249
  {
250
+ uuid: "c6a47305-44fc-8835-b15f-3f494c1f9e20",
241
251
  distinctId: "us3r",
242
252
  event: "page view",
243
253
  properties: {},
@@ -246,25 +256,53 @@ var captureWithGroupContext = {
246
256
  ]
247
257
  ]
248
258
  };
259
+ var analyticsDenied = { analytics: false };
260
+ var analyticsGranted = { analytics: true };
249
261
  var consentRevoke = {
250
262
  title: "Consent revoked",
251
- description: "A walker consent command with analytics denied calls client.disable on the PostHog client.",
263
+ description: "With consent: { analytics: true } in the destination config, revoking analytics consent after a grant calls client.disable on the PostHog client.",
252
264
  command: "consent",
253
265
  before: { analytics: true },
254
- in: { analytics: false },
266
+ in: analyticsDenied,
255
267
  settings: {},
256
268
  out: [["client.enable"], ["client.disable"]]
257
269
  };
258
270
  var consentGrant = {
259
271
  title: "Consent granted",
260
- description: "A walker consent command with analytics granted calls client.enable on the PostHog client.",
272
+ description: "With consent: { analytics: true } in the destination config, a walker consent command that grants analytics calls client.enable on the PostHog client.",
261
273
  command: "consent",
262
- in: { analytics: true },
274
+ in: analyticsGranted,
263
275
  settings: {},
264
276
  out: [["client.enable"]]
265
277
  };
278
+ var silentRule = {
279
+ public: false,
280
+ description: "A rule with silent: true and no identify or group mapping sends nothing to PostHog.",
281
+ in: (0, import_core.getEvent)("page view", { timestamp: 1700000105 }),
282
+ mapping: { silent: true },
283
+ out: []
284
+ };
285
+ var groupIdentifyWithoutData = {
286
+ public: false,
287
+ description: "A silent group rule whose key finds no data sends nothing: an unmet mapping, not a failure, so the push returns normally.",
288
+ in: {
289
+ name: "company update",
290
+ entity: "company",
291
+ action: "update",
292
+ timestamp: 1700000106
293
+ },
294
+ mapping: groupIdentifyWithProperties.mapping,
295
+ out: []
296
+ };
297
+
298
+ // src/examples/minimal.ts
299
+ var minimal = {
300
+ settings: { apiKey: "phc_test" },
301
+ secrets: { apiKey: "POSTHOG_API_KEY" }
302
+ };
266
303
  // Annotate the CommonJS export names for ESM import in node:
267
304
  0 && (module.exports = {
268
305
  env,
306
+ minimal,
269
307
  step
270
308
  });
@@ -65,17 +65,20 @@ __export(step_exports, {
65
65
  consentRevoke: () => consentRevoke,
66
66
  defaultCapture: () => defaultCapture,
67
67
  groupIdentifyWithProperties: () => groupIdentifyWithProperties,
68
- identifyWithSetAndSetOnce: () => identifyWithSetAndSetOnce
68
+ groupIdentifyWithoutData: () => groupIdentifyWithoutData,
69
+ identifyWithSetAndSetOnce: () => identifyWithSetAndSetOnce,
70
+ silentRule: () => silentRule
69
71
  });
70
- import { getEvent } from "@walkeros/core";
72
+ import { createEvent, getEvent } from "@walkeros/core";
71
73
  var defaultCapture = {
72
74
  title: "Default capture",
73
75
  description: "A walker event becomes a PostHog capture call with the user id as distinctId and no extra properties.",
74
- in: getEvent("product view", { timestamp: 1700000100 }),
76
+ in: getEvent("product view", { id: "ev1700000100", timestamp: 1700000100 }),
75
77
  out: [
76
78
  [
77
79
  "client.capture",
78
80
  {
81
+ uuid: "b8a7f21f-1a9f-8aa7-8480-8d16fb64c44c",
79
82
  distinctId: "us3r",
80
83
  event: "product view",
81
84
  properties: {}
@@ -85,21 +88,23 @@ var defaultCapture = {
85
88
  };
86
89
  var captureWithInclude = {
87
90
  title: "Capture with include",
88
- description: "Destination-level include flattens data and globals sections into prefixed PostHog event properties.",
89
- in: getEvent("order complete", { timestamp: 1700000101 }),
91
+ description: "With include: ['data', 'globals'] in the destination config, the data and globals sections are flattened into prefixed PostHog event properties.",
92
+ in: getEvent("order complete", { id: "ev1700000101", timestamp: 1700000101 }),
90
93
  configInclude: ["data", "globals"],
91
94
  out: [
92
95
  [
93
96
  "client.capture",
94
97
  {
98
+ uuid: "a5a5ede9-4f3b-85f4-b30f-3da8773fabfa",
95
99
  distinctId: "us3r",
96
100
  event: "order complete",
97
101
  properties: {
98
102
  data_id: "0rd3r1d",
99
103
  data_currency: "EUR",
104
+ data_value: 462,
105
+ data_tax: 73.76,
100
106
  data_shipping: 5.22,
101
- data_taxes: 73.76,
102
- data_total: 555,
107
+ data_total: 467.22,
103
108
  globals_pagegroup: "shop"
104
109
  }
105
110
  }
@@ -109,8 +114,9 @@ var captureWithInclude = {
109
114
  var identifyWithSetAndSetOnce = {
110
115
  title: "Identify with $set",
111
116
  description: "A user login fires PostHog identify with $set and $set_once person properties and skips the capture.",
112
- in: getEvent("user login", {
113
- timestamp: 1700000102,
117
+ in: createEvent({
118
+ name: "user login",
119
+ timestamp: 1700000102e3,
114
120
  data: {
115
121
  user_id: "new-user-123",
116
122
  email: "user@acme.com",
@@ -149,7 +155,7 @@ var identifyWithSetAndSetOnce = {
149
155
  plan: "premium"
150
156
  },
151
157
  $set_once: {
152
- first_login: 1700000102
158
+ first_login: 1700000102e3
153
159
  }
154
160
  }
155
161
  }
@@ -159,7 +165,8 @@ var identifyWithSetAndSetOnce = {
159
165
  var groupIdentifyWithProperties = {
160
166
  title: "Group identify",
161
167
  description: "A company update fires PostHog groupIdentify with group type, key, and associated group properties.",
162
- in: getEvent("company update", {
168
+ in: createEvent({
169
+ name: "company update",
163
170
  timestamp: 1700000103,
164
171
  data: {
165
172
  company_id: "company_123",
@@ -200,8 +207,9 @@ var groupIdentifyWithProperties = {
200
207
  };
201
208
  var captureWithGroupContext = {
202
209
  title: "Capture with group",
203
- description: "A destination-level group mapping attaches the resolved group context to every PostHog capture call.",
210
+ description: "With settings.group mapping type to 'company' and key to 'globals.company_id', every PostHog capture call carries the resolved group.",
204
211
  in: getEvent("page view", {
212
+ id: "ev1700000104",
205
213
  timestamp: 1700000104,
206
214
  globals: { pagegroup: "docs", company_id: "company_123" }
207
215
  }),
@@ -217,6 +225,7 @@ var captureWithGroupContext = {
217
225
  [
218
226
  "client.capture",
219
227
  {
228
+ uuid: "c6a47305-44fc-8835-b15f-3f494c1f9e20",
220
229
  distinctId: "us3r",
221
230
  event: "page view",
222
231
  properties: {},
@@ -225,24 +234,52 @@ var captureWithGroupContext = {
225
234
  ]
226
235
  ]
227
236
  };
237
+ var analyticsDenied = { analytics: false };
238
+ var analyticsGranted = { analytics: true };
228
239
  var consentRevoke = {
229
240
  title: "Consent revoked",
230
- description: "A walker consent command with analytics denied calls client.disable on the PostHog client.",
241
+ description: "With consent: { analytics: true } in the destination config, revoking analytics consent after a grant calls client.disable on the PostHog client.",
231
242
  command: "consent",
232
243
  before: { analytics: true },
233
- in: { analytics: false },
244
+ in: analyticsDenied,
234
245
  settings: {},
235
246
  out: [["client.enable"], ["client.disable"]]
236
247
  };
237
248
  var consentGrant = {
238
249
  title: "Consent granted",
239
- description: "A walker consent command with analytics granted calls client.enable on the PostHog client.",
250
+ description: "With consent: { analytics: true } in the destination config, a walker consent command that grants analytics calls client.enable on the PostHog client.",
240
251
  command: "consent",
241
- in: { analytics: true },
252
+ in: analyticsGranted,
242
253
  settings: {},
243
254
  out: [["client.enable"]]
244
255
  };
256
+ var silentRule = {
257
+ public: false,
258
+ description: "A rule with silent: true and no identify or group mapping sends nothing to PostHog.",
259
+ in: getEvent("page view", { timestamp: 1700000105 }),
260
+ mapping: { silent: true },
261
+ out: []
262
+ };
263
+ var groupIdentifyWithoutData = {
264
+ public: false,
265
+ description: "A silent group rule whose key finds no data sends nothing: an unmet mapping, not a failure, so the push returns normally.",
266
+ in: {
267
+ name: "company update",
268
+ entity: "company",
269
+ action: "update",
270
+ timestamp: 1700000106
271
+ },
272
+ mapping: groupIdentifyWithProperties.mapping,
273
+ out: []
274
+ };
275
+
276
+ // src/examples/minimal.ts
277
+ var minimal = {
278
+ settings: { apiKey: "phc_test" },
279
+ secrets: { apiKey: "POSTHOG_API_KEY" }
280
+ };
245
281
  export {
246
282
  env_exports as env,
283
+ minimal,
247
284
  step_exports as step
248
285
  };
package/dist/index.d.mts CHANGED
@@ -11,8 +11,6 @@ interface Settings {
11
11
  identify?: Mapping$1.Value;
12
12
  /** Destination-level group mapping */
13
13
  group?: Mapping$1.Value;
14
- /** Event sections to flatten into capture properties */
15
- include?: string[];
16
14
  host?: string;
17
15
  flushAt?: number;
18
16
  flushInterval?: number;
@@ -25,6 +23,8 @@ interface Settings {
25
23
  fetchRetryDelay?: number;
26
24
  debug?: boolean;
27
25
  disabled?: boolean;
26
+ /** The running send; the next one waits for it. Runtime only. */
27
+ _sending?: Promise<void>;
28
28
  }
29
29
  type InitSettings = Partial<Settings>;
30
30
  interface Mapping {
@@ -40,6 +40,10 @@ interface PostHogClient {
40
40
  capture(props: Parameters<PostHog['capture']>[0]): void;
41
41
  identify(props: Parameters<PostHog['identify']>[0]): void;
42
42
  groupIdentify(props: Parameters<PostHog['groupIdentify']>[0]): void;
43
+ /** Sends the queued calls; rejects when the request failed. */
44
+ flush(): Promise<void>;
45
+ /** The SDK reports a failed send as an `error` event; returns its remover. */
46
+ on?(event: 'error', listener: (error: unknown) => void): () => void;
43
47
  shutdown(): Promise<void> | void;
44
48
  enable(): Promise<void> | void;
45
49
  disable(): Promise<void> | void;
@@ -56,6 +60,7 @@ type Config = {
56
60
  } & DestinationServer.Config<Types>;
57
61
  type InitFn = DestinationServer.InitFn<Types>;
58
62
  type PushFn = DestinationServer.PushFn<Types>;
63
+ type PushBatchFn = Destination$1.PushBatchFn<Types>;
59
64
  type PartialConfig = DestinationServer.PartialConfig<Types>;
60
65
  type PushEvents = DestinationServer.PushEvents<Mapping>;
61
66
  type Rule = Mapping$1.Rule<Mapping>;
@@ -69,6 +74,7 @@ type index_InitSettings = InitSettings;
69
74
  type index_Mapping = Mapping;
70
75
  type index_PartialConfig = PartialConfig;
71
76
  type index_PostHogClient = PostHogClient;
77
+ type index_PushBatchFn = PushBatchFn;
72
78
  type index_PushEvents = PushEvents;
73
79
  type index_PushFn = PushFn;
74
80
  type index_Rule = Rule;
@@ -76,7 +82,7 @@ type index_Rules = Rules;
76
82
  type index_Settings = Settings;
77
83
  type index_Types = Types;
78
84
  declare namespace index {
79
- export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_InitFn as InitFn, index_InitSettings as InitSettings, index_Mapping as Mapping, index_PartialConfig as PartialConfig, index_PostHogClient as PostHogClient, index_PushEvents as PushEvents, index_PushFn as PushFn, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types };
85
+ export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_InitFn as InitFn, index_InitSettings as InitSettings, index_Mapping as Mapping, index_PartialConfig as PartialConfig, index_PostHogClient as PostHogClient, index_PushBatchFn as PushBatchFn, index_PushEvents as PushEvents, index_PushFn as PushFn, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types };
80
86
  }
81
87
 
82
88
  declare const destinationPostHog: Destination;
package/dist/index.d.ts CHANGED
@@ -11,8 +11,6 @@ interface Settings {
11
11
  identify?: Mapping$1.Value;
12
12
  /** Destination-level group mapping */
13
13
  group?: Mapping$1.Value;
14
- /** Event sections to flatten into capture properties */
15
- include?: string[];
16
14
  host?: string;
17
15
  flushAt?: number;
18
16
  flushInterval?: number;
@@ -25,6 +23,8 @@ interface Settings {
25
23
  fetchRetryDelay?: number;
26
24
  debug?: boolean;
27
25
  disabled?: boolean;
26
+ /** The running send; the next one waits for it. Runtime only. */
27
+ _sending?: Promise<void>;
28
28
  }
29
29
  type InitSettings = Partial<Settings>;
30
30
  interface Mapping {
@@ -40,6 +40,10 @@ interface PostHogClient {
40
40
  capture(props: Parameters<PostHog['capture']>[0]): void;
41
41
  identify(props: Parameters<PostHog['identify']>[0]): void;
42
42
  groupIdentify(props: Parameters<PostHog['groupIdentify']>[0]): void;
43
+ /** Sends the queued calls; rejects when the request failed. */
44
+ flush(): Promise<void>;
45
+ /** The SDK reports a failed send as an `error` event; returns its remover. */
46
+ on?(event: 'error', listener: (error: unknown) => void): () => void;
43
47
  shutdown(): Promise<void> | void;
44
48
  enable(): Promise<void> | void;
45
49
  disable(): Promise<void> | void;
@@ -56,6 +60,7 @@ type Config = {
56
60
  } & DestinationServer.Config<Types>;
57
61
  type InitFn = DestinationServer.InitFn<Types>;
58
62
  type PushFn = DestinationServer.PushFn<Types>;
63
+ type PushBatchFn = Destination$1.PushBatchFn<Types>;
59
64
  type PartialConfig = DestinationServer.PartialConfig<Types>;
60
65
  type PushEvents = DestinationServer.PushEvents<Mapping>;
61
66
  type Rule = Mapping$1.Rule<Mapping>;
@@ -69,6 +74,7 @@ type index_InitSettings = InitSettings;
69
74
  type index_Mapping = Mapping;
70
75
  type index_PartialConfig = PartialConfig;
71
76
  type index_PostHogClient = PostHogClient;
77
+ type index_PushBatchFn = PushBatchFn;
72
78
  type index_PushEvents = PushEvents;
73
79
  type index_PushFn = PushFn;
74
80
  type index_Rule = Rule;
@@ -76,7 +82,7 @@ type index_Rules = Rules;
76
82
  type index_Settings = Settings;
77
83
  type index_Types = Types;
78
84
  declare namespace index {
79
- export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_InitFn as InitFn, index_InitSettings as InitSettings, index_Mapping as Mapping, index_PartialConfig as PartialConfig, index_PostHogClient as PostHogClient, index_PushEvents as PushEvents, index_PushFn as PushFn, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types };
85
+ export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_InitFn as InitFn, index_InitSettings as InitSettings, index_Mapping as Mapping, index_PartialConfig as PartialConfig, index_PostHogClient as PostHogClient, index_PushBatchFn as PushBatchFn, index_PushEvents as PushEvents, index_PushFn as PushFn, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types };
80
86
  }
81
87
 
82
88
  declare const destinationPostHog: Destination;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var mod,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,index_exports={};((target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})})(index_exports,{DestinationPostHog:()=>types_exports,default:()=>index_default,destinationPostHog:()=>destinationPostHog}),module.exports=(mod=index_exports,((to,from,except,desc)=>{if(from&&"object"==typeof from||"function"==typeof from)for(let key of __getOwnPropNames(from))__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to})(__defProp({},"__esModule",{value:!0}),mod));var import_posthog_node=require("posthog-node");var import_core=require("@walkeros/core"),types_exports={},destinationPostHog={type:"posthog",config:{},async init({config:partialConfig,env:env,logger:logger}){const config=function(partialConfig={},env,logger){const settings=partialConfig.settings||{},{apiKey:apiKey}=settings;apiKey||logger.throw("Config settings apiKey missing");const options={};settings.host&&(options.host=settings.host),void 0!==settings.flushAt&&(options.flushAt=settings.flushAt),void 0!==settings.flushInterval&&(options.flushInterval=settings.flushInterval),settings.personalApiKey&&(options.personalApiKey=settings.personalApiKey),void 0!==settings.featureFlagsPollingInterval&&(options.featureFlagsPollingInterval=settings.featureFlagsPollingInterval),void 0!==settings.disableGeoip&&(options.disableGeoip=settings.disableGeoip),void 0!==settings.disableCompression&&(options.disableCompression=settings.disableCompression),void 0!==settings.requestTimeout&&(options.requestTimeout=settings.requestTimeout),void 0!==settings.fetchRetryCount&&(options.fetchRetryCount=settings.fetchRetryCount),void 0!==settings.fetchRetryDelay&&(options.fetchRetryDelay=settings.fetchRetryDelay),void 0!==settings.debug&&(options.debug=settings.debug),void 0!==settings.disabled&&(options.disabled=settings.disabled);const client=new(env?.PostHog||import_posthog_node.PostHog)(apiKey,options),settingsConfig={...settings,apiKey:apiKey,client:client};return{...partialConfig,settings:settingsConfig}}(partialConfig,env,logger);return config},push:async(event,context)=>await async function(event,{config:config,rule:rule,data:data,collector:collector}){const settings=config.settings,client=settings.client;if(!client)return;const mappingSettings=rule?.settings||{},identifyMapping=mappingSettings.identify??settings.identify;let distinctId,identifyResolved;if(void 0!==identifyMapping){const resolved=await(0,import_core.getMappingValue)(event,identifyMapping,{collector:collector});(0,import_core.isObject)(resolved)&&(identifyResolved=resolved,(0,import_core.isString)(identifyResolved.distinctId)&&(distinctId=identifyResolved.distinctId))}if(distinctId||(distinctId=((0,import_core.isString)(event.user?.id)?event.user.id:void 0)||((0,import_core.isString)(event.user?.hash)?event.user.hash:void 0)||((0,import_core.isString)(event.user?.session)?event.user.session:void 0)||"anonymous"),identifyResolved){const $set=(0,import_core.isObject)(identifyResolved.$set)?identifyResolved.$set:void 0,$setOnce=(0,import_core.isObject)(identifyResolved.$set_once)?identifyResolved.$set_once:void 0;if($set||$setOnce){const properties={};$set&&(properties.$set=$set),$setOnce&&(properties.$set_once=$setOnce),client.identify({distinctId:distinctId,properties:properties})}}const groupMapping=mappingSettings.group??settings.group;let groups;if(void 0!==groupMapping){const resolved=await(0,import_core.getMappingValue)(event,groupMapping,{collector:collector});if((0,import_core.isObject)(resolved)){const groupResolved=resolved,type=groupResolved.type,key=groupResolved.key,properties=(0,import_core.isObject)(groupResolved.properties)?groupResolved.properties:void 0;(0,import_core.isString)(type)&&((0,import_core.isString)(key)||"number"==typeof key)&&(properties&&client.groupIdentify({groupType:type,groupKey:String(key),properties:properties}),groups={[type]:key})}}if(!0!==rule?.silent){const captureArgs={distinctId:distinctId,event:(0,import_core.isString)(rule?.name)?rule.name:event.name,properties:(0,import_core.isObject)(data)?data:{}};groups&&(captureArgs.groups=groups),client.capture(captureArgs)}}(event,context),async destroy({config:config}){const client=config?.settings?.client;client&&await client.shutdown()},on(type,context){if("consent"!==type||!context?.data)return;const client=(context.config?.settings||{}).client;if(!client)return;const consent=context.data,required=context.config?.consent;if(!required||0===Object.keys(required).length)return;Object.keys(required).every(key=>!0===consent[key])?client.enable():client.disable()}},index_default=destinationPostHog;//# sourceMappingURL=index.js.map
1
+ "use strict";var mod,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,index_exports={};((target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})})(index_exports,{DestinationPostHog:()=>types_exports,default:()=>index_default,destinationPostHog:()=>destinationPostHog}),module.exports=(mod=index_exports,((to,from,except,desc)=>{if(from&&"object"==typeof from||"function"==typeof from)for(let key of __getOwnPropNames(from))__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to})(__defProp({},"__esModule",{value:!0}),mod));var import_core=require("@walkeros/core"),import_server_core=require("@walkeros/server-core"),import_posthog_node=require("posthog-node");var import_crypto=require("crypto"),import_core2=require("@walkeros/core"),import_server_core2=require("@walkeros/server-core");async function call(client,message,send2){let failure;const off=client.on?.("error",error=>{failure=failure??error});try{await send2()}catch(error){failure=failure??error}finally{off?.()}if(void 0!==failure)throw new import_core2.StepError(message,{code:timedOut(failure)?"timeout":"transport",cause:failure})}function timedOut(error){if("object"!=typeof error||null===error)return!1;const name=Reflect.get(error,"name");return"AbortError"===name||"TimeoutError"===name||timedOut(Reflect.get(error,"error")??Reflect.get(error,"cause"))}function skipped(logger,event,call2,key){logger.debug(`PostHog skipped ${call2}: ${key} resolved to nothing`,{event:event.name})}async function queue(message,send2){try{await send2()}catch(error){throw new import_core2.StepError(message,{code:"transport",cause:error})}}function exclusive(settings,task){const running=(settings._sending??Promise.resolve()).then(task);return settings._sending=running.catch(()=>{}),running}function clientOf(settings){const client=settings?.client;if(!settings||!client)throw new import_core2.StepError("PostHog client not initialized",{code:"not-ready"});return{settings:settings,client:client}}async function send(event,rule,data,settings,client,collector,logger){const mappingSettings=rule?.settings||{},identifyMapping=mappingSettings.identify??settings.identify;let distinctId,identifyResolved;if(void 0!==identifyMapping){const resolved=await(0,import_core2.getMappingValue)(event,identifyMapping,{collector:collector});(0,import_core2.isObject)(resolved)?(identifyResolved=resolved,(0,import_core2.isString)(identifyResolved.distinctId)&&(distinctId=identifyResolved.distinctId)):skipped(logger,event,"identify","identify")}if(distinctId||(distinctId=((0,import_core2.isString)(event.user?.id)?event.user.id:void 0)||((0,import_core2.isString)(event.user?.hash)?event.user.hash:void 0)||((0,import_core2.isString)(event.user?.session)?event.user.session:void 0)||"anonymous"),identifyResolved){const $set=(0,import_core2.isObject)(identifyResolved.$set)?identifyResolved.$set:void 0,$setOnce=(0,import_core2.isObject)(identifyResolved.$set_once)?identifyResolved.$set_once:void 0;if($set||$setOnce){const properties={};$set&&(properties.$set=$set),$setOnce&&(properties.$set_once=$setOnce),await queue("PostHog identify failed",()=>client.identify({distinctId:distinctId,properties:properties}))}}const groupMapping=mappingSettings.group??settings.group;let groups;if(void 0!==groupMapping){const resolved=await(0,import_core2.getMappingValue)(event,groupMapping,{collector:collector});if((0,import_core2.isObject)(resolved)){const groupResolved=resolved,type=groupResolved.type,key=groupResolved.key,properties=(0,import_core2.isObject)(groupResolved.properties)?groupResolved.properties:void 0;(0,import_core2.isString)(type)&&((0,import_core2.isString)(key)||"number"==typeof key)?(properties&&await queue("PostHog group identify failed",()=>client.groupIdentify({groupType:type,groupKey:String(key),properties:properties})),groups={[type]:key}):skipped(logger,event,"group","group")}else skipped(logger,event,"group","group")}if(!0!==rule?.silent){const eventName=(0,import_core2.isString)(rule?.name)?rule.name:event.name,properties=(0,import_core2.isObject)(data)?data:{},captureArgs={distinctId:distinctId,event:eventName,properties:properties};groups&&(captureArgs.groups=groups),event.id&&(captureArgs.uuid=function(id){const hex=(0,import_crypto.createHash)("sha256").update(id).digest("hex"),variant=(3&parseInt(hex[16],16)|8).toString(16);return[hex.slice(0,8),hex.slice(8,12),`8${hex.slice(13,16)}`,`${variant}${hex.slice(17,20)}`,hex.slice(20,32)].join("-")}(event.id)),await queue("PostHog capture failed",()=>client.capture(captureArgs))}}var types_exports={},destinationPostHog={type:"posthog",config:{batch:{size:20,wait:1e4}},init:async({config:partialConfig,env:env})=>function(partialConfig={},env){const settings=partialConfig.settings||{},{apiKey:apiKey}=settings;if(!apiKey)throw new import_core.StepError("Config settings apiKey missing",{code:"config"});const budget=(0,import_server_core.retryBudget)(partialConfig.timeout),options={requestTimeout:budget.attempt,fetchRetryCount:budget.retries,fetchRetryDelay:budget.wait};settings.host&&(options.host=settings.host),void 0!==settings.flushAt&&(options.flushAt=settings.flushAt),void 0!==settings.flushInterval&&(options.flushInterval=settings.flushInterval),settings.personalApiKey&&(options.personalApiKey=settings.personalApiKey),void 0!==settings.featureFlagsPollingInterval&&(options.featureFlagsPollingInterval=settings.featureFlagsPollingInterval),void 0!==settings.disableGeoip&&(options.disableGeoip=settings.disableGeoip),void 0!==settings.disableCompression&&(options.disableCompression=settings.disableCompression),void 0!==settings.requestTimeout&&(options.requestTimeout=settings.requestTimeout),void 0!==settings.fetchRetryCount&&(options.fetchRetryCount=settings.fetchRetryCount),void 0!==settings.fetchRetryDelay&&(options.fetchRetryDelay=settings.fetchRetryDelay),void 0!==settings.debug&&(options.debug=settings.debug),void 0!==settings.disabled&&(options.disabled=settings.disabled);const client=new(env?.PostHog||import_posthog_node.PostHog)(apiKey,options),settingsConfig={...settings,apiKey:apiKey,client:client};return{...partialConfig,settings:settingsConfig}}(partialConfig,env),push:async function(event,{config:config,rule:rule,data:data,collector:collector,logger:logger}){const{settings:settings,client:client}=clientOf(config.settings);await exclusive(settings,async()=>{await send(event,rule,data,settings,client,collector,logger),await call(client,"PostHog send failed",()=>client.flush())})},pushBatch:async function(batch,{config:config,collector:collector,logger:logger}){const{settings:settings,client:client}=clientOf(config.settings),failed=[];let sendError;return await exclusive(settings,async()=>{const queued=[];for(const[index,entry]of batch.entries.entries())await send(entry.event,entry.rule,entry.data,settings,client,collector,logger).then(()=>queued.push(index),error=>failed.push({index:index,error:error}));queued.length&&await call(client,"PostHog send failed",()=>client.flush()).catch(error=>{sendError=error;for(const index of queued)failed.push({index:index,error:error})})}),(0,import_server_core2.batchOutcome)(batch.entries.length,failed,sendError)},async destroy({config:config}){const client=config?.settings?.client;client&&await client.shutdown()},on(type,context){if("consent"!==type||!context?.data)return;const client=(context.config?.settings||{}).client;if(!client)return;const consent=context.data,required=context.config?.consent;if(!required||0===Object.keys(required).length)return;Object.keys(required).every(key=>!0===consent[key])?client.enable():client.disable()}},index_default=destinationPostHog;//# 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/types/index.ts"],"sourcesContent":["import type { WalkerOS } from '@walkeros/core';\nimport type { Destination, Env, Settings } from './types';\nimport { getConfig } from './config';\nimport { push } from './push';\n\n// Types\nexport * as DestinationPostHog from './types';\n\nexport const destinationPostHog: Destination = {\n type: 'posthog',\n\n config: {},\n\n async init({ config: partialConfig, env, logger }) {\n const config = getConfig(partialConfig, env as Env | undefined, logger);\n return config;\n },\n\n async push(event, context) {\n return await push(event, context);\n },\n\n async destroy({ config }) {\n const client = (config?.settings as Settings | undefined)?.client;\n if (client) {\n await client.shutdown();\n }\n },\n\n on(type, context) {\n if (type !== 'consent' || !context?.data) return;\n\n const settings = (context.config?.settings || {}) as Settings;\n const client = settings.client;\n if (!client) return;\n\n const consent = context.data as WalkerOS.Consent;\n const required = (context.config as { consent?: WalkerOS.Consent })\n ?.consent;\n if (!required || Object.keys(required).length === 0) return;\n\n const allGranted = Object.keys(required).every(\n (key) => consent[key] === true,\n );\n if (allGranted) {\n client.enable();\n } else {\n client.disable();\n }\n },\n};\n\nexport default destinationPostHog;\n","import type { Config, Env, PartialConfig, Settings } from './types';\nimport type { Logger } from '@walkeros/core';\nimport { PostHog } from 'posthog-node';\n\nexport function getConfig(\n partialConfig: PartialConfig = {},\n env: Env | undefined,\n logger: Logger.Instance,\n): Config {\n const settings = (partialConfig.settings || {}) as Partial<Settings>;\n const { apiKey } = settings;\n\n if (!apiKey) logger.throw('Config settings apiKey missing');\n\n // Extract PostHog SDK options from settings\n const options: Record<string, unknown> = {};\n if (settings.host) options.host = settings.host;\n if (settings.flushAt !== undefined) options.flushAt = settings.flushAt;\n if (settings.flushInterval !== undefined)\n options.flushInterval = settings.flushInterval;\n if (settings.personalApiKey) options.personalApiKey = settings.personalApiKey;\n if (settings.featureFlagsPollingInterval !== undefined)\n options.featureFlagsPollingInterval = settings.featureFlagsPollingInterval;\n if (settings.disableGeoip !== undefined)\n options.disableGeoip = settings.disableGeoip;\n if (settings.disableCompression !== undefined)\n options.disableCompression = settings.disableCompression;\n if (settings.requestTimeout !== undefined)\n options.requestTimeout = settings.requestTimeout;\n if (settings.fetchRetryCount !== undefined)\n options.fetchRetryCount = settings.fetchRetryCount;\n if (settings.fetchRetryDelay !== undefined)\n options.fetchRetryDelay = settings.fetchRetryDelay;\n if (settings.debug !== undefined) options.debug = settings.debug;\n if (settings.disabled !== undefined) options.disabled = settings.disabled;\n\n // Use PostHog from env if available, otherwise use real PostHog\n const PostHogClass = env?.PostHog || PostHog;\n const client = new PostHogClass(apiKey, options);\n\n const settingsConfig: Settings = {\n ...settings,\n apiKey,\n client,\n };\n\n return { ...partialConfig, settings: settingsConfig };\n}\n","import type { PushFn } from './types';\nimport { getMappingValue, isObject, isString } from '@walkeros/core';\n\nexport const push: PushFn = async function (\n event,\n { config, rule, data, collector },\n) {\n const settings = config.settings!;\n const client = settings.client;\n if (!client) return;\n\n const mappingSettings = (rule?.settings || {}) as Record<string, unknown>;\n\n // Resolve distinctId: rule-level identify wins over destination-level\n const identifyMapping = mappingSettings.identify ?? settings.identify;\n let distinctId: string | undefined;\n let identifyResolved: Record<string, unknown> | undefined;\n\n if (identifyMapping !== undefined) {\n const resolved = await getMappingValue(event, identifyMapping, {\n collector,\n });\n if (isObject(resolved)) {\n identifyResolved = resolved as Record<string, unknown>;\n if (isString(identifyResolved.distinctId)) {\n distinctId = identifyResolved.distinctId as string;\n }\n }\n }\n\n // Fallback distinctId from event.user\n if (!distinctId) {\n distinctId =\n (isString(event.user?.id) ? event.user.id : undefined) ||\n (isString(event.user?.hash) ? event.user.hash : undefined) ||\n (isString(event.user?.session) ? event.user.session : undefined) ||\n 'anonymous';\n }\n\n // 1. Identity - if $set or $set_once present, call client.identify()\n if (identifyResolved) {\n const $set = isObject(identifyResolved.$set)\n ? (identifyResolved.$set as Record<string, unknown>)\n : undefined;\n const $setOnce = isObject(identifyResolved.$set_once)\n ? (identifyResolved.$set_once as Record<string, unknown>)\n : undefined;\n\n if ($set || $setOnce) {\n const properties: Record<string, unknown> = {};\n if ($set) properties.$set = $set;\n if ($setOnce) properties.$set_once = $setOnce;\n client.identify({ distinctId, properties });\n }\n }\n\n // 2. Group - resolve group mapping (rule-level wins)\n const groupMapping = mappingSettings.group ?? settings.group;\n let groups: Record<string, string | number> | undefined;\n\n if (groupMapping !== undefined) {\n const resolved = await getMappingValue(event, groupMapping, {\n collector,\n });\n if (isObject(resolved)) {\n const groupResolved = resolved as Record<string, unknown>;\n const type = groupResolved.type;\n const key = groupResolved.key;\n const properties = isObject(groupResolved.properties)\n ? (groupResolved.properties as Record<string, unknown>)\n : undefined;\n\n if (isString(type) && (isString(key) || typeof key === 'number')) {\n // If properties present, call groupIdentify\n if (properties) {\n client.groupIdentify({\n groupType: type,\n groupKey: String(key),\n properties,\n });\n }\n // Build groups object for capture\n groups = { [type]: key as string | number };\n }\n }\n }\n\n // 3. Capture - unless rule opts out via silent\n if (rule?.silent !== true) {\n const eventName = isString(rule?.name) ? rule.name : event.name;\n const properties = isObject(data) ? (data as Record<string, unknown>) : {};\n\n const captureArgs: Record<string, unknown> = {\n distinctId,\n event: eventName,\n properties,\n };\n if (groups) captureArgs.groups = groups;\n\n client.capture(captureArgs as Parameters<typeof client.capture>[0]);\n }\n};\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationServer } from '@walkeros/server-core';\nimport type { PostHog } from 'posthog-node';\n\nexport interface Settings {\n /** PostHog project API key (phc_...) */\n apiKey: string;\n /** PostHog client instance, populated by init */\n client?: PostHogClient;\n /** Destination-level identity mapping */\n identify?: WalkerOSMapping.Value;\n /** Destination-level group mapping */\n group?: WalkerOSMapping.Value;\n /** Event sections to flatten into capture properties */\n include?: string[];\n // PostHog SDK passthrough options\n host?: string;\n flushAt?: number;\n flushInterval?: number;\n personalApiKey?: string;\n featureFlagsPollingInterval?: number;\n disableGeoip?: boolean;\n disableCompression?: boolean;\n requestTimeout?: number;\n fetchRetryCount?: number;\n fetchRetryDelay?: number;\n debug?: boolean;\n disabled?: boolean;\n}\n\nexport type InitSettings = Partial<Settings>;\n\nexport interface Mapping {\n identify?: WalkerOSMapping.Value;\n group?: WalkerOSMapping.Value;\n}\n\n/**\n * The part of a PostHog client this destination calls. `PostHog` from\n * `posthog-node` satisfies it, and so does an injected mock (tests, simulate)\n * without a cast.\n */\nexport interface PostHogClient {\n capture(props: Parameters<PostHog['capture']>[0]): void;\n identify(props: Parameters<PostHog['identify']>[0]): void;\n groupIdentify(props: Parameters<PostHog['groupIdentify']>[0]): void;\n shutdown(): Promise<void> | void;\n enable(): Promise<void> | void;\n disable(): Promise<void> | void;\n}\n\nexport interface Env extends DestinationServer.Env {\n PostHog?: new (\n apiKey: string,\n options?: ConstructorParameters<typeof PostHog>[1],\n ) => PostHogClient;\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>;\n\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\n\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,0BAAwB;AAEjB,SAAS,UACd,gBAA+B,CAAC,GAChC,KACA,QACQ;AACR,QAAM,WAAY,cAAc,YAAY,CAAC;AAC7C,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI,CAAC,OAAQ,QAAO,MAAM,gCAAgC;AAG1D,QAAM,UAAmC,CAAC;AAC1C,MAAI,SAAS,KAAM,SAAQ,OAAO,SAAS;AAC3C,MAAI,SAAS,YAAY,OAAW,SAAQ,UAAU,SAAS;AAC/D,MAAI,SAAS,kBAAkB;AAC7B,YAAQ,gBAAgB,SAAS;AACnC,MAAI,SAAS,eAAgB,SAAQ,iBAAiB,SAAS;AAC/D,MAAI,SAAS,gCAAgC;AAC3C,YAAQ,8BAA8B,SAAS;AACjD,MAAI,SAAS,iBAAiB;AAC5B,YAAQ,eAAe,SAAS;AAClC,MAAI,SAAS,uBAAuB;AAClC,YAAQ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A,EAEN,QAAQ,CAAC;AAAA,EAET,MAAM,KAAK,EAAE,QAAQ,eAAe,KAAK,OAAO,GAAG;AACjD,UAAM,SAAS,UAAU,eAAe,KAAwB,MAAM;AACtE,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,KAAK,OAAO,SAAS;AACzB,WAAO,MAAM,KAAK,OAAO,OAAO;AAAA,EAClC;AAAA,EAEA,MAAM,QAAQ,EAAE,OAAO,GAAG;AACxB,UAAM,SAAU,QAAQ,UAAmC;AAC3D,QAAI,QAAQ;AACV,YAAM,OAAO,SAAS;AAAA,IACxB;AAAA,EACF;AAAA,EAEA,GAAG,MAAM,SAAS;AAChB,QAAI,SAAS,aAAa,CAAC,SAAS,KAAM;AAE1C,UAAM,WAAY,QAAQ,QAAQ,YAAY,CAAC;AAC/C,UAAM,SAAS,SAAS;AACxB,QAAI,CAAC,OAAQ;AAEb,UAAM,UAAU,QAAQ;AACxB,UAAM,WAAY,QAAQ,QACtB;AACJ,QAAI,CAAC,YAAY,OAAO,KAAK,QAAQ,EAAE,WAAW,EAAG;AAErD,UAAM,aAAa,OAAO,KAAK,QAAQ,EAAE;AAAA,MACvC,CAAC,QAAQ,QAAQ,GAAG,MAAM;AAAA,IAC5B;AACA,QAAI,YAAY;AACd,aAAO,OAAO;AAAA,IAChB,OAAO;AACL,aAAO,QAAQ;AAAA,IACjB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/config.ts","../src/push.ts","../src/types/index.ts"],"sourcesContent":["import type { WalkerOS } from '@walkeros/core';\nimport type { Destination, Env, Settings } from './types';\nimport { getConfig } from './config';\nimport { push, pushBatch } from './push';\n\n// Types\nexport * as DestinationPostHog from './types';\n\nexport const destinationPostHog: Destination = {\n type: 'posthog',\n\n // Batched by default, at the SDK's own former defaults (20 events, 10 s).\n config: { batch: { size: 20, wait: 10_000 } },\n\n async init({ config: partialConfig, env }) {\n return getConfig(partialConfig, env);\n },\n\n push,\n\n pushBatch,\n\n async destroy({ config }) {\n const client = config?.settings?.client;\n if (client) {\n await client.shutdown();\n }\n },\n\n on(type, context) {\n if (type !== 'consent' || !context?.data) return;\n\n const settings = (context.config?.settings || {}) as Settings;\n const client = settings.client;\n if (!client) return;\n\n const consent = context.data as WalkerOS.Consent;\n const required = (context.config as { consent?: WalkerOS.Consent })\n ?.consent;\n if (!required || Object.keys(required).length === 0) return;\n\n const allGranted = Object.keys(required).every(\n (key) => consent[key] === true,\n );\n if (allGranted) {\n client.enable();\n } else {\n client.disable();\n }\n },\n};\n\nexport default destinationPostHog;\n","import type { Config, Env, PartialConfig, Settings } from './types';\nimport { StepError } from '@walkeros/core';\nimport { retryBudget } from '@walkeros/server-core';\nimport { PostHog } from 'posthog-node';\n\nexport function getConfig(\n partialConfig: PartialConfig = {},\n env: Env | undefined,\n): Config {\n const settings: Partial<Settings> = partialConfig.settings || {};\n const { apiKey } = settings;\n\n if (!apiKey)\n throw new StepError('Config settings apiKey missing', { code: 'config' });\n\n // The SDK's own retry ends within config.timeout: a quarter of it per\n // request, two retries a tenth of it apart. A value set in the settings\n // wins.\n const budget = retryBudget(partialConfig.timeout);\n const options: Record<string, unknown> = {\n requestTimeout: budget.attempt,\n fetchRetryCount: budget.retries,\n fetchRetryDelay: budget.wait,\n };\n\n // Extract PostHog SDK options from settings\n if (settings.host) options.host = settings.host;\n if (settings.flushAt !== undefined) options.flushAt = settings.flushAt;\n if (settings.flushInterval !== undefined)\n options.flushInterval = settings.flushInterval;\n if (settings.personalApiKey) options.personalApiKey = settings.personalApiKey;\n if (settings.featureFlagsPollingInterval !== undefined)\n options.featureFlagsPollingInterval = settings.featureFlagsPollingInterval;\n if (settings.disableGeoip !== undefined)\n options.disableGeoip = settings.disableGeoip;\n if (settings.disableCompression !== undefined)\n options.disableCompression = settings.disableCompression;\n if (settings.requestTimeout !== undefined)\n options.requestTimeout = settings.requestTimeout;\n if (settings.fetchRetryCount !== undefined)\n options.fetchRetryCount = settings.fetchRetryCount;\n if (settings.fetchRetryDelay !== undefined)\n options.fetchRetryDelay = settings.fetchRetryDelay;\n if (settings.debug !== undefined) options.debug = settings.debug;\n if (settings.disabled !== undefined) options.disabled = settings.disabled;\n\n // Use PostHog from env if available, otherwise use real PostHog\n const PostHogClass = env?.PostHog || PostHog;\n const client = new PostHogClass(apiKey, options);\n\n const settingsConfig: Settings = {\n ...settings,\n apiKey,\n client,\n };\n\n return { ...partialConfig, settings: settingsConfig };\n}\n","import type { Collector, Destination, Logger, WalkerOS } from '@walkeros/core';\nimport type {\n PostHogClient,\n PushBatchFn,\n PushFn,\n Rule,\n Settings,\n} from './types';\nimport { createHash } from 'crypto';\nimport { getMappingValue, isObject, isString, StepError } from '@walkeros/core';\nimport { batchOutcome } from '@walkeros/server-core';\n\n/**\n * Run one flush to its end. The SDK reports a failed send as an `error`\n * event and a rejected flush; the call listens for the event while it runs.\n * Sends never overlap (`exclusive`), so the event belongs to this flush.\n */\nasync function call(\n client: PostHogClient,\n message: string,\n send: () => unknown,\n): Promise<void> {\n let failure: unknown;\n const off = client.on?.('error', (error) => {\n failure = failure ?? error;\n });\n try {\n await send();\n } catch (error) {\n failure = failure ?? error;\n } finally {\n off?.();\n }\n if (failure !== undefined)\n throw new StepError(message, {\n code: timedOut(failure) ? 'timeout' : 'transport',\n cause: failure,\n });\n}\n\n/**\n * Whether the SDK's last request timed out: it aborts a request after\n * `requestTimeout` and reports a network error carrying the abort.\n */\nfunction timedOut(error: unknown): boolean {\n if (typeof error !== 'object' || error === null) return false;\n const name: unknown = Reflect.get(error, 'name');\n if (name === 'AbortError' || name === 'TimeoutError') return true;\n return timedOut(Reflect.get(error, 'error') ?? Reflect.get(error, 'cause'));\n}\n\n/**\n * The uuid PostHog deduplicates a captured event by, derived from the event\n * id: the same event resent gets the same uuid. PostHog takes only a UUID,\n * so the id is hashed into one (RFC 9562 version 8, name based).\n */\nfunction uuidOf(id: string): string {\n const hex = createHash('sha256').update(id).digest('hex');\n const variant = ((parseInt(hex[16], 16) & 0x3) | 0x8).toString(16);\n return [\n hex.slice(0, 8),\n hex.slice(8, 12),\n `8${hex.slice(13, 16)}`,\n `${variant}${hex.slice(17, 20)}`,\n hex.slice(20, 32),\n ].join('-');\n}\n\n/**\n * A configured mapping that resolved to nothing skips its call: a declared\n * skip, said once at DEBUG with the event and the mapping key, never the\n * value, so a wrong mapping path does not look like an event without data.\n */\nfunction skipped(\n logger: Logger.Instance,\n event: WalkerOS.Event,\n call: string,\n key: string,\n): void {\n logger.debug(`PostHog skipped ${call}: ${key} resolved to nothing`, {\n event: event.name,\n });\n}\n\n/** Run one queueing call; an injected client may answer with a promise. */\nasync function queue(message: string, send: () => unknown): Promise<void> {\n try {\n await send();\n } catch (error) {\n throw new StepError(message, { code: 'transport', cause: error });\n }\n}\n\n/**\n * One send at a time per client: its calls queued, then one flush. A flush\n * sends the whole queue, so a send that overlapped another could be carried,\n * and failed, by the other's request without hearing of it.\n */\nfunction exclusive(\n settings: Partial<Settings>,\n task: () => Promise<void>,\n): Promise<void> {\n const running = (settings._sending ?? Promise.resolve()).then(task);\n settings._sending = running.catch(() => undefined);\n return running;\n}\n\n/** The settings and client init resolved, or a StepError. */\nfunction clientOf(settings: Partial<Settings> | undefined): {\n settings: Partial<Settings>;\n client: PostHogClient;\n} {\n const client = settings?.client;\n if (!settings || !client)\n throw new StepError('PostHog client not initialized', {\n code: 'not-ready',\n });\n return { settings, client };\n}\n\n/** One event: its calls queued and sent by one flush. */\nexport const push: PushFn = async function (\n event,\n { config, rule, data, collector, logger },\n) {\n const { settings, client } = clientOf(config.settings);\n await exclusive(settings, async () => {\n await send(event, rule, data, settings, client, collector, logger);\n await call(client, 'PostHog send failed', () => client.flush());\n });\n};\n\n/**\n * A flushed `config.batch` batch: every entry's calls queued, then one flush\n * sends them. An entry whose calls could not be queued fails alone; a failed\n * flush fails the batch, since PostHog answers a request as a whole.\n */\nexport const pushBatch: PushBatchFn = async function (\n batch,\n { config, collector, logger },\n) {\n const { settings, client } = clientOf(config.settings);\n const failed: Destination.BatchFailure[] = [];\n let sendError: unknown;\n\n await exclusive(settings, async () => {\n const queued: number[] = [];\n for (const [index, entry] of batch.entries.entries())\n await send(\n entry.event,\n entry.rule,\n entry.data,\n settings,\n client,\n collector,\n logger,\n ).then(\n () => queued.push(index),\n (error: unknown) => failed.push({ index, error }),\n );\n\n // One request carries every queued entry: a failed flush fails them all.\n if (queued.length)\n await call(client, 'PostHog send failed', () => client.flush()).catch(\n (error: unknown) => {\n sendError = error;\n for (const index of queued) failed.push({ index, error });\n },\n );\n });\n\n return batchOutcome(batch.entries.length, failed, sendError);\n};\n\n/** The calls of one event (identify, group identify, capture). */\nasync function send(\n event: WalkerOS.Event,\n rule: Rule | undefined,\n data: Destination.Data,\n settings: Partial<Settings>,\n client: PostHogClient,\n collector: Collector.Instance,\n logger: Logger.Instance,\n): Promise<void> {\n const mappingSettings = (rule?.settings || {}) as Record<string, unknown>;\n\n // Resolve distinctId: rule-level identify wins over destination-level\n const identifyMapping = mappingSettings.identify ?? settings.identify;\n let distinctId: string | undefined;\n let identifyResolved: Record<string, unknown> | undefined;\n\n if (identifyMapping !== undefined) {\n const resolved = await getMappingValue(event, identifyMapping, {\n collector,\n });\n if (isObject(resolved)) {\n identifyResolved = resolved as Record<string, unknown>;\n if (isString(identifyResolved.distinctId)) {\n distinctId = identifyResolved.distinctId as string;\n }\n } else skipped(logger, event, 'identify', 'identify');\n }\n\n // Fallback distinctId from event.user\n if (!distinctId) {\n distinctId =\n (isString(event.user?.id) ? event.user.id : undefined) ||\n (isString(event.user?.hash) ? event.user.hash : undefined) ||\n (isString(event.user?.session) ? event.user.session : undefined) ||\n 'anonymous';\n }\n\n // 1. Identity - if $set or $set_once present, call client.identify()\n if (identifyResolved) {\n const $set = isObject(identifyResolved.$set)\n ? (identifyResolved.$set as Record<string, unknown>)\n : undefined;\n const $setOnce = isObject(identifyResolved.$set_once)\n ? (identifyResolved.$set_once as Record<string, unknown>)\n : undefined;\n\n if ($set || $setOnce) {\n const properties: Record<string, unknown> = {};\n if ($set) properties.$set = $set;\n if ($setOnce) properties.$set_once = $setOnce;\n await queue('PostHog identify failed', () =>\n client.identify({ distinctId, properties }),\n );\n }\n }\n\n // 2. Group - resolve group mapping (rule-level wins)\n const groupMapping = mappingSettings.group ?? settings.group;\n let groups: Record<string, string | number> | undefined;\n\n if (groupMapping !== undefined) {\n const resolved = await getMappingValue(event, groupMapping, {\n collector,\n });\n if (isObject(resolved)) {\n const groupResolved = resolved as Record<string, unknown>;\n const type = groupResolved.type;\n const key = groupResolved.key;\n const properties = isObject(groupResolved.properties)\n ? (groupResolved.properties as Record<string, unknown>)\n : undefined;\n\n if (isString(type) && (isString(key) || typeof key === 'number')) {\n // If properties present, call groupIdentify\n // No immediate variant: queued, then flushed in this push.\n if (properties)\n await queue('PostHog group identify failed', () =>\n client.groupIdentify({\n groupType: type,\n groupKey: String(key),\n properties,\n }),\n );\n // Build groups object for capture\n groups = { [type]: key as string | number };\n } else skipped(logger, event, 'group', 'group');\n } else skipped(logger, event, 'group', 'group');\n }\n\n // 3. Capture - unless rule opts out via silent\n if (rule?.silent !== true) {\n const eventName = isString(rule?.name) ? rule.name : event.name;\n const properties = isObject(data) ? (data as Record<string, unknown>) : {};\n\n const captureArgs: Parameters<PostHogClient['capture']>[0] = {\n distinctId,\n event: eventName,\n properties,\n };\n if (groups) captureArgs.groups = groups;\n if (event.id) captureArgs.uuid = uuidOf(event.id);\n\n await queue('PostHog capture failed', () => client.capture(captureArgs));\n }\n}\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationServer } from '@walkeros/server-core';\nimport type { PostHog } from 'posthog-node';\n\nexport interface Settings {\n /** PostHog project API key (phc_...) */\n apiKey: string;\n /** PostHog client instance, populated by init */\n client?: PostHogClient;\n /** Destination-level identity mapping */\n identify?: WalkerOSMapping.Value;\n /** Destination-level group mapping */\n group?: WalkerOSMapping.Value;\n // PostHog SDK passthrough options\n host?: string;\n flushAt?: number;\n flushInterval?: number;\n personalApiKey?: string;\n featureFlagsPollingInterval?: number;\n disableGeoip?: boolean;\n disableCompression?: boolean;\n requestTimeout?: number;\n fetchRetryCount?: number;\n fetchRetryDelay?: number;\n debug?: boolean;\n disabled?: boolean;\n /** The running send; the next one waits for it. Runtime only. */\n _sending?: Promise<void>;\n}\n\nexport type InitSettings = Partial<Settings>;\n\nexport interface Mapping {\n identify?: WalkerOSMapping.Value;\n group?: WalkerOSMapping.Value;\n}\n\n/**\n * The part of a PostHog client this destination calls. `PostHog` from\n * `posthog-node` satisfies it, and so does an injected mock (tests, simulate)\n * without a cast.\n */\nexport interface PostHogClient {\n capture(props: Parameters<PostHog['capture']>[0]): void;\n identify(props: Parameters<PostHog['identify']>[0]): void;\n groupIdentify(props: Parameters<PostHog['groupIdentify']>[0]): void;\n /** Sends the queued calls; rejects when the request failed. */\n flush(): Promise<void>;\n /** The SDK reports a failed send as an `error` event; returns its remover. */\n on?(event: 'error', listener: (error: unknown) => void): () => void;\n shutdown(): Promise<void> | void;\n enable(): Promise<void> | void;\n disable(): Promise<void> | void;\n}\n\nexport interface Env extends DestinationServer.Env {\n PostHog?: new (\n apiKey: string,\n options?: ConstructorParameters<typeof PostHog>[1],\n ) => PostHogClient;\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 PushBatchFn = CoreDestination.PushBatchFn<Types>;\n\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\n\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n"],"mappings":";;;;;;;;;;;;;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