@kubernetesjs/cli 0.0.3 → 0.1.0

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.
Files changed (59) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +54 -55
  3. package/commands/apply.d.ts +4 -0
  4. package/commands/apply.js +171 -0
  5. package/commands/cluster-info.d.ts +4 -0
  6. package/commands/cluster-info.js +26 -0
  7. package/commands/config-handler.d.ts +11 -0
  8. package/commands/config-handler.js +81 -0
  9. package/commands/config.d.ts +4 -0
  10. package/commands/config.js +72 -0
  11. package/commands/delete.d.ts +4 -0
  12. package/commands/delete.js +256 -0
  13. package/commands/deploy.d.ts +6 -0
  14. package/commands/deploy.js +209 -0
  15. package/commands/describe.d.ts +4 -0
  16. package/commands/describe.js +216 -0
  17. package/commands/exec.d.ts +4 -0
  18. package/commands/exec.js +145 -0
  19. package/commands/get.d.ts +4 -0
  20. package/commands/get.js +164 -0
  21. package/commands/logs.d.ts +4 -0
  22. package/commands/logs.js +110 -0
  23. package/commands/port-forward.d.ts +4 -0
  24. package/commands/port-forward.js +143 -0
  25. package/commands.d.ts +3 -0
  26. package/commands.js +93 -0
  27. package/config.d.ts +22 -0
  28. package/config.js +113 -0
  29. package/esm/commands/apply.js +133 -0
  30. package/esm/commands/cluster-info.js +21 -0
  31. package/esm/commands/config-handler.js +43 -0
  32. package/esm/commands/config.js +67 -0
  33. package/esm/commands/delete.js +218 -0
  34. package/esm/commands/deploy.js +207 -0
  35. package/esm/commands/describe.js +211 -0
  36. package/esm/commands/exec.js +140 -0
  37. package/esm/commands/get.js +159 -0
  38. package/esm/commands/logs.js +105 -0
  39. package/esm/commands/port-forward.js +138 -0
  40. package/esm/commands.js +86 -0
  41. package/esm/config.js +74 -0
  42. package/esm/index.js +19 -0
  43. package/esm/package.js +26 -0
  44. package/esm/utils.js +49 -0
  45. package/index.d.ts +3 -0
  46. package/index.js +22 -0
  47. package/package.d.ts +1 -0
  48. package/package.js +29 -0
  49. package/package.json +37 -61
  50. package/utils.d.ts +11 -0
  51. package/utils.js +58 -0
  52. package/main/client.js +0 -156
  53. package/main/index.js +0 -2598
  54. package/module/client.js +0 -129
  55. package/module/index.js +0 -2594
  56. package/src/client.ts +0 -156
  57. package/src/index.ts +0 -14187
  58. package/types/client.d.ts +0 -31
  59. package/types/index.d.ts +0 -11331
package/module/client.js DELETED
@@ -1,129 +0,0 @@
1
- import * as http from 'http';
2
- import * as querystring from 'querystring';
3
- import { URLSearchParams } from 'url';
4
- export class APIClient {
5
- hostname;
6
- port = 8001; // Default Kubernetes proxy port
7
- defaultTimeout = 10000; // 10 seconds
8
- constructor(options) {
9
- const url = new URL(options.restEndpoint);
10
- this.hostname = url.hostname;
11
- this.port = url.port ? parseInt(url.port) : this.port;
12
- }
13
- get(endpoint, query, opts = {}) {
14
- const queryString = query ? `?${querystring.stringify(query)}` : '';
15
- const fullPath = endpoint + queryString;
16
- return this.request({
17
- path: fullPath,
18
- method: 'GET',
19
- // @ts-ignore
20
- headers: opts.headers,
21
- timeout: opts.timeout || this.defaultTimeout,
22
- });
23
- }
24
- post(endpoint, params, opts = {}) {
25
- const headers = opts.isFormData ? {
26
- 'Content-Type': 'application/x-www-form-urlencoded',
27
- ...opts.headers
28
- } : {
29
- 'Content-Type': 'application/json',
30
- ...opts.headers
31
- };
32
- const body = opts.isFormData ? new URLSearchParams(params).toString() : JSON.stringify(params);
33
- headers['Content-Length'] = Buffer.byteLength(body).toString();
34
- return this.request({
35
- path: endpoint,
36
- method: 'POST',
37
- // @ts-ignore
38
- headers,
39
- // @ts-ignore
40
- params: body,
41
- timeout: opts.timeout || this.defaultTimeout,
42
- });
43
- }
44
- patch(endpoint, params, opts = {}) {
45
- const headers = opts.isFormData ? {
46
- 'Content-Type': 'application/x-www-form-urlencoded',
47
- ...opts.headers
48
- } : {
49
- 'Content-Type': 'application/json',
50
- ...opts.headers
51
- };
52
- const body = opts.isFormData ? new URLSearchParams(params).toString() : JSON.stringify(params);
53
- headers['Content-Length'] = Buffer.byteLength(body).toString();
54
- return this.request({
55
- path: endpoint,
56
- // @ts-ignore
57
- method: 'PATCH',
58
- // @ts-ignore
59
- headers,
60
- // @ts-ignore
61
- params: body,
62
- timeout: opts.timeout || this.defaultTimeout,
63
- });
64
- }
65
- put(endpoint, params, opts = {}) {
66
- const stringParams = JSON.stringify(params);
67
- const defaultHeaders = {
68
- 'Content-Type': 'application/json',
69
- 'Content-Length': Buffer.byteLength(stringParams).toString(),
70
- ...opts.headers
71
- };
72
- return this.request({
73
- path: endpoint,
74
- method: 'PUT',
75
- // @ts-ignore
76
- headers: defaultHeaders,
77
- // @ts-ignore
78
- params: stringParams,
79
- timeout: opts.timeout || this.defaultTimeout,
80
- });
81
- }
82
- delete(endpoint, opts = {}) {
83
- return this.request({
84
- path: endpoint,
85
- method: 'DELETE',
86
- // @ts-ignore
87
- headers: opts.headers,
88
- timeout: opts.timeout || this.defaultTimeout,
89
- });
90
- }
91
- request(options) {
92
- return new Promise((resolve, reject) => {
93
- const requestOptions = {
94
- hostname: this.hostname,
95
- port: this.port,
96
- path: options.path,
97
- method: options.method,
98
- headers: options.headers,
99
- };
100
- const req = http.request(requestOptions, res => {
101
- let data = '';
102
- res.on('data', chunk => {
103
- data += chunk;
104
- });
105
- res.on('end', () => {
106
- try {
107
- const parsedData = JSON.parse(data);
108
- resolve(parsedData);
109
- }
110
- catch (error) {
111
- reject(error);
112
- }
113
- });
114
- });
115
- req.on('error', error => {
116
- reject(error);
117
- });
118
- // @ts-ignore
119
- req.setTimeout(options.timeout, () => {
120
- req.abort();
121
- reject(new Error('Request timeout'));
122
- });
123
- if (options.params && (options.method === 'POST' || options.method === 'PUT')) {
124
- req.write(options.params);
125
- }
126
- req.end();
127
- });
128
- }
129
- }