@posthog/core 1.69.9 → 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 (122) 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/featureFlagLocalEvaluation.d.ts +2 -0
  35. package/dist/featureFlagLocalEvaluation.d.ts.map +1 -1
  36. package/dist/featureFlagLocalEvaluation.js +38 -0
  37. package/dist/featureFlagLocalEvaluation.mjs +38 -0
  38. package/dist/featureFlagUtils.d.ts +7 -5
  39. package/dist/featureFlagUtils.d.ts.map +1 -1
  40. package/dist/featureFlagUtils.js +17 -11
  41. package/dist/featureFlagUtils.mjs +14 -11
  42. package/dist/index.d.ts +1 -1
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +27 -16
  45. package/dist/index.mjs +1 -1
  46. package/dist/posthog-core-stateless.d.ts +44 -7
  47. package/dist/posthog-core-stateless.d.ts.map +1 -1
  48. package/dist/posthog-core-stateless.js +103 -24
  49. package/dist/posthog-core-stateless.mjs +103 -24
  50. package/dist/posthog-core.d.ts +138 -53
  51. package/dist/posthog-core.d.ts.map +1 -1
  52. package/dist/posthog-core.js +341 -115
  53. package/dist/posthog-core.mjs +338 -115
  54. package/dist/types.d.ts +33 -1
  55. package/dist/types.d.ts.map +1 -1
  56. package/dist/utils/index.d.ts +1 -1
  57. package/dist/utils/index.d.ts.map +1 -1
  58. package/dist/utils/index.js +25 -12
  59. package/dist/utils/index.mjs +1 -1
  60. package/dist/utils/json-utils.d.ts +11 -1
  61. package/dist/utils/json-utils.d.ts.map +1 -1
  62. package/dist/utils/json-utils.js +50 -2
  63. package/dist/utils/json-utils.mjs +46 -1
  64. package/package.json +13 -3
  65. package/src/capture-v1/compression.ts +50 -0
  66. package/src/capture-v1/errors.ts +91 -0
  67. package/src/capture-v1/index.ts +34 -0
  68. package/src/capture-v1/sender.ts +779 -0
  69. package/src/capture-v1/serialize.ts +113 -0
  70. package/src/capture-v1/transform.ts +135 -0
  71. package/src/capture-v1/types.ts +59 -0
  72. package/src/capture-v1/uuid.ts +53 -0
  73. package/src/featureFlagLocalEvaluation.ts +51 -0
  74. package/src/featureFlagUtils.ts +22 -10
  75. package/src/index.ts +1 -0
  76. package/src/posthog-core-stateless.ts +190 -35
  77. package/src/posthog-core.ts +615 -178
  78. package/src/types.ts +31 -1
  79. package/src/utils/index.ts +1 -1
  80. package/src/utils/json-utils.ts +64 -1
  81. package/src/error-tracking/chunk-ids.spec.ts +0 -77
  82. package/src/error-tracking/coercers/error-event-coercer.spec.ts +0 -142
  83. package/src/error-tracking/coercers/promise-rejection-event.spec.ts +0 -77
  84. package/src/error-tracking/coercers/string-coercer.spec.ts +0 -26
  85. package/src/error-tracking/error-properties-builder.aggregate-errors.spec.ts +0 -412
  86. package/src/error-tracking/error-properties-builder.coerce.spec.ts +0 -337
  87. package/src/error-tracking/error-properties-builder.metadata.spec.ts +0 -318
  88. package/src/error-tracking/error-properties-builder.parse.spec.ts +0 -37
  89. package/src/error-tracking/exception-steps.spec.ts +0 -115
  90. package/src/error-tracking/parsers/base.spec.ts +0 -156
  91. package/src/error-tracking/parsers/index.spec.ts +0 -270
  92. package/src/error-tracking/parsers/node.spec.ts +0 -34
  93. package/src/error-tracking/release.spec.ts +0 -34
  94. package/src/logs/index.spec.ts +0 -2421
  95. package/src/logs/logs-utils.spec.ts +0 -266
  96. package/src/metrics/index.spec.ts +0 -1249
  97. package/src/surveys/activation.spec.ts +0 -61
  98. package/src/surveys/events.spec.ts +0 -183
  99. package/src/surveys/keys.spec.ts +0 -29
  100. package/src/surveys/property-matching.spec.ts +0 -539
  101. package/src/surveys/shuffling.spec.ts +0 -51
  102. package/src/surveys/translations.spec.ts +0 -274
  103. package/src/surveys/validation.spec.ts +0 -168
  104. package/src/traces/config.spec.ts +0 -271
  105. package/src/traces/ids.spec.ts +0 -115
  106. package/src/traces/index.spec.ts +0 -3287
  107. package/src/traces/live-spans.spec.ts +0 -69
  108. package/src/traces/otlp.spec.ts +0 -368
  109. package/src/traces/span.spec.ts +0 -1137
  110. package/src/traces/traceparent.spec.ts +0 -184
  111. package/src/utils/bot-detection.spec.ts +0 -107
  112. package/src/utils/bucketed-rate-limiter.spec.ts +0 -327
  113. package/src/utils/json-utils.spec.ts +0 -115
  114. package/src/utils/named-error.spec.ts +0 -36
  115. package/src/utils/number-utils.spec.ts +0 -212
  116. package/src/utils/otlp-any-value.spec.ts +0 -376
  117. package/src/utils/otlp-resource.spec.ts +0 -171
  118. package/src/utils/promise-queue.spec.ts +0 -55
  119. package/src/utils/string-utils.spec.ts +0 -158
  120. package/src/utils/type-utils.spec.ts +0 -38
  121. package/src/utils/webview-app-utils.spec.ts +0 -118
  122. package/src/vendor/uuidv7.spec.ts +0 -26
