@cloudoperators/juno-k8s-client 1.1.5 → 1.1.6

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
- 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;
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,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,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
@@ -48,7 +48,7 @@ var o = "[k8sClient]:", s = (e) => function(...t) {
48
48
  }
49
49
  };
50
50
  function d(t, n) {
51
- if (!(!t || !n.startsWith("https:") || typeof window < "u")) try {
51
+ if (t && n.startsWith("https:") && typeof window > "u") try {
52
52
  return e?.Agent ? new e.Agent({ rejectUnauthorized: !1 }) : void 0;
53
53
  } catch {
54
54
  return;
@@ -136,7 +136,7 @@ var p = "ADDED", m = "MODIFIED", h = "DELETED", g = "ERROR", _ = "BOOKMARK", v =
136
136
  for (; !r;) {
137
137
  l(e.PREFIX, "read stream chunk");
138
138
  let t = await n?.read();
139
- r = t?.done ?? !0, i += e.decoder.decode(t?.value || new Uint8Array());
139
+ r = t?.done ?? !0, i += e.decoder.decode(t?.value || /* @__PURE__ */ new Uint8Array());
140
140
  let a = i.split(/\n|\r|\r\n/);
141
141
  i = a.pop() ?? "";
142
142
  let o = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudoperators/juno-k8s-client",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "author": "UI-Team",
5
5
  "description": "JavaScript client for Kubernetes API",
6
6
  "main": "build/index.cjs.js",
@@ -17,7 +17,10 @@
17
17
  "build/**",
18
18
  "LICENCE"
19
19
  ],
20
- "repository": "https://github.com/cloudoperators/juno/tree/main/packages/k8s-client",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/cloudoperators/juno/tree/main/packages/k8s-client"
23
+ },
21
24
  "license": "Apache-2.0",
22
25
  "keywords": [
23
26
  "kubernetes",
@@ -26,10 +29,10 @@
26
29
  "client"
27
30
  ],
28
31
  "devDependencies": {
29
- "vite": "8.0.10",
30
- "vite-plugin-dts": "4.5.4",
31
- "vitest": "3.2.4",
32
- "@cloudoperators/juno-config": "0.0.7"
32
+ "@cloudoperators/juno-config": "0.1.1",
33
+ "vite": "8.3.0",
34
+ "vite-plugin-dts": "5.1.1",
35
+ "vitest": "5.0.0"
33
36
  },
34
37
  "scripts": {
35
38
  "test": "vitest run",