posthog-node 5.74.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/MIGRATION.md +556 -0
  2. package/README.md +3 -1
  3. package/dist/ai-capture/routing.d.ts +0 -3
  4. package/dist/ai-capture/routing.d.ts.map +1 -1
  5. package/dist/ai-capture/routing.js +2 -14
  6. package/dist/ai-capture/routing.mjs +1 -4
  7. package/dist/capture-lane/lane.d.ts +109 -0
  8. package/dist/capture-lane/lane.d.ts.map +1 -0
  9. package/dist/capture-lane/lane.js +308 -0
  10. package/dist/capture-lane/lane.mjs +270 -0
  11. package/dist/capture-lane/limits.d.ts +7 -0
  12. package/dist/capture-lane/limits.d.ts.map +1 -0
  13. package/dist/{capture-v1/config.js → capture-lane/limits.js} +13 -11
  14. package/dist/capture-lane/limits.mjs +4 -0
  15. package/dist/capture-lane/settings.d.ts +30 -0
  16. package/dist/capture-lane/settings.d.ts.map +1 -0
  17. package/dist/capture-lane/settings.js +100 -0
  18. package/dist/capture-lane/settings.mjs +47 -0
  19. package/dist/capture-v1/compression.d.ts +18 -0
  20. package/dist/capture-v1/compression.d.ts.map +1 -0
  21. package/dist/capture-v1/compression.js +70 -0
  22. package/dist/capture-v1/compression.mjs +26 -0
  23. package/dist/capture-v1/errors.d.ts +23 -7
  24. package/dist/capture-v1/errors.d.ts.map +1 -1
  25. package/dist/capture-v1/errors.js +37 -8
  26. package/dist/capture-v1/errors.mjs +29 -6
  27. package/dist/capture-v1/sender.d.ts +63 -23
  28. package/dist/capture-v1/sender.d.ts.map +1 -1
  29. package/dist/capture-v1/sender.js +281 -74
  30. package/dist/capture-v1/sender.mjs +275 -77
  31. package/dist/capture-v1/serialize.d.ts +28 -0
  32. package/dist/capture-v1/serialize.d.ts.map +1 -0
  33. package/dist/capture-v1/serialize.js +82 -0
  34. package/dist/capture-v1/serialize.mjs +38 -0
  35. package/dist/capture-v1/transform.d.ts +10 -25
  36. package/dist/capture-v1/transform.d.ts.map +1 -1
  37. package/dist/capture-v1/transform.js +33 -64
  38. package/dist/capture-v1/transform.mjs +28 -53
  39. package/dist/capture-v1/types.d.ts +16 -14
  40. package/dist/capture-v1/types.d.ts.map +1 -1
  41. package/dist/capture-v1/types.js +27 -1
  42. package/dist/capture-v1/types.mjs +3 -1
  43. package/dist/capture-v1/uuid.d.ts +9 -0
  44. package/dist/capture-v1/uuid.d.ts.map +1 -0
  45. package/dist/capture-v1/uuid.js +75 -0
  46. package/dist/capture-v1/uuid.mjs +34 -0
  47. package/dist/client.d.ts +201 -94
  48. package/dist/client.d.ts.map +1 -1
  49. package/dist/client.js +456 -228
  50. package/dist/client.mjs +455 -227
  51. package/dist/compression.node.d.ts +13 -0
  52. package/dist/compression.node.d.ts.map +1 -0
  53. package/dist/{capture-v1/routing.js → compression.node.js} +23 -16
  54. package/dist/compression.node.mjs +18 -0
  55. package/dist/entrypoints/index.node.d.ts +2 -0
  56. package/dist/entrypoints/index.node.d.ts.map +1 -1
  57. package/dist/entrypoints/index.node.js +11 -4
  58. package/dist/entrypoints/index.node.mjs +4 -0
  59. package/dist/event-defaults.d.ts +46 -0
  60. package/dist/event-defaults.d.ts.map +1 -0
  61. package/dist/event-defaults.js +141 -0
  62. package/dist/event-defaults.mjs +79 -0
  63. package/dist/exports.d.ts +3 -0
  64. package/dist/exports.d.ts.map +1 -1
  65. package/dist/exports.js +22 -11
  66. package/dist/exports.mjs +1 -0
  67. package/dist/extensions/context/context.d.ts +0 -1
  68. package/dist/extensions/context/context.d.ts.map +1 -1
  69. package/dist/extensions/context/context.js +4 -3
  70. package/dist/extensions/context/context.mjs +4 -3
  71. package/dist/extensions/context/event-context.d.ts.map +1 -1
  72. package/dist/extensions/context/event-context.js +3 -0
  73. package/dist/extensions/context/event-context.mjs +3 -0
  74. package/dist/extensions/context/types.d.ts +9 -1
  75. package/dist/extensions/context/types.d.ts.map +1 -1
  76. package/dist/extensions/error-tracking/index.d.ts +1 -1
  77. package/dist/extensions/error-tracking/index.d.ts.map +1 -1
  78. package/dist/extensions/error-tracking/index.js +71 -7
  79. package/dist/extensions/error-tracking/index.mjs +75 -11
  80. package/dist/extensions/express.d.ts +8 -0
  81. package/dist/extensions/express.d.ts.map +1 -1
  82. package/dist/extensions/express.js +3 -3
  83. package/dist/extensions/express.mjs +4 -4
  84. package/dist/extensions/fetch-request.d.ts.map +1 -1
  85. package/dist/extensions/fetch-request.js +2 -2
  86. package/dist/extensions/fetch-request.mjs +3 -3
  87. package/dist/extensions/nestjs.d.ts.map +1 -1
  88. package/dist/extensions/nestjs.js +7 -4
  89. package/dist/extensions/nestjs.mjs +8 -5
  90. package/dist/extensions/tracing-headers.d.ts +7 -0
  91. package/dist/extensions/tracing-headers.d.ts.map +1 -1
  92. package/dist/extensions/tracing-headers.js +11 -1
  93. package/dist/extensions/tracing-headers.mjs +9 -2
  94. package/dist/flag-events.d.ts +1 -1
  95. package/dist/flag-events.d.ts.map +1 -1
  96. package/dist/flag-events.js +2 -2
  97. package/dist/flag-events.mjs +2 -2
  98. package/dist/types.d.ts +191 -27
  99. package/dist/types.d.ts.map +1 -1
  100. package/dist/version.d.ts +1 -1
  101. package/dist/version.d.ts.map +1 -1
  102. package/dist/version.js +1 -1
  103. package/dist/version.mjs +1 -1
  104. package/package.json +5 -4
  105. package/src/ai-capture/routing.ts +0 -6
  106. package/src/capture-lane/lane.ts +414 -0
  107. package/src/capture-lane/limits.ts +8 -0
  108. package/src/capture-lane/settings.ts +119 -0
  109. package/src/capture-v1/compression.ts +50 -0
  110. package/src/capture-v1/errors.ts +50 -11
  111. package/src/capture-v1/sender.ts +405 -111
  112. package/src/capture-v1/serialize.ts +77 -0
  113. package/src/capture-v1/transform.ts +59 -92
  114. package/src/capture-v1/types.ts +19 -15
  115. package/src/capture-v1/uuid.ts +53 -0
  116. package/src/client.ts +845 -422
  117. package/src/compression.node.ts +30 -0
  118. package/src/entrypoints/index.node.ts +6 -0
  119. package/src/event-defaults.ts +177 -0
  120. package/src/exports.ts +3 -0
  121. package/src/extensions/context/context.ts +4 -4
  122. package/src/extensions/context/event-context.ts +3 -1
  123. package/src/extensions/context/types.ts +10 -1
  124. package/src/extensions/error-tracking/index.ts +51 -7
  125. package/src/extensions/express.ts +12 -3
  126. package/src/extensions/fetch-request.ts +7 -3
  127. package/src/extensions/nestjs.ts +9 -5
  128. package/src/extensions/tracing-headers.ts +26 -7
  129. package/src/flag-events.ts +5 -2
  130. package/src/types.ts +211 -44
  131. package/src/version.ts +1 -1
  132. package/dist/ai-capture/batching.d.ts +0 -11
  133. package/dist/ai-capture/batching.d.ts.map +0 -1
  134. package/dist/ai-capture/batching.js +0 -77
  135. package/dist/ai-capture/batching.mjs +0 -36
  136. package/dist/capture-v1/config.d.ts +0 -11
  137. package/dist/capture-v1/config.d.ts.map +0 -1
  138. package/dist/capture-v1/config.mjs +0 -8
  139. package/dist/capture-v1/routing.d.ts +0 -21
  140. package/dist/capture-v1/routing.d.ts.map +0 -1
  141. package/dist/capture-v1/routing.mjs +0 -7
  142. package/src/ai-capture/batching.ts +0 -47
  143. package/src/capture-v1/config.ts +0 -18
  144. package/src/capture-v1/routing.ts +0 -28
