@opensearch-project/opensearch 2.6.0 → 2.8.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/CHANGELOG.md CHANGED
@@ -9,6 +9,26 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
9
9
  ### Deprecated
10
10
  ### Removed
11
11
  ### Fixed
12
+ ### Security
13
+
14
+ ## [2.8.0]
15
+ ### Added
16
+ - Added `@opensearch-project/opensearch/aws-v3` import ([758](https://github.com/opensearch-project/opensearch-js/pull/758)).
17
+ ### Dependencies
18
+ - Bumps `@types/node` from 20.12.5 to 20.12.7
19
+ - Bumps `semver` from 5.7.1 to 7.6.0
20
+ - Bumps `dedent` from 1.5.1 to 1.5.3
21
+ ### Changed
22
+ - Disabled fail_ci_if_error for upload coverage step in coverage workflow ([#755](https://github.com/opensearch-project/opensearch-js/issues/755)
23
+
24
+ ## [2.7.0]
25
+ ### Dependencies
26
+ - Bumps `@aws-sdk/types` from 3.523.0 to 3.535.0
27
+ - Bumps `simple-git` from 3.22.0 to 3.24.0
28
+ - Bumps `@types/node` from 20.11.25 to 20.12.5
29
+ - Bumps `@babel/eslint-parser` from 7.23.10 to 7.24.1
30
+ ### Changed
31
+ - Added `search_pipeline` ([#716](https://github.com/opensearch-project/opensearch-js/pull/716))
12
32
 
13
33
  ## [2.6.0]
14
34
  ### Added
@@ -16,7 +36,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
16
36
  ### Dependencies
17
37
  - Bumps `prettier` from 3.1.1 to 3.2.5
18
38
  - Bumps `@aws-sdk/types` from 3.485.0 to 3.523.0
19
- - Bumps `@types/node` from 20.10.7 to 20.11.24
39
+ - Bumps `@types/node` from 20.10.7 to 20.11.25
20
40
  - Bumps `eslint-plugin-prettier` from 5.1.2 to 5.1.3
21
41
  - Bumps `@babel/eslint-parser` from 7.23.3 to 7.23.10
22
42
  - Bumps `semver` from 7.5.1 to 7.6.0
@@ -26,12 +46,10 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
26
46
  - Updated integration tests to use strong password in OS 2.12 and up ([#707](https://github.com/opensearch-project/opensearch-js/pull/707))
27
47
  - Simplified client creation in the guides ([#707](https://github.com/opensearch-project/opensearch-js/pull/707))
28
48
  - Corrected `guides/bulk.md` ([#616](https://github.com/opensearch-project/opensearch-js/issues/616))
29
- ### Deprecated
30
49
  ### Removed
31
50
  - Removed AutoHeal([#707](https://github.com/opensearch-project/opensearch-js/pull/707))
32
51
  ### Fixed
33
52
  - Make optional fields optional in `MappingGenericProperty` ([708](https://github.com/opensearch-project/opensearch-js/pull/708))
34
- ### Security
35
53
 
36
54
  ## [2.5.0]
37
55
  ### Added
@@ -59,8 +77,6 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
59
77
  - Bumps `eslint-config-prettier` from 9.0.0 to 9.1.0
60
78
  - Bumps `ora` from 7.0.1 to 8.0.1
61
79
  - Bumps `simple-git` from 3.21.0 to 3.22.0
62
- ### Changed
63
- ### Deprecated
64
80
  ### Removed
65
81
  - Removed fixture lines that git-secrets wrongly flagged as passwords/secrets ([654](https://github.com/opensearch-project/opensearch-js/pull/645))
66
82
  ### Fixed
@@ -88,11 +104,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
88
104
  ### Changed
89
105
  - Make handling of long numerals an option that is disabled by default ([#557](https://github.com/opensearch-project/opensearch-js/pull/557))
90
106
  - Add `enableLongNumeralSupport` to the type definition for `ClientOptions` ([#598](https://github.com/opensearch-project/opensearch-js/pull/598))
91
- ### Deprecated
92
- ### Removed
93
107
  ### Fixed
94
108
  - Fix wrong documentation for file serach.md regarding `search_after` param ([#584](https://github.com/opensearch-project/opensearch-js/pull/584))
95
- ### Security
96
109
 
97
110
  ## [2.3.0]
98
111
 
@@ -113,24 +126,18 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
113
126
  - Implemented Docker Image caching for `integration-unreleased` workflow ([#387](https://github.com/opensearch-project/opensearch-js/issues/387))
114
127
  - Add upgrading NPM to all workflows running older Node.js versions ([#545](https://github.com/opensearch-project/opensearch-js/issues/545))
115
128
  - Upgrade and secure the backport workflow ([#547](https://github.com/opensearch-project/opensearch-js/issues/547))
116
- ### Deprecated
117
- ### Removed
118
129
  ### Fixed
119
130
  - Fixed malformed `bundler.yml` ([#497](https://github.com/opensearch-project/opensearch-js/pull/497))
120
- ### Security
121
131
 
122
132
  ## [2.2.1]
123
133
 
124
134
  ### Added
125
-
126
135
  - Add release details to releasing.md ([319](https://github.com/opensearch-project/opensearch-js/pull/319))
127
136
  - Added Amazon OpenSearch Serverless in user_guide ([#372](https://github.com/opensearch-project/opensearch-js/issues/372))
128
137
  - Add guidelines on installing yarn, dependencies; instructions on running ESLint in developer_guide ([#439](https://github.com/opensearch-project/opensearch-js/issues/435))
129
138
  - Added pull_request_template ([440](https://github.com/opensearch-project/opensearch-js/pull/440))
130
139
  - Added guide for Search ([#473](https://github.com/opensearch-project/opensearch-js/pull/489))
131
-
132
140
  ### Dependencies
133
-
134
141
  - Bumps `aws4` from 1.11.0 to 1.12.0
135
142
  - Bumps `minimist` from 1.2.6 to 1.2.8
136
143
  - Bumps `tsd` from 0.24.1 to 0.27.0
@@ -152,37 +159,26 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
152
159
  - Bumps `prettier` from 2.8.4 to 2.8.7
153
160
  - Bumps `jsdoc` from 4.0.0 to 4.0.2
154
161
  - Bumps `@babel/eslint-parser` from 7.19.1 to 7.21.3
155
-
156
162
  ### Changed
157
-
158
163
  - Remove test artifacts from gh_pages workflow ([#335](https://github.com/opensearch-project/opensearch-js/issues/335))
159
164
  - Make fields in `BulkOperation` optional to match OpenSearch Bulk API requirements ([#378](https://github.com/opensearch-project/opensearch-js/pull/378))
160
165
  - Remove guidance on using npm and switch completely to yarn in developer_guide ([#439](https://github.com/opensearch-project/opensearch-js/issues/435))
161
166
  - Change coverage, compatability, integration, integration with unreleased Open Search, node ci, bundler tests not to run on documentation change ([441](https://github.com/opensearch-project/opensearch-js/pull/441))
162
167
  - Change the Windows yarn installation troubleshoot steps ([455](https://github.com/opensearch-project/opensearch-js/issues/455))
163
168
  - Make `callback` arg in `BaseConnectionPool`, `CloudConnectionPool` and `ConnectionPool` optional ([#451](https://github.com/opensearch-project/opensearch-js/pull/451))
164
-
165
169
  ### Deprecated
166
-
167
170
  - Remove deprecation warnings in bulk.test.js ([#434](https://github.com/opensearch-project/opensearch-js/issues/434))
168
-
169
171
  ### Removed
170
-
171
172
  - Remove waitCluster in Integration Tests ([#422](https://github.com/opensearch-project/opensearch-js/issues/422))
172
-
173
173
  ### Fixed
174
-
175
174
  - Added missing types for AwsSigv4SignerOptions.service ([#377](https://github.com/opensearch-project/opensearch-js/pull/377))
176
175
  - Fixed deprecated folder mapping "./" in the "exports" field module resolution ([#416](https://github.com/opensearch-project/opensearch-js/pull/416))
177
176
 
178
- ### Security
179
-
180
177
  - [CVE-2022-25912] Bumps simple-git from 3.4.0 to 3.15.0 ([#341](https://github.com/opensearch-project/opensearch-js/pull/341))
181
178
 
182
179
  ## [2.2.0]
183
180
 
184
181
  ### Added
185
-
186
182
  - Add release details to releasing.md ([319](https://github.com/opensearch-project/opensearch-js/pull/319))
187
183
  - Allow overriding the aws service identifier in AwsSigv4Signer ([333](https://github.com/opensearch-project/opensearch-js/pull/333))
188
184
  - Added skip-changelog label ([339](https://github.com/opensearch-project/opensearch-js/pull/339))
@@ -196,9 +192,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
196
192
  - Fixed typos in `ConnectionPool` ([#427](https://github.com/opensearch-project/opensearch-js/pull/427))
197
193
  - Added the solution for the possible error during yarn installation on Windows OS ([#435](https://github.com/opensearch-project/opensearch-js/issues/435))
198
194
  - Added missing `createConnection` method type definition in `BaseConnectionPool` )([#490](https://github.com/opensearch-project/opensearch-js/pull/490))
199
-
200
195
  ### Dependencies
201
-
202
196
  - Bumps `xmlbuilder2` from 2.4.1 to 3.0.2
203
197
  - Bumps `minimatch` from 3.0.4 to 3.1.2
204
198
  - Bumps `eslint` from 7.32.0 to 8.32.0
@@ -211,36 +205,18 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
211
205
  - Bumps `hpagent` from 0.1.2 to 1.2.0
212
206
  - Bumps `eslint-config-prettier` from 8.5.0 to 8.6.0
213
207
  - Bumps `rimraf` from 3.0.2 to 4.1.1
214
-
215
- ### Dependencies
216
-
217
208
  ### Changed
218
-
219
209
  - Remove test artifacts from gh_pages workflow ([#335](https://github.com/opensearch-project/opensearch-js/issues/335))
220
210
  - Make `TimeoutError` and `RequestAbortedError` classes' `meta` argument optional ([#478](https://github.com/opensearch-project/opensearch-js/pull/478/))
221
-
222
- ### Deprecated
223
-
224
- ### Removed
225
-
226
- ### Fixed
227
-
228
211
  ### Security
229
-
230
212
  - [CVE-2022-25912] Bumps simple-git from 3.4.0 to 3.15.0 ([#341](https://github.com/opensearch-project/opensearch-js/pull/341))
231
213
 
232
214
  ## [2.1.0]
233
-
234
215
  ### Added
235
-
236
216
  - Github workflow for changelog verification ([#306](https://github.com/opensearch-project/opensearch-js/pull/306))
237
217
  - Add GitHub and Jenkins release workflow ([#317](https://github.com/opensearch-project/opensearch-js/pull/317))
238
-
239
218
  ### Dependencies
240
-
241
219
  - Bumps `tsd` from 0.22.0 to 0.24.1
242
220
  - Bumps `semver` from 7.3.7 to 7.3.8
243
-
244
221
  ### Fixed
245
-
246
222
  - Fix mutability of connection headers ([#291](https://github.com/opensearch-project/opensearch-js/issues/291))
package/USER_GUIDE.md CHANGED
@@ -90,7 +90,9 @@ const client = new Client({
90
90
  ```javascript
91
91
  const { defaultProvider } = require('@aws-sdk/credential-provider-node'); // V3 SDK.
92
92
  const { Client } = require('@opensearch-project/opensearch');
93
- const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws');
93
+ const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws-v3'); // use aws-v3 import path if you are using aws-sdk v3
94
+ // Unlike the import path in the v2 example above that lazy loads both aws-sdk v3 credential providers & entire aws-sdk v2 if available
95
+ // This will only lazy load the aws-sdk v3 credential providers
94
96
 
95
97
  const client = new Client({
96
98
  ...AwsSigv4Signer({
package/api/api/search.js CHANGED
@@ -54,6 +54,7 @@ const acceptedQuerystring = [
54
54
  'q',
55
55
  'routing',
56
56
  'scroll',
57
+ 'search_pipeline',
57
58
  'search_type',
58
59
  'size',
59
60
  'sort',
@@ -97,6 +98,7 @@ const snakeCase = {
97
98
  ignoreThrottled: 'ignore_throttled',
98
99
  allowNoIndices: 'allow_no_indices',
99
100
  expandWildcards: 'expand_wildcards',
101
+ searchPipeline: 'search_pipeline',
100
102
  searchType: 'search_type',
101
103
  _sourceExcludes: '_source_excludes',
102
104
  _sourceExclude: '_source_exclude',
@@ -148,6 +150,7 @@ const snakeCase = {
148
150
  * @param {string} [params.q] - Query in the Lucene query string syntax
149
151
  * @param {string} [params.routing] - A comma-separated list of specific routing values
150
152
  * @param {string} [params.scroll] - Specify how long a consistent view of the index should be maintained for scrolled search
153
+ * @param {string} [params.search_pipeline] - Customizable sequence of processing stages applied to search queries.
151
154
  * @param {string} [params.search_type] - Search operation type (options: query_then_fetch, dfs_query_then_fetch)
152
155
  * @param {number} [params.size] - Number of hits to return (default: 10)
153
156
  * @param {string} [params.sort] - A comma-separated list of <field>:<direction> pairs
@@ -1516,6 +1516,7 @@ export interface Search<T = RequestBody> extends Generic {
1516
1516
  q?: string;
1517
1517
  routing?: string | string[];
1518
1518
  scroll?: string;
1519
+ search_pipeline?: string;
1519
1520
  search_type?: 'query_then_fetch' | 'dfs_query_then_fetch';
1520
1521
  size?: number;
1521
1522
  sort?: string | string[];
package/api/types.d.ts CHANGED
@@ -935,6 +935,7 @@ export interface SearchRequest extends RequestBase {
935
935
  request_cache?: boolean;
936
936
  routing?: Routing;
937
937
  scroll?: Time;
938
+ search_pipeline?: string;
938
939
  search_type?: SearchType;
939
940
  stats?: string[];
940
941
  stored_fields?: Fields;
@@ -973,6 +974,7 @@ export interface SearchRequest extends RequestBase {
973
974
  query?: QueryDslQueryContainer;
974
975
  rescore?: SearchRescore | SearchRescore[];
975
976
  script_fields?: Record<string, ScriptField>;
977
+ search_pipeline?: Record<string, any>;
976
978
  search_after?: (integer | string)[];
977
979
  size?: integer;
978
980
  slice?: SlicedScroll;
package/guides/msearch.md CHANGED
@@ -18,7 +18,7 @@ await client.bulk({
18
18
  ],
19
19
  });
20
20
 
21
- await client.index.refresh({ index: 'movies' });
21
+ await client.indices.refresh({ index: 'movies' });
22
22
  ```
23
23
 
24
24
  # Multi Search API
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright OpenSearch Contributors
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ *
5
+ * The OpenSearch Contributors require contributions made to
6
+ * this file be licensed under the Apache-2.0 license or a
7
+ * compatible open source license.
8
+ *
9
+ */
10
+
11
+ 'use strict';
12
+ const AwsSigv4SignerError = require('./errors');
13
+ const { giveAwsV4Signer, giveAwsCredentialProviderLoader } = require('./shared');
14
+
15
+ const getAwsSDKCredentialsProvider = async () => {
16
+ try {
17
+ const awsV3 = await import('@aws-sdk/credential-provider-node');
18
+ if (typeof awsV3.defaultProvider === 'function') {
19
+ return awsV3.defaultProvider();
20
+ }
21
+ } catch (err) {
22
+ throw new AwsSigv4SignerError(
23
+ "Missing '@aws-sdk/credential-provider-node' module. Install it as a dependency."
24
+ );
25
+ }
26
+ };
27
+
28
+ const AwsSigv4Signer = giveAwsV4Signer(
29
+ giveAwsCredentialProviderLoader(getAwsSDKCredentialsProvider)
30
+ );
31
+
32
+ module.exports = AwsSigv4Signer;
@@ -9,12 +9,8 @@
9
9
  */
10
10
 
11
11
  'use strict';
12
- const Connection = require('../Connection');
13
- const Transport = require('../Transport');
14
- const aws4 = require('aws4');
15
12
  const AwsSigv4SignerError = require('./errors');
16
- const crypto = require('crypto');
17
- const { toMs } = Transport.internals;
13
+ const { giveAwsV4Signer, giveAwsCredentialProviderLoader } = require('./shared');
18
14
 
19
15
  const getAwsSDKCredentialsProvider = async () => {
20
16
  // First try V3
@@ -49,150 +45,8 @@ const getAwsSDKCredentialsProvider = async () => {
49
45
  );
50
46
  };
51
47
 
52
- const awsDefaultCredentialsProvider = () =>
53
- new Promise((resolve, reject) => {
54
- getAwsSDKCredentialsProvider()
55
- .then((provider) => {
56
- provider().then(resolve).catch(reject);
57
- })
58
- .catch((err) => {
59
- reject(err);
60
- });
61
- });
48
+ const AwsSigv4Signer = giveAwsV4Signer(
49
+ giveAwsCredentialProviderLoader(getAwsSDKCredentialsProvider)
50
+ );
62
51
 
63
- function AwsSigv4Signer(opts = {}) {
64
- const credentialsState = {
65
- credentials: null,
66
- };
67
- if (!opts.region) {
68
- throw new AwsSigv4SignerError('Region cannot be empty');
69
- }
70
- if (!opts.service) {
71
- opts.service = 'es';
72
- }
73
- if (typeof opts.getCredentials !== 'function') {
74
- opts.getCredentials = awsDefaultCredentialsProvider;
75
- }
76
-
77
- function buildSignedRequestObject(request = {}) {
78
- request.service = opts.service;
79
- request.region = opts.region;
80
- request.headers = request.headers || {};
81
- request.headers['host'] = request.hostname;
82
-
83
- if (request['auth']) {
84
- const awssigv4Cred = request['auth'];
85
- credentialsState.credentials = {
86
- accessKeyId: awssigv4Cred.credentials.accessKeyId,
87
- secretAccessKey: awssigv4Cred.credentials.secretAccessKey,
88
- sessionToken: awssigv4Cred.credentials.sessionToken,
89
- };
90
- request.region = awssigv4Cred.region;
91
- request.service = awssigv4Cred.service;
92
- delete request['auth'];
93
- }
94
- const signed = aws4.sign(request, credentialsState.credentials);
95
- signed.headers['x-amz-content-sha256'] = crypto
96
- .createHash('sha256')
97
- .update(request.body || '', 'utf8')
98
- .digest('hex');
99
- return signed;
100
- }
101
-
102
- class AwsSigv4SignerConnection extends Connection {
103
- buildRequestObject(params) {
104
- const request = super.buildRequestObject(params);
105
- return buildSignedRequestObject(request);
106
- }
107
- }
108
-
109
- class AwsSigv4SignerTransport extends Transport {
110
- request(params, options = {}, callback = undefined) {
111
- // options is optional so if options is a function, it's the callback.
112
- if (typeof options === 'function') {
113
- callback = options;
114
- options = {};
115
- }
116
-
117
- const currentCredentials = credentialsState.credentials;
118
- /**
119
- * For AWS SDK V3
120
- * Make sure token will expire no earlier than `expiryBufferMs` milliseconds in the future.
121
- */
122
- const expiryBufferMs = toMs(options.requestTimeout || this.requestTimeout);
123
-
124
- let expired = false;
125
- if (!currentCredentials) {
126
- // Credentials haven't been acquired yet.
127
- expired = true;
128
- }
129
- // AWS SDK V2, needsRefresh should be available.
130
- else if (typeof currentCredentials.needsRefresh === 'function') {
131
- expired = currentCredentials.needsRefresh();
132
- }
133
- // AWS SDK V2, alternative to needsRefresh.
134
- else if (currentCredentials.expired === true) {
135
- expired = true;
136
- }
137
- // AWS SDK V2, alternative to needsRefresh and expired.
138
- else if (currentCredentials.expireTime && currentCredentials.expireTime < new Date()) {
139
- expired = true;
140
- }
141
- // AWS SDK V3, Credentials.expiration is a Date object
142
- else if (
143
- currentCredentials.expiration &&
144
- currentCredentials.expiration.getTime() - Date.now() < expiryBufferMs
145
- ) {
146
- expired = true;
147
- }
148
-
149
- if (!expired) {
150
- if (typeof callback === 'undefined') {
151
- return super.request(params, options);
152
- }
153
- super.request(params, options, callback);
154
- return;
155
- }
156
-
157
- // In AWS SDK V2 Credentials.refreshPromise should be available.
158
- if (currentCredentials && typeof currentCredentials.refreshPromise === 'function') {
159
- if (typeof callback === 'undefined') {
160
- return currentCredentials.refreshPromise().then(() => {
161
- return super.request(params, options);
162
- });
163
- } else {
164
- currentCredentials
165
- .refreshPromise()
166
- .then(() => {
167
- super.request(params, options, callback);
168
- })
169
- .catch(callback);
170
- return;
171
- }
172
- }
173
-
174
- // For AWS SDK V3 or when the client has not acquired credentials yet.
175
- if (typeof callback === 'undefined') {
176
- return opts.getCredentials().then((credentials) => {
177
- credentialsState.credentials = credentials;
178
- return super.request(params, options);
179
- });
180
- } else {
181
- opts
182
- .getCredentials()
183
- .then((credentials) => {
184
- credentialsState.credentials = credentials;
185
- super.request(params, options, callback);
186
- })
187
- .catch(callback);
188
- }
189
- }
190
- }
191
-
192
- return {
193
- Transport: AwsSigv4SignerTransport,
194
- Connection: AwsSigv4SignerConnection,
195
- buildSignedRequestObject,
196
- };
197
- }
198
52
  module.exports = AwsSigv4Signer;
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright OpenSearch Contributors
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ *
5
+ * The OpenSearch Contributors require contributions made to
6
+ * this file be licensed under the Apache-2.0 license or a
7
+ * compatible open source license.
8
+ *
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ const AwsSigv4Signer = require('./AwsSigv4Signer-sdk-v3');
14
+ const AwsSigv4SignerError = require('./errors');
15
+
16
+ module.exports = {
17
+ AwsSigv4Signer,
18
+ AwsSigv4SignerError,
19
+ };
@@ -0,0 +1,172 @@
1
+ /*
2
+ * Copyright OpenSearch Contributors
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ *
5
+ * The OpenSearch Contributors require contributions made to
6
+ * this file be licensed under the Apache-2.0 license or a
7
+ * compatible open source license.
8
+ *
9
+ */
10
+
11
+ 'use strict';
12
+ const Connection = require('../Connection');
13
+ const Transport = require('../Transport');
14
+ const aws4 = require('aws4');
15
+ const AwsSigv4SignerError = require('./errors');
16
+ const crypto = require('crypto');
17
+ const { toMs } = Transport.internals;
18
+
19
+ function giveAwsCredentialProviderLoader(getAwsSDKCredentialsProvider) {
20
+ return function loadAwsCredentialProvider() {
21
+ return new Promise((resolve, reject) => {
22
+ getAwsSDKCredentialsProvider()
23
+ .then((provider) => {
24
+ provider().then(resolve).catch(reject);
25
+ })
26
+ .catch((err) => {
27
+ reject(err);
28
+ });
29
+ });
30
+ };
31
+ }
32
+
33
+ function giveAwsV4Signer(awsDefaultCredentialsProvider) {
34
+ return function AwsSigv4Signer(opts = {}) {
35
+ const credentialsState = {
36
+ credentials: null,
37
+ };
38
+ if (!opts.region) {
39
+ throw new AwsSigv4SignerError('Region cannot be empty');
40
+ }
41
+ if (!opts.service) {
42
+ opts.service = 'es';
43
+ }
44
+ if (typeof opts.getCredentials !== 'function') {
45
+ opts.getCredentials = awsDefaultCredentialsProvider;
46
+ }
47
+
48
+ function buildSignedRequestObject(request = {}) {
49
+ request.service = opts.service;
50
+ request.region = opts.region;
51
+ request.headers = request.headers || {};
52
+ request.headers['host'] = request.hostname;
53
+
54
+ if (request['auth']) {
55
+ const awssigv4Cred = request['auth'];
56
+ credentialsState.credentials = {
57
+ accessKeyId: awssigv4Cred.credentials.accessKeyId,
58
+ secretAccessKey: awssigv4Cred.credentials.secretAccessKey,
59
+ sessionToken: awssigv4Cred.credentials.sessionToken,
60
+ };
61
+ request.region = awssigv4Cred.region;
62
+ request.service = awssigv4Cred.service;
63
+ delete request['auth'];
64
+ }
65
+ const signed = aws4.sign(request, credentialsState.credentials);
66
+ signed.headers['x-amz-content-sha256'] = crypto
67
+ .createHash('sha256')
68
+ .update(request.body || '', 'utf8')
69
+ .digest('hex');
70
+ return signed;
71
+ }
72
+
73
+ class AwsSigv4SignerConnection extends Connection {
74
+ buildRequestObject(params) {
75
+ const request = super.buildRequestObject(params);
76
+ return buildSignedRequestObject(request);
77
+ }
78
+ }
79
+
80
+ class AwsSigv4SignerTransport extends Transport {
81
+ request(params, options = {}, callback = undefined) {
82
+ // options is optional so if options is a function, it's the callback.
83
+ if (typeof options === 'function') {
84
+ callback = options;
85
+ options = {};
86
+ }
87
+
88
+ const currentCredentials = credentialsState.credentials;
89
+ /**
90
+ * For AWS SDK V3
91
+ * Make sure token will expire no earlier than `expiryBufferMs` milliseconds in the future.
92
+ */
93
+ const expiryBufferMs = toMs(options.requestTimeout || this.requestTimeout);
94
+
95
+ let expired = false;
96
+ if (!currentCredentials) {
97
+ // Credentials haven't been acquired yet.
98
+ expired = true;
99
+ }
100
+ // AWS SDK V2, needsRefresh should be available.
101
+ else if (typeof currentCredentials.needsRefresh === 'function') {
102
+ expired = currentCredentials.needsRefresh();
103
+ }
104
+ // AWS SDK V2, alternative to needsRefresh.
105
+ else if (currentCredentials.expired === true) {
106
+ expired = true;
107
+ }
108
+ // AWS SDK V2, alternative to needsRefresh and expired.
109
+ else if (currentCredentials.expireTime && currentCredentials.expireTime < new Date()) {
110
+ expired = true;
111
+ }
112
+ // AWS SDK V3, Credentials.expiration is a Date object
113
+ else if (
114
+ currentCredentials.expiration &&
115
+ currentCredentials.expiration.getTime() - Date.now() < expiryBufferMs
116
+ ) {
117
+ expired = true;
118
+ }
119
+
120
+ if (!expired) {
121
+ if (typeof callback === 'undefined') {
122
+ return super.request(params, options);
123
+ }
124
+ super.request(params, options, callback);
125
+ return;
126
+ }
127
+
128
+ // In AWS SDK V2 Credentials.refreshPromise should be available.
129
+ if (currentCredentials && typeof currentCredentials.refreshPromise === 'function') {
130
+ if (typeof callback === 'undefined') {
131
+ return currentCredentials.refreshPromise().then(() => {
132
+ return super.request(params, options);
133
+ });
134
+ } else {
135
+ currentCredentials
136
+ .refreshPromise()
137
+ .then(() => {
138
+ super.request(params, options, callback);
139
+ })
140
+ .catch(callback);
141
+ return;
142
+ }
143
+ }
144
+
145
+ // For AWS SDK V3 or when the client has not acquired credentials yet.
146
+ if (typeof callback === 'undefined') {
147
+ return opts.getCredentials().then((credentials) => {
148
+ credentialsState.credentials = credentials;
149
+ return super.request(params, options);
150
+ });
151
+ } else {
152
+ opts
153
+ .getCredentials()
154
+ .then((credentials) => {
155
+ credentialsState.credentials = credentials;
156
+ super.request(params, options, callback);
157
+ })
158
+ .catch(callback);
159
+ }
160
+ }
161
+ }
162
+
163
+ return {
164
+ Transport: AwsSigv4SignerTransport,
165
+ Connection: AwsSigv4SignerConnection,
166
+ buildSignedRequestObject,
167
+ };
168
+ };
169
+ }
170
+
171
+ module.exports.giveAwsCredentialProviderLoader = giveAwsCredentialProviderLoader;
172
+ module.exports.giveAwsV4Signer = giveAwsV4Signer;
package/package.json CHANGED
@@ -16,6 +16,7 @@
16
16
  "types": "./api/types.d.ts"
17
17
  },
18
18
  "./aws": "./lib/aws/index.js",
19
+ "./aws-v3": "./lib/aws/index-v3.js",
19
20
  "./*": "./*"
20
21
  },
21
22
  "typesVersions": {
@@ -29,7 +30,7 @@
29
30
  }
30
31
  },
31
32
  "homepage": "https://www.opensearch.org/",
32
- "version": "2.6.0",
33
+ "version": "2.8.0",
33
34
  "versionCanary": "7.10.0-canary.6",
34
35
  "keywords": [
35
36
  "opensearch",
@@ -53,7 +54,7 @@
53
54
  "test:coverage-ui": "tap test/{unit,acceptance}/{*,**/*,**/**/*}.test.js --coverage --coverage-report=html --nyc-arg=\"--exclude=api\"",
54
55
  "lint": "eslint .",
55
56
  "lint:fix": "eslint . --fix",
56
- "license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause'",
57
+ "license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;0BSD;ISC;BSD-3-Clause;BSD-2-Clause'",
57
58
  "build-esm": "npx gen-esm-wrapper . index.mjs && eslint --fix index.mjs"
58
59
  },
59
60
  "author": "opensearch-project",