@opensearch-project/opensearch 2.10.0 → 2.11.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
@@ -11,6 +11,23 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
11
11
  ### Fixed
12
12
  ### Security
13
13
 
14
+ ## [2.11.0]
15
+ ### Changed
16
+ - Return a transport object from `AwsSigv4SignerTransport.request` that has an `.abort()` method that allows in-flight requests to be canceled
17
+ ### Dependencies
18
+ - Bumps `@aws-sdk/types` from 3.577.0 to 3.609.0
19
+ - Bumps `@babel/eslint-parser` from 7.24.7 to 7.24.8
20
+ - Bumps `@types/node` from20.14.2 to 20.14.11
21
+ - Bumps `eslint-plugin-prettier` from 5.1.3 to 5.2.1
22
+ - Bumps `faker` from 5.5.3 to 6.6.6
23
+ - Bumps `prettier` from 3.3.1 to 3.3.3
24
+ - Bumps `rimraf` from 5.0.7 to 6.0.1
25
+ - Bumps `semver` from 7.6.2 to 7.6.3
26
+ - Bumps `simple-git` from 3.24.0 to 3.25.0
27
+ - Bumps `ws` from 7.5.9 to 7.5.10
28
+ ### Fixed
29
+ - Add missing types in `package.json` for `aws-v3` ([810](https://github.com/opensearch-project/opensearch-js/pull/810))
30
+
14
31
  ## [2.10.0]
15
32
  ### Added
16
33
  - Added Rollups API ([744](https://github.com/opensearch-project/opensearch-js/issues/744))
@@ -253,4 +270,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
253
270
  - Bumps `tsd` from 0.22.0 to 0.24.1
254
271
  - Bumps `semver` from 7.3.7 to 7.3.8
255
272
  ### Fixed
256
- - Fix mutability of connection headers ([#291](https://github.com/opensearch-project/opensearch-js/issues/291))
273
+ - Fix mutability of connection headers ([#291](https://github.com/opensearch-project/opensearch-js/issues/291))
package/lib/aws/shared.js CHANGED
@@ -13,9 +13,12 @@ const Connection = require('../Connection');
13
13
  const Transport = require('../Transport');
14
14
  const aws4 = require('aws4');
15
15
  const AwsSigv4SignerError = require('./errors');
16
+ const { RequestAbortedError } = require('../errors');
16
17
  const crypto = require('crypto');
17
18
  const { toMs } = Transport.internals;
18
19
 
20
+ const noop = () => {};
21
+
19
22
  function giveAwsCredentialProviderLoader(getAwsSDKCredentialsProvider) {
20
23
  return function loadAwsCredentialProvider() {
21
24
  return new Promise((resolve, reject) => {
@@ -118,45 +121,88 @@ function giveAwsV4Signer(awsDefaultCredentialsProvider) {
118
121
  }
119
122
 
120
123
  if (!expired) {
121
- if (typeof callback === 'undefined') {
124
+ if (callback === undefined) {
122
125
  return super.request(params, options);
126
+ } else {
127
+ return super.request(params, options, callback);
123
128
  }
124
- super.request(params, options, callback);
125
- return;
126
129
  }
127
130
 
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 {
131
+ let p = null;
132
+
133
+ // promises support
134
+ if (callback === undefined) {
135
+ let onFulfilled = null;
136
+ let onRejected = null;
137
+ p = new Promise((resolve, reject) => {
138
+ onFulfilled = resolve;
139
+ onRejected = reject;
140
+ });
141
+ callback = function callback(err, result) {
142
+ err ? onRejected(err) : onFulfilled(result);
143
+ };
144
+ }
145
+
146
+ const meta = {
147
+ aborted: false,
148
+ };
149
+
150
+ let request = { abort: noop };
151
+
152
+ const transportReturn = {
153
+ then(onFulfilled, onRejected) {
154
+ if (p != null) {
155
+ return p.then(onFulfilled, onRejected);
156
+ }
157
+ },
158
+ catch(onRejected) {
159
+ if (p != null) {
160
+ return p.catch(onRejected);
161
+ }
162
+ },
163
+ abort() {
164
+ meta.aborted = true;
165
+ request.abort();
166
+ return this;
167
+ },
168
+ finally(onFinally) {
169
+ if (p != null) {
170
+ return p.finally(onFinally);
171
+ }
172
+ },
173
+ };
174
+
175
+ const makeRequest = () => {
176
+ // In AWS SDK V2 Credentials.refreshPromise should be available.
177
+ if (currentCredentials && typeof currentCredentials.refreshPromise === 'function') {
135
178
  currentCredentials
136
179
  .refreshPromise()
137
180
  .then(() => {
138
- super.request(params, options, callback);
181
+ if (meta.aborted) {
182
+ return callback(new RequestAbortedError());
183
+ }
184
+ request = super.request(params, options, callback);
139
185
  })
140
186
  .catch(callback);
141
- return;
142
187
  }
143
- }
188
+ // For AWS SDK V3.
189
+ else {
190
+ opts
191
+ .getCredentials()
192
+ .then((credentials) => {
193
+ if (meta.aborted) {
194
+ return callback(new RequestAbortedError());
195
+ }
196
+ credentialsState.credentials = credentials;
197
+ request = super.request(params, options, callback);
198
+ })
199
+ .catch(callback);
200
+ }
201
+ };
144
202
 
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
- }
203
+ makeRequest();
204
+
205
+ return transportReturn;
160
206
  }
161
207
  }
162
208
 
package/package.json CHANGED
@@ -26,11 +26,14 @@
26
26
  ],
27
27
  "aws": [
28
28
  "./lib/aws/index.d.ts"
29
+ ],
30
+ "aws-v3": [
31
+ "./lib/aws/index-v3.d.ts"
29
32
  ]
30
33
  }
31
34
  },
32
35
  "homepage": "https://www.opensearch.org/",
33
- "version": "2.10.0",
36
+ "version": "2.11.0",
34
37
  "versionCanary": "7.10.0-canary.6",
35
38
  "keywords": [
36
39
  "opensearch",
@@ -75,7 +78,7 @@
75
78
  "eslint": "^8.30.0",
76
79
  "eslint-config-prettier": "^9.0.0",
77
80
  "eslint-plugin-prettier": "^5.0.0",
78
- "faker": "^5.5.3",
81
+ "faker": "^6.6.6",
79
82
  "fast-deep-equal": "^3.1.3",
80
83
  "into-stream": "^6.0.0",
81
84
  "js-yaml": "^4.1.0",
@@ -87,7 +90,7 @@
87
90
  "prettier": "^3.0.1",
88
91
  "pretty-hrtime": "^1.0.3",
89
92
  "proxy": "^1.0.2",
90
- "rimraf": "^5.0.0",
93
+ "rimraf": "^6.0.1",
91
94
  "semver": "^7.3.5",
92
95
  "simple-git": "^3.15.0",
93
96
  "simple-statistics": "^7.7.0",