@yuno-payments/sdk-event-log 1.0.0-beta.1 → 1.0.0-beta.11
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/dist/cjs/api/api.d.ts +5 -3
- package/dist/cjs/api/api.types.d.ts +9 -0
- package/dist/cjs/cron/cron.d.ts +1 -0
- package/dist/cjs/database/database.types.d.ts +2 -2
- package/dist/cjs/database/local-storage/local-storage.d.ts +2 -2
- package/dist/cjs/database/memory-storage/memory-storage.d.ts +2 -4
- package/dist/cjs/event-log-main/event-log-main.d.ts +26 -0
- package/dist/cjs/event-log-main/event-logs-main.types.d.ts +24 -0
- package/dist/cjs/event-log-main/index.d.ts +2 -0
- package/dist/cjs/index.d.ts +7 -9
- package/dist/cjs/index.js +2 -74
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types/index.d.ts +5 -15
- package/dist/cjs/utils/client-detection.d.ts +2 -8
- package/dist/esm/api/api.d.ts +5 -3
- package/dist/esm/api/api.types.d.ts +9 -0
- package/dist/esm/cron/cron.d.ts +1 -0
- package/dist/esm/database/database.types.d.ts +2 -2
- package/dist/esm/database/local-storage/local-storage.d.ts +2 -2
- package/dist/esm/database/memory-storage/memory-storage.d.ts +2 -4
- package/dist/esm/event-log-main/event-log-main.d.ts +26 -0
- package/dist/esm/event-log-main/event-logs-main.types.d.ts +24 -0
- package/dist/esm/event-log-main/index.d.ts +2 -0
- package/dist/esm/index.d.ts +7 -9
- package/dist/esm/index.js +2 -67
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types/index.d.ts +5 -15
- package/dist/esm/utils/client-detection.d.ts +2 -8
- package/package.json +13 -6
- package/dist/cjs/api/__tests__/api.test.d.ts +0 -1
- package/dist/cjs/api/__tests__/api.test.js +0 -45
- package/dist/cjs/api/__tests__/api.utils.test.d.ts +0 -1
- package/dist/cjs/api/__tests__/api.utils.test.js +0 -35
- package/dist/cjs/api/api.js +0 -48
- package/dist/cjs/api/api.utils.js +0 -18
- package/dist/cjs/api/index.js +0 -17
- package/dist/cjs/cron/cron.js +0 -58
- package/dist/cjs/cron/cron.test.d.ts +0 -1
- package/dist/cjs/cron/cron.test.js +0 -56
- package/dist/cjs/cron/index.js +0 -17
- package/dist/cjs/database/database.js +0 -20
- package/dist/cjs/database/database.test.d.ts +0 -1
- package/dist/cjs/database/database.test.js +0 -25
- package/dist/cjs/database/database.types.js +0 -2
- package/dist/cjs/database/index.js +0 -18
- package/dist/cjs/database/local-storage/index.js +0 -17
- package/dist/cjs/database/local-storage/local-storage.js +0 -74
- package/dist/cjs/database/local-storage/local-storage.test.d.ts +0 -1
- package/dist/cjs/database/local-storage/local-storage.test.js +0 -40
- package/dist/cjs/database/memory-storage/index.js +0 -17
- package/dist/cjs/database/memory-storage/memory-storage.js +0 -56
- package/dist/cjs/database/memory-storage/memory-storage.test.d.ts +0 -1
- package/dist/cjs/database/memory-storage/memory-storage.test.js +0 -34
- package/dist/cjs/index.test.d.ts +0 -1
- package/dist/cjs/index.test.js +0 -197
- package/dist/cjs/index.types.d.ts +0 -8
- package/dist/cjs/index.types.js +0 -2
- package/dist/cjs/index.utils.d.ts +0 -5
- package/dist/cjs/index.utils.js +0 -20
- package/dist/cjs/types/index.js +0 -14
- package/dist/cjs/utils/__tests__/check-environment.test.d.ts +0 -1
- package/dist/cjs/utils/__tests__/check-environment.test.js +0 -30
- package/dist/cjs/utils/__tests__/client-detection.test.d.ts +0 -1
- package/dist/cjs/utils/__tests__/client-detection.test.js +0 -40
- package/dist/cjs/utils/check-environment.js +0 -17
- package/dist/cjs/utils/client-detection.js +0 -216
- package/dist/cjs/utils/index.js +0 -19
- package/dist/cjs/utils/stringyfy.js +0 -20
- package/dist/esm/api/__tests__/api.test.d.ts +0 -1
- package/dist/esm/api/__tests__/api.test.js +0 -36
- package/dist/esm/api/__tests__/api.utils.test.d.ts +0 -1
- package/dist/esm/api/__tests__/api.utils.test.js +0 -35
- package/dist/esm/api/api.js +0 -48
- package/dist/esm/api/api.utils.js +0 -18
- package/dist/esm/api/index.js +0 -17
- package/dist/esm/cron/cron.js +0 -47
- package/dist/esm/cron/cron.test.d.ts +0 -1
- package/dist/esm/cron/cron.test.js +0 -47
- package/dist/esm/cron/index.js +0 -17
- package/dist/esm/database/database.js +0 -20
- package/dist/esm/database/database.test.d.ts +0 -1
- package/dist/esm/database/database.test.js +0 -25
- package/dist/esm/database/database.types.js +0 -2
- package/dist/esm/database/index.js +0 -18
- package/dist/esm/database/local-storage/index.js +0 -17
- package/dist/esm/database/local-storage/local-storage.js +0 -61
- package/dist/esm/database/local-storage/local-storage.test.d.ts +0 -1
- package/dist/esm/database/local-storage/local-storage.test.js +0 -31
- package/dist/esm/database/memory-storage/index.js +0 -17
- package/dist/esm/database/memory-storage/memory-storage.js +0 -43
- package/dist/esm/database/memory-storage/memory-storage.test.d.ts +0 -1
- package/dist/esm/database/memory-storage/memory-storage.test.js +0 -25
- package/dist/esm/index.test.d.ts +0 -1
- package/dist/esm/index.test.js +0 -228
- package/dist/esm/index.types.d.ts +0 -8
- package/dist/esm/index.types.js +0 -2
- package/dist/esm/index.utils.d.ts +0 -5
- package/dist/esm/index.utils.js +0 -29
- package/dist/esm/types/index.js +0 -14
- package/dist/esm/utils/__tests__/check-environment.test.d.ts +0 -1
- package/dist/esm/utils/__tests__/check-environment.test.js +0 -30
- package/dist/esm/utils/__tests__/client-detection.test.d.ts +0 -1
- package/dist/esm/utils/__tests__/client-detection.test.js +0 -31
- package/dist/esm/utils/check-environment.js +0 -17
- package/dist/esm/utils/client-detection.js +0 -205
- package/dist/esm/utils/index.js +0 -19
- package/dist/esm/utils/stringyfy.js +0 -20
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _LocalStorage_instances, _LocalStorage_localStorage, _LocalStorage_databaseName, _LocalStorage_getDatabase;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.LocalStorage = void 0;
|
|
16
|
-
const utils_1 = require("../../utils");
|
|
17
|
-
const DATABASE_NAME_SPACE = 'YUNO_EVENT_LOGS';
|
|
18
|
-
class LocalStorage {
|
|
19
|
-
constructor(organizationName) {
|
|
20
|
-
_LocalStorage_instances.add(this);
|
|
21
|
-
_LocalStorage_localStorage.set(this, void 0);
|
|
22
|
-
_LocalStorage_databaseName.set(this, void 0);
|
|
23
|
-
__classPrivateFieldSet(this, _LocalStorage_localStorage, window.localStorage, "f");
|
|
24
|
-
__classPrivateFieldSet(this, _LocalStorage_databaseName, `${DATABASE_NAME_SPACE}_${organizationName}`, "f");
|
|
25
|
-
const database = __classPrivateFieldGet(this, _LocalStorage_localStorage, "f").getItem(__classPrivateFieldGet(this, _LocalStorage_databaseName, "f"));
|
|
26
|
-
if (database === null || database === undefined) {
|
|
27
|
-
this.reset();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async reset() {
|
|
31
|
-
__classPrivateFieldGet(this, _LocalStorage_localStorage, "f").setItem(__classPrivateFieldGet(this, _LocalStorage_databaseName, "f"), JSON.stringify({}));
|
|
32
|
-
}
|
|
33
|
-
async setItem(item, publicApiKey) {
|
|
34
|
-
const database = __classPrivateFieldGet(this, _LocalStorage_instances, "m", _LocalStorage_getDatabase).call(this);
|
|
35
|
-
if (database[publicApiKey] === undefined) {
|
|
36
|
-
database[publicApiKey] = [];
|
|
37
|
-
}
|
|
38
|
-
database[publicApiKey].push(item);
|
|
39
|
-
__classPrivateFieldGet(this, _LocalStorage_localStorage, "f").setItem(__classPrivateFieldGet(this, _LocalStorage_databaseName, "f"), (0, utils_1.stringify)(database));
|
|
40
|
-
}
|
|
41
|
-
getItem(id) {
|
|
42
|
-
throw new Error('Method not implemented.' + id);
|
|
43
|
-
}
|
|
44
|
-
removeItem(id) {
|
|
45
|
-
throw new Error('Method not implemented.' + id);
|
|
46
|
-
}
|
|
47
|
-
getAllItems() {
|
|
48
|
-
const database = __classPrivateFieldGet(this, _LocalStorage_instances, "m", _LocalStorage_getDatabase).call(this);
|
|
49
|
-
this.reset();
|
|
50
|
-
return Promise.resolve(database);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.LocalStorage = LocalStorage;
|
|
54
|
-
_LocalStorage_localStorage = new WeakMap(), _LocalStorage_databaseName = new WeakMap(), _LocalStorage_instances = new WeakSet(), _LocalStorage_getDatabase = function _LocalStorage_getDatabase() {
|
|
55
|
-
let database = __classPrivateFieldGet(this, _LocalStorage_localStorage, "f").getItem(__classPrivateFieldGet(this, _LocalStorage_databaseName, "f"));
|
|
56
|
-
if (database === null || database === undefined) {
|
|
57
|
-
database = JSON.stringify({});
|
|
58
|
-
__classPrivateFieldGet(this, _LocalStorage_localStorage, "f").setItem(__classPrivateFieldGet(this, _LocalStorage_databaseName, "f"), database);
|
|
59
|
-
}
|
|
60
|
-
return JSON.parse(database);
|
|
61
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const types_1 = require("../../types");
|
|
4
|
-
const local_storage_1 = require("./local-storage");
|
|
5
|
-
const batch = {
|
|
6
|
-
source: 'test',
|
|
7
|
-
event: 'testEvent',
|
|
8
|
-
description: 'Test event',
|
|
9
|
-
original_created_at: new Date().toISOString(),
|
|
10
|
-
type: types_1.EventLogType.EVENT,
|
|
11
|
-
};
|
|
12
|
-
describe('LocalStorageDatabase', () => {
|
|
13
|
-
let localStorageDatabase;
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
localStorageDatabase = new local_storage_1.LocalStorage('test');
|
|
16
|
-
});
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
localStorage.clear();
|
|
19
|
-
});
|
|
20
|
-
it('should set an item in the database', async () => {
|
|
21
|
-
const testKey = 'testKey';
|
|
22
|
-
await localStorageDatabase.setItem(batch, testKey);
|
|
23
|
-
const database = JSON.parse(localStorage.getItem('YUNO_EVENT_LOGS_test') || '[]');
|
|
24
|
-
expect(database).toEqual({ [testKey]: [batch] });
|
|
25
|
-
});
|
|
26
|
-
it('should get an item from the database', async () => {
|
|
27
|
-
localStorage.setItem('YUNO_EVENT_LOGS_test', JSON.stringify({ testKey: [batch] }));
|
|
28
|
-
const result = await localStorageDatabase.getAllItems();
|
|
29
|
-
expect(result).toEqual({ testKey: [batch] });
|
|
30
|
-
});
|
|
31
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./memory-storage"), exports);
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _MemoryStorage_items;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.MemoryStorage = void 0;
|
|
16
|
-
class MemoryStorage {
|
|
17
|
-
constructor() {
|
|
18
|
-
_MemoryStorage_items.set(this, void 0);
|
|
19
|
-
__classPrivateFieldSet(this, _MemoryStorage_items, {}, "f");
|
|
20
|
-
}
|
|
21
|
-
async reset() {
|
|
22
|
-
__classPrivateFieldSet(this, _MemoryStorage_items, {}, "f");
|
|
23
|
-
}
|
|
24
|
-
async setItem(item, publicApiKey) {
|
|
25
|
-
if (__classPrivateFieldGet(this, _MemoryStorage_items, "f")[publicApiKey] === undefined) {
|
|
26
|
-
__classPrivateFieldGet(this, _MemoryStorage_items, "f")[publicApiKey] = [];
|
|
27
|
-
}
|
|
28
|
-
__classPrivateFieldGet(this, _MemoryStorage_items, "f")[publicApiKey].push(item);
|
|
29
|
-
}
|
|
30
|
-
getItem(id) {
|
|
31
|
-
throw new Error('Method not implemented.' + id);
|
|
32
|
-
}
|
|
33
|
-
removeItem(id) {
|
|
34
|
-
throw new Error('Method not implemented.' + id);
|
|
35
|
-
}
|
|
36
|
-
getAllItems() {
|
|
37
|
-
const items = { ...__classPrivateFieldGet(this, _MemoryStorage_items, "f") };
|
|
38
|
-
this.reset();
|
|
39
|
-
return Promise.resolve(items);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.MemoryStorage = MemoryStorage;
|
|
43
|
-
_MemoryStorage_items = new WeakMap();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const types_1 = require("../../types");
|
|
4
|
-
const memory_storage_1 = require("./memory-storage");
|
|
5
|
-
const batch = {
|
|
6
|
-
source: 'test',
|
|
7
|
-
event: 'testEvent',
|
|
8
|
-
description: 'Test event',
|
|
9
|
-
original_created_at: new Date().toISOString(),
|
|
10
|
-
type: types_1.EventLogType.EVENT,
|
|
11
|
-
};
|
|
12
|
-
describe('MemoryStorage', () => {
|
|
13
|
-
let memoryStorage;
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
memoryStorage = new memory_storage_1.MemoryStorage();
|
|
16
|
-
});
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
memoryStorage.reset();
|
|
19
|
-
});
|
|
20
|
-
it('should set an item in the database', async () => {
|
|
21
|
-
await memoryStorage.setItem(batch, 'testKey');
|
|
22
|
-
const database = await memoryStorage.getAllItems();
|
|
23
|
-
expect(database).toEqual({ testKey: [batch] });
|
|
24
|
-
});
|
|
25
|
-
});
|
package/dist/esm/index.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/index.test.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/* eslint-disable no-magic-numbers */
|
|
4
|
-
const index_1 = require("./index");
|
|
5
|
-
const types_1 = require("./types");
|
|
6
|
-
const node_1 = require("msw/node");
|
|
7
|
-
const msw_1 = require("msw");
|
|
8
|
-
const eventArgs = {
|
|
9
|
-
source: 'test',
|
|
10
|
-
event: 'testEvent',
|
|
11
|
-
description: 'Test event',
|
|
12
|
-
original_created_at: new Date().toISOString(),
|
|
13
|
-
};
|
|
14
|
-
const logArgs = {
|
|
15
|
-
sdk_version: '',
|
|
16
|
-
url: '',
|
|
17
|
-
method: '',
|
|
18
|
-
country: '',
|
|
19
|
-
original_created_at: new Date().toISOString(),
|
|
20
|
-
};
|
|
21
|
-
const browserClientInfo = {
|
|
22
|
-
browser: 'jsdom',
|
|
23
|
-
browserMajorVersion: 20,
|
|
24
|
-
browserVersion: '20.0.3',
|
|
25
|
-
cookies: true,
|
|
26
|
-
mobile: false,
|
|
27
|
-
os: '-',
|
|
28
|
-
osVersion: '-',
|
|
29
|
-
screen: '',
|
|
30
|
-
};
|
|
31
|
-
const metadata = {
|
|
32
|
-
browser_info: browserClientInfo,
|
|
33
|
-
};
|
|
34
|
-
const publicApiKey = 'prod_1';
|
|
35
|
-
let mockInterceptRequest = jest.fn();
|
|
36
|
-
const server = (0, node_1.setupServer)(
|
|
37
|
-
// Describe the requests to mock.
|
|
38
|
-
msw_1.rest.post('https://api.y.uno/v1/sdk/event-log/publish', (req, res, ctx) => {
|
|
39
|
-
mockInterceptRequest(req.body);
|
|
40
|
-
return res(ctx.status(200));
|
|
41
|
-
}));
|
|
42
|
-
describe('EventLog', () => {
|
|
43
|
-
let eventLog;
|
|
44
|
-
beforeAll(() => {
|
|
45
|
-
mockInterceptRequest = jest.fn();
|
|
46
|
-
server.listen();
|
|
47
|
-
});
|
|
48
|
-
// Reset any request handlers that we may add during the tests,
|
|
49
|
-
// so they don't affect other tests.
|
|
50
|
-
afterEach(() => server.resetHandlers());
|
|
51
|
-
// Clean up after the tests are finished.
|
|
52
|
-
afterAll(() => server.close());
|
|
53
|
-
beforeEach(() => {
|
|
54
|
-
eventLog = new index_1.EventLog({
|
|
55
|
-
organizationName: 'testOrg',
|
|
56
|
-
debug: false,
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
afterEach(() => {
|
|
60
|
-
jest.clearAllMocks();
|
|
61
|
-
});
|
|
62
|
-
describe('event', () => {
|
|
63
|
-
it('should add an event to the database if events are enabled', async () => {
|
|
64
|
-
eventLog.event(eventArgs, publicApiKey);
|
|
65
|
-
eventLog.sendBatch();
|
|
66
|
-
await new Promise(process.nextTick);
|
|
67
|
-
expect(mockInterceptRequest).toHaveBeenCalledWith({
|
|
68
|
-
batch: [
|
|
69
|
-
{ ...eventArgs, os: browserClientInfo.os, type: types_1.EventLogType.EVENT },
|
|
70
|
-
],
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
it('should not add an event to the database if events are disabled', async () => {
|
|
74
|
-
const publicApiKey = 'testApiKey';
|
|
75
|
-
eventLog = new index_1.EventLog({
|
|
76
|
-
organizationName: 'testOrg',
|
|
77
|
-
enableEvents: false,
|
|
78
|
-
});
|
|
79
|
-
eventLog.event(eventArgs, publicApiKey);
|
|
80
|
-
eventLog.sendBatch();
|
|
81
|
-
await new Promise(process.nextTick);
|
|
82
|
-
expect(mockInterceptRequest).not.toHaveBeenCalled();
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
describe('logger', () => {
|
|
86
|
-
it('should add an error log to the database if logs are enabled', async () => {
|
|
87
|
-
eventLog.logger.error(logArgs, publicApiKey);
|
|
88
|
-
eventLog.sendBatch();
|
|
89
|
-
await new Promise(process.nextTick);
|
|
90
|
-
expect(mockInterceptRequest).toHaveBeenCalledWith({
|
|
91
|
-
batch: [
|
|
92
|
-
{
|
|
93
|
-
...logArgs,
|
|
94
|
-
os: browserClientInfo.os,
|
|
95
|
-
metadata,
|
|
96
|
-
type: types_1.EventLogType.LOG,
|
|
97
|
-
level: types_1.Level.ERROR,
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
it('should not add an error log to the database if logs are disabled', async () => {
|
|
103
|
-
const publicApiKey = 'testApiKey';
|
|
104
|
-
eventLog = new index_1.EventLog({
|
|
105
|
-
organizationName: 'testOrg',
|
|
106
|
-
enableEvents: true,
|
|
107
|
-
enableLogs: false,
|
|
108
|
-
debug: false,
|
|
109
|
-
});
|
|
110
|
-
eventLog.logger.error(logArgs, publicApiKey);
|
|
111
|
-
eventLog.sendBatch();
|
|
112
|
-
await new Promise(process.nextTick);
|
|
113
|
-
expect(mockInterceptRequest).not.toHaveBeenCalled();
|
|
114
|
-
});
|
|
115
|
-
it('should add a debug log to the database if logs are enabled', async () => {
|
|
116
|
-
eventLog.logger.debug(logArgs, publicApiKey);
|
|
117
|
-
eventLog.sendBatch();
|
|
118
|
-
await new Promise(process.nextTick);
|
|
119
|
-
expect(mockInterceptRequest).toHaveBeenCalledWith({
|
|
120
|
-
batch: [
|
|
121
|
-
{
|
|
122
|
-
...logArgs,
|
|
123
|
-
os: browserClientInfo.os,
|
|
124
|
-
metadata,
|
|
125
|
-
type: types_1.EventLogType.LOG,
|
|
126
|
-
level: types_1.Level.DEBUG,
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
it('should not add a debug log to the database if logs are disabled', async () => {
|
|
132
|
-
const publicApiKey = 'testApiKey';
|
|
133
|
-
eventLog = new index_1.EventLog({
|
|
134
|
-
organizationName: 'testOrg',
|
|
135
|
-
platform: 'web',
|
|
136
|
-
enableEvents: true,
|
|
137
|
-
enableLogs: false,
|
|
138
|
-
debug: false,
|
|
139
|
-
});
|
|
140
|
-
eventLog.logger.debug(logArgs, publicApiKey);
|
|
141
|
-
eventLog.sendBatch();
|
|
142
|
-
await new Promise(process.nextTick);
|
|
143
|
-
expect(mockInterceptRequest).not.toHaveBeenCalled();
|
|
144
|
-
});
|
|
145
|
-
it('should add an info log to the database if logs are enabled', async () => {
|
|
146
|
-
eventLog.logger.info(logArgs, publicApiKey);
|
|
147
|
-
eventLog.sendBatch();
|
|
148
|
-
await new Promise(process.nextTick);
|
|
149
|
-
expect(mockInterceptRequest).toHaveBeenCalledWith({
|
|
150
|
-
batch: [
|
|
151
|
-
{
|
|
152
|
-
...logArgs,
|
|
153
|
-
os: browserClientInfo.os,
|
|
154
|
-
metadata,
|
|
155
|
-
type: types_1.EventLogType.LOG,
|
|
156
|
-
level: types_1.Level.INFO,
|
|
157
|
-
},
|
|
158
|
-
],
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
it('should not add an info log to the database if logs are disabled', async () => {
|
|
162
|
-
eventLog = new index_1.EventLog({
|
|
163
|
-
organizationName: 'testOrg',
|
|
164
|
-
platform: 'web',
|
|
165
|
-
enableEvents: true,
|
|
166
|
-
enableLogs: false,
|
|
167
|
-
debug: false,
|
|
168
|
-
});
|
|
169
|
-
eventLog.sendBatch();
|
|
170
|
-
await new Promise(process.nextTick);
|
|
171
|
-
expect(mockInterceptRequest).not.toHaveBeenCalled();
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
describe('sendBatch', () => {
|
|
175
|
-
it('should not send a batch of items to the API if there are no items in the database', async () => {
|
|
176
|
-
await eventLog.sendBatch();
|
|
177
|
-
await new Promise(process.nextTick);
|
|
178
|
-
expect(mockInterceptRequest).not.toHaveBeenCalled();
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
describe('Cron', () => {
|
|
182
|
-
it('should send a batch of items to the API', async () => {
|
|
183
|
-
eventLog = new index_1.EventLog({
|
|
184
|
-
organizationName: 'testOrg',
|
|
185
|
-
platform: 'web',
|
|
186
|
-
batchTime: 1000,
|
|
187
|
-
enableEvents: true,
|
|
188
|
-
enableLogs: true,
|
|
189
|
-
debug: false,
|
|
190
|
-
});
|
|
191
|
-
await eventLog.event(eventArgs, publicApiKey);
|
|
192
|
-
await eventLog.logger.error(logArgs, publicApiKey);
|
|
193
|
-
await eventLog.logger.debug(logArgs, publicApiKey);
|
|
194
|
-
await eventLog.logger.info(logArgs, publicApiKey);
|
|
195
|
-
await new Promise((resolve) => setTimeout(resolve, 1200));
|
|
196
|
-
expect(mockInterceptRequest).toHaveBeenCalledWith({
|
|
197
|
-
batch: [
|
|
198
|
-
{
|
|
199
|
-
...eventArgs,
|
|
200
|
-
os: browserClientInfo.os,
|
|
201
|
-
type: types_1.EventLogType.EVENT,
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
...logArgs,
|
|
205
|
-
os: browserClientInfo.os,
|
|
206
|
-
metadata,
|
|
207
|
-
type: types_1.EventLogType.LOG,
|
|
208
|
-
level: types_1.Level.ERROR,
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
...logArgs,
|
|
212
|
-
os: browserClientInfo.os,
|
|
213
|
-
metadata,
|
|
214
|
-
type: types_1.EventLogType.LOG,
|
|
215
|
-
level: types_1.Level.DEBUG,
|
|
216
|
-
},
|
|
217
|
-
{
|
|
218
|
-
...logArgs,
|
|
219
|
-
os: browserClientInfo.os,
|
|
220
|
-
metadata,
|
|
221
|
-
type: types_1.EventLogType.LOG,
|
|
222
|
-
level: types_1.Level.INFO,
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
});
|
package/dist/esm/index.types.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Database } from './database';
|
|
2
|
-
import { BrowserClientInfo, Level, Log } from './types';
|
|
3
|
-
export declare function setLog(logArgs: Omit<Log, 'level' | 'type'>, level: Level, enableLog: boolean, database: Database, publicApiKey: string, browserInfo: BrowserClientInfo | null): Promise<void> | undefined;
|
|
4
|
-
declare let browserClientInfo: BrowserClientInfo | null;
|
|
5
|
-
export { browserClientInfo };
|
package/dist/esm/index.utils.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.browserClientInfo = exports.setLog = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
const utils_2 = require("./utils");
|
|
7
|
-
function setLog(logArgs, level, enableLog, database, publicApiKey, browserInfo) {
|
|
8
|
-
if (!enableLog) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
return database.setItem({
|
|
12
|
-
os: browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.os,
|
|
13
|
-
...logArgs,
|
|
14
|
-
metadata: {
|
|
15
|
-
...logArgs.metadata,
|
|
16
|
-
browser_info: browserInfo,
|
|
17
|
-
},
|
|
18
|
-
level,
|
|
19
|
-
type: types_1.EventLogType.LOG,
|
|
20
|
-
}, publicApiKey);
|
|
21
|
-
}
|
|
22
|
-
exports.setLog = setLog;
|
|
23
|
-
let browserClientInfo = null;
|
|
24
|
-
exports.browserClientInfo = browserClientInfo;
|
|
25
|
-
if ((0, utils_1.isBrowser)()) {
|
|
26
|
-
(0, utils_2.clientDetection)().then((clientInfo) => {
|
|
27
|
-
exports.browserClientInfo = browserClientInfo = clientInfo;
|
|
28
|
-
});
|
|
29
|
-
}
|
package/dist/esm/types/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Level = exports.EventLogType = void 0;
|
|
4
|
-
var EventLogType;
|
|
5
|
-
(function (EventLogType) {
|
|
6
|
-
EventLogType["LOG"] = "LOG";
|
|
7
|
-
EventLogType["EVENT"] = "EVENT";
|
|
8
|
-
})(EventLogType || (exports.EventLogType = EventLogType = {}));
|
|
9
|
-
var Level;
|
|
10
|
-
(function (Level) {
|
|
11
|
-
Level["ERROR"] = "ERROR";
|
|
12
|
-
Level["DEBUG"] = "DEBUG";
|
|
13
|
-
Level["INFO"] = "INFO";
|
|
14
|
-
})(Level || (exports.Level = Level = {}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const check_environment_1 = require("../check-environment");
|
|
4
|
-
describe('isLocalStorageEnabled', () => {
|
|
5
|
-
it('should return true if local storage is enabled', () => {
|
|
6
|
-
expect((0, check_environment_1.isLocalStorageEnabled)()).toBe(true);
|
|
7
|
-
});
|
|
8
|
-
it('should return false if local storage is disabled', () => {
|
|
9
|
-
const localStorageMock = {
|
|
10
|
-
getItem: jest.fn(() => null),
|
|
11
|
-
setItem: jest.fn(() => {
|
|
12
|
-
throw new Error('Local storage is disabled');
|
|
13
|
-
}),
|
|
14
|
-
removeItem: jest.fn(() => null),
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(window, 'localStorage', {
|
|
17
|
-
value: localStorageMock,
|
|
18
|
-
});
|
|
19
|
-
expect((0, check_environment_1.isLocalStorageEnabled)()).toBe(false);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
describe('isBrowser', () => {
|
|
23
|
-
it('should return true if running in a browser environment', () => {
|
|
24
|
-
expect((0, check_environment_1.isBrowser)()).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
it('should return false if running in a non-browser environment', () => {
|
|
27
|
-
const isBrowserMock = new Function('try {return this===window;}catch(e){ return false;}').bind({});
|
|
28
|
-
expect(isBrowserMock()).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/* eslint-disable no-magic-numbers */
|
|
4
|
-
const client_detection_1 = require("../client-detection");
|
|
5
|
-
describe('clientDetection', () => {
|
|
6
|
-
it('should return an object with screen, browser, browserVersion, browserMajorVersion, mobile, os, osVersion, and cookies properties', async () => {
|
|
7
|
-
const result = await (0, client_detection_1.clientDetection)();
|
|
8
|
-
expect(result).toHaveProperty('screen');
|
|
9
|
-
expect(result).toHaveProperty('browser');
|
|
10
|
-
expect(result).toHaveProperty('browserVersion');
|
|
11
|
-
expect(result).toHaveProperty('browserMajorVersion');
|
|
12
|
-
expect(result).toHaveProperty('mobile');
|
|
13
|
-
expect(result).toHaveProperty('os');
|
|
14
|
-
expect(result).toHaveProperty('osVersion');
|
|
15
|
-
expect(result).toHaveProperty('cookies');
|
|
16
|
-
});
|
|
17
|
-
it('should correctly detect the browser and browser version', async () => {
|
|
18
|
-
const result = await (0, client_detection_1.clientDetection)();
|
|
19
|
-
expect(result.browser).toBe('jsdom');
|
|
20
|
-
expect(result.browserVersion).toBe('20.0.3');
|
|
21
|
-
expect(result.browserMajorVersion).toBeGreaterThanOrEqual(20);
|
|
22
|
-
});
|
|
23
|
-
it('should correctly detect whether the client is mobile', async () => {
|
|
24
|
-
const result = await (0, client_detection_1.clientDetection)();
|
|
25
|
-
expect(result.mobile).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
it('should correctly detect whether cookies are enabled', async () => {
|
|
28
|
-
const result = await (0, client_detection_1.clientDetection)();
|
|
29
|
-
expect(result.cookies).toBe(true);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBrowser = exports.isLocalStorageEnabled = void 0;
|
|
4
|
-
function isLocalStorageEnabled() {
|
|
5
|
-
try {
|
|
6
|
-
const key = '__yuno_storage__test';
|
|
7
|
-
window.localStorage.setItem(key, 'test_value');
|
|
8
|
-
window.localStorage.removeItem(key);
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.isLocalStorageEnabled = isLocalStorageEnabled;
|
|
16
|
-
// https://stackoverflow.com/questions/17575790/environment-detection-node-js-or-browser
|
|
17
|
-
exports.isBrowser = new Function('try {return this===window;}catch(e){ return false;}');
|