@opensearch-project/opensearch 2.4.0 → 2.6.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/index.d.ts CHANGED
@@ -54,6 +54,7 @@ import {
54
54
  CloudConnectionPool,
55
55
  ResurrectEvent,
56
56
  BasicAuth,
57
+ AwsSigv4Auth,
57
58
  } from './lib/pool';
58
59
  import Serializer from './lib/Serializer';
59
60
  import Helpers from './lib/Helpers';
@@ -126,7 +127,7 @@ interface ClientOptions {
126
127
  opaqueIdPrefix?: string;
127
128
  generateRequestId?: generateRequestIdFn;
128
129
  name?: string | symbol;
129
- auth?: BasicAuth;
130
+ auth?: BasicAuth | AwsSigv4Auth;
130
131
  context?: Context;
131
132
  proxy?: string | URL;
132
133
  enableMetaHeader?: boolean;
@@ -2073,6 +2074,53 @@ declare class Client {
2073
2074
  options: TransportRequestOptions,
2074
2075
  callback: callbackFn<TResponse, TContext>
2075
2076
  ): TransportRequestCallback;
2077
+ http: {
2078
+ connect<TResponse = Record<string, any>, TContext = Context>(
2079
+ params: RequestParams.HttpParams,
2080
+ options?: TransportRequestOptions,
2081
+ callback?: callbackFn<TResponse, TContext>
2082
+ ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2083
+ delete<TResponse = Record<string, any>, TContext = Context>(
2084
+ params: RequestParams.HttpParams,
2085
+ options?: TransportRequestOptions,
2086
+ callback?: callbackFn<TResponse, TContext>
2087
+ ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2088
+ get<TResponse = Record<string, any>, TContext = Context>(
2089
+ params: RequestParams.HttpParams,
2090
+ options?: TransportRequestOptions,
2091
+ callback?: callbackFn<TResponse, TContext>
2092
+ ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2093
+ head<TResponse = Record<string, any>, TContext = Context>(
2094
+ params: RequestParams.HttpParams,
2095
+ options?: TransportRequestOptions,
2096
+ callback?: callbackFn<TResponse, TContext>
2097
+ ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2098
+ options<TResponse = Record<string, any>, TContext = Context>(
2099
+ params: RequestParams.HttpParams,
2100
+ options?: TransportRequestOptions,
2101
+ callback?: callbackFn<TResponse, TContext>
2102
+ ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2103
+ patch<TResponse = Record<string, any>, TContext = Context>(
2104
+ params: RequestParams.HttpParams,
2105
+ options?: TransportRequestOptions,
2106
+ callback?: callbackFn<TResponse, TContext>
2107
+ ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2108
+ post<TResponse = Record<string, any>, TContext = Context>(
2109
+ params: RequestParams.HttpParams,
2110
+ options?: TransportRequestOptions,
2111
+ callback?: callbackFn<TResponse, TContext>
2112
+ ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2113
+ put<TResponse = Record<string, any>, TContext = Context>(
2114
+ params: RequestParams.HttpParams,
2115
+ options?: TransportRequestOptions,
2116
+ callback?: callbackFn<TResponse, TContext>
2117
+ ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2118
+ trace<TResponse = Record<string, any>, TContext = Context>(
2119
+ params: RequestParams.HttpParams,
2120
+ options?: TransportRequestOptions,
2121
+ callback?: callbackFn<TResponse, TContext>
2122
+ ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2123
+ };
2076
2124
  index<
2077
2125
  TResponse = Record<string, any>,
2078
2126
  TRequestBody extends RequestBody = Record<string, any>,
@@ -2360,33 +2408,41 @@ declare class Client {
2360
2408
  options: TransportRequestOptions,
2361
2409
  callback: callbackFn<TResponse, TContext>
2362
2410
  ): TransportRequestCallback;
2411
+ /** @deprecated use delete_index_template instead */
2363
2412
  delete_template<TResponse = Record<string, any>, TContext = Context>(
2364
2413
  params?: RequestParams.IndicesDeleteTemplate,
2365
2414
  options?: TransportRequestOptions
2366
2415
  ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2416
+ /** @deprecated use delete_index_template instead */
2367
2417
  delete_template<TResponse = Record<string, any>, TContext = Context>(
2368
2418
  callback: callbackFn<TResponse, TContext>
2369
2419
  ): TransportRequestCallback;
2420
+ /** @deprecated use delete_index_template instead */
2370
2421
  delete_template<TResponse = Record<string, any>, TContext = Context>(
2371
2422
  params: RequestParams.IndicesDeleteTemplate,
2372
2423
  callback: callbackFn<TResponse, TContext>
2373
2424
  ): TransportRequestCallback;
2425
+ /** @deprecated use delete_index_template instead */
2374
2426
  delete_template<TResponse = Record<string, any>, TContext = Context>(
2375
2427
  params: RequestParams.IndicesDeleteTemplate,
2376
2428
  options: TransportRequestOptions,
2377
2429
  callback: callbackFn<TResponse, TContext>
2378
2430
  ): TransportRequestCallback;
2431
+ /** @deprecated use deleteIndexTemplate instead */
2379
2432
  deleteTemplate<TResponse = Record<string, any>, TContext = Context>(
2380
2433
  params?: RequestParams.IndicesDeleteTemplate,
2381
2434
  options?: TransportRequestOptions
2382
2435
  ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2436
+ /** @deprecated use deleteIndexTemplate instead */
2383
2437
  deleteTemplate<TResponse = Record<string, any>, TContext = Context>(
2384
2438
  callback: callbackFn<TResponse, TContext>
2385
2439
  ): TransportRequestCallback;
2440
+ /** @deprecated use deleteIndexTemplate instead */
2386
2441
  deleteTemplate<TResponse = Record<string, any>, TContext = Context>(
2387
2442
  params: RequestParams.IndicesDeleteTemplate,
2388
2443
  callback: callbackFn<TResponse, TContext>
2389
2444
  ): TransportRequestCallback;
2445
+ /** @deprecated use deleteIndexTemplate instead */
2390
2446
  deleteTemplate<TResponse = Record<string, any>, TContext = Context>(
2391
2447
  params: RequestParams.IndicesDeleteTemplate,
2392
2448
  options: TransportRequestOptions,
@@ -2504,33 +2560,41 @@ declare class Client {
2504
2560
  options: TransportRequestOptions,
2505
2561
  callback: callbackFn<TResponse, TContext>
2506
2562
  ): TransportRequestCallback;
2563
+ /** @deprecated use exists_index_template instead */
2507
2564
  exists_template<TResponse = boolean, TContext = Context>(
2508
2565
  params?: RequestParams.IndicesExistsTemplate,
2509
2566
  options?: TransportRequestOptions
2510
2567
  ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2568
+ /** @deprecated use exists_index_template instead */
2511
2569
  exists_template<TResponse = boolean, TContext = Context>(
2512
2570
  callback: callbackFn<TResponse, TContext>
2513
2571
  ): TransportRequestCallback;
2572
+ /** @deprecated use exists_index_template instead */
2514
2573
  exists_template<TResponse = boolean, TContext = Context>(
2515
2574
  params: RequestParams.IndicesExistsTemplate,
2516
2575
  callback: callbackFn<TResponse, TContext>
2517
2576
  ): TransportRequestCallback;
2577
+ /** @deprecated use exists_index_template instead */
2518
2578
  exists_template<TResponse = boolean, TContext = Context>(
2519
2579
  params: RequestParams.IndicesExistsTemplate,
2520
2580
  options: TransportRequestOptions,
2521
2581
  callback: callbackFn<TResponse, TContext>
2522
2582
  ): TransportRequestCallback;
2583
+ /** @deprecated use existsIndexTemplate instead */
2523
2584
  existsTemplate<TResponse = boolean, TContext = Context>(
2524
2585
  params?: RequestParams.IndicesExistsTemplate,
2525
2586
  options?: TransportRequestOptions
2526
2587
  ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2588
+ /** @deprecated use existsIndexTemplate instead */
2527
2589
  existsTemplate<TResponse = boolean, TContext = Context>(
2528
2590
  callback: callbackFn<TResponse, TContext>
2529
2591
  ): TransportRequestCallback;
2592
+ /** @deprecated use existsIndexTemplate instead */
2530
2593
  existsTemplate<TResponse = boolean, TContext = Context>(
2531
2594
  params: RequestParams.IndicesExistsTemplate,
2532
2595
  callback: callbackFn<TResponse, TContext>
2533
2596
  ): TransportRequestCallback;
2597
+ /** @deprecated use existsIndexTemplate instead */
2534
2598
  existsTemplate<TResponse = boolean, TContext = Context>(
2535
2599
  params: RequestParams.IndicesExistsTemplate,
2536
2600
  options: TransportRequestOptions,
@@ -2776,33 +2840,41 @@ declare class Client {
2776
2840
  options: TransportRequestOptions,
2777
2841
  callback: callbackFn<TResponse, TContext>
2778
2842
  ): TransportRequestCallback;
2843
+ /** @deprecated use get_index_template instead */
2779
2844
  get_template<TResponse = Record<string, any>, TContext = Context>(
2780
2845
  params?: RequestParams.IndicesGetTemplate,
2781
2846
  options?: TransportRequestOptions
2782
2847
  ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2848
+ /** @deprecated use get_index_template instead */
2783
2849
  get_template<TResponse = Record<string, any>, TContext = Context>(
2784
2850
  callback: callbackFn<TResponse, TContext>
2785
2851
  ): TransportRequestCallback;
2852
+ /** @deprecated use get_index_template instead */
2786
2853
  get_template<TResponse = Record<string, any>, TContext = Context>(
2787
2854
  params: RequestParams.IndicesGetTemplate,
2788
2855
  callback: callbackFn<TResponse, TContext>
2789
2856
  ): TransportRequestCallback;
2857
+ /** @deprecated use get_index_template instead */
2790
2858
  get_template<TResponse = Record<string, any>, TContext = Context>(
2791
2859
  params: RequestParams.IndicesGetTemplate,
2792
2860
  options: TransportRequestOptions,
2793
2861
  callback: callbackFn<TResponse, TContext>
2794
2862
  ): TransportRequestCallback;
2863
+ /** @deprecated use getIndexTemplate instead */
2795
2864
  getTemplate<TResponse = Record<string, any>, TContext = Context>(
2796
2865
  params?: RequestParams.IndicesGetTemplate,
2797
2866
  options?: TransportRequestOptions
2798
2867
  ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
2868
+ /** @deprecated use getIndexTemplate instead */
2799
2869
  getTemplate<TResponse = Record<string, any>, TContext = Context>(
2800
2870
  callback: callbackFn<TResponse, TContext>
2801
2871
  ): TransportRequestCallback;
2872
+ /** @deprecated use getIndexTemplate instead */
2802
2873
  getTemplate<TResponse = Record<string, any>, TContext = Context>(
2803
2874
  params: RequestParams.IndicesGetTemplate,
2804
2875
  callback: callbackFn<TResponse, TContext>
2805
2876
  ): TransportRequestCallback;
2877
+ /** @deprecated use getIndexTemplate instead */
2806
2878
  getTemplate<TResponse = Record<string, any>, TContext = Context>(
2807
2879
  params: RequestParams.IndicesGetTemplate,
2808
2880
  options: TransportRequestOptions,
@@ -3112,6 +3184,7 @@ declare class Client {
3112
3184
  options: TransportRequestOptions,
3113
3185
  callback: callbackFn<TResponse, TContext>
3114
3186
  ): TransportRequestCallback;
3187
+ /** @deprecated use put_index_template instead */
3115
3188
  put_template<
3116
3189
  TResponse = Record<string, any>,
3117
3190
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3120,6 +3193,7 @@ declare class Client {
3120
3193
  params?: RequestParams.IndicesPutTemplate<TRequestBody>,
3121
3194
  options?: TransportRequestOptions
3122
3195
  ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
3196
+ /** @deprecated use put_index_template instead */
3123
3197
  put_template<
3124
3198
  TResponse = Record<string, any>,
3125
3199
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3127,6 +3201,7 @@ declare class Client {
3127
3201
  >(
3128
3202
  callback: callbackFn<TResponse, TContext>
3129
3203
  ): TransportRequestCallback;
3204
+ /** @deprecated use put_index_template instead */
3130
3205
  put_template<
3131
3206
  TResponse = Record<string, any>,
3132
3207
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3135,6 +3210,7 @@ declare class Client {
3135
3210
  params: RequestParams.IndicesPutTemplate<TRequestBody>,
3136
3211
  callback: callbackFn<TResponse, TContext>
3137
3212
  ): TransportRequestCallback;
3213
+ /** @deprecated use put_index_template instead */
3138
3214
  put_template<
3139
3215
  TResponse = Record<string, any>,
3140
3216
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3144,6 +3220,7 @@ declare class Client {
3144
3220
  options: TransportRequestOptions,
3145
3221
  callback: callbackFn<TResponse, TContext>
3146
3222
  ): TransportRequestCallback;
3223
+ /** @deprecated use putIndexTemplate instead */
3147
3224
  putTemplate<
3148
3225
  TResponse = Record<string, any>,
3149
3226
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3152,6 +3229,7 @@ declare class Client {
3152
3229
  params?: RequestParams.IndicesPutTemplate<TRequestBody>,
3153
3230
  options?: TransportRequestOptions
3154
3231
  ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
3232
+ /** @deprecated use putIndexTemplate instead */
3155
3233
  putTemplate<
3156
3234
  TResponse = Record<string, any>,
3157
3235
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3159,6 +3237,7 @@ declare class Client {
3159
3237
  >(
3160
3238
  callback: callbackFn<TResponse, TContext>
3161
3239
  ): TransportRequestCallback;
3240
+ /** @deprecated use putIndexTemplate instead */
3162
3241
  putTemplate<
3163
3242
  TResponse = Record<string, any>,
3164
3243
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3167,6 +3246,7 @@ declare class Client {
3167
3246
  params: RequestParams.IndicesPutTemplate<TRequestBody>,
3168
3247
  callback: callbackFn<TResponse, TContext>
3169
3248
  ): TransportRequestCallback;
3249
+ /** @deprecated use putIndexTemplate instead */
3170
3250
  putTemplate<
3171
3251
  TResponse = Record<string, any>,
3172
3252
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3416,6 +3496,7 @@ declare class Client {
3416
3496
  options: TransportRequestOptions,
3417
3497
  callback: callbackFn<TResponse, TContext>
3418
3498
  ): TransportRequestCallback;
3499
+ /** @deprecated use simulate_index_template instead */
3419
3500
  simulate_template<
3420
3501
  TResponse = Record<string, any>,
3421
3502
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3424,6 +3505,7 @@ declare class Client {
3424
3505
  params?: RequestParams.IndicesSimulateTemplate<TRequestBody>,
3425
3506
  options?: TransportRequestOptions
3426
3507
  ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
3508
+ /** @deprecated use simulate_index_template instead */
3427
3509
  simulate_template<
3428
3510
  TResponse = Record<string, any>,
3429
3511
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3431,6 +3513,7 @@ declare class Client {
3431
3513
  >(
3432
3514
  callback: callbackFn<TResponse, TContext>
3433
3515
  ): TransportRequestCallback;
3516
+ /** @deprecated use simulate_index_template instead */
3434
3517
  simulate_template<
3435
3518
  TResponse = Record<string, any>,
3436
3519
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3439,6 +3522,7 @@ declare class Client {
3439
3522
  params: RequestParams.IndicesSimulateTemplate<TRequestBody>,
3440
3523
  callback: callbackFn<TResponse, TContext>
3441
3524
  ): TransportRequestCallback;
3525
+ /** @deprecated use simulate_index_template instead */
3442
3526
  simulate_template<
3443
3527
  TResponse = Record<string, any>,
3444
3528
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3448,6 +3532,7 @@ declare class Client {
3448
3532
  options: TransportRequestOptions,
3449
3533
  callback: callbackFn<TResponse, TContext>
3450
3534
  ): TransportRequestCallback;
3535
+ /** @deprecated use simulateIndexTemplate instead */
3451
3536
  simulateTemplate<
3452
3537
  TResponse = Record<string, any>,
3453
3538
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3456,6 +3541,7 @@ declare class Client {
3456
3541
  params?: RequestParams.IndicesSimulateTemplate<TRequestBody>,
3457
3542
  options?: TransportRequestOptions
3458
3543
  ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
3544
+ /** @deprecated use simulateIndexTemplate instead */
3459
3545
  simulateTemplate<
3460
3546
  TResponse = Record<string, any>,
3461
3547
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3463,6 +3549,7 @@ declare class Client {
3463
3549
  >(
3464
3550
  callback: callbackFn<TResponse, TContext>
3465
3551
  ): TransportRequestCallback;
3552
+ /** @deprecated use simulateIndexTemplate instead */
3466
3553
  simulateTemplate<
3467
3554
  TResponse = Record<string, any>,
3468
3555
  TRequestBody extends RequestBody = Record<string, any>,
@@ -3471,6 +3558,7 @@ declare class Client {
3471
3558
  params: RequestParams.IndicesSimulateTemplate<TRequestBody>,
3472
3559
  callback: callbackFn<TResponse, TContext>
3473
3560
  ): TransportRequestCallback;
3561
+ /** @deprecated use simulateIndexTemplate instead */
3474
3562
  simulateTemplate<
3475
3563
  TResponse = Record<string, any>,
3476
3564
  TRequestBody extends RequestBody = Record<string, any>,
package/index.js CHANGED
@@ -192,6 +192,7 @@ class Client extends OpenSearchAPI {
192
192
  opaqueIdPrefix: options.opaqueIdPrefix,
193
193
  context: options.context,
194
194
  memoryCircuitBreaker: options.memoryCircuitBreaker,
195
+ auth: options.auth,
195
196
  });
196
197
 
197
198
  this.helpers = new Helpers({
@@ -32,7 +32,7 @@
32
32
  import { URL } from 'url';
33
33
  import { inspect, InspectOptions } from 'util';
34
34
  import { Readable as ReadableStream } from 'stream';
35
- import { BasicAuth } from './pool';
35
+ import { BasicAuth, AwsSigv4Auth } from './pool';
36
36
  import * as http from 'http';
37
37
  import * as https from 'https';
38
38
  import * as hpagent from 'hpagent';
@@ -48,7 +48,7 @@ export interface ConnectionOptions {
48
48
  agent?: AgentOptions | agentFn;
49
49
  status?: string;
50
50
  roles?: ConnectionRoles;
51
- auth?: BasicAuth;
51
+ auth?: BasicAuth | AwsSigv4Auth;
52
52
  proxy?: string | URL;
53
53
  }
54
54
 
@@ -30,7 +30,7 @@
30
30
  import { Readable as ReadableStream } from 'stream';
31
31
  import Connection from './Connection';
32
32
  import * as errors from './errors';
33
- import { CloudConnectionPool, ConnectionPool } from './pool';
33
+ import { CloudConnectionPool, ConnectionPool, BasicAuth, AwsSigv4Auth } from './pool';
34
34
  import Serializer from './Serializer';
35
35
 
36
36
  export type ApiError =
@@ -82,6 +82,7 @@ interface TransportOptions {
82
82
  name?: string;
83
83
  opaqueIdPrefix?: string;
84
84
  memoryCircuitBreaker?: MemoryCircuitBreakerOptions;
85
+ auth?: BasicAuth | AwsSigv4Auth;
85
86
  }
86
87
 
87
88
  export interface RequestEvent<TResponse = Record<string, any>, TContext = Context> {
package/lib/Transport.js CHANGED
@@ -101,6 +101,7 @@ class Transport {
101
101
  this._sniffEnabled = typeof this.sniffInterval === 'number';
102
102
  this._nextSniff = this._sniffEnabled ? Date.now() + this.sniffInterval : 0;
103
103
  this._isSniffing = false;
104
+ this._auth = opts.auth;
104
105
 
105
106
  if (opts.sniffOnStart === true) {
106
107
  // timer needed otherwise it will clash
@@ -197,8 +198,8 @@ class Transport {
197
198
  isStream(params.body) || isStream(params.bulkBody)
198
199
  ? 0
199
200
  : typeof options.maxRetries === 'number'
200
- ? options.maxRetries
201
- : this.maxRetries;
201
+ ? options.maxRetries
202
+ : this.maxRetries;
202
203
  const compression = options.compression !== undefined ? options.compression : this.compression;
203
204
  let request = { abort: noop };
204
205
  const transportReturn = {
@@ -495,6 +496,9 @@ class Transport {
495
496
  Object.assign({}, params.querystring, options.querystring)
496
497
  );
497
498
  }
499
+ if (this._auth !== null && typeof this._auth === 'object' && 'credentials' in this._auth) {
500
+ params.auth = this._auth;
501
+ }
498
502
 
499
503
  // handles request timeout
500
504
  params.timeout = toMs(options.requestTimeout || this.requestTimeout);
@@ -729,4 +733,5 @@ module.exports.internals = {
729
733
  randomSelector,
730
734
  generateRequestId,
731
735
  lowerCaseHeaders,
736
+ toMs,
732
737
  };
@@ -14,6 +14,7 @@ const Transport = require('../Transport');
14
14
  const aws4 = require('aws4');
15
15
  const AwsSigv4SignerError = require('./errors');
16
16
  const crypto = require('crypto');
17
+ const { toMs } = Transport.internals;
17
18
 
18
19
  const getAwsSDKCredentialsProvider = async () => {
19
20
  // First try V3
@@ -78,6 +79,18 @@ function AwsSigv4Signer(opts = {}) {
78
79
  request.region = opts.region;
79
80
  request.headers = request.headers || {};
80
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
+ }
81
94
  const signed = aws4.sign(request, credentialsState.credentials);
82
95
  signed.headers['x-amz-content-sha256'] = crypto
83
96
  .createHash('sha256')
@@ -102,6 +115,12 @@ function AwsSigv4Signer(opts = {}) {
102
115
  }
103
116
 
104
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
+
105
124
  let expired = false;
106
125
  if (!currentCredentials) {
107
126
  // Credentials haven't been acquired yet.
@@ -120,7 +139,10 @@ function AwsSigv4Signer(opts = {}) {
120
139
  expired = true;
121
140
  }
122
141
  // AWS SDK V3, Credentials.expiration is a Date object
123
- else if (currentCredentials.expiration && currentCredentials.expiration < new Date()) {
142
+ else if (
143
+ currentCredentials.expiration &&
144
+ currentCredentials.expiration.getTime() - Date.now() < expiryBufferMs
145
+ ) {
124
146
  expired = true;
125
147
  }
126
148
 
@@ -38,7 +38,7 @@ interface BaseConnectionPoolOptions {
38
38
  ssl?: SecureContextOptions;
39
39
  agent?: AgentOptions;
40
40
  proxy?: string | URL;
41
- auth?: BasicAuth;
41
+ auth?: BasicAuth | AwsSigv4Auth;
42
42
  emit: (event: string | symbol, ...args: any[]) => boolean;
43
43
  Connection: typeof Connection;
44
44
  }
@@ -62,6 +62,16 @@ interface BasicAuth {
62
62
  password: string;
63
63
  }
64
64
 
65
+ interface AwsSigv4Auth {
66
+ credentials : {
67
+ accessKeyId: string;
68
+ secretAccessKey: string;
69
+ sessionToken: string;
70
+ }
71
+ region: string;
72
+ service: string;
73
+ }
74
+
65
75
  interface resurrectOptions {
66
76
  now?: number;
67
77
  requestId: string;
@@ -85,7 +95,7 @@ declare class BaseConnectionPool {
85
95
  _ssl: SecureContextOptions | null;
86
96
  _agent: AgentOptions | null;
87
97
  _proxy: string | URL;
88
- auth: BasicAuth;
98
+ auth: BasicAuth | AwsSigv4Auth;
89
99
  Connection: typeof Connection;
90
100
  constructor(opts?: BaseConnectionPoolOptions);
91
101
  /**
@@ -235,6 +245,7 @@ export {
235
245
  ConnectionPoolOptions,
236
246
  getConnectionOptions,
237
247
  BasicAuth,
248
+ AwsSigv4Auth,
238
249
  internals,
239
250
  resurrectOptions,
240
251
  ResurrectEvent,
package/lib/tools.d.ts ADDED
@@ -0,0 +1,11 @@
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
+ export function strongPasswordRequired(os_version?: string): boolean;
package/lib/tools.js ADDED
@@ -0,0 +1,21 @@
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
+ function strongPasswordRequired(os_version = process.env.OPENSEARCH_VERSION) {
12
+ // OpenSearch 2.12.X and later require strong passwords
13
+ if (os_version === undefined)
14
+ throw new Error('OPENSEARCH_VERSION environment variable is not set');
15
+ if (os_version === 'latest') return true;
16
+ const [major, minor] = os_version.split('.');
17
+ if (parseInt(major) > 2) return true;
18
+ return major === '2' && (minor === 'x' || parseInt(minor) >= 12);
19
+ }
20
+
21
+ module.exports = { strongPasswordRequired };
package/package.json CHANGED
@@ -9,6 +9,12 @@
9
9
  "types": "./index.d.ts",
10
10
  "import": "./index.mjs"
11
11
  },
12
+ "./api/new": {
13
+ "types": "./api/new.d.ts"
14
+ },
15
+ "./api/types": {
16
+ "types": "./api/types.d.ts"
17
+ },
12
18
  "./aws": "./lib/aws/index.js",
13
19
  "./*": "./*"
14
20
  },
@@ -23,7 +29,7 @@
23
29
  }
24
30
  },
25
31
  "homepage": "https://www.opensearch.org/",
26
- "version": "2.4.0",
32
+ "version": "2.6.0",
27
33
  "versionCanary": "7.10.0-canary.6",
28
34
  "keywords": [
29
35
  "opensearch",
@@ -75,7 +81,7 @@
75
81
  "license-checker": "^25.0.1",
76
82
  "minimist": "^1.2.5",
77
83
  "node-fetch": "^3.2.10",
78
- "ora": "^7.0.1",
84
+ "ora": "^8.0.1",
79
85
  "prettier": "^3.0.1",
80
86
  "pretty-hrtime": "^1.0.3",
81
87
  "proxy": "^1.0.2",
@@ -0,0 +1,17 @@
1
+ # OpenSearch JavaScript Samples
2
+
3
+ The following will set up a single node OpenSearch instance with the default admin password `myStrongPassword123!`, which we will use to instantiate a client in all samples.
4
+
5
+ ```shell
6
+ docker pull opensearchproject/opensearch:latest
7
+ docker run -d -p 9200:9200 -p 9600:9600 \
8
+ -e 'discovery.type=single-node' -e 'OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!' \
9
+ opensearchproject/opensearch:latest
10
+ ```
11
+
12
+ ## Run Samples
13
+
14
+ To run the `json.js` sample:
15
+ ```shell
16
+ node json.js
17
+ ```
@@ -0,0 +1,91 @@
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
+ // For more information on how to make custom HTTP requests, check out: ./guides/bulk.md
12
+
13
+ const { Client } = require('@opensearch-project/opensearch');
14
+
15
+ // Instantiate a client with basic auth as setup in the README.md file
16
+ const client = new Client({
17
+ ssl: {
18
+ rejectUnauthorized: false,
19
+ },
20
+ node: 'https://localhost:9200',
21
+ auth: {
22
+ username: 'admin',
23
+ password: 'myStrongPassword123!',
24
+ },
25
+ });
26
+
27
+ const start = async () => {
28
+ const movies = 'movies';
29
+ const books = 'books';
30
+
31
+ if ((await client.indices.exists({ index: movies })).body)
32
+ await client.indices.delete({ index: movies });
33
+ if ((await client.indices.exists({ index: books })).body)
34
+ await client.indices.delete({ index: books });
35
+
36
+ await client.indices.create({ index: movies });
37
+ await client.indices.create({ index: books });
38
+
39
+ client
40
+ .bulk({
41
+ index: movies,
42
+ body: [
43
+ { create: {} },
44
+ { title: 'Beauty and the Beast', year: 2030, director: 'Ella' },
45
+ { index: {} },
46
+ { title: 'Snow White', year: 2031, director: 'Jake' },
47
+ { create: {} },
48
+ { title: 'Cinderella', year: 2032, director: 'Clyde' },
49
+ ],
50
+ })
51
+ .then((response) => {
52
+ console.log(response.body.items);
53
+ });
54
+
55
+ client
56
+ .bulk({
57
+ index: movies,
58
+ body: [
59
+ { create: { _id: 1 } },
60
+ { title: 'Beauty and the Beast 1', year: 2050 },
61
+ { delete: { _id: 1 } },
62
+ { create: { _id: 2 } },
63
+ { title: 'Beauty and the Beast 2', year: 2051 },
64
+ { create: {} },
65
+ { title: 'Beauty and the Beast 2', year: 2051 },
66
+ { create: { _index: books } },
67
+ { title: '2012', year: 2012 },
68
+ ],
69
+ })
70
+ .then((response) => {
71
+ console.log(response.body.items);
72
+ });
73
+
74
+ const docs = [
75
+ { title: 'Beauty and the Beast 1', year: 2050 },
76
+ { title: 'Beauty and the Beast 2', year: 2051 },
77
+ ];
78
+
79
+ client.helpers
80
+ .bulk({
81
+ datasource: docs,
82
+ onDocument(_) {
83
+ return { index: { _index: movies } };
84
+ },
85
+ })
86
+ .then((result) => {
87
+ console.log(result);
88
+ });
89
+ };
90
+
91
+ start().then(() => console.log('done'));