@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.
Files changed (107) hide show
  1. package/dist/cjs/api/api.d.ts +5 -3
  2. package/dist/cjs/api/api.types.d.ts +9 -0
  3. package/dist/cjs/cron/cron.d.ts +1 -0
  4. package/dist/cjs/database/database.types.d.ts +2 -2
  5. package/dist/cjs/database/local-storage/local-storage.d.ts +2 -2
  6. package/dist/cjs/database/memory-storage/memory-storage.d.ts +2 -4
  7. package/dist/cjs/event-log-main/event-log-main.d.ts +26 -0
  8. package/dist/cjs/event-log-main/event-logs-main.types.d.ts +24 -0
  9. package/dist/cjs/event-log-main/index.d.ts +2 -0
  10. package/dist/cjs/index.d.ts +7 -9
  11. package/dist/cjs/index.js +2 -74
  12. package/dist/cjs/index.js.map +1 -0
  13. package/dist/cjs/types/index.d.ts +5 -15
  14. package/dist/cjs/utils/client-detection.d.ts +2 -8
  15. package/dist/esm/api/api.d.ts +5 -3
  16. package/dist/esm/api/api.types.d.ts +9 -0
  17. package/dist/esm/cron/cron.d.ts +1 -0
  18. package/dist/esm/database/database.types.d.ts +2 -2
  19. package/dist/esm/database/local-storage/local-storage.d.ts +2 -2
  20. package/dist/esm/database/memory-storage/memory-storage.d.ts +2 -4
  21. package/dist/esm/event-log-main/event-log-main.d.ts +26 -0
  22. package/dist/esm/event-log-main/event-logs-main.types.d.ts +24 -0
  23. package/dist/esm/event-log-main/index.d.ts +2 -0
  24. package/dist/esm/index.d.ts +7 -9
  25. package/dist/esm/index.js +2 -67
  26. package/dist/esm/index.js.map +1 -0
  27. package/dist/esm/types/index.d.ts +5 -15
  28. package/dist/esm/utils/client-detection.d.ts +2 -8
  29. package/package.json +13 -6
  30. package/dist/cjs/api/__tests__/api.test.d.ts +0 -1
  31. package/dist/cjs/api/__tests__/api.test.js +0 -45
  32. package/dist/cjs/api/__tests__/api.utils.test.d.ts +0 -1
  33. package/dist/cjs/api/__tests__/api.utils.test.js +0 -35
  34. package/dist/cjs/api/api.js +0 -48
  35. package/dist/cjs/api/api.utils.js +0 -18
  36. package/dist/cjs/api/index.js +0 -17
  37. package/dist/cjs/cron/cron.js +0 -58
  38. package/dist/cjs/cron/cron.test.d.ts +0 -1
  39. package/dist/cjs/cron/cron.test.js +0 -56
  40. package/dist/cjs/cron/index.js +0 -17
  41. package/dist/cjs/database/database.js +0 -20
  42. package/dist/cjs/database/database.test.d.ts +0 -1
  43. package/dist/cjs/database/database.test.js +0 -25
  44. package/dist/cjs/database/database.types.js +0 -2
  45. package/dist/cjs/database/index.js +0 -18
  46. package/dist/cjs/database/local-storage/index.js +0 -17
  47. package/dist/cjs/database/local-storage/local-storage.js +0 -74
  48. package/dist/cjs/database/local-storage/local-storage.test.d.ts +0 -1
  49. package/dist/cjs/database/local-storage/local-storage.test.js +0 -40
  50. package/dist/cjs/database/memory-storage/index.js +0 -17
  51. package/dist/cjs/database/memory-storage/memory-storage.js +0 -56
  52. package/dist/cjs/database/memory-storage/memory-storage.test.d.ts +0 -1
  53. package/dist/cjs/database/memory-storage/memory-storage.test.js +0 -34
  54. package/dist/cjs/index.test.d.ts +0 -1
  55. package/dist/cjs/index.test.js +0 -197
  56. package/dist/cjs/index.types.d.ts +0 -8
  57. package/dist/cjs/index.types.js +0 -2
  58. package/dist/cjs/index.utils.d.ts +0 -5
  59. package/dist/cjs/index.utils.js +0 -20
  60. package/dist/cjs/types/index.js +0 -14
  61. package/dist/cjs/utils/__tests__/check-environment.test.d.ts +0 -1
  62. package/dist/cjs/utils/__tests__/check-environment.test.js +0 -30
  63. package/dist/cjs/utils/__tests__/client-detection.test.d.ts +0 -1
  64. package/dist/cjs/utils/__tests__/client-detection.test.js +0 -40
  65. package/dist/cjs/utils/check-environment.js +0 -17
  66. package/dist/cjs/utils/client-detection.js +0 -216
  67. package/dist/cjs/utils/index.js +0 -19
  68. package/dist/cjs/utils/stringyfy.js +0 -20
  69. package/dist/esm/api/__tests__/api.test.d.ts +0 -1
  70. package/dist/esm/api/__tests__/api.test.js +0 -36
  71. package/dist/esm/api/__tests__/api.utils.test.d.ts +0 -1
  72. package/dist/esm/api/__tests__/api.utils.test.js +0 -35
  73. package/dist/esm/api/api.js +0 -48
  74. package/dist/esm/api/api.utils.js +0 -18
  75. package/dist/esm/api/index.js +0 -17
  76. package/dist/esm/cron/cron.js +0 -47
  77. package/dist/esm/cron/cron.test.d.ts +0 -1
  78. package/dist/esm/cron/cron.test.js +0 -47
  79. package/dist/esm/cron/index.js +0 -17
  80. package/dist/esm/database/database.js +0 -20
  81. package/dist/esm/database/database.test.d.ts +0 -1
  82. package/dist/esm/database/database.test.js +0 -25
  83. package/dist/esm/database/database.types.js +0 -2
  84. package/dist/esm/database/index.js +0 -18
  85. package/dist/esm/database/local-storage/index.js +0 -17
  86. package/dist/esm/database/local-storage/local-storage.js +0 -61
  87. package/dist/esm/database/local-storage/local-storage.test.d.ts +0 -1
  88. package/dist/esm/database/local-storage/local-storage.test.js +0 -31
  89. package/dist/esm/database/memory-storage/index.js +0 -17
  90. package/dist/esm/database/memory-storage/memory-storage.js +0 -43
  91. package/dist/esm/database/memory-storage/memory-storage.test.d.ts +0 -1
  92. package/dist/esm/database/memory-storage/memory-storage.test.js +0 -25
  93. package/dist/esm/index.test.d.ts +0 -1
  94. package/dist/esm/index.test.js +0 -228
  95. package/dist/esm/index.types.d.ts +0 -8
  96. package/dist/esm/index.types.js +0 -2
  97. package/dist/esm/index.utils.d.ts +0 -5
  98. package/dist/esm/index.utils.js +0 -29
  99. package/dist/esm/types/index.js +0 -14
  100. package/dist/esm/utils/__tests__/check-environment.test.d.ts +0 -1
  101. package/dist/esm/utils/__tests__/check-environment.test.js +0 -30
  102. package/dist/esm/utils/__tests__/client-detection.test.d.ts +0 -1
  103. package/dist/esm/utils/__tests__/client-detection.test.js +0 -31
  104. package/dist/esm/utils/check-environment.js +0 -17
  105. package/dist/esm/utils/client-detection.js +0 -205
  106. package/dist/esm/utils/index.js +0 -19
  107. package/dist/esm/utils/stringyfy.js +0 -20
