@cumulus/es-client 18.5.1 → 18.5.3

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 (2) hide show
  1. package/indexer.js +31 -8
  2. package/package.json +9 -8
package/indexer.js CHANGED
@@ -26,6 +26,10 @@ const mappings = require('./config/mappings.json');
26
26
 
27
27
  const logger = new Logger({ sender: '@cumulus/es-client/indexer' });
28
28
 
29
+ /**
30
+ * @typedef {import('@cumulus/types').ApiGranule} ApiGranule
31
+ */
32
+
29
33
  async function createIndex(esClient, indexName) {
30
34
  const indexExists = await esClient.client.indices.exists({ index: indexName })
31
35
  .then((response) => response.body);
@@ -90,7 +94,7 @@ async function genericRecordUpdate(esClient, id, doc, index, type, parent) {
90
94
  try {
91
95
  indexResponse = await actualEsClient.client.index(params);
92
96
  } catch (error) {
93
- if (error.name === 'ResponseError' && error?.meta?.body?.message.includes('The security token included in the request is expired')) {
97
+ if (error.name === 'ResponseError' && error?.meta?.body?.message?.includes('The security token included in the request is expired')) {
94
98
  logger.warn(`genericRecordUpdate encountered a ResponseError ${JSON.stringify(error)}, updating credentials and retrying`);
95
99
  await actualEsClient.refreshClient();
96
100
  indexResponse = await actualEsClient.client.index(params);
@@ -108,14 +112,15 @@ async function genericRecordUpdate(esClient, id, doc, index, type, parent) {
108
112
  /**
109
113
  * Updates a given record for the Elasticsearch index and type
110
114
  *
111
- * @param {Object} esClient - Elasticsearch Connection object
112
- * @param {string} id - the record id
113
- * @param {Object} doc - the record
114
- * @param {string} index - Elasticsearch index alias
115
- * @param {string} type - Elasticsearch type
115
+ * @param {Object} esClient - Elasticsearch Connection object
116
+ * @param {string} id - the record id
117
+ * @param {Object} doc - the record
118
+ * @param {string} index - Elasticsearch index alias
119
+ * @param {string} type - Elasticsearch type
120
+ * @param {string | undefined} parent - parent identifier if applicable
116
121
  * @returns {Promise} Elasticsearch response
117
122
  */
118
- async function updateExistingRecord(esClient, id, doc, index, type) {
123
+ async function updateExistingRecord(esClient, id, doc, index, type, parent) {
119
124
  return await esClient.client.update({
120
125
  index,
121
126
  type,
@@ -127,6 +132,7 @@ async function updateExistingRecord(esClient, id, doc, index, type) {
127
132
  },
128
133
  },
129
134
  refresh: inTestMode(),
135
+ parent,
130
136
  });
131
137
  }
132
138
 
@@ -141,7 +147,23 @@ async function updateExistingRecord(esClient, id, doc, index, type) {
141
147
  * @returns {Promise} elasticsearch update response
142
148
  */
143
149
  function updateAsyncOperation(esClient, id, updates, index = defaultIndexAlias, type = 'asyncOperation') {
144
- return updateExistingRecord(esClient, id, updates, index, type);
150
+ const parent = undefined;
151
+ return updateExistingRecord(esClient, id, updates, index, type, parent);
152
+ }
153
+
154
+ /**
155
+ * Updates a granule record in Elasticsearch
156
+ *
157
+ * @param {Object} esClient - Elasticsearch Connection object
158
+ * @param {ApiGranule} granule - Api Granule to update
159
+ * @param {Object} updates - Updates to make to granule in Elasticsearch
160
+ * @param {string} index - Elasticsearch index alias (default defined in search.js)
161
+ * @param {string} type - Elasticsearch type (default: granule)
162
+ * @returns {Promise} elasticsearch update response
163
+ */
164
+ function updateGranule(esClient, granule, updates, index = defaultIndexAlias, type = 'granule') {
165
+ const collectionId = granule.collectionId;
166
+ return updateExistingRecord(esClient, granule.granuleId, updates, index, type, collectionId);
145
167
  }
146
168
 
147
169
  const executionInvalidNullFields = [
@@ -821,4 +843,5 @@ module.exports = {
821
843
  upsertExecution,
822
844
  upsertGranule,
823
845
  upsertPdr,
846
+ updateGranule,
824
847
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulus/es-client",
3
- "version": "18.5.1",
3
+ "version": "18.5.3",
4
4
  "description": "Utilities for working with Elasticsearch",
5
5
  "keywords": [
6
6
  "CUMULUS",
@@ -34,10 +34,11 @@
34
34
  "license": "Apache-2.0",
35
35
  "dependencies": {
36
36
  "@aws-sdk/credential-providers": "^3.621.0",
37
- "@cumulus/common": "18.5.1",
38
- "@cumulus/errors": "18.5.1",
39
- "@cumulus/logger": "18.5.1",
40
- "@cumulus/message": "18.5.1",
37
+ "@cumulus/common": "18.5.3",
38
+ "@cumulus/errors": "18.5.3",
39
+ "@cumulus/logger": "18.5.3",
40
+ "@cumulus/message": "18.5.3",
41
+ "@cumulus/types": "18.5.3",
41
42
  "@elastic/elasticsearch": "^5.6.20",
42
43
  "aws4": "^1.12.0",
43
44
  "lodash": "~4.17.21",
@@ -45,9 +46,9 @@
45
46
  "p-limit": "^1.2.0"
46
47
  },
47
48
  "devDependencies": {
48
- "@cumulus/aws-client": "18.5.1",
49
- "@cumulus/test-data": "18.5.1",
49
+ "@cumulus/aws-client": "18.5.3",
50
+ "@cumulus/test-data": "18.5.3",
50
51
  "p-each-series": "^2.1.0"
51
52
  },
52
- "gitHead": "c55c0107364cada95299b869d47ace80b87bdfdc"
53
+ "gitHead": "710a2742b86966888094319920f57471b72a0cf8"
53
54
  }