@diia-inhouse/analytics 1.72.29 → 2.3.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.
Files changed (65) hide show
  1. package/dist/index.d.ts +12 -0
  2. package/dist/index.js +9 -21
  3. package/dist/interfaces/actionResult.d.ts +26 -0
  4. package/dist/interfaces/actionResult.js +27 -28
  5. package/dist/interfaces/actionType.d.ts +24 -0
  6. package/dist/interfaces/actionType.js +25 -26
  7. package/dist/interfaces/analytics.d.ts +40 -0
  8. package/dist/interfaces/categories.d.ts +11 -0
  9. package/dist/interfaces/categories.js +12 -13
  10. package/dist/interfaces/data.d.ts +28 -0
  11. package/dist/interfaces/device.d.ts +12 -0
  12. package/dist/interfaces/index.d.ts +8 -0
  13. package/dist/interfaces/nextGenAnalytics.d.ts +18 -0
  14. package/dist/interfaces/rating.d.ts +457 -0
  15. package/dist/interfaces/rating.js +348 -355
  16. package/dist/mocks/analytics.d.ts +6 -0
  17. package/dist/mocks/analytics.js +75 -79
  18. package/dist/mocks/index.d.ts +1 -0
  19. package/dist/services/analytics.d.ts +25 -0
  20. package/dist/services/analytics.js +134 -146
  21. package/dist/services/index.d.ts +1 -0
  22. package/dist/services/index.js +2 -18
  23. package/dist/utils/index.d.ts +1 -0
  24. package/dist/utils/rating.d.ts +13 -0
  25. package/dist/utils/rating.js +179 -157
  26. package/package.json +35 -44
  27. package/dist/index.js.map +0 -1
  28. package/dist/interfaces/actionResult.js.map +0 -1
  29. package/dist/interfaces/actionType.js.map +0 -1
  30. package/dist/interfaces/analytics.js +0 -3
  31. package/dist/interfaces/analytics.js.map +0 -1
  32. package/dist/interfaces/categories.js.map +0 -1
  33. package/dist/interfaces/data.js +0 -3
  34. package/dist/interfaces/data.js.map +0 -1
  35. package/dist/interfaces/device.js +0 -3
  36. package/dist/interfaces/device.js.map +0 -1
  37. package/dist/interfaces/index.js +0 -25
  38. package/dist/interfaces/index.js.map +0 -1
  39. package/dist/interfaces/nextGenAnalytics.js +0 -3
  40. package/dist/interfaces/nextGenAnalytics.js.map +0 -1
  41. package/dist/interfaces/rating.js.map +0 -1
  42. package/dist/mocks/analytics.js.map +0 -1
  43. package/dist/mocks/index.js +0 -18
  44. package/dist/mocks/index.js.map +0 -1
  45. package/dist/services/analytics.js.map +0 -1
  46. package/dist/services/index.js.map +0 -1
  47. package/dist/types/index.d.ts +0 -4
  48. package/dist/types/interfaces/actionResult.d.ts +0 -23
  49. package/dist/types/interfaces/actionType.d.ts +0 -21
  50. package/dist/types/interfaces/analytics.d.ts +0 -37
  51. package/dist/types/interfaces/categories.d.ts +0 -8
  52. package/dist/types/interfaces/data.d.ts +0 -25
  53. package/dist/types/interfaces/device.d.ts +0 -8
  54. package/dist/types/interfaces/index.d.ts +0 -8
  55. package/dist/types/interfaces/nextGenAnalytics.d.ts +0 -14
  56. package/dist/types/interfaces/rating.d.ts +0 -441
  57. package/dist/types/mocks/analytics.d.ts +0 -2
  58. package/dist/types/mocks/index.d.ts +0 -1
  59. package/dist/types/services/analytics.d.ts +0 -18
  60. package/dist/types/services/index.d.ts +0 -1
  61. package/dist/types/utils/index.d.ts +0 -1
  62. package/dist/types/utils/rating.d.ts +0 -9
  63. package/dist/utils/index.js +0 -18
  64. package/dist/utils/index.js.map +0 -1
  65. package/dist/utils/rating.js.map +0 -1
