caprover-api 0.0.22 → 0.0.24
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/dist/api/ApiManager.js +10 -3
- package/dist/models/OneClickAppDefinitionResponse.d.ts +2 -1
- package/package.json +3 -2
- package/src/api/ApiManager.ts +22 -9
- package/src/models/OneClickAppDefinitionResponse.ts +3 -1
- package/test/ApiManager.test.js +83 -2
- package/test/OneClickAppDefinitionResponse.test.ts +11 -0
package/dist/api/ApiManager.js
CHANGED
|
@@ -78,12 +78,19 @@ class ApiManager {
|
|
|
78
78
|
}
|
|
79
79
|
saveTheme(oldName, theme) {
|
|
80
80
|
const http = this.http;
|
|
81
|
-
|
|
82
|
-
.then(http.fetch(http.POST, '/user/system/themes/update', {
|
|
81
|
+
const payload = {
|
|
83
82
|
oldName,
|
|
84
83
|
name: theme.name,
|
|
85
84
|
content: theme.content,
|
|
86
|
-
}
|
|
85
|
+
};
|
|
86
|
+
if (theme.extra !== undefined) {
|
|
87
|
+
payload.extra = theme.extra;
|
|
88
|
+
}
|
|
89
|
+
if (theme.headEmbed !== undefined) {
|
|
90
|
+
payload.headEmbed = theme.headEmbed;
|
|
91
|
+
}
|
|
92
|
+
return Promise.resolve() //
|
|
93
|
+
.then(http.fetch(http.POST, '/user/system/themes/update', payload));
|
|
87
94
|
}
|
|
88
95
|
deleteTheme(themeName) {
|
|
89
96
|
const http = this.http;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "caprover-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "API client for CapRover",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"formatter-write": "prettier --write './src/**/*.ts*'",
|
|
10
10
|
"tslint": "tslint -c tslint.json -p tsconfig.json",
|
|
11
11
|
"tslint-fix": "tslint --fix -c tslint.json -p tsconfig.json",
|
|
12
|
-
"test": "npm run build && node --test test/*.test.js",
|
|
12
|
+
"test": "npm run build && npm run test-types && node --test test/*.test.js",
|
|
13
|
+
"test-types": "npx tsc --noEmit --strict --skipLibCheck --target ES2020 --module commonjs --moduleResolution Node test/*.test.ts",
|
|
13
14
|
"build": "rm -rf ./dist && npm run tslint && npx tsc && chmod +x ./dist -R",
|
|
14
15
|
"dev": "rm -rf ./dist && npx tsc && node ./dist/example.js",
|
|
15
16
|
"generate-barrels": "rm ./src/models/index.ts && barrelsby --directory src/models"
|
package/src/api/ApiManager.ts
CHANGED
|
@@ -145,15 +145,28 @@ export default class ApiManager {
|
|
|
145
145
|
|
|
146
146
|
saveTheme(oldName: string, theme: CapRoverTheme): Promise<{}> {
|
|
147
147
|
const http = this.http
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
148
|
+
const payload: {
|
|
149
|
+
oldName: string
|
|
150
|
+
name: string
|
|
151
|
+
content: string
|
|
152
|
+
extra?: string
|
|
153
|
+
headEmbed?: string
|
|
154
|
+
} = {
|
|
155
|
+
oldName,
|
|
156
|
+
name: theme.name,
|
|
157
|
+
content: theme.content,
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (theme.extra !== undefined) {
|
|
161
|
+
payload.extra = theme.extra
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (theme.headEmbed !== undefined) {
|
|
165
|
+
payload.headEmbed = theme.headEmbed
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return Promise.resolve() //
|
|
169
|
+
.then(http.fetch(http.POST, '/user/system/themes/update', payload))
|
|
157
170
|
}
|
|
158
171
|
|
|
159
172
|
deleteTheme(themeName: string): Promise<{}> {
|
package/test/ApiManager.test.js
CHANGED
|
@@ -5,7 +5,7 @@ const ApiManagerModule = require('../dist/api/ApiManager')
|
|
|
5
5
|
const ApiManager = ApiManagerModule.default
|
|
6
6
|
const { SimpleAuthenticationProvider } = ApiManagerModule
|
|
7
7
|
|
|
8
|
-
function createApiWithRequestRecorder() {
|
|
8
|
+
function createApiWithRequestRecorder(response = {}) {
|
|
9
9
|
const api = new ApiManager(
|
|
10
10
|
'https://captain.example.com',
|
|
11
11
|
new SimpleAuthenticationProvider(() =>
|
|
@@ -21,7 +21,7 @@ function createApiWithRequestRecorder() {
|
|
|
21
21
|
FORM_DATA: 'form-data',
|
|
22
22
|
fetch(method, endpoint, data, bodyType = 'json') {
|
|
23
23
|
requests.push({ method, endpoint, data, bodyType })
|
|
24
|
-
return () => Promise.resolve(
|
|
24
|
+
return () => Promise.resolve(response)
|
|
25
25
|
},
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -101,3 +101,84 @@ test('executeGenericApiCommand accepts PATCH', async () => {
|
|
|
101
101
|
|
|
102
102
|
assert.equal(requests[0].method, 'PATCH')
|
|
103
103
|
})
|
|
104
|
+
|
|
105
|
+
test('saveTheme sends supplied writable theme fields', async () => {
|
|
106
|
+
const { api, requests } = createApiWithRequestRecorder()
|
|
107
|
+
|
|
108
|
+
await api.saveTheme('old-theme', {
|
|
109
|
+
name: 'new-theme',
|
|
110
|
+
content: 'theme-content',
|
|
111
|
+
extra: '{"siderTheme":"dark"}',
|
|
112
|
+
headEmbed: '<meta name="theme-marker" content="test">',
|
|
113
|
+
builtIn: true,
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
assert.deepEqual(requests, [
|
|
117
|
+
{
|
|
118
|
+
method: 'POST',
|
|
119
|
+
endpoint: '/user/system/themes/update',
|
|
120
|
+
data: {
|
|
121
|
+
oldName: 'old-theme',
|
|
122
|
+
name: 'new-theme',
|
|
123
|
+
content: 'theme-content',
|
|
124
|
+
extra: '{"siderTheme":"dark"}',
|
|
125
|
+
headEmbed: '<meta name="theme-marker" content="test">',
|
|
126
|
+
},
|
|
127
|
+
bodyType: 'json',
|
|
128
|
+
},
|
|
129
|
+
])
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('saveTheme omits unspecified optional theme fields', async () => {
|
|
133
|
+
const { api, requests } = createApiWithRequestRecorder()
|
|
134
|
+
|
|
135
|
+
await api.saveTheme('old-theme', {
|
|
136
|
+
name: 'new-theme',
|
|
137
|
+
content: 'theme-content',
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
assert.deepEqual(requests[0].data, {
|
|
141
|
+
oldName: 'old-theme',
|
|
142
|
+
name: 'new-theme',
|
|
143
|
+
content: 'theme-content',
|
|
144
|
+
})
|
|
145
|
+
assert.equal('extra' in requests[0].data, false)
|
|
146
|
+
assert.equal('headEmbed' in requests[0].data, false)
|
|
147
|
+
assert.equal(JSON.stringify(requests[0].data).includes('undefined'), false)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
test('getOneClickAppByName returns the parsed template object', async () => {
|
|
151
|
+
const appTemplate = {
|
|
152
|
+
services: {
|
|
153
|
+
'srv-captain--demo': {
|
|
154
|
+
image: 'nginx:alpine',
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
captainVersion: 4,
|
|
158
|
+
caproverOneClickApp: {
|
|
159
|
+
instructions: {
|
|
160
|
+
start: 'Start instructions',
|
|
161
|
+
end: 'End instructions',
|
|
162
|
+
},
|
|
163
|
+
displayName: 'Demo',
|
|
164
|
+
variables: [],
|
|
165
|
+
},
|
|
166
|
+
}
|
|
167
|
+
const { api, requests } = createApiWithRequestRecorder({ appTemplate })
|
|
168
|
+
|
|
169
|
+
const response = await api.getOneClickAppByName(
|
|
170
|
+
'demo',
|
|
171
|
+
'https://repo.example.com'
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
assert.deepEqual(requests[0], {
|
|
175
|
+
method: 'GET',
|
|
176
|
+
endpoint: '/user/oneclick/template/app',
|
|
177
|
+
data: {
|
|
178
|
+
appName: 'demo',
|
|
179
|
+
baseDomain: 'https://repo.example.com',
|
|
180
|
+
},
|
|
181
|
+
bodyType: 'json',
|
|
182
|
+
})
|
|
183
|
+
assert.strictEqual(response.appTemplate, appTemplate)
|
|
184
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type CapRoverAPI from '../dist'
|
|
2
|
+
import type { CapRoverModels } from '../dist'
|
|
3
|
+
|
|
4
|
+
type OneClickAppDefinitionResponse = Awaited<
|
|
5
|
+
ReturnType<CapRoverAPI['getOneClickAppByName']>
|
|
6
|
+
>
|
|
7
|
+
|
|
8
|
+
declare const response: OneClickAppDefinitionResponse
|
|
9
|
+
const appTemplate: CapRoverModels.IOneClickTemplate = response.appTemplate
|
|
10
|
+
|
|
11
|
+
void appTemplate
|