caprover-api 0.0.10 → 0.0.12

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 (89) hide show
  1. package/dist/api/ApiManager.d.ts +0 -0
  2. package/dist/api/ApiManager.js +0 -0
  3. package/dist/api/ErrorFactory.d.ts +0 -0
  4. package/dist/api/ErrorFactory.js +0 -0
  5. package/dist/api/HttpClient.d.ts +3 -3
  6. package/dist/api/HttpClient.js +53 -15
  7. package/dist/example.d.ts +0 -0
  8. package/dist/example.js +0 -0
  9. package/dist/index.d.ts +0 -0
  10. package/dist/index.js +0 -0
  11. package/dist/models/AppDefinition.d.ts +0 -0
  12. package/dist/models/AppDefinition.js +0 -0
  13. package/dist/models/AppDefinitionsResponse.d.ts +0 -0
  14. package/dist/models/AppDefinitionsResponse.js +0 -0
  15. package/dist/models/AppDeleteResponse.d.ts +0 -0
  16. package/dist/models/AppDeleteResponse.js +0 -0
  17. package/dist/models/AutomatedCleanupConfigs.d.ts +0 -0
  18. package/dist/models/AutomatedCleanupConfigs.js +0 -0
  19. package/dist/models/BackupMeta.d.ts +0 -0
  20. package/dist/models/BackupMeta.js +0 -0
  21. package/dist/models/BuildLogsResponse.d.ts +0 -0
  22. package/dist/models/BuildLogsResponse.js +0 -0
  23. package/dist/models/CapRoverTheme.d.ts +0 -0
  24. package/dist/models/CapRoverTheme.js +0 -0
  25. package/dist/models/CaptainInfo.d.ts +0 -0
  26. package/dist/models/CaptainInfo.js +0 -0
  27. package/dist/models/ContainerProps.d.ts +0 -0
  28. package/dist/models/ContainerProps.js +0 -0
  29. package/dist/models/DockerAuthObj.d.ts +0 -0
  30. package/dist/models/DockerAuthObj.js +0 -0
  31. package/dist/models/DockerSecret.d.ts +0 -0
  32. package/dist/models/DockerSecret.js +0 -0
  33. package/dist/models/DockerService.d.ts +0 -0
  34. package/dist/models/DockerService.js +0 -0
  35. package/dist/models/GoAccessInfo.d.ts +0 -0
  36. package/dist/models/GoAccessInfo.js +0 -0
  37. package/dist/models/GoAccessReportResponse.d.ts +0 -0
  38. package/dist/models/GoAccessReportResponse.js +0 -0
  39. package/dist/models/IBuiltImage.d.ts +0 -0
  40. package/dist/models/IBuiltImage.js +0 -0
  41. package/dist/models/ICaptainDefinition.d.ts +0 -0
  42. package/dist/models/ICaptainDefinition.js +0 -0
  43. package/dist/models/IGoAccessInfo.d.ts +0 -0
  44. package/dist/models/IGoAccessInfo.js +0 -0
  45. package/dist/models/IHashMapGeneric.d.ts +0 -0
  46. package/dist/models/IHashMapGeneric.js +0 -0
  47. package/dist/models/IImageSource.d.ts +0 -0
  48. package/dist/models/IImageSource.js +0 -0
  49. package/dist/models/IOneClickAppModels.d.ts +0 -0
  50. package/dist/models/IOneClickAppModels.js +0 -0
  51. package/dist/models/IProFeatures.d.ts +0 -0
  52. package/dist/models/IProFeatures.js +0 -0
  53. package/dist/models/IRegistryInfo.d.ts +0 -0
  54. package/dist/models/IRegistryInfo.js +0 -0
  55. package/dist/models/IServerBlockDetails.d.ts +0 -0
  56. package/dist/models/IServerBlockDetails.js +0 -0
  57. package/dist/models/IVersionInfo.d.ts +0 -0
  58. package/dist/models/IVersionInfo.js +0 -0
  59. package/dist/models/LoadBalancerInfo.d.ts +0 -0
  60. package/dist/models/LoadBalancerInfo.js +0 -0
  61. package/dist/models/LogsResponse.d.ts +0 -0
  62. package/dist/models/LogsResponse.js +0 -0
  63. package/dist/models/NetDataInfo.d.ts +0 -0
  64. package/dist/models/NetDataInfo.js +0 -0
  65. package/dist/models/NginxConfig.d.ts +0 -0
  66. package/dist/models/NginxConfig.js +0 -0
  67. package/dist/models/OneClickAppDefinitionResponse.d.ts +0 -0
  68. package/dist/models/OneClickAppDefinitionResponse.js +0 -0
  69. package/dist/models/OneClickAppRepositories.d.ts +0 -0
  70. package/dist/models/OneClickAppRepositories.js +0 -0
  71. package/dist/models/OneClickAppResponse.d.ts +0 -0
  72. package/dist/models/OneClickAppResponse.js +0 -0
  73. package/dist/models/OtherTypes.d.ts +0 -0
  74. package/dist/models/OtherTypes.js +0 -0
  75. package/dist/models/ProjectDefinition.d.ts +0 -0
  76. package/dist/models/ProjectDefinition.js +0 -0
  77. package/dist/models/ProjectsResponse.d.ts +0 -0
  78. package/dist/models/ProjectsResponse.js +0 -0
  79. package/dist/models/RegistriesResponse.d.ts +0 -0
  80. package/dist/models/RegistriesResponse.js +0 -0
  81. package/dist/models/ServerDockerInfo.d.ts +0 -0
  82. package/dist/models/ServerDockerInfo.js +0 -0
  83. package/dist/models/UnusedImagesResponse.d.ts +1 -1
  84. package/dist/models/UnusedImagesResponse.js +0 -0
  85. package/dist/models/index.d.ts +0 -0
  86. package/dist/models/index.js +0 -0
  87. package/package.json +2 -2
  88. package/src/api/HttpClient.ts +79 -17
  89. package/src/models/UnusedImagesResponse.ts +1 -1
