caprover-api 0.0.23 → 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.
@@ -1,3 +1,4 @@
1
+ import { IOneClickTemplate } from './IOneClickAppModels';
1
2
  export default interface OneClickAppDefinitionResponse {
2
- appTemplate: string;
3
+ appTemplate: IOneClickTemplate;
3
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caprover-api",
3
- "version": "0.0.23",
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"
@@ -1,3 +1,5 @@
1
+ import { IOneClickTemplate } from './IOneClickAppModels'
2
+
1
3
  export default interface OneClickAppDefinitionResponse {
2
- appTemplate: string
4
+ appTemplate: IOneClickTemplate
3
5
  }
@@ -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
 
@@ -146,3 +146,39 @@ test('saveTheme omits unspecified optional theme fields', async () => {
146
146
  assert.equal('headEmbed' in requests[0].data, false)
147
147
  assert.equal(JSON.stringify(requests[0].data).includes('undefined'), false)
148
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