@openreplay/tracker 3.5.9 → 3.5.12

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 (66) hide show
  1. package/README.md +5 -1
  2. package/cjs/app/index.d.ts +24 -15
  3. package/cjs/app/index.js +25 -26
  4. package/cjs/app/observer/iframe_observer.js +2 -2
  5. package/cjs/app/observer/observer.js +13 -13
  6. package/cjs/app/observer/shadow_root_observer.js +2 -2
  7. package/cjs/app/observer/top_observer.js +2 -2
  8. package/cjs/app/session.js +3 -3
  9. package/cjs/{messages/index.d.ts → common/messages.d.ts} +2 -3
  10. package/cjs/{messages/index.js → common/messages.js} +0 -0
  11. package/cjs/common/types.d.ts +9 -0
  12. package/cjs/{messages/message.js → common/types.js} +0 -0
  13. package/cjs/common/webworker.d.ts +19 -0
  14. package/cjs/common/webworker.js +2 -0
  15. package/cjs/index.d.ts +3 -3
  16. package/cjs/index.js +6 -6
  17. package/cjs/modules/connection.js +2 -2
  18. package/cjs/modules/console.js +2 -2
  19. package/cjs/modules/cssrules.js +4 -4
  20. package/cjs/modules/exception.d.ts +1 -1
  21. package/cjs/modules/exception.js +4 -4
  22. package/cjs/modules/img.js +7 -7
  23. package/cjs/modules/input.js +5 -5
  24. package/cjs/modules/longtasks.js +2 -2
  25. package/cjs/modules/mouse.js +3 -3
  26. package/cjs/modules/performance.js +2 -2
  27. package/cjs/modules/scroll.js +3 -3
  28. package/cjs/modules/timing.js +15 -18
  29. package/cjs/modules/viewport.js +4 -4
  30. package/lib/app/index.d.ts +24 -15
  31. package/lib/app/index.js +21 -22
  32. package/lib/app/observer/iframe_observer.js +1 -1
  33. package/lib/app/observer/observer.js +1 -1
  34. package/lib/app/observer/shadow_root_observer.js +1 -1
  35. package/lib/app/observer/top_observer.js +1 -1
  36. package/lib/app/session.js +1 -1
  37. package/lib/{messages/index.d.ts → common/messages.d.ts} +2 -3
  38. package/lib/{messages/index.js → common/messages.js} +0 -0
  39. package/lib/common/tsconfig.tsbuildinfo +1 -0
  40. package/lib/common/types.d.ts +9 -0
  41. package/lib/{messages/message.js → common/types.js} +0 -0
  42. package/lib/common/webworker.d.ts +19 -0
  43. package/lib/common/webworker.js +1 -0
  44. package/lib/index.d.ts +3 -3
  45. package/lib/index.js +3 -3
  46. package/lib/modules/connection.js +1 -1
  47. package/lib/modules/console.js +1 -1
  48. package/lib/modules/cssrules.js +1 -1
  49. package/lib/modules/exception.d.ts +1 -1
  50. package/lib/modules/exception.js +1 -1
  51. package/lib/modules/img.js +1 -1
  52. package/lib/modules/input.js +1 -1
  53. package/lib/modules/longtasks.js +1 -1
  54. package/lib/modules/mouse.js +1 -1
  55. package/lib/modules/performance.js +1 -1
  56. package/lib/modules/scroll.js +1 -1
  57. package/lib/modules/timing.js +13 -16
  58. package/lib/modules/viewport.js +1 -1
  59. package/package.json +1 -1
  60. package/cjs/messages/message.d.ts +0 -4
  61. package/cjs/messages/writer.d.ts +0 -15
  62. package/cjs/messages/writer.js +0 -115
  63. package/lib/messages/message.d.ts +0 -4
  64. package/lib/messages/tsconfig.tsbuildinfo +0 -1
  65. package/lib/messages/writer.d.ts +0 -15
  66. package/lib/messages/writer.js +0 -112
