@platform-x/hep-notification-client 1.2.9 → 1.3.1

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.
@@ -0,0 +1,7 @@
1
+ export declare class SecretKeyServices {
2
+ private ruleCache;
3
+ /**
4
+ * Fetches all the secret keys
5
+ */
6
+ getSecretKeys(): Promise<any>;
7
+ }
@@ -1,38 +1,58 @@
1
1
  "use strict";
2
- // import { secretManager } from 'hep-secret-access';
3
- // import config from '../../config';
4
- // import { DynamicValues } from '../../platform-x/constants';
5
- // export class SecretKeyServices {
6
- // private ruleCache = new Map<string, any | null>();
7
- // /**
8
- // * Fetches all the secret keys
9
- // */
10
- // public async getSecretKeys() {
11
- // try {
12
- // // Initialize secret manager object
13
- // if (this.ruleCache.has('secret_data')) {
14
- // return this.ruleCache.get('secret_data')!;
15
- // }
16
- // const secretObject = secretManager();
17
- // // If secret mode is ENV – read one by one
18
- // // for local testing
19
- // if (config?.SECRET_MODE === 'env') {
20
- // const keyConfig: Record<any, any> = {};
21
- // for (const key of Object.values(DynamicValues)) {
22
- // // Fetch individual value (existing read() method)
23
- // const value = await secretObject.read(key);
24
- // keyConfig[key] = value;
25
- // }
26
- // this.ruleCache.set('secret_data', keyConfig);
27
- // return keyConfig;
28
- // }
29
- // // else fetch all secrets from GSM
30
- // const data = await secretObject.readAllSecrets();
31
- // this.ruleCache.set('secret_data', data);
32
- // return data;
33
- // } catch (err) {
34
- // return {};
35
- // }
36
- // }
37
- // }
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SecretKeyServices = void 0;
16
+ const hep_secret_access_1 = require("hep-secret-access");
17
+ const config_1 = __importDefault(require("../../config"));
18
+ const constants_1 = require("../../platform-x/constants");
19
+ class SecretKeyServices {
20
+ constructor() {
21
+ this.ruleCache = new Map();
22
+ }
23
+ /**
24
+ * Fetches all the secret keys
25
+ */
26
+ getSecretKeys() {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ try {
29
+ // Initialize secret manager object
30
+ if (this.ruleCache.has('secret_data')) {
31
+ return this.ruleCache.get('secret_data');
32
+ }
33
+ const secretObject = (0, hep_secret_access_1.secretManager)();
34
+ // If secret mode is ENV – read one by one
35
+ // for local testing
36
+ if ((config_1.default === null || config_1.default === void 0 ? void 0 : config_1.default.SECRET_MODE) === 'env') {
37
+ const keyConfig = {};
38
+ for (const key of Object.values(constants_1.DynamicValues)) {
39
+ // Fetch individual value (existing read() method)
40
+ const value = yield secretObject.read(key);
41
+ keyConfig[key] = value;
42
+ }
43
+ this.ruleCache.set('secret_data', keyConfig);
44
+ return keyConfig;
45
+ }
46
+ // else – fetch all secrets from GSM
47
+ const data = yield secretObject.readAllSecrets();
48
+ this.ruleCache.set('secret_data', data);
49
+ return data;
50
+ }
51
+ catch (err) {
52
+ return {};
53
+ }
54
+ });
55
+ }
56
+ }
57
+ exports.SecretKeyServices = SecretKeyServices;
38
58
  //# sourceMappingURL=secretKeyManager.services.js.map
@@ -1,35 +1,47 @@
1
1
  interface SolrQuery {
2
2
  query(query: string | object | null | undefined): any;
3
3
  paginate(start?: number, rows?: number): any;
4
- filterList(fields: any): any;
5
- sort(fields: any): any;
6
- filterQuery(fields: any): any;
4
+ filterList(fields: object | string[] | null | undefined): any;
5
+ sort(fields: object | string[] | null | undefined): any;
6
+ filterQuery(fields: object | string[] | null | undefined): any;
7
+ facet(fields: object | string | null | undefined): any;
7
8
  }
8
9
  export declare class SolrClient {
9
10
  private host;
10
11
  private port;
11
12
  private core;
12
13
  private path;
14
+ private httpClient;
15
+ private queryParams;
13
16
  private secure;
14
- private solrNodeClient;
15
- private solrQuery;
16
17
  constructor(core?: string);
17
18
  getQuery(): any;
18
19
  createQuery(): SolrQuery;
19
20
  executeSearch(): Promise<any>;
20
21
  /**
21
- * solrSearch- fn to call solr search
22
+ * solrSearch - fn to call solr search via Solr 9 HTTP API
22
23
  * @param queryParams
23
24
  * @param fields
24
25
  * @param fieldType
25
26
  * @param sortData
27
+ * @param filterQuery
26
28
  * @returns
27
29
  */
28
- solrSearch(queryParams: any, fields?: any, fieldType?: any, sortData?: any, filterQuery?: any): Promise<unknown>;
30
+ solrSearch(queryParams: any, fields?: any, fieldType?: any, sortData?: any, filterQuery?: any): Promise<any>;
31
+ /**
32
+ * Function to delete document from solr via Solr 9 HTTP API
33
+ * @param query
34
+ * @returns
35
+ */
36
+ deleteByQuery(query: string | object): Promise<boolean>;
37
+ private _executeHttpRequest;
38
+ private _handleSearchError;
39
+ private _checkSolrResponse;
29
40
  private query;
30
41
  private paginate;
31
42
  private filterList;
32
43
  private sort;
44
+ private facet;
33
45
  private filterQuery;
34
46
  }
