Skip to content

Commit e27ecb8

Browse files
committed
feat: ✨ Marketplace app implementation done
1 parent 84ec3bd commit e27ecb8

File tree

7 files changed

+93
-26
lines changed

7 files changed

+93
-26
lines changed

lib/app/index.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function App (http, data) {
7070
* const client = contentstack.client({ authtoken: 'TOKEN'})
7171
*
7272
* client.organization('organization_uid').app('app_uid').delete()
73-
* .then((app) => console.log(app))
73+
* .then((response) => console.log(response))
7474
*/
7575
this.delete = deleteEntity(http, false, this.params)
7676

@@ -152,6 +152,8 @@ export function App (http, data) {
152152

153153
/**
154154
* @description The install call is used to initiate the installation of the app
155+
* @memberof App
156+
* @func install
155157
* @param {String} param.targetType - The target on which app needs to be installed, stack or ogranization.
156158
* @param {String} param.targetUid - The uid of the target, on which the app will be installed
157159
* @returns Promise<Installation>
@@ -181,6 +183,8 @@ export function App (http, data) {
181183

182184
/**
183185
* @description The Installation will allow you to fetch, update and delete of the app installation.
186+
* @memberof App
187+
* @func installation
184188
* @param {String} uid Installation uid
185189
* @returns Installation
186190
*
@@ -232,17 +236,17 @@ export function App (http, data) {
232236
this.create = create({ http, params: this.params })
233237

234238
/**
235-
* @description The create an app call is used for creating a new app in your Contentstack organization.
239+
* @description The get all apps call is used to fetch all the apps in your Contentstack organization.
236240
* @memberof App
237-
* @func create
241+
* @func findAll
238242
* @returns {Promise<ContentstackCollection<App>>}
239243
*
240244
* @example
241245
* import * as contentstack from '@contentstack/management'
242246
* const client = contentstack.client({ authtoken: 'TOKEN'})
243247
*
244248
* client.organization('organization_uid').app().fetchAll()
245-
* .then((app) => console.log(app))
249+
* .then((collection) => console.log(collection))
246250
*
247251
*/
248252
this.findAll = fetchAll(http, AppCollection, this.params)

lib/app/installation/index.js

+40-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import cloneDeep from 'lodash/cloneDeep'
2+
import error from '../../core/contentstackError'
23
import { deleteEntity, fetch, fetchAll, update } from '../../entity'
34

45
export function Installation (http, data, params = {}) {
@@ -16,7 +17,7 @@ export function Installation (http, data, params = {}) {
1617
this.urlPath = `/installations/${this.uid}`
1718

1819
/**
19-
* @description The GET installation call is used to retrieve a specific installation of an app
20+
* @description The GET installation call is used to retrieve a specific installation of an app.
2021
* @memberof Installation
2122
* @func fetch
2223
* @returns {Promise<Installation>}
@@ -32,7 +33,7 @@ export function Installation (http, data, params = {}) {
3233
this.fetch = fetch(http, 'data', this.params)
3334

3435
/**
35-
* @description The Update installation call is used to update information of an app
36+
* @description The Update installation call is used to update information of an installation.
3637
* @memberof Installation
3738
* @func update
3839
* @returns {Promise<Installation>}
@@ -65,24 +66,57 @@ export function Installation (http, data, params = {}) {
6566
* const client = contentstack.client({ authtoken: 'TOKEN'})
6667
*
6768
* client.organization('organization_uid').app('app_uid').installation('installation_uid').uninstall()
68-
* .then((app) => console.log(app))
69+
* .then((response) => console.log(response))
6970
*/
7071
this.uninstall = deleteEntity(http, false, this.params)
72+
73+
/**
74+
* @description To fetch organization level app installation configuration.
75+
* @memberof Installation
76+
* @func configuration
77+
* @param {*} param
78+
* @returns {Promise<Response>}
79+
*
80+
* @example
81+
* import * as contentstack from '@contentstack/management'
82+
* const client = contentstack.client({ authtoken: 'TOKEN'})
83+
*
84+
* client.organization('organization_uid').app('app_uid').installation('installation_uid').configuration()
85+
* .then((response) => console.log(response))
86+
*/
87+
this.configuration = async (param = {}) => {
88+
try {
89+
const headers = {
90+
headers: { ...cloneDeep(params) },
91+
params: {
92+
...cloneDeep(param)
93+
}
94+
} || {}
95+
const response = await http.get(`${this.urlPath}/configuration`, headers)
96+
if (response.data) {
97+
return response.data.data
98+
} else {
99+
throw error(response)
100+
}
101+
} catch (err) {
102+
throw error(err)
103+
}
104+
}
71105
} else {
72106
if (data.app_uid) {
73107
this.urlPath = `apps/${data.app_uid}/installations`
74108
/**
75-
* @description The create an app call is used for creating a new app in your Contentstack organization.
109+
* @description The find installation call is used to retrieve all installations of your Contentstack organization.
76110
* @memberof Installation
77-
* @func create
111+
* @func findAll
78112
* @returns {Promise<ContentstackCollection<Installation>>}
79113
*
80114
* @example
81115
* import * as contentstack from '@contentstack/management'
82116
* const client = contentstack.client({ authtoken: 'TOKEN'})
83117
*
84118
* client.organization('organization_uid').app('app_uid').installation().fetchAll()
85-
* .then((app) => console.log(app))
119+
* .then((collection) => console.log(collection))
86120
*
87121
*/
88122
this.findAll = fetchAll(http, InstallationCollection, this.params)

test/api/app-test.js

+8
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ describe('Apps api Test', () => {
117117
.catch(done)
118118
})
119119

120+
it('Get configuration for installation test', done => {
121+
client.organization(orgID).app(appUid).installation(installationUid).configuration()
122+
.then((installation) => {
123+
expect(installation).to.deep.equal({})
124+
done()
125+
}).catch(done)
126+
})
127+
120128
it('Fetch installation test', done => {
121129
client.organization(orgID).app(appUid).installation(installationUid).fetch()
122130
.then((installation) => {

test/typescript/app.ts

+7
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ export function installation(organization: Organization) {
145145
}).catch(done)
146146
})
147147

148+
test('Get Configuration for App installation', done => {
149+
organization.app(appUid).installation(installationUid).configuration()
150+
.then(() => {
151+
done()
152+
}).catch(done)
153+
})
154+
148155
test('Uninstall App installation', done => {
149156
organization.app(appUid).installation(installationUid).uninstall()
150157
.then((installation) => {

test/unit/apps-test.js

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ function checkApp (app) {
176176
expect(app.description).to.be.equal('Description of the app')
177177
expect(app.organization_uid).to.be.equal('org_uid')
178178
}
179+
179180
function makeApp (data) {
180181
return new App(Axios, data)
181182
}

test/unit/installation-test.js

+28-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Contentstack apps installation test', () => {
1717
done()
1818
})
1919

20-
it('Installation with app uid', done => {
20+
it('Installation with app uid', done => {
2121
const uid = appMock.uid
2222
const installation = makeInstallation({ app_uid: uid })
2323
expect(installation.urlPath).to.be.equal(`apps/${uid}/installations`)
@@ -91,11 +91,7 @@ describe('Contentstack apps installation test', () => {
9191
.findAll()
9292
.then((installations) => {
9393
installations.items.forEach(installation => {
94-
expect(installation.status).to.be.equal(installationMock.status)
95-
expect(installation.uid).to.be.equal(installationMock.uid)
96-
expect(installation.organization_uid).to.be.equal(installationMock.organization_uid)
97-
expect(installation.target.type).to.be.equal(installationMock.target.type)
98-
expect(installation.target.uid).to.be.equal(installationMock.target.uid)
94+
checkInstallation(installation)
9995
})
10096
done()
10197
})
@@ -112,11 +108,23 @@ describe('Contentstack apps installation test', () => {
112108
makeInstallation({ data: { uid } })
113109
.fetch()
114110
.then((installation) => {
115-
expect(installation.status).to.be.equal(installationMock.status)
116-
expect(installation.uid).to.be.equal(installationMock.uid)
117-
expect(installation.organization_uid).to.be.equal(installationMock.organization_uid)
118-
expect(installation.target.type).to.be.equal(installationMock.target.type)
119-
expect(installation.target.uid).to.be.equal(installationMock.target.uid)
111+
checkInstallation(installation)
112+
done()
113+
})
114+
.catch(done)
115+
})
116+
117+
it('Get installation configuration test', done => {
118+
const mock = new MockAdapter(Axios)
119+
const uid = installationMock.uid
120+
mock.onGet(`/installations/${uid}/configuration`).reply(200, {
121+
data: {}
122+
})
123+
124+
makeInstallation({ data: { uid } })
125+
.configuration()
126+
.then((configuration) => {
127+
expect(configuration).to.deep.equal({})
120128
done()
121129
})
122130
.catch(done)
@@ -131,11 +139,7 @@ describe('Contentstack apps installation test', () => {
131139
makeInstallation({ data: { uid } })
132140
.update()
133141
.then((installation) => {
134-
expect(installation.status).to.be.equal(installationMock.status)
135-
expect(installation.uid).to.be.equal(installationMock.uid)
136-
expect(installation.organization_uid).to.be.equal(installationMock.organization_uid)
137-
expect(installation.target.type).to.be.equal(installationMock.target.type)
138-
expect(installation.target.uid).to.be.equal(installationMock.target.uid)
142+
checkInstallation(installation)
139143
done()
140144
})
141145
.catch(done)
@@ -156,6 +160,14 @@ describe('Contentstack apps installation test', () => {
156160
})
157161
})
158162

163+
function checkInstallation (installation) {
164+
expect(installation.status).to.be.equal(installationMock.status)
165+
expect(installation.uid).to.be.equal(installationMock.uid)
166+
expect(installation.organization_uid).to.be.equal(installationMock.organization_uid)
167+
expect(installation.target.type).to.be.equal(installationMock.target.type)
168+
expect(installation.target.uid).to.be.equal(installationMock.target.uid)
169+
}
170+
159171
function makeInstallation (data, param = {}) {
160172
return new Installation(Axios, data, param)
161173
}

types/app/installation.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface Installation extends SystemFields{
55
update(param?: AnyProperty): Promise<Installation>
66
fetch(param?: AnyProperty): Promise<Installation>
77
uninstall(param?: AnyProperty): Promise<AnyProperty>
8+
configuration(param?: AnyProperty): Promise<AnyProperty>
89
}
910

1011
export interface Installations {

0 commit comments

Comments
 (0)