@posthog/core 1.70.0 → 1.71.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 (117) hide show
  1. package/capture-v1/package.json +6 -0
  2. package/dist/capture-v1/compression.d.ts +18 -0
  3. package/dist/capture-v1/compression.d.ts.map +1 -0
  4. package/dist/capture-v1/compression.js +70 -0
  5. package/dist/capture-v1/compression.mjs +26 -0
  6. package/dist/capture-v1/errors.d.ts +48 -0
  7. package/dist/capture-v1/errors.d.ts.map +1 -0
  8. package/dist/capture-v1/errors.js +82 -0
  9. package/dist/capture-v1/errors.mjs +38 -0
  10. package/dist/capture-v1/index.d.ts +15 -0
  11. package/dist/capture-v1/index.d.ts.map +1 -0
  12. package/dist/capture-v1/index.js +88 -0
  13. package/dist/capture-v1/index.mjs +7 -0
  14. package/dist/capture-v1/sender.d.ts +150 -0
  15. package/dist/capture-v1/sender.d.ts.map +1 -0
  16. package/dist/capture-v1/sender.js +554 -0
  17. package/dist/capture-v1/sender.mjs +507 -0
  18. package/dist/capture-v1/serialize.d.ts +30 -0
  19. package/dist/capture-v1/serialize.d.ts.map +1 -0
  20. package/dist/capture-v1/serialize.js +106 -0
  21. package/dist/capture-v1/serialize.mjs +59 -0
  22. package/dist/capture-v1/transform.d.ts +19 -0
  23. package/dist/capture-v1/transform.d.ts.map +1 -0
  24. package/dist/capture-v1/transform.js +118 -0
  25. package/dist/capture-v1/transform.mjs +77 -0
  26. package/dist/capture-v1/types.d.ts +52 -0
  27. package/dist/capture-v1/types.d.ts.map +1 -0
  28. package/dist/capture-v1/types.js +44 -0
  29. package/dist/capture-v1/types.mjs +3 -0
  30. package/dist/capture-v1/uuid.d.ts +9 -0
  31. package/dist/capture-v1/uuid.d.ts.map +1 -0
  32. package/dist/capture-v1/uuid.js +75 -0
  33. package/dist/capture-v1/uuid.mjs +34 -0
  34. package/dist/featureFlagUtils.d.ts +7 -5
  35. package/dist/featureFlagUtils.d.ts.map +1 -1
  36. package/dist/featureFlagUtils.js +17 -11
  37. package/dist/featureFlagUtils.mjs +14 -11
  38. package/dist/index.d.ts +1 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +27 -16
  41. package/dist/index.mjs +1 -1
  42. package/dist/posthog-core-stateless.d.ts +40 -3
  43. package/dist/posthog-core-stateless.d.ts.map +1 -1
  44. package/dist/posthog-core-stateless.js +87 -19
  45. package/dist/posthog-core-stateless.mjs +87 -19
  46. package/dist/posthog-core.d.ts +138 -53
  47. package/dist/posthog-core.d.ts.map +1 -1
  48. package/dist/posthog-core.js +341 -115
  49. package/dist/posthog-core.mjs +338 -115
  50. package/dist/types.d.ts +24 -1
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/utils/index.d.ts +1 -1
  53. package/dist/utils/index.d.ts.map +1 -1
  54. package/dist/utils/index.js +25 -12
  55. package/dist/utils/index.mjs +1 -1
  56. package/dist/utils/json-utils.d.ts +11 -1
  57. package/dist/utils/json-utils.d.ts.map +1 -1
  58. package/dist/utils/json-utils.js +50 -2
  59. package/dist/utils/json-utils.mjs +46 -1
  60. package/package.json +12 -2
  61. package/src/capture-v1/compression.ts +50 -0
  62. package/src/capture-v1/errors.ts +91 -0
  63. package/src/capture-v1/index.ts +34 -0
  64. package/src/capture-v1/sender.ts +779 -0
  65. package/src/capture-v1/serialize.ts +113 -0
  66. package/src/capture-v1/transform.ts +135 -0
  67. package/src/capture-v1/types.ts +59 -0
  68. package/src/capture-v1/uuid.ts +53 -0
  69. package/src/featureFlagUtils.ts +22 -10
  70. package/src/index.ts +1 -0
  71. package/src/posthog-core-stateless.ts +166 -30
  72. package/src/posthog-core.ts +615 -178
  73. package/src/types.ts +21 -1
  74. package/src/utils/index.ts +1 -1
  75. package/src/utils/json-utils.ts +64 -1
  76. package/src/error-tracking/chunk-ids.spec.ts +0 -77
  77. package/src/error-tracking/coercers/error-event-coercer.spec.ts +0 -142
  78. package/src/error-tracking/coercers/promise-rejection-event.spec.ts +0 -77
  79. package/src/error-tracking/coercers/string-coercer.spec.ts +0 -26
  80. package/src/error-tracking/error-properties-builder.aggregate-errors.spec.ts +0 -412
  81. package/src/error-tracking/error-properties-builder.coerce.spec.ts +0 -337
  82. package/src/error-tracking/error-properties-builder.metadata.spec.ts +0 -318
  83. package/src/error-tracking/error-properties-builder.parse.spec.ts +0 -37
  84. package/src/error-tracking/exception-steps.spec.ts +0 -115
  85. package/src/error-tracking/parsers/base.spec.ts +0 -156
  86. package/src/error-tracking/parsers/index.spec.ts +0 -270
  87. package/src/error-tracking/parsers/node.spec.ts +0 -34
  88. package/src/error-tracking/release.spec.ts +0 -34
  89. package/src/logs/index.spec.ts +0 -2421
  90. package/src/logs/logs-utils.spec.ts +0 -266
  91. package/src/metrics/index.spec.ts +0 -1249
  92. package/src/surveys/activation.spec.ts +0 -61
  93. package/src/surveys/events.spec.ts +0 -183
  94. package/src/surveys/keys.spec.ts +0 -29
  95. package/src/surveys/property-matching.spec.ts +0 -539
  96. package/src/surveys/shuffling.spec.ts +0 -51
  97. package/src/surveys/translations.spec.ts +0 -274
  98. package/src/surveys/validation.spec.ts +0 -168
  99. package/src/traces/config.spec.ts +0 -271
  100. package/src/traces/ids.spec.ts +0 -115
  101. package/src/traces/index.spec.ts +0 -3287
  102. package/src/traces/live-spans.spec.ts +0 -69
  103. package/src/traces/otlp.spec.ts +0 -368
  104. package/src/traces/span.spec.ts +0 -1137
  105. package/src/traces/traceparent.spec.ts +0 -184
  106. package/src/utils/bot-detection.spec.ts +0 -107
  107. package/src/utils/bucketed-rate-limiter.spec.ts +0 -327
  108. package/src/utils/json-utils.spec.ts +0 -115
  109. package/src/utils/named-error.spec.ts +0 -36
  110. package/src/utils/number-utils.spec.ts +0 -212
  111. package/src/utils/otlp-any-value.spec.ts +0 -376
  112. package/src/utils/otlp-resource.spec.ts +0 -171
  113. package/src/utils/promise-queue.spec.ts +0 -55
  114. package/src/utils/string-utils.spec.ts +0 -158
  115. package/src/utils/type-utils.spec.ts +0 -38
  116. package/src/utils/webview-app-utils.spec.ts +0 -118
  117. package/src/vendor/uuidv7.spec.ts +0 -26