@@ -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;}');
@@ -1,216 +0,0 @@
1
- "use strict";
2
- /* eslint-disable no-magic-numbers */
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.clientDetection = void 0;
14
- /**
15
- * JavaScript Client Detection
16
- * (C) viazenetti GmbH (Christian Ludwig)
17
- * https://stackoverflow.com/questions/9514179/how-to-find-the-operating-system-details-using-javascript
18
- * this package is better but too weighty: https://www.npmjs.com/package/ua-parser-js
19
- */
20
- function clientDetection() {
21
- var _a, _b, _c;
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const unknown = '-';
24
- // screen
25
- let screenSize = '';
26
- if (screen.width) {
27
- const width = screen.width ? screen.width : '';
28
- const height = screen.height ? screen.height : '';
29
- screenSize += '' + width + ' x ' + height;
30
- }
31
- // browser
32
- const nVer = navigator.appVersion;
33
- const nAgt = navigator.userAgent;
34
- let browser = navigator.appName;
35
- let version = '' + parseFloat(nVer);
36
- let nameOffset, verOffset, ix;
37
- // Yandex Browser
38
- if ((verOffset = nAgt.indexOf('YaBrowser')) !== -1) {
39
- browser = 'Yandex';
40
- version = nAgt.substring(verOffset + 10);
41
- }
42
- // Samsung Browser
43
- else if ((verOffset = nAgt.indexOf('SamsungBrowser')) !== -1) {
44
- browser = 'Samsung';
45
- version = nAgt.substring(verOffset + 15);
46
- }
47
- // UC Browser
48
- else if ((verOffset = nAgt.indexOf('UCBrowser')) !== -1) {
49
- browser = 'UC Browser';
50
- version = nAgt.substring(verOffset + 10);
51
- }
52
- // Opera Next
53
- else if ((verOffset = nAgt.indexOf('OPR')) !== -1) {
54
- browser = 'Opera';
55
- version = nAgt.substring(verOffset + 4);
56
- }
57
- // Opera
58
- else if ((verOffset = nAgt.indexOf('Opera')) !== -1) {
59
- browser = 'Opera';
60
- version = nAgt.substring(verOffset + 6);
61
- if ((verOffset = nAgt.indexOf('Version')) !== -1) {
62
- version = nAgt.substring(verOffset + 8);
63
- }
64
- }
65
- // Legacy Edge
66
- else if ((verOffset = nAgt.indexOf('Edge')) !== -1) {
67
- browser = 'Microsoft Legacy Edge';
68
- version = nAgt.substring(verOffset + 5);
69
- }
70
- // Edge (Chromium)
71
- else if ((verOffset = nAgt.indexOf('Edg')) !== -1) {
72
- browser = 'Microsoft Edge';
73
- version = nAgt.substring(verOffset + 4);
74
- }
75
- // MSIE
76
- else if ((verOffset = nAgt.indexOf('MSIE')) !== -1) {
77
- browser = 'Microsoft Internet Explorer';
78
- version = nAgt.substring(verOffset + 5);
79
- }
80
- // Chrome
81
- else if ((verOffset = nAgt.indexOf('Chrome')) !== -1) {
82
- browser = 'Chrome';
83
- version = nAgt.substring(verOffset + 7);
84
- }
85
- // Safari
86
- else if ((verOffset = nAgt.indexOf('Safari')) !== -1) {
87
- browser = 'Safari';
88
- version = nAgt.substring(verOffset + 7);
89
- if ((verOffset = nAgt.indexOf('Version')) !== -1) {
90
- version = nAgt.substring(verOffset + 8);
91
- }
92
- }
93
- // Firefox
94
- else if ((verOffset = nAgt.indexOf('Firefox')) !== -1) {
95
- browser = 'Firefox';
96
- version = nAgt.substring(verOffset + 8);
97
- }
98
- // MSIE 11+
99
- else if (nAgt.indexOf('Trident/') !== -1) {
100
- browser = 'Microsoft Internet Explorer';
101
- version = nAgt.substring(nAgt.indexOf('rv:') + 3);
102
- }
103
- // Other browsers
104
- else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) <
105
- (verOffset = nAgt.lastIndexOf('/'))) {
106
- browser = nAgt.substring(nameOffset, verOffset);
107
- version = nAgt.substring(verOffset + 1);
108
- if (browser.toLowerCase() === browser.toUpperCase()) {
109
- browser = navigator.appName;
110
- }
111
- }
112
- // trim the version string
113
- if ((ix = version.indexOf(';')) !== -1)
114
- version = version.substring(0, ix);
115
- if ((ix = version.indexOf(' ')) !== -1)
116
- version = version.substring(0, ix);
117
- if ((ix = version.indexOf(')')) !== -1)
118
- version = version.substring(0, ix);
119
- let majorVersion = parseInt('' + version, 10);
120
- if (isNaN(majorVersion)) {
121
- version = '' + parseFloat(nVer);
122
- majorVersion = parseInt(nVer, 10);
123
- }
124
- // mobile version
125
- const mobile = /Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test(nVer);
126
- // cookie
127
- let cookieEnabled = navigator.cookieEnabled ? true : false;
128
- if (typeof navigator.cookieEnabled === 'undefined' && !cookieEnabled) {
129
- document.cookie = 'testcookie';
130
- cookieEnabled = document.cookie.indexOf('testcookie') !== -1 ? true : false;
131
- }
132
- // system
133
- let os = unknown;
134
- const clientStrings = [
135
- { s: 'Windows 10', r: /(Windows 10.0|Windows NT 10.0)/ },
136
- { s: 'Windows 8.1', r: /(Windows 8.1|Windows NT 6.3)/ },
137
- { s: 'Windows 8', r: /(Windows 8|Windows NT 6.2)/ },
138
- { s: 'Windows 7', r: /(Windows 7|Windows NT 6.1)/ },
139
- { s: 'Windows Vista', r: /Windows NT 6.0/ },
140
- { s: 'Windows Server 2003', r: /Windows NT 5.2/ },
141
- { s: 'Windows XP', r: /(Windows NT 5.1|Windows XP)/ },
142
- { s: 'Windows 2000', r: /(Windows NT 5.0|Windows 2000)/ },
143
- { s: 'Windows ME', r: /(Win 9x 4.90|Windows ME)/ },
144
- { s: 'Windows 98', r: /(Windows 98|Win98)/ },
145
- { s: 'Windows 95', r: /(Windows 95|Win95|Windows_95)/ },
146
- { s: 'Windows NT 4.0', r: /(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/ },
147
- { s: 'Windows CE', r: /Windows CE/ },
148
- { s: 'Windows 3.11', r: /Win16/ },
149
- { s: 'Android', r: /Android/ },
150
- { s: 'Open BSD', r: /OpenBSD/ },
151
- { s: 'Sun OS', r: /SunOS/ },
152
- { s: 'Chrome OS', r: /CrOS/ },
153
- { s: 'Linux', r: /(Linux|X11(?!.*CrOS))/ },
154
- { s: 'iOS', r: /(iPhone|iPad|iPod)/ },
155
- { s: 'Mac OS X', r: /Mac OS X/ },
156
- { s: 'Mac OS', r: /(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ },
157
- { s: 'QNX', r: /QNX/ },
158
- { s: 'UNIX', r: /UNIX/ },
159
- { s: 'BeOS', r: /BeOS/ },
160
- { s: 'OS/2', r: /OS\/2/ },
161
- {
162
- s: 'Search Bot',
163
- r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/,
164
- },
165
- ];
166
- for (const id in clientStrings) {
167
- const cs = clientStrings[id];
168
- if (cs.r.test(nAgt)) {
169
- os = cs.s;
170
- break;
171
- }
172
- }
173
- let osVersion = unknown;
174
- if (/Windows/.test(os)) {
175
- osVersion = (_a = /Windows (.*)/.exec(os)) === null || _a === void 0 ? void 0 : _a[1];
176
- if (osVersion && parseInt(osVersion) === 10 && navigator.userAgentData) {
177
- osVersion = yield navigator.userAgentData
178
- .getHighEntropyValues(['platformVersion'])
179
- .then((ua) => { var _a, _b; return parseInt((_b = (_a = ua.platformVersion) === null || _a === void 0 ? void 0 : _a.split('.')[0]) !== null && _b !== void 0 ? _b : '0') < 13 ? 10 : 11; });
180
- }
181
- os = 'Windows';
182
- }
183
- switch (os) {
184
- case 'Mac OS':
185
- case 'Mac OS X':
186
- case 'Android':
187
- osVersion =
188
- (_c = (_b = /(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(nAgt)) === null || _b === void 0 ? void 0 : _b[1]) !== null && _c !== void 0 ? _c : osVersion;
189
- break;
190
- case 'iOS':
191
- {
192
- const osVersionRegexp = /OS (\d+)_(\d+)_?(\d+)?/.exec(nVer);
193
- if (osVersionRegexp) {
194
- osVersion =
195
- osVersionRegexp[1] +
196
- '.' +
197
- osVersionRegexp[2] +
198
- '.' +
199
- osVersionRegexp[3];
200
- }
201
- }
202
- break;
203
- }
204
- return {
205
- screen: screenSize,
206
- browser,
207
- browserVersion: version,
208
- browserMajorVersion: majorVersion,
209
- mobile,
210
- os,
211
- osVersion: osVersion,
212
- cookies: cookieEnabled,
213
- };
214
- });
215
- }
216
- exports.clientDetection = clientDetection;
@@ -1,19 +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("./check-environment"), exports);
18
- __exportStar(require("./client-detection"), exports);
19
- __exportStar(require("./stringyfy"), exports);
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringify = void 0;
4
- const DO_NOT_EXIST = -1;
5
- function stringify(obj) {
6
- const cache = [];
7
- const str = JSON.stringify(obj, function (key, value) {
8
- if (typeof value === 'object' && value !== null) {
9
- if (cache.indexOf(value) !== DO_NOT_EXIST) {
10
- // Circular reference found, discard key
11
- return;
12
- }
13
- // Store value in our collection
14
- cache.push(value);
15
- }
16
- return value;
17
- });
18
- return str;
19
- }
20
- exports.stringify = stringify;
@@ -1 +0,0 @@
1
- export {};
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const types_1 = require("../../types");
4
- const api_1 = require("../api");
5
- const PUBLIC_API_KEY = 'staging_gAAAAABj-NC2WEf3XA4lHnN6RfGbjETf6qL27jlU7c1tm01ERV-Y-E6ddee1QPyV_CA8cxjVlGy-qDNA2-mqa9msQlTJit-Fmbvv6f2AZdfbFd_CUo1stvixnF4_8MzM_IYVWYz7KK86VfEBvxNpjRCyp7BDef-QzrT1-yqa8HAYTuA1GU3Hjjo=';
6
- const publicApiKey = PUBLIC_API_KEY;
7
- const platform = 'web';
8
- const STATUS_CREATED = 201;
9
- describe('Api', () => {
10
- let api;
11
- beforeEach(() => {
12
- // Reset the instance before each test
13
- api = new api_1.Api(platform, true);
14
- });
15
- it('should initialize the instance with the correct headers', () => {
16
- const instance = api.getInstances();
17
- expect(instance === null || instance === void 0 ? void 0 : instance.defaults.headers['X-Platform']).toBe(platform);
18
- });
19
- it('should send a batch of events to the server', async () => {
20
- const batches = [
21
- {
22
- source: 'test',
23
- event: 'testEvent',
24
- description: 'Test event',
25
- original_created_at: new Date().toISOString(),
26
- type: types_1.EventLogType.EVENT,
27
- },
28
- ];
29
- const response = await api.sendBatch(batches, publicApiKey);
30
- expect(response === null || response === void 0 ? void 0 : response.status).toBe(STATUS_CREATED);
31
- });
32
- it('should return the instance', () => {
33
- const instance = api.getInstances();
34
- expect(instance).not.toBeNull();
35
- });
36
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const api_utils_1 = require("../api.utils");
4
- describe('getBaseUrl', () => {
5
- it('should return the correct base URL for a dev environment', () => {
6
- const publicApiKey = 'dev_1234567890';
7
- const expectedUrl = 'https://api-dev.y.uno/v1';
8
- const result = (0, api_utils_1.getBaseUrl)(publicApiKey);
9
- expect(result).toBe(expectedUrl);
10
- });
11
- it('should return the correct base URL for a staging environment', () => {
12
- const publicApiKey = 'staging_1234567890';
13
- const expectedUrl = 'https://api-staging.y.uno/v1';
14
- const result = (0, api_utils_1.getBaseUrl)(publicApiKey);
15
- expect(result).toBe(expectedUrl);
16
- });
17
- it('should return the correct base URL for a sandbox environment', () => {
18
- const publicApiKey = 'sandbox_1234567890';
19
- const expectedUrl = 'https://api-sandbox.y.uno/v1';
20
- const result = (0, api_utils_1.getBaseUrl)(publicApiKey);
21
- expect(result).toBe(expectedUrl);
22
- });
23
- it('should return the correct base URL for a prod environment', () => {
24
- const publicApiKey = 'prod_1234567890';
25
- const expectedUrl = 'https://api.y.uno/v1';
26
- const result = (0, api_utils_1.getBaseUrl)(publicApiKey);
27
- expect(result).toBe(expectedUrl);
28
- });
29
- it('should throw an error for an invalid public API key', () => {
30
- const publicApiKey = 'invalidApiKey';
31
- expect(() => {
32
- (0, api_utils_1.getBaseUrl)(publicApiKey);
33
- }).toThrowError('Not environment found publicApiKey: invalidApiKey, apiKeyPrefix: invalidApiKey, environmentSuffix: undefined');
34
- });
35
- });
@@ -1,48 +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 __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- var _Api_instance, _Api_debug;
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.Api = void 0;
19
- const axios_1 = __importDefault(require("axios"));
20
- const api_utils_1 = require("./api.utils");
21
- class Api {
22
- constructor(platform, debug = false) {
23
- _Api_instance.set(this, null);
24
- _Api_debug.set(this, false);
25
- __classPrivateFieldSet(this, _Api_debug, debug, "f");
26
- __classPrivateFieldSet(this, _Api_instance, axios_1.default.create({
27
- // eslint-disable-next-line @typescript-eslint/naming-convention
28
- headers: { 'X-Platform': platform },
29
- }), "f");
30
- }
31
- sendBatch(batches, publicApiKey) {
32
- var _a;
33
- if (__classPrivateFieldGet(this, _Api_debug, "f")) {
34
- console.dir(batches, { depth: null });
35
- console.log(publicApiKey);
36
- }
37
- return (_a = __classPrivateFieldGet(this, _Api_instance, "f")) === null || _a === void 0 ? void 0 : _a.post('/sdk/event-log/publish', { batch: batches }, {
38
- baseURL: (0, api_utils_1.getBaseUrl)(publicApiKey),
39
- // eslint-disable-next-line @typescript-eslint/naming-convention
40
- headers: { 'public-api-key': publicApiKey }
41
- });
42
- }
43
- getInstances() {
44
- return __classPrivateFieldGet(this, _Api_instance, "f");
45
- }
46
- }
47
- exports.Api = Api;
48
- _Api_instance = new WeakMap(), _Api_debug = new WeakMap();
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBaseUrl = void 0;
4
- const ApiKeyPrefixToEnvironmentSuffix = {
5
- dev: '-dev',
6
- staging: '-staging',
7
- sandbox: '-sandbox',
8
- prod: '',
9
- };
10
- const getBaseUrl = (publicApiKey) => {
11
- const [apiKeyPrefix] = publicApiKey.split('_');
12
- const environmentSuffix = ApiKeyPrefixToEnvironmentSuffix[apiKeyPrefix];
13
- if (environmentSuffix === undefined) {
14
- throw new Error(`Not environment found publicApiKey: ${publicApiKey}, apiKeyPrefix: ${apiKeyPrefix}, environmentSuffix: ${environmentSuffix}`);
15
- }
16
- return 'https://api_ENVIRONMENT_.y.uno/v1'.replace('_ENVIRONMENT_', environmentSuffix);
17
- };
18
- exports.getBaseUrl = getBaseUrl;
@@ -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("./api"), exports);
@@ -1,47 +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 _Cron_interval, _Cron_api, _Cron_database;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Cron = void 0;
16
- const NONE_ITEMS = 0;
17
- class Cron {
18
- constructor(batchTime, api, database) {
19
- _Cron_interval.set(this, void 0);
20
- _Cron_api.set(this, void 0);
21
- _Cron_database.set(this, void 0);
22
- this.stop();
23
- __classPrivateFieldSet(this, _Cron_api, api, "f");
24
- __classPrivateFieldSet(this, _Cron_database, database, "f");
25
- __classPrivateFieldSet(this, _Cron_interval, setInterval(this.sendBatch.bind(this), batchTime), "f");
26
- }
27
- async sendBatch() {
28
- const items = await __classPrivateFieldGet(this, _Cron_database, "f").getAllItems();
29
- const keys = Object.keys(items);
30
- if (keys.length > NONE_ITEMS) {
31
- for (const key of keys) {
32
- __classPrivateFieldGet(this, _Cron_api, "f").sendBatch(items[key], key);
33
- }
34
- }
35
- }
36
- stop() {
37
- if (__classPrivateFieldGet(this, _Cron_interval, "f")) {
38
- clearInterval(__classPrivateFieldGet(this, _Cron_interval, "f"));
39
- __classPrivateFieldSet(this, _Cron_interval, undefined, "f");
40
- }
41
- }
42
- getInterval() {
43
- return __classPrivateFieldGet(this, _Cron_interval, "f");
44
- }
45
- }
46
- exports.Cron = Cron;
47
- _Cron_interval = new WeakMap(), _Cron_api = new WeakMap(), _Cron_database = new WeakMap();
@@ -1 +0,0 @@
1
- export {};
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const cron_1 = require("./cron");
4
- const api_1 = require("../api");
5
- const database_1 = require("../database");
6
- const types_1 = require("../types");
7
- const TIME_INTERVAL = 1000;
8
- describe('Cron', () => {
9
- let spy;
10
- let cron;
11
- let api;
12
- let database;
13
- beforeEach(async () => {
14
- // restore the spy created with spyOn
15
- jest.restoreAllMocks();
16
- api = new api_1.Api('web', true);
17
- database = (0, database_1.databaseFactory)('testOrganization');
18
- cron = new cron_1.Cron(TIME_INTERVAL, api, database);
19
- spy = jest.spyOn(api, 'sendBatch');
20
- await database.reset();
21
- });
22
- it('should send a batch of items to the API if there are items in the database', async () => {
23
- const batch = {
24
- source: 'test',
25
- event: 'testEvent',
26
- description: 'Test event',
27
- original_created_at: new Date().toISOString(),
28
- type: types_1.EventLogType.EVENT,
29
- };
30
- database.setItem(batch, 'sandbox_1');
31
- await cron.sendBatch();
32
- expect(spy).toHaveBeenCalledWith([batch], 'sandbox_1');
33
- });
34
- it('should not send a batch of items to the API if there are no items in the database', async () => {
35
- await cron.sendBatch();
36
- expect(spy).not.toHaveBeenCalled();
37
- });
38
- it('should stop the interval when stop is called', () => {
39
- jest.useFakeTimers();
40
- cron.stop();
41
- expect(cron.getInterval()).toBeUndefined();
42
- });
43
- it('should start the interval when init is called', () => {
44
- jest.useFakeTimers();
45
- expect(cron.getInterval()).toBeDefined();
46
- });
47
- });
@@ -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("./cron"), exports);
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.databaseFactory = void 0;
4
- const local_storage_1 = require("./local-storage");
5
- const memory_storage_1 = require("./memory-storage");
6
- const utils_1 = require("../utils");
7
- function databaseFactory(organizationName) {
8
- const databaseType = (0, utils_1.isLocalStorageEnabled)()
9
- ? 'local-storage'
10
- : 'memory-storage';
11
- switch (databaseType) {
12
- case 'local-storage':
13
- return new local_storage_1.LocalStorage(organizationName);
14
- case 'memory-storage':
15
- return new memory_storage_1.MemoryStorage();
16
- default:
17
- throw new Error(`Database type ${databaseType} not supported`);
18
- }
19
- }
20
- exports.databaseFactory = databaseFactory;
@@ -1 +0,0 @@
1
- export {};
@@ -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,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -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);