File without changes
File without changes
File without changes
File without changes
@@ -9,7 +9,7 @@ export default class HttpClient {
9
9
  createHeaders(): Promise<any>;
10
10
  destroy(): void;
11
11
  fetch(method: 'GET' | 'POST', endpoint: string, variables: any): () => Promise<any>;
12
- fetchInternal(method: 'GET' | 'POST', endpoint: string, variables: any): Promise<import("axios").AxiosResponse<any, any>>;
13
- getReq(endpoint: string, variables: any): Promise<import("axios").AxiosResponse<any, any>>;
14
- postReq(endpoint: string, variables: any): Promise<import("axios").AxiosResponse<any, any>>;
12
+ fetchInternal(method: 'GET' | 'POST', endpoint: string, variables: any): Promise<any>;
13
+ getReq(endpoint: string, variables: any): Promise<any>;
14
+ postReq(endpoint: string, variables: any): Promise<any>;
15
15
  }
@@ -3,11 +3,54 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const axios_1 = __importDefault(require("axios"));
7
6
  const ErrorFactory_1 = __importDefault(require("./ErrorFactory"));
7
+ const cross_fetch_1 = __importDefault(require("cross-fetch"));
8
+ function buildQueryParams(params) {
9
+ if (!params || Object.keys(params).length === 0)
10
+ return '';
11
+ return ('?' +
12
+ Object.entries(params)
13
+ .map(([key, value]) => encodeURIComponent(key) + '=' + encodeURIComponent(value))
14
+ .join('&'));
15
+ }
8
16
  let TOKEN_HEADER = 'x-captain-auth';
9
17
  let NAMESPACE = 'x-namespace';
10
18
  let CAPTAIN = 'captain';