35
47
  export {};
@@ -17,141 +17,282 @@ const logger_1 = require("./logger");
17
17
  const index_1 = __importDefault(require("../../config/index"));
18
18
  const errorHandler_1 = require("./errorHandler");
19
19
  const constants_1 = require("../../platform-x/constants");
20
- const solr = require('solr-client');
20
+ const axios_1 = __importDefault(require("axios"));
21
+ // Solr constants
22
+ const SOLR_RESPONSE_FORMAT = 'json';
23
+ const SOLR_SELECT_ENDPOINT = '/select';
24
+ const SOLR_UPDATE_ENDPOINT = '/update';
25
+ const SOLR_DEFAULT_QUERY = '*:*';
26
+ const SOLR_QUERY_JOIN_OPERATOR = ' AND ';
27
+ const SOLR_PROTOCOL_HTTPS = 'https';
28
+ const SOLR_PROTOCOL_HTTP = 'http';
29
+ // Error constants
30
+ const SOLR_ERROR_NETWORK = 'Network error';
31
+ const SOLR_ERROR_EXECUTION = 'Solr execution error';
32
+ const SOLR_ERROR_CODE_ETIMEDOUT = 'ETIMEDOUT';
33
+ const SOLR_ERROR_CODE_ECONNRESET = 'ECONNRESET';
34
+ const SOLR_ERROR_CODE_ECONNABORTED = 'ECONNABORTED';
35
+ const SOLR_TIMEOUT_KEYWORD = 'timeout';
36
+ const HTTP_STATUS_OK = 200;
37
+ const HTTP_STATUS_REQUEST_TIMEOUT = 408;
38
+ /**
39
+ * Prepares query value - handles both string and object types
40
+ * @param query - string, object, null, or undefined
41
+ * @returns formatted query string for Solr
42
+ */
43
+ const prepareQuery = (query) => {
44
+ if (!query)
45
+ return SOLR_DEFAULT_QUERY;
46
+ if (typeof query === 'string')
47
+ return query;
48
+ if (typeof query === 'object' && !Array.isArray(query)) {
49
+ return Object.entries(query)
50
+ .map(([field, value]) => {
51
+ if (typeof value === 'string') {
52
+ if (value.includes('"') || value.includes("'") || value.includes('*') || value.includes('(') || value.includes('[')) {
53
+ return `${field}:${value}`;
54
+ }
55
+ return `${field}:"${value}"`;
56
+ }
57
+ return `${field}:${value}`;
58
+ })
59
+ .join(SOLR_QUERY_JOIN_OPERATOR);
60
+ }
61
+ return SOLR_DEFAULT_QUERY;
62
+ };
21
63
  class SolrClient {
22
64
  constructor(core) {
23
- this.host = index_1.default.SOLR.HOST || '';
24
- this.port = Number(index_1.default.SOLR.PORT);
25
- this.path = index_1.default.SOLR.PATH || '/solr';
26
- this.secure = false;
27
- this.core = core || process.env.SOLR_CORE || '';
28
- const options = {
29
- host: this.host,
30
- port: this.port,
65
+ var _a, _b, _c, _d, _e, _f, _g, _h;
66
+ this.host = (_b = (_a = index_1.default === null || index_1.default === void 0 ? void 0 : index_1.default.SOLR) === null || _a === void 0 ? void 0 : _a.HOST) !== null && _b !== void 0 ? _b : '';
67
+ this.port = Number((_c = index_1.default === null || index_1.default === void 0 ? void 0 : index_1.default.SOLR) === null || _c === void 0 ? void 0 : _c.PORT);
68
+ this.path = (_e = (_d = index_1.default === null || index_1.default === void 0 ? void 0 : index_1.default.SOLR) === null || _d === void 0 ? void 0 : _d.PATH) !== null && _e !== void 0 ? _e : '/solr';
69
+ this.secure = (_f = index_1.default === null || index_1.default === void 0 ? void 0 : index_1.default.SOLR) === null || _f === void 0 ? void 0 : _f.SECURE;
70
+ this.core = (_h = core !== null && core !== void 0 ? core : (_g = process.env) === null || _g === void 0 ? void 0 : _g.SOLR_CORE) !== null && _h !== void 0 ? _h : '';
71
+ const protocol = this.secure ? SOLR_PROTOCOL_HTTPS : SOLR_PROTOCOL_HTTP;
72
+ const baseURL = `${protocol}://${this.host}:${this.port}${this.path}`;
73
+ this.httpClient = axios_1.default.create({
74
+ baseURL,
75
+ headers: {
76
+ 'Content-Type': constants_1.HTTP_CONTENT_TYPE_JSON,
77
+ 'Accept': constants_1.HTTP_CONTENT_TYPE_JSON,
78
+ },
79
+ });
80
+ this.queryParams = { wt: SOLR_RESPONSE_FORMAT };
81
+ logger_1.Logger.info('SolrClient initialized for Solr 9', 'SolrClient');
82
+ logger_1.Logger.debug('SolrClient initialization payload', 'SolrClient', {
83
+ baseURL,
31
84
  core: this.core,
32
- path: this.path,
33
- secure: this.secure,
34
- };
35
- this.solrNodeClient = solr.createClient(options);
36
- this.solrQuery = null;
85
+ });
37
86
  }
38
87
  getQuery() {
39
- return this.solrQuery;
88
+ return this.queryParams;
40
89
  }
41
90
  createQuery() {
42
- this.solrQuery = this.solrNodeClient.createQuery();
91
+ this.queryParams = {
92
+ wt: SOLR_RESPONSE_FORMAT,
93
+ start: 0,
94
+ rows: constants_1.DEFAULT_SOLR_ROWS,
95
+ };
43
96
  return {
44
97
  query: this.query.bind(this),
45
98
  filterQuery: this.filterQuery.bind(this),
46
99
  sort: this.sort.bind(this),
47
100
  filterList: this.filterList.bind(this),
48
101
  paginate: this.paginate.bind(this),
102
+ facet: this.facet.bind(this),
49
103
  };
50
104
  }
51
105
  executeSearch() {
52
- logger_1.Logger.info('SOLR ExecuteSearch Reached', 'executeSearch');
53
- const q = this.solrQuery;
54
- logger_1.Logger.debug('Before calling search method', 'executeSearch', q);
55
- //try {
56
- return new Promise((resolve, reject) => {
57
- this.solrNodeClient.search(q, function (err, res) {
58
- if (err) {
59
- logger_1.Logger.error(`Error in Solr Search for query:--------------------->`, 'executeSearch', err);
60
- let solrError = new errorHandler_1.SolrError(err.message || err.name, Number(err.statusCode));
61
- logger_1.Logger.error('Error in Solr Search for query: ${q}', 'solrSearch', err);
62
- reject(solrError);
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
108
+ var _a, _b, _c, _d, _e;
109
+ try {
110
+ const response = yield this._executeHttpRequest('executeSearch');
111
+ const responseData = (_e = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.grouped) !== null && _b !== void 0 ? _b : (_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.docs) !== null && _e !== void 0 ? _e : [];
112
+ resolve(responseData);
63
113
  }
64
- else {
65
- logger_1.Logger.debug('Before returning search result', 'executeSearch', res);
66
- resolve(res.response.docs);
114
+ catch (error) {
115
+ reject(this._handleSearchError(error, 'executeSearch'));
67
116
  }
68
- });
117
+ }));
69
118
  });
70
- // } catch (err: any) {
71
- // Logger.info(`SOLR EXECUTION ERRROR------${err}`);
72
- // throw err;
73
- // }
74
119
  }
