@cloudoperators/juno-k8s-client 1.0.4 → 1.0.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.
package/README.md CHANGED
@@ -24,6 +24,12 @@ With npm:
24
24
  npm install @cloudoperators/juno-k8s-client
25
25
  ```
26
26
 
27
+ With pnpm:
28
+
29
+ ```
30
+ pnpm add @cloudoperators/juno-k8s-client
31
+ ```
32
+
27
33
  With yarn:
28
34
 
29
35
  ```
@@ -135,7 +141,7 @@ setTimeout(podsWatch.cancel, 5 * 60 * 1000) // 5 minutes
135
141
  All dependencies of this project are expressed in its package.json file. Before you start developing, ensure that you have NPM installed, then run:
136
142
 
137
143
  ```bash
138
- npm install
139
- npm run test
140
- npm run build
144
+ pnpm install
145
+ pnpm test
146
+ pnpm build
141
147
  ```
@@ -1 +1 @@
1
- {"version":3,"file":"apiErrorHandler.d.ts","sourceRoot":"","sources":["../src/apiErrorHandler.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE;YAAE,OAAO,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,QAAA,MAAM,eAAe,aAAoB,WAAW,KAAG,OAAO,CAAC,WAAW,CAIzE,CAAA;AAED,eAAe,eAAe,CAAA"}
1
+ {"version":3,"file":"apiErrorHandler.d.ts","sourceRoot":"","sources":["../src/apiErrorHandler.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE;YAAE,OAAO,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,QAAA,MAAM,eAAe,GAAU,UAAU,WAAW,KAAG,OAAO,CAAC,WAAW,CAIzE,CAAA;AAED,eAAe,eAAe,CAAA"}
@@ -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
@@ -1,3 +1,5 @@
1
1
  export { createClient } from './client';
2
2
  export type { RequestOptions } from './client';
3
+ export type { K8sApiError } from './apiErrorHandler';
4
+ export { ADDED, MODIFIED, DELETED, ERROR, Watch } from './watch';
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -237,5 +237,10 @@ function H(t) {
237
237
  };
238
238
  }
239
239
  export {
240
+ D as ADDED,
241
+ O as DELETED,
242
+ R as ERROR,
243
+ A as MODIFIED,
244
+ $ as Watch,
240
245
  H as createClient
241
246
  };
@@ -1 +1 @@
1
- {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AASA,QAAA,MAAM,KAAK,UAAU,CAAA;AACrB,QAAA,MAAM,QAAQ,aAAa,CAAA;AAC3B,QAAA,MAAM,OAAO,YAAY,CAAA;AACzB,QAAA,MAAM,KAAK,UAAU,CAAA;AAGrB,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;AAmBzC,UAAU,YAAY;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,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;CACjC;AAED,cAAM,KAAK;IACT,OAAO,CAAC,QAAQ,CAAC,SAAS,CAKzB;IACD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyC;IACpE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAC7D,OAAO,CAAC,eAAe,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAc;gBAEnC,GAAG,EAAE,MAAM,EAAE,OA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C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAc;gBAEnC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,EAAE,eAAe,CAAC,EAAE,MAAM,MAAM;IAYnF,YAAY,GAAI,UAAU,MAAM,UAI/B;IAED,OAAO,CAAC,SAAS,CAIhB;IAED,OAAO,CAAC,WAAW,CAGlB;IAED,OAAO,CAAC,eAAe,CAYtB;IAED,OAAO,CAAC,YAAY,CAsBnB;IAED,OAAO,CAAC,kBAAkB,CAazB;IAED,KAAK,mBAmFJ;IAED,EAAE,GAAI,MAAM,MAAM,EAAE,UAAU,QAAQ,UAGrC;IAED,MAAM,aAGL;CACF;AAED,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,16 +1,35 @@
1
1
  {
2
2
  "name": "@cloudoperators/juno-k8s-client",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
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/types/index.d.ts",
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",
20
+ "keywords": [
21
+ "kubernetes",
22
+ "js",
23
+ "typescript",
24
+ "client"
25
+ ],
26
+ "devDependencies": {
27
+ "vite": "^6.3.5",
28
+ "vitest": "^3.0.7",
29
+ "@testing-library/jest-dom": "^5.16.5",
30
+ "vite-plugin-dts": "^4.0.3",
31
+ "@cloudoperators/juno-config": "0.0.1"
32
+ },
14
33
  "scripts": {
15
34
  "test": "vitest run",
16
35
  "lint": "eslint",
@@ -20,16 +39,5 @@
20
39
  "serve": "vite preview",
21
40
  "clean": "rm -rf build && rm -rf node_modules && rm -rf .turbo",
22
41
  "clean:cache": "rm -rf .turbo"
23
- },
24
- "keywords": [
25
- "kubernetes",
26
- "js",
27
- "typescript",
28
- "client"
29
- ],
30
- "devDependencies": {
31
- "@cloudoperators/juno-config": "*",
32
- "vite": "^6.2.4",
33
- "vite-plugin-dts": "^4.0.3"
34
42
  }
35
- }
43
+ }
@@ -1,2 +0,0 @@
1
- export * from '../index'
2
- export {}