package/README.md CHANGED
@@ -25,7 +25,11 @@ tracker.start({
25
25
  balance: "10M",
26
26
  role: "admin",
27
27
  }
28
- });
28
+ }).then(startedSession => {
29
+ if (startedSession.success) {
30
+ console.log(startedSession)
31
+ }
32
+ })
29
33
  ```
30
34
 
31
35
  Then you can use OpenReplay JavaScript API anywhere in your code.
@@ -1,4 +1,4 @@
1
- import Message from "../messages/message.js";
1
+ import type Message from "../common/messages.js";
2
2
  import Nodes from "./nodes.js";
3
3
  import Sanitizer from "./sanitizer.js";
4
4
  import Ticker from "./ticker.js";
@@ -7,17 +7,30 @@ import Session from "./session.js";
7
7
  import type { Options as ObserverOptions } from "./observer/top_observer.js";
8
8
  import type { Options as SanitizerOptions } from "./sanitizer.js";
9
9
  import type { Options as LoggerOptions } from "./logger.js";
10
- import type { Options as WebworkerOptions } from "../../webworker/types.js";
11
- export interface OnStartInfo {
12
- sessionID: string;
13
- sessionToken: string;
14
- userUUID: string;
15
- }
10
+ import type { Options as WebworkerOptions } from "../common/webworker.js";
16
11
  export interface StartOptions {
17
12
  userID?: string;
18
13
  metadata?: Record<string, string>;
19
14
  forceNew?: boolean;
20
15
  }
16
+ interface OnStartInfo {
17
+ sessionID: string;
18
+ sessionToken: string;
19
+ userUUID: string;
20
+ }
21
+ declare const CANCELED: "canceled";
22
+ declare type SuccessfulStart = OnStartInfo & {
23
+ success: true;
24
+ };
25
+ declare type UnsuccessfulStart = {
26
+ reason: typeof CANCELED | string;
27
+ success: false;
28
+ };
29
+ declare const UnsuccessfulStart: (reason: string) => UnsuccessfulStart;
30
+ declare const SuccessfulStart: (body: OnStartInfo) => SuccessfulStart;
31
+ export declare type StartPromiseReturn = SuccessfulStart | UnsuccessfulStart;
32
+ declare type StartCallback = (i: OnStartInfo) => void;
33
+ declare type CommitCallback = (messages: Array<Message>) => void;
21
34
  declare type AppOptions = {
22
35
  revID: string;
23
36
  node_id: string;
@@ -31,12 +44,9 @@ declare type AppOptions = {
31
44
  __is_snippet: boolean;
32
45
  __debug_report_edp: string | null;
33
46
  __debug__?: LoggerOptions;
34
- onStart?: (info: OnStartInfo) => void;
47
+ onStart?: StartCallback;
35
48
  } & WebworkerOptions;
36
49
  export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
37
- declare type Callback = () => void;
38
- declare type CommitCallback = (messages: Array<Message>) => void;
39
- export declare const CANCELED = "canceled";
40
50
  export declare const DEFAULT_INGEST_POINT = "https://api.openreplay.com/ingest";
41
51
  export default class App {
42
52
  readonly nodes: Nodes;
@@ -58,13 +68,12 @@ export default class App {
58
68
  private readonly worker?;
59
69
  constructor(projectKey: string, sessionToken: string | null | undefined, options: Partial<Options>);
60
70
  private _debug;
61
- private readonly preStartMessages;
62
71
  send(message: Message, urgent?: boolean): void;
63
72
  private commit;
64
73
  safe<T extends (...args: any[]) => void>(fn: T): T;
65
74
  attachCommitCallback(cb: CommitCallback): void;
66
- attachStartCallback(cb: Callback): void;
67
- attachStopCallback(cb: Callback): void;
75
+ attachStartCallback(cb: StartCallback): void;
76
+ attachStopCallback(cb: Function): void;
68
77
  attachEventListener(target: EventTarget, type: string, listener: EventListener, useSafe?: boolean, useCapture?: boolean): void;
69
78
  checkRequiredVersion(version: string): boolean;
70
79
  private getStartInfo;
@@ -89,7 +98,7 @@ export default class App {
89
98
  active(): boolean;
90
99
  resetNextPageSession(flag: boolean): void;
91
100
  private _start;
92
- start(options?: StartOptions): Promise<OnStartInfo>;
101
+ start(options?: StartOptions): Promise<StartPromiseReturn>;
93
102
  stop(): void;
94
103
  }
95
104
  export {};
package/cjs/app/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_INGEST_POINT = exports.CANCELED = void 0;
3
+ exports.DEFAULT_INGEST_POINT = void 0;
4
+ const messages_js_1 = require("../common/messages.js");
4
5
  const utils_js_1 = require("../utils.js");
5
- const index_js_1 = require("../messages/index.js");
6
6
  const nodes_js_1 = require("./nodes.js");
7
7
  const top_observer_js_1 = require("./observer/top_observer.js");
8
8
  const sanitizer_js_1 = require("./sanitizer.js");
@@ -10,13 +10,16 @@ const ticker_js_1 = require("./ticker.js");
10
10
  const logger_js_1 = require("./logger.js");
11
11
  const session_js_1 = require("./session.js");
12
12
  const performance_js_1 = require("../modules/performance.js");
13
+ const CANCELED = "canceled";
14
+ const START_ERROR = ":(";
15
+ const UnsuccessfulStart = (reason) => ({ reason, success: false });
16
+ const SuccessfulStart = (body) => (Object.assign(Object.assign({}, body), { success: true }));
13
17
  var ActivityState;
14
18
  (function (ActivityState) {
15
19
  ActivityState[ActivityState["NotActive"] = 0] = "NotActive";
16
20
  ActivityState[ActivityState["Starting"] = 1] = "Starting";
17
21
  ActivityState[ActivityState["Active"] = 2] = "Active";
18
22
  })(ActivityState || (ActivityState = {}));
19
- exports.CANCELED = "canceled";
20
23
  // TODO: use backendHost only
21
24
  exports.DEFAULT_INGEST_POINT = 'https://api.openreplay.com/ingest';
22
25
  class App {
@@ -29,8 +32,7 @@ class App {
29
32
  this.stopCallbacks = [];
30
33
  this.commitCallbacks = [];
31
34
  this.activityState = ActivityState.NotActive;
32
- this.version = '3.5.9'; // TODO: version compatability check inside each plugin.
33
- this.preStartMessages = [];
35
+ this.version = '3.5.12'; // TODO: version compatability check inside each plugin.
34
36
  this.projectKey = projectKey;
35
37
  this.options = Object.assign({
36
38
  revID: '',
@@ -103,21 +105,18 @@ class App {
103
105
  if (this.activityState === ActivityState.NotActive) {
104
106
  return;
105
107
  }
106
- if (this.activityState === ActivityState.Starting) {
107
- this.preStartMessages.push(message);
108
- }
109
- if (this.preStartMessages.length) {
110
- this.messages.push(...this.preStartMessages);
111
- this.preStartMessages.length = 0;
112
- }
113
108
  this.messages.push(message);
114
- if (urgent) {
109
+ // TODO: commit on start if there were `urgent` sends;
110
+ // Clearify where urgent can be used for;
111
+ // Clearify workflow for each type of message in case it was sent before start
112
+ // (like Fetch before start; maybe add an option "preCapture: boolean" or sth alike)
113
+ if (this.activityState === ActivityState.Active && urgent) {
115
114
  this.commit();
116
115
  }
117
116
  }
118
117
  commit() {
119
118
  if (this.worker && this.messages.length) {
120
- this.messages.unshift(new index_js_1.Timestamp((0, utils_js_1.timestamp)()));
119
+ this.messages.unshift(new messages_js_1.Timestamp((0, utils_js_1.timestamp)()));
121
120
  this.worker.postMessage(this.messages);
122
121
  this.commitCallbacks.forEach(cb => cb(this.messages));
123
122
  this.messages.length = 0;
@@ -229,10 +228,10 @@ class App {
229
228
  }
230
229
  _start(startOpts) {
231
230
  if (!this.worker) {
232
- return Promise.reject("No worker found: perhaps, CSP is not set.");
231
+ return Promise.resolve(UnsuccessfulStart("No worker found: perhaps, CSP is not set."));
233
232
  }
234
233
  if (this.activityState !== ActivityState.NotActive) {
235
- return Promise.reject("OpenReplay: trying to call `start()` on the instance that has been started already.");
234
+ return Promise.resolve(UnsuccessfulStart("OpenReplay: trying to call `start()` on the instance that has been started already."));
236
235
  }
237
236
  this.activityState = ActivityState.Starting;
238
237
  let pageNo = 0;
@@ -267,8 +266,8 @@ class App {
267
266
  return r.json();
268
267
  }
269
268
  else {
270
- return r.text().then(text => text === exports.CANCELED
271
- ? Promise.reject(exports.CANCELED) // TODO: return {error: CANCELED} instead
269
+ return r.text().then(text => text === CANCELED
270
+ ? Promise.reject(CANCELED) // TODO: return {error: CANCELED} instead
272
271
  : Promise.reject(`Server error: ${r.status}. ${text}`));
273
272
  }
274
273
  })
@@ -292,26 +291,26 @@ class App {
292
291
  beaconSizeLimit
293
292
  };
294
293
  this.worker.postMessage(startWorkerMsg);
295
- this.startCallbacks.forEach((cb) => cb());
294
+ const onStartInfo = { sessionToken: token, userUUID, sessionID };
295
+ this.startCallbacks.forEach((cb) => cb(onStartInfo));
296
296
  this.observer.observe();
297
297
  this.ticker.start();
298
298
  this.notify.log("OpenReplay tracking started.");
299
299
  // TODO: get rid of onStart
300
- const onStartInfo = { sessionToken: token, userUUID, sessionID };
301
300
  if (typeof this.options.onStart === 'function') {
302
301
  this.options.onStart(onStartInfo);
303
302
  }
304
- return onStartInfo;
303
+ return SuccessfulStart(onStartInfo);
305
304
  })
306
305
  .catch(reason => {
307
306
  sessionStorage.removeItem(this.options.session_token_key);
308
307
  this.stop();
309
- //if (reason === CANCELED) { return Promise.resolve(CANCELED) } // TODO: what to return ????? Throwing is baad
310
- if (reason !== exports.CANCELED) {
311
- this.notify.log("OpenReplay was unable to start. ", reason);
312
- this._debug("session_start", reason);
308
+ if (reason === CANCELED) {
309
+ return UnsuccessfulStart(CANCELED);
313
310
  }
314
- return Promise.reject(reason);
311
+ this.notify.log("OpenReplay was unable to start. ", reason);
312
+ this._debug("session_start", reason);
313
+ return UnsuccessfulStart(START_ERROR);
315
314
  });
316
315
  }
317
316
  start(options = {}) {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const observer_js_1 = require("./observer.js");
4
- const index_js_1 = require("../../messages/index.js");
4
+ const messages_js_1 = require("../../common/messages.js");
5
5
  class IFrameObserver extends observer_js_1.default {
6
6
  observe(iframe) {
7
7
  const doc = iframe.contentDocument;
@@ -15,7 +15,7 @@ class IFrameObserver extends observer_js_1.default {
15
15
  console.log("OpenReplay: Iframe document not bound");
16
16
  return;
17
17
  }
18
- this.app.send((0, index_js_1.CreateIFrameDocument)(hostID, docID));
18
+ this.app.send((0, messages_js_1.CreateIFrameDocument)(hostID, docID));
19
19
  });
20
20
  }
21
21
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_js_1 = require("../../messages/index.js");
3
+ const messages_js_1 = require("../../common/messages.js");
4
4
  const context_js_1 = require("../context.js");
5
5
  function isSVGElement(node) {
6
6
  return node.namespaceURI === 'http://www.w3.org/2000/svg';
@@ -99,16 +99,16 @@ class Observer {
99
99
  name = name.substr(6);
100
100
  }
101
101
  if (value === null) {
102
- this.app.send(new index_js_1.RemoveNodeAttribute(id, name));
102
+ this.app.send(new messages_js_1.RemoveNodeAttribute(id, name));
103
103
  }
104
104
  else if (name === 'href') {
105
105
  if (value.length > 1e5) {
106
106
  value = '';
107
107
  }
108
- this.app.send(new index_js_1.SetNodeAttributeURLBased(id, name, value, this.app.getBaseHref()));
108
+ this.app.send(new messages_js_1.SetNodeAttributeURLBased(id, name, value, this.app.getBaseHref()));
109
109
  }
110
110
  else {
111
- this.app.send(new index_js_1.SetNodeAttribute(id, name, value));
111
+ this.app.send(new messages_js_1.SetNodeAttribute(id, name, value));
112
112
  }
113
113
  return;
114
114
  }
@@ -128,25 +128,25 @@ class Observer {
128
128
  return;
129
129
  }
130
130
  if (value === null) {
131
- this.app.send(new index_js_1.RemoveNodeAttribute(id, name));
131
+ this.app.send(new messages_js_1.RemoveNodeAttribute(id, name));
132
132
  return;
133
133
  }
134
134
  if (name === 'style' || name === 'href' && (0, context_js_1.isInstance)(node, HTMLLinkElement)) {
135
- this.app.send(new index_js_1.SetNodeAttributeURLBased(id, name, value, this.app.getBaseHref()));
135
+ this.app.send(new messages_js_1.SetNodeAttributeURLBased(id, name, value, this.app.getBaseHref()));
136
136
  return;
137
137
  }
138
138
  if (name === 'href' || value.length > 1e5) {
139
139
  value = '';
140
140
  }
141
- this.app.send(new index_js_1.SetNodeAttribute(id, name, value));
141
+ this.app.send(new messages_js_1.SetNodeAttribute(id, name, value));
142
142
  }
143
143
  sendNodeData(id, parentElement, data) {
144
144
  if ((0, context_js_1.isInstance)(parentElement, HTMLStyleElement) || (0, context_js_1.isInstance)(parentElement, SVGStyleElement)) {
145
- this.app.send(new index_js_1.SetCSSDataURLBased(id, data, this.app.getBaseHref()));
145
+ this.app.send(new messages_js_1.SetCSSDataURLBased(id, data, this.app.getBaseHref()));
146
146
  return;
147
147
  }
148
148
  data = this.app.sanitizer.sanitize(id, data);
149
- this.app.send(new index_js_1.SetNodeData(id, data));
149
+ this.app.send(new messages_js_1.SetNodeData(id, data));
150
150
  }
151
151
  bindNode(node) {
152
152
  const r = this.app.nodes.registerNode(node);
@@ -173,7 +173,7 @@ class Observer {
173
173
  unbindNode(node) {
174
174
  const id = this.app.nodes.unregisterNode(node);
175
175
  if (id !== undefined && this.recents[id] === false) {
176
- this.app.send(new index_js_1.RemoveNode(id));
176
+ this.app.send(new messages_js_1.RemoveNode(id));
177
177
  }
178
178
  }
179
179
  _commitNode(id, node) {
@@ -222,7 +222,7 @@ class Observer {
222
222
  if (isNew === true) {
223
223
  if ((0, context_js_1.isInstance)(node, Element)) {
224
224
  if (parentID !== undefined) {
225
- this.app.send(new index_js_1.CreateElementNode(id, parentID, index, node.tagName, isSVGElement(node)));
225
+ this.app.send(new messages_js_1.CreateElementNode(id, parentID, index, node.tagName, isSVGElement(node)));
226
226
  }
227
227
  for (let i = 0; i < node.attributes.length; i++) {
228
228
  const attr = node.attributes[i];
@@ -231,13 +231,13 @@ class Observer {
231
231
  }
232
232
  else if ((0, context_js_1.isInstance)(node, Text)) {
233
233
  // for text node id != 0, hence parentID !== undefined and parent is Element
234
- this.app.send(new index_js_1.CreateTextNode(id, parentID, index));
234
+ this.app.send(new messages_js_1.CreateTextNode(id, parentID, index));
235
235
  this.sendNodeData(id, parent, node.data);
236
236
  }
237
237
  return true;
238
238
  }
239
239
  if (isNew === false && parentID !== undefined) {
240
- this.app.send(new index_js_1.MoveNode(id, parentID, index));
240
+ this.app.send(new messages_js_1.MoveNode(id, parentID, index));
241
241
  }
242
242
  const attr = this.attributesList[id];
243
243
  if (attr !== undefined) {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const observer_js_1 = require("./observer.js");
4
- const index_js_1 = require("../../messages/index.js");
4
+ const messages_js_1 = require("../../common/messages.js");
5
5
  class ShadowRootObserver extends observer_js_1.default {
6
6
  observe(el) {
7
7
  const shRoot = el.shadowRoot;
@@ -14,7 +14,7 @@ class ShadowRootObserver extends observer_js_1.default {
14
14
  console.log("OpenReplay: Shadow Root was not bound");
15
15
  return;
16
16
  }
17
- this.app.send((0, index_js_1.CreateIFrameDocument)(hostID, rootID));
17
+ this.app.send((0, messages_js_1.CreateIFrameDocument)(hostID, rootID));
18
18
  });
19
19
  }
20
20
  }
@@ -4,7 +4,7 @@ const observer_js_1 = require("./observer.js");
4
4
  const context_js_1 = require("../context.js");
5
5
  const iframe_observer_js_1 = require("./iframe_observer.js");
6
6
  const shadow_root_observer_js_1 = require("./shadow_root_observer.js");
7
- const index_js_1 = require("../../messages/index.js");
7
+ const messages_js_1 = require("../../common/messages.js");
8
8
  const utils_js_1 = require("../../utils.js");
9
9
  const attachShadowNativeFn = utils_js_1.IN_BROWSER ? Element.prototype.attachShadow : () => new ShadowRoot();
10
10
  class TopObserver extends observer_js_1.default {
@@ -71,7 +71,7 @@ class TopObserver extends observer_js_1.default {
71
71
  // the 0-node ("fRoot") will become #document rather than documentElement as it is now.
72
72
  // Alternatively - observe(#document) then bindNode(documentElement)
73
73
  this.observeRoot(window.document, () => {
74
- this.app.send(new index_js_1.CreateDocument());
74
+ this.app.send(new messages_js_1.CreateDocument());
75
75
  }, window.document.documentElement);
76
76
  }
77
77
  disconnect() {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_js_1 = require("../messages/index.js");
3
+ const messages_js_1 = require("../common/messages.js");
4
4
  var ActivityState;
5
5
  (function (ActivityState) {
6
6
  ActivityState[ActivityState["NotActive"] = 0] = "NotActive";
@@ -42,11 +42,11 @@ class Session {
42
42
  this.handleUpdate();
43
43
  }
44
44
  _setMetadata(key, value) {
45
- this.app.send(new index_js_1.Metadata(key, value));
45
+ this.app.send(new messages_js_1.Metadata(key, value));
46
46
  this.metadata[key] = value;
47
47
  }
48
48
  _setUserID(userID) {
49
- this.app.send(new index_js_1.UserID(userID));
49
+ this.app.send(new messages_js_1.UserID(userID));
50
50
  this.userID = userID;
51
51
  }
52
52
  setMetadata(key, value) {
@@ -1,5 +1,5 @@
1
- import Message from "./message.js";
2
- import Writer from "./writer.js";
1
+ import type { Writer, Message } from "./types.js";
2
+ export default Message;
3
3
  export declare const classes: Map<number, Function>;
4
4
  declare class _BatchMeta implements Message {
5
5
  pageNo: number;
@@ -442,4 +442,3 @@ declare class _CreateIFrameDocument implements Message {
442
442
  encode(writer: Writer): boolean;
443
443
  }
444
444
  export declare const CreateIFrameDocument: typeof _CreateIFrameDocument & ((frameID: number, id: number) => _CreateIFrameDocument);
445
- export {};
File without changes
@@ -0,0 +1,9 @@
1
+ export interface Writer {
2
+ uint(n: number): boolean;
3
+ int(n: number): boolean;
4
+ string(s: string): boolean;
5
+ boolean(b: boolean): boolean;
6
+ }
7
+ export interface Message {
8
+ encode(w: Writer): boolean;
9
+ }
File without changes
@@ -0,0 +1,19 @@
1
+ export interface Options {
2
+ connAttemptCount?: number;
3
+ connAttemptGap?: number;
4
+ }
5
+ declare type Start = {
6
+ type: "start";
7
+ ingestPoint: string;
8
+ pageNo: number;
9
+ timestamp: number;
10
+ } & Options;
11
+ declare type Auth = {
12
+ type: "auth";
13
+ token: string;
14
+ beaconSizeLimit?: number;
15
+ };
16
+ export declare type WorkerMessageData = null | "stop" | Start | Auth | Array<{
17
+ _id: number;
18
+ }>;
19
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import App from "./app/index.js";
2
2
  export { default as App } from './app/index.js';
3
- import * as _Messages from "./messages/index.js";
3
+ import * as _Messages from "./common/messages.js";
4
4
  export declare const Messages: typeof _Messages;
5
5
  import type { Options as AppOptions } from "./app/index.js";
6
6
  import type { Options as ConsoleOptions } from "./modules/console.js";
@@ -9,7 +9,7 @@ import type { Options as InputOptions } from "./modules/input.js";
9
9
  import type { Options as PerformanceOptions } from "./modules/performance.js";
10
10
  import type { Options as TimingOptions } from "./modules/timing.js";
11
11
  import type { StartOptions } from './app/index.js';
12
- import type { OnStartInfo } from './app/index.js';
12
+ import type { StartPromiseReturn } from './app/index.js';
13
13
  export declare type Options = Partial<AppOptions & ConsoleOptions & ExceptionOptions & InputOptions & PerformanceOptions & TimingOptions> & {
14
14
  projectID?: number;
15
15
  projectKey: string;
@@ -24,7 +24,7 @@ export default class API {
24
24
  constructor(options: Options);
25
25
  use<T>(fn: (app: App | null, options?: Options) => T): T;
26
26
  isActive(): boolean;
27
- start(startOpts?: Partial<StartOptions>): Promise<OnStartInfo>;
27
+ start(startOpts?: Partial<StartOptions>): Promise<StartPromiseReturn>;
28
28
  stop(): void;
29
29
  getSessionToken(): string | null | undefined;
30
30
  getSessionID(): string | null | undefined;
package/cjs/index.js CHANGED
@@ -4,8 +4,8 @@ exports.Messages = exports.App = void 0;
4
4
  const index_js_1 = require("./app/index.js");
5
5
  var index_js_2 = require("./app/index.js");
6
6
  Object.defineProperty(exports, "App", { enumerable: true, get: function () { return index_js_2.default; } });
7
- const index_js_3 = require("./messages/index.js");
8
- const _Messages = require("./messages/index.js");
7
+ const messages_js_1 = require("./common/messages.js");
8
+ const _Messages = require("./common/messages.js");
9
9
  exports.Messages = _Messages;
10
10
  const connection_js_1 = require("./modules/connection.js");
11
11
  const console_js_1 = require("./modules/console.js");
@@ -127,7 +127,7 @@ class API {
127
127
  // no-cors issue only with text/plain or not-set Content-Type
128
128
  // req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
129
129
  req.send(JSON.stringify({
130
- trackerVersion: '3.5.9',
130
+ trackerVersion: '3.5.12',
131
131
  projectKey: options.projectKey,
132
132
  doNotTrack,
133
133
  // TODO: add precise reason (an exact API missing)
@@ -187,7 +187,7 @@ class API {
187
187
  }
188
188
  setUserAnonymousID(id) {
189
189
  if (typeof id === 'string' && this.app !== null) {
190
- this.app.send(new index_js_3.UserAnonymousID(id));
190
+ this.app.send(new messages_js_1.UserAnonymousID(id));
191
191
  }
192
192
  }
193
193
  userAnonymousID(id) {
@@ -217,7 +217,7 @@ class API {
217
217
  catch (e) {
218
218
  return;
219
219
  }
220
- this.app.send(new index_js_3.RawCustomEvent(key, payload));
220
+ this.app.send(new messages_js_1.RawCustomEvent(key, payload));
221
221
  }
222
222
  }
223
223
  }
@@ -229,7 +229,7 @@ class API {
229
229
  catch (e) {
230
230
  return;
231
231
  }
232
- this.app.send(new index_js_3.CustomIssue(key, payload));
232
+ this.app.send(new messages_js_1.CustomIssue(key, payload));
233
233
  }
234
234
  }
235
235
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_js_1 = require("../messages/index.js");
3
+ const messages_js_1 = require("../common/messages.js");
4
4
  function default_1(app) {
5
5
  const connection = navigator.connection ||
6
6
  navigator.mozConnection ||
@@ -8,7 +8,7 @@ function default_1(app) {
8
8
  if (connection === undefined) {
9
9
  return;
10
10
  }
11
- const sendConnectionInformation = () => app.send(new index_js_1.ConnectionInformation(Math.round(connection.downlink * 1000), connection.type || 'unknown'));
11
+ const sendConnectionInformation = () => app.send(new messages_js_1.ConnectionInformation(Math.round(connection.downlink * 1000), connection.type || 'unknown'));
12
12
  sendConnectionInformation();
13
13
  connection.addEventListener('change', sendConnectionInformation);
14
14
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utils_js_1 = require("../utils.js");
4
- const index_js_1 = require("../messages/index.js");
4
+ const messages_js_1 = require("../common/messages.js");
5
5
  const printError = utils_js_1.IN_BROWSER && 'InstallTrigger' in window // detect Firefox
6
6
  ? (e) => e.message + '\n' + e.stack
7
7
  : (e) => e.stack || e.message;
@@ -92,7 +92,7 @@ function default_1(app, opts) {
92
92
  options.consoleMethods.length === 0) {
93
93
  return;
94
94
  }
95
- const sendConsoleLog = app.safe((level, args) => app.send(new index_js_1.ConsoleLog(level, printf(args))));
95
+ const sendConsoleLog = app.safe((level, args) => app.send(new messages_js_1.ConsoleLog(level, printf(args))));
96
96
  let n;
97
97
  const reset = () => {
98
98
  n = 0;
@@ -1,18 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_js_1 = require("../messages/index.js");
3
+ const messages_js_1 = require("../common/messages.js");
4
4
  function default_1(app) {
5
5
  if (app === null) {
6
6
  return;
7
7
  }
8
8
  if (!window.CSSStyleSheet) {
9
- app.send(new index_js_1.TechnicalInfo("no_stylesheet_prototype_in_window", ""));
9
+ app.send(new messages_js_1.TechnicalInfo("no_stylesheet_prototype_in_window", ""));
10
10
  return;
11
11
  }
12
12
  const processOperation = app.safe((stylesheet, index, rule) => {
13
13
  const sendMessage = typeof rule === 'string'
14
- ? (nodeID) => app.send(new index_js_1.CSSInsertRuleURLBased(nodeID, rule, index, app.getBaseHref()))
15
- : (nodeID) => app.send(new index_js_1.CSSDeleteRule(nodeID, index));
14
+ ? (nodeID) => app.send(new messages_js_1.CSSInsertRuleURLBased(nodeID, rule, index, app.getBaseHref()))
15
+ : (nodeID) => app.send(new messages_js_1.CSSDeleteRule(nodeID, index));
16
16
  // TODO: Extend messages to maintain nested rules (CSSGroupingRule prototype, as well as CSSKeyframesRule)
17
17
  if (stylesheet.ownerNode == null) {
18
18
  throw new Error("Owner Node not found");
@@ -1,5 +1,5 @@
1
+ import type Message from "../common/messages.js";
1
2
  import App from "../app/index.js";
2
- import Message from "../messages/message.js";
3
3
  export interface Options {
4
4
  captureExceptions: boolean;
5
5
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getExceptionMessageFromEvent = exports.getExceptionMessage = void 0;
4
- const index_js_1 = require("../messages/index.js");
4
+ const messages_js_1 = require("../common/messages.js");
5
5
  const error_stack_parser_1 = require("error-stack-parser");
6
6
  function getDefaultStack(e) {
7
7
  return [{
@@ -19,7 +19,7 @@ function getExceptionMessage(error, fallbackStack) {
19
19
  }
20
20
  catch (e) {
21
21
  }
22
- return new index_js_1.JSException(error.name, error.message, JSON.stringify(stack));
22
+ return new messages_js_1.JSException(error.name, error.message, JSON.stringify(stack));
23
23
  }
24
24
  exports.getExceptionMessage = getExceptionMessage;
25
25
  function getExceptionMessageFromEvent(e) {
@@ -33,7 +33,7 @@ function getExceptionMessageFromEvent(e) {
33
33
  name = 'Error';
34
34
  message = e.message;
35
35
  }
36
- return new index_js_1.JSException(name, message, JSON.stringify(getDefaultStack(e)));
36
+ return new messages_js_1.JSException(name, message, JSON.stringify(getDefaultStack(e)));
37
37
  }
38
38
  }
39
39
  else if ('PromiseRejectionEvent' in window && e instanceof PromiseRejectionEvent) {
@@ -48,7 +48,7 @@ function getExceptionMessageFromEvent(e) {
48
48
  catch (_) {
49
49
  message = String(e.reason);
50
50
  }
51
- return new index_js_1.JSException('Unhandled Promise Rejection', message, '[]');
51
+ return new messages_js_1.JSException('Unhandled Promise Rejection', message, '[]');
52
52
  }
53
53
  }
54
54
  return null;