Skip to content

Commit 3f0c523

Browse files
Merge pull request #21 from contentstack/feat/DX-660-disconnect-api-support
dx - 660 | disconnect api support
2 parents 2f15481 + 6ec6c1c commit 3f0c523

File tree

7 files changed

+94
-23
lines changed

7 files changed

+94
-23
lines changed

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.2.0](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.1.1) (2024-06-21)
4+
- Added disconnect hosting function
5+
36
## [v1.1.1](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.1.1) (2024-06-11)
47
- Added GCP Region support
58

lib/marketplace/app/hosting/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,32 @@ export function Hosting (http, data, params) {
186186
return new Deployment(http, content, this.params)
187187
}
188188
}
189+
190+
/**
191+
* @description this disconnects the hosting.
192+
* @memberof Hosting
193+
* @func disconnect
194+
* @returns {disconnect}
195+
*
196+
* @example
197+
* import * as contentstack from '@contentstack/marketplace'
198+
* const client = contentstack.client({ authtoken: 'TOKEN'})
199+
* client.marketplace('organization_uid').app('manifest_uid').hosting().disconnect({ 'provider': 'launch' })
200+
*
201+
*/
202+
this.disconnect = async (data = {}) => {
203+
try {
204+
const headers = {
205+
headers: { ...cloneDeep(this.params) }
206+
}
207+
const response = await http.patch(`${this.urlPath}/disconnect`, data, headers)
208+
if (response.data) {
209+
return response.data
210+
} else {
211+
throw error(response)
212+
}
213+
} catch (err) {
214+
throw error(err)
215+
}
216+
}
189217
}

package-lock.json

Lines changed: 22 additions & 22 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.1.1",
3+
"version": "1.2.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/hosting-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ describe('Apps hosting api Test', () => {
133133
})
134134
.catch(done)
135135
})
136+
137+
it.only('should disconnect apps hosting', done => {
138+
makeHosting(apps.uid).disconnect({ provider: 'launch' })
139+
.then((response) => {
140+
expect(response.enabled).to.not.equal(false)
141+
done()
142+
})
143+
.catch(done)
144+
})
136145
})
137146

138147
function makeHosting (appUid) {

test/unit/hosting-test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,36 @@ describe('Contentstack hosting test', () => {
225225
done()
226226
})
227227
})
228+
229+
it('should test to disconnect hosting', done => {
230+
const mock = new MockAdapter(Axios)
231+
const uid = appMock.uid
232+
mock.onPatch(`manifests/${uid}/hosting/disconnect`).reply(200, {
233+
data: { provider: 'launch' }
234+
})
235+
236+
makeHosting({ app_uid: uid })
237+
.disconnect()
238+
.then((response) => {
239+
expect(response.data.provider).to.be.equal('launch')
240+
done()
241+
})
242+
.catch(done)
243+
})
244+
245+
it('should fail test to disconnect hosting', done => {
246+
const mock = new MockAdapter(Axios)
247+
const uid = appMock.uid
248+
mock.onPatch(`manifests/${uid}/hosting/disconnect`).reply(400, {})
249+
250+
makeHosting({ app_uid: uid })
251+
.disconnect()
252+
.then(done)
253+
.catch((error) => {
254+
expect(error).to.not.equal(null)
255+
done()
256+
})
257+
})
228258
})
229259

230260
function makeHosting (data, param = {}) {

types/marketplace/app/hosting.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface Hosting {
88
deployment(): Deployments
99
deployment(uid: string): Deployment
1010
latestLiveDeployment(): Promise<Deployment>
11+
disconnect(): Promise<AnyProperty>
1112
}
1213

1314
export interface UploadDetails {

0 commit comments

Comments
 (0)