@availity/analytics-core 4.0.5 → 4.1.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ # [4.1.0](https://github.com/Availity/sdk-js/compare/@availity/analytics-core@4.0.5...@availity/analytics-core@4.1.0) (2024-03-07)
6
+
7
+
8
+ ### Features
9
+
10
+ * **analytics-core:** add telemetry plugin ([5c5dfa1](https://github.com/Availity/sdk-js/commit/5c5dfa13e47813a6b5cfaa37caa70ebe744591bb))
11
+
12
+
13
+
5
14
  ## [4.0.5](https://github.com/Availity/sdk-js/compare/@availity/analytics-core@4.0.4...@availity/analytics-core@4.0.5) (2024-02-19)
6
15
 
7
16
 
package/dist/index.d.mts CHANGED
@@ -71,6 +71,18 @@ declare class AvSplunkAnalytics extends AvAnalyticsPlugin {
71
71
  /* eslint-disable @typescript-eslint/no-explicit-any */
72
72
 
73
73
 
74
+ declare class AvTelemetryAnalytics extends AvAnalyticsPlugin {
75
+ constructor(AvLogMessages: any, enabled?: boolean, source_system: string, contact: string, sessionId?: string);
76
+
77
+ trackEvent(properties: any): any;
78
+
79
+ trackPageView(url: string): any;
80
+ }
81
+
82
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
83
+ /* eslint-disable @typescript-eslint/no-explicit-any */
84
+
85
+
74
86
  declare class AvDmaAnalytics extends AvAnalyticsPlugin {
75
87
  constructor(AvLogMessages: any, enabled?: boolean);
76
88
 
@@ -79,4 +91,4 @@ declare class AvDmaAnalytics extends AvAnalyticsPlugin {
79
91
  trackPageView(url: string): any;
80
92
  }
81
93
 
82
- export { AvAnalytics, AvAnalyticsPlugin, AvDmaAnalytics, AvSplunkAnalytics };
94
+ export { AvAnalytics, AvAnalyticsPlugin, AvDmaAnalytics, AvSplunkAnalytics, AvTelemetryAnalytics };
package/dist/index.d.ts CHANGED
@@ -71,6 +71,18 @@ declare class AvSplunkAnalytics extends AvAnalyticsPlugin {
71
71
  /* eslint-disable @typescript-eslint/no-explicit-any */
72
72
 
73
73
 
74
+ declare class AvTelemetryAnalytics extends AvAnalyticsPlugin {
75
+ constructor(AvLogMessages: any, enabled?: boolean, source_system: string, contact: string, sessionId?: string);
76
+
77
+ trackEvent(properties: any): any;
78
+
79
+ trackPageView(url: string): any;
80
+ }
81
+
82
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
83
+ /* eslint-disable @typescript-eslint/no-explicit-any */
84
+
85
+
74
86
  declare class AvDmaAnalytics extends AvAnalyticsPlugin {
75
87
  constructor(AvLogMessages: any, enabled?: boolean);
76
88
 
@@ -79,4 +91,4 @@ declare class AvDmaAnalytics extends AvAnalyticsPlugin {
79
91
  trackPageView(url: string): any;
80
92
  }
81
93
 
82
- export { AvAnalytics, AvAnalyticsPlugin, AvDmaAnalytics, AvSplunkAnalytics };
94
+ export { AvAnalytics, AvAnalyticsPlugin, AvDmaAnalytics, AvSplunkAnalytics, AvTelemetryAnalytics };
package/dist/index.js CHANGED
@@ -19,6 +19,18 @@ var __spreadValues = (a, b) => {
19
19
  }
20
20
  return a;
21
21
  };
22
+ var __objRest = (source, exclude) => {
23
+ var target = {};
24
+ for (var prop in source)
25
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
26
+ target[prop] = source[prop];
27
+ if (source != null && __getOwnPropSymbols)
28
+ for (var prop of __getOwnPropSymbols(source)) {
29
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
30
+ target[prop] = source[prop];
31
+ }
32
+ return target;
33
+ };
22
34
  var __export = (target, all) => {
23
35
  for (var name in all)
24
36
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -51,7 +63,8 @@ __export(src_exports, {
51
63
  AvAnalytics: () => AvAnalytics,
52
64
  AvAnalyticsPlugin: () => AvAnalyticsPlugin,
53
65
  AvDmaAnalytics: () => AvDmaAnalytics,
54
- AvSplunkAnalytics: () => AvSplunkAnalytics
66
+ AvSplunkAnalytics: () => AvSplunkAnalytics,
67
+ AvTelemetryAnalytics: () => AvTelemetryAnalytics
55
68
  });
56
69
  module.exports = __toCommonJS(src_exports);
57
70
 
@@ -256,6 +269,49 @@ var AvSplunkAnalytics = class extends AvAnalyticsPlugin {
256
269
  }
257
270
  };
258
271
 
272
+ // src/telemetry.js
273
+ var import_uuid = require("uuid");
274
+ var AvTelemetryAnalytics = class extends AvAnalyticsPlugin {
275
+ constructor(AvLogMessages, enabled, source_system, contact, sessionId) {
276
+ super(enabled);
277
+ this.AvLogMessages = AvLogMessages;
278
+ if (!source_system)
279
+ throw new Error("source_system is required");
280
+ if (!contact)
281
+ throw new Error("contact is required");
282
+ this.source_system = source_system;
283
+ this.contact = contact;
284
+ this.sessionId = sessionId || (0, import_uuid.v4)();
285
+ }
286
+ trackEvent(_a) {
287
+ var _b = _a, { customerId, level, payerId } = _b, properties = __objRest(_b, ["customerId", "level", "payerId"]);
288
+ const payload = {
289
+ customerId,
290
+ contact: this.contact,
291
+ source_system: this.source_system,
292
+ version: "v1",
293
+ sessionId: this.sessionId,
294
+ telemetryBody: {
295
+ level: level || "info",
296
+ entries: __spreadValues({}, properties)
297
+ }
298
+ };
299
+ if (payerId)
300
+ payload.payerId = payerId;
301
+ return this.AvLogMessages[payload.telemetryBody.level](payload);
302
+ }
303
+ trackPageView(url) {
304
+ return this.trackEvent({
305
+ event: "page",
306
+ action: "load",
307
+ category: this.source_system,
308
+ label: "page-load",
309
+ url,
310
+ customerId: "0000"
311
+ });
312
+ }
313
+ };
314
+
259
315
  // src/dma.js
260
316
  var yup = __toESM(require("yup"));
261
317
  var schema = yup.object().shape({
@@ -297,5 +353,6 @@ var AvDmaAnalytics = class extends AvAnalyticsPlugin {
297
353
  AvAnalytics,
298
354
  AvAnalyticsPlugin,
299
355
  AvDmaAnalytics,
300
- AvSplunkAnalytics
356
+ AvSplunkAnalytics,
357
+ AvTelemetryAnalytics
301
358
  });
package/dist/index.mjs CHANGED
@@ -14,6 +14,18 @@ var __spreadValues = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
+ var __objRest = (source, exclude) => {
18
+ var target = {};
19
+ for (var prop in source)
20
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
21
+ target[prop] = source[prop];
22
+ if (source != null && __getOwnPropSymbols)
23
+ for (var prop of __getOwnPropSymbols(source)) {
24
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
25
+ target[prop] = source[prop];
26
+ }
27
+ return target;
28
+ };
17
29
  var __publicField = (obj, key, value) => {
18
30
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
19
31
  return value;
@@ -220,6 +232,49 @@ var AvSplunkAnalytics = class extends AvAnalyticsPlugin {
220
232
  }
221
233
  };
222
234
 
235
+ // src/telemetry.js
236
+ import { v4 as uuidv4 } from "uuid";
237
+ var AvTelemetryAnalytics = class extends AvAnalyticsPlugin {
238
+ constructor(AvLogMessages, enabled, source_system, contact, sessionId) {
239
+ super(enabled);
240
+ this.AvLogMessages = AvLogMessages;
241
+ if (!source_system)
242
+ throw new Error("source_system is required");
243
+ if (!contact)
244
+ throw new Error("contact is required");
245
+ this.source_system = source_system;
246
+ this.contact = contact;
247
+ this.sessionId = sessionId || uuidv4();
248
+ }
249
+ trackEvent(_a) {
250
+ var _b = _a, { customerId, level, payerId } = _b, properties = __objRest(_b, ["customerId", "level", "payerId"]);
251
+ const payload = {
252
+ customerId,
253
+ contact: this.contact,
254
+ source_system: this.source_system,
255
+ version: "v1",
256
+ sessionId: this.sessionId,
257
+ telemetryBody: {
258
+ level: level || "info",
259
+ entries: __spreadValues({}, properties)
260
+ }
261
+ };
262
+ if (payerId)
263
+ payload.payerId = payerId;
264
+ return this.AvLogMessages[payload.telemetryBody.level](payload);
265
+ }
266
+ trackPageView(url) {
267
+ return this.trackEvent({
268
+ event: "page",
269
+ action: "load",
270
+ category: this.source_system,
271
+ label: "page-load",
272
+ url,
273
+ customerId: "0000"
274
+ });
275
+ }
276
+ };
277
+
223
278
  // src/dma.js
224
279
  import * as yup from "yup";
225
280
  var schema = yup.object().shape({
@@ -260,5 +315,6 @@ export {
260
315
  AvAnalytics,
261
316
  AvAnalyticsPlugin,
262
317
  AvDmaAnalytics,
263
- AvSplunkAnalytics
318
+ AvSplunkAnalytics,
319
+ AvTelemetryAnalytics
264
320
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@availity/analytics-core",
3
- "version": "4.0.5",
3
+ "version": "4.1.0",
4
4
  "description": "Analytics base configuration for sdk-js",
5
5
  "keywords": [
6
6
  "availity",
@@ -28,10 +28,11 @@
28
28
  "publish": "yarn npm publish --tolerate-republish --access public"
29
29
  },
30
30
  "dependencies": {
31
+ "uuid": "^9.0.1",
31
32
  "yup": "^0.32.11"
32
33
  },
33
34
  "devDependencies": {
34
- "@availity/api-axios": "8.0.4",
35
+ "@availity/api-axios": "8.0.5",
35
36
  "tsup": "^7.2.0",
36
37
  "typescript": "^5.1.6"
37
38
  },
package/src/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as AvAnalytics } from './analytics';
2
2
  export { default as AvAnalyticsPlugin } from './plugin';
3
3
  export { default as AvSplunkAnalytics } from './splunk';
4
+ export { default as AvTelemetryAnalytics } from './telemetry';
4
5
  export { default as AvDmaAnalytics } from './dma';
package/src/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as AvAnalytics } from './analytics';
2
2
  export { default as AvAnalyticsPlugin } from './plugin';
3
3
  export { default as AvSplunkAnalytics } from './splunk';
4
+ export { default as AvTelemetryAnalytics } from './telemetry';
4
5
  export { default as AvDmaAnalytics } from './dma';
@@ -0,0 +1,13 @@
1
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ import AvAnalyticsPlugin from './plugin';
4
+
5
+ declare class AvTelemetryAnalytics extends AvAnalyticsPlugin {
6
+ constructor(AvLogMessages: any, enabled?: boolean, source_system: string, contact: string, sessionId?: string);
7
+
8
+ trackEvent(properties: any): any;
9
+
10
+ trackPageView(url: string): any;
11
+ }
12
+
13
+ export default AvTelemetryAnalytics;
@@ -0,0 +1,46 @@
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ import AvAnalyticsPlugin from './plugin';
3
+
4
+ export default class AvTelemetryAnalytics extends AvAnalyticsPlugin {
5
+ constructor(AvLogMessages, enabled, source_system, contact, sessionId) {
6
+ super(enabled);
7
+ this.AvLogMessages = AvLogMessages;
8
+
9
+ if (!source_system) throw new Error('source_system is required');
10
+ if (!contact) throw new Error('contact is required');
11
+ this.source_system = source_system;
12
+ this.contact = contact;
13
+ this.sessionId = sessionId || uuidv4();
14
+ }
15
+
16
+ trackEvent({ customerId, level, payerId, ...properties }) {
17
+ const payload = {
18
+ customerId,
19
+ contact: this.contact,
20
+ source_system: this.source_system,
21
+ version: 'v1',
22
+ sessionId: this.sessionId,
23
+ telemetryBody: {
24
+ level: level || 'info',
25
+ entries: {
26
+ ...properties,
27
+ },
28
+ },
29
+ };
30
+
31
+ if (payerId) payload.payerId = payerId;
32
+
33
+ return this.AvLogMessages[payload.telemetryBody.level](payload);
34
+ }
35
+
36
+ trackPageView(url) {
37
+ return this.trackEvent({
38
+ event: 'page',
39
+ action: 'load',
40
+ category: this.source_system,
41
+ label: 'page-load',
42
+ url,
43
+ customerId: '0000',
44
+ });
45
+ }
46
+ }
@@ -0,0 +1,98 @@
1
+ import { AvTelemetryAnalytics } from '..';
2
+
3
+ describe('AvTelemetryAnalytics', () => {
4
+ let mockLog: { info: () => void; test: () => void };
5
+ let mockAvTelemetryAnalytics: AvTelemetryAnalytics;
6
+
7
+ beforeEach(() => {
8
+ mockLog = {
9
+ info: jest.fn(),
10
+ test: jest.fn(),
11
+ };
12
+
13
+ mockAvTelemetryAnalytics = new AvTelemetryAnalytics(mockLog, false, 'testApp', 'AVOSS@availity.com', '1234');
14
+ });
15
+
16
+ test('AvTelemetryAnalytics should be defined', () => {
17
+ expect(mockAvTelemetryAnalytics).toBeDefined();
18
+ });
19
+
20
+ test('trackEvent should call AvLogMessages[level]', () => {
21
+ let level = 'info';
22
+ mockAvTelemetryAnalytics.trackEvent({ level });
23
+ expect(mockLog.info).toHaveBeenCalledTimes(1);
24
+ expect(mockLog.test).toHaveBeenCalledTimes(0);
25
+ level = 'test';
26
+ mockAvTelemetryAnalytics.trackEvent({ level });
27
+ expect(mockLog.info).toHaveBeenCalledTimes(1);
28
+ expect(mockLog.test).toHaveBeenCalledTimes(1);
29
+ });
30
+
31
+ test("trackEvent should default level to 'info'", () => {
32
+ mockAvTelemetryAnalytics.trackEvent({});
33
+ expect(mockLog.info).toHaveBeenCalledTimes(1);
34
+ expect(mockLog.test).toHaveBeenCalledTimes(0);
35
+ });
36
+
37
+ test("trackEvent should default properties.url to location.href or 'N/A'", () => {
38
+ let startingObject: { message: string; url: string; level?: string; customerId: string } = {
39
+ message: 'hello world',
40
+ url: window.location.href || 'N/A',
41
+ customerId: '0000',
42
+ };
43
+ let expectedCall = {
44
+ contact: 'AVOSS@availity.com',
45
+ customerId: '0000',
46
+ sessionId: '1234',
47
+ source_system: 'testApp',
48
+ telemetryBody: {
49
+ entries: {
50
+ message: startingObject.message,
51
+ url: window.location.href || 'N/A',
52
+ },
53
+ level: 'info',
54
+ },
55
+ version: 'v1',
56
+ };
57
+ mockAvTelemetryAnalytics.trackEvent(startingObject);
58
+ expect(mockLog.info).toHaveBeenCalledWith(expectedCall);
59
+
60
+ startingObject = {
61
+ message: 'hello world',
62
+ url: 'testUrl',
63
+ level: 'test',
64
+ customerId: '0000',
65
+ };
66
+
67
+ expectedCall = {
68
+ contact: 'AVOSS@availity.com',
69
+ customerId: '0000',
70
+ sessionId: '1234',
71
+ source_system: 'testApp',
72
+ telemetryBody: {
73
+ entries: {
74
+ message: 'hello world',
75
+ url: 'testUrl',
76
+ },
77
+ level: 'test',
78
+ },
79
+ version: 'v1',
80
+ };
81
+ mockAvTelemetryAnalytics.trackEvent(startingObject);
82
+ expect(mockLog.test).toHaveBeenCalledWith(expectedCall);
83
+ });
84
+
85
+ test("trackPageView should call trackEvent with event 'page' and passed in url", () => {
86
+ const testUrl = 'testUrl';
87
+ mockAvTelemetryAnalytics.trackEvent = jest.fn();
88
+ mockAvTelemetryAnalytics.trackPageView(testUrl);
89
+ expect(mockAvTelemetryAnalytics.trackEvent).toHaveBeenCalledWith({
90
+ action: 'load',
91
+ category: 'testApp',
92
+ customerId: '0000',
93
+ event: 'page',
94
+ label: 'page-load',
95
+ url: testUrl,
96
+ });
97
+ });
98
+ });