@@ -0,0 +1,59 @@
1
+ import { safeJsonStringify } from "../utils/string-utils.mjs";
2
+ import { buildV1Event } from "./transform.mjs";
3
+ const encoder = "u" < typeof TextEncoder ? void 0 : new TextEncoder();
4
+ function utf8Length(value) {
5
+ return encoder ? encoder.encode(value).length : countUtf8Bytes(value);
6
+ }
7
+ function countUtf8Bytes(value) {
8
+ let bytes = 0;
9
+ for(let index = 0; index < value.length; index++){
10
+ const code = value.charCodeAt(index);
11
+ if (code < 0x80) bytes += 1;
12
+ else if (code < 0x800) bytes += 2;
13
+ else if (code >= 0xd800 && code <= 0xdbff && index + 1 < value.length) {
14
+ const next = value.charCodeAt(index + 1);
15
+ if (next >= 0xdc00 && next <= 0xdfff) {
16
+ bytes += 4;
17
+ index++;
18
+ } else bytes += 3;
19
+ } else bytes += 3;
20
+ }
21
+ return bytes;
22
+ }
23
+ const PROPERTIES_KEY = ',"properties":';
24
+ const PROPERTIES_KEY_BYTES = utf8Length(PROPERTIES_KEY);
25
+ const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]/;
26
+ const LONE_SURROGATE_ESCAPE = /\\\\|\\u[dD][89a-fA-F][0-9a-fA-F]{2}/g;
27
+ function wireProblem(message) {
28
+ const { event, distinct_id: distinctId, properties } = message;
29
+ if ('string' != typeof event || '' === event) return 'event name is missing, empty or not a string';
30
+ if ('string' != typeof distinctId) return 'distinct id is missing or not a string';
31
+ const props = properties ?? {};
32
+ const ids = [
33
+ event,
34
+ distinctId,
35
+ props.$session_id,
36
+ props.$window_id
37
+ ];
38
+ if (ids.some((value)=>'string' == typeof value && LONE_SURROGATE.test(value))) return 'event name or id is not well-formed Unicode';
39
+ }
40
+ function repairLoneSurrogates(json) {
41
+ return json.includes('\\ud') || json.includes('\\uD') ? json.replace(LONE_SURROGATE_ESCAPE, (match)=>2 === match.length ? match : '\\ufffd') : json;
42
+ }
43
+ function serializeV1Event(message) {
44
+ const { properties, ...rest } = buildV1Event(message);
45
+ const restJson = repairLoneSurrogates(safeJsonStringify(rest));
46
+ const propertiesJson = repairLoneSurrogates(safeJsonStringify(properties));
47
+ const propertiesBytes = utf8Length(propertiesJson);
48
+ return {
49
+ uuid: rest.uuid,
50
+ json: `${restJson.slice(0, -1)}${PROPERTIES_KEY}${propertiesJson}}`,
51
+ bytes: utf8Length(restJson) + PROPERTIES_KEY_BYTES + propertiesBytes,
52
+ propertiesBytes
53
+ };
54
+ }
55
+ function buildV1Body(events, { createdAt, historicalMigration }) {
56
+ const migration = historicalMigration ? ',"historical_migration":true' : '';
57
+ return `{"created_at":${JSON.stringify(createdAt)}${migration},"batch":[${events.map((event)=>event.json).join(',')}]}`;
58
+ }
59
+ export { buildV1Body, serializeV1Event, utf8Length, wireProblem };
@@ -0,0 +1,19 @@
1
+ import type { JsonType, PostHogEventProperties } from '../types';
2
+ import type { V1Event } from './types';
3
+ /**
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.
6
+ */
7
+ export declare function readEventOptions(value: unknown): Record<string, JsonType> | undefined;
8
+ /**
9
+ * Transform one already-normalized queued message into a Capture V1 wire event.
10
+ *
11
+ * The input message is never mutated (events may be retried or handed to
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`.
17
+ */
18
+ export declare function buildV1Event(message: PostHogEventProperties): V1Event;
19
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/capture-v1/transform.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAEhE,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"}
@@ -0,0 +1,118 @@
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
+ buildV1Event: ()=>buildV1Event,
32
+ readEventOptions: ()=>readEventOptions
33
+ });
34
+ const external_event_options_js_namespaceObject = require("../event-options.js");
35
+ const TOPLEVEL_SENTINELS = [
36
+ {
37
+ property: '$session_id',
38
+ field: 'session_id'
39
+ },
40
+ {
41
+ property: '$window_id',
42
+ field: 'window_id'
43
+ }
44
+ ];
45
+ function isRecord(value) {
46
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
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
+ }
62
+ function toRfc3339(timestamp) {
63
+ if ('string' == typeof timestamp) {
64
+ const asDate = new Date(timestamp);
65
+ if (Number.isNaN(asDate.getTime())) return replaceUnparseableTimestamp();
66
+ const normalized = asDate.toISOString();
67
+ const fractionalSeconds = timestamp.match(/\.(\d+)(?:Z|[+-]\d{2}:?\d{2})?$/i)?.[1];
68
+ return fractionalSeconds && fractionalSeconds.length > 3 ? normalized.replace(/\.\d{3}Z$/, `.${fractionalSeconds}Z`) : normalized;
69
+ }
70
+ if (timestamp instanceof Date) return Number.isNaN(timestamp.getTime()) ? replaceUnparseableTimestamp() : timestamp.toISOString();
71
+ const asDate = null == timestamp ? new Date() : new Date(timestamp);
72
+ return Number.isNaN(asDate.getTime()) ? new Date().toISOString() : asDate.toISOString();
73
+ }
74
+ function relocateInto(properties, key, value) {
75
+ if (void 0 !== value && !(key in properties)) properties[key] = value;
76
+ }
77
+ function buildV1Event(message) {
78
+ const sourceProperties = isRecord(message.properties) ? message.properties : {};
79
+ const properties = {
80
+ ...sourceProperties
81
+ };
82
+ const options = readEventOptions(message.options) ?? {};
83
+ for (const [optionKey, property] of Object.entries(external_event_options_js_namespaceObject.EVENT_OPTION_LEGACY_PROPERTIES)){
84
+ if (!(property in properties)) continue;
85
+ const legacyValue = properties[property];
86
+ delete properties[property];
87
+ const option = options[optionKey];
88
+ if (null == option && void 0 !== legacyValue) options[optionKey] = legacyValue;
89
+ }
90
+ const topLevel = {};
91
+ for (const { property, field } of TOPLEVEL_SENTINELS){
92
+ if (!(property in properties)) continue;
93
+ const value = properties[property];
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`);
97
+ }
98
+ relocateInto(properties, '$set', message.$set);
99
+ relocateInto(properties, '$set_once', message.$set_once);
100
+ return {
101
+ event: String(message.event ?? ''),
102
+ uuid: String(message.uuid ?? ''),
103
+ distinct_id: String(message.distinct_id ?? ''),
104
+ timestamp: toRfc3339(message.timestamp),
105
+ ...topLevel,
106
+ options,
107
+ properties
108
+ };
109
+ }
110
+ exports.buildV1Event = __webpack_exports__.buildV1Event;
111
+ exports.readEventOptions = __webpack_exports__.readEventOptions;
112
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
113
+ "buildV1Event",
114
+ "readEventOptions"
115
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
116
+ Object.defineProperty(exports, '__esModule', {
117
+ value: true
118
+ });
@@ -0,0 +1,77 @@
1
+ import { EVENT_OPTION_LEGACY_PROPERTIES } from "../event-options.mjs";
2
+ const TOPLEVEL_SENTINELS = [
3
+ {
4
+ property: '$session_id',
5
+ field: 'session_id'
6
+ },
7
+ {
8
+ property: '$window_id',
9
+ field: 'window_id'
10
+ }
11
+ ];
12
+ function isRecord(value) {
13
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
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
+ }
29
+ function toRfc3339(timestamp) {
30
+ if ('string' == typeof timestamp) {
31
+ const asDate = new Date(timestamp);
32
+ if (Number.isNaN(asDate.getTime())) return replaceUnparseableTimestamp();
33
+ const normalized = asDate.toISOString();
34
+ const fractionalSeconds = timestamp.match(/\.(\d+)(?:Z|[+-]\d{2}:?\d{2})?$/i)?.[1];
35
+ return fractionalSeconds && fractionalSeconds.length > 3 ? normalized.replace(/\.\d{3}Z$/, `.${fractionalSeconds}Z`) : normalized;
36
+ }
37
+ if (timestamp instanceof Date) return Number.isNaN(timestamp.getTime()) ? replaceUnparseableTimestamp() : timestamp.toISOString();
38
+ const asDate = null == timestamp ? new Date() : new Date(timestamp);
39
+ return Number.isNaN(asDate.getTime()) ? new Date().toISOString() : asDate.toISOString();
40
+ }
41
+ function relocateInto(properties, key, value) {
42
+ if (void 0 !== value && !(key in properties)) properties[key] = value;
43
+ }
44
+ function buildV1Event(message) {
45
+ const sourceProperties = isRecord(message.properties) ? message.properties : {};
46
+ const properties = {
47
+ ...sourceProperties
48
+ };
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];
53
+ delete properties[property];
54
+ const option = options[optionKey];
55
+ if (null == option && void 0 !== legacyValue) options[optionKey] = legacyValue;
56
+ }
57
+ const topLevel = {};
58
+ for (const { property, field } of TOPLEVEL_SENTINELS){
59
+ if (!(property in properties)) continue;
60
+ const value = properties[property];
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`);
64
+ }
65
+ relocateInto(properties, '$set', message.$set);
66
+ relocateInto(properties, '$set_once', message.$set_once);
67
+ return {
68
+ event: String(message.event ?? ''),
69
+ uuid: String(message.uuid ?? ''),
70
+ distinct_id: String(message.distinct_id ?? ''),
71
+ timestamp: toRfc3339(message.timestamp),
72
+ ...topLevel,
73
+ options,
74
+ properties
75
+ };
76
+ }
77
+ export { buildV1Event, readEventOptions };
@@ -0,0 +1,52 @@
1
+ import type { JsonType, PostHogEventProperties } from '../types';
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;
7
+ /**
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.
10
+ * Always serialized as an object (`{}` when empty), never `null`.
11
+ */
12
+ export interface V1EventOptions {
13
+ /** Whether to process this event in cookieless mode. */
14
+ cookieless_mode?: boolean;
15
+ /** Whether to disable server-side timestamp skew correction for this event. */
16
+ disable_skew_correction?: boolean;
17
+ /** Whether to create or update a person profile for this event. */
18
+ process_person_profile?: boolean;
19
+ /** Additional capture options, sent to capture v1 unchanged. */
20
+ [key: string]: JsonType | undefined;
21
+ }
22
+ /**
23
+ * A single event in a Capture V1 batch.
24
+ * `session_id`/`window_id` are promoted from the `$session_id`/`$window_id`
25
+ * sentinels; there is no top-level `api_key`.
26
+ */
27
+ export interface V1Event {
28
+ event: string;
29
+ uuid: string;
30
+ distinct_id: string;
31
+ timestamp: string;
32
+ session_id?: string;
33
+ window_id?: string;
34
+ options: V1EventOptions;
35
+ properties: PostHogEventProperties;
36
+ }
37
+ /**
38
+ * Per-event result codes in a v1 2xx response body. Unknown strings are
39
+ * tolerated as terminal success for forward compatibility.
40
+ */
41
+ export type V1ResultCode = 'ok' | 'warning' | 'drop' | 'retry';
42
+ export interface V1EventResult {
43
+ result: V1ResultCode | string;
44
+ details?: string | null;
45
+ /** How many later copies of this uuid in the request the server dropped as duplicates. */
46
+ duplicates_dropped?: number;
47
+ }
48
+ /** Shape of a v1 2xx response body: a per-uuid map of results. */
49
+ export interface V1BatchResponse {
50
+ results: Record<string, V1EventResult>;
51
+ }
52
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
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,UAAU,CAAA;AAEhE,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"}
@@ -0,0 +1,44 @@
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
+ 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];
42
+ Object.defineProperty(exports, '__esModule', {
43
+ value: true
44
+ });
@@ -0,0 +1,3 @@
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 uuidv7_js_namespaceObject = require("../vendor/uuidv7.js");
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 uuidv7_js_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 "../vendor/uuidv7.mjs";
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 };
@@ -1,5 +1,5 @@
1
- import { FeatureFlagDetail, FeatureFlagResult, FeatureFlagValue, PostHogFlagsResponse, PostHogV1FlagsResponse, PostHogV2FlagsResponse, PartialWithRequired, PostHogFeatureFlagsResponse } from './types';
2
- export declare const normalizeFlagsResponse: (flagsResponse: PartialWithRequired<PostHogV2FlagsResponse, 'flags'> | PartialWithRequired<PostHogV1FlagsResponse, 'featureFlags' | 'featureFlagPayloads'>) => PostHogFeatureFlagsResponse;
1
+ import { FeatureFlagDetail, FeatureFlagResult, FeatureFlagValue, JsonType, PostHogFlagsResponse, PostHogV1FlagsResponse, PostHogV2FlagsResponse, PartialWithRequired, PostHogFeatureFlagsResponse } from './types';
2
+ export declare const normalizeFlagsResponse: (flagsResponse: PartialWithRequired<PostHogV2FlagsResponse, 'flags'> | PartialWithRequired<PostHogV1FlagsResponse, 'featureFlags' | 'featureFlagPayloads'>, decodePayload?: (payload: any) => any) => PostHogFeatureFlagsResponse;
3
3
  /**
4
4
  * Get the flag values from the flags v4 response.
5
5
  * @param flags - The flags
@@ -11,7 +11,7 @@ export declare const getFlagValuesFromFlags: (flags: PostHogFlagsResponse['flags
11
11
  * @param flags - The flags
12
12
  * @returns The payloads
13
13
  */
