@bikdotai/bik-shared-backend 20.5.0 → 20.6.1-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.
Files changed (82) hide show
  1. package/lib/alerts/templates/campaign/campaignMovedToDraftSegmentSyncDelay.d.ts +1 -0
  2. package/lib/alerts/templates/campaign/campaignMovedToDraftSegmentSyncDelay.js +4 -0
  3. package/lib/alerts/templates/campaign/campaignMovedToDraftSegmentSyncFailed.d.ts +1 -0
  4. package/lib/alerts/templates/campaign/campaignMovedToDraftSegmentSyncFailed.js +4 -0
  5. package/lib/alerts/templates/campaign/campaignScheduledTimeExceededDueToSyncDelay.d.ts +1 -0
  6. package/lib/alerts/templates/campaign/campaignScheduledTimeExceededDueToSyncDelay.js +4 -0
  7. package/lib/alertsV2/alertInstances.repo.js +26 -2
  8. package/lib/alertsV2/alertsV2.helper.d.ts +3 -4
  9. package/lib/alertsV2/alertsV2.helper.js +49 -3
  10. package/lib/alertsV2/alertsV2.service.js +14 -5
  11. package/lib/auth/authMiddlewares.js +68 -3
  12. package/lib/auth/firebase-auth.service.js +3 -3
  13. package/lib/auth/implementations/bik-admin-auth-service.d.ts +1 -1
  14. package/lib/auth/implementations/bik-admin-auth-service.js +2 -1
  15. package/lib/auth/index.d.ts +3 -0
  16. package/lib/auth/index.js +3 -0
  17. package/lib/auth/secret-manager/configManager.firestore.d.ts +22 -0
  18. package/lib/auth/secret-manager/configManager.firestore.js +166 -0
  19. package/lib/auth/secret-manager/configManager.helper.d.ts +13 -0
  20. package/lib/auth/secret-manager/configManager.helper.js +32 -0
  21. package/lib/auth/secret-manager/configManager.model.d.ts +38 -0
  22. package/lib/auth/secret-manager/configManager.model.js +2 -0
  23. package/lib/auth/secret-manager/configManager.service.d.ts +17 -0
  24. package/lib/auth/secret-manager/configManager.service.js +138 -0
  25. package/lib/auth/secret-manager/env-variables/variables.list.d.ts +3 -0
  26. package/lib/auth/secret-manager/env-variables/variables.list.js +3 -0
  27. package/lib/chat-handover-protocol/chat-handover-protocol.js +26 -41
  28. package/lib/core/local_runner.d.ts +1 -0
  29. package/lib/core/local_runner.js +60 -0
  30. package/lib/core/setup.d.ts +3 -0
  31. package/lib/core/setup.js +24 -2
  32. package/lib/database/database.model.d.ts +95 -0
  33. package/lib/database/database.model.js +5 -0
  34. package/lib/database/database.service.d.ts +90 -0
  35. package/lib/database/database.service.js +382 -0
  36. package/lib/database/index.d.ts +7 -0
  37. package/lib/database/index.js +23 -0
  38. package/lib/elastic/counter/ingestion.js +1 -0
  39. package/lib/elastic/queries/campaign/getBroadcastDetailedStats.d.ts +117 -0
  40. package/lib/elastic/queries/campaign/getBroadcastDetailedStats.js +94 -1
  41. package/lib/elastic/queries/campaign/getUniqueCustomerCnt.d.ts +1 -0
  42. package/lib/elastic/queries/campaign/getUniqueCustomerCnt.js +1 -0
  43. package/lib/elastic/queries/chatbot/getAIVoiceAgentCallLogs.js +4 -0
  44. package/lib/elastic/queries/chatbot/getAgentCostForBroadcast.d.ts +117 -0
  45. package/lib/elastic/queries/chatbot/getAgentCostForBroadcast.js +98 -0
  46. package/lib/elastic/queries/chatbot/getAiOperations.d.ts +5 -5
  47. package/lib/elastic/queries/chatbot/getAiOperations.js +3 -3
  48. package/lib/elastic/queries/chatbot/index.d.ts +1 -0
  49. package/lib/elastic/queries/chatbot/index.js +1 -0
  50. package/lib/elastic/queries/crm/getActivityTimelineByAgent.js +1 -1
  51. package/lib/elastic/queries/crm/getBreachedSLACount.d.ts +1 -0
  52. package/lib/elastic/queries/crm/getBreachedSLACount.js +8 -5
  53. package/lib/elastic/queries/crm/getFirstResponseTime.d.ts +1 -0
  54. package/lib/elastic/queries/crm/getFirstResponseTime.js +8 -5
  55. package/lib/elastic/queries/integrations/getOrdersShadowServices.d.ts +76 -0
  56. package/lib/elastic/queries/integrations/getOrdersShadowServices.js +61 -0
  57. package/lib/elastic/queries/integrations/index.d.ts +1 -0
  58. package/lib/elastic/queries/integrations/index.js +1 -0
  59. package/lib/elastic/queries/openAi/addToCartSession.d.ts +1 -0
  60. package/lib/elastic/queries/openAi/addToCartSession.js +11 -3
  61. package/lib/elastic/queries/openAi/checkoutCompletedSession.d.ts +1 -0
  62. package/lib/elastic/queries/openAi/checkoutCompletedSession.js +11 -3
  63. package/lib/elastic/reports/crm/index.d.ts +1 -0
  64. package/lib/elastic/reports/crm/index.js +1 -0
  65. package/lib/elastic/reports/reports.service.js +17 -8
  66. package/lib/events/events.d.ts +8 -0
  67. package/lib/events/events.js +25 -1
  68. package/lib/events/schema/events.helper.d.ts +1 -0
  69. package/lib/events/schema/events.helper.js +12 -6
  70. package/lib/index.d.ts +1 -0
  71. package/lib/index.js +1 -0
  72. package/lib/merchant-events/elastic.search.d.ts +5 -0
  73. package/lib/merchant-events/elastic.search.js +23 -2
  74. package/lib/merchant-events/merchant.service.d.ts +1 -1
  75. package/lib/merchant-events/merchant.service.js +12 -11
  76. package/lib/recordAnalytics/recordAnalytics.service.js +5 -4
  77. package/lib/redis/redisPubSubService.d.ts +4 -6
  78. package/lib/redis/redisPubSubService.js +211 -123
  79. package/lib/redis/redisService.js +14 -8
  80. package/lib/swagger/SwaggerSchemaHelper.js +21 -17
  81. package/lib/user-properties/userProperties.service.js +1 -0
  82. package/package.json +2 -2
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FirestoreConfigManager = void 0;
13
+ const config_1 = require("../config");
14
+ class FirestoreConfigManager {
15
+ constructor() {
16
+ this.secretsCollection = 'secrets';
17
+ this.envDocPrefix = 'bik-platform-secrets-';
18
+ this.globalSecretsDocId = 'bik-platform-secrets-globalsecrets';
19
+ const app = (0, config_1.getSecondaryApp)();
20
+ this.db = app.firestore();
21
+ }
22
+ static getInstance() {
23
+ if (!FirestoreConfigManager.instance) {
24
+ FirestoreConfigManager.instance = new FirestoreConfigManager();
25
+ }
26
+ return FirestoreConfigManager.instance;
27
+ }
28
+ getDocId(section, podName) {
29
+ if (section === 'secrets') {
30
+ return this.globalSecretsDocId;
31
+ }
32
+ return `${this.envDocPrefix}${podName}`;
33
+ }
34
+ isDocFromSection(section, docId) {
35
+ if (section === 'secrets') {
36
+ return docId === this.globalSecretsDocId;
37
+ }
38
+ return docId.startsWith(this.envDocPrefix) && docId !== this.globalSecretsDocId;
39
+ }
40
+ getPodNameFromDocId(section, docId) {
41
+ if (!this.isDocFromSection(section, docId)) {
42
+ return undefined;
43
+ }
44
+ if (section === 'secrets') {
45
+ return 'global';
46
+ }
47
+ const podName = docId.replace(this.envDocPrefix, '');
48
+ if (!podName) {
49
+ return undefined;
50
+ }
51
+ return podName;
52
+ }
53
+ toEmptySchema(schema) {
54
+ if (!schema || typeof schema !== 'object') {
55
+ return { generic: {} };
56
+ }
57
+ const normalized = { generic: {} };
58
+ Object.keys(schema).forEach((serviceName) => {
59
+ const category = schema[serviceName];
60
+ normalized[serviceName] = category && typeof category === 'object' ? Object.assign({}, category) : {};
61
+ });
62
+ if (!normalized.generic) {
63
+ normalized.generic = {};
64
+ }
65
+ return normalized;
66
+ }
67
+ getConfig(section, podName) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ try {
70
+ const id = this.getDocId(section, podName);
71
+ const docRef = this.db.collection(this.secretsCollection).doc(id);
72
+ const docSnap = yield docRef.get();
73
+ const docData = docSnap.data();
74
+ return {
75
+ id,
76
+ section,
77
+ podName,
78
+ schema: this.toEmptySchema(docData === null || docData === void 0 ? void 0 : docData.schema),
79
+ updatedAtMills: (docData === null || docData === void 0 ? void 0 : docData.updatedAtMills) || Date.now(),
80
+ updatedBy: (docData === null || docData === void 0 ? void 0 : docData.updatedBy) || 'NA',
81
+ };
82
+ }
83
+ catch (error) {
84
+ throw new Error(`Failed to retrieve config: ${error}`);
85
+ }
86
+ });
87
+ }
88
+ storeConfig(section, podName, schema, updatedBy = 'NA') {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ try {
91
+ const id = this.getDocId(section, podName);
92
+ const configDoc = {
93
+ id,
94
+ section,
95
+ podName,
96
+ schema: this.toEmptySchema(schema),
97
+ updatedAtMills: Date.now(),
98
+ updatedBy,
99
+ };
100
+ const docRef = this.db.collection(this.secretsCollection).doc(id);
101
+ yield docRef.set(configDoc);
102
+ }
103
+ catch (error) {
104
+ throw new Error(`Failed to store config: ${error}`);
105
+ }
106
+ });
107
+ }
108
+ getAll(section) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ try {
111
+ const snapshot = yield this.db.collection(this.secretsCollection).get();
112
+ const configs = {};
113
+ snapshot.forEach((doc) => {
114
+ if (!this.isDocFromSection(section, doc.id)) {
115
+ return;
116
+ }
117
+ const docData = doc.data();
118
+ const podName = docData.podName || this.getPodNameFromDocId(section, doc.id);
119
+ if (!podName) {
120
+ return;
121
+ }
122
+ if (section === 'secrets' && podName !== 'global') {
123
+ return;
124
+ }
125
+ configs[podName] = this.toEmptySchema(docData.schema);
126
+ });
127
+ return configs;
128
+ }
129
+ catch (error) {
130
+ throw new Error(`Failed to retrieve all configs for section ${section}: ${error}`);
131
+ }
132
+ });
133
+ }
134
+ getAllConfigs() {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ try {
137
+ const snapshot = yield this.db.collection(this.secretsCollection).get();
138
+ const envVariables = {};
139
+ const secrets = {};
140
+ snapshot.forEach((doc) => {
141
+ if (doc.id.startsWith(this.envDocPrefix) && doc.id !== this.globalSecretsDocId) {
142
+ const docData = doc.data();
143
+ const podName = docData.podName || this.getPodNameFromDocId('envVariables', doc.id);
144
+ if (!podName) {
145
+ return;
146
+ }
147
+ envVariables[podName] = this.toEmptySchema(docData.schema);
148
+ return;
149
+ }
150
+ if (doc.id === this.globalSecretsDocId) {
151
+ const docData = doc.data();
152
+ secrets.global = this.toEmptySchema(docData.schema);
153
+ }
154
+ });
155
+ return {
156
+ envVariables,
157
+ secrets,
158
+ };
159
+ }
160
+ catch (error) {
161
+ throw new Error(`Failed to retrieve all configs: ${error}`);
162
+ }
163
+ });
164
+ }
165
+ }
166
+ exports.FirestoreConfigManager = FirestoreConfigManager;
@@ -0,0 +1,13 @@
1
+ import { ResolvedFunctionResponse } from '../../apis';
2
+ import { ConfigManagerService } from './configManager.service';
3
+ import { CheckConflictsResponse, GetConfigRequest, PodConfigData, StoreConfigRequest, UnifiedConfigsData } from './configManager.model';
4
+ export declare class ConfigManagerHelper {
5
+ private service;
6
+ constructor(service?: ConfigManagerService);
7
+ getAllConfigs(): ResolvedFunctionResponse<UnifiedConfigsData>;
8
+ getConfig(request: GetConfigRequest): ResolvedFunctionResponse<PodConfigData>;
9
+ storeConfig(request: StoreConfigRequest): ResolvedFunctionResponse<{
10
+ success: boolean;
11
+ }>;
12
+ checkConflicts(request: StoreConfigRequest): ResolvedFunctionResponse<CheckConflictsResponse>;
13
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigManagerHelper = void 0;
4
+ const apis_1 = require("../../apis");
5
+ const configManager_service_1 = require("./configManager.service");
6
+ class ConfigManagerHelper {
7
+ constructor(service = new configManager_service_1.ConfigManagerService()) {
8
+ this.service = service;
9
+ }
10
+ getAllConfigs() {
11
+ return this.service.getAllConfigs();
12
+ }
13
+ getConfig(request) {
14
+ if (!(request === null || request === void 0 ? void 0 : request.podName)) {
15
+ return Promise.resolve(apis_1.FunctionResponseHelper.failed(apis_1.ErrorCodes.VALIDATION_FAILED, 'podName is required', 'podName is required'));
16
+ }
17
+ return this.service.getConfig(request);
18
+ }
19
+ storeConfig(request) {
20
+ if (!(request === null || request === void 0 ? void 0 : request.section) || !(request === null || request === void 0 ? void 0 : request.podName) || !(request === null || request === void 0 ? void 0 : request.schema)) {
21
+ return Promise.resolve(apis_1.FunctionResponseHelper.failed(apis_1.ErrorCodes.VALIDATION_FAILED, 'section, podName and schema are required', 'section, podName and schema are required'));
22
+ }
23
+ return this.service.storeConfig(request);
24
+ }
25
+ checkConflicts(request) {
26
+ if (!(request === null || request === void 0 ? void 0 : request.section) || !(request === null || request === void 0 ? void 0 : request.podName) || !(request === null || request === void 0 ? void 0 : request.schema)) {
27
+ return Promise.resolve(apis_1.FunctionResponseHelper.failed(apis_1.ErrorCodes.VALIDATION_FAILED, 'section, podName and schema are required', 'section, podName and schema are required'));
28
+ }
29
+ return this.service.checkConflicts(request);
30
+ }
31
+ }
32
+ exports.ConfigManagerHelper = ConfigManagerHelper;
@@ -0,0 +1,38 @@
1
+ import { PodNameOrGlobal, SecretSchema } from './secretManager.model';
2
+ export type ConfigSection = 'envVariables' | 'secrets';
3
+ export interface StoreConfigRequest {
4
+ section: ConfigSection;
5
+ podName: PodNameOrGlobal;
6
+ schema: SecretSchema;
7
+ }
8
+ export interface GetConfigRequest {
9
+ podName: PodNameOrGlobal;
10
+ }
11
+ export interface UnifiedConfigsData {
12
+ envVariables: Record<string, SecretSchema>;
13
+ secrets: Record<string, SecretSchema>;
14
+ }
15
+ export interface PodConfigData {
16
+ podName: PodNameOrGlobal;
17
+ envVariables: SecretSchema;
18
+ secrets: Record<'global', SecretSchema>;
19
+ }
20
+ export interface ConflictItem {
21
+ serviceName: string;
22
+ keyName: string;
23
+ existingPods: string[];
24
+ currentValue: string;
25
+ existingValues: Record<string, string>;
26
+ }
27
+ export interface CheckConflictsResponse {
28
+ hasConflicts: boolean;
29
+ conflicts: ConflictItem[];
30
+ }
31
+ export interface ConfigDocument {
32
+ id: string;
33
+ section: ConfigSection;
34
+ podName: PodNameOrGlobal;
35
+ schema: SecretSchema;
36
+ updatedAtMills: number;
37
+ updatedBy: string;
38
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ import { ResolvedFunctionResponse } from '../../apis';
2
+ import { FirestoreConfigManager } from './configManager.firestore';
3
+ import { CheckConflictsResponse, GetConfigRequest, StoreConfigRequest, UnifiedConfigsData, PodConfigData } from './configManager.model';
4
+ export declare class ConfigManagerService {
5
+ private configStore;
6
+ constructor(configStore?: FirestoreConfigManager);
7
+ private normalizeSchema;
8
+ private validateSectionAndPod;
9
+ getAllConfigs(): ResolvedFunctionResponse<UnifiedConfigsData>;
10
+ getConfig({ podName }: GetConfigRequest): ResolvedFunctionResponse<PodConfigData>;
11
+ storeConfig(request: StoreConfigRequest): ResolvedFunctionResponse<{
12
+ success: boolean;
13
+ }>;
14
+ private getExistingPodsAndValues;
15
+ checkConflicts(request: StoreConfigRequest): ResolvedFunctionResponse<CheckConflictsResponse>;
16
+ static getInvalidSecretsPodMessage(): string;
17
+ }
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ConfigManagerService = void 0;
13
+ const apis_1 = require("../../apis");
14
+ const configManager_firestore_1 = require("./configManager.firestore");
15
+ const INVALID_SECRETS_POD_ERROR = 'Secrets are supported only for podName=global';
16
+ class ConfigManagerService {
17
+ constructor(configStore = configManager_firestore_1.FirestoreConfigManager.getInstance()) {
18
+ this.configStore = configStore;
19
+ }
20
+ normalizeSchema(schema) {
21
+ if (!schema || typeof schema !== 'object') {
22
+ return { generic: {} };
23
+ }
24
+ const normalized = { generic: {} };
25
+ Object.keys(schema).forEach((serviceName) => {
26
+ const category = schema[serviceName];
27
+ normalized[serviceName] = category && typeof category === 'object' ? Object.assign({}, category) : {};
28
+ });
29
+ if (!normalized.generic) {
30
+ normalized.generic = {};
31
+ }
32
+ return normalized;
33
+ }
34
+ validateSectionAndPod(section, podName) {
35
+ if (section === 'secrets' && podName !== 'global') {
36
+ return INVALID_SECRETS_POD_ERROR;
37
+ }
38
+ return null;
39
+ }
40
+ getAllConfigs() {
41
+ var _a;
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const allConfigs = yield this.configStore.getAllConfigs();
44
+ const envVariables = {};
45
+ Object.keys(allConfigs.envVariables || {}).forEach((podName) => {
46
+ envVariables[podName] = this.normalizeSchema(allConfigs.envVariables[podName]);
47
+ });
48
+ const secrets = {};
49
+ if ((_a = allConfigs.secrets) === null || _a === void 0 ? void 0 : _a.global) {
50
+ secrets.global = this.normalizeSchema(allConfigs.secrets.global);
51
+ }
52
+ return apis_1.FunctionResponseHelper.success({
53
+ envVariables,
54
+ secrets,
55
+ });
56
+ });
57
+ }
58
+ getConfig({ podName }) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const [envConfig, globalSecretConfig] = yield Promise.all([
61
+ this.configStore.getConfig('envVariables', podName),
62
+ this.configStore.getConfig('secrets', 'global'),
63
+ ]);
64
+ return apis_1.FunctionResponseHelper.success({
65
+ podName,
66
+ envVariables: this.normalizeSchema(envConfig.schema),
67
+ secrets: {
68
+ global: this.normalizeSchema(globalSecretConfig.schema),
69
+ },
70
+ });
71
+ });
72
+ }
73
+ storeConfig(request) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const validationError = this.validateSectionAndPod(request.section, request.podName);
76
+ if (validationError) {
77
+ return apis_1.FunctionResponseHelper.failed(apis_1.ErrorCodes.VALIDATION_FAILED, validationError, validationError);
78
+ }
79
+ yield this.configStore.storeConfig(request.section, request.podName, this.normalizeSchema(request.schema));
80
+ return apis_1.FunctionResponseHelper.success({ success: true });
81
+ });
82
+ }
83
+ getExistingPodsAndValues(section, podName, allConfigs, serviceName, keyName) {
84
+ const existingValues = {};
85
+ Object.keys(allConfigs).forEach((existingPodName) => {
86
+ var _a, _b;
87
+ if (section === 'envVariables' && existingPodName === podName) {
88
+ return;
89
+ }
90
+ const existingValue = (_b = (_a = allConfigs[existingPodName]) === null || _a === void 0 ? void 0 : _a[serviceName]) === null || _b === void 0 ? void 0 : _b[keyName];
91
+ if (typeof existingValue === 'string') {
92
+ existingValues[existingPodName] = existingValue;
93
+ }
94
+ });
95
+ return existingValues;
96
+ }
97
+ checkConflicts(request) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ const validationError = this.validateSectionAndPod(request.section, request.podName);
100
+ if (validationError) {
101
+ return apis_1.FunctionResponseHelper.failed(apis_1.ErrorCodes.VALIDATION_FAILED, validationError, validationError);
102
+ }
103
+ const normalizedSchema = this.normalizeSchema(request.schema);
104
+ const allConfigs = yield this.configStore.getAll(request.section);
105
+ const conflicts = [];
106
+ Object.keys(normalizedSchema).forEach((serviceName) => {
107
+ const keys = normalizedSchema[serviceName] || {};
108
+ Object.keys(keys).forEach((keyName) => {
109
+ const currentValue = keys[keyName] || '';
110
+ const existingValues = this.getExistingPodsAndValues(request.section, request.podName, allConfigs, serviceName, keyName);
111
+ const existingPods = Object.keys(existingValues);
112
+ if (existingPods.length === 0) {
113
+ return;
114
+ }
115
+ const hasDifferentValue = existingPods.some((pod) => existingValues[pod] !== currentValue);
116
+ if (!hasDifferentValue) {
117
+ return;
118
+ }
119
+ conflicts.push({
120
+ serviceName,
121
+ keyName,
122
+ existingPods,
123
+ currentValue,
124
+ existingValues,
125
+ });
126
+ });
127
+ });
128
+ return apis_1.FunctionResponseHelper.success({
129
+ hasConflicts: conflicts.length > 0,
130
+ conflicts,
131
+ });
132
+ });
133
+ }
134
+ static getInvalidSecretsPodMessage() {
135
+ return INVALID_SECRETS_POD_ERROR;
136
+ }
137
+ }
138
+ exports.ConfigManagerService = ConfigManagerService;
@@ -64,6 +64,7 @@ export declare const ShopifyKeys: {
64
64
  };
