@cloudoperators/juno-k8s-client 1.1.3 → 1.1.5
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/build/index.cjs.js +1 -1
- package/build/index.es.js +241 -249
- package/package.json +6 -4
package/build/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`https`);c=s(c);function l(e){return typeof e==`string`||e instanceof String}function u(e){return typeof e==`number`&&e.constructor===Number}function d(e){return typeof e==`object`&&!!e&&e.constructor===Object}var f=e=>{if(!e)return;let t=[];for(let n in e)if(Object.keys(e).includes(n)){let r=e[n];t.push(encodeURIComponent(n)+`=`+encodeURIComponent(r))}return t.join(`&`)};function p(...e){if(e.length<2)throw Error(`Bad parameters: buildUrl needs at least two non-empty parameters.`);let t=d(e[e.length-1])?e.pop():null;e.forEach(e=>{if(!e||!(l(e)||u(e)))throw Error(`Bad parameters: buildUrl accepts only strings and numbers, with a hash map as the last parameter`);if(l(e)&&e.indexOf(`?`)>=0)throw Error(`Bad parameters: buildUrl does not accept strings with "?" character. Please use a hashmap as the last parameter instead!`)});let n=e.join(`/`),[r,i]=n.split(`://`);if(!r||!i)throw Error(`Bad URL: ${n}`);return n=`${r}://${i.replace(/\/\/+/g,`/`)}`,t&&(n+=`?${f(t)}`),n}var m=`[k8sClient]:`,h=e=>function(...t){try{let n=[`${m}`,...t];console[e](...n)}catch(e){console.error(m,`Logging error:`,e)}},g=h(`error`),_=h(`debug`),v=e=>{if(e.status>=200&&e.status<300)return e;{let t=Error(e.statusText||`${e.status}`);throw t.response=e,t}};function y(e,t){if(!(!e||!t.startsWith(`https:`)||typeof window<`u`))try{return c.default?.Agent?new c.default.Agent({rejectUnauthorized:!1}):void 0}catch{return}}function b(e,t,n={}){n.params&&(t=p(t,n.params));let{ignoreSsl:r,debug:i,...a}=n,o=y(r||!1,t);o&&i===!0&&process.env.NODE_ENV!==`test`&&_(`⚠️ SSL verification disabled for request to: ${t}`);let s=[`signal`,`headers`,`body`,`mode`,`cache`,`credentials`].reduce((e,t)=>a[t]?{...e,[t]:a[t]}:e,{credentials:`same-origin`,method:e});return o&&(s.agent=o),s.body&&typeof s.body!=`string`&&(s.body=JSON.stringify(s.body)),i===!0&&_(`fetch >`,t,{...s,agent:o?`HTTPS Agent (SSL ignored)`:s.agent}),fetch(t,s).then(v)}var x=`ADDED`,S=`MODIFIED`,C=`DELETED`,w=`ERROR`,T=`BOOKMARK`,E=class{constructor(e,t={},n){this.listeners={[x]:[],[S]:[],[C]:[],[w]:[]},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(![`ADDED`,`MODIFIED`,`DELETED`,`ERROR`].includes(e))throw Error(`Bad type: ${e}`)},this.addListener=(e,t)=>{this.checkType(e),this.listeners[e].push(t)},this.informListeners=(e,t)=>{let n=this.listeners[e];n&&n.forEach(e=>{try{e(t)}catch(e){g(e)}})},this.handleEvents=e=>{Array.isArray(e)||(e=[e]);let t=this;setTimeout(()=>{let n={};e.forEach(e=>{e.type===T?t.resourceVersion=e?.object?.metadata?.resourceVersion??null:(n[e.type]||(n[e.type]=[]),n[e.type].push(e.object))}),Object.keys(n).forEach(e=>t.informListeners(e,n[e]))})},this.getResourceVersion=async()=>{if(this.resourceVersion)return this.resourceVersion;_(this.PREFIX,`get resource version from API`);let{metadata:e,items:t}=await b(`GET`,this.url,this.options).then(e=>e.json());return this.resourceVersion=e.resourceVersion,t&&this.informListeners(x,t),this.resourceVersion},this.start=()=>{let e=this;return e.getCurrentToken&&e.refreshToken(e.getCurrentToken()),e.getResourceVersion().then(t=>(_(e.PREFIX,`current resource version`,t),b(`GET`,e.url,{...e.options,params:{...e.options.params,watch:1,allowWatchBookmarks:!0,resourceVersion:t},signal:e.signal}))).then(async t=>{let n=t.body?.getReader(),r=!1,i=``;for(;!r;){_(e.PREFIX,`read stream chunk`);let t=await n?.read();r=t?.done??!0,i+=e.decoder.decode(t?.value||new Uint8Array);let a=i.split(/\n|\r|\r\n/);i=a.pop()??``;let o=[];a.forEach(t=>{let n=JSON.parse(t);if(n.type===`ERROR`&&n?.object?.code===410){e.cancel(),setTimeout(()=>{_(e.PREFIX,`resource is gone 410`,`recreate watch request!`),e.start()});return}o.push(n)}),_(e.PREFIX,`inform listeners`,a),e.handleEvents(o)}}).catch(t=>{if(t.name===`AbortError`)return;let n=t.code??t?.response?.status;if(n===410){_(e.PREFIX,`resource is gone 410`),e.resourceVersion=null,setTimeout(()=>e.start(),0);return}if(n===404){e.handleEvents({type:w,object:t}),e.cancel();return}g(`WATCH ERROR`,t,t.code,n,t.response),console.dir(t),setTimeout(()=>{_(e.PREFIX,`recover connection`,`restart!`),e.start()},3e4)}),e.cancel},this.on=(e,t)=>(this.addListener(e,t),this),this.cancel=()=>{_(this.PREFIX,`cancel connection`),this.controller.abort()},this.url=e,this.options=t,this.getCurrentToken=n,t?.params?.resourceVersion&&(this.resourceVersion=t.params.resourceVersion,delete t.params.resourceVersion)}},D=async e=>{let t=e.response?.data?Error(e.response.data.message??e.message):e;return Promise.reject(t)};function O(e){let{apiEndpoint:t,ignoreSsl:n=!1,debug:r=!1}=e,i=e.token;if(!t||!i)throw Error(`Bad options: ${JSON.stringify(e,null,4)}. Please provide apiEndpoint and token`);n&&r===!0&&(console.warn(`⚠️ K8s Client: SSL certificate verification disabled for ${t}`),console.warn(`🔒 This should only be used in development or secure internal networks`));let a=()=>({Authorization:`Bearer ${i}`,"Content-Type":`application/json`});function o(e,t={}){let i={...a(),...t.headers,...e.headers};return{debug:r,ignoreSsl:n,...t,...e,headers:i}}function s(e,n={}){return b(`HEAD`,p(t,e),o(n)).catch(D)}function c(e,n={}){return b(`GET`,p(t,e),o(n)).then(e=>e.json()).catch(D)}function l(e,n,r={}){return b(`POST`,p(t,e),o(r,{body:n})).then(e=>e.json()).catch(D)}function u(e,n,r={}){return b(`PUT`,p(t,e),o(r,{body:n})).then(e=>e.json()).catch(D)}function d(e,n,r={}){return b(`PATCH`,p(t,e),o(r,{headers:{"Content-Type":`application/merge-patch+json`},body:n})).then(e=>e.json()).catch(D)}function f(e,n,r={}){return b(`DELETE`,p(t,e),o(r,{body:n})).then(e=>e.json()).catch(D)}function m(e,n={}){return new E(p(t,e),o(n),()=>i)}function h(e){i=e}function g(){return i}return{WATCH_ERROR:w,WATCH_ADDED:x,WATCH_DELETED:C,WATCH_MODIFIED:S,head:s,get:c,post:l,put:u,patch:d,delete:f,watch:m,refreshToken:h,currentToken:g}}exports.ADDED=x,exports.DELETED=C,exports.ERROR=w,exports.MODIFIED=S,exports.Watch=E,exports.createClient=O;
|
package/build/index.es.js
CHANGED
|
@@ -1,259 +1,251 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import e from "https";
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
function t(e) {
|
|
4
|
+
return typeof e == "string" || e instanceof String;
|
|
4
5
|
}
|
|
5
|
-
function
|
|
6
|
-
|
|
6
|
+
function n(e) {
|
|
7
|
+
return typeof e == "number" && e.constructor === Number;
|
|
7
8
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
9
|
+
function r(e) {
|
|
10
|
+
return typeof e == "object" && !!e && e.constructor === Object;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/urlHelpers.ts
|
|
14
|
+
var i = (e) => {
|
|
15
|
+
if (!e) return;
|
|
16
|
+
let t = [];
|
|
17
|
+
for (let n in e) if (Object.keys(e).includes(n)) {
|
|
18
|
+
let r = e[n];
|
|
19
|
+
t.push(encodeURIComponent(n) + "=" + encodeURIComponent(r));
|
|
20
|
+
}
|
|
21
|
+
return t.join("&");
|
|
20
22
|
};
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
throw new Error(
|
|
32
|
-
'Bad parameters: buildUrl does not accept strings with "?" character. Please use a hashmap as the last parameter instead!'
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
let o = t.join("/");
|
|
36
|
-
const [h, e] = o.split("://");
|
|
37
|
-
if (!h || !e)
|
|
38
|
-
throw new Error(`Bad URL: ${o}`);
|
|
39
|
-
return o = `${h}://${e.replace(/\/\/+/g, "/")}`, n && (o += `?${B(n)}`), o;
|
|
23
|
+
function a(...e) {
|
|
24
|
+
if (e.length < 2) throw Error("Bad parameters: buildUrl needs at least two non-empty parameters.");
|
|
25
|
+
let a = r(e[e.length - 1]) ? e.pop() : null;
|
|
26
|
+
e.forEach((e) => {
|
|
27
|
+
if (!e || !(t(e) || n(e))) throw Error("Bad parameters: buildUrl accepts only strings and numbers, with a hash map as the last parameter");
|
|
28
|
+
if (t(e) && e.indexOf("?") >= 0) throw Error("Bad parameters: buildUrl does not accept strings with \"?\" character. Please use a hashmap as the last parameter instead!");
|
|
29
|
+
});
|
|
30
|
+
let o = e.join("/"), [s, c] = o.split("://");
|
|
31
|
+
if (!s || !c) throw Error(`Bad URL: ${o}`);
|
|
32
|
+
return o = `${s}://${c.replace(/\/\/+/g, "/")}`, a && (o += `?${i(a)}`), o;
|
|
40
33
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/logger.ts
|
|
36
|
+
var o = "[k8sClient]:", s = (e) => function(...t) {
|
|
37
|
+
try {
|
|
38
|
+
let n = [`${o}`, ...t];
|
|
39
|
+
console[e](...n);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
console.error(o, "Logging error:", e);
|
|
42
|
+
}
|
|
43
|
+
}, c = s("error"), l = s("debug"), u = (e) => {
|
|
44
|
+
if (e.status >= 200 && e.status < 300) return e;
|
|
45
|
+
{
|
|
46
|
+
let t = Error(e.statusText || `${e.status}`);
|
|
47
|
+
throw t.response = e, t;
|
|
48
|
+
}
|
|
55
49
|
};
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} catch {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
50
|
+
function d(t, n) {
|
|
51
|
+
if (!(!t || !n.startsWith("https:") || typeof window < "u")) try {
|
|
52
|
+
return e?.Agent ? new e.Agent({ rejectUnauthorized: !1 }) : void 0;
|
|
53
|
+
} catch {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
65
56
|
}
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
57
|
+
function f(e, t, n = {}) {
|
|
58
|
+
n.params && (t = a(t, n.params));
|
|
59
|
+
let { ignoreSsl: r, debug: i, ...o } = n, s = d(r || !1, t);
|
|
60
|
+
s && i === !0 && process.env.NODE_ENV !== "test" && l(`⚠️ SSL verification disabled for request to: ${t}`);
|
|
61
|
+
let c = [
|
|
62
|
+
"signal",
|
|
63
|
+
"headers",
|
|
64
|
+
"body",
|
|
65
|
+
"mode",
|
|
66
|
+
"cache",
|
|
67
|
+
"credentials"
|
|
68
|
+
].reduce((e, t) => o[t] ? {
|
|
69
|
+
...e,
|
|
70
|
+
[t]: o[t]
|
|
71
|
+
} : e, {
|
|
72
|
+
credentials: "same-origin",
|
|
73
|
+
method: e
|
|
74
|
+
});
|
|
75
|
+
return s && (c.agent = s), c.body && typeof c.body != "string" && (c.body = JSON.stringify(c.body)), i === !0 && l("fetch >", t, {
|
|
76
|
+
...c,
|
|
77
|
+
agent: s ? "HTTPS Agent (SSL ignored)" : c.agent
|
|
78
|
+
}), fetch(t, c).then(u);
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/watch.ts
|
|
82
|
+
var p = "ADDED", m = "MODIFIED", h = "DELETED", g = "ERROR", _ = "BOOKMARK", v = class {
|
|
83
|
+
constructor(e, t = {}, n) {
|
|
84
|
+
this.listeners = {
|
|
85
|
+
[p]: [],
|
|
86
|
+
[m]: [],
|
|
87
|
+
[h]: [],
|
|
88
|
+
[g]: []
|
|
89
|
+
}, this.controller = new AbortController(), this.signal = this.controller.signal, this.resourceVersion = null, this.PREFIX = "watch >", this.decoder = new TextDecoder(), this.refreshToken = (e) => {
|
|
90
|
+
this.options.headers && (this.options.headers.Authorization = `Bearer ${e}`);
|
|
91
|
+
}, this.checkType = (e) => {
|
|
92
|
+
if (![
|
|
93
|
+
"ADDED",
|
|
94
|
+
"MODIFIED",
|
|
95
|
+
"DELETED",
|
|
96
|
+
"ERROR"
|
|
97
|
+
].includes(e)) throw Error(`Bad type: ${e}`);
|
|
98
|
+
}, this.addListener = (e, t) => {
|
|
99
|
+
this.checkType(e), this.listeners[e].push(t);
|
|
100
|
+
}, this.informListeners = (e, t) => {
|
|
101
|
+
let n = this.listeners[e];
|
|
102
|
+
n && n.forEach((e) => {
|
|
103
|
+
try {
|
|
104
|
+
e(t);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
c(e);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}, this.handleEvents = (e) => {
|
|
110
|
+
Array.isArray(e) || (e = [e]);
|
|
111
|
+
let t = this;
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
let n = {};
|
|
114
|
+
e.forEach((e) => {
|
|
115
|
+
e.type === _ ? t.resourceVersion = e?.object?.metadata?.resourceVersion ?? null : (n[e.type] || (n[e.type] = []), n[e.type].push(e.object));
|
|
116
|
+
}), Object.keys(n).forEach((e) => t.informListeners(e, n[e]));
|
|
117
|
+
});
|
|
118
|
+
}, this.getResourceVersion = async () => {
|
|
119
|
+
if (this.resourceVersion) return this.resourceVersion;
|
|
120
|
+
l(this.PREFIX, "get resource version from API");
|
|
121
|
+
let { metadata: e, items: t } = await f("GET", this.url, this.options).then((e) => e.json());
|
|
122
|
+
return this.resourceVersion = e.resourceVersion, t && this.informListeners(p, t), this.resourceVersion;
|
|
123
|
+
}, this.start = () => {
|
|
124
|
+
let e = this;
|
|
125
|
+
return e.getCurrentToken && e.refreshToken(e.getCurrentToken()), e.getResourceVersion().then((t) => (l(e.PREFIX, "current resource version", t), f("GET", e.url, {
|
|
126
|
+
...e.options,
|
|
127
|
+
params: {
|
|
128
|
+
...e.options.params,
|
|
129
|
+
watch: 1,
|
|
130
|
+
allowWatchBookmarks: !0,
|
|
131
|
+
resourceVersion: t
|
|
132
|
+
},
|
|
133
|
+
signal: e.signal
|
|
134
|
+
}))).then(async (t) => {
|
|
135
|
+
let n = t.body?.getReader(), r = !1, i = "";
|
|
136
|
+
for (; !r;) {
|
|
137
|
+
l(e.PREFIX, "read stream chunk");
|
|
138
|
+
let t = await n?.read();
|
|
139
|
+
r = t?.done ?? !0, i += e.decoder.decode(t?.value || new Uint8Array());
|
|
140
|
+
let a = i.split(/\n|\r|\r\n/);
|
|
141
|
+
i = a.pop() ?? "";
|
|
142
|
+
let o = [];
|
|
143
|
+
a.forEach((t) => {
|
|
144
|
+
let n = JSON.parse(t);
|
|
145
|
+
if (n.type === "ERROR" && n?.object?.code === 410) {
|
|
146
|
+
e.cancel(), setTimeout(() => {
|
|
147
|
+
l(e.PREFIX, "resource is gone 410", "recreate watch request!"), e.start();
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
o.push(n);
|
|
152
|
+
}), l(e.PREFIX, "inform listeners", a), e.handleEvents(o);
|
|
153
|
+
}
|
|
154
|
+
}).catch((t) => {
|
|
155
|
+
if (t.name === "AbortError") return;
|
|
156
|
+
let n = t.code ?? t?.response?.status;
|
|
157
|
+
if (n === 410) {
|
|
158
|
+
l(e.PREFIX, "resource is gone 410"), e.resourceVersion = null, setTimeout(() => e.start(), 0);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (n === 404) {
|
|
162
|
+
e.handleEvents({
|
|
163
|
+
type: g,
|
|
164
|
+
object: t
|
|
165
|
+
}), e.cancel();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
c("WATCH ERROR", t, t.code, n, t.response), console.dir(t), setTimeout(() => {
|
|
169
|
+
l(e.PREFIX, "recover connection", "restart!"), e.start();
|
|
170
|
+
}, 3e4);
|
|
171
|
+
}), e.cancel;
|
|
172
|
+
}, this.on = (e, t) => (this.addListener(e, t), this), this.cancel = () => {
|
|
173
|
+
l(this.PREFIX, "cancel connection"), this.controller.abort();
|
|
174
|
+
}, this.url = e, this.options = t, this.getCurrentToken = n, t?.params?.resourceVersion && (this.resourceVersion = t.params.resourceVersion, delete t.params.resourceVersion);
|
|
175
|
+
}
|
|
176
|
+
}, y = async (e) => {
|
|
177
|
+
let t = e.response?.data ? Error(e.response.data.message ?? e.message) : e;
|
|
178
|
+
return Promise.reject(t);
|
|
177
179
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
watch: b,
|
|
248
|
-
refreshToken: S,
|
|
249
|
-
currentToken: F
|
|
250
|
-
};
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/client.ts
|
|
182
|
+
function b(e) {
|
|
183
|
+
let { apiEndpoint: t, ignoreSsl: n = !1, debug: r = !1 } = e, i = e.token;
|
|
184
|
+
if (!t || !i) throw Error(`Bad options: ${JSON.stringify(e, null, 4)}. Please provide apiEndpoint and token`);
|
|
185
|
+
n && r === !0 && (console.warn(`⚠️ K8s Client: SSL certificate verification disabled for ${t}`), console.warn("🔒 This should only be used in development or secure internal networks"));
|
|
186
|
+
let o = () => ({
|
|
187
|
+
Authorization: `Bearer ${i}`,
|
|
188
|
+
"Content-Type": "application/json"
|
|
189
|
+
});
|
|
190
|
+
function s(e, t = {}) {
|
|
191
|
+
let i = {
|
|
192
|
+
...o(),
|
|
193
|
+
...t.headers,
|
|
194
|
+
...e.headers
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
debug: r,
|
|
198
|
+
ignoreSsl: n,
|
|
199
|
+
...t,
|
|
200
|
+
...e,
|
|
201
|
+
headers: i
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function c(e, n = {}) {
|
|
205
|
+
return f("HEAD", a(t, e), s(n)).catch(y);
|
|
206
|
+
}
|
|
207
|
+
function l(e, n = {}) {
|
|
208
|
+
return f("GET", a(t, e), s(n)).then((e) => e.json()).catch(y);
|
|
209
|
+
}
|
|
210
|
+
function u(e, n, r = {}) {
|
|
211
|
+
return f("POST", a(t, e), s(r, { body: n })).then((e) => e.json()).catch(y);
|
|
212
|
+
}
|
|
213
|
+
function d(e, n, r = {}) {
|
|
214
|
+
return f("PUT", a(t, e), s(r, { body: n })).then((e) => e.json()).catch(y);
|
|
215
|
+
}
|
|
216
|
+
function _(e, n, r = {}) {
|
|
217
|
+
return f("PATCH", a(t, e), s(r, {
|
|
218
|
+
headers: { "Content-Type": "application/merge-patch+json" },
|
|
219
|
+
body: n
|
|
220
|
+
})).then((e) => e.json()).catch(y);
|
|
221
|
+
}
|
|
222
|
+
function b(e, n, r = {}) {
|
|
223
|
+
return f("DELETE", a(t, e), s(r, { body: n })).then((e) => e.json()).catch(y);
|
|
224
|
+
}
|
|
225
|
+
function x(e, n = {}) {
|
|
226
|
+
return new v(a(t, e), s(n), () => i);
|
|
227
|
+
}
|
|
228
|
+
function S(e) {
|
|
229
|
+
i = e;
|
|
230
|
+
}
|
|
231
|
+
function C() {
|
|
232
|
+
return i;
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
WATCH_ERROR: g,
|
|
236
|
+
WATCH_ADDED: p,
|
|
237
|
+
WATCH_DELETED: h,
|
|
238
|
+
WATCH_MODIFIED: m,
|
|
239
|
+
head: c,
|
|
240
|
+
get: l,
|
|
241
|
+
post: u,
|
|
242
|
+
put: d,
|
|
243
|
+
patch: _,
|
|
244
|
+
delete: b,
|
|
245
|
+
watch: x,
|
|
246
|
+
refreshToken: S,
|
|
247
|
+
currentToken: C
|
|
248
|
+
};
|
|
251
249
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
O as DELETED,
|
|
255
|
-
w as ERROR,
|
|
256
|
-
A as MODIFIED,
|
|
257
|
-
W as Watch,
|
|
258
|
-
x as createClient
|
|
259
|
-
};
|
|
250
|
+
//#endregion
|
|
251
|
+
export { p as ADDED, h as DELETED, g as ERROR, m as MODIFIED, v as Watch, b as createClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudoperators/juno-k8s-client",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"author": "UI-Team",
|
|
5
5
|
"description": "JavaScript client for Kubernetes API",
|
|
6
6
|
"main": "build/index.cjs.js",
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
"build/**",
|
|
18
18
|
"LICENCE"
|
|
19
19
|
],
|
|
20
|
+
"repository": "https://github.com/cloudoperators/juno/tree/main/packages/k8s-client",
|
|
21
|
+
"license": "Apache-2.0",
|
|
20
22
|
"keywords": [
|
|
21
23
|
"kubernetes",
|
|
22
24
|
"js",
|
|
@@ -24,10 +26,10 @@
|
|
|
24
26
|
"client"
|
|
25
27
|
],
|
|
26
28
|
"devDependencies": {
|
|
27
|
-
"vite": "
|
|
28
|
-
"vitest": "3.2.4",
|
|
29
|
+
"vite": "8.0.10",
|
|
29
30
|
"vite-plugin-dts": "4.5.4",
|
|
30
|
-
"
|
|
31
|
+
"vitest": "3.2.4",
|
|
32
|
+
"@cloudoperators/juno-config": "0.0.7"
|
|
31
33
|
},
|
|
32
34
|
"scripts": {
|
|
33
35
|
"test": "vitest run",
|