14
- export declare const getPayloadsFromFlags: (flags: PostHogFlagsResponse['flags']) => PostHogFlagsResponse['featureFlagPayloads'];
14
+ export declare const getPayloadsFromFlags: (flags: PostHogFlagsResponse['flags'], decodePayload?: (payload: any) => any) => PostHogFlagsResponse['featureFlagPayloads'];
15
15
  export declare const getFeatureFlagValue: (detail: FeatureFlagDetail | undefined) => FeatureFlagValue | undefined;
16
16
  export declare const parsePayload: (response: any) => any;
17
17
  /**
@@ -24,11 +24,13 @@ export declare const parsePayload: (response: any) => any;
24
24
  * @param featureFlagPayloads - The feature flag payloads
25
25
  * @returns The normalized flag details
26
26
  */
27
- export declare const createFlagsResponseFromFlagsAndPayloads: (featureFlags: PostHogV1FlagsResponse['featureFlags'], featureFlagPayloads: PostHogV1FlagsResponse['featureFlagPayloads']) => PostHogFeatureFlagsResponse;
27
+ export declare const createFlagsResponseFromFlagsAndPayloads: (featureFlags: PostHogV1FlagsResponse['featureFlags'], featureFlagPayloads: PostHogV1FlagsResponse['featureFlagPayloads'], decodePayload?: (payload: any) => any) => PostHogFeatureFlagsResponse;
28
28
  export declare const updateFlagValue: (flag: FeatureFlagDetail, value: FeatureFlagValue) => FeatureFlagDetail;
