@openreplay/tracker 3.4.16 → 3.5.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.
Files changed (48) hide show
  1. package/README.md +8 -1
  2. package/cjs/app/context.d.ts +18 -0
  3. package/cjs/app/context.js +48 -0
  4. package/cjs/app/index.d.ts +39 -9
  5. package/cjs/app/index.js +155 -121
  6. package/cjs/app/logger.d.ts +27 -0
  7. package/cjs/app/logger.js +42 -0
  8. package/cjs/app/observer/observer.d.ts +2 -27
  9. package/cjs/app/observer/observer.js +18 -92
  10. package/cjs/app/observer/top_observer.d.ts +3 -3
  11. package/cjs/app/observer/top_observer.js +11 -8
  12. package/cjs/app/sanitizer.d.ts +16 -0
  13. package/cjs/app/sanitizer.js +46 -0
  14. package/cjs/index.d.ts +10 -9
  15. package/cjs/index.js +32 -21
  16. package/cjs/modules/console.js +1 -1
  17. package/cjs/modules/img.js +15 -1
  18. package/cjs/modules/input.d.ts +3 -1
  19. package/cjs/modules/input.js +6 -3
  20. package/cjs/modules/mouse.js +3 -1
  21. package/cjs/utils.d.ts +0 -8
  22. package/cjs/utils.js +3 -4
  23. package/lib/app/context.d.ts +18 -0
  24. package/lib/app/context.js +43 -0
  25. package/lib/app/index.d.ts +39 -9
  26. package/lib/app/index.js +156 -122
  27. package/lib/app/logger.d.ts +27 -0
  28. package/lib/app/logger.js +39 -1
  29. package/lib/app/observer/observer.d.ts +2 -27
  30. package/lib/app/observer/observer.js +7 -79
  31. package/lib/app/observer/top_observer.d.ts +3 -3
  32. package/lib/app/observer/top_observer.js +10 -7
  33. package/lib/app/sanitizer.d.ts +16 -0
  34. package/lib/app/sanitizer.js +44 -1
  35. package/lib/index.d.ts +10 -9
  36. package/lib/index.js +32 -21
  37. package/lib/modules/console.js +1 -1
  38. package/lib/modules/img.js +16 -2
  39. package/lib/modules/input.d.ts +3 -1
  40. package/lib/modules/input.js +6 -3
  41. package/lib/modules/mouse.js +3 -1
  42. package/lib/utils.d.ts +0 -8
  43. package/lib/utils.js +2 -3
  44. package/package.json +1 -1
  45. package/cjs/app/observer.d.ts +0 -47
  46. package/cjs/app/observer.js +0 -395
  47. package/lib/app/observer.d.ts +0 -47
  48. package/lib/app/observer.js +0 -392
