opensecureconf-client 1.0.0 → 2.2.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/dist/index.d.mts +97 -7
- package/dist/index.d.ts +97 -7
- package/dist/index.js +149 -7
- package/dist/index.mjs +156 -7
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* OpenSecureConf JavaScript/TypeScript Client
|
|
3
3
|
*
|
|
4
4
|
* A comprehensive REST API client for OpenSecureConf - Encrypted configuration
|
|
5
|
-
* management system with cluster support.
|
|
5
|
+
* management system with cluster support and HTTPS/SSL.
|
|
6
6
|
*
|
|
7
|
-
* @version
|
|
7
|
+
* @version 2.2.0
|
|
8
8
|
* @license MIT
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
@@ -22,9 +22,9 @@ interface ConfigEntry {
|
|
|
22
22
|
interface ClusterStatus {
|
|
23
23
|
enabled: boolean;
|
|
24
24
|
mode?: string;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
node_id?: string;
|
|
26
|
+
total_nodes?: number;
|
|
27
|
+
healthy_nodes?: number;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Client configuration options
|
|
@@ -34,6 +34,7 @@ interface OpenSecureConfOptions {
|
|
|
34
34
|
userKey: string;
|
|
35
35
|
apiKey?: string;
|
|
36
36
|
timeout?: number;
|
|
37
|
+
rejectUnauthorized?: boolean;
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
39
40
|
* Custom error class for OpenSecureConf API errors
|
|
@@ -45,28 +46,117 @@ declare class OpenSecureConfError extends Error {
|
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* OpenSecureConf API Client
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // Basic HTTP usage
|
|
52
|
+
* const client = new OpenSecureConfClient({
|
|
53
|
+
* baseUrl: 'http://localhost:9000',
|
|
54
|
+
* userKey: 'my-secret-key-12345'
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // HTTPS with valid certificate
|
|
59
|
+
* const client = new OpenSecureConfClient({
|
|
60
|
+
* baseUrl: 'https://config.example.com',
|
|
61
|
+
* userKey: 'my-secret-key-12345',
|
|
62
|
+
* apiKey: 'optional-api-key'
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // HTTPS with self-signed certificate (Node.js)
|
|
67
|
+
* const client = new OpenSecureConfClient({
|
|
68
|
+
* baseUrl: 'https://localhost:9443',
|
|
69
|
+
* userKey: 'my-secret-key-12345',
|
|
70
|
+
* rejectUnauthorized: false // Accept self-signed certs
|
|
71
|
+
* });
|
|
48
72
|
*/
|
|
49
73
|
declare class OpenSecureConfClient {
|
|
50
74
|
private baseUrl;
|
|
51
75
|
private userKey;
|
|
52
76
|
private apiKey?;
|
|
53
77
|
private timeout;
|
|
78
|
+
private rejectUnauthorized;
|
|
79
|
+
private httpsAgent?;
|
|
54
80
|
constructor(options: OpenSecureConfOptions);
|
|
81
|
+
/**
|
|
82
|
+
* Setup HTTPS agent for Node.js environment to handle SSL certificates
|
|
83
|
+
*/
|
|
84
|
+
private setupNodeHttpsAgent;
|
|
85
|
+
/**
|
|
86
|
+
* Make HTTP request with HTTPS/SSL support
|
|
87
|
+
*/
|
|
55
88
|
private request;
|
|
56
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Get service information
|
|
91
|
+
*/
|
|
92
|
+
getInfo(): Promise<Record<string, any>>;
|
|
93
|
+
/**
|
|
94
|
+
* Create a new configuration entry
|
|
95
|
+
*/
|
|
57
96
|
create(key: string, value: Record<string, any>, category?: string): Promise<ConfigEntry>;
|
|
97
|
+
/**
|
|
98
|
+
* Read a configuration entry by key
|
|
99
|
+
*/
|
|
58
100
|
read(key: string): Promise<ConfigEntry>;
|
|
101
|
+
/**
|
|
102
|
+
* Update an existing configuration entry
|
|
103
|
+
*/
|
|
59
104
|
update(key: string, value: Record<string, any>, category?: string): Promise<ConfigEntry>;
|
|
105
|
+
/**
|
|
106
|
+
* Delete a configuration entry
|
|
107
|
+
*/
|
|
60
108
|
delete(key: string): Promise<{
|
|
61
109
|
message: string;
|
|
62
110
|
}>;
|
|
111
|
+
/**
|
|
112
|
+
* List all configurations with optional category filter
|
|
113
|
+
*/
|
|
63
114
|
list(category?: string): Promise<ConfigEntry[]>;
|
|
115
|
+
/**
|
|
116
|
+
* Get cluster status
|
|
117
|
+
*/
|
|
64
118
|
getClusterStatus(): Promise<ClusterStatus>;
|
|
119
|
+
/**
|
|
120
|
+
* Perform health check
|
|
121
|
+
*/
|
|
65
122
|
healthCheck(): Promise<{
|
|
66
123
|
status: string;
|
|
67
|
-
|
|
124
|
+
node_id: string;
|
|
68
125
|
}>;
|
|
126
|
+
/**
|
|
127
|
+
* Get Prometheus metrics
|
|
128
|
+
*/
|
|
69
129
|
getMetrics(): Promise<string>;
|
|
130
|
+
/**
|
|
131
|
+
* Check if configuration key exists
|
|
132
|
+
*/
|
|
133
|
+
exists(key: string): Promise<boolean>;
|
|
134
|
+
/**
|
|
135
|
+
* Count total configurations
|
|
136
|
+
*/
|
|
137
|
+
count(category?: string): Promise<number>;
|
|
138
|
+
/**
|
|
139
|
+
* Bulk create configurations
|
|
140
|
+
*/
|
|
141
|
+
bulkCreate(configs: Array<{
|
|
142
|
+
key: string;
|
|
143
|
+
value: Record<string, any>;
|
|
144
|
+
category?: string;
|
|
145
|
+
}>, ignoreErrors?: boolean): Promise<ConfigEntry[]>;
|
|
146
|
+
/**
|
|
147
|
+
* Bulk read configurations
|
|
148
|
+
*/
|
|
149
|
+
bulkRead(keys: string[], ignoreErrors?: boolean): Promise<ConfigEntry[]>;
|
|
150
|
+
/**
|
|
151
|
+
* Bulk delete configurations
|
|
152
|
+
*/
|
|
153
|
+
bulkDelete(keys: string[], ignoreErrors?: boolean): Promise<{
|
|
154
|
+
deleted: string[];
|
|
155
|
+
failed: Array<{
|
|
156
|
+
key: string;
|
|
157
|
+
error: any;
|
|
158
|
+
}>;
|
|
159
|
+
}>;
|
|
70
160
|
}
|
|
71
161
|
|
|
72
162
|
export { type ClusterStatus, type ConfigEntry, OpenSecureConfClient, OpenSecureConfError, type OpenSecureConfOptions, OpenSecureConfClient as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* OpenSecureConf JavaScript/TypeScript Client
|
|
3
3
|
*
|
|
4
4
|
* A comprehensive REST API client for OpenSecureConf - Encrypted configuration
|
|
5
|
-
* management system with cluster support.
|
|
5
|
+
* management system with cluster support and HTTPS/SSL.
|
|
6
6
|
*
|
|
7
|
-
* @version
|
|
7
|
+
* @version 2.2.0
|
|
8
8
|
* @license MIT
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
@@ -22,9 +22,9 @@ interface ConfigEntry {
|
|
|
22
22
|
interface ClusterStatus {
|
|
23
23
|
enabled: boolean;
|
|
24
24
|
mode?: string;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
node_id?: string;
|
|
26
|
+
total_nodes?: number;
|
|
27
|
+
healthy_nodes?: number;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Client configuration options
|
|
@@ -34,6 +34,7 @@ interface OpenSecureConfOptions {
|
|
|
34
34
|
userKey: string;
|
|
35
35
|
apiKey?: string;
|
|
36
36
|
timeout?: number;
|
|
37
|
+
rejectUnauthorized?: boolean;
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
39
40
|
* Custom error class for OpenSecureConf API errors
|
|
@@ -45,28 +46,117 @@ declare class OpenSecureConfError extends Error {
|
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* OpenSecureConf API Client
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // Basic HTTP usage
|
|
52
|
+
* const client = new OpenSecureConfClient({
|
|
53
|
+
* baseUrl: 'http://localhost:9000',
|
|
54
|
+
* userKey: 'my-secret-key-12345'
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // HTTPS with valid certificate
|
|
59
|
+
* const client = new OpenSecureConfClient({
|
|
60
|
+
* baseUrl: 'https://config.example.com',
|
|
61
|
+
* userKey: 'my-secret-key-12345',
|
|
62
|
+
* apiKey: 'optional-api-key'
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // HTTPS with self-signed certificate (Node.js)
|
|
67
|
+
* const client = new OpenSecureConfClient({
|
|
68
|
+
* baseUrl: 'https://localhost:9443',
|
|
69
|
+
* userKey: 'my-secret-key-12345',
|
|
70
|
+
* rejectUnauthorized: false // Accept self-signed certs
|
|
71
|
+
* });
|
|
48
72
|
*/
|
|
49
73
|
declare class OpenSecureConfClient {
|
|
50
74
|
private baseUrl;
|
|
51
75
|
private userKey;
|
|
52
76
|
private apiKey?;
|
|
53
77
|
private timeout;
|
|
78
|
+
private rejectUnauthorized;
|
|
79
|
+
private httpsAgent?;
|
|
54
80
|
constructor(options: OpenSecureConfOptions);
|
|
81
|
+
/**
|
|
82
|
+
* Setup HTTPS agent for Node.js environment to handle SSL certificates
|
|
83
|
+
*/
|
|
84
|
+
private setupNodeHttpsAgent;
|
|
85
|
+
/**
|
|
86
|
+
* Make HTTP request with HTTPS/SSL support
|
|
87
|
+
*/
|
|
55
88
|
private request;
|
|
56
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Get service information
|
|
91
|
+
*/
|
|
92
|
+
getInfo(): Promise<Record<string, any>>;
|
|
93
|
+
/**
|
|
94
|
+
* Create a new configuration entry
|
|
95
|
+
*/
|
|
57
96
|
create(key: string, value: Record<string, any>, category?: string): Promise<ConfigEntry>;
|
|
97
|
+
/**
|
|
98
|
+
* Read a configuration entry by key
|
|
99
|
+
*/
|
|
58
100
|
read(key: string): Promise<ConfigEntry>;
|
|
101
|
+
/**
|
|
102
|
+
* Update an existing configuration entry
|
|
103
|
+
*/
|
|
59
104
|
update(key: string, value: Record<string, any>, category?: string): Promise<ConfigEntry>;
|
|
105
|
+
/**
|
|
106
|
+
* Delete a configuration entry
|
|
107
|
+
*/
|
|
60
108
|
delete(key: string): Promise<{
|
|
61
109
|
message: string;
|
|
62
110
|
}>;
|
|
111
|
+
/**
|
|
112
|
+
* List all configurations with optional category filter
|
|
113
|
+
*/
|
|
63
114
|
list(category?: string): Promise<ConfigEntry[]>;
|
|
115
|
+
/**
|
|
116
|
+
* Get cluster status
|
|
117
|
+
*/
|
|
64
118
|
getClusterStatus(): Promise<ClusterStatus>;
|
|
119
|
+
/**
|
|
120
|
+
* Perform health check
|
|
121
|
+
*/
|
|
65
122
|
healthCheck(): Promise<{
|
|
66
123
|
status: string;
|
|
67
|
-
|
|
124
|
+
node_id: string;
|
|
68
125
|
}>;
|
|
126
|
+
/**
|
|
127
|
+
* Get Prometheus metrics
|
|
128
|
+
*/
|
|
69
129
|
getMetrics(): Promise<string>;
|
|
130
|
+
/**
|
|
131
|
+
* Check if configuration key exists
|
|
132
|
+
*/
|
|
133
|
+
exists(key: string): Promise<boolean>;
|
|
134
|
+
/**
|
|
135
|
+
* Count total configurations
|
|
136
|
+
*/
|
|
137
|
+
count(category?: string): Promise<number>;
|
|
138
|
+
/**
|
|
139
|
+
* Bulk create configurations
|
|
140
|
+
*/
|
|
141
|
+
bulkCreate(configs: Array<{
|
|
142
|
+
key: string;
|
|
143
|
+
value: Record<string, any>;
|
|
144
|
+
category?: string;
|
|
145
|
+
}>, ignoreErrors?: boolean): Promise<ConfigEntry[]>;
|
|
146
|
+
/**
|
|
147
|
+
* Bulk read configurations
|
|
148
|
+
*/
|
|
149
|
+
bulkRead(keys: string[], ignoreErrors?: boolean): Promise<ConfigEntry[]>;
|
|
150
|
+
/**
|
|
151
|
+
* Bulk delete configurations
|
|
152
|
+
*/
|
|
153
|
+
bulkDelete(keys: string[], ignoreErrors?: boolean): Promise<{
|
|
154
|
+
deleted: string[];
|
|
155
|
+
failed: Array<{
|
|
156
|
+
key: string;
|
|
157
|
+
error: any;
|
|
158
|
+
}>;
|
|
159
|
+
}>;
|
|
70
160
|
}
|
|
71
161
|
|
|
72
162
|
export { type ClusterStatus, type ConfigEntry, OpenSecureConfClient, OpenSecureConfError, type OpenSecureConfOptions, OpenSecureConfClient as default };
|
package/dist/index.js
CHANGED
|
@@ -36,16 +36,38 @@ var OpenSecureConfError = class _OpenSecureConfError extends Error {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
+
function isNodeEnvironment() {
|
|
40
|
+
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
41
|
+
}
|
|
39
42
|
var OpenSecureConfClient = class {
|
|
40
43
|
constructor(options) {
|
|
41
44
|
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
42
45
|
this.userKey = options.userKey;
|
|
43
46
|
this.apiKey = options.apiKey;
|
|
44
47
|
this.timeout = options.timeout || 3e4;
|
|
48
|
+
this.rejectUnauthorized = options.rejectUnauthorized !== false;
|
|
45
49
|
if (!this.userKey || this.userKey.length < 8) {
|
|
46
50
|
throw new Error("userKey must be at least 8 characters long");
|
|
47
51
|
}
|
|
52
|
+
if (isNodeEnvironment() && this.baseUrl.startsWith("https://")) {
|
|
53
|
+
this.setupNodeHttpsAgent();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Setup HTTPS agent for Node.js environment to handle SSL certificates
|
|
58
|
+
*/
|
|
59
|
+
setupNodeHttpsAgent() {
|
|
60
|
+
try {
|
|
61
|
+
const https = require("https");
|
|
62
|
+
this.httpsAgent = new https.Agent({
|
|
63
|
+
rejectUnauthorized: this.rejectUnauthorized
|
|
64
|
+
});
|
|
65
|
+
} catch (error) {
|
|
66
|
+
}
|
|
48
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Make HTTP request with HTTPS/SSL support
|
|
70
|
+
*/
|
|
49
71
|
async request(method, endpoint, body) {
|
|
50
72
|
const url = `${this.baseUrl}${endpoint}`;
|
|
51
73
|
const headers = {
|
|
@@ -58,12 +80,16 @@ var OpenSecureConfClient = class {
|
|
|
58
80
|
const controller = new AbortController();
|
|
59
81
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
60
82
|
try {
|
|
61
|
-
const
|
|
83
|
+
const fetchOptions = {
|
|
62
84
|
method,
|
|
63
85
|
headers,
|
|
64
86
|
body: body ? JSON.stringify(body) : void 0,
|
|
65
87
|
signal: controller.signal
|
|
66
|
-
}
|
|
88
|
+
};
|
|
89
|
+
if (this.httpsAgent) {
|
|
90
|
+
fetchOptions.agent = this.httpsAgent;
|
|
91
|
+
}
|
|
92
|
+
const response = await fetch(url, fetchOptions);
|
|
67
93
|
clearTimeout(timeoutId);
|
|
68
94
|
if (!response.ok) {
|
|
69
95
|
let errorDetail;
|
|
@@ -97,14 +123,27 @@ var OpenSecureConfClient = class {
|
|
|
97
123
|
`Request exceeded ${this.timeout}ms`
|
|
98
124
|
);
|
|
99
125
|
}
|
|
126
|
+
if (error.message.includes("certificate") || error.message.includes("SSL")) {
|
|
127
|
+
throw new OpenSecureConfError(
|
|
128
|
+
0,
|
|
129
|
+
"SSL/TLS error",
|
|
130
|
+
`${error.message}. For self-signed certificates, set rejectUnauthorized: false`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
100
133
|
throw new OpenSecureConfError(0, "Network error", error.message);
|
|
101
134
|
}
|
|
102
135
|
throw error;
|
|
103
136
|
}
|
|
104
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Get service information
|
|
140
|
+
*/
|
|
105
141
|
async getInfo() {
|
|
106
142
|
return this.request("GET", "/");
|
|
107
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Create a new configuration entry
|
|
146
|
+
*/
|
|
108
147
|
async create(key, value, category) {
|
|
109
148
|
return this.request("POST", "/configs", {
|
|
110
149
|
key,
|
|
@@ -112,35 +151,60 @@ var OpenSecureConfClient = class {
|
|
|
112
151
|
category
|
|
113
152
|
});
|
|
114
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Read a configuration entry by key
|
|
156
|
+
*/
|
|
115
157
|
async read(key) {
|
|
116
158
|
return this.request("GET", `/configs/${encodeURIComponent(key)}`);
|
|
117
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Update an existing configuration entry
|
|
162
|
+
*/
|
|
118
163
|
async update(key, value, category) {
|
|
119
164
|
return this.request("PUT", `/configs/${encodeURIComponent(key)}`, {
|
|
120
165
|
value,
|
|
121
166
|
category
|
|
122
167
|
});
|
|
123
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Delete a configuration entry
|
|
171
|
+
*/
|
|
124
172
|
async delete(key) {
|
|
125
173
|
return this.request("DELETE", `/configs/${encodeURIComponent(key)}`);
|
|
126
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* List all configurations with optional category filter
|
|
177
|
+
*/
|
|
127
178
|
async list(category) {
|
|
128
179
|
const endpoint = category ? `/configs?category=${encodeURIComponent(category)}` : "/configs";
|
|
129
180
|
return this.request("GET", endpoint);
|
|
130
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Get cluster status
|
|
184
|
+
*/
|
|
131
185
|
async getClusterStatus() {
|
|
132
186
|
return this.request("GET", "/cluster/status");
|
|
133
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Perform health check
|
|
190
|
+
*/
|
|
134
191
|
async healthCheck() {
|
|
135
192
|
return this.request("GET", "/cluster/health");
|
|
136
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Get Prometheus metrics
|
|
196
|
+
*/
|
|
137
197
|
async getMetrics() {
|
|
138
198
|
const url = `${this.baseUrl}/metrics`;
|
|
139
199
|
const headers = {};
|
|
140
200
|
if (this.apiKey) {
|
|
141
201
|
headers["X-API-Key"] = this.apiKey;
|
|
142
202
|
}
|
|
143
|
-
const
|
|
203
|
+
const fetchOptions = { headers };
|
|
204
|
+
if (this.httpsAgent) {
|
|
205
|
+
fetchOptions.agent = this.httpsAgent;
|
|
206
|
+
}
|
|
207
|
+
const response = await fetch(url, fetchOptions);
|
|
144
208
|
if (!response.ok) {
|
|
145
209
|
throw new OpenSecureConfError(
|
|
146
210
|
response.status,
|
|
@@ -149,6 +213,84 @@ var OpenSecureConfClient = class {
|
|
|
149
213
|
}
|
|
150
214
|
return await response.text();
|
|
151
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Check if configuration key exists
|
|
218
|
+
*/
|
|
219
|
+
async exists(key) {
|
|
220
|
+
try {
|
|
221
|
+
await this.read(key);
|
|
222
|
+
return true;
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (error instanceof OpenSecureConfError && error.statusCode === 404) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Count total configurations
|
|
232
|
+
*/
|
|
233
|
+
async count(category) {
|
|
234
|
+
const configs = await this.list(category);
|
|
235
|
+
return configs.length;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Bulk create configurations
|
|
239
|
+
*/
|
|
240
|
+
async bulkCreate(configs, ignoreErrors = false) {
|
|
241
|
+
const results = [];
|
|
242
|
+
const errors = [];
|
|
243
|
+
for (const config of configs) {
|
|
244
|
+
try {
|
|
245
|
+
const result = await this.create(config.key, config.value, config.category);
|
|
246
|
+
results.push(result);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
errors.push({ key: config.key, error });
|
|
249
|
+
if (!ignoreErrors) {
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return results;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Bulk read configurations
|
|
258
|
+
*/
|
|
259
|
+
async bulkRead(keys, ignoreErrors = false) {
|
|
260
|
+
const results = [];
|
|
261
|
+
const errors = [];
|
|
262
|
+
for (const key of keys) {
|
|
263
|
+
try {
|
|
264
|
+
const result = await this.read(key);
|
|
265
|
+
results.push(result);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
errors.push({ key, error });
|
|
268
|
+
if (!ignoreErrors) {
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return results;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Bulk delete configurations
|
|
277
|
+
*/
|
|
278
|
+
async bulkDelete(keys, ignoreErrors = false) {
|
|
279
|
+
const deleted = [];
|
|
280
|
+
const failed = [];
|
|
281
|
+
for (const key of keys) {
|
|
282
|
+
try {
|
|
283
|
+
await this.delete(key);
|
|
284
|
+
deleted.push(key);
|
|
285
|
+
} catch (error) {
|
|
286
|
+
failed.push({ key, error });
|
|
287
|
+
if (!ignoreErrors) {
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return { deleted, failed };
|
|
293
|
+
}
|
|
152
294
|
};
|
|
153
295
|
var index_default = OpenSecureConfClient;
|
|
154
296
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -158,10 +300,10 @@ var index_default = OpenSecureConfClient;
|
|
|
158
300
|
});
|
|
159
301
|
/**
|
|
160
302
|
* OpenSecureConf JavaScript/TypeScript Client
|
|
161
|
-
*
|
|
303
|
+
*
|
|
162
304
|
* A comprehensive REST API client for OpenSecureConf - Encrypted configuration
|
|
163
|
-
* management system with cluster support.
|
|
164
|
-
*
|
|
165
|
-
* @version
|
|
305
|
+
* management system with cluster support and HTTPS/SSL.
|
|
306
|
+
*
|
|
307
|
+
* @version 2.2.0
|
|
166
308
|
* @license MIT
|
|
167
309
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
1
8
|
// src/index.ts
|
|
2
9
|
var OpenSecureConfError = class _OpenSecureConfError extends Error {
|
|
3
10
|
constructor(statusCode, message, detail) {
|
|
@@ -10,16 +17,38 @@ var OpenSecureConfError = class _OpenSecureConfError extends Error {
|
|
|
10
17
|
}
|
|
11
18
|
}
|
|
12
19
|
};
|
|
20
|
+
function isNodeEnvironment() {
|
|
21
|
+
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
22
|
+
}
|
|
13
23
|
var OpenSecureConfClient = class {
|
|
14
24
|
constructor(options) {
|
|
15
25
|
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
16
26
|
this.userKey = options.userKey;
|
|
17
27
|
this.apiKey = options.apiKey;
|
|
18
28
|
this.timeout = options.timeout || 3e4;
|
|
29
|
+
this.rejectUnauthorized = options.rejectUnauthorized !== false;
|
|
19
30
|
if (!this.userKey || this.userKey.length < 8) {
|
|
20
31
|
throw new Error("userKey must be at least 8 characters long");
|
|
21
32
|
}
|
|
33
|
+
if (isNodeEnvironment() && this.baseUrl.startsWith("https://")) {
|
|
34
|
+
this.setupNodeHttpsAgent();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Setup HTTPS agent for Node.js environment to handle SSL certificates
|
|
39
|
+
*/
|
|
40
|
+
setupNodeHttpsAgent() {
|
|
41
|
+
try {
|
|
42
|
+
const https = __require("https");
|
|
43
|
+
this.httpsAgent = new https.Agent({
|
|
44
|
+
rejectUnauthorized: this.rejectUnauthorized
|
|
45
|
+
});
|
|
46
|
+
} catch (error) {
|
|
47
|
+
}
|
|
22
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Make HTTP request with HTTPS/SSL support
|
|
51
|
+
*/
|
|
23
52
|
async request(method, endpoint, body) {
|
|
24
53
|
const url = `${this.baseUrl}${endpoint}`;
|
|
25
54
|
const headers = {
|
|
@@ -32,12 +61,16 @@ var OpenSecureConfClient = class {
|
|
|
32
61
|
const controller = new AbortController();
|
|
33
62
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
34
63
|
try {
|
|
35
|
-
const
|
|
64
|
+
const fetchOptions = {
|
|
36
65
|
method,
|
|
37
66
|
headers,
|
|
38
67
|
body: body ? JSON.stringify(body) : void 0,
|
|
39
68
|
signal: controller.signal
|
|
40
|
-
}
|
|
69
|
+
};
|
|
70
|
+
if (this.httpsAgent) {
|
|
71
|
+
fetchOptions.agent = this.httpsAgent;
|
|
72
|
+
}
|
|
73
|
+
const response = await fetch(url, fetchOptions);
|
|
41
74
|
clearTimeout(timeoutId);
|
|
42
75
|
if (!response.ok) {
|
|
43
76
|
let errorDetail;
|
|
@@ -71,14 +104,27 @@ var OpenSecureConfClient = class {
|
|
|
71
104
|
`Request exceeded ${this.timeout}ms`
|
|
72
105
|
);
|
|
73
106
|
}
|
|
107
|
+
if (error.message.includes("certificate") || error.message.includes("SSL")) {
|
|
108
|
+
throw new OpenSecureConfError(
|
|
109
|
+
0,
|
|
110
|
+
"SSL/TLS error",
|
|
111
|
+
`${error.message}. For self-signed certificates, set rejectUnauthorized: false`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
74
114
|
throw new OpenSecureConfError(0, "Network error", error.message);
|
|
75
115
|
}
|
|
76
116
|
throw error;
|
|
77
117
|
}
|
|
78
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Get service information
|
|
121
|
+
*/
|
|
79
122
|
async getInfo() {
|
|
80
123
|
return this.request("GET", "/");
|
|
81
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Create a new configuration entry
|
|
127
|
+
*/
|
|
82
128
|
async create(key, value, category) {
|
|
83
129
|
return this.request("POST", "/configs", {
|
|
84
130
|
key,
|
|
@@ -86,35 +132,60 @@ var OpenSecureConfClient = class {
|
|
|
86
132
|
category
|
|
87
133
|
});
|
|
88
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Read a configuration entry by key
|
|
137
|
+
*/
|
|
89
138
|
async read(key) {
|
|
90
139
|
return this.request("GET", `/configs/${encodeURIComponent(key)}`);
|
|
91
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Update an existing configuration entry
|
|
143
|
+
*/
|
|
92
144
|
async update(key, value, category) {
|
|
93
145
|
return this.request("PUT", `/configs/${encodeURIComponent(key)}`, {
|
|
94
146
|
value,
|
|
95
147
|
category
|
|
96
148
|
});
|
|
97
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Delete a configuration entry
|
|
152
|
+
*/
|
|
98
153
|
async delete(key) {
|
|
99
154
|
return this.request("DELETE", `/configs/${encodeURIComponent(key)}`);
|
|
100
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* List all configurations with optional category filter
|
|
158
|
+
*/
|
|
101
159
|
async list(category) {
|
|
102
160
|
const endpoint = category ? `/configs?category=${encodeURIComponent(category)}` : "/configs";
|
|
103
161
|
return this.request("GET", endpoint);
|
|
104
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Get cluster status
|
|
165
|
+
*/
|
|
105
166
|
async getClusterStatus() {
|
|
106
167
|
return this.request("GET", "/cluster/status");
|
|
107
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Perform health check
|
|
171
|
+
*/
|
|
108
172
|
async healthCheck() {
|
|
109
173
|
return this.request("GET", "/cluster/health");
|
|
110
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Get Prometheus metrics
|
|
177
|
+
*/
|
|
111
178
|
async getMetrics() {
|
|
112
179
|
const url = `${this.baseUrl}/metrics`;
|
|
113
180
|
const headers = {};
|
|
114
181
|
if (this.apiKey) {
|
|
115
182
|
headers["X-API-Key"] = this.apiKey;
|
|
116
183
|
}
|
|
117
|
-
const
|
|
184
|
+
const fetchOptions = { headers };
|
|
185
|
+
if (this.httpsAgent) {
|
|
186
|
+
fetchOptions.agent = this.httpsAgent;
|
|
187
|
+
}
|
|
188
|
+
const response = await fetch(url, fetchOptions);
|
|
118
189
|
if (!response.ok) {
|
|
119
190
|
throw new OpenSecureConfError(
|
|
120
191
|
response.status,
|
|
@@ -123,6 +194,84 @@ var OpenSecureConfClient = class {
|
|
|
123
194
|
}
|
|
124
195
|
return await response.text();
|
|
125
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Check if configuration key exists
|
|
199
|
+
*/
|
|
200
|
+
async exists(key) {
|
|
201
|
+
try {
|
|
202
|
+
await this.read(key);
|
|
203
|
+
return true;
|
|
204
|
+
} catch (error) {
|
|
205
|
+
if (error instanceof OpenSecureConfError && error.statusCode === 404) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Count total configurations
|
|
213
|
+
*/
|
|
214
|
+
async count(category) {
|
|
215
|
+
const configs = await this.list(category);
|
|
216
|
+
return configs.length;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Bulk create configurations
|
|
220
|
+
*/
|
|
221
|
+
async bulkCreate(configs, ignoreErrors = false) {
|
|
222
|
+
const results = [];
|
|
223
|
+
const errors = [];
|
|
224
|
+
for (const config of configs) {
|
|
225
|
+
try {
|
|
226
|
+
const result = await this.create(config.key, config.value, config.category);
|
|
227
|
+
results.push(result);
|
|
228
|
+
} catch (error) {
|
|
229
|
+
errors.push({ key: config.key, error });
|
|
230
|
+
if (!ignoreErrors) {
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return results;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Bulk read configurations
|
|
239
|
+
*/
|
|
240
|
+
async bulkRead(keys, ignoreErrors = false) {
|
|
241
|
+
const results = [];
|
|
242
|
+
const errors = [];
|
|
243
|
+
for (const key of keys) {
|
|
244
|
+
try {
|
|
245
|
+
const result = await this.read(key);
|
|
246
|
+
results.push(result);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
errors.push({ key, error });
|
|
249
|
+
if (!ignoreErrors) {
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return results;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Bulk delete configurations
|
|
258
|
+
*/
|
|
259
|
+
async bulkDelete(keys, ignoreErrors = false) {
|
|
260
|
+
const deleted = [];
|
|
261
|
+
const failed = [];
|
|
262
|
+
for (const key of keys) {
|
|
263
|
+
try {
|
|
264
|
+
await this.delete(key);
|
|
265
|
+
deleted.push(key);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
failed.push({ key, error });
|
|
268
|
+
if (!ignoreErrors) {
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return { deleted, failed };
|
|
274
|
+
}
|
|
126
275
|
};
|
|
127
276
|
var index_default = OpenSecureConfClient;
|
|
128
277
|
export {
|
|
@@ -132,10 +281,10 @@ export {
|
|
|
132
281
|
};
|
|
133
282
|
/**
|
|
134
283
|
* OpenSecureConf JavaScript/TypeScript Client
|
|
135
|
-
*
|
|
284
|
+
*
|
|
136
285
|
* A comprehensive REST API client for OpenSecureConf - Encrypted configuration
|
|
137
|
-
* management system with cluster support.
|
|
138
|
-
*
|
|
139
|
-
* @version
|
|
286
|
+
* management system with cluster support and HTTPS/SSL.
|
|
287
|
+
*
|
|
288
|
+
* @version 2.2.0
|
|
140
289
|
* @license MIT
|
|
141
290
|
*/
|
package/package.json
CHANGED