@cloudoperators/juno-k8s-client 1.0.8 → 1.1.1
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 +318 -20
- package/build/client.d.ts +3 -9
- package/build/client.d.ts.map +1 -1
- package/build/index.cjs.js +1 -1
- package/build/index.es.js +142 -123
- package/build/request.d.ts +5 -2
- package/build/request.d.ts.map +1 -1
- package/build/watch.d.ts +2 -0
- package/build/watch.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# JavaScript client for Kubernetes API
|
|
2
2
|
|
|
3
|
-
This `Kubernetes client` is designed for use in
|
|
3
|
+
This `Kubernetes client` is designed for use in both browser and Node.js environments. It utilizes the fetch API and is compatible with all modern browsers. For older browsers, the fetch polyfill (github/fetch) should be used.
|
|
4
4
|
|
|
5
5
|
The k8sclient facilitates communication with the Kubernetes API. It minimizes data interpretation and adds only essential logic. In addition to standard HTTP methods like GET or POST, it implements the WATCH method, which establishes a stream to the server and reacts to events.
|
|
6
6
|
|
|
7
|
-
All functions return Promise objects and can therefore be processed with a chain of then calls. Potential errors can be caught using the catch method
|
|
7
|
+
All functions return Promise objects and can therefore be processed with a chain of then calls. Potential errors can be caught using the catch method and will be of type `K8sApiError`.
|
|
8
8
|
|
|
9
9
|
The client requires a Kubernetes API endpoint and a token. Once both parameters are provided, the following functions are available:
|
|
10
10
|
|
|
@@ -36,8 +36,84 @@ With yarn:
|
|
|
36
36
|
yarn add @cloudoperators/juno-k8s-client
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
# Configuration Options
|
|
40
|
+
|
|
41
|
+
When creating a client, you can pass the following options:
|
|
42
|
+
|
|
43
|
+
| Option | Type | Required | Description |
|
|
44
|
+
| ------------- | ------- | -------- | --------------------------------------------------- |
|
|
45
|
+
| `apiEndpoint` | string | Yes | The Kubernetes API server endpoint |
|
|
46
|
+
| `token` | string | Yes | Bearer token for authentication |
|
|
47
|
+
| `ignoreSsl` | boolean | No | Ignore SSL certificate verification (Node.js only) |
|
|
48
|
+
| `debug` | boolean | No | Enable debug logging for API requests and responses |
|
|
49
|
+
|
|
50
|
+
## SSL Certificate Handling
|
|
51
|
+
|
|
52
|
+
The `ignoreSsl` option allows you to bypass SSL certificate verification when connecting to Kubernetes APIs with self-signed or invalid certificates.
|
|
53
|
+
|
|
54
|
+
**⚠️ Security Warning**: Only use `ignoreSsl: true` in development environments or with trusted internal APIs. Never disable SSL verification in production.
|
|
55
|
+
|
|
56
|
+
**Browser Limitation**: The `ignoreSsl` option is only supported in Node.js environments. In browser environments, this option is ignored for security reasons, as browsers handle SSL certificate validation automatically.
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import { createClient } from "@cloudoperators/juno-k8s-client"
|
|
60
|
+
|
|
61
|
+
// For internal/development APIs with self-signed certificates (Node.js only)
|
|
62
|
+
const apiClient = createClient({
|
|
63
|
+
apiEndpoint: "https://internal-k8s-api.company.com",
|
|
64
|
+
token: "BEARER-TOKEN",
|
|
65
|
+
ignoreSsl: true, // Only works in Node.js
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
# Error Handling
|
|
70
|
+
|
|
71
|
+
All API errors thrown by this client implement the `K8sApiError` interface:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
interface K8sApiError extends Error {
|
|
75
|
+
apiVersion?: string
|
|
76
|
+
kind?: string
|
|
77
|
+
message: string
|
|
78
|
+
metadata?: Record<string, any>
|
|
79
|
+
reason?: string
|
|
80
|
+
status?: string
|
|
81
|
+
code?: number
|
|
82
|
+
response?: {
|
|
83
|
+
data?: { message?: string }
|
|
84
|
+
status?: number
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
This provides detailed information about Kubernetes API errors, including status codes, reasons, and additional metadata.
|
|
90
|
+
|
|
39
91
|
# Example Code (ES6)
|
|
40
92
|
|
|
93
|
+
## Basic client creation
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
import { createClient } from "@cloudoperators/juno-k8s-client"
|
|
97
|
+
|
|
98
|
+
const apiEndpoint = "https://k8s-api.com"
|
|
99
|
+
let token = "BEARER-TOKEN"
|
|
100
|
+
const apiClient = createClient({ apiEndpoint, token })
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Client with SSL ignore (Node.js only)
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
import { createClient } from "@cloudoperators/juno-k8s-client"
|
|
107
|
+
|
|
108
|
+
const apiEndpoint = "https://internal-k8s-api.company.com"
|
|
109
|
+
let token = "BEARER-TOKEN"
|
|
110
|
+
const apiClient = createClient({
|
|
111
|
+
apiEndpoint,
|
|
112
|
+
token,
|
|
113
|
+
ignoreSsl: true, // For internal APIs with self-signed certificates
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
|
|
41
117
|
## List all pods
|
|
42
118
|
|
|
43
119
|
In this code snippet, we use the get method to fetch all pods from the Kubernetes API endpoint. The retrieved data is then logged to the console.
|
|
@@ -47,10 +123,46 @@ import { createClient } from "@cloudoperators/juno-k8s-client"
|
|
|
47
123
|
|
|
48
124
|
const apiEndpoint = "https://k8s-api.com"
|
|
49
125
|
let token = "BEARER-TOKEN"
|
|
126
|
+
const apiClient = createClient({ apiEndpoint, token })
|
|
127
|
+
|
|
128
|
+
apiClient
|
|
129
|
+
.get("/api/v1/pods")
|
|
130
|
+
.then((data) => console.log(data))
|
|
131
|
+
.catch((error) => {
|
|
132
|
+
console.error("Failed to fetch pods:", error.message)
|
|
133
|
+
console.error("Status:", error.status)
|
|
134
|
+
console.error("Reason:", error.reason)
|
|
135
|
+
console.error("HTTP Code:", error.code)
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## List pods with query parameters
|
|
50
140
|
|
|
141
|
+
```js
|
|
142
|
+
import { createClient } from "@cloudoperators/juno-k8s-client"
|
|
143
|
+
|
|
144
|
+
const apiEndpoint = "https://k8s-api.com"
|
|
145
|
+
let token = "BEARER-TOKEN"
|
|
51
146
|
const apiClient = createClient({ apiEndpoint, token })
|
|
52
147
|
|
|
53
|
-
|
|
148
|
+
// Get pods with label selector
|
|
149
|
+
apiClient
|
|
150
|
+
.get("/api/v1/namespaces/default/pods", {
|
|
151
|
+
params: {
|
|
152
|
+
labelSelector: "app=nginx",
|
|
153
|
+
fieldSelector: "status.phase=Running",
|
|
154
|
+
},
|
|
155
|
+
})
|
|
156
|
+
.then((data) => console.log(data))
|
|
157
|
+
.catch((error) => {
|
|
158
|
+
if (error.code === 403) {
|
|
159
|
+
console.error("Access forbidden:", error.reason)
|
|
160
|
+
} else if (error.code === 404) {
|
|
161
|
+
console.error("Namespace not found:", error.message)
|
|
162
|
+
} else {
|
|
163
|
+
console.error("API Error:", error.message)
|
|
164
|
+
}
|
|
165
|
+
})
|
|
54
166
|
```
|
|
55
167
|
|
|
56
168
|
## Create a new namespace
|
|
@@ -62,18 +174,28 @@ import { createClient } from "@cloudoperators/juno-k8s-client"
|
|
|
62
174
|
|
|
63
175
|
const apiEndpoint = "https://k8s-api.com"
|
|
64
176
|
let token = "BEARER-TOKEN"
|
|
65
|
-
|
|
66
177
|
const apiClient = createClient({ apiEndpoint, token })
|
|
67
178
|
|
|
68
|
-
apiClient
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
179
|
+
apiClient
|
|
180
|
+
.post("/api/v1/namespaces", {
|
|
181
|
+
apiVersion: "v1",
|
|
182
|
+
kind: "Namespace",
|
|
183
|
+
metadata: {
|
|
184
|
+
name: "my_namespace",
|
|
185
|
+
annotations: { displayName: "My Namespace" },
|
|
186
|
+
labels: { app: "my-app" },
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
.then((result) => console.log("Namespace created:", result))
|
|
190
|
+
.catch((error) => {
|
|
191
|
+
if (error.reason === "AlreadyExists") {
|
|
192
|
+
console.error("Namespace already exists:", error.message)
|
|
193
|
+
} else if (error.code === 422) {
|
|
194
|
+
console.error("Invalid namespace configuration:", error.message)
|
|
195
|
+
} else {
|
|
196
|
+
console.error("Failed to create namespace:", error.message)
|
|
197
|
+
}
|
|
198
|
+
})
|
|
77
199
|
```
|
|
78
200
|
|
|
79
201
|
## Delete a namespace
|
|
@@ -85,10 +207,50 @@ import { createClient } from "@cloudoperators/juno-k8s-client"
|
|
|
85
207
|
|
|
86
208
|
const apiEndpoint = "https://k8s-api.com"
|
|
87
209
|
let token = "BEARER-TOKEN"
|
|
88
|
-
|
|
89
210
|
const apiClient = createClient({ apiEndpoint, token })
|
|
90
211
|
|
|
91
|
-
apiClient
|
|
212
|
+
apiClient
|
|
213
|
+
.delete("/api/v1/namespaces/my_namespace")
|
|
214
|
+
.then((result) => console.log("Namespace deleted:", result))
|
|
215
|
+
.catch((error) => {
|
|
216
|
+
if (error.code === 404) {
|
|
217
|
+
console.error("Namespace not found:", error.message)
|
|
218
|
+
} else if (error.reason === "Forbidden") {
|
|
219
|
+
console.error("Insufficient permissions to delete namespace:", error.message)
|
|
220
|
+
} else {
|
|
221
|
+
console.error("Failed to delete namespace:", error.message)
|
|
222
|
+
console.error("Error details:", error.metadata)
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Per-request SSL override (Node.js only)
|
|
228
|
+
|
|
229
|
+
You can also override SSL behavior on a per-request basis:
|
|
230
|
+
|
|
231
|
+
```js
|
|
232
|
+
import { createClient } from "@cloudoperators/juno-k8s-client"
|
|
233
|
+
|
|
234
|
+
const apiEndpoint = "https://k8s-api.com"
|
|
235
|
+
let token = "BEARER-TOKEN"
|
|
236
|
+
|
|
237
|
+
// Client with SSL verification enabled by default
|
|
238
|
+
const apiClient = createClient({ apiEndpoint, token, ignoreSsl: false })
|
|
239
|
+
|
|
240
|
+
// Most requests use SSL verification
|
|
241
|
+
apiClient.get("/api/v1/pods")
|
|
242
|
+
|
|
243
|
+
// But you can override for specific requests (Node.js only)
|
|
244
|
+
apiClient
|
|
245
|
+
.get("/api/v1/secrets", {
|
|
246
|
+
ignoreSsl: true, // This request ignores SSL
|
|
247
|
+
})
|
|
248
|
+
.catch((error) => {
|
|
249
|
+
console.error("Failed to fetch secrets:", error.message)
|
|
250
|
+
if (error.response?.status) {
|
|
251
|
+
console.error("HTTP Status:", error.response.status)
|
|
252
|
+
}
|
|
253
|
+
})
|
|
92
254
|
```
|
|
93
255
|
|
|
94
256
|
## Refresh Token
|
|
@@ -100,13 +262,17 @@ import { createClient } from "@cloudoperators/juno-k8s-client"
|
|
|
100
262
|
|
|
101
263
|
const apiEndpoint = "https://k8s-api.com"
|
|
102
264
|
let token = "BEARER-TOKEN"
|
|
103
|
-
|
|
104
265
|
const apiClient = createClient({ apiEndpoint, token })
|
|
105
266
|
|
|
106
|
-
|
|
267
|
+
try {
|
|
268
|
+
apiClient.refreshToken("NEW-TOKEN")
|
|
269
|
+
console.log("Token refreshed successfully")
|
|
270
|
+
} catch (error) {
|
|
271
|
+
console.error("Failed to refresh token:", error.message)
|
|
272
|
+
}
|
|
107
273
|
```
|
|
108
274
|
|
|
109
|
-
|
|
275
|
+
## Watch
|
|
110
276
|
|
|
111
277
|
The watch call establishes a persistent connection to the Kubernetes API server and listens for changes to the specified resource. In this example, we're watching for changes to pods ("/api/v1/pods").
|
|
112
278
|
|
|
@@ -117,14 +283,27 @@ import { createClient } from "@cloudoperators/juno-k8s-client"
|
|
|
117
283
|
|
|
118
284
|
const apiEndpoint = "https://k8s-api.com"
|
|
119
285
|
let token = "BEARER-TOKEN"
|
|
120
|
-
|
|
121
286
|
const apiClient = createClient({ apiEndpoint, token })
|
|
287
|
+
|
|
122
288
|
const dispatch = (action) => console.log(action)
|
|
123
289
|
|
|
124
290
|
// Initialize the watch call
|
|
125
291
|
const podsWatch = apiClient
|
|
126
292
|
.watch("/api/v1/pods")
|
|
127
|
-
.on(apiClient.WATCH_ERROR, () =>
|
|
293
|
+
.on(apiClient.WATCH_ERROR, (error) => {
|
|
294
|
+
console.error("Watch error occurred:", error.message)
|
|
295
|
+
console.error("Error reason:", error.reason)
|
|
296
|
+
console.error("Error code:", error.code)
|
|
297
|
+
|
|
298
|
+
// Handle specific error cases
|
|
299
|
+
if (error.code === 401) {
|
|
300
|
+
console.error("Authentication failed - token may be expired")
|
|
301
|
+
} else if (error.code === 403) {
|
|
302
|
+
console.error("Access forbidden - insufficient permissions")
|
|
303
|
+
} else if (error.reason === "Expired") {
|
|
304
|
+
console.error("Watch session expired - consider restarting")
|
|
305
|
+
}
|
|
306
|
+
})
|
|
128
307
|
.on(apiClient.WATCH_ADDED, (items) => dispatch({ type: "RECEIVE_ITEMS", items }))
|
|
129
308
|
.on(apiClient.WATCH_MODIFIED, (items) => dispatch({ type: "UPDATE_ITEMS", items }))
|
|
130
309
|
.on(apiClient.WATCH_DELETED, (items) => dispatch({ type: "DELETE_ITEMS", items }))
|
|
@@ -136,6 +315,125 @@ podsWatch.start()
|
|
|
136
315
|
setTimeout(podsWatch.cancel, 5 * 60 * 1000) // 5 minutes
|
|
137
316
|
```
|
|
138
317
|
|
|
318
|
+
## Watch with SSL ignore (Node.js only)
|
|
319
|
+
|
|
320
|
+
```javascript
|
|
321
|
+
import { createClient } from "@cloudoperators/juno-k8s-client"
|
|
322
|
+
|
|
323
|
+
const apiEndpoint = "https://internal-k8s-api.company.com"
|
|
324
|
+
let token = "BEARER-TOKEN"
|
|
325
|
+
const apiClient = createClient({
|
|
326
|
+
apiEndpoint,
|
|
327
|
+
token,
|
|
328
|
+
ignoreSsl: true, // For internal APIs
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
const podsWatch = apiClient
|
|
332
|
+
.watch("/api/v1/pods", {
|
|
333
|
+
params: { watch: "true" },
|
|
334
|
+
ignoreSsl: true, // Can also be set per-request
|
|
335
|
+
})
|
|
336
|
+
.on(apiClient.WATCH_ERROR, (error) => {
|
|
337
|
+
console.error("Watch connection failed:", error.message)
|
|
338
|
+
if (error.response?.data?.message) {
|
|
339
|
+
console.error("Server message:", error.response.data.message)
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
.on(apiClient.WATCH_ADDED, (items) => console.log("Added:", items))
|
|
343
|
+
|
|
344
|
+
podsWatch.start()
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
# Common Use Cases
|
|
348
|
+
|
|
349
|
+
## Internal Kubernetes Clusters
|
|
350
|
+
|
|
351
|
+
For internal clusters with self-signed certificates (Node.js environments):
|
|
352
|
+
|
|
353
|
+
```js
|
|
354
|
+
const apiClient = createClient({
|
|
355
|
+
apiEndpoint: "https://rancher.internal.company.com/k8s/clusters/c-12345",
|
|
356
|
+
token: process.env.K8S_TOKEN,
|
|
357
|
+
ignoreSsl: true, // Safe for internal networks
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
// Example with error handling for internal clusters
|
|
361
|
+
apiClient
|
|
362
|
+
.get("/api/v1/nodes")
|
|
363
|
+
.then((nodes) => console.log("Cluster nodes:", nodes))
|
|
364
|
+
.catch((error) => {
|
|
365
|
+
console.error("Failed to connect to internal cluster:", error.message)
|
|
366
|
+
if (error.code === 0 || error.message.includes("ECONNREFUSED")) {
|
|
367
|
+
console.error("Network connectivity issue - check VPN or firewall")
|
|
368
|
+
}
|
|
369
|
+
})
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## Development Environment
|
|
373
|
+
|
|
374
|
+
```js
|
|
375
|
+
const apiClient = createClient({
|
|
376
|
+
apiEndpoint: "https://localhost:6443",
|
|
377
|
+
token: "dev-token",
|
|
378
|
+
ignoreSsl: process.env.NODE_ENV === "development", // Only in development
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
// Development-specific error handling
|
|
382
|
+
apiClient.get("/api/v1/namespaces").catch((error) => {
|
|
383
|
+
if (process.env.NODE_ENV === "development") {
|
|
384
|
+
console.warn("Development API error:", error.message)
|
|
385
|
+
console.warn("This might be expected in dev environment")
|
|
386
|
+
} else {
|
|
387
|
+
console.error("Production API error:", error)
|
|
388
|
+
}
|
|
389
|
+
})
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## Production Environment
|
|
393
|
+
|
|
394
|
+
```js
|
|
395
|
+
const apiClient = createClient({
|
|
396
|
+
apiEndpoint: "https://prod-k8s-api.company.com",
|
|
397
|
+
token: process.env.K8S_TOKEN,
|
|
398
|
+
// ignoreSsl should not be used in production
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
// Production error handling with monitoring
|
|
402
|
+
apiClient.get("/api/v1/pods").catch((error) => {
|
|
403
|
+
// Log detailed error information for monitoring
|
|
404
|
+
console.error("Production API Error:", {
|
|
405
|
+
message: error.message,
|
|
406
|
+
status: error.status,
|
|
407
|
+
reason: error.reason,
|
|
408
|
+
code: error.code,
|
|
409
|
+
apiVersion: error.apiVersion,
|
|
410
|
+
kind: error.kind,
|
|
411
|
+
timestamp: new Date().toISOString(),
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
// Send to monitoring service
|
|
415
|
+
// monitoringService.reportError(error)
|
|
416
|
+
})
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
# Environment Support
|
|
420
|
+
|
|
421
|
+
## Browser Environment
|
|
422
|
+
|
|
423
|
+
- ✅ Full HTTP methods support (GET, POST, PUT, PATCH, DELETE, HEAD)
|
|
424
|
+
- ✅ Watch functionality
|
|
425
|
+
- ✅ Token refresh
|
|
426
|
+
- ✅ Complete error handling with `K8sApiError`
|
|
427
|
+
- ❌ `ignoreSsl` option (ignored for security reasons)
|
|
428
|
+
|
|
429
|
+
## Node.js Environment
|
|
430
|
+
|
|
431
|
+
- ✅ Full HTTP methods support
|
|
432
|
+
- ✅ Watch functionality
|
|
433
|
+
- ✅ Token refresh
|
|
434
|
+
- ✅ Complete error handling with `K8sApiError`
|
|
435
|
+
- ✅ `ignoreSsl` option with HTTPS agent support
|
|
436
|
+
|
|
139
437
|
# Development
|
|
140
438
|
|
|
141
439
|
All dependencies of this project are expressed in its package.json file. Before you start developing, ensure that you have NPM installed, then run:
|
package/build/client.d.ts
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
|
+
import { RequestOptions } from './request';
|
|
1
2
|
import { Watch } from './watch';
|
|
2
3
|
import { K8sApiError } from './apiErrorHandler';
|
|
3
4
|
interface ClientOptions {
|
|
4
5
|
apiEndpoint: string;
|
|
5
6
|
token: string;
|
|
7
|
+
ignoreSsl?: boolean;
|
|
8
|
+
debug?: boolean;
|
|
6
9
|
[key: string]: any;
|
|
7
10
|
}
|
|
8
|
-
interface RequestOptions {
|
|
9
|
-
params?: Record<string, any>;
|
|
10
|
-
headers?: Record<string, string>;
|
|
11
|
-
body?: Object | null;
|
|
12
|
-
signal?: AbortSignal;
|
|
13
|
-
mode?: RequestMode;
|
|
14
|
-
cache?: RequestCache;
|
|
15
|
-
credentials?: RequestCredentials;
|
|
16
|
-
}
|
|
17
11
|
declare function createClient(options: ClientOptions): {
|
|
18
12
|
WATCH_ERROR: string;
|
|
19
13
|
WATCH_ADDED: string;
|
package/build/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAKA,OAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAEnD,OAAO,EAAE,KAAK,EAAmC,MAAM,SAAS,CAAA;AAChE,OAAuB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/D,UAAU,aAAa;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED,iBAAS,YAAY,CAAC,OAAO,EAAE,aAAa;;;;;iBAmCtB,MAAM,YAAW,cAAc,KAAQ,OAAO,CAAC,QAAQ,GAAG,WAAW,CAAC;gBAIvE,MAAM,YAAW,cAAc,KAAQ,OAAO,CAAC,OAAO,CAAC;iBAMtD,MAAM,QAAQ,EAAE,YAAW,cAAc,KAAQ,OAAO,CAAC,OAAO,CAAC;gBAOlE,MAAM,QAAQ,EAAE,YAAW,cAAc,KAAQ,OAAO,CAAC,OAAO,CAAC;kBAM/D,MAAM,QAAQ,EAAE,YAAW,cAAc,KAAQ,OAAO,CAAC,OAAO,CAAC;mBAanE,MAAM,SAAS,EAAE,GAAG,IAAI,YAAW,cAAc,KAAQ,OAAO,CAAC,OAAO,CAAC;kBAMvE,MAAM,YAAW,cAAc,KAAQ,KAAK;6BAIjC,MAAM,KAAG,IAAI;wBAIpB,MAAM;EAmBhC;AAED,OAAO,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,CAAA"}
|
package/build/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("https");function I(t){return typeof t=="string"||t instanceof String}function $(t){return typeof t=="number"&&t.constructor===Number}function B(t){return t!==null&&typeof t=="object"&&t.constructor===Object}const H=t=>{if(!t)return;const n=[];for(const o in t)if(Object.keys(t).includes(o)){const h=t[o];n.push(encodeURIComponent(o)+"="+encodeURIComponent(h))}return n.join("&")};function p(...t){if(t.length<2)throw new Error("Bad parameters: buildUrl needs at least two non-empty parameters.");const n=B(t[t.length-1])?t.pop():null;t.forEach(r=>{if(!r||!(I(r)||$(r)))throw new Error("Bad parameters: buildUrl accepts only strings and numbers, with a hash map as the last parameter");if(I(r)&&r.indexOf("?")>=0)throw new Error('Bad parameters: buildUrl does not accept strings with "?" character. Please use a hashmap as the last parameter instead!')});let o=t.join("/");const[h,e]=o.split("://");if(!h||!e)throw new Error(`Bad URL: ${o}`);return o=`${h}://${e.replace(/\/\/+/g,"/")}`,n&&(o+=`?${H(n)}`),o}const k="[k8sClient]:",C=t=>function(...n){try{const o=[`${k}`,...n];console[t](...o)}catch(o){console.error(k,"Logging error:",o)}},P=C("error"),l=C("debug"),U=t=>{if(t.status>=200&&t.status<300)return t;{const n=new Error(t.statusText||`${t.status}`);throw n.response=t,n}};function X(t,n){if(!(!t||!n.startsWith("https:")||typeof window<"u"))try{return j?.Agent?new j.Agent({rejectUnauthorized:!1}):void 0}catch{return}}function E(t,n,o={}){o.params&&(n=p(n,o.params));const{ignoreSsl:h,debug:e,...r}=o,s=X(h||!1,n);s&&e===!0&&process.env.NODE_ENV!=="test"&&l(`⚠️ SSL verification disabled for request to: ${n}`);const a=["signal","headers","body","mode","cache","credentials"].reduce((m,f)=>r[f]?{...m,[f]:r[f]}:m,{credentials:"same-origin",method:t});return s&&(a.agent=s),a.body&&typeof a.body!="string"&&(a.body=JSON.stringify(a.body)),e===!0&&l("fetch >",n,{...a,agent:s?"HTTPS Agent (SSL ignored)":a.agent}),fetch(n,a).then(U)}const w="ADDED",R="MODIFIED",A="DELETED",b="ERROR",W="BOOKMARK";class S{constructor(n,o={},h){this.listeners={[w]:[],[R]:[],[A]:[],[b]:[]},this.controller=new AbortController,this.signal=this.controller.signal,this.resourceVersion=null,this.PREFIX="watch >",this.decoder=new TextDecoder,this.refreshToken=e=>{this.options.headers&&(this.options.headers.Authorization=`Bearer ${e}`)},this.checkType=e=>{if(![w,R,A,b].includes(e))throw new Error(`Bad type: ${e}`)},this.addListener=(e,r)=>{this.checkType(e),this.listeners[e].push(r)},this.informListeners=(e,r)=>{const s=this.listeners[e];s&&s.forEach(c=>{try{c(r)}catch(a){P(a)}})},this.handleEvents=e=>{Array.isArray(e)||(e=[e]);const r=this;setTimeout(()=>{const s={};e.forEach(c=>{c.type===W?r.resourceVersion=c?.object?.metadata?.resourceVersion??null:(s[c.type]||(s[c.type]=[]),s[c.type].push(c.object))}),Object.keys(s).forEach(c=>r.informListeners(c,s[c]))})},this.getResourceVersion=async()=>{if(this.resourceVersion)return this.resourceVersion;l(this.PREFIX,"get resource version from API");const{metadata:e,items:r}=await E("GET",this.url,this.options).then(s=>s.json());return this.resourceVersion=e.resourceVersion,r&&this.informListeners(w,r),this.resourceVersion},this.start=()=>{const e=this;return e.getCurrentToken&&e.refreshToken(e.getCurrentToken()),e.getResourceVersion().then(r=>(l(e.PREFIX,"current resource version",r),E("GET",e.url,{...e.options,params:{...e.options.params,watch:1,allowWatchBookmarks:!0,resourceVersion:r},signal:e.signal}))).then(async r=>{const s=r.body?.getReader();let c=!1,a="";for(;!c;){l(e.PREFIX,"read stream chunk");const m=await s?.read();c=m?.done??!0,a+=e.decoder.decode(m?.value||new Uint8Array);const f=a.split(/\n|\r|\r\n/);a=f.pop()??"";const D=[];f.forEach(O=>{const T=JSON.parse(O);if(T.type===b&&T?.object?.code===410){e.cancel(),setTimeout(()=>{l(e.PREFIX,"resource is gone 410","recreate watch request!"),e.start()});return}D.push(T)}),l(e.PREFIX,"inform listeners",f),e.handleEvents(D)}}).catch(r=>{if(r.name==="AbortError")return;const s=r.code??r?.response?.status;if(s===410){l(e.PREFIX,"resource is gone 410"),e.resourceVersion=null,setTimeout(()=>e.start(),0);return}if(s===404){e.handleEvents({type:b,object:r}),e.cancel();return}P("WATCH ERROR",r,r.code,s,r.response),console.dir(r),setTimeout(()=>{l(e.PREFIX,"recover connection","restart!"),e.start()},3e4)}),e.cancel},this.on=(e,r)=>(this.addListener(e,r),this),this.cancel=()=>{l(this.PREFIX,"cancel connection"),this.controller.abort()},this.url=n,this.options=o,this.getCurrentToken=h,o?.params?.resourceVersion&&(this.resourceVersion=o.params.resourceVersion,delete o.params.resourceVersion)}}const y=async t=>{const n=t.response?.data?new Error(t.response.data.message??t.message):t;return Promise.reject(n)};function v(t){const{apiEndpoint:n,ignoreSsl:o=!1,debug:h=!1}=t;let e=t.token;if(!n||!e)throw new Error(`Bad options: ${JSON.stringify(t,null,4)}. Please provide apiEndpoint and token`);o&&h===!0&&(console.warn(`⚠️ K8s Client: SSL certificate verification disabled for ${n}`),console.warn("🔒 This should only be used in development or secure internal networks"));const r=()=>({Authorization:`Bearer ${e}`,"Content-Type":"application/json"});function s(i,u={}){const d={...r(),...u.headers,...i.headers};return{debug:h,ignoreSsl:o,...u,...i,headers:d}}function c(i,u={}){return E("HEAD",p(n,i),s(u)).catch(y)}function a(i,u={}){return E("GET",p(n,i),s(u)).then(d=>d.json()).catch(y)}function m(i,u,d={}){return E("POST",p(n,i),s(d,{body:u})).then(V=>V.json()).catch(y)}function f(i,u,d={}){return E("PUT",p(n,i),s(d,{body:u})).then(g=>g.json()).catch(y)}function D(i,u,d={}){return E("PATCH",p(n,i),s(d,{headers:{"Content-Type":"application/merge-patch+json"},body:u})).then(g=>g.json()).catch(y)}function O(i,u,d={}){return E("DELETE",p(n,i),s(d,{body:u})).then(g=>g.json()).catch(y)}function T(i,u={}){return new S(p(n,i),s(u),()=>e)}function F(i){e=i}function L(){return e}return{WATCH_ERROR:b,WATCH_ADDED:w,WATCH_DELETED:A,WATCH_MODIFIED:R,head:c,get:a,post:m,put:f,patch:D,delete:O,watch:T,refreshToken:F,currentToken:L}}exports.ADDED=w;exports.DELETED=A;exports.ERROR=b;exports.MODIFIED=R;exports.Watch=S;exports.createClient=v;
|
package/build/index.es.js
CHANGED
|
@@ -1,111 +1,127 @@
|
|
|
1
|
-
|
|
1
|
+
import j from "https";
|
|
2
|
+
function k(t) {
|
|
2
3
|
return typeof t == "string" || t instanceof String;
|
|
3
4
|
}
|
|
4
|
-
function
|
|
5
|
+
function V(t) {
|
|
5
6
|
return typeof t == "number" && t.constructor === Number;
|
|
6
7
|
}
|
|
7
|
-
function
|
|
8
|
+
function $(t) {
|
|
8
9
|
return t !== null && typeof t == "object" && t.constructor === Object;
|
|
9
10
|
}
|
|
10
11
|
const B = (t) => {
|
|
11
12
|
if (!t) return;
|
|
12
|
-
const
|
|
13
|
-
for (const
|
|
14
|
-
if (Object.keys(t).includes(
|
|
15
|
-
const h = t[
|
|
16
|
-
|
|
13
|
+
const n = [];
|
|
14
|
+
for (const o in t)
|
|
15
|
+
if (Object.keys(t).includes(o)) {
|
|
16
|
+
const h = t[o];
|
|
17
|
+
n.push(encodeURIComponent(o) + "=" + encodeURIComponent(h));
|
|
17
18
|
}
|
|
18
|
-
return
|
|
19
|
+
return n.join("&");
|
|
19
20
|
};
|
|
20
|
-
function
|
|
21
|
+
function p(...t) {
|
|
21
22
|
if (t.length < 2)
|
|
22
23
|
throw new Error("Bad parameters: buildUrl needs at least two non-empty parameters.");
|
|
23
|
-
const
|
|
24
|
+
const n = $(t[t.length - 1]) ? t.pop() : null;
|
|
24
25
|
t.forEach((r) => {
|
|
25
|
-
if (!r || !(
|
|
26
|
+
if (!r || !(k(r) || V(r)))
|
|
26
27
|
throw new Error(
|
|
27
28
|
"Bad parameters: buildUrl accepts only strings and numbers, with a hash map as the last parameter"
|
|
28
29
|
);
|
|
29
|
-
if (
|
|
30
|
+
if (k(r) && r.indexOf("?") >= 0)
|
|
30
31
|
throw new Error(
|
|
31
32
|
'Bad parameters: buildUrl does not accept strings with "?" character. Please use a hashmap as the last parameter instead!'
|
|
32
33
|
);
|
|
33
34
|
});
|
|
34
|
-
let
|
|
35
|
-
const [h, e] =
|
|
35
|
+
let o = t.join("/");
|
|
36
|
+
const [h, e] = o.split("://");
|
|
36
37
|
if (!h || !e)
|
|
37
|
-
throw new Error(`Bad URL: ${
|
|
38
|
-
return
|
|
38
|
+
throw new Error(`Bad URL: ${o}`);
|
|
39
|
+
return o = `${h}://${e.replace(/\/\/+/g, "/")}`, n && (o += `?${B(n)}`), o;
|
|
39
40
|
}
|
|
40
|
-
const I = "k8sClient:",
|
|
41
|
+
const I = "[k8sClient]:", C = (t) => function(...n) {
|
|
41
42
|
try {
|
|
42
|
-
const
|
|
43
|
-
console[t](...
|
|
44
|
-
} catch (
|
|
45
|
-
console.error(I, "Logging error:",
|
|
43
|
+
const o = [`${I}`, ...n];
|
|
44
|
+
console[t](...o);
|
|
45
|
+
} catch (o) {
|
|
46
|
+
console.error(I, "Logging error:", o);
|
|
46
47
|
}
|
|
47
|
-
},
|
|
48
|
+
}, P = C("error"), l = C("debug"), H = (t) => {
|
|
48
49
|
if (t.status >= 200 && t.status < 300)
|
|
49
50
|
return t;
|
|
50
51
|
{
|
|
51
|
-
const
|
|
52
|
-
throw
|
|
52
|
+
const n = new Error(t.statusText || `${t.status}`);
|
|
53
|
+
throw n.response = t, n;
|
|
53
54
|
}
|
|
54
55
|
};
|
|
55
|
-
function
|
|
56
|
-
n.
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
function U(t, n) {
|
|
57
|
+
if (!(!t || !n.startsWith("https:") || typeof window < "u"))
|
|
58
|
+
try {
|
|
59
|
+
return j?.Agent ? new j.Agent({
|
|
60
|
+
rejectUnauthorized: !1
|
|
61
|
+
}) : void 0;
|
|
62
|
+
} catch {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function E(t, n, o = {}) {
|
|
67
|
+
o.params && (n = p(n, o.params));
|
|
68
|
+
const { ignoreSsl: h, debug: e, ...r } = o, s = U(h || !1, n);
|
|
69
|
+
s && e === !0 && process.env.NODE_ENV !== "test" && l(`⚠️ SSL verification disabled for request to: ${n}`);
|
|
70
|
+
const a = ["signal", "headers", "body", "mode", "cache", "credentials"].reduce(
|
|
71
|
+
(m, f) => r[f] ? { ...m, [f]: r[f] } : m,
|
|
59
72
|
{ credentials: "same-origin", method: t }
|
|
60
73
|
);
|
|
61
|
-
return
|
|
74
|
+
return s && (a.agent = s), a.body && typeof a.body != "string" && (a.body = JSON.stringify(a.body)), e === !0 && l("fetch >", n, {
|
|
75
|
+
...a,
|
|
76
|
+
agent: s ? "HTTPS Agent (SSL ignored)" : a.agent
|
|
77
|
+
}), fetch(n, a).then(H);
|
|
62
78
|
}
|
|
63
|
-
const
|
|
64
|
-
class
|
|
65
|
-
constructor(
|
|
79
|
+
const R = "ADDED", A = "MODIFIED", O = "DELETED", w = "ERROR", X = "BOOKMARK";
|
|
80
|
+
class W {
|
|
81
|
+
constructor(n, o = {}, h) {
|
|
66
82
|
this.listeners = {
|
|
67
|
-
[
|
|
83
|
+
[R]: [],
|
|
68
84
|
[A]: [],
|
|
69
85
|
[O]: [],
|
|
70
|
-
[
|
|
86
|
+
[w]: []
|
|
71
87
|
}, this.controller = new AbortController(), this.signal = this.controller.signal, this.resourceVersion = null, this.PREFIX = "watch >", this.decoder = new TextDecoder(), this.refreshToken = (e) => {
|
|
72
88
|
this.options.headers && (this.options.headers.Authorization = `Bearer ${e}`);
|
|
73
89
|
}, this.checkType = (e) => {
|
|
74
|
-
if (![
|
|
90
|
+
if (![R, A, O, w].includes(e))
|
|
75
91
|
throw new Error(`Bad type: ${e}`);
|
|
76
92
|
}, this.addListener = (e, r) => {
|
|
77
93
|
this.checkType(e), this.listeners[e].push(r);
|
|
78
94
|
}, this.informListeners = (e, r) => {
|
|
79
|
-
const
|
|
80
|
-
|
|
95
|
+
const s = this.listeners[e];
|
|
96
|
+
s && s.forEach((c) => {
|
|
81
97
|
try {
|
|
82
|
-
|
|
83
|
-
} catch (
|
|
84
|
-
|
|
98
|
+
c(r);
|
|
99
|
+
} catch (a) {
|
|
100
|
+
P(a);
|
|
85
101
|
}
|
|
86
102
|
});
|
|
87
103
|
}, this.handleEvents = (e) => {
|
|
88
104
|
Array.isArray(e) || (e = [e]);
|
|
89
105
|
const r = this;
|
|
90
106
|
setTimeout(() => {
|
|
91
|
-
const
|
|
92
|
-
e.forEach((
|
|
93
|
-
|
|
94
|
-
}), Object.keys(
|
|
107
|
+
const s = {};
|
|
108
|
+
e.forEach((c) => {
|
|
109
|
+
c.type === X ? r.resourceVersion = c?.object?.metadata?.resourceVersion ?? null : (s[c.type] || (s[c.type] = []), s[c.type].push(c.object));
|
|
110
|
+
}), Object.keys(s).forEach((c) => r.informListeners(c, s[c]));
|
|
95
111
|
});
|
|
96
112
|
}, this.getResourceVersion = async () => {
|
|
97
113
|
if (this.resourceVersion) return this.resourceVersion;
|
|
98
114
|
l(this.PREFIX, "get resource version from API");
|
|
99
|
-
const { metadata: e, items: r } = await
|
|
100
|
-
(
|
|
115
|
+
const { metadata: e, items: r } = await E("GET", this.url, this.options).then(
|
|
116
|
+
(s) => (
|
|
101
117
|
// 'Body.json()' type definition expects 'any' as a return value
|
|
102
|
-
|
|
118
|
+
s.json()
|
|
103
119
|
)
|
|
104
120
|
);
|
|
105
|
-
return this.resourceVersion = e.resourceVersion, r && this.informListeners(
|
|
121
|
+
return this.resourceVersion = e.resourceVersion, r && this.informListeners(R, r), this.resourceVersion;
|
|
106
122
|
}, this.start = () => {
|
|
107
123
|
const e = this;
|
|
108
|
-
return e.getCurrentToken && e.refreshToken(e.getCurrentToken()), e.getResourceVersion().then((r) => (l(e.PREFIX, "current resource version", r),
|
|
124
|
+
return e.getCurrentToken && e.refreshToken(e.getCurrentToken()), e.getResourceVersion().then((r) => (l(e.PREFIX, "current resource version", r), E("GET", e.url, {
|
|
109
125
|
...e.options,
|
|
110
126
|
params: {
|
|
111
127
|
...e.options.params,
|
|
@@ -115,126 +131,129 @@ class $ {
|
|
|
115
131
|
},
|
|
116
132
|
signal: e.signal
|
|
117
133
|
}))).then(async (r) => {
|
|
118
|
-
const
|
|
119
|
-
let
|
|
120
|
-
for (; !
|
|
134
|
+
const s = r.body?.getReader();
|
|
135
|
+
let c = !1, a = "";
|
|
136
|
+
for (; !c; ) {
|
|
121
137
|
l(e.PREFIX, "read stream chunk");
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
if (
|
|
138
|
+
const m = await s?.read();
|
|
139
|
+
c = m?.done ?? !0, a += e.decoder.decode(m?.value || new Uint8Array());
|
|
140
|
+
const f = a.split(/\n|\r|\r\n/);
|
|
141
|
+
a = f.pop() ?? "";
|
|
142
|
+
const T = [];
|
|
143
|
+
f.forEach((D) => {
|
|
144
|
+
const b = JSON.parse(D);
|
|
145
|
+
if (b.type === w && b?.object?.code === 410) {
|
|
130
146
|
e.cancel(), setTimeout(() => {
|
|
131
147
|
l(e.PREFIX, "resource is gone 410", "recreate watch request!"), e.start();
|
|
132
148
|
});
|
|
133
149
|
return;
|
|
134
150
|
}
|
|
135
|
-
|
|
136
|
-
}), l(e.PREFIX, "inform listeners",
|
|
151
|
+
T.push(b);
|
|
152
|
+
}), l(e.PREFIX, "inform listeners", f), e.handleEvents(T);
|
|
137
153
|
}
|
|
138
154
|
}).catch((r) => {
|
|
139
155
|
if (r.name === "AbortError") return;
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
156
|
+
const s = r.code ?? r?.response?.status;
|
|
157
|
+
if (s === 410) {
|
|
142
158
|
l(e.PREFIX, "resource is gone 410"), e.resourceVersion = null, setTimeout(() => e.start(), 0);
|
|
143
159
|
return;
|
|
144
160
|
}
|
|
145
|
-
if (
|
|
146
|
-
e.handleEvents({ type:
|
|
161
|
+
if (s === 404) {
|
|
162
|
+
e.handleEvents({ type: w, object: r }), e.cancel();
|
|
147
163
|
return;
|
|
148
164
|
}
|
|
149
|
-
|
|
165
|
+
P("WATCH ERROR", r, r.code, s, r.response), console.dir(r), setTimeout(() => {
|
|
150
166
|
l(e.PREFIX, "recover connection", "restart!"), e.start();
|
|
151
167
|
}, 3e4);
|
|
152
168
|
}), e.cancel;
|
|
153
169
|
}, this.on = (e, r) => (this.addListener(e, r), this), this.cancel = () => {
|
|
154
170
|
l(this.PREFIX, "cancel connection"), this.controller.abort();
|
|
155
|
-
}, this.url =
|
|
171
|
+
}, this.url = n, this.options = o, this.getCurrentToken = h, o?.params?.resourceVersion && (this.resourceVersion = o.params.resourceVersion, delete o.params.resourceVersion);
|
|
156
172
|
}
|
|
157
173
|
}
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
return Promise.reject(
|
|
174
|
+
const y = async (t) => {
|
|
175
|
+
const n = t.response?.data ? new Error(t.response.data.message ?? t.message) : t;
|
|
176
|
+
return Promise.reject(n);
|
|
161
177
|
};
|
|
162
|
-
function
|
|
163
|
-
const { apiEndpoint:
|
|
164
|
-
let
|
|
165
|
-
if (!
|
|
178
|
+
function x(t) {
|
|
179
|
+
const { apiEndpoint: n, ignoreSsl: o = !1, debug: h = !1 } = t;
|
|
180
|
+
let e = t.token;
|
|
181
|
+
if (!n || !e)
|
|
166
182
|
throw new Error(`Bad options: ${JSON.stringify(t, null, 4)}. Please provide apiEndpoint and token`);
|
|
167
|
-
|
|
168
|
-
|
|
183
|
+
o && h === !0 && (console.warn(`⚠️ K8s Client: SSL certificate verification disabled for ${n}`), console.warn("🔒 This should only be used in development or secure internal networks"));
|
|
184
|
+
const r = () => ({
|
|
185
|
+
Authorization: `Bearer ${e}`,
|
|
169
186
|
"Content-Type": "application/json"
|
|
170
187
|
});
|
|
171
|
-
function
|
|
172
|
-
const
|
|
173
|
-
...
|
|
174
|
-
...
|
|
175
|
-
...
|
|
188
|
+
function s(i, u = {}) {
|
|
189
|
+
const d = {
|
|
190
|
+
...r(),
|
|
191
|
+
...u.headers,
|
|
192
|
+
...i.headers
|
|
176
193
|
};
|
|
177
194
|
return {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
195
|
+
debug: h,
|
|
196
|
+
ignoreSsl: o,
|
|
197
|
+
...u,
|
|
198
|
+
...i,
|
|
199
|
+
headers: d
|
|
181
200
|
};
|
|
182
201
|
}
|
|
183
|
-
function
|
|
184
|
-
return
|
|
202
|
+
function c(i, u = {}) {
|
|
203
|
+
return E("HEAD", p(n, i), s(u)).catch(y);
|
|
185
204
|
}
|
|
186
|
-
function
|
|
187
|
-
return
|
|
205
|
+
function a(i, u = {}) {
|
|
206
|
+
return E("GET", p(n, i), s(u)).then((d) => d.json()).catch(y);
|
|
188
207
|
}
|
|
189
|
-
function i
|
|
190
|
-
return
|
|
208
|
+
function m(i, u, d = {}) {
|
|
209
|
+
return E("POST", p(n, i), s(d, { body: u })).then((L) => L.json()).catch(y);
|
|
191
210
|
}
|
|
192
|
-
function
|
|
193
|
-
return
|
|
211
|
+
function f(i, u, d = {}) {
|
|
212
|
+
return E("PUT", p(n, i), s(d, { body: u })).then((g) => g.json()).catch(y);
|
|
194
213
|
}
|
|
195
|
-
function
|
|
196
|
-
return
|
|
214
|
+
function T(i, u, d = {}) {
|
|
215
|
+
return E(
|
|
197
216
|
"PATCH",
|
|
198
|
-
|
|
199
|
-
|
|
217
|
+
p(n, i),
|
|
218
|
+
s(d, {
|
|
200
219
|
headers: { "Content-Type": "application/merge-patch+json" },
|
|
201
|
-
body:
|
|
220
|
+
body: u
|
|
202
221
|
})
|
|
203
|
-
).then((
|
|
222
|
+
).then((g) => g.json()).catch(y);
|
|
204
223
|
}
|
|
205
|
-
function
|
|
206
|
-
return
|
|
224
|
+
function D(i, u, d = {}) {
|
|
225
|
+
return E("DELETE", p(n, i), s(d, { body: u })).then((g) => g.json()).catch(y);
|
|
207
226
|
}
|
|
208
|
-
function
|
|
209
|
-
return new
|
|
227
|
+
function b(i, u = {}) {
|
|
228
|
+
return new W(p(n, i), s(u), () => e);
|
|
210
229
|
}
|
|
211
|
-
function
|
|
212
|
-
|
|
230
|
+
function S(i) {
|
|
231
|
+
e = i;
|
|
213
232
|
}
|
|
214
|
-
function
|
|
215
|
-
return
|
|
233
|
+
function F() {
|
|
234
|
+
return e;
|
|
216
235
|
}
|
|
217
236
|
return {
|
|
218
|
-
WATCH_ERROR:
|
|
219
|
-
WATCH_ADDED:
|
|
237
|
+
WATCH_ERROR: w,
|
|
238
|
+
WATCH_ADDED: R,
|
|
220
239
|
WATCH_DELETED: O,
|
|
221
240
|
WATCH_MODIFIED: A,
|
|
222
|
-
head:
|
|
223
|
-
get:
|
|
224
|
-
post:
|
|
225
|
-
put:
|
|
226
|
-
patch:
|
|
227
|
-
delete:
|
|
228
|
-
watch:
|
|
229
|
-
refreshToken:
|
|
230
|
-
currentToken:
|
|
241
|
+
head: c,
|
|
242
|
+
get: a,
|
|
243
|
+
post: m,
|
|
244
|
+
put: f,
|
|
245
|
+
patch: T,
|
|
246
|
+
delete: D,
|
|
247
|
+
watch: b,
|
|
248
|
+
refreshToken: S,
|
|
249
|
+
currentToken: F
|
|
231
250
|
};
|
|
232
251
|
}
|
|
233
252
|
export {
|
|
234
|
-
|
|
253
|
+
R as ADDED,
|
|
235
254
|
O as DELETED,
|
|
236
|
-
|
|
255
|
+
w as ERROR,
|
|
237
256
|
A as MODIFIED,
|
|
238
|
-
|
|
239
|
-
|
|
257
|
+
W as Watch,
|
|
258
|
+
x as createClient
|
|
240
259
|
};
|
package/build/request.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
interface RequestOptions {
|
|
2
2
|
params?: Record<string, any>;
|
|
3
3
|
signal?: AbortSignal;
|
|
4
|
-
headers?:
|
|
4
|
+
headers?: Record<string, any>;
|
|
5
5
|
body?: Object | null;
|
|
6
6
|
mode?: RequestMode;
|
|
7
7
|
cache?: RequestCache;
|
|
8
8
|
credentials?: RequestCredentials;
|
|
9
|
+
ignoreSsl?: boolean;
|
|
10
|
+
debug?: boolean;
|
|
9
11
|
[key: string]: any;
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
@@ -13,9 +15,10 @@ interface RequestOptions {
|
|
|
13
15
|
*
|
|
14
16
|
* @param {string} method Http method.
|
|
15
17
|
* @param {string} url The URL to send the request to.
|
|
16
|
-
* @param {RequestOptions} options params, headers, and other options supported by fetch.
|
|
18
|
+
* @param {RequestOptions} options params, headers, ignoreSsl, and other options supported by fetch.
|
|
17
19
|
* @return {Promise<Response>} The response promise.
|
|
18
20
|
*/
|
|
19
21
|
declare function request(method: string, url: string, options?: RequestOptions): Promise<Response>;
|
|
20
22
|
export default request;
|
|
23
|
+
export type { RequestOptions };
|
|
21
24
|
//# sourceMappingURL=request.d.ts.map
|
package/build/request.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAUA,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAUA,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAChC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAiCD;;;;;;;GAOG;AACH,iBAAS,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CA8C7F;AAED,eAAe,OAAO,CAAA;AACtB,YAAY,EAAE,cAAc,EAAE,CAAA"}
|
package/build/watch.d.ts
CHANGED
package/build/watch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AASA,QAAA,MAAM,KAAK,UAAU,CAAA;AACrB,QAAA,MAAM,QAAQ,aAAa,CAAA;AAC3B,QAAA,MAAM,OAAO,YAAY,CAAA;AACzB,QAAA,MAAM,KAAK,UAAU,CAAA;AAGrB,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;AAmBzC,UAAU,YAAY;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,WAAW,CAAC,EAAE,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AASA,QAAA,MAAM,KAAK,UAAU,CAAA;AACrB,QAAA,MAAM,QAAQ,aAAa,CAAA;AAC3B,QAAA,MAAM,OAAO,YAAY,CAAA;AACzB,QAAA,MAAM,KAAK,UAAU,CAAA;AAGrB,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;AAmBzC,UAAU,YAAY;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAChC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,cAAM,KAAK;IACT,OAAO,CAAC,QAAQ,CAAC,SAAS,CAKzB;IACD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyC;IACpE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAC7D,OAAO,CAAC,eAAe,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAc;gBAEnC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,EAAE,eAAe,CAAC,EAAE,MAAM,MAAM;IAYnF,YAAY,GAAI,UAAU,MAAM,UAI/B;IAED,OAAO,CAAC,SAAS,CAIhB;IAED,OAAO,CAAC,WAAW,CAGlB;IAED,OAAO,CAAC,eAAe,CAYtB;IAED,OAAO,CAAC,YAAY,CAsBnB;IAED,OAAO,CAAC,kBAAkB,CAazB;IAED,KAAK,mBAmFJ;IAED,EAAE,GAAI,MAAM,MAAM,EAAE,UAAU,QAAQ,UAGrC;IAED,MAAM,aAGL;CACF;AAED,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudoperators/juno-k8s-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"author": "UI-Team",
|
|
5
5
|
"description": "JavaScript client for Kubernetes API",
|
|
6
6
|
"main": "build/index.cjs.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"vitest": "^3.2.4",
|
|
29
29
|
"@testing-library/jest-dom": "^6.6.3",
|
|
30
30
|
"vite-plugin-dts": "^4.5.4",
|
|
31
|
-
"@cloudoperators/juno-config": "0.0.
|
|
31
|
+
"@cloudoperators/juno-config": "0.0.5"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"test": "vitest run",
|