75
120
  /**
76
- * solrSearch- fn to call solr search
121
+ * solrSearch - fn to call solr search via Solr 9 HTTP API
77
122
  * @param queryParams
78
123
  * @param fields
79
124
  * @param fieldType
80
125
  * @param sortData
126
+ * @param filterQuery
81
127
  * @returns
82
128
  */
83
129
  solrSearch(queryParams, fields, fieldType, sortData, filterQuery) {
84
130
  return __awaiter(this, void 0, void 0, function* () {
85
- logger_1.Logger.debug('Before calling solrSearch method', 'solrSearch', queryParams);
86
- return new Promise((resolve, reject) => {
87
- logger_1.Logger.info('Reached Solr Search', 'solrSearch');
88
- logger_1.Logger.debug('Reached Solr Search', 'solrSearch', { queryParams });
89
- const defaultRows = constants_1.DEFAULT_SOLR_ROWS;
90
- let query = this.solrNodeClient.createQuery();
91
- if (filterQuery) {
92
- query.matchFilter(filterQuery === null || filterQuery === void 0 ? void 0 : filterQuery.filterKey, filterQuery === null || filterQuery === void 0 ? void 0 : filterQuery.filterValue);
93
- }
94
- if (queryParams) {
95
- query.q(fieldType);
96
- }
97
- else {
98
- query.q(`*:*`);
99
- }
100
- if (queryParams && queryParams.pagination) {
101
- query.start(queryParams.pagination.start ? queryParams.pagination.start : 0);
102
- query.rows(queryParams.pagination.rows
103
- ? queryParams.pagination.rows
104
- : defaultRows);
105
- }
106
- else {
107
- query.start(0);
108
- query.rows(defaultRows);
109
- }
110
- if (fields) {
111
- let fieldsTemp = Array.isArray(fields) ? fields : Object.keys(fields);
112
- query.fl(fieldsTemp);
113
- }
114
- if (sortData) {
115
- query.sort(sortData);
116
- }
117
- this.solrNodeClient.search(query, function (err, res) {
118
- if (err) {
119
- let solrError = new errorHandler_1.SolrError(err.message || err.name, Number(err.statusCode));
120
- logger_1.Logger.error(`Error in Solr Search for query: ${query}`, 'solrSearch', err);
121
- reject(solrError);
131
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
132
+ var _a, _b, _c, _d, _e;
133
+ try {
134
+ logger_1.Logger.info('Reached Solr Search', 'solrSearch');
135
+ logger_1.Logger.debug('Reached Solr Search', 'solrSearch', { queryParams });
136
+ const q = qCommon(queryParams, fieldType);
137
+ const { start, rows } = paginationCommon(queryParams);
138
+ this.queryParams = {
139
+ q,
140
+ start,
141
+ rows,
142
+ wt: SOLR_RESPONSE_FORMAT,
143
+ };
144
+ if (filterQuery) {
145
+ this.queryParams.fq = `${filterQuery.filterKey}:${filterQuery.filterValue}`;
122
146
  }
123
- else {
124
- logger_1.Logger.debug('Before returning search result', 'solrSearch', res);
125
- resolve(res.response.docs);
147
+ if (fields) {
148
+ const fieldsTemp = Array.isArray(fields) ? fields : Object.keys(fields);
149
+ this.queryParams.fl = fieldsTemp.join(',');
126
150
  }
151
+ if (sortData) {
152
+ this.queryParams.sort = sortData;
153
+ }
154
+ const response = yield this._executeHttpRequest('solrSearch');
155
+ const responseData = (_e = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.grouped) !== null && _b !== void 0 ? _b : (_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.docs) !== null && _e !== void 0 ? _e : [];
156
+ resolve(responseData);
157
+ }
158
+ catch (error) {
159
+ logger_1.Logger.debug('Reached in solr connector.ts', 'solrSearch', this.queryParams);
160
+ reject(this._handleSearchError(error, 'solrSearch'));
161
+ }
162
+ }));
163
+ });
164
+ }
165
+ /**
166
+ * Function to delete document from solr via Solr 9 HTTP API
167
+ * @param query
168
+ * @returns
169
+ */
170
+ deleteByQuery(query) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ logger_1.Logger.info('Reached Solr Search', 'solrSearch');
173
+ logger_1.Logger.debug('Reached Solr Search', 'solrSearch', { queryParams: query });
174
+ const queryString = prepareQuery(query);
175
+ const endpoint = this.core
176
+ ? `/${this.core}${SOLR_UPDATE_ENDPOINT}?commit=true`
177
+ : `${SOLR_UPDATE_ENDPOINT}?commit=true`;
178
+ try {
179
+ const response = yield this.httpClient.post(endpoint, {
180
+ delete: { query: queryString },
127
181
  });
182
+ this._checkSolrResponse(response, 'deleteByQuery');
183
+ return true;
184
+ }
185
+ catch (err) {
186
+ const solrError = this._handleSearchError(err, 'deleteByQuery');
187
+ throw solrError;
188
+ }
189
+ });
190
+ }
191
+ _executeHttpRequest(methodName) {
192
+ return __awaiter(this, void 0, void 0, function* () {
193
+ const endpoint = this.core
194
+ ? `/${this.core}${SOLR_SELECT_ENDPOINT}`
195
+ : SOLR_SELECT_ENDPOINT;
196
+ // http call to solr with query params
197
+ const response = yield this.httpClient.get(endpoint, {
198
+ params: this.queryParams,
199
+ validateStatus: (status) => status < 500 /* HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR */,
128
200
  });
201
+ // Check for errors in the response status and data
202
+ this._checkSolrResponse(response, methodName);
203
+ return response;
204
+ });
205
+ }
206
+ // Common error handling for all search methods
207
+ _handleSearchError(error, methodName) {
208
+ var _a;
209
+ // Enhanced timeout error detection
210
+ const isTimeout = ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(SOLR_TIMEOUT_KEYWORD)) ||
211
+ (error === null || error === void 0 ? void 0 : error.code) === SOLR_ERROR_CODE_ETIMEDOUT ||
212
+ (error === null || error === void 0 ? void 0 : error.code) === SOLR_ERROR_CODE_ECONNRESET ||
213
+ (error === null || error === void 0 ? void 0 : error.code) === SOLR_ERROR_CODE_ECONNABORTED;
214
+ const errorStatus = (error === null || error === void 0 ? void 0 : error.status) ||
215
+ (error === null || error === void 0 ? void 0 : error.statusCode) ||
216
+ (isTimeout
217
+ ? HTTP_STATUS_REQUEST_TIMEOUT
218
+ : 500 /* HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR */);
219
+ const solrError = new errorHandler_1.SolrError((error === null || error === void 0 ? void 0 : error.message) || SOLR_ERROR_NETWORK, errorStatus);
220
+ logger_1.Logger.error(`Error in ${methodName}`, methodName, {
221
+ error: error === null || error === void 0 ? void 0 : error.message,
222
+ errorCode: error === null || error === void 0 ? void 0 : error.code,
223
+ isTimeoutError: isTimeout,
224
+ statusCode: errorStatus,
129
225
  });
