@cloudoperators/juno-k8s-client 1.1.0 → 1.1.2

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