Skip to content

Commit 73c17c8

Browse files
feat: reinstall function implementation
1 parent 6b2e7c0 commit 73c17c8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lib/marketplace/app/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,37 @@ export function App (http, data) {
144144
}
145145
}
146146

147+
/**
148+
* @description The reinstall call is used to initiate the reinstallation of the app
149+
* @memberof App
150+
* @func reinstall
151+
* @param {String} param.targetType - The target on which app needs to be reinstalled, stack or ogranization.
152+
* @param {String} param.targetUid - The uid of the target, on which the app will be reinstalled
153+
* @returns Promise<Reinstallation>
154+
*
155+
* @example
156+
* import * as contentstack from '@contentstack/marketplace'
157+
* const client = contentstack.client({ authtoken: 'TOKEN'})
158+
* client.marketplace('organization_uid').app('manifest_uid').reinstall({ targetUid: 'STACK_API_KEY', targetType: 'stack' })
159+
* .then((reinstallation) => console.log(installation))
160+
*/
161+
this.reinstall = async ({ targetUid, targetType }) => {
162+
try {
163+
const headers = {
164+
headers: { ...cloneDeep(this.params) }
165+
} || {}
166+
167+
const response = await http.put(`${this.urlPath}/reinstall`, { target_type: targetType, target_uid: targetUid }, headers)
168+
if (response.data) {
169+
return new Installation(http, response.data, this.params) || {}
170+
} else {
171+
throw error(response)
172+
}
173+
} catch (err) {
174+
throw error(err)
175+
}
176+
}
177+
147178
/**
148179
* @description The upgrade call is used to upgrade the installation of an app
149180
* @memberof App

0 commit comments

Comments
 (0)