29
29
  export declare function getEnabledFromValue(value: FeatureFlagValue): boolean;
30
+ /** Whether a flag value is on: `true`, or a variant that isn't an empty string. */
31
+ export declare function isEnabledFlagValue(value: FeatureFlagValue | undefined): boolean;
30
32
  export declare function getVariantFromValue(value: FeatureFlagValue): string | undefined;
31
- export declare const flagDetailsToResults: (flagDetails: Record<string, FeatureFlagDetail>) => FeatureFlagResult[];
33
+ export declare const flagDetailsToResults: (flagDetails: Record<string, FeatureFlagDetail>, decodePayload?: (payload: any) => JsonType, isEnabled?: (value: FeatureFlagValue) => boolean) => FeatureFlagResult[];
32
34
  /**
33
35
  * Strict allowlist of event properties kept on a minimal `$feature_flag_called` event.
34
36
  *
@@ -1 +1 @@
1
- {"version":3,"file":"featureFlagUtils.d.ts","sourceRoot":"","sources":["../src/featureFlagUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAEhB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EAEtB,mBAAmB,EACnB,2BAA2B,EAC5B,MAAM,SAAS,CAAA;AAEhB,eAAO,MAAM,sBAAsB,kBAE7B,mBAAmB,CAAC,sBAAsB,EAAE,OAAO,CAAC,GACpD,mBAAmB,CAAC,sBAAsB,EAAE,cAAc,GAAG,qBAAqB,CAAC,KACtF,2BAgCF,CAAA;AAqBD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,UAAW,oBAAoB,CAAC,OAAO,CAAC,KAAG,oBAAoB,CAAC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