@yuno-payments/sdk-event-log 0.3.0-beta.7 → 0.3.0-beta.8

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.
@@ -2,7 +2,7 @@ import { AxiosInstance } from 'axios';
2
2
  import { Batch } from '../types';
3
3
  declare class Api {
4
4
  #private;
5
- init(publicApiKey: string, platform: string): void;
5
+ init(publicApiKey: string, platform: string, debug?: boolean): void;
6
6
  sendBatch(batches: Batch[]): Promise<import("axios").AxiosResponse<any, any>> | undefined;
7
7
  getInstances(): AxiosInstance | null;
8
8
  }
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- var _Api_instance;
16
+ var _Api_instance, _Api_debug;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.api = void 0;
19
19
  const axios_1 = __importDefault(require("axios"));
@@ -21,8 +21,10 @@ const api_utils_1 = require("./api.utils");
21
21
  class Api {
22
22
  constructor() {
23
23
  _Api_instance.set(this, null);
24
+ _Api_debug.set(this, false);
24
25
  }
25
- init(publicApiKey, platform) {
26
+ init(publicApiKey, platform, debug = false) {
27
+ __classPrivateFieldSet(this, _Api_debug, debug, "f");
26
28
  __classPrivateFieldSet(this, _Api_instance, axios_1.default.create({
27
29
  baseURL: (0, api_utils_1.getBaseUrl)(publicApiKey),
28
30
  // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -31,12 +33,14 @@ class Api {
31
33
  }
32
34
  sendBatch(batches) {
33
35
  var _a;
34
- console.dir(batches, { depth: null });
36
+ if (!__classPrivateFieldGet(this, _Api_debug, "f")) {
37
+ console.dir(batches, { depth: null });
38
+ }
35
39
  return (_a = __classPrivateFieldGet(this, _Api_instance, "f")) === null || _a === void 0 ? void 0 : _a.post('/sdk/event-log/publish', { batch: batches });
36
40
  }
37
41
  getInstances() {
38
42
  return __classPrivateFieldGet(this, _Api_instance, "f");
39
43
  }
40
44
  }
41
- _Api_instance = new WeakMap();
45
+ _Api_instance = new WeakMap(), _Api_debug = new WeakMap();
42
46
  exports.api = new Api();
@@ -23,10 +23,12 @@ class Cron {
23
23
  init(batchTime) {
24
24
  this.stop();
25
25
  __classPrivateFieldSet(this, _Cron_interval, setInterval(this.sendBatch, batchTime), "f");
26
+ console.log('cron started');
26
27
  }
27
28
  sendBatch() {
28
29
  database_1.database.getAllItems().then((items) => {
29
30
  var _a;
31
+ console.log('items', items);
30
32
  if (items.length > NONE_ITEMS) {
31
33
  (_a = api_1.api.sendBatch(items)) === null || _a === void 0 ? void 0 : _a.then(() => database_1.database.reset());
32
34
  }
@@ -3,7 +3,7 @@ import './database';
3
3
  import { Event, Log } from './types';
4
4
  declare class EventLog {
5
5
  #private;
6
- init({ publicApiKey, platform, batchTime, enableEvents, enableLogs }: InitArgs): void;
6
+ init({ publicApiKey, platform, batchTime, enableEvents, enableLogs, debug }: InitArgs): void;
7
7
  event(eventArgs: Omit<Event, 'type'>): Promise<void> | undefined;
8
8
  logger: {
9
9
  error: (errorArgs: Omit<Log, 'level' | 'type'>) => Promise<void> | undefined;
package/dist/cjs/index.js CHANGED
@@ -35,10 +35,10 @@ class EventLog {
35
35
  }
36
36
  };
37
37
  }
38
- init({ publicApiKey, platform = 'web', batchTime, enableEvents, enableLogs }) {
38
+ init({ publicApiKey, platform = 'web', batchTime, enableEvents, enableLogs, debug = false }) {
39
39
  __classPrivateFieldSet(this, _EventLog_enableEvents, enableEvents, "f");
40
40
  __classPrivateFieldSet(this, _EventLog_enableLogs, enableLogs, "f");
41
- api_1.api.init(publicApiKey, platform);
41
+ api_1.api.init(publicApiKey, platform, debug);
42
42
  cron_1.cron.init(batchTime);
43
43
  }
44
44
  event(eventArgs) {
@@ -60,10 +60,12 @@ describe('EventLog', () => {
60
60
  expect(events).toHaveLength(0);
61
61
  }));
62
62
  it('should log an error', () => __awaiter(void 0, void 0, void 0, function* () {
63
+ index_1.eventLog.logger.error(logArgs);
63
64
  index_1.eventLog.logger.error(logArgs);
64
65
  const events = yield database_1.database.getAllItems();
65
- expect(events).toHaveLength(1);
66
+ expect(events).toHaveLength(2);
66
67
  expect(events[0]).toMatchObject(logArgs);
68
+ expect(events[1]).toMatchObject(logArgs);
67
69
  }));
68
70
  it('should not log an error if logs are disabled', () => __awaiter(void 0, void 0, void 0, function* () {
69
71
  index_1.eventLog.init({
@@ -4,4 +4,5 @@ export type InitArgs = {
4
4
  enableEvents: boolean;
5
5
  enableLogs: boolean;
6
6
  platform?: string;
7
+ debug?: boolean;
7
8
  };
@@ -2,7 +2,7 @@ import { AxiosInstance } from 'axios';
2
2
  import { Batch } from '../types';
3
3
  declare class Api {
4
4
  #private;
5
- init(publicApiKey: string, platform: string): void;
5
+ init(publicApiKey: string, platform: string, debug?: boolean): void;
6
6
  sendBatch(batches: Batch[]): Promise<import("axios").AxiosResponse<any, any>> | undefined;
7
7
  getInstances(): AxiosInstance | null;
8
8
  }
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- var _Api_instance;
16
+ var _Api_instance, _Api_debug;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.api = void 0;
19
19
  const axios_1 = __importDefault(require("axios"));
@@ -21,8 +21,10 @@ const api_utils_1 = require("./api.utils");
21
21
  class Api {
22
22
  constructor() {
23
23
  _Api_instance.set(this, null);
24
+ _Api_debug.set(this, false);
24
25
  }
25
- init(publicApiKey, platform) {
26
+ init(publicApiKey, platform, debug = false) {
27
+ __classPrivateFieldSet(this, _Api_debug, debug, "f");
26
28
  __classPrivateFieldSet(this, _Api_instance, axios_1.default.create({
27
29
  baseURL: (0, api_utils_1.getBaseUrl)(publicApiKey),
28
30
  // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -31,12 +33,14 @@ class Api {
31
33
  }
32
34
  sendBatch(batches) {
33
35
  var _a;
34
- console.dir(batches, { depth: null });
36
+ if (!__classPrivateFieldGet(this, _Api_debug, "f")) {
37
+ console.dir(batches, { depth: null });
38
+ }
35
39
  return (_a = __classPrivateFieldGet(this, _Api_instance, "f")) === null || _a === void 0 ? void 0 : _a.post('/sdk/event-log/publish', { batch: batches });
36
40
  }
37
41
  getInstances() {
38
42
  return __classPrivateFieldGet(this, _Api_instance, "f");
39
43
  }
40
44
  }
41
- _Api_instance = new WeakMap();
45
+ _Api_instance = new WeakMap(), _Api_debug = new WeakMap();
42
46
  exports.api = new Api();
@@ -23,10 +23,12 @@ class Cron {
23
23
  init(batchTime) {
24
24
  this.stop();
25
25
  __classPrivateFieldSet(this, _Cron_interval, setInterval(this.sendBatch, batchTime), "f");
26
+ console.log('cron started');
26
27
  }
27
28
  sendBatch() {
28
29
  database_1.database.getAllItems().then((items) => {
29
30
  var _a;
31
+ console.log('items', items);
30
32
  if (items.length > NONE_ITEMS) {
31
33
  (_a = api_1.api.sendBatch(items)) === null || _a === void 0 ? void 0 : _a.then(() => database_1.database.reset());
32
34
  }
@@ -3,7 +3,7 @@ import './database';
3
3
  import { Event, Log } from './types';
4
4
  declare class EventLog {
5
5
  #private;
6
- init({ publicApiKey, platform, batchTime, enableEvents, enableLogs }: InitArgs): void;
6
+ init({ publicApiKey, platform, batchTime, enableEvents, enableLogs, debug }: InitArgs): void;
7
7
  event(eventArgs: Omit<Event, 'type'>): Promise<void> | undefined;
8
8
  logger: {
9
9
  error: (errorArgs: Omit<Log, 'level' | 'type'>) => Promise<void> | undefined;
package/dist/esm/index.js CHANGED
@@ -35,10 +35,10 @@ class EventLog {
35
35
  }
36
36
  };
37
37
  }
38
- init({ publicApiKey, platform = 'web', batchTime, enableEvents, enableLogs }) {
38
+ init({ publicApiKey, platform = 'web', batchTime, enableEvents, enableLogs, debug = false }) {
39
39
  __classPrivateFieldSet(this, _EventLog_enableEvents, enableEvents, "f");
40
40
  __classPrivateFieldSet(this, _EventLog_enableLogs, enableLogs, "f");
41
- api_1.api.init(publicApiKey, platform);
41
+ api_1.api.init(publicApiKey, platform, debug);
42
42
  cron_1.cron.init(batchTime);
43
43
  }
44
44
  event(eventArgs) {
@@ -51,10 +51,12 @@ describe('EventLog', () => {
51
51
  expect(events).toHaveLength(0);
52
52
  });
53
53
  it('should log an error', async () => {
54
+ index_1.eventLog.logger.error(logArgs);
54
55
  index_1.eventLog.logger.error(logArgs);
55
56
  const events = await database_1.database.getAllItems();
56
- expect(events).toHaveLength(1);
57
+ expect(events).toHaveLength(2);
57
58
  expect(events[0]).toMatchObject(logArgs);
59
+ expect(events[1]).toMatchObject(logArgs);
58
60
  });
59
61
  it('should not log an error if logs are disabled', async () => {
60
62
  index_1.eventLog.init({
@@ -4,4 +4,5 @@ export type InitArgs = {
4
4
  enableEvents: boolean;
5
5
  enableLogs: boolean;
6
6
  platform?: string;
7
+ debug?: boolean;
7
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuno-payments/sdk-event-log",
3
- "version": "0.3.0-beta.7",
3
+ "version": "0.3.0-beta.8",
4
4
  "description": "Register application logs and events",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",