65
65
  export declare const PgSQLKeys: {
66
66
  readonly SECRET_NAME: "SECRET_NAME";
67
+ readonly SECRET_NAME_SMTP: "SECRET_NAME_SMTP";
67
68
  };
68
69
  export declare const ApiKeys: {
69
70
  readonly API_KEY: "API_KEY";
@@ -74,6 +75,7 @@ export declare const GenericKeys: {
74
75
  readonly NODE_ENV: "NODE_ENV";
75
76
  readonly USE_CLOUD_REDIS: "USE_CLOUD_REDIS";
76
77
  readonly ENVIRONMENT: "ENVIRONMENT";
78
+ readonly ENVIRONMENT_SMTP: "ENVIRONMENT_SMTP";
77
79
  readonly USE_PRIVATE_NETWORK: "USE_PRIVATE_NETWORK";
78
80
  readonly PORT: "PORT";
79
81
  readonly SERVICE_NAME: "SERVICE_NAME";
@@ -107,6 +109,7 @@ export declare const SlackKeys: {
107
109
  readonly SLACK_ALERT_CHANNEL: "SLACK_ALERT_CHANNEL";
108
110
  readonly SLACK_LOG_LEVEL: "SLACK_LOG_LEVEL";
109
111
  readonly SLACK_TOKEN: "slack_token";
112
+ readonly SLACK_SECRET: "slack_secret";
110
113
  };
111
114
  export declare const MiraimindsKeys: {
112
115
  readonly PUBLIC_KEY: "PUBLIC_KEY";
@@ -67,6 +67,7 @@ exports.ShopifyKeys = {
67
67
  };
68
68
  exports.PgSQLKeys = {
69
69
  SECRET_NAME: 'SECRET_NAME',
70
+ SECRET_NAME_SMTP: 'SECRET_NAME_SMTP',
70
71
  };
71
72
  exports.ApiKeys = {
72
73
  API_KEY: 'API_KEY',
@@ -77,6 +78,7 @@ exports.GenericKeys = {
77
78
  NODE_ENV: 'NODE_ENV',
78
79
  USE_CLOUD_REDIS: 'USE_CLOUD_REDIS',
79
80
  ENVIRONMENT: 'ENVIRONMENT',
81
+ ENVIRONMENT_SMTP: 'ENVIRONMENT_SMTP',
80
82
  USE_PRIVATE_NETWORK: 'USE_PRIVATE_NETWORK',
81
83
  PORT: 'PORT',
82
84
  SERVICE_NAME: 'SERVICE_NAME',
@@ -110,6 +112,7 @@ exports.SlackKeys = {
110
112
  SLACK_ALERT_CHANNEL: 'SLACK_ALERT_CHANNEL',
111
113
  SLACK_LOG_LEVEL: 'SLACK_LOG_LEVEL',
112
114
  SLACK_TOKEN: 'slack_token',
115
+ SLACK_SECRET: 'slack_secret',
113
116
  };
114
117
  exports.MiraimindsKeys = {
115
118
  PUBLIC_KEY: 'PUBLIC_KEY',
@@ -61,12 +61,10 @@ class ChatHandoverProtocol {
61
61
  if (assetId) {
62
62
  whatsAppPhoneNumberId = `${whatsAppPhoneNumberId}|${assetId}`;
63
63
  }
64
- else {
65
- // TODO: log error here
66
- }
67
64
  uniqueId.push(whatsAppPhoneNumberId);
68
65
  }
69
- return uniqueId.filter((e) => !!e).join('#');
66
+ const finalChatId = uniqueId.filter((e) => !!e).join('#');
67
+ return finalChatId;
70
68
  });
71
69
  }
72
70
  static getAssetId(payload) {
@@ -103,9 +101,7 @@ class ChatHandoverProtocol {
103
101
  const redisService = redis_1.RedisAppService.getInstance();
104
102
  assignmentInfo = JSON.parse((yield redisService.retrieveData(chatId)) || '{}');
105
103
  }
106
- catch (err) {
107
- console.error('REDIS CONNECTION ERROR', JSON.stringify(err));
108
- }
104
+ catch (err) { }
109
105
  return assignmentInfo;
110
106
  });
111
107
  }
@@ -117,9 +113,7 @@ class ChatHandoverProtocol {
117
113
  const response = yield redisService.cacheData(chatId, data, TTL);
118
114
  return response === null || response === void 0 ? void 0 : response.success;
119
115
  }
120
- catch (err) {
121
- console.error('REDIS CONNECTION ERROR', JSON.stringify(err));
122
- }
116
+ catch (err) { }
123
117
  });
