@openreplay/tracker 3.5.11 → 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.
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.
@@ -13,11 +13,22 @@ export interface StartOptions {
13
13
  metadata?: Record<string, string>;
14
14
  forceNew?: boolean;
15
15
  }
16
- export interface OnStartInfo {
16
+ interface OnStartInfo {
17
17
  sessionID: string;
18
18
  sessionToken: string;
19
19
  userUUID: string;
20
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;
21
32
  declare type StartCallback = (i: OnStartInfo) => void;
22
33
  declare type CommitCallback = (messages: Array<Message>) => void;
23
34
  declare type AppOptions = {
@@ -36,7 +47,6 @@ declare type AppOptions = {
36
47
  onStart?: StartCallback;
37
48
  } & WebworkerOptions;
38
49
  export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
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;
@@ -88,7 +98,7 @@ export default class App {
88
98
  active(): boolean;
89
99
  resetNextPageSession(flag: boolean): void;
90
100
  private _start;
91
- start(options?: StartOptions): Promise<OnStartInfo>;
101
+ start(options?: StartOptions): Promise<StartPromiseReturn>;
92
102
  stop(): void;
93
103
  }
94
104
  export {};
package/cjs/app/index.js CHANGED
@@ -1,6 +1,6 @@
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
4
  const messages_js_1 = require("../common/messages.js");
5
5
  const utils_js_1 = require("../utils.js");
6
6
  const nodes_js_1 = require("./nodes.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,7 +32,7 @@ class App {
29
32
  this.stopCallbacks = [];
30
33
  this.commitCallbacks = [];
31
34
  this.activityState = ActivityState.NotActive;
32
- this.version = '3.5.11'; // TODO: version compatability check inside each plugin.
35
+ this.version = '3.5.12'; // TODO: version compatability check inside each plugin.
33
36
  this.projectKey = projectKey;
34
37
  this.options = Object.assign({
35
38
  revID: '',
@@ -225,10 +228,10 @@ class App {
225
228
  }
226
229
  _start(startOpts) {
227
230
  if (!this.worker) {
228
- return Promise.reject("No worker found: perhaps, CSP is not set.");
231
+ return Promise.resolve(UnsuccessfulStart("No worker found: perhaps, CSP is not set."));
229
232
  }
230
233
  if (this.activityState !== ActivityState.NotActive) {
231
- 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."));
232
235
  }
233
236
  this.activityState = ActivityState.Starting;
234
237
  let pageNo = 0;
@@ -263,8 +266,8 @@ class App {
263
266
  return r.json();
264
267
  }
265
268
  else {
266
- return r.text().then(text => text === exports.CANCELED
267
- ? 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
268
271
  : Promise.reject(`Server error: ${r.status}. ${text}`));
269
272
  }
270
273
  })
@@ -297,17 +300,17 @@ class App {
297
300
  if (typeof this.options.onStart === 'function') {
298
301
  this.options.onStart(onStartInfo);
299
302
  }
300
- return onStartInfo;
303
+ return SuccessfulStart(onStartInfo);
301
304
  })
302
305
  .catch(reason => {
303
306
  sessionStorage.removeItem(this.options.session_token_key);
304
307
  this.stop();
305
- //if (reason === CANCELED) { return Promise.resolve(CANCELED) } // TODO: what to return ????? Throwing is baad
306
- if (reason !== exports.CANCELED) {
307
- this.notify.log("OpenReplay was unable to start. ", reason);
308
- this._debug("session_start", reason);
308
+ if (reason === CANCELED) {
309
+ return UnsuccessfulStart(CANCELED);
309
310
  }
310
- 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);
311
314
  });
312
315
  }
313
316
  start(options = {}) {
package/cjs/index.d.ts CHANGED
@@ -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
@@ -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.11',
130
+ trackerVersion: '3.5.12',
131
131
  projectKey: options.projectKey,
132
132
  doNotTrack,
133
133
  // TODO: add precise reason (an exact API missing)
@@ -13,11 +13,22 @@ export interface StartOptions {
13
13
  metadata?: Record<string, string>;
14
14
  forceNew?: boolean;
15
15
  }
16
- export interface OnStartInfo {
16
+ interface OnStartInfo {
17
17
  sessionID: string;
18
18
  sessionToken: string;
19
19
  userUUID: string;
20
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;
21
32
  declare type StartCallback = (i: OnStartInfo) => void;
22
33
  declare type CommitCallback = (messages: Array<Message>) => void;
23
34
  declare type AppOptions = {
@@ -36,7 +47,6 @@ declare type AppOptions = {
36
47
  onStart?: StartCallback;
37
48
  } & WebworkerOptions;
38
49
  export declare type Options = AppOptions & ObserverOptions & SanitizerOptions;
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;
@@ -88,7 +98,7 @@ export default class App {
88
98
  active(): boolean;
89
99
  resetNextPageSession(flag: boolean): void;
90
100
  private _start;
91
- start(options?: StartOptions): Promise<OnStartInfo>;
101
+ start(options?: StartOptions): Promise<StartPromiseReturn>;
92
102
  stop(): void;
93
103
  }
94
104
  export {};
package/lib/app/index.js CHANGED
@@ -7,13 +7,16 @@ import Ticker from "./ticker.js";
7
7
  import Logger, { LogLevel } from "./logger.js";
8
8
  import Session from "./session.js";
9
9
  import { deviceMemory, jsHeapSizeLimit } from "../modules/performance.js";
10
+ const CANCELED = "canceled";
11
+ const START_ERROR = ":(";
12
+ const UnsuccessfulStart = (reason) => ({ reason, success: false });
13
+ const SuccessfulStart = (body) => (Object.assign(Object.assign({}, body), { success: true }));
10
14
  var ActivityState;
11
15
  (function (ActivityState) {
12
16
  ActivityState[ActivityState["NotActive"] = 0] = "NotActive";
13
17
  ActivityState[ActivityState["Starting"] = 1] = "Starting";
14
18
  ActivityState[ActivityState["Active"] = 2] = "Active";
15
19
  })(ActivityState || (ActivityState = {}));
16
- export const CANCELED = "canceled";
17
20
  // TODO: use backendHost only
18
21
  export const DEFAULT_INGEST_POINT = 'https://api.openreplay.com/ingest';
19
22
  export default class App {
@@ -26,7 +29,7 @@ export default class App {
26
29
  this.stopCallbacks = [];
27
30
  this.commitCallbacks = [];
28
31
  this.activityState = ActivityState.NotActive;
29
- this.version = '3.5.11'; // TODO: version compatability check inside each plugin.
32
+ this.version = '3.5.12'; // TODO: version compatability check inside each plugin.
30
33
  this.projectKey = projectKey;
31
34
  this.options = Object.assign({
32
35
  revID: '',
@@ -222,10 +225,10 @@ export default class App {
222
225
  }
223
226
  _start(startOpts) {
224
227
  if (!this.worker) {
225
- return Promise.reject("No worker found: perhaps, CSP is not set.");
228
+ return Promise.resolve(UnsuccessfulStart("No worker found: perhaps, CSP is not set."));
226
229
  }
227
230
  if (this.activityState !== ActivityState.NotActive) {
228
- return Promise.reject("OpenReplay: trying to call `start()` on the instance that has been started already.");
231
+ return Promise.resolve(UnsuccessfulStart("OpenReplay: trying to call `start()` on the instance that has been started already."));
229
232
  }
230
233
  this.activityState = ActivityState.Starting;
231
234
  let pageNo = 0;
@@ -294,17 +297,17 @@ export default class App {
294
297
  if (typeof this.options.onStart === 'function') {
295
298
  this.options.onStart(onStartInfo);
296
299
  }
297
- return onStartInfo;
300
+ return SuccessfulStart(onStartInfo);
298
301
  })
299
302
  .catch(reason => {
300
303
  sessionStorage.removeItem(this.options.session_token_key);
301
304
  this.stop();
302
- //if (reason === CANCELED) { return Promise.resolve(CANCELED) } // TODO: what to return ????? Throwing is baad
303
- if (reason !== CANCELED) {
304
- this.notify.log("OpenReplay was unable to start. ", reason);
305
- this._debug("session_start", reason);
305
+ if (reason === CANCELED) {
306
+ return UnsuccessfulStart(CANCELED);
306
307
  }
307
- return Promise.reject(reason);
308
+ this.notify.log("OpenReplay was unable to start. ", reason);
309
+ this._debug("session_start", reason);
310
+ return UnsuccessfulStart(START_ERROR);
308
311
  });
309
312
  }
310
313
  start(options = {}) {
package/lib/index.d.ts CHANGED
@@ -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/lib/index.js CHANGED
@@ -123,7 +123,7 @@ export default class API {
123
123
  // no-cors issue only with text/plain or not-set Content-Type
124
124
  // req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
125
125
  req.send(JSON.stringify({
126
- trackerVersion: '3.5.11',
126
+ trackerVersion: '3.5.12',
127
127
  projectKey: options.projectKey,
128
128
  doNotTrack,
129
129
  // TODO: add precise reason (an exact API missing)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openreplay/tracker",
3
3
  "description": "The OpenReplay tracker main package",
4
- "version": "3.5.11",
4
+ "version": "3.5.12",
5
5
  "keywords": [
6
6
  "logging",
7
7
  "replay"