@xnestjs/elasticsearch 1.5.2 → 1.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/README.md +4 -0
- package/cjs/elasticsearch-core.module.js +4 -72
- package/cjs/get-elasticsearch-config.js +73 -0
- package/cjs/index.js +1 -0
- package/esm/elasticsearch-core.module.js +4 -72
- package/esm/get-elasticsearch-config.js +69 -0
- package/esm/index.js +1 -0
- package/package.json +1 -1
- package/types/elasticsearch-core.module.d.ts +0 -1
- package/types/get-elasticsearch-config.d.ts +2 -0
- package/types/index.d.cts +1 -0
- package/types/index.d.ts +1 -0
package/README.md
CHANGED
|
@@ -62,6 +62,8 @@ export class MyModule {
|
|
|
62
62
|
The library supports configuration through environment variables. Environment variables below is accepted.
|
|
63
63
|
All environment variables starts with prefix (MONGODB_). This can be configured while registering the module.
|
|
64
64
|
|
|
65
|
+
<--- BEGIN env --->
|
|
66
|
+
|
|
65
67
|
| Environment Variable | Type | Default | Description |
|
|
66
68
|
|--------------------------------------|---------|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
67
69
|
| ELASTIC_NODE | String | http://localhost:9200 | Elasticsearch node settings, if there is only one node. Required if `NODES` or `CLOUD_ID` is not set. |
|
|
@@ -84,3 +86,5 @@ All environment variables starts with prefix (MONGODB_). This can be configured
|
|
|
84
86
|
| ELASTIC_TLS_KEY_PASSPHRASE | String | | PFX or PKCS12 encoded private key and certificate chain. |
|
|
85
87
|
| ELASTIC_TLS_REJECT_UNAUTHORIZED | Boolean | False | If true the server will reject any connection which is notauthorized with the list of supplied CAs. This option only has an effect if requestCert is true. |
|
|
86
88
|
| ELASTIC_CA_FINGERPRINT | String | | If configured, verifies that the fingerprint of the CA certificate that has signed the certificate of the server matches the supplied fingerprint; only accepts SHA256 digest fingerprints |
|
|
89
|
+
|
|
90
|
+
<--- END env --->
|
|
@@ -5,20 +5,18 @@ exports.ElasticsearchCoreModule = void 0;
|
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
|
|
7
7
|
const crypto = tslib_1.__importStar(require("node:crypto"));
|
|
8
|
-
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
9
|
-
const objects_1 = require("@jsopen/objects");
|
|
10
8
|
const common_1 = require("@nestjs/common");
|
|
11
9
|
const elasticsearch_1 = require("@nestjs/elasticsearch");
|
|
12
10
|
const colors = tslib_1.__importStar(require("ansi-colors"));
|
|
13
|
-
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
14
11
|
const constants_js_1 = require("./constants.js");
|
|
12
|
+
const get_elasticsearch_config_js_1 = require("./get-elasticsearch-config.js");
|
|
15
13
|
const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
|
|
16
14
|
let ElasticsearchCoreModule = ElasticsearchCoreModule_1 = class ElasticsearchCoreModule {
|
|
17
15
|
/**
|
|
18
16
|
*
|
|
19
17
|
*/
|
|
20
18
|
static forRoot(moduleOptions) {
|
|
21
|
-
const connectionOptions =
|
|
19
|
+
const connectionOptions = (0, get_elasticsearch_config_js_1.getElasticsearchConfig)(moduleOptions.useValue || {}, moduleOptions.envPrefix);
|
|
22
20
|
return this._createDynamicModule(moduleOptions, {
|
|
23
21
|
global: moduleOptions.global,
|
|
24
22
|
providers: [
|
|
@@ -42,7 +40,7 @@ let ElasticsearchCoreModule = ElasticsearchCoreModule_1 = class ElasticsearchCor
|
|
|
42
40
|
inject: asyncOptions.inject,
|
|
43
41
|
useFactory: async (...args) => {
|
|
44
42
|
const opts = await asyncOptions.useFactory(...args);
|
|
45
|
-
return
|
|
43
|
+
return (0, get_elasticsearch_config_js_1.getElasticsearchConfig)(opts, asyncOptions.envPrefix);
|
|
46
44
|
},
|
|
47
45
|
},
|
|
48
46
|
],
|
|
@@ -79,7 +77,7 @@ let ElasticsearchCoreModule = ElasticsearchCoreModule_1 = class ElasticsearchCor
|
|
|
79
77
|
return {
|
|
80
78
|
module: ElasticsearchCoreModule_1,
|
|
81
79
|
providers,
|
|
82
|
-
|
|
80
|
+
global: opts.global,
|
|
83
81
|
imports: [
|
|
84
82
|
elasticsearch_1.ElasticsearchModule.registerAsync({
|
|
85
83
|
imports: [
|
|
@@ -98,72 +96,6 @@ let ElasticsearchCoreModule = ElasticsearchCoreModule_1 = class ElasticsearchCor
|
|
|
98
96
|
exports,
|
|
99
97
|
};
|
|
100
98
|
}
|
|
101
|
-
static _readConnectionOptions(moduleOptions, prefix = 'ELASTIC_') {
|
|
102
|
-
const options = (0, objects_1.clone)(moduleOptions);
|
|
103
|
-
const env = node_process_1.default.env;
|
|
104
|
-
options.node = options.node || env[prefix + 'NODE'];
|
|
105
|
-
if (options.node) {
|
|
106
|
-
if (typeof options.node === 'string' && options.node.includes(','))
|
|
107
|
-
options.node.split(/\s*,\s*/);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
options.nodes = options.nodes || env[prefix + 'NODES'];
|
|
111
|
-
if (options.nodes) {
|
|
112
|
-
if (typeof options.nodes === 'string' && options.nodes.includes(','))
|
|
113
|
-
options.nodes.split(/\s*,\s*/);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (!(options.node || options.nodes))
|
|
117
|
-
options.node = 'http://localhost:9200';
|
|
118
|
-
options.maxRetries = options.maxRetries ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_RETRIES']);
|
|
119
|
-
options.requestTimeout = options.requestTimeout ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'REQUEST_TIMEOUT']);
|
|
120
|
-
options.pingTimeout = options.pingTimeout ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'PING_TIMEOUT']);
|
|
121
|
-
if (options.tls == null && (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS'])) {
|
|
122
|
-
options.tls = {
|
|
123
|
-
ca: [env[prefix + 'TLS_CA_CERT'] || ''],
|
|
124
|
-
cert: env[prefix + 'TLS_CERT_FILE'],
|
|
125
|
-
key: env[prefix + 'TLS_KEY_FILE'],
|
|
126
|
-
passphrase: env[prefix + 'TLS_KEY_PASSPHRASE'],
|
|
127
|
-
rejectUnauthorized: (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS_REJECT_UNAUTHORIZED']),
|
|
128
|
-
checkServerIdentity: (host, cert) => {
|
|
129
|
-
if (cert.subject.CN !== host) {
|
|
130
|
-
return new Error(`Certificate CN (${cert.subject.CN}) does not match host (${host})`);
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
options.name = options.name ?? env[prefix + 'NAME'];
|
|
136
|
-
if (!options.auth) {
|
|
137
|
-
if (env[prefix + 'AUTH_USERNAME']) {
|
|
138
|
-
options.auth = {
|
|
139
|
-
username: env[prefix + 'AUTH_USERNAME'],
|
|
140
|
-
password: env[prefix + 'AUTH_PASSWORD'] || '',
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
else if (env[prefix + 'AUTH_BEARER']) {
|
|
144
|
-
options.auth = {
|
|
145
|
-
bearer: env[prefix + 'AUTH_BEARER'],
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
else if (env[prefix + 'AUTH_API_KEY']) {
|
|
149
|
-
if (env[prefix + 'API_KEY_ID'])
|
|
150
|
-
options.auth = {
|
|
151
|
-
apiKey: {
|
|
152
|
-
id: env[prefix + 'API_KEY_ID'],
|
|
153
|
-
api_key: env[prefix + 'API_KEY'],
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
options.auth = {
|
|
157
|
-
apiKey: env[prefix + 'API_KEY'],
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
options.caFingerprint = options.caFingerprint ?? env[prefix + 'CA_FINGERPRINT'];
|
|
162
|
-
options.maxResponseSize = options.maxResponseSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_RESPONSE_SIZE']);
|
|
163
|
-
options.maxCompressedResponseSize =
|
|
164
|
-
options.maxCompressedResponseSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_COMPRESSED_RESPONSE_SIZE']);
|
|
165
|
-
return options;
|
|
166
|
-
}
|
|
167
99
|
/**
|
|
168
100
|
*
|
|
169
101
|
* @constructor
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getElasticsearchConfig = getElasticsearchConfig;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
6
|
+
const objects_1 = require("@jsopen/objects");
|
|
7
|
+
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
8
|
+
function getElasticsearchConfig(moduleOptions, prefix = 'ELASTIC_') {
|
|
9
|
+
const options = (0, objects_1.clone)(moduleOptions);
|
|
10
|
+
const env = node_process_1.default.env;
|
|
11
|
+
options.node = options.node || env[prefix + 'NODE'];
|
|
12
|
+
if (options.node) {
|
|
13
|
+
if (typeof options.node === 'string' && options.node.includes(','))
|
|
14
|
+
options.node.split(/\s*,\s*/);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
options.nodes = options.nodes || env[prefix + 'NODES'];
|
|
18
|
+
if (options.nodes) {
|
|
19
|
+
if (typeof options.nodes === 'string' && options.nodes.includes(','))
|
|
20
|
+
options.nodes.split(/\s*,\s*/);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (!(options.node || options.nodes))
|
|
24
|
+
options.node = 'http://localhost:9200';
|
|
25
|
+
options.maxRetries = options.maxRetries ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_RETRIES']);
|
|
26
|
+
options.requestTimeout = options.requestTimeout ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'REQUEST_TIMEOUT']);
|
|
27
|
+
options.pingTimeout = options.pingTimeout ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'PING_TIMEOUT']);
|
|
28
|
+
if (options.tls == null && (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS'])) {
|
|
29
|
+
options.tls = {
|
|
30
|
+
ca: [env[prefix + 'TLS_CA_CERT'] || ''],
|
|
31
|
+
cert: env[prefix + 'TLS_CERT_FILE'],
|
|
32
|
+
key: env[prefix + 'TLS_KEY_FILE'],
|
|
33
|
+
passphrase: env[prefix + 'TLS_KEY_PASSPHRASE'],
|
|
34
|
+
rejectUnauthorized: (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS_REJECT_UNAUTHORIZED']),
|
|
35
|
+
checkServerIdentity: (host, cert) => {
|
|
36
|
+
if (cert.subject.CN !== host) {
|
|
37
|
+
return new Error(`Certificate CN (${cert.subject.CN}) does not match host (${host})`);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
options.name = options.name ?? env[prefix + 'NAME'];
|
|
43
|
+
if (!options.auth) {
|
|
44
|
+
if (env[prefix + 'AUTH_USERNAME']) {
|
|
45
|
+
options.auth = {
|
|
46
|
+
username: env[prefix + 'AUTH_USERNAME'],
|
|
47
|
+
password: env[prefix + 'AUTH_PASSWORD'] || '',
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
else if (env[prefix + 'AUTH_BEARER']) {
|
|
51
|
+
options.auth = {
|
|
52
|
+
bearer: env[prefix + 'AUTH_BEARER'],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else if (env[prefix + 'AUTH_API_KEY']) {
|
|
56
|
+
if (env[prefix + 'API_KEY_ID'])
|
|
57
|
+
options.auth = {
|
|
58
|
+
apiKey: {
|
|
59
|
+
id: env[prefix + 'API_KEY_ID'],
|
|
60
|
+
api_key: env[prefix + 'API_KEY'],
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
options.auth = {
|
|
64
|
+
apiKey: env[prefix + 'API_KEY'],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
options.caFingerprint = options.caFingerprint ?? env[prefix + 'CA_FINGERPRINT'];
|
|
69
|
+
options.maxResponseSize = options.maxResponseSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_RESPONSE_SIZE']);
|
|
70
|
+
options.maxCompressedResponseSize =
|
|
71
|
+
options.maxCompressedResponseSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_COMPRESSED_RESPONSE_SIZE']);
|
|
72
|
+
return options;
|
|
73
|
+
}
|
package/cjs/index.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.ElasticsearchService = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./constants.js"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./elasticsearch.module.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./get-elasticsearch-config.js"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./types.js"), exports);
|
|
8
9
|
var elasticsearch_1 = require("@nestjs/elasticsearch");
|
|
9
10
|
Object.defineProperty(exports, "ElasticsearchService", { enumerable: true, get: function () { return elasticsearch_1.ElasticsearchService; } });
|
|
@@ -2,20 +2,18 @@ var ElasticsearchCoreModule_1;
|
|
|
2
2
|
import { __decorate, __metadata, __param } from "tslib";
|
|
3
3
|
import assert from 'node:assert';
|
|
4
4
|
import * as crypto from 'node:crypto';
|
|
5
|
-
import process from 'node:process';
|
|
6
|
-
import { clone } from '@jsopen/objects';
|
|
7
5
|
import { Inject, Logger } from '@nestjs/common';
|
|
8
6
|
import { ElasticsearchModule, ElasticsearchService } from '@nestjs/elasticsearch';
|
|
9
7
|
import * as colors from 'ansi-colors';
|
|
10
|
-
import { toBoolean, toInt } from 'putil-varhelpers';
|
|
11
8
|
import { ELASTICSEARCH_CONNECTION_OPTIONS, ELASTICSEARCH_MODULE_ID } from './constants.js';
|
|
9
|
+
import { getElasticsearchConfig } from './get-elasticsearch-config.js';
|
|
12
10
|
const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
|
|
13
11
|
let ElasticsearchCoreModule = ElasticsearchCoreModule_1 = class ElasticsearchCoreModule {
|
|
14
12
|
/**
|
|
15
13
|
*
|
|
16
14
|
*/
|
|
17
15
|
static forRoot(moduleOptions) {
|
|
18
|
-
const connectionOptions =
|
|
16
|
+
const connectionOptions = getElasticsearchConfig(moduleOptions.useValue || {}, moduleOptions.envPrefix);
|
|
19
17
|
return this._createDynamicModule(moduleOptions, {
|
|
20
18
|
global: moduleOptions.global,
|
|
21
19
|
providers: [
|
|
@@ -39,7 +37,7 @@ let ElasticsearchCoreModule = ElasticsearchCoreModule_1 = class ElasticsearchCor
|
|
|
39
37
|
inject: asyncOptions.inject,
|
|
40
38
|
useFactory: async (...args) => {
|
|
41
39
|
const opts = await asyncOptions.useFactory(...args);
|
|
42
|
-
return
|
|
40
|
+
return getElasticsearchConfig(opts, asyncOptions.envPrefix);
|
|
43
41
|
},
|
|
44
42
|
},
|
|
45
43
|
],
|
|
@@ -76,7 +74,7 @@ let ElasticsearchCoreModule = ElasticsearchCoreModule_1 = class ElasticsearchCor
|
|
|
76
74
|
return {
|
|
77
75
|
module: ElasticsearchCoreModule_1,
|
|
78
76
|
providers,
|
|
79
|
-
|
|
77
|
+
global: opts.global,
|
|
80
78
|
imports: [
|
|
81
79
|
ElasticsearchModule.registerAsync({
|
|
82
80
|
imports: [
|
|
@@ -95,72 +93,6 @@ let ElasticsearchCoreModule = ElasticsearchCoreModule_1 = class ElasticsearchCor
|
|
|
95
93
|
exports,
|
|
96
94
|
};
|
|
97
95
|
}
|
|
98
|
-
static _readConnectionOptions(moduleOptions, prefix = 'ELASTIC_') {
|
|
99
|
-
const options = clone(moduleOptions);
|
|
100
|
-
const env = process.env;
|
|
101
|
-
options.node = options.node || env[prefix + 'NODE'];
|
|
102
|
-
if (options.node) {
|
|
103
|
-
if (typeof options.node === 'string' && options.node.includes(','))
|
|
104
|
-
options.node.split(/\s*,\s*/);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
options.nodes = options.nodes || env[prefix + 'NODES'];
|
|
108
|
-
if (options.nodes) {
|
|
109
|
-
if (typeof options.nodes === 'string' && options.nodes.includes(','))
|
|
110
|
-
options.nodes.split(/\s*,\s*/);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (!(options.node || options.nodes))
|
|
114
|
-
options.node = 'http://localhost:9200';
|
|
115
|
-
options.maxRetries = options.maxRetries ?? toInt(env[prefix + 'MAX_RETRIES']);
|
|
116
|
-
options.requestTimeout = options.requestTimeout ?? toInt(env[prefix + 'REQUEST_TIMEOUT']);
|
|
117
|
-
options.pingTimeout = options.pingTimeout ?? toInt(env[prefix + 'PING_TIMEOUT']);
|
|
118
|
-
if (options.tls == null && toBoolean(env[prefix + 'TLS'])) {
|
|
119
|
-
options.tls = {
|
|
120
|
-
ca: [env[prefix + 'TLS_CA_CERT'] || ''],
|
|
121
|
-
cert: env[prefix + 'TLS_CERT_FILE'],
|
|
122
|
-
key: env[prefix + 'TLS_KEY_FILE'],
|
|
123
|
-
passphrase: env[prefix + 'TLS_KEY_PASSPHRASE'],
|
|
124
|
-
rejectUnauthorized: toBoolean(env[prefix + 'TLS_REJECT_UNAUTHORIZED']),
|
|
125
|
-
checkServerIdentity: (host, cert) => {
|
|
126
|
-
if (cert.subject.CN !== host) {
|
|
127
|
-
return new Error(`Certificate CN (${cert.subject.CN}) does not match host (${host})`);
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
options.name = options.name ?? env[prefix + 'NAME'];
|
|
133
|
-
if (!options.auth) {
|
|
134
|
-
if (env[prefix + 'AUTH_USERNAME']) {
|
|
135
|
-
options.auth = {
|
|
136
|
-
username: env[prefix + 'AUTH_USERNAME'],
|
|
137
|
-
password: env[prefix + 'AUTH_PASSWORD'] || '',
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
else if (env[prefix + 'AUTH_BEARER']) {
|
|
141
|
-
options.auth = {
|
|
142
|
-
bearer: env[prefix + 'AUTH_BEARER'],
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
else if (env[prefix + 'AUTH_API_KEY']) {
|
|
146
|
-
if (env[prefix + 'API_KEY_ID'])
|
|
147
|
-
options.auth = {
|
|
148
|
-
apiKey: {
|
|
149
|
-
id: env[prefix + 'API_KEY_ID'],
|
|
150
|
-
api_key: env[prefix + 'API_KEY'],
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
options.auth = {
|
|
154
|
-
apiKey: env[prefix + 'API_KEY'],
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
options.caFingerprint = options.caFingerprint ?? env[prefix + 'CA_FINGERPRINT'];
|
|
159
|
-
options.maxResponseSize = options.maxResponseSize ?? toInt(env[prefix + 'MAX_RESPONSE_SIZE']);
|
|
160
|
-
options.maxCompressedResponseSize =
|
|
161
|
-
options.maxCompressedResponseSize ?? toInt(env[prefix + 'MAX_COMPRESSED_RESPONSE_SIZE']);
|
|
162
|
-
return options;
|
|
163
|
-
}
|
|
164
96
|
/**
|
|
165
97
|
*
|
|
166
98
|
* @constructor
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { clone } from '@jsopen/objects';
|
|
3
|
+
import { toBoolean, toInt } from 'putil-varhelpers';
|
|
4
|
+
export function getElasticsearchConfig(moduleOptions, prefix = 'ELASTIC_') {
|
|
5
|
+
const options = clone(moduleOptions);
|
|
6
|
+
const env = process.env;
|
|
7
|
+
options.node = options.node || env[prefix + 'NODE'];
|
|
8
|
+
if (options.node) {
|
|
9
|
+
if (typeof options.node === 'string' && options.node.includes(','))
|
|
10
|
+
options.node.split(/\s*,\s*/);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
options.nodes = options.nodes || env[prefix + 'NODES'];
|
|
14
|
+
if (options.nodes) {
|
|
15
|
+
if (typeof options.nodes === 'string' && options.nodes.includes(','))
|
|
16
|
+
options.nodes.split(/\s*,\s*/);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (!(options.node || options.nodes))
|
|
20
|
+
options.node = 'http://localhost:9200';
|
|
21
|
+
options.maxRetries = options.maxRetries ?? toInt(env[prefix + 'MAX_RETRIES']);
|
|
22
|
+
options.requestTimeout = options.requestTimeout ?? toInt(env[prefix + 'REQUEST_TIMEOUT']);
|
|
23
|
+
options.pingTimeout = options.pingTimeout ?? toInt(env[prefix + 'PING_TIMEOUT']);
|
|
24
|
+
if (options.tls == null && toBoolean(env[prefix + 'TLS'])) {
|
|
25
|
+
options.tls = {
|
|
26
|
+
ca: [env[prefix + 'TLS_CA_CERT'] || ''],
|
|
27
|
+
cert: env[prefix + 'TLS_CERT_FILE'],
|
|
28
|
+
key: env[prefix + 'TLS_KEY_FILE'],
|
|
29
|
+
passphrase: env[prefix + 'TLS_KEY_PASSPHRASE'],
|
|
30
|
+
rejectUnauthorized: toBoolean(env[prefix + 'TLS_REJECT_UNAUTHORIZED']),
|
|
31
|
+
checkServerIdentity: (host, cert) => {
|
|
32
|
+
if (cert.subject.CN !== host) {
|
|
33
|
+
return new Error(`Certificate CN (${cert.subject.CN}) does not match host (${host})`);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
options.name = options.name ?? env[prefix + 'NAME'];
|
|
39
|
+
if (!options.auth) {
|
|
40
|
+
if (env[prefix + 'AUTH_USERNAME']) {
|
|
41
|
+
options.auth = {
|
|
42
|
+
username: env[prefix + 'AUTH_USERNAME'],
|
|
43
|
+
password: env[prefix + 'AUTH_PASSWORD'] || '',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
else if (env[prefix + 'AUTH_BEARER']) {
|
|
47
|
+
options.auth = {
|
|
48
|
+
bearer: env[prefix + 'AUTH_BEARER'],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
else if (env[prefix + 'AUTH_API_KEY']) {
|
|
52
|
+
if (env[prefix + 'API_KEY_ID'])
|
|
53
|
+
options.auth = {
|
|
54
|
+
apiKey: {
|
|
55
|
+
id: env[prefix + 'API_KEY_ID'],
|
|
56
|
+
api_key: env[prefix + 'API_KEY'],
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
options.auth = {
|
|
60
|
+
apiKey: env[prefix + 'API_KEY'],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
options.caFingerprint = options.caFingerprint ?? env[prefix + 'CA_FINGERPRINT'];
|
|
65
|
+
options.maxResponseSize = options.maxResponseSize ?? toInt(env[prefix + 'MAX_RESPONSE_SIZE']);
|
|
66
|
+
options.maxCompressedResponseSize =
|
|
67
|
+
options.maxCompressedResponseSize ?? toInt(env[prefix + 'MAX_COMPRESSED_RESPONSE_SIZE']);
|
|
68
|
+
return options;
|
|
69
|
+
}
|
package/esm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -14,7 +14,6 @@ export declare class ElasticsearchCoreModule implements OnApplicationShutdown, O
|
|
|
14
14
|
*/
|
|
15
15
|
static forRootAsync(asyncOptions: ElasticsearchModuleAsyncOptions): DynamicModule;
|
|
16
16
|
private static _createDynamicModule;
|
|
17
|
-
private static _readConnectionOptions;
|
|
18
17
|
/**
|
|
19
18
|
*
|
|
20
19
|
* @constructor
|
package/types/index.d.cts
CHANGED