226
+ if (isTimeout) {
227
+ logger_1.Logger.error(`TIMEOUT DETECTED in ${methodName}`, methodName, {
228
+ errorMessage: error === null || error === void 0 ? void 0 : error.message,
229
+ errorCode: error === null || error === void 0 ? void 0 : error.code,
230
+ });
231
+ }
232
+ return solrError;
233
+ }
234
+ // Check the solr response for errors
235
+ _checkSolrResponse(response, methodName) {
236
+ var _a, _b, _c, _d, _e, _f, _g;
237
+ if ((response === null || response === void 0 ? void 0 : response.status) !== HTTP_STATUS_OK ||
238
+ ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.error) ||
239
+ (((_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.responseHeader) &&
240
+ ((_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.responseHeader) === null || _d === void 0 ? void 0 : _d.status) !== 0)) {
241
+ const errorMsg = (_g = (_f = (_e = response === null || response === void 0 ? void 0 : response.data) === null || _e === void 0 ? void 0 : _e.error) === null || _f === void 0 ? void 0 : _f.msg) !== null && _g !== void 0 ? _g : SOLR_ERROR_EXECUTION;
242
+ const error = new errorHandler_1.SolrError(errorMsg, response === null || response === void 0 ? void 0 : response.status);
243
+ logger_1.Logger.error(`Error in ${methodName}: ${errorMsg}`, methodName);
244
+ throw error;
245
+ }
130
246
  }
