@cloudoperators/juno-k8s-client 1.0.2 → 1.0.4

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,10 +1,18 @@
1
- interface ApiErrorType extends Error {
1
+ export interface K8sApiError extends Error {
2
+ apiVersion?: string;
3
+ kind?: string;
4
+ message: string;
5
+ metadata?: Record<string, any>;
6
+ reason?: string;
7
+ status?: string;
8
+ code?: number;
2
9
  response?: {
3
10
  data?: {
4
11
  message?: string;
5
12
  };
13
+ status?: number;
6
14
  };
7
15
  }
8
- declare const apiErrorHandler: (apiError: ApiErrorType) => Promise<never>;
16
+ declare const apiErrorHandler: (apiError: K8sApiError) => Promise<K8sApiError>;
9
17
  export default apiErrorHandler;
10
18
  //# sourceMappingURL=apiErrorHandler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"apiErrorHandler.d.ts","sourceRoot":"","sources":["../src/apiErrorHandler.ts"],"names":[],"mappings":"AAAA,UAAU,YAAa,SAAQ,KAAK;IAClC,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE;YAAE,OAAO,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAC5B,CAAA;CACF;AACD,QAAA,MAAM,eAAe,aAAoB,YAAY,KAAG,OAAO,CAAC,KAAK,CAIpE,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,aAAoB,WAAW,KAAG,OAAO,CAAC,WAAW,CAIzE,CAAA;AAED,eAAe,eAAe,CAAA"}
package/build/client.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Watch } from './watch';
2
+ import { K8sApiError } from './apiErrorHandler';
2
3
  interface ClientOptions {
3
4
  apiEndpoint: string;
4
5
  token: string;
@@ -7,7 +8,7 @@ interface ClientOptions {
7
8
  interface RequestOptions {
8
9
  params?: Record<string, any>;
9
10
  headers?: Record<string, string>;
10
- body?: any;
11
+ body?: Object | null;
11
12
  signal?: AbortSignal;
12
13
  mode?: RequestMode;
13
14
  cache?: RequestCache;
@@ -18,15 +19,15 @@ declare function createClient(options: ClientOptions): {
18
19
  WATCH_ADDED: string;
19
20
  WATCH_DELETED: string;
20
21
  WATCH_MODIFIED: string;
21
- head: (path: string, options?: RequestOptions) => Promise<Response>;
22
- get: (path: string, options?: RequestOptions) => Promise<any>;
23
- post: (path: string, data: {}, options?: RequestOptions) => Promise<any>;
24
- put: (path: string, data: {}, options?: RequestOptions) => Promise<any>;
25
- patch: (path: string, data: {}, options?: RequestOptions) => Promise<any>;
26
- delete: (path: string, data?: {} | null, options?: RequestOptions) => Promise<any>;
22
+ head: (path: string, options?: RequestOptions) => Promise<Response | K8sApiError>;
23
+ get: (path: string, options?: RequestOptions) => Promise<unknown>;
24
+ post: (path: string, data: {}, options?: RequestOptions) => Promise<unknown>;
25
+ put: (path: string, data: {}, options?: RequestOptions) => Promise<unknown>;
26
+ patch: (path: string, data: {}, options?: RequestOptions) => Promise<unknown>;
27
+ delete: (path: string, data?: {} | null, options?: RequestOptions) => Promise<unknown>;
27
28
  watch: (path: string, options?: RequestOptions) => Watch;
28
29
  refreshToken: (newToken: string) => void;
29
30
  currentToken: () => string;
30
31
  };
31
- export { createClient };
32
+ export { createClient, type RequestOptions };
32
33
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAmC,MAAM,SAAS,CAAA;AAGhE,UAAU,aAAa;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,WAAW,CAAC,EAAE,kBAAkB,CAAA;CACjC;AAED,iBAAS,YAAY,CAAC,OAAO,EAAE,aAAa;;;;;iBA2BtB,MAAM,YAAW,cAAc,KAAQ,OAAO,CAAC,QAAQ,CAAC;gBAIzD,MAAM,YAAW,cAAc,KAAQ,OAAO,CAAC,GAAG,CAAC;iBAMlD,MAAM,QAAQ,EAAE,YAAW,cAAc,KAAQ,OAAO,CAAC,GAAG,CAAC;gBAO9D,MAAM,QAAQ,EAAE,YAAW,cAAc,KAAQ,OAAO,CAAC,GAAG,CAAC;kBAM3D,MAAM,QAAQ,EAAE,YAAW,cAAc,KAAQ,OAAO,CAAC,GAAG,CAAC;mBAa/D,MAAM,SAAS,EAAE,GAAG,IAAI,YAAW,cAAc,KAAQ,OAAO,CAAC,GAAG,CAAC;kBAMnE,MAAM,YAAW,cAAc,KAAQ,KAAK;6BAIjC,MAAM,KAAG,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C,MAAM,KAAG,IAAI;wBAIpB,MAAM;EAmBhC;AAED,OAAO,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,CAAA"}
package/build/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { createClient } from './client';
2
+ export type { RequestOptions } from './client';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,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"}
package/build/index.js CHANGED
@@ -1,238 +1,239 @@
1
- function D(r) {
2
- return typeof r == "string" || r instanceof String;
1
+ function j(t) {
2
+ return typeof t == "string" || t instanceof String;
3
3
  }
4
- function V(r) {
5
- return typeof r == "number" && r.constructor === Number;
4
+ function F(t) {
5
+ return typeof t == "number" && t.constructor === Number;
6
6
  }
7
- function F(r) {
8
- return r !== null && typeof r == "object" && r.constructor === Object;
7
+ function V(t) {
8
+ return t !== null && typeof t == "object" && t.constructor === Object;
9
9
  }
10
- const B = (r) => {
11
- if (!r) return;
12
- const e = [];
13
- for (const t in r)
14
- if (Object.prototype.hasOwnProperty.call(r, t)) {
15
- const n = r[t];
16
- e.push(encodeURIComponent(t) + "=" + encodeURIComponent(n));
10
+ const B = (t) => {
11
+ if (!t) return;
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));
17
17
  }
18
- return e.join("&");
18
+ return s.join("&");
19
19
  };
20
- function d(...r) {
21
- if (r.length < 2)
20
+ function E(...t) {
21
+ if (t.length < 2)
22
22
  throw new Error("Bad parameters: buildUrl needs at least two non-empty parameters.");
23
- const e = F(r[r.length - 1]) ? r.pop() : null;
24
- r.forEach((i) => {
25
- if (!i || !(D(i) || V(i)))
23
+ const s = V(t[t.length - 1]) ? t.pop() : null;
24
+ t.forEach((e) => {
25
+ if (!e || !(j(e) || F(e)))
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 (D(i) && i.indexOf("?") >= 0)
29
+ if (j(e) && e.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 t = r.join("/");
35
- const [n, s] = t.split("://");
36
- if (!n || !s)
37
- throw new Error(`Bad URL: ${t}`);
38
- return t = `${n}://${s.replace(/\/\/+/g, "/")}`, e && (t += `?${B(e)}`), t;
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;
39
39
  }
40
- const O = "k8sClient:", j = (r) => function(...e) {
40
+ const I = "k8sClient:", P = (t) => function(...s) {
41
41
  try {
42
- const t = [`${O}`, ...e];
43
- console[r](...t);
44
- } catch (t) {
45
- console.error(O, "Logging error:", t);
42
+ const r = [`${I}`, ...s];
43
+ console[t](...r);
44
+ } catch (r) {
45
+ console.error(I, "Logging error:", r);
46
46
  }
47
- }, A = j("error"), h = j("debug"), L = (r) => {
48
- if (r.status >= 200 && r.status < 300)
49
- return r;
47
+ }, k = P("error"), f = P("debug"), L = (t) => {
48
+ if (t.status >= 200 && t.status < 300)
49
+ return t;
50
50
  {
51
- const e = new Error(r.statusText || `${r.status}`);
52
- throw e.response = r, e;
51
+ const s = new Error(t.statusText || `${t.status}`);
52
+ throw s.response = t, s;
53
53
  }
54
54
  };
55
- function l(r, e, t = {}) {
56
- t.params && (e = d(e, t.params));
57
- const n = ["signal", "headers", "body", "mode", "cache", "credentials"].reduce(
58
- (s, i) => (t[i] && (s[i] = t[i]), s),
59
- { credentials: "same-origin", method: r }
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,
59
+ { credentials: "same-origin", method: t }
60
60
  );
61
- return n.body && typeof n.body != "string" && (n.body = JSON.stringify(n.body)), h("fetch >", e, n), fetch(e, n).then(L);
61
+ return i.body && typeof i.body != "string" && (i.body = JSON.stringify(i.body)), f("fetch >", s, i), fetch(s, i).then(L);
62
62
  }
63
- const b = "ADDED", R = "MODIFIED", g = "DELETED", y = "ERROR", X = "BOOKMARK";
63
+ const D = "ADDED", A = "MODIFIED", O = "DELETED", R = "ERROR", X = "BOOKMARK";
64
64
  class $ {
65
- constructor(e, t = {}, n) {
65
+ constructor(s, r = {}, d) {
66
+ var i;
66
67
  this.listeners = {
67
- [b]: [],
68
- [R]: [],
69
- [g]: [],
70
- [y]: []
71
- }, this.controller = new AbortController(), this.signal = this.controller.signal, this.resourceVersion = null, this.PREFIX = "watch >", this.decoder = new TextDecoder(), this.url = e, this.options = t, this.getCurrentToken = n, t.params && t.params.resourceVersion && (this.resourceVersion = t.params.resourceVersion, delete t.params.resourceVersion);
72
- }
73
- refreshToken(e) {
74
- this.options.headers && (this.options.headers.Authorization = `Bearer ${e}`);
75
- }
76
- checkType(e) {
77
- if (![b, R, g, y].includes(e))
78
- throw new Error(`Bad type: ${e}`);
79
- }
80
- addListener(e, t) {
81
- this.checkType(e), this.listeners[e].push(t);
82
- }
83
- informListeners(e, t) {
84
- const n = this.listeners[e];
85
- n && n.forEach((s) => {
86
- try {
87
- s(t);
88
- } catch (i) {
89
- A(i);
90
- }
91
- });
92
- }
93
- handleEvents(e) {
94
- Array.isArray(e) || (e = [e]), setTimeout(() => {
95
- const t = {};
96
- e.forEach((n) => {
97
- n.type === X ? this.resourceVersion = n.object.metadata.resourceVersion : (t[n.type] || (t[n.type] = []), t[n.type].push(n.object));
98
- }), Object.keys(t).forEach((n) => this.informListeners(n, t[n]));
99
- });
100
- }
101
- async getResourceVersion() {
102
- if (this.resourceVersion) return this.resourceVersion;
103
- h(this.PREFIX, "get resource version from API");
104
- const { metadata: e, items: t } = await l("GET", this.url, this.options).then((n) => n.json());
105
- return this.resourceVersion = e.resourceVersion, t && this.informListeners(b, t), this.resourceVersion;
106
- }
107
- start() {
108
- return this.getCurrentToken && this.refreshToken(this.getCurrentToken()), this.getResourceVersion().then((e) => (h(this.PREFIX, "current resource version", e), l("GET", this.url, {
109
- ...this.options,
110
- params: {
111
- ...this.options.params,
112
- watch: 1,
113
- allowWatchBookmarks: !0,
114
- resourceVersion: e
115
- },
116
- signal: this.signal
117
- }))).then(async (e) => {
118
- var i;
119
- const t = (i = e.body) == null ? void 0 : i.getReader();
120
- let n = !1, s = "";
121
- for (; !n; ) {
122
- h(this.PREFIX, "read stream chunk");
123
- const u = await (t == null ? void 0 : t.read());
124
- n = (u == null ? void 0 : u.done) ?? !0, s += this.decoder.decode((u == null ? void 0 : u.value) || new Uint8Array());
125
- const E = s.split(/\n|\r|\r\n/);
126
- s = E.pop() || "";
127
- const T = [];
128
- E.forEach((w) => {
129
- const m = JSON.parse(w);
130
- if (m.type === y && m.object.code === 410) {
131
- this.cancel(), setTimeout(() => {
132
- h(this.PREFIX, "resource is gone 410", "recreate watch request!"), this.start();
133
- });
134
- return;
135
- }
136
- T.push(m);
137
- }), h(this.PREFIX, "inform listeners", E), this.handleEvents(T);
138
- }
139
- }).catch((e) => {
140
- if (e.name === "AbortError") return;
141
- const t = e.code || e.response && e.response.status;
142
- if (t === 410) {
143
- h(this.PREFIX, "resource is gone 410"), this.resourceVersion = null, setTimeout(() => this.start(), 0);
144
- return;
145
- }
146
- if ([404].includes(t)) {
147
- this.handleEvents({ type: y, object: e }), this.cancel();
148
- return;
149
- }
150
- A("WATCH ERROR", e, e.code, t, e.response), console.dir(e), setTimeout(() => {
151
- h(this.PREFIX, "recover connection", "restart!"), this.start();
152
- }, 3e4);
153
- }), this.cancel;
154
- }
155
- on(e, t) {
156
- return this.addListener(e, t), this;
157
- }
158
- cancel() {
159
- h(this.PREFIX, "cancel connection"), this.controller.abort();
68
+ [D]: [],
69
+ [A]: [],
70
+ [O]: [],
71
+ [R]: []
72
+ }, this.controller = new AbortController(), this.signal = this.controller.signal, this.resourceVersion = null, this.PREFIX = "watch >", this.decoder = new TextDecoder(), this.refreshToken = (e) => {
73
+ this.options.headers && (this.options.headers.Authorization = `Bearer ${e}`);
74
+ }, this.checkType = (e) => {
75
+ if (![D, A, O, R].includes(e))
76
+ 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) => {
82
+ try {
83
+ c(n);
84
+ } catch (l) {
85
+ k(l);
86
+ }
87
+ });
88
+ }, this.handleEvents = (e) => {
89
+ Array.isArray(e) || (e = [e]);
90
+ const n = this;
91
+ 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]));
97
+ });
98
+ }, this.getResourceVersion = async () => {
99
+ 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) => (
103
+ // 'Body.json()' type definition expects 'any' as a return value
104
+ a.json()
105
+ )
106
+ );
107
+ return this.resourceVersion = e.resourceVersion, n && this.informListeners(D, n), this.resourceVersion;
108
+ }, this.start = () => {
109
+ 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, {
111
+ ...e.options,
112
+ params: {
113
+ ...e.options.params,
114
+ watch: 1,
115
+ allowWatchBookmarks: !0,
116
+ resourceVersion: n
117
+ },
118
+ 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) {
134
+ e.cancel(), setTimeout(() => {
135
+ f(e.PREFIX, "resource is gone 410", "recreate watch request!"), e.start();
136
+ });
137
+ return;
138
+ }
139
+ g.push(o);
140
+ }), f(e.PREFIX, "inform listeners", w), e.handleEvents(g);
141
+ }
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);
148
+ return;
149
+ }
150
+ if (a === 404) {
151
+ e.handleEvents({ type: R, object: n }), e.cancel();
152
+ return;
153
+ }
154
+ k("WATCH ERROR", n, n.code, a, n.response), console.dir(n), setTimeout(() => {
155
+ f(e.PREFIX, "recover connection", "restart!"), e.start();
156
+ }, 3e4);
157
+ }), 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);
160
161
  }
