@cloudoperators/juno-k8s-client 1.0.7 → 1.0.8

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