diff --git a/api/api/http.js b/api/api/http.js new file mode 100644 index 000000000..9fff29dfd --- /dev/null +++ b/api/api/http.js @@ -0,0 +1,193 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + +'use strict'; + +/** @namespace API-HTTP */ + +const { normalizeArguments, kConfigurationError } = require('../utils'); + +function HttpApi(transport, ConfigurationError) { + this.transport = transport; + this[kConfigurationError] = ConfigurationError; +} + +HttpApi.prototype.request = function (method, params, options, callback) { + [params, options, callback] = normalizeArguments(params, options, callback); + if (Array.isArray(params.body)) { + params.bulkBody = params.body; + delete params.body; + } + options = options || {}; + options.headers = params.headers || options.headers; + return this.transport.request({ ...params, method }, options, callback); +}; + +/** + * Make a customized CONNECT request. + * + * @memberOf API-HTTP + * + * @param {Object} params + * @param {Object} params.path - The URL of the request + * @param {Object} [params.querystring] - The querystring parameters + * @param {Object} [params.headers] - The request headers + * @param {Object} [params.body] - The request body + * + * @param {Object} [options] - Options for {@link Transport#request} + * @param {function} [callback] - Callback that handles errors and response + * + * @returns {{abort: function(), then: function(), catch: function()}|Promise|*} + */ +HttpApi.prototype.connect = function (params, options, callback) { + return this.request('CONNECT', params, options, callback); +}; + +/** + * Make a customized DELETE request. + * + * @memberOf API-HTTP + * + * @param {Object} params + * @param {Object} params.path - The URL of the request + * @param {Object} [params.querystring] - The querystring parameters + * @param {Object} [params.headers] - The request headers + * @param {Object} [params.body] - The request body + * + * @param {Object} [options] - Options for {@link Transport#request} + * @param {function} [callback] - Callback that handles errors and response + * + * @returns {{abort: function(), then: function(), catch: function()}|Promise|*} + */ +HttpApi.prototype.delete = function (params, options, callback) { + return this.request('DELETE', params, options, callback); +}; + +/** + * Make a customized GET request. + * + * @memberOf API-HTTP + * + * @param {Object} params + * @param {Object} params.path - The URL of the request + * @param {Object} [params.querystring] - The querystring parameters + * @param {Object} [params.headers] - The request headers + * @param {Object} [params.body] - The request body + * + * @param {Object} [options] - Options for {@link Transport#request} + * @param {function} [callback] - Callback that handles errors and response + * + * @returns {{abort: function(), then: function(), catch: function()}|Promise|*} + */ +HttpApi.prototype.get = function (params, options, callback) { + return this.request('GET', params, options, callback); +}; + +/** + * Make a customized HEAD request. + * + * @memberOf API-HTTP + * + * @param {Object} params + * @param {Object} params.path - The URL of the request + * @param {Object} [params.querystring] - The querystring parameters + * @param {Object} [params.headers] - The request headers + * @param {Object} [params.body] - The request body + * + * @param {Object} [options] - Options for {@link Transport#request} + * @param {function} [callback] - Callback that handles errors and response + * + * @returns {{abort: function(), then: function(), catch: function()}|Promise|*} + */ +HttpApi.prototype.head = function (params, options, callback) { + return this.request('HEAD', params, options, callback); +}; + +/** + * Make a customized OPTIONS request. + * + * @memberOf API-HTTP + * + * @param {Object} params + * @param {Object} params.path - The URL of the request + * @param {Object} [params.querystring] - The querystring parameters + * @param {Object} [params.headers] - The request headers + * @param {Object} [params.body] - The request body + * + * @param {Object} [options] - Options for {@link Transport#request} + * @param {function} [callback] - Callback that handles errors and response + * + * @returns {{abort: function(), then: function(), catch: function()}|Promise|*} + */ +HttpApi.prototype.options = function (params, options, callback) { + return this.request('OPTIONS', params, options, callback); +}; + +/** + * Make a customized POST request. + * + * @memberOf API-HTTP + * + * @param {Object} params + * @param {Object} params.path - The URL of the request + * @param {Object} [params.querystring] - The querystring parameters + * @param {Object} [params.headers] - The request headers + * @param {Object} [params.body] - The request body + * + * @param {Object} [options] - Options for {@link Transport#request} + * @param {function} [callback] - Callback that handles errors and response + * + * @returns {{abort: function(), then: function(), catch: function()}|Promise|*} + */ +HttpApi.prototype.post = function (params, options, callback) { + return this.request('POST', params, options, callback); +}; + +/** + * Make a customized PUT request. + * + * @memberOf API-HTTP + * + * @param {Object} params + * @param {Object} params.path - The URL of the request + * @param {Object} [params.querystring] - The querystring parameters + * @param {Object} [params.headers] - The request headers + * @param {Object} [params.body] - The request body + * + * @param {Object} [options] - Options for {@link Transport#request} + * @param {function} [callback] - Callback that handles errors and response + * + * @returns {{abort: function(), then: function(), catch: function()}|Promise|*} + */ +HttpApi.prototype.put = function (params, options, callback) { + return this.request('PUT', params, options, callback); +}; + +/** + * Make a customized TRACE request. + * + * @memberOf API-HTTP + * + * @param {Object} params + * @param {Object} params.path - The URL of the request + * @param {Object} [params.querystring] - The querystring parameters + * @param {Object} [params.headers] - The request headers + * @param {Object} [params.body] - The request body + * + * @param {Object} [options] - Options for {@link Transport#request} + * @param {function} [callback] - Callback that handles errors and response + * + * @returns {{abort: function(), then: function(), catch: function()}|Promise|*} + */ +HttpApi.prototype.trace = function (params, options, callback) { + return this.request('TRACE', params, options, callback); +}; + +module.exports = HttpApi; diff --git a/api/index.js b/api/index.js index d98e3a280..63bed5eec 100644 --- a/api/index.js +++ b/api/index.js @@ -54,6 +54,7 @@ const getScriptApi = require('./api/get_script'); const getScriptContextApi = require('./api/get_script_context'); const getScriptLanguagesApi = require('./api/get_script_languages'); const getSourceApi = require('./api/get_source'); +const HttpApi = require('./api/http'); const indexApi = require('./api/index'); const IndicesApi = require('./api/indices'); const infoApi = require('./api/info'); @@ -89,6 +90,7 @@ const kCat = Symbol('Cat'); const kCluster = Symbol('Cluster'); const kDanglingIndices = Symbol('DanglingIndices'); const kFeatures = Symbol('Features'); +const kHttp = Symbol('Http'); const kIndices = Symbol('Indices'); const kIngest = Symbol('Ingest'); const kNodes = Symbol('Nodes'); @@ -103,6 +105,7 @@ function OpenSearchAPI(opts) { this[kCluster] = null; this[kDanglingIndices] = null; this[kFeatures] = null; + this[kHttp] = null; this[kIndices] = null; this[kIngest] = null; this[kNodes] = null; @@ -264,6 +267,14 @@ Object.defineProperties(OpenSearchAPI.prototype, { return this.getSource; }, }, + http: { + get() { + if (this[kHttp] === null) { + this[kHttp] = new HttpApi(this.transport, this[kConfigurationError]); + } + return this[kHttp]; + }, + }, indices: { get() { if (this[kIndices] === null) { diff --git a/api/requestParams.d.ts b/api/requestParams.d.ts index 3afc4fc57..da7568c1b 100644 --- a/api/requestParams.d.ts +++ b/api/requestParams.d.ts @@ -71,8 +71,8 @@ export interface CatAllocation extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; h?: string | string[]; help?: boolean; @@ -121,8 +121,8 @@ export interface CatIndices extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; h?: string | string[]; health?: 'green' | 'yellow' | 'red'; @@ -146,16 +146,16 @@ export interface CatClusterManager extends Generic { } /** -* // TODO: delete CatMaster interface when it is removed from OpenSearch -* @deprecated use CatClusterManager instead -*/ + * // TODO: delete CatMaster interface when it is removed from OpenSearch + * @deprecated use CatClusterManager instead + */ export interface CatMaster extends Generic { format?: string; local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; h?: string | string[]; help?: boolean; @@ -168,8 +168,8 @@ export interface CatNodeattrs extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; h?: string | string[]; help?: boolean; @@ -184,8 +184,8 @@ export interface CatNodes extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; h?: string | string[]; help?: boolean; @@ -200,8 +200,8 @@ export interface CatPendingTasks extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; h?: string | string[]; help?: boolean; @@ -215,8 +215,8 @@ export interface CatPlugins extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; h?: string | string[]; help?: boolean; @@ -243,8 +243,8 @@ export interface CatRepositories extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; h?: string | string[]; help?: boolean; @@ -269,8 +269,8 @@ export interface CatShards extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; h?: string | string[]; help?: boolean; @@ -285,8 +285,8 @@ export interface CatSnapshots extends Generic { ignore_unavailable?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; h?: string | string[]; help?: boolean; @@ -314,8 +314,8 @@ export interface CatTemplates extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; h?: string | string[]; help?: boolean; @@ -330,8 +330,8 @@ export interface CatThreadPool extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; h?: string | string[]; help?: boolean; @@ -355,8 +355,8 @@ export interface ClusterDeleteComponentTemplate extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -368,8 +368,8 @@ export interface ClusterExistsComponentTemplate extends Generic { name: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; local?: boolean; } @@ -378,8 +378,8 @@ export interface ClusterGetComponentTemplate extends Generic { name?: string | string[]; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; local?: boolean; } @@ -388,8 +388,8 @@ export interface ClusterGetSettings extends Generic { flat_settings?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; timeout?: string; include_defaults?: boolean; @@ -402,8 +402,8 @@ export interface ClusterHealth extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; timeout?: string; wait_for_active_shards?: string; @@ -418,8 +418,8 @@ export interface ClusterPendingTasks extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -435,8 +435,8 @@ export interface ClusterPutComponentTemplate extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; body: T; } @@ -445,8 +445,8 @@ export interface ClusterPutSettings extends Generic { flat_settings?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; timeout?: string; body: T; @@ -461,8 +461,8 @@ export interface ClusterReroute extends Generic { metric?: string | string[]; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; timeout?: string; body?: T; @@ -474,8 +474,8 @@ export interface ClusterState extends Generic { local?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; flat_settings?: boolean; wait_for_metadata_version?: number; @@ -537,8 +537,8 @@ export interface DanglingIndicesDeleteDanglingIndex extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -548,8 +548,8 @@ export interface DanglingIndicesImportDanglingIndex extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -624,8 +624,8 @@ export interface DeleteScript extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -685,8 +685,8 @@ export interface Explain extends Generic { export interface FeaturesGetFeatures extends Generic { cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -725,8 +725,8 @@ export interface GetScript extends Generic { id: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -750,6 +750,13 @@ export interface GetSource extends Generic { version_type?: 'internal' | 'external' | 'external_gte' | 'force'; } +export interface HttpParams extends Generic { + path: string; + querystring?: Record; + headers?: Record; + body?: Record | string | Array>; +} + export interface Index extends Generic { id?: string; index: string; @@ -773,8 +780,8 @@ export interface IndicesAddBlock extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; ignore_unavailable?: boolean; allow_no_indices?: boolean; @@ -803,8 +810,8 @@ export interface IndicesClone extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; wait_for_active_shards?: string; body?: T; @@ -815,8 +822,8 @@ export interface IndicesClose extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; ignore_unavailable?: boolean; allow_no_indices?: boolean; @@ -830,8 +837,8 @@ export interface IndicesCreate extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; body?: T; } @@ -841,8 +848,8 @@ export interface IndicesDelete extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; ignore_unavailable?: boolean; allow_no_indices?: boolean; @@ -855,8 +862,8 @@ export interface IndicesDeleteAlias extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -865,8 +872,8 @@ export interface IndicesDeleteIndexTemplate extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -875,8 +882,8 @@ export interface IndicesDeleteTemplate extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -913,8 +920,8 @@ export interface IndicesExistsIndexTemplate extends Generic { flat_settings?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; local?: boolean; } @@ -924,8 +931,8 @@ export interface IndicesExistsTemplate extends Generic { flat_settings?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; local?: boolean; } @@ -967,8 +974,8 @@ export interface IndicesGet extends Generic { include_defaults?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -996,8 +1003,8 @@ export interface IndicesGetIndexTemplate extends Generic { flat_settings?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; local?: boolean; } @@ -1009,8 +1016,8 @@ export interface IndicesGetMapping extends Generic { expand_wildcards?: 'open' | 'closed' | 'hidden' | 'none' | 'all'; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; local?: boolean; } @@ -1020,8 +1027,8 @@ export interface IndicesGetSettings extends Generic { name?: string | string[]; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; ignore_unavailable?: boolean; allow_no_indices?: boolean; @@ -1036,8 +1043,8 @@ export interface IndicesGetTemplate extends Generic { flat_settings?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; local?: boolean; } @@ -1054,8 +1061,8 @@ export interface IndicesOpen extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; ignore_unavailable?: boolean; allow_no_indices?: boolean; @@ -1069,8 +1076,8 @@ export interface IndicesPutAlias extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; body?: T; } @@ -1081,8 +1088,8 @@ export interface IndicesPutIndexTemplate extends Generic { cause?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; body: T; } @@ -1092,8 +1099,8 @@ export interface IndicesPutMapping extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; ignore_unavailable?: boolean; allow_no_indices?: boolean; @@ -1106,8 +1113,8 @@ export interface IndicesPutSettings extends Generic { index?: string | string[]; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; timeout?: string; preserve_existing?: boolean; @@ -1124,8 +1131,8 @@ export interface IndicesPutTemplate extends Generic { create?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; body: T; } @@ -1155,8 +1162,8 @@ export interface IndicesRollover extends Generic { dry_run?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; wait_for_active_shards?: string; body?: T; @@ -1185,8 +1192,8 @@ export interface IndicesShrink extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; wait_for_active_shards?: string; body?: T; @@ -1198,8 +1205,8 @@ export interface IndicesSimulateIndexTemplate extends Generic { cause?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; body?: T; } @@ -1210,8 +1217,8 @@ export interface IndicesSimulateTemplate extends Generic { cause?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; body?: T; } @@ -1223,8 +1230,8 @@ export interface IndicesSplit extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; wait_for_active_shards?: string; body?: T; @@ -1249,8 +1256,8 @@ export interface IndicesUpdateAliases extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; body: T; } @@ -1287,8 +1294,8 @@ export interface IngestDeletePipeline extends Generic { id: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; timeout?: string; } @@ -1300,8 +1307,8 @@ export interface IngestGetPipeline extends Generic { summary?: boolean; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -1311,8 +1318,8 @@ export interface IngestPutPipeline extends Generic { id: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; timeout?: string; body: T; @@ -1439,8 +1446,8 @@ export interface PutScript extends Generic { timeout?: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; body: T; } @@ -1582,8 +1589,8 @@ export interface SnapshotCleanupRepository extends Generic { repository: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; timeout?: string; } @@ -1594,8 +1601,8 @@ export interface SnapshotClone extends Generic { target_snapshot: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; body: T; } @@ -1605,8 +1612,8 @@ export interface SnapshotCreate extends Generic { snapshot: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; wait_for_completion?: boolean; body?: T; @@ -1616,8 +1623,8 @@ export interface SnapshotCreateRepository extends Generic { repository: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; timeout?: string; verify?: boolean; @@ -1629,8 +1636,8 @@ export interface SnapshotDelete extends Generic { snapshot: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; } @@ -1638,8 +1645,8 @@ export interface SnapshotDeleteRepository extends Generic { repository: string | string[]; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; timeout?: string; } @@ -1649,8 +1656,8 @@ export interface SnapshotGet extends Generic { snapshot: string | string[]; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; ignore_unavailable?: boolean; index_details?: boolean; @@ -1662,8 +1669,8 @@ export interface SnapshotGetRepository extends Generic { repository?: string | string[]; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; local?: boolean; } @@ -1688,8 +1695,8 @@ export interface SnapshotRestore extends Generic { snapshot: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; wait_for_completion?: boolean; body?: T; @@ -1700,8 +1707,8 @@ export interface SnapshotStatus extends Generic { snapshot?: string | string[]; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; ignore_unavailable?: boolean; } @@ -1710,8 +1717,8 @@ export interface SnapshotVerifyRepository extends Generic { repository: string; cluster_manager_timeout?: string; /** - * @deprecated use cluster_manager_timeout instead - */ + * @deprecated use cluster_manager_timeout instead + */ master_timeout?: string; timeout?: string; } diff --git a/index.d.ts b/index.d.ts index f80d8f22d..aac05cb30 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2073,6 +2073,48 @@ declare class Client { options: TransportRequestOptions, callback: callbackFn ): TransportRequestCallback; + http: { + connect, TContext = Context>( + params: RequestParams.HttpParams, + options?: TransportRequestOptions, + callback?: callbackFn + ): TransportRequestPromise>; + delete, TContext = Context>( + params: RequestParams.HttpParams, + options?: TransportRequestOptions, + callback?: callbackFn + ): TransportRequestPromise>; + get, TContext = Context>( + params: RequestParams.HttpParams, + options?: TransportRequestOptions, + callback?: callbackFn + ): TransportRequestPromise>; + head, TContext = Context>( + params: RequestParams.HttpParams, + options?: TransportRequestOptions, + callback?: callbackFn + ): TransportRequestPromise>; + options, TContext = Context>( + params: RequestParams.HttpParams, + options?: TransportRequestOptions, + callback?: callbackFn + ): TransportRequestPromise>; + post, TContext = Context>( + params: RequestParams.HttpParams, + options?: TransportRequestOptions, + callback?: callbackFn + ): TransportRequestPromise>; + put, TContext = Context>( + params: RequestParams.HttpParams, + options?: TransportRequestOptions, + callback?: callbackFn + ): TransportRequestPromise>; + trace, TContext = Context>( + params: RequestParams.HttpParams, + options?: TransportRequestOptions, + callback?: callbackFn + ): TransportRequestPromise>; + }; index< TResponse = Record, TRequestBody extends RequestBody = Record, diff --git a/test/integration/helpers-secure/http.test.js b/test/integration/helpers-secure/http.test.js new file mode 100644 index 000000000..c1d23650b --- /dev/null +++ b/test/integration/helpers-secure/http.test.js @@ -0,0 +1,50 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + +const { test } = require('tap'); +const { Client } = require('../../../'); + +const client = new Client({ + ssl: { + rejectUnauthorized: false, + }, + node: 'https://localhost:9200', + auth: { + username: 'admin', + password: 'admin', + }, +}); +const http = client.http; +const index = 'books'; + +test('Create an index using HTTP functions', async (t) => { + const response = await http.put({ + path: index, + body: { settings: { number_of_shards: 5, number_of_replicas: 2 } }, + }); + t.equal(response.body.acknowledged, true); + t.equal(response.body.index, index); +}); + +test('Check that the previously created index exists', async (t) => { + const response = await http.head({ path: index }); + t.equal(response.statusCode, 200); +}); + + +test('Close the previously created index', async (t) => { + const response = await http.post({ path: `${index}/_close` }); + t.equal(response.body.acknowledged, true); +}); + +test('Delete the previously created index', async (t) => { + const response = await http.delete({ path: index }); + t.equal(response.body.acknowledged, true); +});