19
+ class CrossFetchEngine {
20
+ static async post(url, variables, headers) {
21
+ const res = await (0, cross_fetch_1.default)(url, {
22
+ method: 'POST',
23
+ headers: {
24
+ 'Content-Type': 'application/json',
25
+ ...headers,
26
+ },
27
+ body: JSON.stringify(variables),
28
+ });
29
+ if (!res.ok) {
30
+ const errBody = await res.text();
31
+ throw new Error(`HTTP ${res.status}: ${errBody}`);
32
+ }
33
+ return res.json();
34
+ }
35
+ static async get(url, params, headers) {
36
+ const fullUrl = url +
37
+ (params && Object.keys(params).length > 0
38
+ ? buildQueryParams(params)
39
+ : '');
40
+ const res = await (0, cross_fetch_1.default)(fullUrl, {
41
+ method: 'GET',
42
+ headers: {
43
+ 'Content-Type': 'application/json',
44
+ ...headers,
45
+ },
46
+ });
47
+ if (!res.ok) {
48
+ const errBody = await res.text();
49
+ throw new Error(`HTTP ${res.status}: ${errBody}`);
50
+ }
51
+ return res.json();
52
+ }
53
+ }
11
54
  class HttpClient {
12
55
  constructor(baseUrl, authTokenProvider, onLoginRequested) {
13
56
  this.baseUrl = baseUrl;
@@ -42,18 +85,18 @@ class HttpClient {
42
85
  .then(function () {
43
86
  return self.fetchInternal(method, endpoint, variables); //
44
87
  })
45
- .then(function (axiosResponse) {
46
- const data = axiosResponse.data; // this is an axios thing!
88
+ .then(function (fetchResponse) {
47
89
  if (
48
90
  // if we ever get STATUS_ERROR_NOT_AUTHORIZED when trying to log in, we will end up in an infinite loop!
49
- data.status === ErrorFactory_1.default.STATUS_AUTH_TOKEN_INVALID) {
91
+ fetchResponse.status ===
92
+ ErrorFactory_1.default.STATUS_AUTH_TOKEN_INVALID) {
50
93
  return self
51
94
  .onLoginRequested() //
52
95
  .then(function () {
53
96
  return self
54
97
  .fetchInternal(method, endpoint, variables)
55
- .then(function (newAxiosResponse) {
56
- return newAxiosResponse.data;
98
+ .then(function (httpResponse) {
99
+ return httpResponse;
57
100
  });
58
101
  })
59
102
  .catch(function (error) {
@@ -61,7 +104,7 @@ class HttpClient {
61
104
  });
62
105
  }
63
106
  else {
64
- return data;
107
+ return fetchResponse;
65
108
  }
66
109
  })
67
110
  .then(function (data) {
@@ -105,10 +148,7 @@ class HttpClient {
105
148
  return self.createHeaders();
106
149
  })
107
150
  .then(function (headers) {
108
- return axios_1.default.get(self.baseUrl + endpoint, {
109
- params: variables,
110
- headers: headers,
111
- });
151
+ return CrossFetchEngine.get(self.baseUrl + endpoint, variables, headers);
112
152
  })
113
153
  .then(function (data) {
114
154
  // console.log(data);
@@ -122,10 +162,8 @@ class HttpClient {
122
162
  return self.createHeaders();
123
163
  })
124
164
  .then(function (headers) {
125
- return axios_1.default.post(self.baseUrl + endpoint, variables, {
126
- headers: headers,
127
- }); //
128
- }) //
165
+ return CrossFetchEngine.post(self.baseUrl + endpoint, variables, headers);
166
+ })
129
167
  .then(function (data) {
130
168
  // console.log(data);
131
169
  return data;
package/dist/example.d.ts CHANGED
File without changes
package/dist/example.js CHANGED
File without changes
package/dist/index.d.ts CHANGED
File without changes
package/dist/index.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  export default interface UnusedImagesResponse {
2
- images: {
2
+ unusedImages: {
3
3
  id: string;
4
4
  tags: string[];
5
5
  }[];
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caprover-api",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "API client for CapRover",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
@@ -25,7 +25,7 @@
25
25
  "author": "",
26
26
  "license": "ISC",
27
27
  "dependencies": {
28
- "axios": "^1.10.0"
28
+ "cross-fetch": "^4.1.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^24.0.10",
@@ -1,11 +1,71 @@
1
- import axios from 'axios'
2
1
  import ErrorFactory from './ErrorFactory'
3
- import { AuthenticationProvider } from './ApiManager'
2
+ import fetch from 'cross-fetch'
4
3
 
4
+ function buildQueryParams(params: Record<string, any>): string {
5
+ if (!params || Object.keys(params).length === 0) return ''
6
+ return (
7
+ '?' +
8
+ Object.entries(params)
9
+ .map(
10
+ ([key, value]) =>
11
+ encodeURIComponent(key) + '=' + encodeURIComponent(value)
12
+ )
13
+ .join('&')
14
+ )
15
+ }
5
16
  let TOKEN_HEADER = 'x-captain-auth'
6
17
  let NAMESPACE = 'x-namespace'
7
18
  let CAPTAIN = 'captain'
8
19
 
20
+ class CrossFetchEngine {
21
+ public static async post(
22
+ url: string,
23
+ variables: Record<string, any>,
24
+ headers: Record<string, string>
25
+ ): Promise<any> {
26
+ const res = await fetch(url, {
27
+ method: 'POST',
28
+ headers: {
29
+ 'Content-Type': 'application/json',
30
+ ...headers,
31
+ },
32
+ body: JSON.stringify(variables),
33
+ })
34
+
35
+ if (!res.ok) {
36
+ const errBody = await res.text()
37
+ throw new Error(`HTTP ${res.status}: ${errBody}`)
38
+ }
39
+ return res.json()
40
+ }
41
+
42
+ public static async get(
43
+ url: string,
44
+ params: Record<string, any>,
45
+ headers: Record<string, string>
46
+ ): Promise<any> {
47
+ const fullUrl =
48
+ url +
49
+ (params && Object.keys(params).length > 0
50
+ ? buildQueryParams(params)
51
+ : '')
52
+
53
+ const res = await fetch(fullUrl, {
54
+ method: 'GET',
55
+ headers: {
56
+ 'Content-Type': 'application/json',
57
+ ...headers,
58
+ },
59
+ })
60
+
61
+ if (!res.ok) {
62
+ const errBody = await res.text()
63
+ throw new Error(`HTTP ${res.status}: ${errBody}`)
64
+ }
65
+ return res.json()
66
+ }
67
+ }
68
+
9
69
  export default class HttpClient {
10
70
  public readonly GET = 'GET'
11
71
  public readonly POST = 'POST'
@@ -46,27 +106,26 @@ export default class HttpClient {
46
106
  .then(function () {
47
107
  return self.fetchInternal(method, endpoint, variables) //
48
108
  })
49
- .then(function (axiosResponse) {
50
- const data = axiosResponse.data // this is an axios thing!
51
-
109
+ .then(function (fetchResponse) {
52
110
  if (
53
111
  // if we ever get STATUS_ERROR_NOT_AUTHORIZED when trying to log in, we will end up in an infinite loop!
54
- data.status === ErrorFactory.STATUS_AUTH_TOKEN_INVALID
112
+ fetchResponse.status ===
113
+ ErrorFactory.STATUS_AUTH_TOKEN_INVALID
55
114
  ) {
56
115
  return self
57
116
  .onLoginRequested() //
58
117
  .then(function () {
59
118
  return self
60
119
  .fetchInternal(method, endpoint, variables)
61
- .then(function (newAxiosResponse) {
62
- return newAxiosResponse.data
120
+ .then(function (httpResponse) {
121
+ return httpResponse
63
122
  })
64
123
  })
65
124
  .catch(function (error) {
66
125
  return Promise.reject(error)
67
126
  })
68
127
  } else {
69
- return data
128
+ return fetchResponse
70
129
  }
71
130
  })
72
131
  .then(function (data) {
@@ -115,10 +174,11 @@ export default class HttpClient {
115
174
  return self.createHeaders()
116
175
  })
117
176
  .then(function (headers) {
118
- return axios.get(self.baseUrl + endpoint, {
119
- params: variables,
120
- headers: headers,
121
- })
177
+ return CrossFetchEngine.get(
178
+ self.baseUrl + endpoint,
179
+ variables,
180
+ headers
181
+ )
122
182
  })
123
183
  .then(function (data) {
124
184
  // console.log(data);
@@ -133,10 +193,12 @@ export default class HttpClient {
133
193
  return self.createHeaders()
134
194
  })
135
195
  .then(function (headers) {
136
- return axios.post(self.baseUrl + endpoint, variables, {
137
- headers: headers,
138
- }) //
139
- }) //
196
+ return CrossFetchEngine.post(
197
+ self.baseUrl + endpoint,
198
+ variables,
199
+ headers
200
+ )
201
+ })
140
202
  .then(function (data) {
141
203
  // console.log(data);
142
204
  return data
@@ -1,3 +1,3 @@
1
1
  export default interface UnusedImagesResponse {
2
- images: { id: string; tags: string[] }[]
2
+ unusedImages: { id: string; tags: string[] }[]
3
3
  }