@@ -1,34 +1,19 @@
1
- import type { JsonType, PostHogEventProperties } from '@posthog/core';
2
- import type { V1Batch, V1Event } from './types';
1
+ import { type JsonType, type PostHogEventProperties } from '@posthog/core';
2
+ import type { V1Event } from './types';
3
3
  /**
4
- * Coerce a value to a boolean the way the capture server does, or return
5
- * `undefined` if it cannot be coerced (the option is then omitted so the server
6
- * falls back to its default). Accepts native booleans, the strings
7
- * `"true"`/`"1"`/`"false"`/`"0"` (trimmed, case-insensitive), and any number
8
- * (nonzero -> true).
4
+ * A copy of the caller's per-event options, or undefined when there are none. Any value that
5
+ * is not an object is reported and ignored, so the event is still sent.
9
6
  */
10
- export declare function coerceBool(value: JsonType): boolean | undefined;
11
- /**
12
- * Accept only a native string, else return `undefined` (the option is then
13
- * omitted). The backend's `product_tour_id` is `Option<String>`, so numbers,
14
- * booleans, objects, and arrays are dropped rather than coerced — matching
15
- * posthog-go, posthog-rs, and posthog-python exactly.
16
- */
17
- export declare function coerceString(value: JsonType): string | undefined;
7
+ export declare function readEventOptions(value: unknown): Record<string, JsonType> | undefined;
18
8
  /**
19
9
  * Transform one already-normalized queued message into a Capture V1 wire event.
20
10
  *
21
11
  * The input message is never mutated (events may be retried or handed to
22
- * callbacks): a fresh `properties` map is built. Sentinel properties are lifted
23
- * out of `properties` (deleting the copy) into the typed `options` object and
24
- * the top-level `session_id`/`window_id` fields; `$lib`/`$lib_version` are
25
- * stripped (the server injects them from `PostHog-Sdk-Info`); top-level
26
- * `$set`/`$set_once` are relocated into `properties`.
12
+ * callbacks): fresh `options` and `properties` maps are built. Option values are
13
+ * sent unchanged; capture reads them. Each legacy option property is removed from
14
+ * `properties` and fills its option when the caller left that option missing or
15
+ * `null`. `$session_id`/`$window_id` move to the top-level `session_id`/`window_id`
16
+ * fields; top-level `$set`/`$set_once` are relocated into `properties`.
27
17
  */
