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