posthog-js-lite 3.5.0 → 3.5.1

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/src/context.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { utils } from '../../posthog-core'
1
+ import { utils } from 'posthog-core'
2
2
  import { version } from '../package.json'
3
3
 
4
4
  export function getContext(window: Window | undefined): any {
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
+ }
@@ -1,15 +1,12 @@
1
- import {
2
- PostHogCore,
3
- PostHogFetchOptions,
4
- PostHogFetchResponse,
5
- PostHogPersistedProperty,
6
- } from '../../posthog-core/src'
1
+ import { version } from '../package.json'
2
+
3
+ import { PostHogCore, getFetch } from 'posthog-core'
4
+ import type { PostHogFetchOptions, PostHogFetchResponse, PostHogPersistedProperty } from 'posthog-core'
5
+
7
6
  import { getContext } from './context'
8
7
  import { PostHogStorage, getStorage } from './storage'
9
- import { version } from '../package.json'
10
8
  import { PostHogOptions } from './types'
11
- import { getFetch } from 'posthog-core/src/utils'
12
- import { patch } from '../../posthog-core/src/patch'
9
+ import { patch } from './patch'
13
10
 
14
11
  export class PostHog extends PostHogCore {
15
12
  private _storage: PostHogStorage
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PostHogCoreOptions } from '../../posthog-core/src'
1
+ import type { PostHogCoreOptions } from 'posthog-core'
2
2
 
3
3
  export type PostHogOptions = {
4
4
  autocapture?: boolean
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "extends": "../tsconfig.json",
3
3
  "compilerOptions": {
4
+ "incremental": false,
4
5
  "lib": ["DOM", "ES2020", "ES2022.Error"]
5
6
  }
6
7
  }