28
18
  export declare function buildV1Event(message: PostHogEventProperties): V1Event;
29
- /** Build a Capture V1 batch envelope from already-normalized queued messages. */
30
- export declare function buildV1Batch(messages: PostHogEventProperties[], { createdAt, historicalMigration }: {
31
- createdAt: string;
32
- historicalMigration?: boolean;
33
- }): V1Batch;
34
19
  //# sourceMappingURL=transform.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/capture-v1/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAErE,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAA;AAE/D;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,CAiB/D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAEhE;AA6DD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CA0CrE;AAED,iFAAiF;AACjF,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,sBAAsB,EAAE,EAClC,EAAE,SAAS,EAAE,mBAAmB,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAAE,GACvF,OAAO,CAST"}
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/capture-v1/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,QAAQ,EAAE,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAE1G,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAgBtC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,SAAS,CAYrF;AA6CD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CA4CrE"}
@@ -27,40 +27,11 @@ var __webpack_require__ = {};
27
27
  })();
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
- function coerceBool(value) {
31
- if ('boolean' == typeof value) return value;
32
- if ('number' == typeof value) return 0 !== value;
33
- if ('string' == typeof value) {
34
- const normalized = value.trim().toLowerCase();
35
- if ('true' === normalized || '1' === normalized) return true;
36
- if ('false' === normalized || '0' === normalized) return false;
37
- }
38
- }
39
- function coerceString(value) {
40
- return 'string' == typeof value ? value : void 0;
41
- }
42
- const OPTION_SENTINELS = [
43
- {
44
- property: '$cookieless_mode',
45
- optionKey: 'cookieless_mode',
46
- coerce: coerceBool
47
- },
48
- {
49
- property: '$ignore_sent_at',
50
- optionKey: 'disable_skew_correction',
51
- coerce: coerceBool
52
- },
53
- {
54
- property: '$process_person_profile',
55
- optionKey: 'process_person_profile',
56
- coerce: coerceBool
57
- },
58
- {
59
- property: '$product_tour_id',
60
- optionKey: 'product_tour_id',
61
- coerce: coerceString
62
- }
63
- ];
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ buildV1Event: ()=>buildV1Event,
32
+ readEventOptions: ()=>readEventOptions
33
+ });
34
+ const core_namespaceObject = require("@posthog/core");
64
35
  const TOPLEVEL_SENTINELS = [
65
36
  {
66
37
  property: '$session_id',
@@ -74,15 +45,29 @@ const TOPLEVEL_SENTINELS = [
74
45
  function isRecord(value) {
75
46
  return 'object' == typeof value && null !== value && !Array.isArray(value);
76
47
  }
48
+ function jsonTypeName(value) {
49
+ return Array.isArray(value) ? 'array' : typeof value;
50
+ }
51
+ function readEventOptions(value) {
52
+ if (null == value) return;
53
+ if (isRecord(value)) return {
54
+ ...value
55
+ };
56
+ console.error(`[PostHog] options must be an object, got ${jsonTypeName(value)}; sending the event without its options`);
57
+ }
58
+ function replaceUnparseableTimestamp() {
59
+ console.warn('[PostHog] replacing an unparseable event timestamp with the current time');
60
+ return new Date().toISOString();
61
+ }
77
62
  function toRfc3339(timestamp) {
78
63
  if ('string' == typeof timestamp) {
79
64
  const asDate = new Date(timestamp);
80
- if (Number.isNaN(asDate.getTime())) return new Date().toISOString();
65
+ if (Number.isNaN(asDate.getTime())) return replaceUnparseableTimestamp();
81
66
  const normalized = asDate.toISOString();
82
67
  const fractionalSeconds = timestamp.match(/\.(\d+)(?:Z|[+-]\d{2}:?\d{2})?$/i)?.[1];
83
68
  return fractionalSeconds && fractionalSeconds.length > 3 ? normalized.replace(/\.\d{3}Z$/, `.${fractionalSeconds}Z`) : normalized;
84
69
  }
85
- if (timestamp instanceof Date) return Number.isNaN(timestamp.getTime()) ? new Date().toISOString() : timestamp.toISOString();
70
+ if (timestamp instanceof Date) return Number.isNaN(timestamp.getTime()) ? replaceUnparseableTimestamp() : timestamp.toISOString();
86
71
  const asDate = null == timestamp ? new Date() : new Date(timestamp);
87
72
  return Number.isNaN(asDate.getTime()) ? new Date().toISOString() : asDate.toISOString();
88
73
  }
@@ -94,20 +79,22 @@ function buildV1Event(message) {
94
79
  const properties = {
95
80
  ...sourceProperties
96
81
  };
97
- const options = {};
98
- for (const { property, optionKey, coerce } of OPTION_SENTINELS)if (property in properties) {
99
- const coerced = coerce(properties[property]);
100
- if (void 0 !== coerced) options[optionKey] = coerced;
82
+ const options = readEventOptions(message.options) ?? {};
83
+ for (const [optionKey, property] of Object.entries(core_namespaceObject.EVENT_OPTION_LEGACY_PROPERTIES)){
84
+ if (!(property in properties)) continue;
85
+ const legacyValue = properties[property];
101
86
  delete properties[property];
87
+ const option = options[optionKey];
88
+ if (null == option && void 0 !== legacyValue) options[optionKey] = legacyValue;
102
89
  }
103
90
  const topLevel = {};
104
- for (const { property, field } of TOPLEVEL_SENTINELS)if (property in properties) {
91
+ for (const { property, field } of TOPLEVEL_SENTINELS){
92
+ if (!(property in properties)) continue;
105
93
  const value = properties[property];
106
- if ('string' == typeof value) topLevel[field] = value;
107
94
  delete properties[property];
95
+ if ('string' == typeof value) topLevel[field] = value;
96
+ else if (null != value) console.warn(`[PostHog] dropping ${property}: a ${jsonTypeName(value)} value is not a string`);
108
97
  }
109
- delete properties.$lib;
110
- delete properties.$lib_version;
111
98
  relocateInto(properties, '$set', message.$set);
112
99
  relocateInto(properties, '$set_once', message.$set_once);
113
100
  return {
@@ -120,29 +107,11 @@ function buildV1Event(message) {
120
107
  properties
121
108
  };
122
109
  }
123
- function buildV1Batch(messages, { createdAt, historicalMigration }) {
124
- const batch = {
125
- created_at: createdAt,
126
- batch: messages.map(buildV1Event)
127
- };
128
- if (historicalMigration) batch.historical_migration = true;
129
- return batch;
130
- }
131
- __webpack_require__.d(__webpack_exports__, {
132
- buildV1Batch: ()=>buildV1Batch,
133
- buildV1Event: ()=>buildV1Event,
134
- coerceBool: ()=>coerceBool,
135
- coerceString: ()=>coerceString
136
- });
137
- exports.buildV1Batch = __webpack_exports__.buildV1Batch;
138
110
  exports.buildV1Event = __webpack_exports__.buildV1Event;
139
- exports.coerceBool = __webpack_exports__.coerceBool;
140
- exports.coerceString = __webpack_exports__.coerceString;
111
+ exports.readEventOptions = __webpack_exports__.readEventOptions;
141
112
  for(var __rspack_i in __webpack_exports__)if (-1 === [
142
- "buildV1Batch",
143
113
  "buildV1Event",
144
- "coerceBool",
145
- "coerceString"
114
+ "readEventOptions"
146
115
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
147
116
  Object.defineProperty(exports, '__esModule', {
148
117
  value: true
@@ -1,37 +1,4 @@
1
- function coerceBool(value) {
2
- if ('boolean' == typeof value) return value;
3
- if ('number' == typeof value) return 0 !== value;
4
- if ('string' == typeof value) {
5
- const normalized = value.trim().toLowerCase();
6
- if ('true' === normalized || '1' === normalized) return true;
7
- if ('false' === normalized || '0' === normalized) return false;
8
- }
9
- }
10
- function coerceString(value) {
11
- return 'string' == typeof value ? value : void 0;
12
- }
13
- const OPTION_SENTINELS = [
14
- {
15
- property: '$cookieless_mode',
16
- optionKey: 'cookieless_mode',
17
- coerce: coerceBool
18
- },
19
- {
20
- property: '$ignore_sent_at',
21
- optionKey: 'disable_skew_correction',
22
- coerce: coerceBool
23
- },
24
- {
25
- property: '$process_person_profile',
26
- optionKey: 'process_person_profile',
27
- coerce: coerceBool
28
- },
29
- {
30
- property: '$product_tour_id',
31
- optionKey: 'product_tour_id',
32
- coerce: coerceString
33
- }
34
- ];
1
+ import { EVENT_OPTION_LEGACY_PROPERTIES } from "@posthog/core";
35
2
  const TOPLEVEL_SENTINELS = [
36
3
  {
37
4
  property: '$session_id',
@@ -45,15 +12,29 @@ const TOPLEVEL_SENTINELS = [
45
12
  function isRecord(value) {
46
13
  return 'object' == typeof value && null !== value && !Array.isArray(value);
47
14
  }
15
+ function jsonTypeName(value) {
16
+ return Array.isArray(value) ? 'array' : typeof value;
17
+ }
18
+ function readEventOptions(value) {
19
+ if (null == value) return;
20
+ if (isRecord(value)) return {
21
+ ...value
22
+ };
23
+ console.error(`[PostHog] options must be an object, got ${jsonTypeName(value)}; sending the event without its options`);
24
+ }
25
+ function replaceUnparseableTimestamp() {
26
+ console.warn('[PostHog] replacing an unparseable event timestamp with the current time');
27
+ return new Date().toISOString();
28
+ }
48
29
  function toRfc3339(timestamp) {
49
30
  if ('string' == typeof timestamp) {
50
31
  const asDate = new Date(timestamp);
51
- if (Number.isNaN(asDate.getTime())) return new Date().toISOString();
32
+ if (Number.isNaN(asDate.getTime())) return replaceUnparseableTimestamp();
52
33
  const normalized = asDate.toISOString();
53
34
  const fractionalSeconds = timestamp.match(/\.(\d+)(?:Z|[+-]\d{2}:?\d{2})?$/i)?.[1];
54
35
  return fractionalSeconds && fractionalSeconds.length > 3 ? normalized.replace(/\.\d{3}Z$/, `.${fractionalSeconds}Z`) : normalized;
55
36
  }
56
- if (timestamp instanceof Date) return Number.isNaN(timestamp.getTime()) ? new Date().toISOString() : timestamp.toISOString();
37
+ if (timestamp instanceof Date) return Number.isNaN(timestamp.getTime()) ? replaceUnparseableTimestamp() : timestamp.toISOString();
57
38
  const asDate = null == timestamp ? new Date() : new Date(timestamp);
58
39
  return Number.isNaN(asDate.getTime()) ? new Date().toISOString() : asDate.toISOString();
59
40
  }
@@ -65,20 +46,22 @@ function buildV1Event(message) {
65
46
  const properties = {
66
47
  ...sourceProperties
67
48
  };
68
- const options = {};
69
- for (const { property, optionKey, coerce } of OPTION_SENTINELS)if (property in properties) {
70
- const coerced = coerce(properties[property]);
71
- if (void 0 !== coerced) options[optionKey] = coerced;
49
+ const options = readEventOptions(message.options) ?? {};
50
+ for (const [optionKey, property] of Object.entries(EVENT_OPTION_LEGACY_PROPERTIES)){
51
+ if (!(property in properties)) continue;
52
+ const legacyValue = properties[property];
72
53
  delete properties[property];
54
+ const option = options[optionKey];
55
+ if (null == option && void 0 !== legacyValue) options[optionKey] = legacyValue;
73
56
  }
74
57
  const topLevel = {};
75
- for (const { property, field } of TOPLEVEL_SENTINELS)if (property in properties) {
58
+ for (const { property, field } of TOPLEVEL_SENTINELS){
59
+ if (!(property in properties)) continue;
76
60
  const value = properties[property];
77
- if ('string' == typeof value) topLevel[field] = value;
78
61
  delete properties[property];
62
+ if ('string' == typeof value) topLevel[field] = value;
63
+ else if (null != value) console.warn(`[PostHog] dropping ${property}: a ${jsonTypeName(value)} value is not a string`);
79
64
  }
80
- delete properties.$lib;
81
- delete properties.$lib_version;
82
65
  relocateInto(properties, '$set', message.$set);
83
66
  relocateInto(properties, '$set_once', message.$set_once);
84
67
  return {
@@ -91,12 +74,4 @@ function buildV1Event(message) {
91
74
  properties
92
75
  };
93
76
  }
94
- function buildV1Batch(messages, { createdAt, historicalMigration }) {
95
- const batch = {
96
- created_at: createdAt,
97
- batch: messages.map(buildV1Event)
98
- };
99
- if (historicalMigration) batch.historical_migration = true;
100
- return batch;
101
- }
102
- export { buildV1Batch, buildV1Event, coerceBool, coerceString };
77
+ export { buildV1Event, readEventOptions };
@@ -1,17 +1,26 @@
1
- import type { PostHogEventProperties } from '@posthog/core';
1
+ import type { JsonType, PostHogEventProperties } from '@posthog/core';
2
+ /** Capture lane for analytics events. */
3
+ export declare const ANALYTICS_CAPTURE_ENDPOINT = "/i/v1/analytics/events";
4
+ /** Capture lane for events sent through `captureAi`. */
5
+ export declare const AI_CAPTURE_ENDPOINT = "/i/v1/ai/events";
6
+ export type CaptureEndpoint = typeof ANALYTICS_CAPTURE_ENDPOINT | typeof AI_CAPTURE_ENDPOINT;
2
7
  /**
3
- * Typed `options` object on a Capture V1 event. Legacy `$`-prefixed sentinel
4
- * properties are lifted here (renamed + strictly typed) by the transform.
8
+ * The `options` object on a Capture V1 event: the caller's options plus any legacy
9
+ * `$`-prefixed option properties lifted by the transform. Values are sent unchanged.
5
10
  * Always serialized as an object (`{}` when empty), never `null`.
6
11
  */
7
12
  export interface V1EventOptions {
13
+ /** Whether to process this event in cookieless mode. */
8
14
  cookieless_mode?: boolean;
15
+ /** Whether to disable server-side timestamp skew correction for this event. */
9
16
  disable_skew_correction?: boolean;
17
+ /** Whether to create or update a person profile for this event. */
10
18
  process_person_profile?: boolean;
11
- product_tour_id?: string;
19
+ /** Additional capture options, sent to capture v1 unchanged. */
20
+ [key: string]: JsonType | undefined;
12
21
  }
13
22
  /**
14
- * A single event in a Capture V1 batch (`POST /i/v1/analytics/events`).
23
+ * A single event in a Capture V1 batch.
15
24
  * `session_id`/`window_id` are promoted from the `$session_id`/`$window_id`
16
25
  * sentinels; there is no top-level `api_key`.
17
26
  */
@@ -25,15 +34,6 @@ export interface V1Event {
25
34
  options: V1EventOptions;
26
35
  properties: PostHogEventProperties;
27
36
  }
28
- /**
29
- * The Capture V1 batch envelope. Unlike v0 there is no `api_key` (Bearer auth)
30
- * and no `sent_at`. `historical_migration` is omitted when false.
31
- */
32
- export interface V1Batch {
33
- created_at: string;
34
- historical_migration?: boolean;
35
- batch: V1Event[];
36
- }
37
37
  /**
38
38
  * Per-event result codes in a v1 2xx response body. Unknown strings are
39
39
  * tolerated as terminal success for forward compatibility.
@@ -42,6 +42,8 @@ export type V1ResultCode = 'ok' | 'warning' | 'drop' | 'retry';
42
42
  export interface V1EventResult {
43
43
  result: V1ResultCode | string;
44
44
  details?: string | null;
45
+ /** How many later copies of this uuid in the request the server dropped as duplicates. */
46
+ duplicates_dropped?: number;
45
47
  }
46
48
  /** Shape of a v1 2xx response body: a per-uuid map of results. */
47
49
  export interface V1BatchResponse {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/capture-v1/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAE3D;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,cAAc,CAAA;IACvB,UAAU,EAAE,sBAAsB,CAAA;CACnC;AAED;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,KAAK,EAAE,OAAO,EAAE,CAAA;CACjB;AAED;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAA;AAE9D,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,YAAY,GAAG,MAAM,CAAA;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB;AAED,kEAAkE;AAClE,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CACvC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/capture-v1/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAErE,yCAAyC;AACzC,eAAO,MAAM,0BAA0B,2BAA2B,CAAA;AAElE,wDAAwD;AACxD,eAAO,MAAM,mBAAmB,oBAAoB,CAAA;AAEpD,MAAM,MAAM,eAAe,GAAG,OAAO,0BAA0B,GAAG,OAAO,mBAAmB,CAAA;AAE5F;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,wDAAwD;IACxD,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,+EAA+E;IAC/E,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC,mEAAmE;IACnE,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,gEAAgE;IAChE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;CACpC;AAED;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,cAAc,CAAA;IACvB,UAAU,EAAE,sBAAsB,CAAA;CACnC;AAED;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAA;AAE9D,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,YAAY,GAAG,MAAM,CAAA;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,0FAA0F;IAC1F,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,kEAAkE;AAClE,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CACvC"}
@@ -1,5 +1,20 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
3
18
  (()=>{
4
19
  __webpack_require__.r = (exports1)=>{
5
20
  if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
@@ -12,7 +27,18 @@ var __webpack_require__ = {};
12
27
  })();
13
28
  var __webpack_exports__ = {};
14
29
  __webpack_require__.r(__webpack_exports__);
15
- for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
30
+ const ANALYTICS_CAPTURE_ENDPOINT = '/i/v1/analytics/events';
31
+ const AI_CAPTURE_ENDPOINT = '/i/v1/ai/events';
32
+ __webpack_require__.d(__webpack_exports__, {}, {
33
+ AI_CAPTURE_ENDPOINT: AI_CAPTURE_ENDPOINT,
34
+ ANALYTICS_CAPTURE_ENDPOINT: ANALYTICS_CAPTURE_ENDPOINT
35
+ });
36
+ exports.AI_CAPTURE_ENDPOINT = __webpack_exports__.AI_CAPTURE_ENDPOINT;
37
+ exports.ANALYTICS_CAPTURE_ENDPOINT = __webpack_exports__.ANALYTICS_CAPTURE_ENDPOINT;
38
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
39
+ "AI_CAPTURE_ENDPOINT",
40
+ "ANALYTICS_CAPTURE_ENDPOINT"
41
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
16
42
  Object.defineProperty(exports, '__esModule', {
17
43
  value: true
18
44
  });
@@ -1 +1,3 @@
1
- export { };
1
+ const ANALYTICS_CAPTURE_ENDPOINT = '/i/v1/analytics/events';
2
+ const AI_CAPTURE_ENDPOINT = '/i/v1/ai/events';
3
+ export { AI_CAPTURE_ENDPOINT, ANALYTICS_CAPTURE_ENDPOINT };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The lowercase, hyphenated form of an RFC 4122 uuid string, or undefined for anything else.
3
+ * Accepts 32 hex digits, the hyphenated form, the hyphenated form in braces, and the
4
+ * `urn:uuid:` form, in any case.
5
+ */
6
+ export declare function canonicalizeUuid(value: string): string | undefined;
7
+ /** A v7 uuid for an event or a personless distinct id, with random bits from `crypto.getRandomValues`. */
8
+ export declare function eventUuidv7(): string;
9
+ //# sourceMappingURL=uuid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/capture-v1/uuid.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUlE;AA4BD,0GAA0G;AAC1G,wBAAgB,WAAW,IAAI,MAAM,CAEpC"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ canonicalizeUuid: ()=>canonicalizeUuid,
32
+ eventUuidv7: ()=>eventUuidv7
33
+ });
34
+ const core_namespaceObject = require("@posthog/core");
35
+ const HYPHENATED = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
36
+ const HEX_32 = /^[0-9a-f]{32}$/i;
37
+ const URN_PREFIX = 'urn:uuid:';
38
+ function canonicalizeUuid(value) {
39
+ let hyphenated = value;
40
+ if (38 === value.length && value.startsWith('{') && value.endsWith('}')) hyphenated = value.slice(1, -1);
41
+ else if (45 === value.length && value.slice(0, URN_PREFIX.length).toLowerCase() === URN_PREFIX) hyphenated = value.slice(URN_PREFIX.length);
42
+ else if (HEX_32.test(value)) hyphenated = `${value.slice(0, 8)}-${value.slice(8, 12)}-${value.slice(12, 16)}-${value.slice(16, 20)}-${value.slice(20)}`;
43
+ return HYPHENATED.test(hyphenated) ? hyphenated.toLowerCase() : void 0;
44
+ }
45
+ class CryptoRandom {
46
+ constructor(crypto){
47
+ this.crypto = crypto;
48
+ this.words = new Uint32Array(8);
49
+ this.cursor = this.words.length;
50
+ }
51
+ nextUint32() {
52
+ if (this.cursor >= this.words.length) {
53
+ this.crypto.getRandomValues(this.words);
54
+ this.cursor = 0;
55
+ }
56
+ return this.words[this.cursor++];
57
+ }
58
+ }
59
+ function cryptoRandom() {
60
+ const crypto = globalThis.crypto;
61
+ return 'function' == typeof crypto?.getRandomValues ? new CryptoRandom(crypto) : void 0;
62
+ }
63
+ const generator = new core_namespaceObject.V7Generator(cryptoRandom());
64
+ function eventUuidv7() {
65
+ return generator.generate().toString();
66
+ }
67
+ exports.canonicalizeUuid = __webpack_exports__.canonicalizeUuid;
68
+ exports.eventUuidv7 = __webpack_exports__.eventUuidv7;
69
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
70
+ "canonicalizeUuid",
71
+ "eventUuidv7"
72
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
73
+ Object.defineProperty(exports, '__esModule', {
74
+ value: true
75
+ });
@@ -0,0 +1,34 @@
1
+ import { V7Generator } from "@posthog/core";
2
+ const HYPHENATED = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3
+ const HEX_32 = /^[0-9a-f]{32}$/i;
4
+ const URN_PREFIX = 'urn:uuid:';
5
+ function canonicalizeUuid(value) {
6
+ let hyphenated = value;
7
+ if (38 === value.length && value.startsWith('{') && value.endsWith('}')) hyphenated = value.slice(1, -1);
8
+ else if (45 === value.length && value.slice(0, URN_PREFIX.length).toLowerCase() === URN_PREFIX) hyphenated = value.slice(URN_PREFIX.length);
9
+ else if (HEX_32.test(value)) hyphenated = `${value.slice(0, 8)}-${value.slice(8, 12)}-${value.slice(12, 16)}-${value.slice(16, 20)}-${value.slice(20)}`;
10
+ return HYPHENATED.test(hyphenated) ? hyphenated.toLowerCase() : void 0;
11
+ }
12
+ class CryptoRandom {
13
+ constructor(crypto){
14
+ this.crypto = crypto;
15
+ this.words = new Uint32Array(8);
16
+ this.cursor = this.words.length;
17
+ }
18
+ nextUint32() {
19
+ if (this.cursor >= this.words.length) {
20
+ this.crypto.getRandomValues(this.words);
21
+ this.cursor = 0;
22
+ }
23
+ return this.words[this.cursor++];
24
+ }
25
+ }
26
+ function cryptoRandom() {
27
+ const crypto = globalThis.crypto;
28
+ return 'function' == typeof crypto?.getRandomValues ? new CryptoRandom(crypto) : void 0;
29
+ }
30
+ const generator = new V7Generator(cryptoRandom());
31
+ function eventUuidv7() {
32
+ return generator.generate().toString();
33
+ }
34
+ export { canonicalizeUuid, eventUuidv7 };