caprover-api 0.0.23 → 0.0.25

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
  }
@@ -1,5 +1,5 @@
1
1
  import { IRegistryInfo } from './IRegistryInfo';
2
2
  export default interface RegistriesResponse {
3
3
  registries: IRegistryInfo[];
4
- defaultRegistryId?: string;
4
+ defaultPushRegistryId?: string;
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caprover-api",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
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
  }
@@ -2,5 +2,5 @@ import { IRegistryInfo } from './IRegistryInfo'
2
2
 
3
3
  export default interface RegistriesResponse {
4
4
  registries: IRegistryInfo[]
5
- defaultRegistryId?: string
5
+ defaultPushRegistryId?: string
6
6
  }
@@ -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,55 @@ 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
+ })
185
+
186
+ test('getDockerRegistries exposes the backend default push registry ID', async () => {
187
+ const registries = [{ id: 'registry-1', registryDomain: 'ghcr.io' }]
188
+ const data = { registries, defaultPushRegistryId: 'registry-1' }
189
+ const { api, requests } = createApiWithRequestRecorder(data)
190
+
191
+ const response = await api.getDockerRegistries()
192
+
193
+ assert.deepEqual(requests, [{
194
+ method: 'GET',
195
+ endpoint: '/user/registries',
196
+ data: {},
197
+ bodyType: 'json',
198
+ }])
199
+ assert.strictEqual(response, data)
200
+ })
@@ -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
@@ -0,0 +1,11 @@
1
+ import type CapRoverAPI from '../dist'
2
+
3
+ type RegistriesResponse = Awaited<ReturnType<CapRoverAPI['getDockerRegistries']>>
4
+
5
+ declare const response: RegistriesResponse
6
+ const defaultPushRegistryId: string | undefined = response.defaultPushRegistryId
7
+
8
+ // @ts-expect-error The backend never returns this old property.
9
+ response.defaultRegistryId
10
+
11
+ void defaultPushRegistryId