posthog-js-lite 3.5.0 → 3.6.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.
- package/CHANGELOG.md +13 -0
- package/lib/{index.cjs.js → index.cjs} +380 -173
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.ts +668 -642
- package/lib/{index.esm.js → index.mjs} +380 -173
- package/lib/index.mjs.map +1 -0
- package/package.json +3 -3
- package/src/context.ts +1 -1
- package/src/patch.ts +50 -0
- package/src/posthog-web.ts +9 -7
- package/src/types.ts +1 -1
- package/tsconfig.json +1 -0
- package/lib/index.cjs.js.map +0 -1
- package/lib/index.esm.js.map +0 -1
- package/lib/posthog-core/src/eventemitter.d.ts +0 -8
- package/lib/posthog-core/src/featureFlagUtils.d.ts +0 -34
- package/lib/posthog-core/src/index.d.ts +0 -239
- package/lib/posthog-core/src/lz-string.d.ts +0 -8
- package/lib/posthog-core/src/patch.d.ts +0 -3
- package/lib/posthog-core/src/types.d.ts +0 -422
- package/lib/posthog-core/src/utils.d.ts +0 -19
- package/lib/posthog-core/src/vendor/uuidv7.d.ts +0 -179
- package/lib/posthog-web/index.d.ts +0 -3
- package/lib/posthog-web/src/context.d.ts +0 -1
- package/lib/posthog-web/src/posthog-web.d.ts +0 -19
- package/lib/posthog-web/src/storage.d.ts +0 -10
- package/lib/posthog-web/src/types.d.ts +0 -7
package/package.json
CHANGED
package/src/context.ts
CHANGED
package/src/patch.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// import { patch } from 'rrweb/typings/utils'
|
|
2
|
+
// copied from: https://github.com/PostHog/posthog-js/blob/main/src/extensions/replay/rrweb-plugins/patch.ts
|
|
3
|
+
// which was copied from https://github.com/rrweb-io/rrweb/blob/8aea5b00a4dfe5a6f59bd2ae72bb624f45e51e81/packages/rrweb/src/utils.ts#L129
|
|
4
|
+
// which was copied from https://github.com/getsentry/sentry-javascript/blob/b2109071975af8bf0316d3b5b38f519bdaf5dc15/packages/utils/src/object.ts
|
|
5
|
+
|
|
6
|
+
// copied from: https://github.com/PostHog/posthog-js/blob/main/react/src/utils/type-utils.ts#L4
|
|
7
|
+
export const isFunction = function (f: any): f is (...args: any[]) => any {
|
|
8
|
+
return typeof f === 'function'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function patch(
|
|
12
|
+
source: { [key: string]: any },
|
|
13
|
+
name: string,
|
|
14
|
+
replacement: (...args: unknown[]) => unknown
|
|
15
|
+
): () => void {
|
|
16
|
+
try {
|
|
17
|
+
if (!(name in source)) {
|
|
18
|
+
return () => {
|
|
19
|
+
//
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const original = source[name] as () => unknown
|
|
24
|
+
const wrapped = replacement(original)
|
|
25
|
+
|
|
26
|
+
// Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work
|
|
27
|
+
// otherwise it'll throw "TypeError: Object.defineProperties called on non-object"
|
|
28
|
+
if (isFunction(wrapped)) {
|
|
29
|
+
wrapped.prototype = wrapped.prototype || {}
|
|
30
|
+
Object.defineProperties(wrapped, {
|
|
31
|
+
__posthog_wrapped__: {
|
|
32
|
+
enumerable: false,
|
|
33
|
+
value: true,
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
source[name] = wrapped
|
|
39
|
+
|
|
40
|
+
return () => {
|
|
41
|
+
source[name] = original
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
return () => {
|
|
45
|
+
//
|
|
46
|
+
}
|
|
47
|
+
// This can throw if multiple fill happens on a global object like XMLHttpRequest
|
|
48
|
+
// Fixes https://github.com/getsentry/sentry-javascript/issues/2043
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/posthog-web.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { version } from '../package.json'
|
|
2
|
+
|
|
3
|
+
import { PostHogCore, getFetch } from 'posthog-core'
|
|
4
|
+
import type {
|
|
5
|
+
PostHogEventProperties,
|
|
3
6
|
PostHogFetchOptions,
|
|
4
7
|
PostHogFetchResponse,
|
|
5
8
|
PostHogPersistedProperty,
|
|
6
|
-
} from '
|
|
9
|
+
} from 'posthog-core'
|
|
10
|
+
|
|
7
11
|
import { getContext } from './context'
|
|
8
12
|
import { PostHogStorage, getStorage } from './storage'
|
|
9
|
-
import { version } from '../package.json'
|
|
10
13
|
import { PostHogOptions } from './types'
|
|
11
|
-
import {
|
|
12
|
-
import { patch } from '../../posthog-core/src/patch'
|
|
14
|
+
import { patch } from './patch'
|
|
13
15
|
|
|
14
16
|
export class PostHog extends PostHogCore {
|
|
15
17
|
private _storage: PostHogStorage
|
|
@@ -85,7 +87,7 @@ export class PostHog extends PostHogCore {
|
|
|
85
87
|
return
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
getCommonEventProperties():
|
|
90
|
+
getCommonEventProperties(): PostHogEventProperties {
|
|
89
91
|
return {
|
|
90
92
|
...super.getCommonEventProperties(),
|
|
91
93
|
...getContext(this.getWindow()),
|
package/src/types.ts
CHANGED