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.
- package/dist/capture-lane/lane.d.ts +4 -4
- package/dist/capture-lane/lane.d.ts.map +1 -1
- package/dist/capture-lane/lane.js +8 -9
- package/dist/capture-lane/lane.mjs +1 -2
- package/dist/capture-lane/settings.d.ts +1 -1
- package/dist/capture-lane/settings.d.ts.map +1 -1
- package/dist/capture-lane/settings.js +3 -3
- package/dist/capture-lane/settings.mjs +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +16 -20
- package/dist/client.mjs +2 -6
- package/dist/compression.node.d.ts +1 -1
- package/dist/entrypoints/index.node.d.ts +1 -1
- package/dist/entrypoints/index.node.d.ts.map +1 -1
- package/dist/exports.d.ts +3 -3
- package/dist/exports.d.ts.map +1 -1
- package/dist/exports.js +5 -5
- package/dist/exports.mjs +1 -1
- package/dist/extensions/nestjs.d.ts.map +1 -1
- package/dist/extensions/nestjs.js +1 -0
- package/dist/extensions/nestjs.mjs +1 -0
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +4 -4
- package/src/capture-lane/lane.ts +4 -4
- package/src/capture-lane/settings.ts +1 -1
- package/src/client.ts +9 -9
- package/src/compression.node.ts +1 -1
- package/src/entrypoints/index.node.ts +1 -1
- package/src/exports.ts +3 -3
- package/src/extensions/nestjs.ts +12 -0
- package/src/types.ts +3 -3
- package/src/version.ts +1 -1
- package/dist/capture-v1/compression.d.ts +0 -18
- package/dist/capture-v1/compression.d.ts.map +0 -1
- package/dist/capture-v1/compression.js +0 -70
- package/dist/capture-v1/compression.mjs +0 -26
- package/dist/capture-v1/errors.d.ts +0 -48
- package/dist/capture-v1/errors.d.ts.map +0 -1
- package/dist/capture-v1/errors.js +0 -82
- package/dist/capture-v1/errors.mjs +0 -38
- package/dist/capture-v1/sender.d.ts +0 -110
- package/dist/capture-v1/sender.d.ts.map +0 -1
- package/dist/capture-v1/sender.js +0 -481
- package/dist/capture-v1/sender.mjs +0 -434
- package/dist/capture-v1/serialize.d.ts +0 -28
- package/dist/capture-v1/serialize.d.ts.map +0 -1
- package/dist/capture-v1/serialize.js +0 -82
- package/dist/capture-v1/serialize.mjs +0 -38
- package/dist/capture-v1/transform.d.ts +0 -19
- package/dist/capture-v1/transform.d.ts.map +0 -1
- package/dist/capture-v1/transform.js +0 -118
- package/dist/capture-v1/transform.mjs +0 -77
- package/dist/capture-v1/types.d.ts +0 -52
- package/dist/capture-v1/types.d.ts.map +0 -1
- package/dist/capture-v1/types.js +0 -44
- package/dist/capture-v1/types.mjs +0 -3
- package/dist/capture-v1/uuid.d.ts +0 -9
- package/dist/capture-v1/uuid.d.ts.map +0 -1
- package/dist/capture-v1/uuid.js +0 -75
- package/dist/capture-v1/uuid.mjs +0 -34
- package/src/capture-v1/compression.ts +0 -50
- package/src/capture-v1/errors.ts +0 -91
- package/src/capture-v1/sender.ts +0 -668
- package/src/capture-v1/serialize.ts +0 -77
- package/src/capture-v1/transform.ts +0 -134
- package/src/capture-v1/types.ts +0 -59
- package/src/capture-v1/uuid.ts +0 -53
package/src/client.ts
CHANGED
|
@@ -95,16 +95,16 @@ import ErrorTracking from './extensions/error-tracking'
|
|
|
95
95
|
import { getActiveTraceProperties } from './extensions/error-tracking/trace-context'
|
|
96
96
|
import { PostHogMemoryStorage } from './storage-memory'
|
|
97
97
|
import { ContextData, ContextOptions, IPostHogContext } from './extensions/context/types'
|
|
98
|
-
import { V1CaptureSender, type V1CaptureSenderConfig } from '
|
|
99
|
-
import { AI_CAPTURE_ENDPOINT, ANALYTICS_CAPTURE_ENDPOINT, type CaptureEndpoint } from '
|
|
100
|
-
import type { CaptureError } from '
|
|
98
|
+
import { V1CaptureSender, type V1CaptureSenderConfig } from '@posthog/core/capture-v1'
|
|
99
|
+
import { AI_CAPTURE_ENDPOINT, ANALYTICS_CAPTURE_ENDPOINT, type CaptureEndpoint } from '@posthog/core/capture-v1'
|
|
100
|
+
import type { CaptureError } from '@posthog/core/capture-v1'
|
|
101
101
|
import { RemoteConfigPayloadError } from './remote-config-errors'
|
|
102
102
|
import { CaptureLane, type CaptureLaneConfig } from './capture-lane/lane'
|
|
103
103
|
import { AI_MAX_PROPERTIES_BYTES, ANALYTICS_MAX_EVENT_BYTES, CAPTURE_BATCH_TARGET_BYTES } from './capture-lane/limits'
|
|
104
104
|
import { type CaptureSettings, resolveCaptureSettings } from './capture-lane/settings'
|
|
105
|
-
import { type CaptureCompressor, resolveCaptureCodec, webCompressor } from '
|
|
106
|
-
import { canonicalizeUuid, eventUuidv7 } from '
|
|
107
|
-
import { readEventOptions } from '
|
|
105
|
+
import { type CaptureCompressor, resolveCaptureCodec, webCompressor } from '@posthog/core/capture-v1'
|
|
106
|
+
import { canonicalizeUuid, eventUuidv7 } from '@posthog/core/capture-v1'
|
|
107
|
+
import { readEventOptions } from '@posthog/core/capture-v1'
|
|
108
108
|
import {
|
|
109
109
|
dropIdentifyStyleLegacyPersonProfile,
|
|
110
110
|
fillIdentifyStylePersonProfile,
|
|
@@ -1081,7 +1081,7 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
1081
1081
|
return {
|
|
1082
1082
|
host: this.host,
|
|
1083
1083
|
path,
|
|
1084
|
-
|
|
1084
|
+
projectToken: this.projectToken,
|
|
1085
1085
|
libraryId: this.getLibraryId(),
|
|
1086
1086
|
libraryVersion: this.getLibraryVersion(),
|
|
1087
1087
|
userAgent: this.getCustomUserAgent() || undefined,
|
|
@@ -1255,10 +1255,10 @@ export abstract class PostHogBackendClient extends PostHogCoreStateless implemen
|
|
|
1255
1255
|
* })
|
|
1256
1256
|
* if (error) {
|
|
1257
1257
|
* console.error(error.code, error.message)
|
|
1258
|
+
* } else {
|
|
1259
|
+
* const status = await client.emails.get(data.id) // later, for example from a job
|
|
1258
1260
|
* }
|
|
1259
1261
|
*
|
|
1260
|
-
* const status = await client.emails.get(data.id) // later, for example from a job
|
|
1261
|
-
*
|
|
1262
1262
|
* // From a preference center: opt out of one topic, keep the rest
|
|
1263
1263
|
* await client.emails.setPreferences({ to: 'user@example.com', topics: { newsletter: false } })
|
|
1264
1264
|
* ```
|
package/src/compression.node.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as zlib from 'node:zlib'
|
|
2
2
|
import { promisify } from 'node:util'
|
|
3
3
|
|
|
4
|
-
import type { CaptureCodec, CaptureCompressor } from '
|
|
4
|
+
import type { CaptureCodec, CaptureCompressor } from '@posthog/core/capture-v1'
|
|
5
5
|
|
|
6
6
|
type ZlibCompress = typeof zlib.gzip
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ import { ErrorTracking as CoreErrorTracking } from '@posthog/core'
|
|
|
10
10
|
import type { SpanContextManager } from '@posthog/core'
|
|
11
11
|
import { PostHogContext } from '../extensions/context/context'
|
|
12
12
|
import { AsyncLocalStorageSpanContextManager } from '../extensions/context/span-context.node'
|
|
13
|
-
import type { CaptureCompressor } from '
|
|
13
|
+
import type { CaptureCompressor } from '@posthog/core/capture-v1'
|
|
14
14
|
import { zlibCompressor } from '../compression.node'
|
|
15
15
|
import { gzipCompress } from '../gzip.node'
|
|
16
16
|
import { hostOsResourceAttributes } from '../host-os.node'
|
package/src/exports.ts
CHANGED
|
@@ -7,9 +7,9 @@ export * from './types'
|
|
|
7
7
|
export { enrichCurrentSpan } from './extensions/context/listeners'
|
|
8
8
|
|
|
9
9
|
export { FeatureFlagEvaluations } from './feature-flag-evaluations'
|
|
10
|
-
export { CaptureError } from '
|
|
11
|
-
export type { CaptureDroppedEvent, CaptureErrorParams } from '
|
|
12
|
-
export type { CaptureEndpoint } from '
|
|
10
|
+
export { CaptureError } from '@posthog/core/capture-v1'
|
|
11
|
+
export type { CaptureDroppedEvent, CaptureErrorParams } from '@posthog/core/capture-v1'
|
|
12
|
+
export type { CaptureEndpoint } from '@posthog/core/capture-v1'
|
|
13
13
|
export { EmailError } from './emails/errors'
|
|
14
14
|
export type { EmailErrorName } from './emails/errors'
|
|
15
15
|
export { RemoteConfigPayloadError } from './remote-config-errors'
|
package/src/extensions/nestjs.ts
CHANGED
|
@@ -67,6 +67,18 @@ function getExceptionStatus(exception: unknown): number | undefined {
|
|
|
67
67
|
const status = (exception as any).getStatus()
|
|
68
68
|
return typeof status === 'number' ? status : undefined
|
|
69
69
|
}
|
|
70
|
+
// Nest also accepts http-errors instances, which have status fields instead of getStatus().
|
|
71
|
+
if (
|
|
72
|
+
exception instanceof Error &&
|
|
73
|
+
'statusCode' in exception &&
|
|
74
|
+
typeof exception.statusCode === 'number' &&
|
|
75
|
+
'status' in exception &&
|
|
76
|
+
exception.status === exception.statusCode &&
|
|
77
|
+
'expose' in exception &&
|
|
78
|
+
typeof exception.expose === 'boolean'
|
|
79
|
+
) {
|
|
80
|
+
return exception.statusCode
|
|
81
|
+
}
|
|
70
82
|
return undefined
|
|
71
83
|
}
|
|
72
84
|
|
package/src/types.ts
CHANGED
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
TracesConfig,
|
|
18
18
|
} from '@posthog/core'
|
|
19
19
|
import { ContextData, ContextOptions } from './extensions/context/types'
|
|
20
|
-
import type { V1EventOptions } from '
|
|
20
|
+
import type { V1EventOptions } from '@posthog/core/capture-v1'
|
|
21
21
|
|
|
22
22
|
/** Processing options sent with an event to capture v1. */
|
|
23
23
|
export type EventOptions = V1EventOptions
|
|
@@ -1243,8 +1243,8 @@ export interface IPostHog {
|
|
|
1243
1243
|
readonly metrics: Metrics
|
|
1244
1244
|
|
|
1245
1245
|
/**
|
|
1246
|
-
* @description The `posthog.emails` API: sends transactional email from PostHog
|
|
1247
|
-
*
|
|
1246
|
+
* @description The `posthog.emails` API: sends transactional email from PostHog templates or from content
|
|
1247
|
+
* your code rendered, reads send status, and sets topic preferences. Needs `secretKey`.
|
|
1248
1248
|
*/
|
|
1249
1249
|
readonly emails: Emails
|
|
1250
1250
|
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "6.4.
|
|
1
|
+
export const version = "6.4.2"
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare const CAPTURE_COMPRESSIONS: readonly ['none', 'gzip', 'deflate', 'zstd'];
|
|
2
|
-
/** A capture request body encoding; `deflate` is zlib-wrapped, as HTTP `Content-Encoding: deflate` requires. */
|
|
3
|
-
export type CaptureCompression = (typeof CAPTURE_COMPRESSIONS)[number];
|
|
4
|
-
export type CaptureCodec = Exclude<CaptureCompression, 'none'>;
|
|
5
|
-
/** Compresses capture request bodies with the codecs one runtime provides. */
|
|
6
|
-
export interface CaptureCompressor {
|
|
7
|
-
supports(codec: CaptureCodec): boolean;
|
|
8
|
-
/** Resolves to null, or rejects, when compression fails; the sender then sends the body uncompressed. */
|
|
9
|
-
compress(payload: string, codec: CaptureCodec): Promise<Uint8Array | null>;
|
|
10
|
-
}
|
|
11
|
-
/** Uses CompressionStream, so it works wherever the runtime has one. It has no zstd. */
|
|
12
|
-
export declare const webCompressor: CaptureCompressor;
|
|
13
|
-
/**
|
|
14
|
-
* The codec a lane sends with: `requested` when the runtime has it, gzip in place of an unavailable
|
|
15
|
-
* zstd, or no compression when the runtime cannot compress at all.
|
|
16
|
-
*/
|
|
17
|
-
export declare function resolveCaptureCodec(requested: CaptureCompression, compressor: CaptureCompressor, onZstdUnavailable: (fallback: CaptureCompression) => void): CaptureCompression;
|
|
18
|
-
//# sourceMappingURL=compression.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compression.d.ts","sourceRoot":"","sources":["../../src/capture-v1/compression.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,YAAI,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAU,CAAA;AAEhF,gHAAgH;AAChH,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtE,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;AAE9D,8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAA;IACtC,yGAAyG;IACzG,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;CAC3E;AAED,wFAAwF;AACxF,eAAO,MAAM,aAAa,EAAE,iBAa3B,CAAA;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,kBAAkB,EAC7B,UAAU,EAAE,iBAAiB,EAC7B,iBAAiB,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,GACxD,kBAAkB,CASpB"}
|
|
@@ -1,70 +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
|
-
CAPTURE_COMPRESSIONS: ()=>CAPTURE_COMPRESSIONS,
|
|
32
|
-
resolveCaptureCodec: ()=>resolveCaptureCodec,
|
|
33
|
-
webCompressor: ()=>webCompressor
|
|
34
|
-
});
|
|
35
|
-
const core_namespaceObject = require("@posthog/core");
|
|
36
|
-
const CAPTURE_COMPRESSIONS = [
|
|
37
|
-
'none',
|
|
38
|
-
'gzip',
|
|
39
|
-
'deflate',
|
|
40
|
-
'zstd'
|
|
41
|
-
];
|
|
42
|
-
const webCompressor = {
|
|
43
|
-
supports: (codec)=>'zstd' !== codec && (0, core_namespaceObject.isGzipSupported)(),
|
|
44
|
-
async compress (payload, codec) {
|
|
45
|
-
if ('gzip' === codec) {
|
|
46
|
-
const compressed = await (0, core_namespaceObject.gzipCompress)(payload, false);
|
|
47
|
-
return compressed && new Uint8Array(await compressed.arrayBuffer());
|
|
48
|
-
}
|
|
49
|
-
if ('deflate' !== codec) return null;
|
|
50
|
-
const stream = new Response(payload).body.pipeThrough(new globalThis.CompressionStream('deflate'));
|
|
51
|
-
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
function resolveCaptureCodec(requested, compressor, onZstdUnavailable) {
|
|
55
|
-
if ('none' === requested || compressor.supports(requested)) return requested;
|
|
56
|
-
const fallback = compressor.supports('gzip') ? 'gzip' : 'none';
|
|
57
|
-
if ('zstd' === requested) onZstdUnavailable(fallback);
|
|
58
|
-
return fallback;
|
|
59
|
-
}
|
|
60
|
-
exports.CAPTURE_COMPRESSIONS = __webpack_exports__.CAPTURE_COMPRESSIONS;
|
|
61
|
-
exports.resolveCaptureCodec = __webpack_exports__.resolveCaptureCodec;
|
|
62
|
-
exports.webCompressor = __webpack_exports__.webCompressor;
|
|
63
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
64
|
-
"CAPTURE_COMPRESSIONS",
|
|
65
|
-
"resolveCaptureCodec",
|
|
66
|
-
"webCompressor"
|
|
67
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
68
|
-
Object.defineProperty(exports, '__esModule', {
|
|
69
|
-
value: true
|
|
70
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { gzipCompress, isGzipSupported } from "@posthog/core";
|
|
2
|
-
const CAPTURE_COMPRESSIONS = [
|
|
3
|
-
'none',
|
|
4
|
-
'gzip',
|
|
5
|
-
'deflate',
|
|
6
|
-
'zstd'
|
|
7
|
-
];
|
|
8
|
-
const webCompressor = {
|
|
9
|
-
supports: (codec)=>'zstd' !== codec && isGzipSupported(),
|
|
10
|
-
async compress (payload, codec) {
|
|
11
|
-
if ('gzip' === codec) {
|
|
12
|
-
const compressed = await gzipCompress(payload, false);
|
|
13
|
-
return compressed && new Uint8Array(await compressed.arrayBuffer());
|
|
14
|
-
}
|
|
15
|
-
if ('deflate' !== codec) return null;
|
|
16
|
-
const stream = new Response(payload).body.pipeThrough(new globalThis.CompressionStream('deflate'));
|
|
17
|
-
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
function resolveCaptureCodec(requested, compressor, onZstdUnavailable) {
|
|
21
|
-
if ('none' === requested || compressor.supports(requested)) return requested;
|
|
22
|
-
const fallback = compressor.supports('gzip') ? 'gzip' : 'none';
|
|
23
|
-
if ('zstd' === requested) onZstdUnavailable(fallback);
|
|
24
|
-
return fallback;
|
|
25
|
-
}
|
|
26
|
-
export { CAPTURE_COMPRESSIONS, resolveCaptureCodec, webCompressor };
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { CaptureEndpoint } from './types';
|
|
2
|
-
/** A single event the server explicitly rejected (`drop`). */
|
|
3
|
-
export interface CaptureDroppedEvent {
|
|
4
|
-
uuid: string;
|
|
5
|
-
details?: string;
|
|
6
|
-
}
|
|
7
|
-
export interface CaptureErrorParams {
|
|
8
|
-
/** The capture lane the batch was sent to. */
|
|
9
|
-
endpoint: CaptureEndpoint;
|
|
10
|
-
requestId: string;
|
|
11
|
-
/** Events the server rejected outright (billing/validation). */
|
|
12
|
-
drops: CaptureDroppedEvent[];
|
|
13
|
-
/** UUIDs of events still pending `retry` after the attempt budget was exhausted, or lost to a batch-level failure. */
|
|
14
|
-
retryExhausted: string[];
|
|
15
|
-
/** The underlying transport/HTTP/parse failure, when the whole batch failed. */
|
|
16
|
-
cause?: unknown;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Surfaced on the client error channel whenever a capture batch did not
|
|
20
|
-
* fully deliver: some events were `drop`ped, some `retry` events outlived the
|
|
21
|
-
* attempt budget, or the batch hit a terminal transport/HTTP/parse failure.
|
|
22
|
-
*
|
|
23
|
-
* A 2xx with drops is still a partial failure and is reported here — a
|
|
24
|
-
* successful HTTP status does not mean every event was accepted.
|
|
25
|
-
*/
|
|
26
|
-
export declare class CaptureError extends Error {
|
|
27
|
-
name: string;
|
|
28
|
-
readonly endpoint: CaptureEndpoint;
|
|
29
|
-
readonly requestId: string;
|
|
30
|
-
readonly drops: CaptureDroppedEvent[];
|
|
31
|
-
readonly retryExhausted: string[];
|
|
32
|
-
cause?: unknown;
|
|
33
|
-
constructor({ endpoint, requestId, drops, retryExhausted, cause }: CaptureErrorParams);
|
|
34
|
-
private static buildMessage;
|
|
35
|
-
}
|
|
36
|
-
/** Counts of undelivered events by cause, in the order the causes first occurred. */
|
|
37
|
-
export declare class CaptureLossTally {
|
|
38
|
-
private readonly counts;
|
|
39
|
-
add(cause: string, count: number): void;
|
|
40
|
-
get total(): number;
|
|
41
|
-
entries(): [cause: string, count: number][];
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* The one line logged for a capture loss when nothing listens for `'error'`. It holds the lane,
|
|
45
|
-
* counts and causes only: never server response text, event content or uuids.
|
|
46
|
-
*/
|
|
47
|
-
export declare function describeCaptureLoss(endpoint: CaptureEndpoint, loss: CaptureLossTally): string;
|
|
48
|
-
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/capture-v1/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,8DAA8D;AAC9D,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,QAAQ,EAAE,eAAe,CAAA;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,KAAK,EAAE,mBAAmB,EAAE,CAAA;IAC5B,sHAAsH;IACtH,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;;;;;;GAOG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,SAAiB;IACrB,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAA;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,mBAAmB,EAAE,CAAA;IACrC,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAA;IACjC,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE,kBAAkB,EAOpF;IAED,OAAO,CAAC,MAAM,CAAC,YAAY;CAa5B;AAED,qFAAqF;AACrF,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IAEnD,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAItC;IAED,IAAI,KAAK,IAAI,MAAM,CAMlB;IAED,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,CAE1C;CACF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAG7F"}
|
|
@@ -1,82 +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
|
-
class CaptureError extends Error {
|
|
31
|
-
constructor({ endpoint, requestId, drops, retryExhausted, cause }){
|
|
32
|
-
super(CaptureError.buildMessage(endpoint, requestId, drops, retryExhausted, cause)), this.name = 'CaptureError';
|
|
33
|
-
this.endpoint = endpoint;
|
|
34
|
-
this.requestId = requestId;
|
|
35
|
-
this.drops = drops;
|
|
36
|
-
this.retryExhausted = retryExhausted;
|
|
37
|
-
this.cause = cause;
|
|
38
|
-
}
|
|
39
|
-
static buildMessage(endpoint, requestId, drops, retryExhausted, cause) {
|
|
40
|
-
let message = `Capture batch ${requestId} to ${endpoint} did not fully deliver: ${drops.length} dropped, ${retryExhausted.length} undelivered`;
|
|
41
|
-
if (cause instanceof Error) message += ` (${cause.message})`;
|
|
42
|
-
return message;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
class CaptureLossTally {
|
|
46
|
-
add(cause, count) {
|
|
47
|
-
if (count > 0) this.counts.set(cause, (this.counts.get(cause) ?? 0) + count);
|
|
48
|
-
}
|
|
49
|
-
get total() {
|
|
50
|
-
let total = 0;
|
|
51
|
-
for (const count of this.counts.values())total += count;
|
|
52
|
-
return total;
|
|
53
|
-
}
|
|
54
|
-
entries() {
|
|
55
|
-
return [
|
|
56
|
-
...this.counts
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
constructor(){
|
|
60
|
-
this.counts = new Map();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function describeCaptureLoss(endpoint, loss) {
|
|
64
|
-
const causes = loss.entries().map(([cause, count])=>`${count} ${cause}`);
|
|
65
|
-
return `${loss.total} event(s) were not delivered to ${endpoint}: ${causes.join(', ')}`;
|
|
66
|
-
}
|
|
67
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
68
|
-
CaptureError: ()=>CaptureError,
|
|
69
|
-
CaptureLossTally: ()=>CaptureLossTally,
|
|
70
|
-
describeCaptureLoss: ()=>describeCaptureLoss
|
|
71
|
-
});
|
|
72
|
-
exports.CaptureError = __webpack_exports__.CaptureError;
|
|
73
|
-
exports.CaptureLossTally = __webpack_exports__.CaptureLossTally;
|
|
74
|
-
exports.describeCaptureLoss = __webpack_exports__.describeCaptureLoss;
|
|
75
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
76
|
-
"CaptureError",
|
|
77
|
-
"CaptureLossTally",
|
|
78
|
-
"describeCaptureLoss"
|
|
79
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
80
|
-
Object.defineProperty(exports, '__esModule', {
|
|
81
|
-
value: true
|
|
82
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
class CaptureError extends Error {
|
|
2
|
-
constructor({ endpoint, requestId, drops, retryExhausted, cause }){
|
|
3
|
-
super(CaptureError.buildMessage(endpoint, requestId, drops, retryExhausted, cause)), this.name = 'CaptureError';
|
|
4
|
-
this.endpoint = endpoint;
|
|
5
|
-
this.requestId = requestId;
|
|
6
|
-
this.drops = drops;
|
|
7
|
-
this.retryExhausted = retryExhausted;
|
|
8
|
-
this.cause = cause;
|
|
9
|
-
}
|
|
10
|
-
static buildMessage(endpoint, requestId, drops, retryExhausted, cause) {
|
|
11
|
-
let message = `Capture batch ${requestId} to ${endpoint} did not fully deliver: ${drops.length} dropped, ${retryExhausted.length} undelivered`;
|
|
12
|
-
if (cause instanceof Error) message += ` (${cause.message})`;
|
|
13
|
-
return message;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
class CaptureLossTally {
|
|
17
|
-
add(cause, count) {
|
|
18
|
-
if (count > 0) this.counts.set(cause, (this.counts.get(cause) ?? 0) + count);
|
|
19
|
-
}
|
|
20
|
-
get total() {
|
|
21
|
-
let total = 0;
|
|
22
|
-
for (const count of this.counts.values())total += count;
|
|
23
|
-
return total;
|
|
24
|
-
}
|
|
25
|
-
entries() {
|
|
26
|
-
return [
|
|
27
|
-
...this.counts
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
constructor(){
|
|
31
|
-
this.counts = new Map();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function describeCaptureLoss(endpoint, loss) {
|
|
35
|
-
const causes = loss.entries().map(([cause, count])=>`${count} ${cause}`);
|
|
36
|
-
return `${loss.total} event(s) were not delivered to ${endpoint}: ${causes.join(', ')}`;
|
|
37
|
-
}
|
|
38
|
-
export { CaptureError, CaptureLossTally, describeCaptureLoss };
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { type FetchLike } from '@posthog/core';
|
|
2
|
-
import { type CaptureCodec, type CaptureCompression } from './compression';
|
|
3
|
-
import { CaptureError } from './errors';
|
|
4
|
-
import { type SerializedV1Event } from './serialize';
|
|
5
|
-
import type { CaptureEndpoint } from './types';
|
|
6
|
-
/** Wait before the first retry; each later retry doubles it. */
|
|
7
|
-
export declare const RETRY_BASE_DELAY_MS = 100;
|
|
8
|
-
/** Ceiling for every retry wait, including one raised by `Retry-After`. */
|
|
9
|
-
export declare const MAX_RETRY_DELAY_MS = 30000;
|
|
10
|
-
/** Drop details for a copy of an event the server dropped as a duplicate of an earlier one in the request. */
|
|
11
|
-
export declare const DUPLICATE_EVENT_UUID = "duplicate_event_uuid";
|
|
12
|
-
export interface V1CaptureSenderConfig {
|
|
13
|
-
host: string;
|
|
14
|
-
/** The capture lane this sender posts to. */
|
|
15
|
-
path: CaptureEndpoint;
|
|
16
|
-
apiKey: string;
|
|
17
|
-
/** The `PostHog-Sdk-Info` library name. PostHog fills `$lib` from it only for an event that has no `$lib`. */
|
|
18
|
-
libraryId: string;
|
|
19
|
-
libraryVersion: string;
|
|
20
|
-
/** Value for the `User-Agent` header, if the runtime allows setting it. */
|
|
21
|
-
userAgent?: string;
|
|
22
|
-
historicalMigration: boolean;
|
|
23
|
-
/** The body encoding; a body that fails to compress is sent uncompressed. */
|
|
24
|
-
compression: CaptureCompression;
|
|
25
|
-
requestTimeoutMs: number;
|
|
26
|
-
/** Retries after the first attempt. */
|
|
27
|
-
maxRetries: number;
|
|
28
|
-
isDebug?: boolean;
|
|
29
|
-
}
|
|
30
|
-
export interface V1CaptureSenderHooks {
|
|
31
|
-
fetch: FetchLike;
|
|
32
|
-
/**
|
|
33
|
-
* Surfaces partial/terminal delivery failures on the client error channel, at most once per
|
|
34
|
-
* batch. `summary` is one line with counts and causes only, for when nothing listens.
|
|
35
|
-
*/
|
|
36
|
-
onError: (error: CaptureError, summary: string) => void;
|
|
37
|
-
now?: () => number;
|
|
38
|
-
/** Waits between attempts. The sender stops waiting when `signal` aborts, even if this does not. */
|
|
39
|
-
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
40
|
-
generateRequestId?: () => string;
|
|
41
|
-
/** Uniform in [0, 1); sets the jitter of each retry wait. */
|
|
42
|
-
random?: () => number;
|
|
43
|
-
compress?: (payload: string, codec: CaptureCodec) => Promise<Uint8Array | null>;
|
|
44
|
-
}
|
|
45
|
-
export interface V1SendOptions {
|
|
46
|
-
/** Aborting stops the current attempt and every later one; the pending events come back as unsent. */
|
|
47
|
-
signal?: AbortSignal;
|
|
48
|
-
/**
|
|
49
|
-
* When true, events whose last attempt got no HTTP response (or were cut off by `signal`) are
|
|
50
|
-
* returned to the caller unreported, so it can queue them again. When false they are reported
|
|
51
|
-
* as undelivered.
|
|
52
|
-
*/
|
|
53
|
-
keepUnsent?: boolean;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Sends already-serialized events to one Capture V1 lane (`config.path`),
|
|
57
|
-
* owning the full attempt loop: per-event partial retry, exponential backoff
|
|
58
|
-
* clamped against `Retry-After`, v1 status classification, and surfacing drops
|
|
59
|
-
* / undelivered events on the error channel. Used by both the batched and
|
|
60
|
-
* immediate send paths.
|
|
61
|
-
*
|
|
62
|
-
* Never throws for a handled outcome: after exhausting its own attempt budget it
|
|
63
|
-
* reports the failure via `onError` and resolves. Only events that never got an
|
|
64
|
-
* HTTP response can come back to the caller, and only with `keepUnsent`.
|
|
65
|
-
*/
|
|
66
|
-
export declare class V1CaptureSender {
|
|
67
|
-
private readonly config;
|
|
68
|
-
private readonly hostOrigin;
|
|
69
|
-
private readonly fetchFn;
|
|
70
|
-
private readonly onError;
|
|
71
|
-
private readonly now;
|
|
72
|
-
private readonly sleep;
|
|
73
|
-
private readonly generateRequestId;
|
|
74
|
-
private readonly random;
|
|
75
|
-
private readonly compress;
|
|
76
|
-
constructor(config: V1CaptureSenderConfig, hooks: V1CaptureSenderHooks);
|
|
77
|
-
/** Sends `events` and resolves with the ones to queue again (always empty unless `keepUnsent`). */
|
|
78
|
-
send<T extends SerializedV1Event>(events: T[], options?: V1SendOptions): Promise<T[]>;
|
|
79
|
-
private sleepUnlessAborted;
|
|
80
|
-
private sendOnce;
|
|
81
|
-
/**
|
|
82
|
-
* Sends with `redirect: 'manual'` and follows 307 and 308 to the configured host's origin, at most
|
|
83
|
-
* `MAX_REDIRECTS` times, with the same method, headers and body. A fetch that follows redirects
|
|
84
|
-
* itself still works: its final response is not a redirect.
|
|
85
|
-
*/
|
|
86
|
-
private fetchFollowingRedirects;
|
|
87
|
-
/** Compresses `payload` with the configured codec and sets `Content-Encoding` to match. */
|
|
88
|
-
private encodeBody;
|
|
89
|
-
private buildHeaders;
|
|
90
|
-
/**
|
|
91
|
-
* Partition the pending events against a 2xx result map: `drop` accumulates as
|
|
92
|
-
* a terminal failure, `retry` is returned for the next attempt, and
|
|
93
|
-
* `ok`/`warning`/unknown/absent are terminal successes.
|
|
94
|
-
*/
|
|
95
|
-
private classify;
|
|
96
|
-
/** The wait after failed attempt `attempt` (1-based): jittered exponential backoff, raised to `Retry-After`. */
|
|
97
|
-
private backoffDelay;
|
|
98
|
-
/** Parse `Retry-After` (delta-seconds or HTTP-date). Non-positive/past values are ignored. */
|
|
99
|
-
private parseRetryAfter;
|
|
100
|
-
private parseResponse;
|
|
101
|
-
private buildHttpError;
|
|
102
|
-
private surfaceBatchFailure;
|
|
103
|
-
private surfacePartialDrops;
|
|
104
|
-
private report;
|
|
105
|
-
/** A failure without an HTTP response, named by type only: its message can carry server or proxy text. */
|
|
106
|
-
private describeTransportFailure;
|
|
107
|
-
private captureError;
|
|
108
|
-
private cancelBody;
|
|
109
|
-
}
|
|
110
|
-
//# sourceMappingURL=sender.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sender.d.ts","sourceRoot":"","sources":["../../src/capture-v1/sender.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAA+D,MAAM,eAAe,CAAA;AAE3G,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,kBAAkB,EAAiB,MAAM,eAAe,CAAA;AACzF,OAAO,EACL,YAAY,EAKb,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,KAAK,iBAAiB,EAAe,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAE,eAAe,EAAkC,MAAM,SAAS,CAAA;AAG9E,gEAAgE;AAChE,eAAO,MAAM,mBAAmB,MAAM,CAAA;AACtC,2EAA2E;AAC3E,eAAO,MAAM,kBAAkB,QAAS,CAAA;AAuDxC,8GAA8G;AAC9G,eAAO,MAAM,oBAAoB,yBAAyB,CAAA;AAE1D,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ,6CAA6C;IAC7C,IAAI,EAAE,eAAe,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,8GAA8G;IAC9G,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,CAAA;IACtB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,mBAAmB,EAAE,OAAO,CAAA;IAC5B,6EAA6E;IAC7E,WAAW,EAAE,kBAAkB,CAAA;IAC/B,gBAAgB,EAAE,MAAM,CAAA;IACxB,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,SAAS,CAAA;IAChB;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IACvD,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;IAClB,oGAAoG;IACpG,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3D,iBAAiB,CAAC,EAAE,MAAM,MAAM,CAAA;IAChC,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;CAChF;AAED,MAAM,WAAW,aAAa;IAC5B,sGAAsG;IACtG,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAeD;;;;;;;;;;GAUG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAW;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgD;IACxE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAc;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqD;IAC3E,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAc;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsE;IAE/F,YAAY,MAAM,EAAE,qBAAqB,EAAE,KAAK,EAAE,oBAAoB,EAUrE;IAED,mGAAmG;IAC7F,IAAI,CAAC,CAAC,SAAS,iBAAiB,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CA0H9F;YAEa,kBAAkB;YAmBlB,QAAQ;IAmGtB;;;;OAIG;YACW,uBAAuB;IA6CrC,2FAA2F;YAC7E,UAAU;IAmBxB,OAAO,CAAC,YAAY;IAiBpB;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IAuChB,gHAAgH;IAChH,OAAO,CAAC,YAAY;IAUpB,8FAA8F;IAC9F,OAAO,CAAC,eAAe;YAkBT,aAAa;YAab,cAAc;IAe5B,OAAO,CAAC,mBAAmB;IAe3B,OAAO,CAAC,mBAAmB;IAM3B,OAAO,CAAC,MAAM;IAId,0GAA0G;IAC1G,OAAO,CAAC,wBAAwB;IAWhC,OAAO,CAAC,YAAY;YAIN,UAAU;CAOzB"}
|