131
247
  query(query) {
132
- let queryString = query || `*:*`;
133
- this.solrQuery.q(queryString);
248
+ this.queryParams.q = prepareQuery(query);
134
249
  }
135
250
  paginate(start, rows) {
136
- this.solrQuery.start(start || 0);
137
- this.solrQuery.rows(rows || constants_1.DEFAULT_SOLR_ROWS);
251
+ this.queryParams.start = start !== null && start !== void 0 ? start : 0;
252
+ this.queryParams.rows = rows !== null && rows !== void 0 ? rows : constants_1.DEFAULT_SOLR_ROWS;
138
253
  }
139
254
  filterList(fields) {
140
255
  if (fields) {
141
- let fieldsTemp = Array.isArray(fields) ? fields : Object.keys(fields);
142
- this.solrQuery.fl(fieldsTemp);
256
+ const fieldsArray = Array.isArray(fields) ? fields : Object.keys(fields);
257
+ this.queryParams.fl = fieldsArray.join(',');
143
258
  }
144
259
  }
145
260
  sort(fields) {
146
261
  if (fields) {
147
- this.solrQuery.sort(fields);
262
+ this.queryParams.sort = fields;
263
+ }
264
+ }
265
+ facet(fields) {
266
+ if (fields) {
267
+ this.queryParams.facet = true;
268
+ this.queryParams['facet.field'] = fields;
148
269
  }
149
270
  }
150
271
  filterQuery(fields) {
151
- if (fields === null || fields === void 0 ? void 0 : fields.length) {
152
- this.solrQuery.fq(fields);
272
+ if (fields) {
273
+ this.queryParams.fq = fields;
153
274
  }
154
275
  }
155
276
  }
156
277
  exports.SolrClient = SolrClient;
278
+ const qCommon = (queryParams, fieldType) => {
279
+ if (queryParams) {
280
+ if (typeof fieldType === 'string')
281
+ return fieldType;
282
+ if (typeof fieldType === 'object')
283
+ return prepareQuery(fieldType);
284
+ return SOLR_DEFAULT_QUERY;
285
+ }
286
+ return SOLR_DEFAULT_QUERY;
287
+ };
288
+ const paginationCommon = (queryParams) => {
289
+ var _a, _b;
290
+ let start = 0;
291
+ let rows = constants_1.DEFAULT_SOLR_ROWS;
292
+ if (queryParams === null || queryParams === void 0 ? void 0 : queryParams.pagination) {
293
+ start = (_a = queryParams.pagination.start) !== null && _a !== void 0 ? _a : 0;
294
+ rows = (_b = queryParams.pagination.rows) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_SOLR_ROWS;
295
+ }
296
+ return { start, rows };
297
+ };
157
298
  //# sourceMappingURL=solrConnector.js.map