@@ -57,6 +57,7 @@ function _getTarget(target) {
57
57
  if (tag === 'BUTTON' ||
58
58
  tag === 'A' ||
59
59
  tag === 'LI' ||
60
+ tag === 'SELECT' ||
60
61
  element.onclick != null ||
61
62
  element.getAttribute('role') === 'button' ||
62
63
  (0, utils_js_1.getLabelAttribute)(element) !== null) {
@@ -83,9 +84,10 @@ function default_1(app) {
83
84
  if (tag === 'BUTTON' ||
84
85
  tag === 'A' ||
85
86
  tag === 'LI' ||
87
+ tag === 'SELECT' ||
86
88
  target.onclick != null ||
87
89
  target.getAttribute('role') === 'button') {
88
- const label = app.observer.getInnerTextSecure(target);
90
+ const label = app.sanitizer.getInnerTextSecure(target);
89
91
  return (0, utils_js_1.normSpaces)(label).slice(0, 100);
90
92
  }
91
93
  return '';
package/cjs/utils.d.ts CHANGED
@@ -3,14 +3,6 @@ export declare const stars: (str: string) => string;
3
3
  export declare function normSpaces(str: string): string;
4
4
  export declare function isURL(s: string): boolean;
5
5
  export declare const IN_BROWSER: boolean;
6
- export declare const log: {
7
- (...data: any[]): void;
8
- (message?: any, ...optionalParams: any[]): void;
9
- };
10
- export declare const warn: {
11
- (...data: any[]): void;
12
- (message?: any, ...optionalParams: any[]): void;
13
- };
14
6
  export declare const DOCS_HOST = "https://docs.openreplay.com";
15
7
  export declare function deprecationWarn(nameOfFeature: string, useInstead: string, docsPath?: string): void;
16
8
  export declare function getLabelAttribute(e: Element): string | null;
package/cjs/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasOpenreplayAttribute = exports.getLabelAttribute = exports.deprecationWarn = exports.DOCS_HOST = exports.warn = exports.log = exports.IN_BROWSER = exports.isURL = exports.normSpaces = exports.stars = exports.timestamp = void 0;
3
+ exports.hasOpenreplayAttribute = exports.getLabelAttribute = exports.deprecationWarn = exports.DOCS_HOST = exports.IN_BROWSER = exports.isURL = exports.normSpaces = exports.stars = exports.timestamp = void 0;
4
4
  function timestamp() {
5
5
  return Math.round(performance.now()) + performance.timing.navigationStart;
6
6
  }
@@ -18,15 +18,14 @@ function isURL(s) {
18
18
  }
19
19
  exports.isURL = isURL;
20
20
  exports.IN_BROWSER = !(typeof window === "undefined");
21
- exports.log = console.log;
22
- exports.warn = console.warn;
21
+ // TODO: JOIN IT WITH LOGGER somehow (use logging decorators?); Don't forget about index.js loggin when there is no logger instance.
23
22
  exports.DOCS_HOST = 'https://docs.openreplay.com';
24
23
  const warnedFeatures = {};
25
24
  function deprecationWarn(nameOfFeature, useInstead, docsPath = "/") {
26
25
  if (warnedFeatures[nameOfFeature]) {
27
26
  return;
28
27
  }
29
- (0, exports.warn)(`OpenReplay: ${nameOfFeature} is deprecated. ${useInstead ? `Please, use ${useInstead} instead.` : ""} Visit ${exports.DOCS_HOST}${docsPath} for more information.`);
28
+ console.warn(`OpenReplay: ${nameOfFeature} is deprecated. ${useInstead ? `Please, use ${useInstead} instead.` : ""} Visit ${exports.DOCS_HOST}${docsPath} for more information.`);
30
29
  warnedFeatures[nameOfFeature] = true;
31
30
  }
32
31
  exports.deprecationWarn = deprecationWarn;
@@ -0,0 +1,18 @@
1
+ export interface Window extends globalThis.Window {
2
+ HTMLInputElement: typeof HTMLInputElement;
3
+ HTMLLinkElement: typeof HTMLLinkElement;
4
+ HTMLStyleElement: typeof HTMLStyleElement;
5
+ SVGStyleElement: typeof SVGStyleElement;
6
+ HTMLIFrameElement: typeof HTMLIFrameElement;
7
+ Text: typeof Text;
8
+ Element: typeof Element;
9
+ ShadowRoot: typeof ShadowRoot;
10
+ }
11
+ declare type WindowConstructor = Document | Element | Text | ShadowRoot | HTMLInputElement | HTMLLinkElement | HTMLStyleElement | HTMLIFrameElement;
12
+ declare type Constructor<T> = {
13
+ new (...args: any[]): T;
14
+ name: string;
15
+ };
16
+ export declare function isInstance<T extends WindowConstructor>(node: Node, constr: Constructor<T>): node is T;
17
+ export declare function inDocument(node: Node): boolean;
18
+ export {};
@@ -0,0 +1,43 @@
1
+ // TODO: we need a type expert here so we won't have to ignore the lines
2
+ // TODO: use it everywhere (static function; export from which file? <-- global Window typing required)
3
+ export function isInstance(node, constr) {
4
+ const doc = node.ownerDocument;
5
+ if (!doc) { // null if Document
6
+ return constr.name === 'Document';
7
+ }
8
+ let context =
9
+ // @ts-ignore (for EI, Safary)
10
+ doc.parentWindow ||
11
+ doc.defaultView; // TODO: smart global typing for Window object
12
+ while (context.parent && context.parent !== context) {
13
+ // @ts-ignore
14
+ if (node instanceof context[constr.name]) {
15
+ return true;
16
+ }
17
+ // @ts-ignore
18
+ context = context.parent;
19
+ }
20
+ // @ts-ignore
21
+ return node instanceof context[constr.name];
22
+ }
23
+ export function inDocument(node) {
24
+ const doc = node.ownerDocument;
25
+ if (!doc) {
26
+ return false;
27
+ }
28
+ if (doc.contains(node)) {
29
+ return true;
30
+ }
31
+ let context =
32
+ // @ts-ignore (for EI, Safary)
33
+ doc.parentWindow ||
34
+ doc.defaultView;
35
+ while (context.parent && context.parent !== context) {
36
+ if (context.document.contains(node)) {
37
+ return true;
38
+ }
39
+ // @ts-ignore
40
+ context = context.parent;
41
+ }
42
+ return false;
43
+ }
@@ -1,55 +1,84 @@
1
1
  import Message from "../messages/message.js";
2
2
  import Nodes from "./nodes.js";
3
- import Observer from "./observer/top_observer.js";
3
+ import Sanitizer from "./sanitizer.js";
4
4
  import Ticker from "./ticker.js";
5
+ import Logger from "./logger.js";
5
6
  import type { Options as ObserverOptions } from "./observer/top_observer.js";
7
+ import type { Options as SanitizerOptions } from "./sanitizer.js";
8
+ import type { Options as LoggerOptions } from "./logger.js";
6
9
  import type { Options as WebworkerOptions } from "../messages/webworker.js";
7
10
  export interface OnStartInfo {
8
11
  sessionID: string;
9
12
  sessionToken: string;
10
13
  userUUID: string;
11
14
  }
12
- export declare type Options = {
15
+ export interface StartOptions {
16
+ userID?: string;
17
+ metadata?: Record<string, string>;
18
+ forceNew: boolean;
19
+ }
20
+ declare type AppOptions = {
13
21
  revID: string;
14
22
  node_id: string;
15
23
  session_token_key: string;
16
24
  session_pageno_key: string;
25
+ session_reset_key: string;
17
26
  local_uuid_key: string;
18
27
  ingestPoint: string;
19
28
  resourceBaseHref: string | null;
29
+ verbose: boolean;
20
30
  __is_snippet: boolean;
21
31
  __debug_report_edp: string | null;
22
- __debug_log: boolean;
32
+ __debug__?: LoggerOptions;
23
33
  onStart?: (info: OnStartInfo) => void;
24
- } & ObserverOptions & WebworkerOptions;
34
+ } & WebworkerOptions;
35
+ export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
25
36
  declare type Callback = () => void;
26
37
  declare type CommitCallback = (messages: Array<Message>) => void;
38
+ export declare const CANCELED = "canceled";
27
39
  export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
28
40
  export default class App {
29
41
  readonly nodes: Nodes;
30
42
  readonly ticker: Ticker;
31
43
  readonly projectKey: string;
44
+ readonly sanitizer: Sanitizer;
45
+ readonly debug: Logger;
46
+ readonly notify: Logger;
32
47
  private readonly messages;
33
- readonly observer: Observer;
48
+ private readonly observer;
34
49
  private readonly startCallbacks;
35
50
  private readonly stopCallbacks;
36
51
  private readonly commitCallbacks;
37
52
  private readonly options;
38
53
  private readonly revID;
39
54
  private _sessionID;
40
- private isActive;
55
+ private _userID;
56
+ private _metadata;
57
+ private activityState;
41
58
  private version;
42
59
  private readonly worker?;
43
- constructor(projectKey: string, sessionToken: string | null | undefined, opts: Partial<Options>);
60
+ constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
44
61
  private _debug;
45
62
  send(message: Message, urgent?: boolean): void;
46
63
  private commit;
47
64
  attachCommitCallback(cb: CommitCallback): void;
48
- addCommitCallback(cb: CommitCallback): void;
49
65
  safe<T extends (...args: any[]) => void>(fn: T): T;
50
66
  attachStartCallback(cb: Callback): void;
51
67
  attachStopCallback(cb: Callback): void;
52
68
  attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
69
+ checkRequiredVersion(version: string): boolean;
70
+ private getStartInfo;
71
+ getSessionInfo(): {
72
+ userUUID: string | null;
73
+ projectKey: string;
74
+ revID: string;
75
+ timestamp: number;
76
+ trackerVersion: string;
77
+ userID: string | null;
78
+ isSnippet: boolean;
79
+ sessionID: string | null;
80
+ metadata: Record<string, string>;
81
+ };
53
82
  getSessionToken(): string | undefined;
54
83
  getSessionID(): string | undefined;
55
84
  getHost(): string;
@@ -58,8 +87,9 @@ export default class App {
58
87
  resolveResourceURL(resourceURL: string): string;
59
88
  isServiceURL(url: string): boolean;
60
89
  active(): boolean;
90
+ resetNextPageSession(flag: boolean): void;
61
91
  private _start;
62
- start(reset?: boolean): Promise<OnStartInfo>;
92
+ start(options?: StartOptions): Promise<OnStartInfo>;
63
93
  stop(): void;
64
94
  }
65
95
  export {};