caprover-api 0.0.22 → 0.0.23

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.
@@ -78,12 +78,19 @@ class ApiManager {
78
78
  }
79
79
  saveTheme(oldName, theme) {
80
80
  const http = this.http;
81
- return Promise.resolve() //
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.22",
3
+ "version": "0.0.23",
4
4
  "description": "API client for CapRover",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
@@ -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
- return Promise.resolve() //
150
- .then(
151
- http.fetch(http.POST, '/user/system/themes/update', {
152
- oldName,
153
- name: theme.name,
154
- content: theme.content,
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<{}> {
@@ -101,3 +101,48 @@ 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
+ })