124
118
  }
125
119
  static removeRedisInfo(chatId) {
@@ -128,14 +122,12 @@ class ChatHandoverProtocol {
128
122
  const redisService = redis_1.RedisAppService.getInstance();
129
123
  yield redisService.deleteCache(chatId);
130
124
  }
131
- catch (err) {
132
- console.error('Error in remove cache', JSON.stringify(err));
133
- }
125
+ catch (err) { }
134
126
  });
135
127
  }
136
128
  static checkForAgentAssignment(payload, message, call, uniqueId // for forwarding email in same thread, we use this to ensure a new ticket isn't created
137
129
  ) {
138
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
130
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
139
131
  return __awaiter(this, void 0, void 0, function* () {
140
132
  const { messageObj, commentObj, callObj } = payload;
141
133
  const channelName = messageObj
@@ -146,6 +138,7 @@ class ChatHandoverProtocol {
146
138
  ? callObj === null || callObj === void 0 ? void 0 : callObj.channel_id
147
139
  : models_1.CHANNELS.WHATSAPP;
148
140
  const isCommentFlow = !!payload.commentObj;
141
+ const isCallFlow = !!payload.callObj;
149
142
  const isMessengerPostback = !!((_b = (_a = payload === null || payload === void 0 ? void 0 : payload.messageObj) === null || _a === void 0 ? void 0 : _a.buttons) === null || _b === void 0 ? void 0 : _b.includes('"id"'));
150
143
  const isBotMessage = (messageObj === null || messageObj === void 0 ? void 0 : messageObj.owner) === models_1.Owner.BOT;
151
144
  const chatId = uniqueId !== null && uniqueId !== void 0 ? uniqueId : (yield ChatHandoverProtocol.getChatId(payload));
@@ -162,7 +155,7 @@ class ChatHandoverProtocol {
162
155
  (message && message.type === whatsapp_model_1.MultiMediaTypes.Order) ||
163
156
  ((_c = commentObj === null || commentObj === void 0 ? void 0 : commentObj.extras) === null || _c === void 0 ? void 0 : _c.isUnsupportedMessage);
164
157
  // call for every chatbot ticket message, except first one
165
- console.debug('--chatbot ticket update payload--', {
158
+ ChatHandoverProtocol.updateTicketForChatbotMessage({
166
159
  storeId: payload.storeId,
167
160
  uniqueId: chatId,
168
161
  senderId: ((_d = payload.messageObj) === null || _d === void 0 ? void 0 : _d.sender_id) || ((_e = payload.commentObj) === null || _e === void 0 ? void 0 : _e.senderId),
@@ -173,18 +166,6 @@ class ChatHandoverProtocol {
173
166
  contentType: payload.messageObj ? models_1.ChatContentTypeI.MESSAGE : models_1.ChatContentTypeI.COMMENT,
174
167
  commentId: (_m = payload.commentObj) === null || _m === void 0 ? void 0 : _m.commentId,
175
168
  isMediaMessage,
176
- });
177
- ChatHandoverProtocol.updateTicketForChatbotMessage({
178
- storeId: payload.storeId,
179
- uniqueId: chatId,
180
- senderId: ((_o = payload.messageObj) === null || _o === void 0 ? void 0 : _o.sender_id) || ((_p = payload.commentObj) === null || _p === void 0 ? void 0 : _p.senderId),
181
- conversationStartTime: (_q = payload.messageObj) === null || _q === void 0 ? void 0 : _q.sent_at,
182
- message: ((_r = payload.messageObj) === null || _r === void 0 ? void 0 : _r.message) || ((_s = payload.commentObj) === null || _s === void 0 ? void 0 : _s.message) || '',
183
- messageId: (_t = payload.messageObj) === null || _t === void 0 ? void 0 : _t.message_id,
184
- messageTimeStamp: ((_u = payload.messageObj) === null || _u === void 0 ? void 0 : _u.sent_at) || ((_v = payload.commentObj) === null || _v === void 0 ? void 0 : _v.createdAt),
185
- contentType: payload.messageObj ? models_1.ChatContentTypeI.MESSAGE : models_1.ChatContentTypeI.COMMENT,
186
- commentId: (_w = payload.commentObj) === null || _w === void 0 ? void 0 : _w.commentId,
187
- isMediaMessage,
188
169
  })
189
170
  .then()
190
171
  .catch((error) => {
@@ -194,34 +175,35 @@ class ChatHandoverProtocol {
194
175
  const messageOrCall = message || call;
195
176
  // ticket is with crm (agent may or may not be assigned)
196
177
  if (assignmentInfo.customerId) {
197
- console.debug('Agent is assigned, forward to : ', messageOrCall ? ChatHandoverProtocol.podsToFowardWebhook(messageOrCall, payload, true) : []);
178
+ const pods = messageOrCall
179
+ ? ChatHandoverProtocol.podsToFowardWebhook(messageOrCall, payload, true)
180
+ : [];
198
181
  return Promise.resolve({
199
182
  isAgentAssigned: true,
200
183
  chatId,
201
184
  assignmentInfo,
202
185
  eligibleForAgentAssignment: false,
203
186
  ticketId: assignmentInfo.sessionId,
204
- pods: messageOrCall
205
- ? ChatHandoverProtocol.podsToFowardWebhook(messageOrCall, payload, true)
206
- : [],
187
+ pods,
207
188
  });
208
189
  }
209
- console.debug('Agent is not assigned, forward to : ', messageOrCall ? ChatHandoverProtocol.podsToFowardWebhook(messageOrCall, payload, false) : []);
190
+ const pods = messageOrCall
191
+ ? ChatHandoverProtocol.podsToFowardWebhook(messageOrCall, payload, false)
192
+ : [];
210
193
  let eligibleForAgentAssignment = false;
211
194
  // fb dm
212
195
  if (!isMessengerPostback && channelName === models_1.CHANNELS.MESSENGER && !isCommentFlow) {
213
196
  eligibleForAgentAssignment = true;
214
197
  }
215
- return {
198
+ const result = {
216
199
  chatId,
217
200
  isAgentAssigned: false,
218
201
  assignmentInfo,
219
202
  eligibleForAgentAssignment,
220
203
  ticketId: assignmentInfo === null || assignmentInfo === void 0 ? void 0 : assignmentInfo.sessionId,
221
- pods: messageOrCall
222
- ? ChatHandoverProtocol.podsToFowardWebhook(messageOrCall, payload, false)
223
- : [],
204
+ pods,
224
205
  };
206
+ return result;
225
207
  });
226
208
  }
227
209
  static podsToFowardWebhook(messageOrCall, payload, isAgentAssigned) {
@@ -234,7 +216,6 @@ class ChatHandoverProtocol {
234
216
  : commentObj === null || commentObj === void 0 ? void 0 : commentObj.channel;
235
217
  if (((messageObj === null || messageObj === void 0 ? void 0 : messageObj.owner) && [models_1.Owner.AGENT, models_1.Owner.BOT].includes(messageObj === null || messageObj === void 0 ? void 0 : messageObj.owner)) ||
236
218
  ((commentObj === null || commentObj === void 0 ? void 0 : commentObj.owner) && [models_1.Owner.AGENT, models_1.Owner.BOT].includes(commentObj === null || commentObj === void 0 ? void 0 : commentObj.owner))) {
237
- //early return for BICs
238
219
  return [];
239
220
  }
240
221
  // if its manifest, always return CRM
@@ -328,7 +309,8 @@ class ChatHandoverProtocol {
328
309
  }
329
310
  }
330
311
  // convert pods set to an array and return
331
- return Array.from(pods);
312
+ const finalPods = Array.from(pods);
313
+ return finalPods;
332
314
  }
333
315
  static getCrmDecoupledStoreConfigFromFS() {
334
316
  return __awaiter(this, void 0, void 0, function* () {
@@ -340,7 +322,8 @@ class ChatHandoverProtocol {
340
322
  isInternal: true,
341
323
  };
342
324
  const response = yield executor_1.RequestExecutor.executeHttpAPIRequest(updateDetailsRequest);
343
- return yield response.json();
325
+ const result = yield response.json();
326
+ return result;
344
327
  });
345
328
  }
346
329
  static updateTicketForChatbotMessage(payload) {
@@ -399,11 +382,13 @@ class ChatHandoverProtocol {
399
382
  }
400
383
  exports.ChatHandoverProtocol = ChatHandoverProtocol;
401
384
  ChatHandoverProtocol.checkIfQRBReplyIsFromFlow = (payload) => {
402
- if (typeof payload !== 'string')
385
+ if (typeof payload !== 'string') {
403
386
  return false; // Check if it's a string
387
+ }
404
388
  try {
405
389
  const parsed = JSON.parse(payload);
406
- return parsed && typeof parsed === 'object' && 'f' in parsed; // Check if `f` exists
390
+ const isFromFlow = parsed && typeof parsed === 'object' && 'f' in parsed;
391
+ return isFromFlow; // Check if `f` exists
407
392
  }
408
393
  catch (e) {
409
394
  return false; // If parsing fails, it's not a stringified object
@@ -0,0 +1 @@
1
+ export {};