Skip to content

Commit b8e9268

Browse files
Merge pull request #17 from contentstack/feat/DX-659-reinstall-method-implementation
Feat/dx 659 reinstall method implementation
2 parents 1751425 + 2155575 commit b8e9268

File tree

11 files changed

+109
-6
lines changed

11 files changed

+109
-6
lines changed

.github/workflows/jira.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
pull_request:
44
types: [opened]
55
jobs:
6-
security:
6+
security-jira:
77
if: ${{ github.actor == 'dependabot[bot]' || github.actor == 'snyk-bot' || contains(github.event.pull_request.head.ref, 'snyk-fix-') || contains(github.event.pull_request.head.ref, 'snyk-upgrade-')}}
88
runs-on: ubuntu-latest
99
steps:

.github/workflows/sast-scan.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: SAST Scan
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
jobs:
6+
security-sast:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Semgrep Scan
11+
run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v "${PWD}:/src" returntocorp/semgrep semgrep scan --config auto

.github/workflows/sca-scan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
pull_request:
44
types: [opened, synchronize, reopened]
55
jobs:
6-
security:
6+
security-sca:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@master

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [v1.1.0](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.1.0) (2024-06-05)
4+
- added reinstall app function
5+
36
## [v1.0.2](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.0.2) (2024-01-16)
47
- Updated dependencies
58

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

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/marketplace-sdk",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "The Contentstack Marketplace SDK is used to manage the content of your Contentstack marketplace apps",
55
"main": "./dist/node/contentstack-marketplace.js",
66
"browser": "./dist/web/contentstack-marketplace.js",

test/api/app-test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { expect } from 'chai'
66

77
dotenv.config()
88

9-
let stack = {}
9+
// let stack = {}
1010
const orgID = process.env.ORG_UID
1111
let client = {}
1212
let appUid = ''
@@ -190,4 +190,17 @@ describe('Apps api Test', () => {
190190
})
191191
.catch(done)
192192
})
193+
194+
it('should reinstall the app', done => {
195+
client.marketplace(orgID).app(appUid).reinstall({ targetType: 'stack', targetUid: process.env.APIKEY })
196+
.then((reinstallation) => {
197+
expect(reinstallation.reinstallation_uid).to.not.equal(undefined)
198+
expect(reinstallation.params.organization_uid).to.be.equal(orgID)
199+
expect(reinstallation.fetch).to.not.equal(undefined)
200+
expect(reinstallation.update).to.not.equal(undefined)
201+
expect(reinstallation.uninstall).to.not.equal(undefined)
202+
done()
203+
})
204+
.catch(done)
205+
})
193206
})

test/typescript/app.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ export function installation(marketplace: Marketplace) {
192192
done()
193193
}).catch(done)
194194
})
195+
196+
test('should Reinstall App', done => {
197+
marketplace.app(appUid).reinstall({targetType: 'stack', targetUid: process.env.APIKEY as string})
198+
.then((reinstallation) => {
199+
installationUid = reinstallation.installation_uid
200+
expect(reinstallation.installation_uid).to.not.equal(undefined)
201+
expect(reinstallation.fetch).to.not.equal(undefined)
202+
expect(reinstallation.update).to.not.equal(undefined)
203+
expect(reinstallation.uninstall).to.not.equal(undefined)
204+
done()
205+
}).catch(done)
206+
})
195207

196208
test('should Uninstall App installation', done => {
197209
marketplace.installation(installationUid).uninstall()

test/unit/apps-test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,38 @@ describe('Contentstack apps test', () => {
303303
done()
304304
})
305305
})
306+
it('should reinstall the app', done => {
307+
const mock = new MockAdapter(Axios)
308+
const uid = appMock.uid
309+
// using same installation mock data for reinstall
310+
mock.onPut(`/manifests/${uid}/reinstall`).reply(200, {
311+
data: {
312+
...installationMock
313+
}
314+
})
315+
const targetUid = 'target_uid'
316+
const targetType = 'target_type'
317+
makeApp({ data: { uid } })
318+
.upgrade({ targetUid, targetType })
319+
.then((reinstallation) => {
320+
expect(reinstallation.status).to.be.equal(installationMock.status)
321+
expect(reinstallation.manifest.name).to.be.equal(installationMock.manifest.name)
322+
expect(reinstallation.target.uid).to.be.equal(installationMock.target.uid)
323+
expect(reinstallation.organization_uid).to.be.equal(installationMock.organization_uid)
324+
expect(reinstallation.uid).to.be.equal(installationMock.uid)
325+
})
326+
.catch(done)
327+
328+
// failing test when empty data is passed
329+
mock.onPut(`/manifests/${uid}/reinstall`).reply(400, {})
330+
makeApp({ data: { uid } })
331+
.upgrade({ targetUid, targetType })
332+
.then()
333+
.catch((error) => {
334+
expect(error).to.not.equal(null)
335+
done()
336+
})
337+
})
306338
})
307339

308340
function checkApp (app) {

types/marketplace/app/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface App extends SystemFields, SystemFunction<App> {
2020
redirectUri: string,
2121
scope: string,
2222
state: string }): Promise<AnyProperty>
23+
reinstall(data: {targetUid: string, targetType: AppTarget}): Promise<Installation>
2324
authorization(): Authorization
2425
listInstallations(): Promise<ContentstackCollection<App>>
2526
}

0 commit comments

Comments
 (0)