161
162
  }
162
- const p = async (r) => {
163
- var t;
164
- const e = (t = r.response) != null && t.data ? new Error(r.response.data.message || r.message) : r;
165
- return Promise.reject(e);
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;
166
+ return Promise.reject(s);
166
167
  };
167
- function H(r) {
168
- const { apiEndpoint: e } = r;
169
- let t = r.token;
170
- if (!e || !t)
171
- throw new Error(`Bad options: ${JSON.stringify(r, null, 4)}. Please provide apiEndpoint and token`);
172
- const n = () => ({
173
- Authorization: `Bearer ${t}`,
168
+ function H(t) {
169
+ const { apiEndpoint: s } = t;
170
+ let r = t.token;
171
+ if (!s || !r)
172
+ throw new Error(`Bad options: ${JSON.stringify(t, null, 4)}. Please provide apiEndpoint and token`);
173
+ const d = () => ({
174
+ Authorization: `Bearer ${r}`,
174
175
  "Content-Type": "application/json"
175
176
  });
176
- function s(o, c = {}) {
177
- const a = {
178
- ...n(),
179
- ...c.headers,
180
- ...o.headers
177
+ function i(h, o = {}) {
178
+ const u = {
179
+ ...d(),
180
+ ...o.headers,
181
+ ...h.headers
181
182
  };
182
183
  return {
183
- ...c,
184
184
  ...o,
185
- headers: a
185
+ ...h,
186
+ headers: u
186
187
  };
187
188
  }
188
- function i(o, c = {}) {
189
- return l("HEAD", d(e, o), s(c)).catch(p);
189
+ function e(h, o = {}) {
190
+ return m("HEAD", E(s, h), i(o)).catch(b);
190
191
  }
191
- function u(o, c = {}) {
192
- return l("GET", d(e, o), s(c)).then((a) => a.json()).catch(p);
192
+ function n(h, o = {}) {
193
+ return m("GET", E(s, h), i(o)).then((u) => u.json()).catch(b);
193
194
  }
194
- function E(o, c, a = {}) {
195
- return l("POST", d(e, o), s(a, { body: c })).then((C) => C.json()).catch(p);
195
+ function a(h, o, u = {}) {
196
+ return m("POST", E(s, h), i(u, { body: o })).then((C) => C.json()).catch(b);
196
197
  }
197
- function T(o, c, a = {}) {
198
- return l("PUT", d(e, o), s(a, { body: c })).then((f) => f.json()).catch(p);
198
+ function c(h, o, u = {}) {
199
+ return m("PUT", E(s, h), i(u, { body: o })).then((T) => T.json()).catch(b);
199
200
  }
200
- function w(o, c, a = {}) {
201
- return l(
201
+ function l(h, o, u = {}) {
202
+ return m(
202
203
  "PATCH",
203
- d(e, o),
204
- s(a, {
204
+ E(s, h),
205
+ i(u, {
205
206
  headers: { "Content-Type": "application/merge-patch+json" },
206
- body: c
207
+ body: o
207
208
  })
208
- ).then((f) => f.json()).catch(p);
209
+ ).then((T) => T.json()).catch(b);
209
210
  }
210
- function m(o, c, a = {}) {
211
- return l("DELETE", d(e, o), s(a, { body: c })).then((f) => f.json()).catch(p);
211
+ function y(h, o, u = {}) {
212
+ return m("DELETE", E(s, h), i(u, { body: o })).then((T) => T.json()).catch(b);
212
213
  }
213
- function I(o, c = {}) {
214
- return new $(d(e, o), s(c), () => t);
214
+ function p(h, o = {}) {
215
+ return new $(E(s, h), i(o), () => r);
215
216
  }
216
- function P(o) {
217
- t = o;
217
+ function w(h) {
218
+ r = h;
218
219
  }
219
- function k() {
220
- return t;
220
+ function g() {
221
+ return r;
221
222
  }
222
223
  return {
223
- WATCH_ERROR: y,
224
- WATCH_ADDED: b,
225
- WATCH_DELETED: g,
226
- WATCH_MODIFIED: R,
227
- head: i,
228
- get: u,
229
- post: E,
230
- put: T,
231
- patch: w,
232
- delete: m,
233
- watch: I,
234
- refreshToken: P,
235
- currentToken: k
224
+ WATCH_ERROR: R,
225
+ WATCH_ADDED: D,
226
+ WATCH_DELETED: O,
227
+ WATCH_MODIFIED: A,
228
+ head: e,
229
+ get: n,
230
+ post: a,
231
+ put: c,
232
+ patch: l,
233
+ delete: y,
234
+ watch: p,
235
+ refreshToken: w,
236
+ currentToken: g
236
237
  };
237
238
  }
238
239
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,GAAG,YAVY,OAAO,EAAE,SAUA,CAAA;AACrC,eAAO,MAAM,KAAK,YAXU,OAAO,EAAE,SAWI,CAAA;AACzC,eAAO,MAAM,KAAK,YAZU,OAAO,EAAE,SAYI,CAAA;AACzC,eAAO,MAAM,IAAI,YAbW,OAAO,EAAE,SAaE,CAAA"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAuBA,eAAO,MAAM,GAAG,YAVY,OAAO,EAAE,SAUA,CAAA;AACrC,eAAO,MAAM,KAAK,YAXU,OAAO,EAAE,SAWI,CAAA;AACzC,eAAO,MAAM,KAAK,YAZU,OAAO,EAAE,SAYI,CAAA;AACzC,eAAO,MAAM,IAAI,YAbW,OAAO,EAAE,SAaE,CAAA"}
@@ -1,11 +1,12 @@
1
1
  interface RequestOptions {
2
2
  params?: Record<string, any>;
3
3
  signal?: AbortSignal;
4
- headers?: HeadersInit;
5
- body?: any;
4
+ headers?: HeadersInit | null;
5
+ body?: Object | null;
6
6
  mode?: RequestMode;
7
7
  cache?: RequestCache;
8
8
  credentials?: RequestCredentials;
9
+ [key: string]: any;
9
10
  }
10
11
  /**
11
12
  * Creates a request.
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAIA,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,WAAW,CAAA;IACrB,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,WAAW,CAAC,EAAE,kBAAkB,CAAA;CACjC;AAaD;;;;;;;GAOG;AACH,iBAAS,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwB7F;AAED,eAAe,OAAO,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,WAAW,GAAG,IAAI,CAAA;IAC5B,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,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,CA2B7F;AAED,eAAe,OAAO,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"urlHelpers.d.ts","sourceRoot":"","sources":["../src/urlHelpers.ts"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH,iBAAS,QAAQ,CAAC,GAAG,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,MAAM,CAmC5E;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
1
+ {"version":3,"file":"urlHelpers.d.ts","sourceRoot":"","sources":["../src/urlHelpers.ts"],"names":[],"mappings":"AA0BA;;;;;GAKG;AACH,iBAAS,QAAQ,CAAC,GAAG,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,MAAM,CAmC5E;AAED,OAAO,EAAE,QAAQ,EAAE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,iBAAS,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAE7C;AAED;;;;GAIG;AACH,iBAAS,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAE7C;AAED;;;;GAIG;AACH,iBAAS,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAEtC;AAED;;;;GAIG;AACH,iBAAS,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,GAAG,EAAE,CAE3C;AAED;;;;GAIG;AACH,iBAAS,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,QAAQ,CAEjD;AAED;;;;GAIG;AACH,iBAAS,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,IAAI,CAEzC;AAED;;;;GAIG;AACH,iBAAS,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,SAAS,CAEnD;AAED,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,iBAAS,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAE7C;AAED;;;;GAIG;AACH,iBAAS,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAE7C;AAED;;;;GAIG;AACH,iBAAS,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAEtC;AAED;;;;GAIG;AACH,iBAAS,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,GAAG,EAAE,CAE3C;AAED;;;;GAIG;AACH,iBAAS,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,QAAQ,CAEjD;AAED;;;;GAIG;AACH,iBAAS,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,IAAI,CAEzC;AAED;;;;GAIG;AACH,iBAAS,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,SAAS,CAEnD;AAED,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,CAAA"}
package/build/watch.d.ts CHANGED
@@ -2,36 +2,36 @@ declare const ADDED = "ADDED";
2
2
  declare const MODIFIED = "MODIFIED";
3
3
  declare const DELETED = "DELETED";
4
4
  declare const ERROR = "ERROR";
5
- type Listener = (_items: any) => void;
5
+ type Listener = (_items: unknown) => void;
6
6
  interface WatchOptions {
7
- params?: Record<string, any>;
7
+ params?: Record<string, string>;
8
8
  headers?: Record<string, string>;
9
9
  signal?: AbortSignal;
10
- body?: any;
10
+ body?: Object | null;
11
11
  mode?: RequestMode;
12
12
  cache?: RequestCache;
13
13
  credentials?: RequestCredentials;
14
14
  }
15
15
  declare class Watch {
16
- private listeners;
17
- private controller;
18
- private signal;
16
+ private readonly listeners;
17
+ private readonly controller;
18
+ private readonly signal;
19
19
  private resourceVersion;
20
- private PREFIX;
21
- private decoder;
22
- private url;
23
- private options;
24
- private getCurrentToken?;
20
+ private readonly PREFIX;
21
+ private readonly decoder;
22
+ private readonly url;
23
+ private readonly options;
24
+ private readonly getCurrentToken?;
25
25
  constructor(url: string, options?: WatchOptions, getCurrentToken?: () => string);
26
- refreshToken(newToken: string): void;
26
+ refreshToken: (newToken: string) => void;
27
27
  private checkType;
28
28
  private addListener;
29
29
  private informListeners;
30
30
  private handleEvents;
31
31
  private getResourceVersion;
32
- start(): () => void;
33
- on(type: string, listener: Listener): this;
34
- cancel(): void;
32
+ start: () => () => void;
33
+ on: (type: string, listener: Listener) => this;
34
+ cancel: () => void;
35
35
  }
36
36
  export { ADDED, MODIFIED, DELETED, ERROR, Watch };
37
37
  //# sourceMappingURL=watch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AAGA,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,GAAG,KAAK,IAAI,CAAA;AAErC,UAAU,YAAY;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,WAAW,CAAC,EAAE,kBAAkB,CAAA;CACjC;AAED,cAAM,KAAK;IACT,OAAO,CAAC,SAAS,CAKhB;IACD,OAAO,CAAC,UAAU,CAAyC;IAC3D,OAAO,CAAC,MAAM,CAAsC;IACpD,OAAO,CAAC,eAAe,CAAsB;IAC7C,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,GAAG,CAAQ;IACnB,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,eAAe,CAAC,CAAc;gBAE1B,GAAG,EAAE,MAAM,EAAE,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AQ,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,aAAc,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,SAAU,MAAM,YAAY,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,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudoperators/juno-k8s-client",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "author": "UI-Team",
5
5
  "description": "JavaScript client for Kubernetes API",
6
6
  "main": "build/index.js",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "devDependencies": {
31
31
  "@cloudoperators/juno-config": "*",
32
- "vite": "^5.4.0",
32
+ "vite": "^6.2.4",
33
33
  "vite-plugin-dts": "^4.0.3"
34
34
  }
35
35
  }