@@ -0,0 +1,6 @@
1
+ import { RatingForm } from "@diia-inhouse/types";
2
+
3
+ //#region src/mocks/analytics.d.ts
4
+ declare function getRatingFormMock(ratingForm?: Partial<RatingForm>): RatingForm;
5
+ //#endregion
6
+ export { getRatingFormMock };
@@ -1,81 +1,77 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRatingFormMock = getRatingFormMock;
4
- const interfaces_1 = require("../interfaces");
1
+ import "../interfaces/rating.js";
2
+ //#region src/mocks/analytics.ts
5
3
  function getRatingFormMock(ratingForm = {}) {
6
- const chips = [
7
- {
8
- code: 'addressError',
9
- name: 'name',
10
- },
11
- {
12
- code: 'mobility',
13
- name: 'name',
14
- },
15
- ];
16
- return {
17
- title: 'Поділіться враженнями',
18
- rating: {
19
- label: 'Задоволені замовленням та отриманням послуги в Дії?',
20
- items: [
21
- {
22
- rate: interfaces_1.RatingScore.Awful,
23
- emoji: '😡',
24
- chip: {
25
- label: 'Що засмутило?',
26
- description: 'Оберіть один або кілька варіантів.',
27
- chips,
28
- },
29
- chipBlocks: [],
30
- },
31
- {
32
- rate: interfaces_1.RatingScore.Bad,
33
- emoji: '😢',
34
- chip: {
35
- label: 'Що засмутило?',
36
- description: 'Оберіть один або кілька варіантів.',
37
- chips,
38
- },
39
- chipBlocks: [],
40
- },
41
- {
42
- rate: interfaces_1.RatingScore.Ok,
43
- emoji: '😐',
44
- chip: {
45
- label: 'На що команді звернути увагу?',
46
- description: 'Оберіть один або кілька варіантів.',
47
- chips,
48
- },
49
- chipBlocks: [],
50
- },
51
- {
52
- rate: interfaces_1.RatingScore.Good,
53
- emoji: '😁',
54
- chip: {
55
- label: 'Що сподобалось?',
56
- description: 'Оберіть один або кілька варіантів.',
57
- chips,
58
- },
59
- chipBlocks: [],
60
- },
61
- {
62
- rate: interfaces_1.RatingScore.Excellent,
63
- emoji: '😍',
64
- chip: {
65
- label: 'Що сподобалось?',
66
- description: 'Оберіть один або кілька варіантів.',
67
- chips,
68
- },
69
- chipBlocks: [],
70
- },
71
- ],
72
- },
73
- comment: {
74
- label: 'Як можна покращити послугу?',
75
- hint: 'Розкажіть більше про враження (необовʼязково)',
76
- },
77
- mainButton: 'Надіслати відгук',
78
- ...ratingForm,
79
- };
4
+ const chips = [{
5
+ code: "addressError",
6
+ name: "name"
7
+ }, {
8
+ code: "mobility",
9
+ name: "name"
10
+ }];
11
+ return {
12
+ title: "Поділіться враженнями",
13
+ rating: {
14
+ label: "Задоволені замовленням та отриманням послуги в Дії?",
15
+ items: [
16
+ {
17
+ rate: "1",
18
+ emoji: "😡",
19
+ chip: {
20
+ label: "Що засмутило?",
21
+ description: "Оберіть один або кілька варіантів.",
22
+ chips
23
+ },
24
+ chipBlocks: []
25
+ },
26
+ {
27
+ rate: "2",
28
+ emoji: "😢",
29
+ chip: {
30
+ label: "Що засмутило?",
31
+ description: "Оберіть один або кілька варіантів.",
32
+ chips
33
+ },
34
+ chipBlocks: []
35
+ },
36
+ {
37
+ rate: "3",
38
+ emoji: "😐",
39
+ chip: {
40
+ label: "На що команді звернути увагу?",
41
+ description: "Оберіть один або кілька варіантів.",
42
+ chips
43
+ },
44
+ chipBlocks: []
45
+ },
46
+ {
47
+ rate: "4",
48
+ emoji: "😁",
49
+ chip: {
50
+ label: "Що сподобалось?",
51
+ description: "Оберіть один або кілька варіантів.",
52
+ chips
53
+ },
54
+ chipBlocks: []
55
+ },
56
+ {
57
+ rate: "5",
58
+ emoji: "😍",
59
+ chip: {
60
+ label: "Що сподобалось?",
61
+ description: "Оберіть один або кілька варіантів.",
62
+ chips
63
+ },
64
+ chipBlocks: []
65
+ }
66
+ ]
67
+ },
68
+ comment: {
69
+ label: "Як можна покращити послугу?",
70
+ hint: "Розкажіть більше про враження (необовʼязково)"
71
+ },
72
+ mainButton: "Надіслати відгук",
73
+ ...ratingForm
74
+ };
80
75
  }
