posthog-node 6.4.0 → 6.4.2

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 (71) hide show
  1. package/dist/capture-lane/lane.d.ts +4 -4
  2. package/dist/capture-lane/lane.d.ts.map +1 -1
  3. package/dist/capture-lane/lane.js +8 -9
  4. package/dist/capture-lane/lane.mjs +1 -2
  5. package/dist/capture-lane/settings.d.ts +1 -1
  6. package/dist/capture-lane/settings.d.ts.map +1 -1
  7. package/dist/capture-lane/settings.js +3 -3
  8. package/dist/capture-lane/settings.mjs +1 -1
  9. package/dist/client.d.ts +3 -3
  10. package/dist/client.js +16 -20
  11. package/dist/client.mjs +2 -6
  12. package/dist/compression.node.d.ts +1 -1
  13. package/dist/entrypoints/index.node.d.ts +1 -1
  14. package/dist/entrypoints/index.node.d.ts.map +1 -1
  15. package/dist/exports.d.ts +3 -3
  16. package/dist/exports.d.ts.map +1 -1
  17. package/dist/exports.js +5 -5
  18. package/dist/exports.mjs +1 -1
  19. package/dist/extensions/nestjs.d.ts.map +1 -1
  20. package/dist/extensions/nestjs.js +1 -0
  21. package/dist/extensions/nestjs.mjs +1 -0
  22. package/dist/types.d.ts +3 -3
  23. package/dist/types.d.ts.map +1 -1
  24. package/dist/version.d.ts +1 -1
  25. package/dist/version.js +1 -1
  26. package/dist/version.mjs +1 -1
  27. package/package.json +4 -4
  28. package/src/capture-lane/lane.ts +4 -4
  29. package/src/capture-lane/settings.ts +1 -1
  30. package/src/client.ts +9 -9
  31. package/src/compression.node.ts +1 -1
  32. package/src/entrypoints/index.node.ts +1 -1
  33. package/src/exports.ts +3 -3
  34. package/src/extensions/nestjs.ts +12 -0
  35. package/src/types.ts +3 -3
  36. package/src/version.ts +1 -1
  37. package/dist/capture-v1/compression.d.ts +0 -18
  38. package/dist/capture-v1/compression.d.ts.map +0 -1
  39. package/dist/capture-v1/compression.js +0 -70
  40. package/dist/capture-v1/compression.mjs +0 -26
  41. package/dist/capture-v1/errors.d.ts +0 -48
  42. package/dist/capture-v1/errors.d.ts.map +0 -1
  43. package/dist/capture-v1/errors.js +0 -82
  44. package/dist/capture-v1/errors.mjs +0 -38
  45. package/dist/capture-v1/sender.d.ts +0 -110
  46. package/dist/capture-v1/sender.d.ts.map +0 -1
  47. package/dist/capture-v1/sender.js +0 -481
  48. package/dist/capture-v1/sender.mjs +0 -434
  49. package/dist/capture-v1/serialize.d.ts +0 -28
  50. package/dist/capture-v1/serialize.d.ts.map +0 -1
  51. package/dist/capture-v1/serialize.js +0 -82
  52. package/dist/capture-v1/serialize.mjs +0 -38
  53. package/dist/capture-v1/transform.d.ts +0 -19
  54. package/dist/capture-v1/transform.d.ts.map +0 -1
  55. package/dist/capture-v1/transform.js +0 -118
  56. package/dist/capture-v1/transform.mjs +0 -77
  57. package/dist/capture-v1/types.d.ts +0 -52
  58. package/dist/capture-v1/types.d.ts.map +0 -1
  59. package/dist/capture-v1/types.js +0 -44
  60. package/dist/capture-v1/types.mjs +0 -3
  61. package/dist/capture-v1/uuid.d.ts +0 -9
  62. package/dist/capture-v1/uuid.d.ts.map +0 -1
  63. package/dist/capture-v1/uuid.js +0 -75
  64. package/dist/capture-v1/uuid.mjs +0 -34
  65. package/src/capture-v1/compression.ts +0 -50
  66. package/src/capture-v1/errors.ts +0 -91
  67. package/src/capture-v1/sender.ts +0 -668
  68. package/src/capture-v1/serialize.ts +0 -77
  69. package/src/capture-v1/transform.ts +0 -134
  70. package/src/capture-v1/types.ts +0 -59
  71. package/src/capture-v1/uuid.ts +0 -53
@@ -1,118 +0,0 @@
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 core_namespaceObject = require("@posthog/core");
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(core_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
- });
@@ -1,77 +0,0 @@
1
- import { EVENT_OPTION_LEGACY_PROPERTIES } from "@posthog/core";
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 };
@@ -1,52 +0,0 @@
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;
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
@@ -1 +0,0 @@
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,44 +0,0 @@
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
- });
@@ -1,3 +0,0 @@
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 };
@@ -1,9 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,75 +0,0 @@
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
- });
@@ -1,34 +0,0 @@
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 };
@@ -1,50 +0,0 @@
1
- import { gzipCompress, isGzipSupported } from '@posthog/core'
2
-
3
- export const CAPTURE_COMPRESSIONS = ['none', 'gzip', 'deflate', 'zstd'] as const
4
-
5
- /** A capture request body encoding; `deflate` is zlib-wrapped, as HTTP `Content-Encoding: deflate` requires. */
6
- export type CaptureCompression = (typeof CAPTURE_COMPRESSIONS)[number]
7
-
8
- export type CaptureCodec = Exclude<CaptureCompression, 'none'>
9
-
10
- /** Compresses capture request bodies with the codecs one runtime provides. */
11
- export interface CaptureCompressor {
12
- supports(codec: CaptureCodec): boolean
13
- /** Resolves to null, or rejects, when compression fails; the sender then sends the body uncompressed. */
14
- compress(payload: string, codec: CaptureCodec): Promise<Uint8Array | null>
15
- }
16
-
17
- /** Uses CompressionStream, so it works wherever the runtime has one. It has no zstd. */
18
- export const webCompressor: CaptureCompressor = {
19
- supports: (codec) => codec !== 'zstd' && isGzipSupported(),
20
- async compress(payload, codec) {
21
- if (codec === 'gzip') {
22
- const compressed = await gzipCompress(payload, false)
23
- return compressed && new Uint8Array(await compressed.arrayBuffer())
24
- }
25
- if (codec !== 'deflate') {
26
- return null
27
- }
28
- const stream = new Response(payload).body!.pipeThrough(new globalThis.CompressionStream('deflate'))
29
- return new Uint8Array(await new Response(stream).arrayBuffer())
30
- },
31
- }
32
-
33
- /**
34
- * The codec a lane sends with: `requested` when the runtime has it, gzip in place of an unavailable
35
- * zstd, or no compression when the runtime cannot compress at all.
36
- */
37
- export function resolveCaptureCodec(
38
- requested: CaptureCompression,
39
- compressor: CaptureCompressor,
40
- onZstdUnavailable: (fallback: CaptureCompression) => void
41
- ): CaptureCompression {
42
- if (requested === 'none' || compressor.supports(requested)) {
43
- return requested
44
- }
45
- const fallback = compressor.supports('gzip') ? 'gzip' : 'none'
46
- if (requested === 'zstd') {
47
- onZstdUnavailable(fallback)
48
- }
49
- return fallback
50
- }
@@ -1,91 +0,0 @@
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
- }