package/dist/src/index.js CHANGED
@@ -15,6 +15,7 @@ const getIAMSecrets = () => {
15
15
  throw new Error("IAM secrets not initialized");
16
16
  }
17
17
  return injectedSecretService.getSecretKeys(); // returns cached data
18
+ // return new SecretKeyServices().getSecretKeys(); // secret gateway
18
19
  };
19
20
  exports.getIAMSecrets = getIAMSecrets;
20
21
  //# sourceMappingURL=index.js.map
@@ -47,12 +47,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
48
  exports.EmailHandler = void 0;
49
49
  const emailDataSource_1 = require("../dataSource/emailDataSource");
50
- const HTMLParser = __importStar(require("node-html-parser"));
51
50
  const style_1 = require("../constants/style");
52
51
  const config_1 = __importDefault(require("../../config"));
53
52
  const constants_1 = require("../constants");
54
53
  const lodash_1 = require("lodash");
55
54
  const emailTemplate_1 = require("./emailTemplate");
55
+ const HTMLParser = require('node-html-parser');
56
56
  const moment = require('moment-timezone');
57
57
  const sgMail = require('@sendgrid/mail');
58
58
  const sgHelpers = require('@sendgrid/helpers');
@@ -372,6 +372,7 @@ class EmailHandler {
372
372
  }
