Skip to content

Commit 5911fb0

Browse files
committed
feat: ✨ restructures the files for marketplace apis and refactors the code [cs-38336]
1 parent a571128 commit 5911fb0

File tree

20 files changed

+254
-163
lines changed

20 files changed

+254
-163
lines changed

lib/entity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,4 @@ export async function get (http, url, params, data) {
288288
} catch (err) {
289289
throw error(err)
290290
}
291-
}
291+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cloneDeep from 'lodash/cloneDeep'
2-
import ContentstackCollection from '../../contentstackCollection'
3-
import error from '../../core/contentstackError'
2+
import ContentstackCollection from '../../../contentstackCollection'
3+
import error from '../../../core/contentstackError'
44

55
export function Deployment (http, data, params) {
66
http.defaults.versioningStrategy = undefined
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cloneDeep from 'lodash/cloneDeep'
2-
import error from '../../core/contentstackError'
2+
import error from '../../../core/contentstackError'
33
import { Deployment } from './deployment'
44

55
export function Hosting (http, data, params) {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import cloneDeep from 'lodash/cloneDeep'
2-
import error from '../core/contentstackError'
3-
import { create, deleteEntity, fetch, update } from '../entity'
4-
import { Authorization } from './authorization'
2+
import error from '../../core/contentstackError'
3+
import { create, deleteEntity, fetch, update } from '../../entity'
4+
import { Authorization } from '../authorization'
55
import { Hosting } from './hosting'
6-
import { Installation, InstallationCollection } from './installation'
6+
import { Installation, InstallationCollection } from '../installation'
77
import { Oauth } from './oauth'
8-
import ContentstackCollection from '../contentstackCollection'
8+
import ContentstackCollection from '../../contentstackCollection'
99

1010
export function App (http, data) {
1111
http.defaults.versioningStrategy = undefined
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import error from '../../core/contentstackError'
1+
import error from '../../../core/contentstackError'
22
import cloneDeep from 'lodash/cloneDeep'
33
export function Oauth (http, data, params) {
44
http.defaults.versioningStrategy = undefined

lib/marketplace/index.js

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import cloneDeep from 'lodash/cloneDeep'
2-
import { App } from '../app'
3-
import { Installation } from '../app/installation'
2+
import { App } from './app'
3+
import { Installation } from './installation'
44
import error from '../core/contentstackError'
55
import { fetchAll } from '../entity'
6-
import { AppRequest } from '../app/request'
6+
import { AppRequest } from './request'
77

88
export function Marketplace (http, data) {
99
http.defaults.versioningStrategy = undefined
@@ -16,21 +16,59 @@ export function Marketplace (http, data) {
1616
}
1717

1818
/**
19-
* @description Oauth will allow to get, update auth and get scopes.
20-
* @memberof App
21-
* @func oauth
22-
* @returns {Promise<AppOAuth>}
23-
* @returns {Oauth}
19+
* @description App will allow to App instance.
20+
* @memberof Marketplace
21+
* @func app
22+
* @returns {Promise<App>}
23+
* @returns {App}
2424
*
2525
* @example
2626
* import * as contentstack from '@contentstack/management'
2727
* const client = contentstack.client({ authtoken: 'TOKEN'})
28-
* client.organization('organization_uid').app('manifest_uid').oauth()
28+
* client.organization('organization_uid').marketplace().app('manifest_uid')
2929
*/
3030
this.app = (uid = null) => {
3131
return new App(http, uid !== null ? { data: { uid, organization_uid: this.uid } } : { organization_uid: this.uid })
3232
}
3333

34+
/**
35+
* @description The Installation will allow you to fetch, update and delete of the app installation.
36+
* @memberof Marketplace
37+
* @func installation
38+
* @param {String} uid Installation uid
39+
* @returns Installation
40+
*
41+
* @example
42+
* import * as contentstack from '@contentstack/management'
43+
* const client = contentstack.client({ authtoken: 'TOKEN'})
44+
* client.organization('organization_uid').app('manifest_uid').installation().findAll()
45+
* .then((installations) => console.log(installations))
46+
*
47+
* @example
48+
* import * as contentstack from '@contentstack/management'
49+
* const client = contentstack.client({ authtoken: 'TOKEN'})
50+
* client.organization('organization_uid').marketplace().installation('installation_uid').fetch()
51+
* .then((installation) => console.log(installation))
52+
*/
53+
this.installation = (installationUid = null) => {
54+
return new Installation(http, installationUid ? { data: { uid: installationUid } } : { data: {} }, this.params)
55+
}
56+
57+
/**
58+
* @description The Create request call is used to create a app request for an app.
59+
* @returns Request
60+
*
61+
* @example
62+
* import * as contentstack from '@contentstack/management'
63+
* const client = contentstack.client({ authtoken: 'TOKEN'})
64+
*
65+
* client.organization('organization_uid').marketplace().requests()
66+
*
67+
*/
68+
this.appRequests = () => {
69+
return new AppRequest(http, { organization_uid: this.uid })
70+
}
71+
3472
/**
3573
* @description The findAllApps call is used to fetch all the apps in your Contentstack organization.
3674
* @memberof Marketplace
@@ -79,44 +117,6 @@ export function Marketplace (http, data) {
79117
return error(err)
80118
}
81119
}
82-
83-
/**
84-
* @description The Installation will allow you to fetch, update and delete of the app installation.
85-
* @memberof Marketplace
86-
* @func installation
87-
* @param {String} uid Installation uid
88-
* @returns Installation
89-
*
90-
* @example
91-
* import * as contentstack from '@contentstack/management'
92-
* const client = contentstack.client({ authtoken: 'TOKEN'})
93-
* client.organization('organization_uid').app('manifest_uid').installation().findAll()
94-
* .then((installations) => console.log(installations))
95-
*
96-
* @example
97-
* import * as contentstack from '@contentstack/management'
98-
* const client = contentstack.client({ authtoken: 'TOKEN'})
99-
* client.organization('organization_uid').marketplace().installation('installation_uid').fetch()
100-
* .then((installation) => console.log(installation))
101-
*/
102-
this.installation = (installationUid = null) => {
103-
return new Installation(http, installationUid ? { data: { installationUid } } : {}, this.params)
104-
}
105-
106-
/**
107-
* @description The Create request call is used to create a app request for an app.
108-
* @returns Request
109-
*
110-
* @example
111-
* import * as contentstack from '@contentstack/management'
112-
* const client = contentstack.client({ authtoken: 'TOKEN'})
113-
*
114-
* client.organization('organization_uid').marketplace().requests()
115-
*
116-
*/
117-
this.requests = () => {
118-
return new AppRequest(http, { organization_uid: this.uid })
119-
}
120120
}
121121
return this
122122
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export function Installation (http, data, params = {}) {
1111
organization_uid: this.organization_uid
1212
}
1313
}
14-
if (this.installation_uid) {
15-
this.urlPath = `/installations/${this.installation_uid}`
14+
if (this.uid) {
15+
this.urlPath = `/installations/${this.uid}`
1616

1717
/**
1818
* @description The GET installation call is used to retrieve a specific installation of an app.
@@ -340,4 +340,4 @@ export function InstallationCollection (http, data) {
340340
return obj.map((installationData) => {
341341
return new Installation(http, { data: installationData })
342342
})
343-
}
343+
}

test/unit/app-request-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect } from 'chai'
33
import { describe, it } from 'mocha'
44
import MockAdapter from 'axios-mock-adapter'
55
import { appMock } from './mock/objects'
6-
import { AppRequest } from '../../lib/app/request'
6+
import { AppRequest } from '../../lib/marketplace/request'
77
import { requestMock } from './mock/request-mock'
88

99
describe('Contentstack apps request test', () => {

0 commit comments

Comments
 (0)