@bikdotai/bik-shared-backend 20.3.1 → 20.3.2-beta.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/lib/alerts/templates/campaign/campaignMovedToDraftSegmentSyncDelay.d.ts +1 -0
- package/lib/alerts/templates/campaign/campaignMovedToDraftSegmentSyncDelay.js +4 -0
- package/lib/alerts/templates/campaign/campaignMovedToDraftSegmentSyncFailed.d.ts +1 -0
- package/lib/alerts/templates/campaign/campaignMovedToDraftSegmentSyncFailed.js +4 -0
- package/lib/alerts/templates/campaign/campaignScheduledTimeExceededDueToSyncDelay.d.ts +1 -0
- package/lib/alerts/templates/campaign/campaignScheduledTimeExceededDueToSyncDelay.js +4 -0
- package/lib/alertsV2/alertInstances.repo.js +26 -2
- package/lib/alertsV2/alertsV2.helper.d.ts +3 -4
- package/lib/alertsV2/alertsV2.helper.js +49 -3
- package/lib/alertsV2/alertsV2.service.js +14 -5
- package/lib/auth/authMiddlewares.js +68 -3
- package/lib/auth/firebase-auth.service.js +3 -3
- package/lib/auth/implementations/bik-admin-auth-service.d.ts +1 -1
- package/lib/auth/implementations/bik-admin-auth-service.js +2 -1
- package/lib/auth/index.d.ts +3 -0
- package/lib/auth/index.js +3 -0
- package/lib/auth/secret-manager/configManager.firestore.d.ts +22 -0
- package/lib/auth/secret-manager/configManager.firestore.js +166 -0
- package/lib/auth/secret-manager/configManager.helper.d.ts +13 -0
- package/lib/auth/secret-manager/configManager.helper.js +32 -0
- package/lib/auth/secret-manager/configManager.model.d.ts +38 -0
- package/lib/auth/secret-manager/configManager.model.js +2 -0
- package/lib/auth/secret-manager/configManager.service.d.ts +17 -0
- package/lib/auth/secret-manager/configManager.service.js +138 -0
- package/lib/auth/secret-manager/env-variables/variables.list.d.ts +3 -0
- package/lib/auth/secret-manager/env-variables/variables.list.js +3 -0
- package/lib/chat-handover-protocol/chat-handover-protocol.js +26 -41
- package/lib/core/local_runner.js +28 -11
- package/lib/core/setup.d.ts +3 -0
- package/lib/core/setup.js +24 -2
- package/lib/database/database.model.d.ts +95 -0
- package/lib/database/database.model.js +5 -0
- package/lib/database/database.service.d.ts +90 -0
- package/lib/database/database.service.js +382 -0
- package/lib/database/index.d.ts +7 -0
- package/lib/database/index.js +23 -0
- package/lib/elastic/counter/ingestion.js +1 -0
- package/lib/elastic/queries/campaign/getBroadcastDetailedStats.d.ts +117 -0
- package/lib/elastic/queries/campaign/getBroadcastDetailedStats.js +94 -1
- package/lib/elastic/queries/campaign/getUniqueCustomerCnt.d.ts +1 -0
- package/lib/elastic/queries/campaign/getUniqueCustomerCnt.js +1 -0
- package/lib/elastic/queries/chatbot/getAgentCostForBroadcast.d.ts +117 -0
- package/lib/elastic/queries/chatbot/getAgentCostForBroadcast.js +98 -0
- package/lib/elastic/queries/chatbot/getAiOperations.d.ts +5 -5
- package/lib/elastic/queries/chatbot/getAiOperations.js +3 -3
- package/lib/elastic/queries/chatbot/index.d.ts +1 -0
- package/lib/elastic/queries/chatbot/index.js +1 -0
- package/lib/elastic/queries/crm/getActivityTimelineByAgent.js +1 -1
- package/lib/elastic/queries/crm/getBreachedSLACount.d.ts +1 -0
- package/lib/elastic/queries/crm/getBreachedSLACount.js +8 -5
- package/lib/elastic/queries/crm/getFirstResponseTime.d.ts +1 -0
- package/lib/elastic/queries/crm/getFirstResponseTime.js +8 -5
- package/lib/elastic/queries/integrations/getOrdersShadowServices.d.ts +76 -0
- package/lib/elastic/queries/integrations/getOrdersShadowServices.js +61 -0
- package/lib/elastic/queries/integrations/index.d.ts +1 -0
- package/lib/elastic/queries/integrations/index.js +1 -0
- package/lib/elastic/queries/openAi/addToCartSession.d.ts +1 -0
- package/lib/elastic/queries/openAi/addToCartSession.js +11 -3
- package/lib/elastic/queries/openAi/checkoutCompletedSession.d.ts +1 -0
- package/lib/elastic/queries/openAi/checkoutCompletedSession.js +11 -3
- package/lib/elastic/reports/crm/index.d.ts +1 -0
- package/lib/elastic/reports/crm/index.js +1 -0
- package/lib/elastic/reports/reports.service.js +17 -8
- package/lib/events/events.d.ts +8 -0
- package/lib/events/events.js +25 -1
- package/lib/events/schema/events.helper.d.ts +1 -0
- package/lib/events/schema/events.helper.js +12 -6
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/merchant-events/elastic.search.d.ts +5 -0
- package/lib/merchant-events/elastic.search.js +23 -2
- package/lib/merchant-events/merchant.service.d.ts +1 -1
- package/lib/merchant-events/merchant.service.js +12 -11
- package/lib/recordAnalytics/recordAnalytics.service.js +5 -4
- package/lib/redis/redisPubSubService.d.ts +4 -6
- package/lib/redis/redisPubSubService.js +211 -123
- package/lib/redis/redisService.js +14 -8
- package/lib/swagger/SwaggerSchemaHelper.js +21 -17
- package/lib/user-properties/userProperties.service.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Events } from '@bikdotai/bik-models/events';
|
|
2
|
+
import { QueryHelper } from '../query.helper';
|
|
3
|
+
export interface GetAgentCostForBroadcastParams {
|
|
4
|
+
indexName: string;
|
|
5
|
+
storeId: string;
|
|
6
|
+
broadcastId: string;
|
|
7
|
+
startDate: string;
|
|
8
|
+
endDate: string;
|
|
9
|
+
}
|
|
10
|
+
export interface AgentCostUsageBucket {
|
|
11
|
+
usedTier: string | null;
|
|
12
|
+
usageType: string | null;
|
|
13
|
+
isFreeAgent: boolean | null;
|
|
14
|
+
/** For non-audio usage: number of operations */
|
|
15
|
+
count: number;
|
|
16
|
+
/** For audio (AUDIO usageType): total seconds */
|
|
17
|
+
usageUnits: number;
|
|
18
|
+
}
|
|
19
|
+
export interface GetAgentCostForBroadcastResponse {
|
|
20
|
+
buckets: AgentCostUsageBucket[];
|
|
21
|
+
}
|
|
22
|
+
export declare class GetAgentCostForBroadcastQuery implements QueryHelper<GetAgentCostForBroadcastParams, GetAgentCostForBroadcastResponse> {
|
|
23
|
+
getQuery(params: GetAgentCostForBroadcastParams): {
|
|
24
|
+
index: string;
|
|
25
|
+
size: number;
|
|
26
|
+
query: {
|
|
27
|
+
bool: {
|
|
28
|
+
filter: {
|
|
29
|
+
range: {
|
|
30
|
+
timestamp: {
|
|
31
|
+
gte: string;
|
|
32
|
+
lte: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}[];
|
|
36
|
+
must: ({
|
|
37
|
+
term: {
|
|
38
|
+
'storeId.keyword': {
|
|
39
|
+
value: string;
|
|
40
|
+
};
|
|
41
|
+
"eventName.keyword"?: undefined;
|
|
42
|
+
'eventProperties.useCaseId.keyword'?: undefined;
|
|
43
|
+
};
|
|
44
|
+
} | {
|
|
45
|
+
term: {
|
|
46
|
+
'eventName.keyword': {
|
|
47
|
+
value: Events;
|
|
48
|
+
};
|
|
49
|
+
"storeId.keyword"?: undefined;
|
|
50
|
+
'eventProperties.useCaseId.keyword'?: undefined;
|
|
51
|
+
};
|
|
52
|
+
} | {
|
|
53
|
+
term: {
|
|
54
|
+
'eventProperties.useCaseId.keyword': {
|
|
55
|
+
value: string;
|
|
56
|
+
};
|
|
57
|
+
"storeId.keyword"?: undefined;
|
|
58
|
+
"eventName.keyword"?: undefined;
|
|
59
|
+
};
|
|
60
|
+
})[];
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
aggs: {
|
|
64
|
+
usage_by_tier_type_agent: {
|
|
65
|
+
composite: {
|
|
66
|
+
size: number;
|
|
67
|
+
sources: ({
|
|
68
|
+
usedTier: {
|
|
69
|
+
terms: {
|
|
70
|
+
field: string;
|
|
71
|
+
missing_bucket: boolean;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
usageType?: undefined;
|
|
75
|
+
isFreeAgent?: undefined;
|
|
76
|
+
} | {
|
|
77
|
+
usageType: {
|
|
78
|
+
terms: {
|
|
79
|
+
field: string;
|
|
80
|
+
missing_bucket: boolean;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
usedTier?: undefined;
|
|
84
|
+
isFreeAgent?: undefined;
|
|
85
|
+
} | {
|
|
86
|
+
isFreeAgent: {
|
|
87
|
+
terms: {
|
|
88
|
+
field: string;
|
|
89
|
+
missing_bucket: boolean;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
usedTier?: undefined;
|
|
93
|
+
usageType?: undefined;
|
|
94
|
+
})[];
|
|
95
|
+
};
|
|
96
|
+
aggs: {
|
|
97
|
+
audio_usage: {
|
|
98
|
+
filter: {
|
|
99
|
+
term: {
|
|
100
|
+
'eventProperties.usageType.keyword': string;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
aggs: {
|
|
104
|
+
total_usage_units: {
|
|
105
|
+
sum: {
|
|
106
|
+
field: string;
|
|
107
|
+
missing: number;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
transform(elasticOutput: any): GetAgentCostForBroadcastResponse;
|
|
117
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetAgentCostForBroadcastQuery = void 0;
|
|
4
|
+
const events_1 = require("@bikdotai/bik-models/events");
|
|
5
|
+
class GetAgentCostForBroadcastQuery {
|
|
6
|
+
getQuery(params) {
|
|
7
|
+
return {
|
|
8
|
+
index: params.indexName,
|
|
9
|
+
size: 0,
|
|
10
|
+
query: {
|
|
11
|
+
bool: {
|
|
12
|
+
filter: [
|
|
13
|
+
{
|
|
14
|
+
range: {
|
|
15
|
+
timestamp: { gte: params.startDate, lte: params.endDate },
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
must: [
|
|
20
|
+
{ term: { 'storeId.keyword': { value: params.storeId } } },
|
|
21
|
+
{ term: { 'eventName.keyword': { value: events_1.Events.SERVICE_USED } } },
|
|
22
|
+
{
|
|
23
|
+
term: {
|
|
24
|
+
'eventProperties.useCaseId.keyword': { value: params.broadcastId },
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
aggs: {
|
|
31
|
+
usage_by_tier_type_agent: {
|
|
32
|
+
composite: {
|
|
33
|
+
size: 10000,
|
|
34
|
+
sources: [
|
|
35
|
+
{
|
|
36
|
+
usedTier: {
|
|
37
|
+
terms: {
|
|
38
|
+
field: 'eventProperties.usedTier.keyword',
|
|
39
|
+
missing_bucket: true,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
usageType: {
|
|
45
|
+
terms: {
|
|
46
|
+
field: 'eventProperties.usageType.keyword',
|
|
47
|
+
missing_bucket: true,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
isFreeAgent: {
|
|
53
|
+
terms: {
|
|
54
|
+
field: 'eventProperties.isFreeAgent',
|
|
55
|
+
missing_bucket: true,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
aggs: {
|
|
62
|
+
audio_usage: {
|
|
63
|
+
filter: {
|
|
64
|
+
term: { 'eventProperties.usageType.keyword': 'AUDIO' },
|
|
65
|
+
},
|
|
66
|
+
aggs: {
|
|
67
|
+
total_usage_units: {
|
|
68
|
+
sum: { field: 'eventProperties.usageUnits', missing: 0 },
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
transform(elasticOutput) {
|
|
78
|
+
var _a, _b, _c;
|
|
79
|
+
const buckets = (_c = (_b = (_a = elasticOutput === null || elasticOutput === void 0 ? void 0 : elasticOutput.aggregations) === null || _a === void 0 ? void 0 : _a.usage_by_tier_type_agent) === null || _b === void 0 ? void 0 : _b.buckets) !== null && _c !== void 0 ? _c : [];
|
|
80
|
+
return {
|
|
81
|
+
buckets: buckets
|
|
82
|
+
.filter((b) => b.key.usedTier !== null &&
|
|
83
|
+
b.key.usageType !== null &&
|
|
84
|
+
b.key.isFreeAgent !== null)
|
|
85
|
+
.map((b) => {
|
|
86
|
+
var _a, _b, _c, _d;
|
|
87
|
+
return ({
|
|
88
|
+
usedTier: b.key.usedTier,
|
|
89
|
+
usageType: b.key.usageType,
|
|
90
|
+
isFreeAgent: b.key.isFreeAgent,
|
|
91
|
+
count: (_a = b.doc_count) !== null && _a !== void 0 ? _a : 0,
|
|
92
|
+
usageUnits: (_d = (_c = (_b = b.audio_usage) === null || _b === void 0 ? void 0 : _b.total_usage_units) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0,
|
|
93
|
+
});
|
|
94
|
+
}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.GetAgentCostForBroadcastQuery = GetAgentCostForBroadcastQuery;
|
|
@@ -24,7 +24,7 @@ export interface ServiceUsedEventProperties {
|
|
|
24
24
|
usageType?: AiUsageType;
|
|
25
25
|
usageUnits?: number;
|
|
26
26
|
}
|
|
27
|
-
export interface
|
|
27
|
+
export interface GetAiOperationsV2Params {
|
|
28
28
|
startDate: string;
|
|
29
29
|
endDate: string;
|
|
30
30
|
storeId: string;
|
|
@@ -46,7 +46,7 @@ export interface AiOpsBucket {
|
|
|
46
46
|
key: AiOpsBucketKey;
|
|
47
47
|
usage: UsageMeasurement;
|
|
48
48
|
}
|
|
49
|
-
export interface
|
|
49
|
+
export interface GetAiOperationsV2Response {
|
|
50
50
|
buckets: AiOpsBucket[];
|
|
51
51
|
}
|
|
52
52
|
interface RangeTimestampQuery {
|
|
@@ -133,8 +133,8 @@ interface AiOperationsSearchResponse {
|
|
|
133
133
|
};
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
|
-
export declare class
|
|
137
|
-
getQuery(params:
|
|
138
|
-
transform(elasticOutput: AiOperationsSearchResponse):
|
|
136
|
+
export declare class GetAiOperationsV2Query implements QueryHelper<GetAiOperationsV2Params, GetAiOperationsV2Response> {
|
|
137
|
+
getQuery(params: GetAiOperationsV2Params): AiOperationsSearchRequest;
|
|
138
|
+
transform(elasticOutput: AiOperationsSearchResponse): GetAiOperationsV2Response;
|
|
139
139
|
}
|
|
140
140
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GetAiOperationsV2Query = exports.AiTier = exports.AiUsageType = void 0;
|
|
4
4
|
const events_1 = require("@bikdotai/bik-models/events");
|
|
5
5
|
const Channel_1 = require("@bikdotai/bik-models/campaigns/models/Channel");
|
|
6
6
|
var AiUsageType;
|
|
@@ -18,7 +18,7 @@ var AiTier;
|
|
|
18
18
|
AiTier["MODEL_TIER_3"] = "MODEL_TIER_3";
|
|
19
19
|
AiTier["MODEL_TIER_4"] = "MODEL_TIER_4";
|
|
20
20
|
})(AiTier = exports.AiTier || (exports.AiTier = {}));
|
|
21
|
-
class
|
|
21
|
+
class GetAiOperationsV2Query {
|
|
22
22
|
getQuery(params) {
|
|
23
23
|
return {
|
|
24
24
|
index: params.indexName,
|
|
@@ -134,4 +134,4 @@ class GetAiOperationsQuery {
|
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
exports.
|
|
137
|
+
exports.GetAiOperationsV2Query = GetAiOperationsV2Query;
|
|
@@ -115,3 +115,4 @@ export * from './getNewUserAcquiredReportChatbot';
|
|
|
115
115
|
export * from './getNewUserAcquiredReportNonAnalytics';
|
|
116
116
|
export * from './getEventsConversionReportCampaign';
|
|
117
117
|
export * from './getEventsConversionReportNonAnalytics';
|
|
118
|
+
export * from './getAgentCostForBroadcast';
|
|
@@ -131,3 +131,4 @@ __exportStar(require("./getNewUserAcquiredReportChatbot"), exports);
|
|
|
131
131
|
__exportStar(require("./getNewUserAcquiredReportNonAnalytics"), exports);
|
|
132
132
|
__exportStar(require("./getEventsConversionReportCampaign"), exports);
|
|
133
133
|
__exportStar(require("./getEventsConversionReportNonAnalytics"), exports);
|
|
134
|
+
__exportStar(require("./getAgentCostForBroadcast"), exports);
|
|
@@ -42,7 +42,7 @@ class GetActivityTimelineByAgentQuery {
|
|
|
42
42
|
group_by_agent: {
|
|
43
43
|
terms: {
|
|
44
44
|
field: 'eventProperties.agentId',
|
|
45
|
-
size: ((_b = params.agentIds) === null || _b === void 0 ? void 0 : _b.length)
|
|
45
|
+
size: params.agentIds && ((_b = params.agentIds) === null || _b === void 0 ? void 0 : _b.length) > 0 ? params.agentIds.length : 10000, // Limit to provided agents or large number
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
48
|
};
|
|
@@ -15,11 +15,7 @@ class GetBreachedSLACountQuery {
|
|
|
15
15
|
? {
|
|
16
16
|
by_agent_id: {
|
|
17
17
|
terms: {
|
|
18
|
-
|
|
19
|
-
// to support both text and number fields for agentId depending on the source index of the event
|
|
20
|
-
source: "if (doc.containsKey('eventProperties.agentId.keyword') && !doc['eventProperties.agentId.keyword'].empty) { return doc['eventProperties.agentId.keyword'].value; } else if (doc.containsKey('eventProperties.agentId') && !doc['eventProperties.agentId'].empty) { return doc['eventProperties.agentId'].value; } else { return ''; }",
|
|
21
|
-
lang: 'painless',
|
|
22
|
-
},
|
|
18
|
+
field: 'eventProperties.agentId',
|
|
23
19
|
size: ((_a = input.agentIds) === null || _a === void 0 ? void 0 : _a.length) || 500,
|
|
24
20
|
},
|
|
25
21
|
},
|
|
@@ -92,6 +88,13 @@ class GetBreachedSLACountQuery {
|
|
|
92
88
|
},
|
|
93
89
|
});
|
|
94
90
|
}
|
|
91
|
+
if (input.teamId) {
|
|
92
|
+
whereArray.push({
|
|
93
|
+
term: {
|
|
94
|
+
'eventProperties.teamId': input.teamId,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
95
98
|
// if channel is a non-empty array, or a string, then add it to the query
|
|
96
99
|
if (!input.chatSessionIds &&
|
|
97
100
|
((Array.isArray(input.channel) && input.channel.length > 0) ||
|
|
@@ -30,11 +30,7 @@ class GetFirstResponseTimeQuery {
|
|
|
30
30
|
? {
|
|
31
31
|
tickets_by_agent_id: {
|
|
32
32
|
terms: {
|
|
33
|
-
|
|
34
|
-
// to support both text and number fields for agentId depending on the source index of the event
|
|
35
|
-
source: "if (doc.containsKey('eventProperties.agentId.keyword') && !doc['eventProperties.agentId.keyword'].empty) { return doc['eventProperties.agentId.keyword'].value; } else if (doc.containsKey('eventProperties.agentId') && !doc['eventProperties.agentId'].empty) { return doc['eventProperties.agentId'].value; } else { return ''; }",
|
|
36
|
-
lang: 'painless',
|
|
37
|
-
},
|
|
33
|
+
field: 'eventProperties.agentId',
|
|
38
34
|
size: (_c = (_b = params.agentIds) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 500,
|
|
39
35
|
},
|
|
40
36
|
aggs: {
|
|
@@ -122,6 +118,13 @@ class GetFirstResponseTimeQuery {
|
|
|
122
118
|
},
|
|
123
119
|
});
|
|
124
120
|
}
|
|
121
|
+
if (params.teamId) {
|
|
122
|
+
whereArray.push({
|
|
123
|
+
term: {
|
|
124
|
+
'eventProperties.teamId': params.teamId,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
125
128
|
whereArray.push({
|
|
126
129
|
range: {
|
|
127
130
|
createdAt: {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { QueryHelper } from '../query.helper';
|
|
2
|
+
export interface GetOrdersShadowServicesParams {
|
|
3
|
+
indexName: string;
|
|
4
|
+
storeId: string;
|
|
5
|
+
startDate: string;
|
|
6
|
+
endDate: string;
|
|
7
|
+
pageSize?: number;
|
|
8
|
+
afterKey?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface OrderShadowServicesItem {
|
|
11
|
+
id: string;
|
|
12
|
+
orderId?: string;
|
|
13
|
+
orderValue?: number;
|
|
14
|
+
shadowServices?: string[];
|
|
15
|
+
shadowServiceIds?: string[];
|
|
16
|
+
shadowServicePods?: string[];
|
|
17
|
+
}
|
|
18
|
+
export interface GetOrdersShadowServicesResponse {
|
|
19
|
+
orders: OrderShadowServicesItem[];
|
|
20
|
+
afterKey: string | null;
|
|
21
|
+
hasMore: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface ElasticHitSource {
|
|
24
|
+
eventProperties?: {
|
|
25
|
+
orderId?: string;
|
|
26
|
+
orderValue?: number;
|
|
27
|
+
shadowServices?: string[];
|
|
28
|
+
shadowServiceIds?: string[];
|
|
29
|
+
shadowServicePods?: string[];
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
interface ElasticHit {
|
|
33
|
+
_id: string;
|
|
34
|
+
_source: ElasticHitSource;
|
|
35
|
+
sort?: [string];
|
|
36
|
+
}
|
|
37
|
+
interface ElasticSearchResponse {
|
|
38
|
+
hits: {
|
|
39
|
+
hits: ElasticHit[];
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export declare class GetOrdersShadowServicesQuery implements QueryHelper<GetOrdersShadowServicesParams, GetOrdersShadowServicesResponse> {
|
|
43
|
+
getQuery(params: GetOrdersShadowServicesParams): {
|
|
44
|
+
index: string;
|
|
45
|
+
size: number;
|
|
46
|
+
_source: string[];
|
|
47
|
+
query: {
|
|
48
|
+
bool: {
|
|
49
|
+
filter: ({
|
|
50
|
+
term: {
|
|
51
|
+
[field: string]: {
|
|
52
|
+
value: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
} | {
|
|
56
|
+
range: {
|
|
57
|
+
[field: string]: {
|
|
58
|
+
gte: string;
|
|
59
|
+
lte: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
})[];
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
sort: {
|
|
66
|
+
[field: string]: "desc" | "asc";
|
|
67
|
+
}[];
|
|
68
|
+
search_after?: [string] | undefined;
|
|
69
|
+
};
|
|
70
|
+
transform(elasticOutput: ElasticSearchResponse, params: GetOrdersShadowServicesParams): {
|
|
71
|
+
orders: OrderShadowServicesItem[];
|
|
72
|
+
afterKey: string | null;
|
|
73
|
+
hasMore: boolean;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetOrdersShadowServicesQuery = void 0;
|
|
4
|
+
const events_1 = require("@bikdotai/bik-models/events");
|
|
5
|
+
const DEFAULT_PAGE_SIZE = 1000;
|
|
6
|
+
class GetOrdersShadowServicesQuery {
|
|
7
|
+
getQuery(params) {
|
|
8
|
+
var _a;
|
|
9
|
+
const size = (_a = params.pageSize) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_SIZE;
|
|
10
|
+
const query = {
|
|
11
|
+
index: params.indexName,
|
|
12
|
+
size,
|
|
13
|
+
_source: [
|
|
14
|
+
'eventProperties.orderId',
|
|
15
|
+
'eventProperties.orderValue',
|
|
16
|
+
'eventProperties.shadowServices',
|
|
17
|
+
'eventProperties.shadowServiceIds',
|
|
18
|
+
'eventProperties.shadowServicePods',
|
|
19
|
+
],
|
|
20
|
+
query: {
|
|
21
|
+
bool: {
|
|
22
|
+
filter: [
|
|
23
|
+
{ term: { 'storeId.keyword': { value: params.storeId } } },
|
|
24
|
+
{ term: { 'eventName.keyword': { value: events_1.Events.ORDERED } } },
|
|
25
|
+
{ range: { createdAt: { gte: params.startDate, lte: params.endDate } } },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
sort: [{ _id: 'asc' }],
|
|
30
|
+
};
|
|
31
|
+
if (params.afterKey) {
|
|
32
|
+
query.search_after = [params.afterKey];
|
|
33
|
+
}
|
|
34
|
+
return query;
|
|
35
|
+
}
|
|
36
|
+
transform(elasticOutput, params) {
|
|
37
|
+
var _a, _b, _c;
|
|
38
|
+
const hits = (_b = (_a = elasticOutput.hits) === null || _a === void 0 ? void 0 : _a.hits) !== null && _b !== void 0 ? _b : [];
|
|
39
|
+
const orders = hits.map((hit) => {
|
|
40
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
41
|
+
return ({
|
|
42
|
+
id: hit._id,
|
|
43
|
+
orderId: (_b = (_a = hit._source) === null || _a === void 0 ? void 0 : _a.eventProperties) === null || _b === void 0 ? void 0 : _b.orderId,
|
|
44
|
+
orderValue: (_d = (_c = hit._source) === null || _c === void 0 ? void 0 : _c.eventProperties) === null || _d === void 0 ? void 0 : _d.orderValue,
|
|
45
|
+
shadowServices: (_f = (_e = hit._source) === null || _e === void 0 ? void 0 : _e.eventProperties) === null || _f === void 0 ? void 0 : _f.shadowServices,
|
|
46
|
+
shadowServiceIds: (_h = (_g = hit._source) === null || _g === void 0 ? void 0 : _g.eventProperties) === null || _h === void 0 ? void 0 : _h.shadowServiceIds,
|
|
47
|
+
shadowServicePods: (_k = (_j = hit._source) === null || _j === void 0 ? void 0 : _j.eventProperties) === null || _k === void 0 ? void 0 : _k.shadowServicePods,
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
const size = (_c = params.pageSize) !== null && _c !== void 0 ? _c : DEFAULT_PAGE_SIZE;
|
|
51
|
+
const hasMore = hits.length === size && hits.length > 0;
|
|
52
|
+
const lastHit = hits[hits.length - 1];
|
|
53
|
+
const afterKey = hasMore && (lastHit === null || lastHit === void 0 ? void 0 : lastHit._id) ? lastHit._id : null;
|
|
54
|
+
return {
|
|
55
|
+
orders,
|
|
56
|
+
afterKey,
|
|
57
|
+
hasMore,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.GetOrdersShadowServicesQuery = GetOrdersShadowServicesQuery;
|
|
@@ -19,6 +19,7 @@ export type AddToCartSessionBucket = {
|
|
|
19
19
|
addToCartSessions: number;
|
|
20
20
|
};
|
|
21
21
|
export type AddToCartSessionQueryResponse = {
|
|
22
|
+
addToCartCount: number;
|
|
22
23
|
addToCartSessions: number;
|
|
23
24
|
/** Populated only when `graphInterval` param is supplied. */
|
|
24
25
|
addToCartBuckets?: AddToCartSessionBucket[];
|
|
@@ -9,7 +9,14 @@ class AddToCartSessionQuery {
|
|
|
9
9
|
field: 'eventProperties.visitorSessionId.keyword',
|
|
10
10
|
},
|
|
11
11
|
};
|
|
12
|
-
const aggs = {
|
|
12
|
+
const aggs = {
|
|
13
|
+
total_count: {
|
|
14
|
+
value_count: {
|
|
15
|
+
field: 'eventName.keyword',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
unique_sessions: sessionCardinality,
|
|
19
|
+
};
|
|
13
20
|
if (params.graphInterval) {
|
|
14
21
|
aggs.graph = {
|
|
15
22
|
date_histogram: {
|
|
@@ -65,7 +72,7 @@ class AddToCartSessionQuery {
|
|
|
65
72
|
return query;
|
|
66
73
|
}
|
|
67
74
|
transform(elasticOutput) {
|
|
68
|
-
var _a, _b, _c;
|
|
75
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
69
76
|
const addToCartSessions = elasticOutput.aggregations.unique_sessions.value || 0;
|
|
70
77
|
const buckets = (_c = (_b = (_a = elasticOutput.aggregations) === null || _a === void 0 ? void 0 : _a.graph) === null || _b === void 0 ? void 0 : _b.buckets) !== null && _c !== void 0 ? _c : [];
|
|
71
78
|
const addToCartBuckets = buckets.map((b) => {
|
|
@@ -77,7 +84,8 @@ class AddToCartSessionQuery {
|
|
|
77
84
|
});
|
|
78
85
|
});
|
|
79
86
|
return {
|
|
80
|
-
|
|
87
|
+
addToCartCount: ((_e = (_d = elasticOutput.aggregations) === null || _d === void 0 ? void 0 : _d.total_count) === null || _e === void 0 ? void 0 : _e.value) || 0,
|
|
88
|
+
addToCartSessions: ((_g = (_f = elasticOutput.aggregations) === null || _f === void 0 ? void 0 : _f.unique_sessions) === null || _g === void 0 ? void 0 : _g.value) || 0,
|
|
81
89
|
addToCartBuckets: addToCartBuckets.length ? addToCartBuckets : undefined,
|
|
82
90
|
};
|
|
83
91
|
}
|
|
@@ -19,6 +19,7 @@ export type CheckoutCompletedSessionBucket = {
|
|
|
19
19
|
checkoutCompletedSessions: number;
|
|
20
20
|
};
|
|
21
21
|
export type CheckoutCompletedSessionQueryResponse = {
|
|
22
|
+
checkoutCompletedCount: number;
|
|
22
23
|
checkoutCompletedSessions: number;
|
|
23
24
|
/** Populated only when `graphInterval` param is supplied. */
|
|
24
25
|
checkoutCompletedBuckets?: CheckoutCompletedSessionBucket[];
|
|
@@ -9,7 +9,14 @@ class CheckoutCompletedSessionQuery {
|
|
|
9
9
|
field: 'eventProperties.visitorSessionId.keyword',
|
|
10
10
|
},
|
|
11
11
|
};
|
|
12
|
-
const aggs = {
|
|
12
|
+
const aggs = {
|
|
13
|
+
total_count: {
|
|
14
|
+
value_count: {
|
|
15
|
+
field: 'eventName.keyword',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
unique_sessions: sessionCardinality,
|
|
19
|
+
};
|
|
13
20
|
if (params.graphInterval) {
|
|
14
21
|
aggs.graph = {
|
|
15
22
|
date_histogram: {
|
|
@@ -65,7 +72,7 @@ class CheckoutCompletedSessionQuery {
|
|
|
65
72
|
return query;
|
|
66
73
|
}
|
|
67
74
|
transform(elasticOutput) {
|
|
68
|
-
var _a, _b, _c;
|
|
75
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
69
76
|
const checkoutCompletedSessions = elasticOutput.aggregations.unique_sessions.value || 0;
|
|
70
77
|
const buckets = (_c = (_b = (_a = elasticOutput.aggregations) === null || _a === void 0 ? void 0 : _a.graph) === null || _b === void 0 ? void 0 : _b.buckets) !== null && _c !== void 0 ? _c : [];
|
|
71
78
|
const checkoutCompletedBuckets = buckets.map((b) => {
|
|
@@ -77,7 +84,8 @@ class CheckoutCompletedSessionQuery {
|
|
|
77
84
|
});
|
|
78
85
|
});
|
|
79
86
|
return {
|
|
80
|
-
|
|
87
|
+
checkoutCompletedCount: ((_e = (_d = elasticOutput.aggregations) === null || _d === void 0 ? void 0 : _d.total_count) === null || _e === void 0 ? void 0 : _e.value) || 0,
|
|
88
|
+
checkoutCompletedSessions: ((_g = (_f = elasticOutput.aggregations) === null || _f === void 0 ? void 0 : _f.unique_sessions) === null || _g === void 0 ? void 0 : _g.value) || 0,
|
|
81
89
|
checkoutCompletedBuckets: checkoutCompletedBuckets.length ? checkoutCompletedBuckets : undefined,
|
|
82
90
|
};
|
|
83
91
|
}
|
|
@@ -19,3 +19,4 @@ __exportStar(require("./agentEngagement"), exports);
|
|
|
19
19
|
__exportStar(require("./conversationsReport"), exports);
|
|
20
20
|
__exportStar(require("./overAllCSATNPSReport"), exports);
|
|
21
21
|
__exportStar(require("./chatSessionOverviewReport"), exports);
|
|
22
|
+
__exportStar(require("./teamEngagement"), exports);
|