@@ -0,0 +1,91 @@
1
+ import type { CaptureEndpoint } from './types'
2
+
3
+ /** A single event the server explicitly rejected (`drop`). */
4
+ export interface CaptureDroppedEvent {
5
+ uuid: string
6
+ details?: string
7
+ }
8
+
9
+ export interface CaptureErrorParams {
10
+ /** The capture lane the batch was sent to. */
11
+ endpoint: CaptureEndpoint
12
+ requestId: string
13
+ /** Events the server rejected outright (billing/validation). */
14
+ drops: CaptureDroppedEvent[]
15
+ /** UUIDs of events still pending `retry` after the attempt budget was exhausted, or lost to a batch-level failure. */
16
+ retryExhausted: string[]
17
+ /** The underlying transport/HTTP/parse failure, when the whole batch failed. */
18
+ cause?: unknown
19
+ }
20
+
21
+ /**
22
+ * Surfaced on the client error channel whenever a capture batch did not
23
+ * fully deliver: some events were `drop`ped, some `retry` events outlived the
24
+ * attempt budget, or the batch hit a terminal transport/HTTP/parse failure.
25
+ *
26
+ * A 2xx with drops is still a partial failure and is reported here — a
27
+ * successful HTTP status does not mean every event was accepted.
28
+ */
29
+ export class CaptureError extends Error {
30
+ name = 'CaptureError'
31
+ readonly endpoint: CaptureEndpoint
32
+ readonly requestId: string
33
+ readonly drops: CaptureDroppedEvent[]
34
+ readonly retryExhausted: string[]
35
+ cause?: unknown
36
+
37
+ constructor({ endpoint, requestId, drops, retryExhausted, cause }: CaptureErrorParams) {
38
+ super(CaptureError.buildMessage(endpoint, requestId, drops, retryExhausted, cause))
39
+ this.endpoint = endpoint
40
+ this.requestId = requestId
41
+ this.drops = drops
42
+ this.retryExhausted = retryExhausted
43
+ this.cause = cause
44
+ }
45
+
46
+ private static buildMessage(
47
+ endpoint: CaptureEndpoint,
48
+ requestId: string,
49
+ drops: CaptureDroppedEvent[],
50
+ retryExhausted: string[],
51
+ cause: unknown
52
+ ): string {
53
+ let message = `Capture batch ${requestId} to ${endpoint} did not fully deliver: ${drops.length} dropped, ${retryExhausted.length} undelivered`
54
+ if (cause instanceof Error) {
55
+ message += ` (${cause.message})`
56
+ }
57
+ return message
58
+ }
59
+ }
60
+
61
+ /** Counts of undelivered events by cause, in the order the causes first occurred. */
62
+ export class CaptureLossTally {
63
+ private readonly counts = new Map<string, number>()
64
+
65
+ add(cause: string, count: number): void {
66
+ if (count > 0) {
67
+ this.counts.set(cause, (this.counts.get(cause) ?? 0) + count)
68
+ }
69
+ }
70
+
71
+ get total(): number {
72
+ let total = 0
73
+ for (const count of this.counts.values()) {
74
+ total += count
75
+ }
76
+ return total
77
+ }
78
+
79
+ entries(): [cause: string, count: number][] {
80
+ return [...this.counts]
81
+ }
82
+ }
83
+
84
+ /**
85
+ * The one line logged for a capture loss when nothing listens for `'error'`. It holds the lane,
86
+ * counts and causes only: never server response text, event content or uuids.
87
+ */
88
+ export function describeCaptureLoss(endpoint: CaptureEndpoint, loss: CaptureLossTally): string {
89
+ const causes = loss.entries().map(([cause, count]) => `${count} ${cause}`)
90
+ return `${loss.total} event(s) were not delivered to ${endpoint}: ${causes.join(', ')}`
91
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Capture V1 transport shared by the PostHog SDKs. It follows semver, because the SDKs depend on
3
+ * core with a caret range. `CaptureError`, `CaptureDroppedEvent`, `CaptureErrorParams` and
4
+ * `CaptureEndpoint` are also public through posthog-node.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export {
9
+ CAPTURE_COMPRESSIONS,
10
+ resolveCaptureCodec,
11
+ webCompressor,
12
+ type CaptureCodec,
13
+ type CaptureCompression,
14
+ type CaptureCompressor,
15
+ } from './compression'
16
+ export {
17
+ CaptureError,
18
+ CaptureLossTally,
19
+ describeCaptureLoss,
20
+ type CaptureDroppedEvent,
21
+ type CaptureErrorParams,
22
+ } from './errors'
23
+ export {
24
+ V1CaptureSender,
25
+ type V1CaptureSenderConfig,
26
+ type V1CaptureSenderHooks,
27
+ type V1RequestIdentity,
28
+ type V1SendDeferral,
29
+ type V1SendOptions,
30
+ } from './sender'
31
+ export { serializeV1Event, utf8Length, wireProblem, type SerializedV1Event } from './serialize'
32
+ export { readEventOptions } from './transform'
33
+ export { AI_CAPTURE_ENDPOINT, ANALYTICS_CAPTURE_ENDPOINT, type CaptureEndpoint, type V1EventOptions } from './types'
34
+ export { canonicalizeUuid, eventUuidv7 } from './uuid'