81
- //# sourceMappingURL=analytics.js.map
76
+ //#endregion
77
+ export { getRatingFormMock };
@@ -0,0 +1 @@
1
+ import { getRatingFormMock } from "./analytics.js";
@@ -0,0 +1,25 @@
1
+ import { AnalyticsActionResult } from "../interfaces/actionResult.js";
2
+ import { AnalyticsActionType } from "../interfaces/actionType.js";
3
+ import { AnalyticsCategory } from "../interfaces/categories.js";
4
+ import { AcquirerAnalyticsData, NotificationAnalyticsData, UserAnalyticsData } from "../interfaces/data.js";
5
+ import { ObjectId } from "bson";
6
+ import { ActHeaders, AlsData, Logger } from "@diia-inhouse/types";
7
+ import { AsyncLocalStorage } from "node:async_hooks";
8
+
9
+ //#region src/services/analytics.d.ts
10
+ declare class AnalyticsService {
11
+ private readonly logger;
12
+ private readonly asyncLocalStorage;
13
+ constructor(logger: Logger, asyncLocalStorage: AsyncLocalStorage<AlsData>);
14
+ acquirerLog(category: AnalyticsCategory, acquirerId: ObjectId, actionType: AnalyticsActionType, actionResult: AnalyticsActionResult, headers: ActHeaders | undefined, data?: AcquirerAnalyticsData): void;
15
+ userAcquirerLog(category: AnalyticsCategory, userIdentifier: string, acquirerId: ObjectId | undefined, actionType: AnalyticsActionType, actionResult: AnalyticsActionResult, headers: ActHeaders | undefined, data?: AcquirerAnalyticsData): void;
16
+ notificationLog(actionType: AnalyticsActionType, actionResult: AnalyticsActionResult, headers: ActHeaders, data?: NotificationAnalyticsData): void;
17
+ userLog(actionType: AnalyticsActionType, actionResult: AnalyticsActionResult, userIdentifier: string, headers: ActHeaders, data?: UserAnalyticsData): void;
18
+ authLog(actionType: AnalyticsActionType, actionResult: AnalyticsActionResult, userIdentifier: string, headers: ActHeaders, data?: Record<string, unknown>): void;
19
+ log(category: string, actionType: string, actionResult: string, data?: Record<string, unknown>): void;
20
+ private getDate;
21
+ private getDevice;
22
+ private logAnalytics;
23
+ }
24
+ //#endregion
25
+ export { AnalyticsService };
@@ -1,146 +1,134 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AnalyticsService = void 0;
4
- const utils_1 = require("@diia-inhouse/utils");
5
- const interfaces_1 = require("../interfaces");
6
- class AnalyticsService {
7
- logger;
8
- asyncLocalStorage;
9
- constructor(logger, asyncLocalStorage) {
10
- this.logger = logger;
11
- this.asyncLocalStorage = asyncLocalStorage;
12
- }
13
- acquirerLog(category, acquirerId, actionType, actionResult, headers, data) {
14
- const analytics = {
15
- date: this.getDate(),
16
- category,
17
- acquirer: acquirerId,
18
- action: {
19
- type: actionType,
20
- result: actionResult,
21
- },
22
- appVersion: headers?.appVersion,
23
- device: this.getDevice(headers),
24
- data,
25
- };
26
- this.logAnalytics(analytics);
27
- }
28
- userAcquirerLog(category, userIdentifier, acquirerId, actionType, actionResult, headers, data) {
29
- const analytics = {
30
- date: this.getDate(),
31
- category,
32
- acquirer: acquirerId,
33
- identifier: userIdentifier,
34
- action: {
35
- type: actionType,
36
- result: actionResult,
37
- },
38
- appVersion: headers?.appVersion,
39
- device: this.getDevice(headers),
40
- data,
41
- };
42
- this.logAnalytics(analytics);
43
- }
44
- notificationLog(actionType, actionResult, headers, data) {
45
- const analytics = {
46
- date: this.getDate(),
47
- category: interfaces_1.AnalyticsCategory.Notification,
48
- action: {
49
- type: actionType,
50
- result: actionResult,
51
- },
52
- appVersion: headers.appVersion,
53
- device: this.getDevice(headers),
54
- data,
55
- };
56
- this.logAnalytics(analytics);
57
- }
58
- userLog(actionType, actionResult, userIdentifier, headers, data) {
59
- const analytics = {
60
- date: this.getDate(),
61
- category: interfaces_1.AnalyticsCategory.Users,
62
- action: {
63
- type: actionType,
64
- result: actionResult,
65
- },
66
- identifier: userIdentifier,
67
- appVersion: headers.appVersion,
68
- device: this.getDevice(headers),
69
- data,
70
- };
71
- this.logAnalytics(analytics);
72
- }
73
- authLog(actionType, actionResult, userIdentifier, headers, data) {
74
- const analytics = {
75
- date: this.getDate(),
76
- category: interfaces_1.AnalyticsCategory.Auth,
77
- action: {
78
- type: actionType,
79
- result: actionResult,
80
- },
81
- identifier: userIdentifier,
82
- appVersion: headers.appVersion,
83
- device: this.getDevice(headers),
84
- data,
85
- };
86
- this.logAnalytics(analytics);
87
- }
88
- log(category, actionType, actionResult, data) {
89
- const context = this.asyncLocalStorage.getStore();
90
- if (!context) {
91
- this.logger.fatal('Analytics log is used without als context');
92
- return;
93
- }
94
- const { session, headers } = context;
95
- const analytics = {
96
- date: this.getDate(),
97
- category,
98
- action: {
99
- type: actionType,
100
- result: actionResult,
101
- },
102
- appVersion: headers?.appVersion,
103
- device: this.getDevice(headers),
104
- data,
105
- };
106
- if (utils_1.guards.isUserSession(session)) {
107
- analytics.identifier = session.user.identifier;
108
- }
109
- if (utils_1.guards.isServiceEntranceSession(session)) {
110
- const { acquirerId, branchHashId, offerHashId } = session.entrance;
111
- analytics.acquirer = acquirerId;
112
- if (!data) {
113
- data = {};
114
- }
115
- if (!data.branch) {
116
- data.branch = branchHashId;
117
- }
118
- if (!data.offer) {
119
- data.offer = offerHashId;
120
- }
121
- }
122
- this.logger.info('Analytics', { analytics });
123
- }
124
- getDate() {
125
- return new Date().toISOString();
126
- }
127
- getDevice(headers) {
128
- if (!headers) {
129
- return;
130
- }
131
- const { mobileUid, platformType, platformVersion } = headers;
132
- return {
133
- identifier: mobileUid,
134
- platform: {
135
- type: platformType,
136
- version: platformVersion,
137
- },
138
- };
139
- }
140
- logAnalytics(analytics) {
141
- const log = { analytics };
142
- this.logger.info('Analytics', log);
143
- }
144
- }
145
- exports.AnalyticsService = AnalyticsService;
146
- //# sourceMappingURL=analytics.js.map
1
+ import "../interfaces/categories.js";
2
+ import { guards } from "@diia-inhouse/utils";
3
+ //#region src/services/analytics.ts
4
+ var AnalyticsService = class {
5
+ logger;
6
+ asyncLocalStorage;
7
+ constructor(logger, asyncLocalStorage) {
8
+ this.logger = logger;
9
+ this.asyncLocalStorage = asyncLocalStorage;
10
+ }
11
+ acquirerLog(category, acquirerId, actionType, actionResult, headers, data) {
12
+ const analytics = {
13
+ date: this.getDate(),
14
+ category,
15
+ acquirer: acquirerId,
16
+ action: {
17
+ type: actionType,
18
+ result: actionResult
19
+ },
20
+ appVersion: headers?.appVersion,
21
+ device: this.getDevice(headers),
22
+ data
23
+ };
24
+ this.logAnalytics(analytics);
25
+ }
26
+ userAcquirerLog(category, userIdentifier, acquirerId, actionType, actionResult, headers, data) {
27
+ const analytics = {
28
+ date: this.getDate(),
29
+ category,
30
+ acquirer: acquirerId,
31
+ identifier: userIdentifier,
32
+ action: {
33
+ type: actionType,
34
+ result: actionResult
35
+ },
36
+ appVersion: headers?.appVersion,
37
+ device: this.getDevice(headers),
38
+ data
39
+ };
40
+ this.logAnalytics(analytics);
41
+ }
42
+ notificationLog(actionType, actionResult, headers, data) {
43
+ const analytics = {
44
+ date: this.getDate(),
45
+ category: "notification",
46
+ action: {
47
+ type: actionType,
48
+ result: actionResult
49
+ },
50
+ appVersion: headers.appVersion,
51
+ device: this.getDevice(headers),
52
+ data
53
+ };
54
+ this.logAnalytics(analytics);
55
+ }
56
+ userLog(actionType, actionResult, userIdentifier, headers, data) {
57
+ const analytics = {
58
+ date: this.getDate(),
59
+ category: "users",
60
+ action: {
61
+ type: actionType,
62
+ result: actionResult
63
+ },
64
+ identifier: userIdentifier,
65
+ appVersion: headers.appVersion,
66
+ device: this.getDevice(headers),
67
+ data
68
+ };
69
+ this.logAnalytics(analytics);
70
+ }
71
+ authLog(actionType, actionResult, userIdentifier, headers, data) {
72
+ const analytics = {
73
+ date: this.getDate(),
74
+ category: "auth",
75
+ action: {
76
+ type: actionType,
77
+ result: actionResult
78
+ },
79
+ identifier: userIdentifier,
80
+ appVersion: headers.appVersion,
81
+ device: this.getDevice(headers),
82
+ data
83
+ };
84
+ this.logAnalytics(analytics);
85
+ }
86
+ log(category, actionType, actionResult, data) {
87
+ const context = this.asyncLocalStorage.getStore();
88
+ if (!context) {
89
+ this.logger.fatal("Analytics log is used without als context");
90
+ return;
91
+ }
92
+ const { session, headers } = context;
93
+ const analytics = {
94
+ date: this.getDate(),
95
+ category,
96
+ action: {
97
+ type: actionType,
98
+ result: actionResult
99
+ },
100
+ appVersion: headers?.appVersion,
101
+ device: this.getDevice(headers),
102
+ data
103
+ };
104
+ if (guards.isUserSession(session)) analytics.identifier = session.user.identifier;
105
+ if (guards.isServiceEntranceSession(session)) {
106
+ const { acquirerId, branchHashId, offerHashId } = session.entrance;
107
+ analytics.acquirer = acquirerId;
108
+ if (!data) data = {};
109
+ if (!data.branch) data.branch = branchHashId;
110
+ if (!data.offer) data.offer = offerHashId;
111
+ }
112
+ this.logger.info("Analytics", { analytics });
113
+ }
114
+ getDate() {
115
+ return (/* @__PURE__ */ new Date()).toISOString();
116
+ }
117
+ getDevice(headers) {
118
+ if (!headers) return;
119
+ const { mobileUid, platformType, platformVersion } = headers;
120
+ return {
121
+ identifier: mobileUid,
122
+ platform: {
123
+ type: platformType,
124
+ version: platformVersion
125
+ }
126
+ };
127
+ }
128
+ logAnalytics(analytics) {
129
+ const log = { analytics };
130
+ this.logger.info("Analytics", log);
131
+ }
132
+ };
133
+ //#endregion
134
+ export { AnalyticsService };
@@ -0,0 +1 @@
1
+ import { AnalyticsService } from "./analytics.js";
@@ -1,18 +1,2 @@
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("./analytics"), exports);
18
- //# sourceMappingURL=index.js.map
1
+ import "./analytics.js";
2
+ export {};
@@ -0,0 +1 @@
1
+ import { RatingUtils } from "./rating.js";
@@ -0,0 +1,13 @@
1
+ import { ChipParams, RatingCategory, RatingFormCode, TextParams } from "../interfaces/rating.js";
2
+ import { RatingForm } from "@diia-inhouse/types";
3
+
4
+ //#region src/utils/rating.d.ts
5
+ declare class RatingUtils {
6
+ private readonly chipCodeToValueDefaultMap;
7
+ private readonly chipLabelMap;
8
+ private readonly ratingLabelMap;
9
+ private readonly commentLabelMap;
10
+ getRatingForm<T extends string>(formCode: RatingFormCode, category: RatingCategory, chipParams: ChipParams<T>, textParams?: TextParams, resourceId?: string, showInAppReview?: boolean): RatingForm;
11
+ }
12
+ //#endregion
13
+ export { RatingUtils };