373
373
  if (templateData && ((_a = Object.keys(templateData)) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
374
374
  const root = HTMLParser.parse(templateData === null || templateData === void 0 ? void 0 : templateData.body);
375
+ isCFF = (templateData === null || templateData === void 0 ? void 0 : templateData.email_from) && (templateData === null || templateData === void 0 ? void 0 : templateData.email_from) !== '' ? templateData === null || templateData === void 0 ? void 0 : templateData.email_from : isCFF;
375
376
  const emailConfiguration = {
376
377
  email: (_b = reqBody.replacement_variables) === null || _b === void 0 ? void 0 : _b.EMAIL,
377
378
  emailTemplate: root ? root.toString() : '',
@@ -493,7 +494,7 @@ class EmailHandler {
493
494
  }
494
495
  fetchEmailTemplateData(reqBody) {
495
496
  return __awaiter(this, void 0, void 0, function* () {
496
- var _a, _b, _c, _d;
497
+ var _a, _b, _c, _d, _e, _f;
497
498
  try {
498
499
  logger_1.Logger.info('EmailHandler: Reached fetchEmailTemplateData', 'fetchEmailTemplateData');
499
500
  let { email_type } = reqBody;
@@ -504,12 +505,14 @@ class EmailHandler {
504
505
  if ((templateSolrRes === null || templateSolrRes === void 0 ? void 0 : templateSolrRes.length) > 0) {
505
506
  templateData.body = ((_a = templateSolrRes === null || templateSolrRes === void 0 ? void 0 : templateSolrRes[0]) === null || _a === void 0 ? void 0 : _a.hclplatformx_Body) || '';
506
507
  templateData.subject = ((_b = templateSolrRes === null || templateSolrRes === void 0 ? void 0 : templateSolrRes[0]) === null || _b === void 0 ? void 0 : _b.hclplatformx_Subject) || '';
508
+ templateData.email_from = ((_c = templateSolrRes === null || templateSolrRes === void 0 ? void 0 : templateSolrRes[0]) === null || _c === void 0 ? void 0 : _c.hclplatformx_To) || '';
507
509
  }
508
510
  }
509
511
  else {
510
512
  let templateRes = yield new formBuilder_dao_1.default().fetch('email_templates', { name: email_type });
511
- templateData.body = (_c = templateRes === null || templateRes === void 0 ? void 0 : templateRes[0]) === null || _c === void 0 ? void 0 : _c.body;
512
- templateData.subject = (_d = templateRes === null || templateRes === void 0 ? void 0 : templateRes[0]) === null || _d === void 0 ? void 0 : _d.subject;
513
+ templateData.body = (_d = templateRes === null || templateRes === void 0 ? void 0 : templateRes[0]) === null || _d === void 0 ? void 0 : _d.body;
514
+ templateData.subject = (_e = templateRes === null || templateRes === void 0 ? void 0 : templateRes[0]) === null || _e === void 0 ? void 0 : _e.subject;
515
+ templateData.email_from = ((_f = templateRes === null || templateRes === void 0 ? void 0 : templateRes[0]) === null || _f === void 0 ? void 0 : _f.to) || '';
513
516
  }
514
517
  return templateData;
515
518
  }
@@ -1,3 +1,4 @@
1
+ import { DataSource } from 'apollo-datasource';
1
2
  export interface Pagination {
2
3
  start: number;
3
4
  rows: number;
@@ -8,17 +9,19 @@ export interface FilterQueryType {
8
9
  }
9
10
  export interface SolrQueryRequest {
10
11
  query: string | object;
11
- filterQuery?: FilterQueryType[] | null | any;
12
+ filterQuery?: FilterQueryType[] | null;
12
13
  pagination?: Pagination;
13
14
  filter?: object | string[];
14
15
  sort?: object;
15
16
  }
16
- export declare class SolrHttpDataSource<TContext = any> {
17
- private solr;
17
+ export declare class SolrHttpDataSource<TContext = any> extends DataSource {
18
18
  context: TContext;
19
+ private solr;
19
20
  private cache;
20
21
  private memoizedResults;
21
- constructor();
22
+ constructor(core?: string);
23
+ initialize({ context, cache }?: any): void;
24
+ didEncounterError(error: any): void;
22
25
  cacheKey(id: string): string;
23
26
  memoizedCacheKey(): string;
24
27
  createQuery(queryRequest: SolrQueryRequest): void;
@@ -13,12 +13,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.SolrHttpDataSource = void 0;
16
+ const apollo_datasource_1 = require("apollo-datasource");
17
+ const apollo_server_caching_1 = require("apollo-server-caching");
16
18
  const solrConnector_1 = require("../../../common/util/solrConnector");
17
19
  const quick_lru_1 = __importDefault(require("@alloc/quick-lru"));
18
- class SolrHttpDataSource {
20
+ const logger_1 = require("../../../common/util/logger");
21
+ class SolrHttpDataSource extends apollo_datasource_1.DataSource {
19
22
  // private loader: DataLoader<unknown, unknown, unknown>;
20
- constructor() {
21
- this.solr = new solrConnector_1.SolrClient();
23
+ constructor(core) {
24
+ super();
25
+ this.solr = new solrConnector_1.SolrClient(core);
22
26
  this.memoizedResults = new quick_lru_1.default({
23
27
  // The maximum number of items before evicting the least recently used items.
24
28
  maxSize: 50,
@@ -28,45 +32,57 @@ class SolrHttpDataSource {
28
32
  });
29
33
  // this.loader = new DataLoader(ids => dbClient.getByIds(ids))
30
34
  }
31
- // initialize({ context, cache }:any = {}) {
32
- // this.context = context;
33
- // this.cache = cache || new InMemoryLRUCache();
34
- // }
35
- // didEncounterError(error:any) {
36
- // throw error;
37
- // }
35
+ initialize({ context, cache } = {}) {
36
+ this.context = context;
37
+ this.cache = cache || new apollo_server_caching_1.InMemoryLRUCache();
38
+ }
39
+ didEncounterError(error) {
40
+ throw error;
41
+ }
38
42
  cacheKey(id) {
39
43
  return `solr-${id}`;
40
44
  }
41
45
  memoizedCacheKey() {
42
- var _a;
43
- // return (
44
- // JSON.parse(JSON.stringify(this.solr.getQuery())) as any
45
- // )?.parameters?.join('&');
46
- const data = JSON.parse(JSON.stringify(this.solr.getQuery()));
47
- return (_a = data === null || data === void 0 ? void 0 : data.parameters) === null || _a === void 0 ? void 0 : _a.join('&');
46
+ const queryParams = this.solr.getQuery();
47
+ return queryParams ? new URLSearchParams(queryParams).toString() : '';
48
48
  }
49
49
  createQuery(queryRequest) {
50
50
  let { query, pagination, filter, sort, filterQuery } = queryRequest;
51
- let solrQuery = this.solr.createQuery();
52
- solrQuery.query(query); // q
53
- solrQuery.paginate(pagination === null || pagination === void 0 ? void 0 : pagination.start, pagination === null || pagination === void 0 ? void 0 : pagination.rows); // start, rows
54
- solrQuery.filterList(filter); // fl
55
- solrQuery.sort(sort); // sort
56
- solrQuery.filterQuery(filterQuery); // fq
51
+ try {
52
+ let solrQuery = this.solr.createQuery();
53
+ solrQuery.query(query); // q
54
+ solrQuery.paginate(pagination === null || pagination === void 0 ? void 0 : pagination.start, pagination === null || pagination === void 0 ? void 0 : pagination.rows); // start, rows
55
+ solrQuery.filterList(filter); // fl
56
+ solrQuery.sort(sort); // sort
57
+ solrQuery.filterQuery(filterQuery); // fq
58
+ logger_1.Logger.info('SolrHttpDataSource:Solr Query created', 'createQuery');
59
+ logger_1.Logger.debug('SolrHttpDataSource query payload', 'createQuery', {
60
+ query: JSON.stringify(this.solr.getQuery()),
61
+ });
62
+ }
63
+ catch (err) {
64
+ logger_1.Logger.error('Error with SOLR query creation: ', 'SOLR creation', err);
65
+ throw err;
66
+ }
57
67
  }
58
68
  executeSearch() {
59
69
  return __awaiter(this, void 0, void 0, function* () {
60
70
  let response;
61
- let cacheKey = this.memoizedCacheKey();
62
- if (this.memoizedResults.has(cacheKey)) {
63
- response = yield this.memoizedResults.get(cacheKey); // NOSONAR
64
- return response;
71
+ try {
72
+ let cacheKey = this.memoizedCacheKey();
73
+ if (this.memoizedResults.has(cacheKey)) {
74
+ response = this.memoizedResults.get(cacheKey); // eslint-disable-line @typescript-eslint/no-non-null-assertion
75
+ return response;
76
+ }
77
+ else {
78
+ response = yield this.solr.executeSearch();
79
+ this.memoizedResults.set(cacheKey, response);
80
+ return response;
81
+ }
65
82
  }
66
- else {
67
- response = yield this.solr.executeSearch();
68
- this.memoizedResults.set(cacheKey, response);
69
- return response;
83
+ catch (err) {
84
+ logger_1.Logger.error('Error with SOLR query execution: ', 'SOLR QUERY', err);
85
+ throw err;
70
86
  }
71
87
  });
72
88
  }
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@platform-x/hep-notification-client",
3
- "version": "1.2.9",
3
+ "version": "1.3.1",
4
4
  "description": "@platform-x/hep-notification-client",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
7
7
  "scripts": {
8
- "build": "tsc && npm run copy-static",
8
+ "devstart": "npm run build && tsc-watch --onSuccess \"node ./dist/src/index.js\"",
9
+ "start": "node ./dist/src/index.js",
10
+ "build": "tsc && npm run copy-static",
9
11
  "copy-static": "xcopy src\\templates dist\\templates /E /I /Y"
10
12
  },
11
13
  "author": "",
@@ -16,6 +18,7 @@
16
18
  "@types/node": "^22.15.3",
17
19
  "@types/uuid": "^10.0.0",
18
20
  "ts-node": "^10.9.2",
21
+ "tsc-watch": "^7.2.0",
19
22
  "typescript": "^5.8.3"
20
23
  },
21
24
  "dependencies": {
@@ -30,6 +33,7 @@
30
33
  "@types/lodash": "^4.14.171",
31
34
  "@types/node": "^15.12.2",
32
35
  "@types/twilio": "^3.19.2",
36
+ "apollo-datasource": "^3.3.2",
33
37
  "apollo-server-caching": "^3.3.0",
34
38
  "axios": "0.21.4",
35
39
  "bunyan": "^1.8.15",
@@ -53,7 +57,7 @@
53
57
  "request-ip": "2.1.3",
54
58
  "solr-client": "0.10.0-rc6",
55
59
  "twilio": "^5.3.6",
56
- "uuid": "8.3.2"
60
+ "uuid": "^8.3.2"
57
61
  },
58
62
  "private": false,
59
63
  "publishConfig": {
@@ -1,7 +0,0 @@
1
- export declare class SecretKeyServices {
2
- private ruleCache;
3
- /**
4
- * Fetches all the secret keys
5
- */
6
- getSecretKeys(): Promise<any>;
7
- }
@@ -1,58 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.SecretKeyServices = void 0;
16
- const hep_secret_access_1 = require("hep-secret-access");
17
- const constants_1 = require("../../platform-x/constants");
18
- const config_1 = __importDefault(require("../../config"));
19
- class SecretKeyServices {
20
- constructor() {
21
- this.ruleCache = new Map();
22
- }
23
- /**
24
- * Fetches all the secret keys
25
- */
26
- getSecretKeys() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- try {
29
- // Initialize secret manager object
30
- if (this.ruleCache.has('secret_data')) {
31
- return this.ruleCache.get('secret_data');
32
- }
33
- const secretObject = (0, hep_secret_access_1.secretManager)();
34
- // If secret mode is ENV – read one by one
35
- // for local testing
36
- if ((config_1.default === null || config_1.default === void 0 ? void 0 : config_1.default.SECRET_MODE) === 'env') {
37
- const keyConfig = {};
38
- for (const key of Object.values(constants_1.DynamicValues)) {
39
- // Fetch individual value (existing read() method)
40
- const value = yield secretObject.read(key);
41
- keyConfig[key] = value;
42
- }
43
- this.ruleCache.set('secret_data', keyConfig);
44
- return keyConfig;
45
- }
46
- // else – fetch all secrets from GSM
47
- const data = yield secretObject.readAllSecrets();
48
- this.ruleCache.set('secret_data', data);
49
- return data;
50
- }
51
- catch (err) {
52
- return {};
53
- }
54
- });
55
- }
56
- }
57
- exports.SecretKeyServices = SecretKeyServices;
58
- //# sourceMappingURL=secretKeyManager.js.map
@@ -1,4 +0,0 @@
1
- export interface PushNotifyProvider {
2
- fetchTopics(): Promise<any>;
3
- sendNotificationsToTopics(topics: string[], notification: any): Promise<any>;
4
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=interface.js.map