@cloudoperators/juno-k8s-client 1.0.3 → 1.0.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 -0
- package/build/index.d.ts +2 -0
- package/build/index.d.ts.map +1 -1
- package/build/{index.js → index.es.js} +5 -0
- package/package.json +12 -6
- package/build/types/index.d.ts +0 -2
|
@@ -0,0 +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;
|
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC9C,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudoperators/juno-k8s-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"author": "UI-Team",
|
|
5
5
|
"description": "JavaScript client for Kubernetes API",
|
|
6
|
-
"main": "build/index.js",
|
|
7
|
-
"module": "build/index.js",
|
|
8
|
-
"types": "build/
|
|
6
|
+
"main": "build/index.cjs.js",
|
|
7
|
+
"module": "build/index.es.js",
|
|
8
|
+
"types": "build/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./build/index.d.ts",
|
|
12
|
+
"import": "./build/index.es.js",
|
|
13
|
+
"require": "./build/index.cjs.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
9
16
|
"files": [
|
|
10
17
|
"build/**",
|
|
11
18
|
"LICENCE"
|
|
12
19
|
],
|
|
13
|
-
"type": "module",
|
|
14
20
|
"scripts": {
|
|
15
21
|
"test": "vitest run",
|
|
16
22
|
"lint": "eslint",
|
|
@@ -29,7 +35,7 @@
|
|
|
29
35
|
],
|
|
30
36
|
"devDependencies": {
|
|
31
37
|
"@cloudoperators/juno-config": "*",
|
|
32
|
-
"vite": "^6.
|
|
38
|
+
"vite": "^6.2.4",
|
|
33
39
|
"vite-plugin-dts": "^4.0.3"
|
|
34
40
|
}
|
|
35
41
|
}
|
package/build/types/index.d.ts
DELETED