Skip to content

Commit

Permalink
Merge pull request #18 from contentstack/next
Browse files Browse the repository at this point in the history
DX | 05-06-2024 | Release
  • Loading branch information
harshithad0703 authored Jun 5, 2024
2 parents d6cc651 + cb521e4 commit 04da1a1
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [v1.1.0](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.1.0) (2024-06-05)
- added reinstall app function

## [v1.0.2](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.0.2) (2024-01-16)
- Updated dependencies

Expand Down
31 changes: 31 additions & 0 deletions lib/marketplace/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,37 @@ export function App (http, data) {
}
}

/**
* @description The reinstall call is used to initiate the reinstallation of the app
* @memberof App
* @func reinstall
* @param {String} param.targetType - The target on which app needs to be reinstalled, stack or ogranization.
* @param {String} param.targetUid - The uid of the target, on which the app will be reinstalled
* @returns Promise<Reinstallation>
*
* @example
* import * as contentstack from '@contentstack/marketplace'
* const client = contentstack.client({ authtoken: 'TOKEN'})
* client.marketplace('organization_uid').app('manifest_uid').reinstall({ targetUid: 'STACK_API_KEY', targetType: 'stack' })
* .then((reinstallation) => console.log(installation))
*/
this.reinstall = async ({ targetUid, targetType }) => {
try {
const headers = {
headers: { ...cloneDeep(this.params) }
} || {}

const response = await http.put(`${this.urlPath}/reinstall`, { target_type: targetType, target_uid: targetUid }, headers)
if (response.data) {
return new Installation(http, response.data, this.params) || {}
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}

/**
* @description The upgrade call is used to upgrade the installation of an app
* @memberof App
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/marketplace-sdk",
"version": "1.0.2",
"version": "1.1.0",
"description": "The Contentstack Marketplace SDK is used to manage the content of your Contentstack marketplace apps",
"main": "./dist/node/contentstack-marketplace.js",
"browser": "./dist/web/contentstack-marketplace.js",
Expand Down
15 changes: 14 additions & 1 deletion test/api/app-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { expect } from 'chai'

dotenv.config()

let stack = {}
// let stack = {}
const orgID = process.env.ORG_UID
let client = {}
let appUid = ''
Expand Down Expand Up @@ -190,4 +190,17 @@ describe('Apps api Test', () => {
})
.catch(done)
})

it('should reinstall the app', done => {
client.marketplace(orgID).app(appUid).reinstall({ targetType: 'stack', targetUid: process.env.APIKEY })
.then((reinstallation) => {
expect(reinstallation.reinstallation_uid).to.not.equal(undefined)
expect(reinstallation.params.organization_uid).to.be.equal(orgID)
expect(reinstallation.fetch).to.not.equal(undefined)
expect(reinstallation.update).to.not.equal(undefined)
expect(reinstallation.uninstall).to.not.equal(undefined)
done()
})
.catch(done)
})
})
12 changes: 12 additions & 0 deletions test/typescript/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ export function installation(marketplace: Marketplace) {
done()
}).catch(done)
})

test('should Reinstall App', done => {
marketplace.app(appUid).reinstall({targetType: 'stack', targetUid: process.env.APIKEY as string})
.then((reinstallation) => {
installationUid = reinstallation.installation_uid
expect(reinstallation.installation_uid).to.not.equal(undefined)
expect(reinstallation.fetch).to.not.equal(undefined)
expect(reinstallation.update).to.not.equal(undefined)
expect(reinstallation.uninstall).to.not.equal(undefined)
done()
}).catch(done)
})

test('should Uninstall App installation', done => {
marketplace.installation(installationUid).uninstall()
Expand Down
32 changes: 32 additions & 0 deletions test/unit/apps-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,38 @@ describe('Contentstack apps test', () => {
done()
})
})
it('should reinstall the app', done => {
const mock = new MockAdapter(Axios)
const uid = appMock.uid
// using same installation mock data for reinstall
mock.onPut(`/manifests/${uid}/reinstall`).reply(200, {
data: {
...installationMock
}
})
const targetUid = 'target_uid'
const targetType = 'target_type'
makeApp({ data: { uid } })
.upgrade({ targetUid, targetType })
.then((reinstallation) => {
expect(reinstallation.status).to.be.equal(installationMock.status)
expect(reinstallation.manifest.name).to.be.equal(installationMock.manifest.name)
expect(reinstallation.target.uid).to.be.equal(installationMock.target.uid)
expect(reinstallation.organization_uid).to.be.equal(installationMock.organization_uid)
expect(reinstallation.uid).to.be.equal(installationMock.uid)
})
.catch(done)

// failing test when empty data is passed
mock.onPut(`/manifests/${uid}/reinstall`).reply(400, {})
makeApp({ data: { uid } })
.upgrade({ targetUid, targetType })
.then()
.catch((error) => {
expect(error).to.not.equal(null)
done()
})
})
})

function checkApp (app) {
Expand Down
1 change: 1 addition & 0 deletions types/marketplace/app/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface App extends SystemFields, SystemFunction<App> {
redirectUri: string,
scope: string,
state: string }): Promise<AnyProperty>
reinstall(data: {targetUid: string, targetType: AppTarget}): Promise<Installation>
authorization(): Authorization
listInstallations(): Promise<ContentstackCollection<App>>
}
Expand Down

0 comments on commit 04da1a1

Please sign in to comment.