@posthog/browser-common 0.1.0 → 0.2.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/README.md +23 -8
- package/dist/config.d.ts +9 -0
- package/dist/config.js +43 -0
- package/dist/config.mjs +9 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +44 -0
- package/dist/constants.mjs +4 -0
- package/dist/token.d.ts +13 -12
- package/dist/utils/array-at-polyfill.d.ts +1 -0
- package/dist/utils/array-at-polyfill.js +16 -0
- package/dist/utils/array-at-polyfill.mjs +11 -0
- package/dist/utils/autocapture-utils.d.ts +23 -0
- package/dist/utils/autocapture-utils.js +479 -0
- package/dist/utils/autocapture-utils.mjs +385 -0
- package/dist/utils/blocked-uas.d.ts +17 -0
- package/dist/utils/blocked-uas.js +54 -0
- package/dist/utils/blocked-uas.mjs +14 -0
- package/dist/utils/cookie-utils.d.ts +1 -0
- package/dist/utils/cookie-utils.js +49 -0
- package/dist/utils/cookie-utils.mjs +15 -0
- package/dist/utils/device-model-utils.d.ts +8 -0
- package/dist/utils/device-model-utils.js +52 -0
- package/dist/utils/device-model-utils.mjs +18 -0
- package/dist/utils/element-utils.d.ts +5 -0
- package/dist/utils/element-utils.js +67 -0
- package/dist/utils/element-utils.mjs +21 -0
- package/dist/utils/elements-chain-utils.d.ts +4 -0
- package/dist/utils/elements-chain-utils.js +79 -0
- package/dist/utils/elements-chain-utils.mjs +36 -0
- package/dist/utils/encode-utils.d.ts +8 -0
- package/dist/utils/encode-utils.js +39 -0
- package/dist/utils/encode-utils.mjs +5 -0
- package/dist/utils/event-utils.d.ts +24 -0
- package/dist/utils/event-utils.js +344 -0
- package/dist/utils/event-utils.mjs +246 -0
- package/dist/utils/general-utils.d.ts +30 -0
- package/dist/utils/general-utils.js +191 -0
- package/dist/utils/general-utils.mjs +118 -0
- package/dist/utils/globals.d.ts +25 -0
- package/dist/utils/globals.js +75 -0
- package/dist/utils/globals.mjs +14 -0
- package/dist/utils/logger.d.ts +16 -0
- package/dist/utils/logger.js +83 -0
- package/dist/utils/logger.mjs +36 -0
- package/dist/utils/matcher-utils.d.ts +3 -0
- package/dist/utils/matcher-utils.js +63 -0
- package/dist/utils/matcher-utils.mjs +26 -0
- package/dist/utils/property-utils.d.ts +23 -0
- package/dist/utils/property-utils.js +108 -0
- package/dist/utils/property-utils.mjs +65 -0
- package/dist/utils/prototype-utils.d.ts +7 -0
- package/dist/utils/prototype-utils.js +64 -0
- package/dist/utils/prototype-utils.mjs +27 -0
- package/dist/utils/regex-utils.d.ts +2 -0
- package/dist/utils/regex-utils.js +54 -0
- package/dist/utils/regex-utils.mjs +17 -0
- package/dist/utils/request-utils.d.ts +15 -0
- package/dist/utils/request-utils.js +153 -0
- package/dist/utils/request-utils.mjs +95 -0
- package/dist/utils/simple-event-emitter.d.ts +5 -0
- package/dist/utils/simple-event-emitter.js +51 -0
- package/dist/utils/simple-event-emitter.mjs +17 -0
- package/dist/utils/stylesheet-loader.d.ts +7 -0
- package/dist/utils/stylesheet-loader.js +53 -0
- package/dist/utils/stylesheet-loader.mjs +19 -0
- package/dist/utils/type-utils.d.ts +2 -0
- package/dist/utils/type-utils.js +41 -0
- package/dist/utils/type-utils.mjs +4 -0
- package/dist/utils/url-targeting-utils.d.ts +28 -0
- package/dist/utils/url-targeting-utils.js +56 -0
- package/dist/utils/url-targeting-utils.mjs +19 -0
- package/dist/utils/uuidv7.d.ts +43 -0
- package/dist/utils/uuidv7.js +172 -0
- package/dist/utils/uuidv7.js.LICENSE.txt +9 -0
- package/dist/utils/uuidv7.mjs +132 -0
- package/dist/utils/uuidv7.mjs.LICENSE.txt +9 -0
- package/package.json +37 -3
- package/LICENSE +0 -353
package/README.md
CHANGED
|
@@ -96,10 +96,24 @@ if (flags && (await flags.getFeatureFlag('beta-ui'))) {
|
|
|
96
96
|
}
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
A token is implementation-free, so importing it never pulls
|
|
100
|
-
into your bundle — each extension stays independently
|
|
101
|
-
|
|
102
|
-
`
|
|
99
|
+
A token is an implementation-free branded string, so importing it never pulls
|
|
100
|
+
the provider's code into your bundle — each extension stays independently
|
|
101
|
+
tree-shakable and lazily loadable. Use a package-qualified runtime string, such
|
|
102
|
+
as `posthog.featureFlags`, that is globally unique and stable so separately
|
|
103
|
+
compiled scripts resolve the same capability. An extension that provides a
|
|
104
|
+
capability declares its token(s) in `provides`.
|
|
105
|
+
|
|
106
|
+
## Utilities
|
|
107
|
+
|
|
108
|
+
Reusable browser utilities are exposed through `utils/*` subpaths, but they are
|
|
109
|
+
intentionally not re-exported from the package root or a utility barrel. Import
|
|
110
|
+
the exact file you need so lazy extension bundles do not pull in unrelated
|
|
111
|
+
helpers:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { createLogger } from '@posthog/browser-common/utils/logger'
|
|
115
|
+
import { formDataToQuery } from '@posthog/browser-common/utils/request-utils'
|
|
116
|
+
```
|
|
103
117
|
|
|
104
118
|
## Authoring
|
|
105
119
|
|
|
@@ -112,7 +126,8 @@ v1 → `Client` porting map.
|
|
|
112
126
|
|
|
113
127
|
## Status
|
|
114
128
|
|
|
115
|
-
Early and internal. The package currently defines the extension contract
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
the first
|
|
129
|
+
Early and internal. The package currently defines the extension contract, the
|
|
130
|
+
shared `Publisher` helper, and directly imported browser utilities under
|
|
131
|
+
`utils/*` subpaths. Additional shared runtime helpers — key-value stores, the
|
|
132
|
+
registry implementation, and a test `Client` — will land alongside the first
|
|
133
|
+
ported extension.
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
default: ()=>__WEBPACK_DEFAULT_EXPORT__
|
|
28
|
+
});
|
|
29
|
+
const packageVersion = "0.2.1";
|
|
30
|
+
const Config = {
|
|
31
|
+
DEBUG: false,
|
|
32
|
+
LIB_VERSION: packageVersion,
|
|
33
|
+
LIB_NAME: 'browser-common',
|
|
34
|
+
JS_SDK_VERSION: packageVersion
|
|
35
|
+
};
|
|
36
|
+
const __WEBPACK_DEFAULT_EXPORT__ = Config;
|
|
37
|
+
exports["default"] = __webpack_exports__["default"];
|
|
38
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
39
|
+
"default"
|
|
40
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
41
|
+
Object.defineProperty(exports, '__esModule', {
|
|
42
|
+
value: true
|
|
43
|
+
});
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
SDK_DIST_CHANNEL: ()=>SDK_DIST_CHANNEL,
|
|
28
|
+
TOOLBAR_CONTAINER_CLASS: ()=>TOOLBAR_CONTAINER_CLASS,
|
|
29
|
+
TOOLBAR_ID: ()=>TOOLBAR_ID
|
|
30
|
+
});
|
|
31
|
+
const TOOLBAR_ID = '__POSTHOG_TOOLBAR__';
|
|
32
|
+
const TOOLBAR_CONTAINER_CLASS = 'toolbar-global-fade-container';
|
|
33
|
+
const SDK_DIST_CHANNEL = '$sdk_dist_channel';
|
|
34
|
+
exports.SDK_DIST_CHANNEL = __webpack_exports__.SDK_DIST_CHANNEL;
|
|
35
|
+
exports.TOOLBAR_CONTAINER_CLASS = __webpack_exports__.TOOLBAR_CONTAINER_CLASS;
|
|
36
|
+
exports.TOOLBAR_ID = __webpack_exports__.TOOLBAR_ID;
|
|
37
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
38
|
+
"SDK_DIST_CHANNEL",
|
|
39
|
+
"TOOLBAR_CONTAINER_CLASS",
|
|
40
|
+
"TOOLBAR_ID"
|
|
41
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
42
|
+
Object.defineProperty(exports, '__esModule', {
|
|
43
|
+
value: true
|
|
44
|
+
});
|
package/dist/token.d.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
+
/** Phantom brand carrying the capability type without emitting runtime code. */
|
|
2
|
+
declare const extensionTokenType: unique symbol;
|
|
1
3
|
/**
|
|
2
|
-
* A typed, implementation-free
|
|
3
|
-
* capability. Declared as a shared `const` next to the providing extension's
|
|
4
|
+
* A typed, implementation-free string for resolving an extension that provides
|
|
5
|
+
* a capability. Declared as a shared `const` next to the providing extension's
|
|
4
6
|
* interface:
|
|
5
7
|
*
|
|
6
8
|
* ```ts
|
|
7
9
|
* export interface FeatureFlagsExtension extends Extension { … }
|
|
8
|
-
* export const FeatureFlags
|
|
10
|
+
* export const FeatureFlags = 'posthog.featureFlags' as ExtensionToken<FeatureFlagsExtension>
|
|
9
11
|
* ```
|
|
10
12
|
*
|
|
11
13
|
* A token holds no implementation, so importing one never pulls the provider's
|
|
12
|
-
* code into the consumer's bundle.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* code into the consumer's bundle. Its generic brand lets `getExtension` infer
|
|
15
|
+
* the provided type, while its runtime string value remains stable across
|
|
16
|
+
* independently compiled scripts. Token strings must be globally unique and
|
|
17
|
+
* stable for the lifetime of the capability contract.
|
|
15
18
|
*/
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
readonly __provides?: T;
|
|
21
|
-
}
|
|
19
|
+
export type ExtensionToken<T> = string & {
|
|
20
|
+
readonly [extensionTokenType]: T;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __webpack_exports__ = {};
|
|
2
|
+
if ('function' != typeof Array.prototype.at) Object.defineProperty(Array.prototype, 'at', {
|
|
3
|
+
value: function(index) {
|
|
4
|
+
const len = this.length;
|
|
5
|
+
let relativeIndex = Math.trunc(index) || 0;
|
|
6
|
+
if (relativeIndex < 0) relativeIndex += len;
|
|
7
|
+
return relativeIndex < 0 || relativeIndex >= len ? void 0 : this[relativeIndex];
|
|
8
|
+
},
|
|
9
|
+
writable: true,
|
|
10
|
+
enumerable: false,
|
|
11
|
+
configurable: true
|
|
12
|
+
});
|
|
13
|
+
for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
14
|
+
Object.defineProperty(exports, '__esModule', {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
if ('function' != typeof Array.prototype.at) Object.defineProperty(Array.prototype, 'at', {
|
|
2
|
+
value: function(index) {
|
|
3
|
+
const len = this.length;
|
|
4
|
+
let relativeIndex = Math.trunc(index) || 0;
|
|
5
|
+
if (relativeIndex < 0) relativeIndex += len;
|
|
6
|
+
return relativeIndex < 0 || relativeIndex >= len ? void 0 : this[relativeIndex];
|
|
7
|
+
},
|
|
8
|
+
writable: true,
|
|
9
|
+
enumerable: false,
|
|
10
|
+
configurable: true
|
|
11
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AutocaptureConfig, PostHogConfig, Properties } from '@posthog/types';
|
|
2
|
+
import { type UrlTargetingInstance } from './url-targeting-utils';
|
|
3
|
+
export declare const MAX_DOM_ANCESTOR_DEPTH = 1000;
|
|
4
|
+
export declare function splitClassString(s: string): string[];
|
|
5
|
+
export declare function getClassNames(el: Element): string[];
|
|
6
|
+
export declare function makeSafeText(s: string | null | undefined): string | null;
|
|
7
|
+
export declare function getSafeText(el: Element): string;
|
|
8
|
+
export declare function getEventTarget(e: Event): Element | null;
|
|
9
|
+
export declare const autocaptureCompatibleElements: string[];
|
|
10
|
+
export declare function getParentElement(curEl: Element): Element | false;
|
|
11
|
+
export declare const DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS: string[];
|
|
12
|
+
export declare function shouldCaptureDeadClick(el: Element | null, _config: PostHogConfig['capture_dead_clicks']): boolean;
|
|
13
|
+
export declare function isTextSelectionTarget(el: Element | null): boolean;
|
|
14
|
+
export declare function shouldCaptureRageclick(el: Element | null, _config: PostHogConfig['rageclick']): boolean;
|
|
15
|
+
export declare function shouldSkipDeadClick(el: Element | null): boolean;
|
|
16
|
+
export declare function shouldCaptureDomEvent(el: Element, event: Event, autocaptureConfig?: AutocaptureConfig | undefined, captureOnAnyElement?: boolean, allowedEventTypes?: string[], instance?: UrlTargetingInstance): boolean;
|
|
17
|
+
export declare function shouldCaptureElement(el: Element): boolean;
|
|
18
|
+
export declare function isSensitiveElement(el: Element): boolean;
|
|
19
|
+
export declare function shouldCaptureValue(value: string, anchorRegexes?: boolean): boolean;
|
|
20
|
+
export declare function isAngularStyleAttr(attributeName: string): boolean;
|
|
21
|
+
export declare function getDirectAndNestedSpanText(target: Element): string;
|
|
22
|
+
export declare function getNestedSpanText(target: Element): string;
|
|
23
|
+
export declare function getElementsChainString(elements: Properties[]): string;
|