@@ -4,6 +4,7 @@ import { create, deleteEntity, fetch, fetchAll, update } from '../entity'
44import { Authorization } from './authorization'
55import { Hosting } from './hosting'
66import { Installation } from './installation'
7+ import { Oauth } from './oauth'
78
89export function App ( http , data ) {
910 http . defaults . versioningStrategy = undefined
@@ -78,85 +79,25 @@ export function App (http, data) {
7879 this . delete = deleteEntity ( http , false , this . params )
7980
8081 /**
81- * @description The get oauth call is used to fetch the OAuth details of the app .
82+ * @description Oauth will allow to get, update auth and get scopes .
8283 * @memberof App
83- * @func fetchOAuth
84+ * @func oauth
8485 * @returns {Promise<AppOAuth> }
86+ * @returns {Oauth }
8587 *
8688 * @example
8789 * import * as contentstack from '@contentstack/management'
8890 * const client = contentstack.client({ authtoken: 'TOKEN'})
89- *
90- * client.organization('organization_uid').app('manifest_uid').fetchOAuth()
91- * .then((oAuthConfig) => console.log(oAuthConfig))
91+ * client.organization('organization_uid').app('manifest_uid').oauth()
9292 */
93- this . fetchOAuth = async ( param = { } ) => {
94- try {
95- const headers = {
96- headers : { ...cloneDeep ( this . params ) } ,
97- params : {
98- ...cloneDeep ( param )
99- }
100- } || { }
101-
102- const response = await http . get ( `${ this . urlPath } /oauth` , headers )
103- if ( response . data ) {
104- return response . data . data || { }
105- } else {
106- throw error ( response )
107- }
108- } catch ( err ) {
109- throw error ( err )
110- }
111- }
112-
113- /**
114- * @description The change oauth details call is used to update the OAuth details, (redirect url and permission scope) of an app.
115- * @memberof App
116- * @func updateOAuth
117- * @returns {Promise<AppOAuth> }
118- *
119- * @example
120- * import * as contentstack from '@contentstack/management'
121- * const client = contentstack.client({ authtoken: 'TOKEN'})
122- * const config = {
123- * redirect_uri: 'REDIRECT_URI',
124- * app_token_config: {
125- * enabled: true,
126- * scopes: ['scope1', 'scope2']
127- * },
128- * user_token_config: {
129- * enabled: true,
130- * scopes: ['scope1', 'scope2']
131- * }
132- * }
133- * client.organization('organization_uid').app('manifest_uid').updateOAuth({ config })
134- * .then((oAuthConfig) => console.log(oAuthConfig))
135- */
136- this . updateOAuth = async ( { config, param = { } } ) => {
137- try {
138- const headers = {
139- headers : { ...cloneDeep ( this . params ) } ,
140- params : {
141- ...cloneDeep ( param )
142- }
143- } || { }
144-
145- const response = await http . put ( `${ this . urlPath } /oauth` , config , headers )
146- if ( response . data ) {
147- return response . data . data || { }
148- } else {
149- throw error ( response )
150- }
151- } catch ( err ) {
152- throw error ( err )
153- }
93+ this . oauth = ( ) => {
94+ return new Oauth ( http , { app_uid : this . uid , organization_uid : this . organization_uid } , this . params )
15495 }
15596
15697 /**
15798 * @description The hosting will allow you get, update, deploy manifest.
15899 * @memberof App
159- * @func updateOAuth
100+ * @func hosting
160101 * @returns {Promise<AppOAuth> }
161102 * @returns {Hosting }
162103 *
@@ -310,6 +251,25 @@ export function App (http, data) {
310251 this . authorization = ( ) => {
311252 return new Authorization ( http , { app_uid : this . uid } , this . params )
312253 }
254+
255+ /**
256+ * @description The list installation call is used to retrieve all installations of your Contentstack organization.
257+ * @memberof App
258+ * @func listInstallations
259+ * @returns {Promise<ContentstackCollection<Installation>> }
260+ *
261+ * @example
262+ * import * as contentstack from '@contentstack/management'
263+ * const client = contentstack.client({ authtoken: 'TOKEN'})
264+ *
265+ * client.organization('organization_uid').app('app_uid').listInstallations()
266+ * .then((collection) => console.log(collection))
267+ *
268+ */
269+ this . listInstallations = ( ) => {
270+ this . urlPath = `manifests/${ data . app_uid } /installations`
271+ return fetchAll ( http , InstallationCollection , this . params )
272+ }
313273 } else {
314274 /**
315275 * @description The create manifest call is used for creating a new app/manifest in your Contentstack organization.
@@ -352,7 +312,7 @@ export function App (http, data) {
352312 * import * as contentstack from '@contentstack/management'
353313 * const client = contentstack.client({ authtoken: 'TOKEN'})
354314 *
355- * client.organization('organization_uid').app().fetchAll ()
315+ * client.organization('organization_uid').app().findAll ()
356316 * .then((collection) => console.log(collection))
357317 *
358318 */
@@ -400,3 +360,10 @@ export function AppCollection (http, data) {
400360 return new App ( http , { data : appData } )
401361 } )
402362}
363+
364+ function InstallationCollection ( http , data ) {
365+ const obj = cloneDeep ( data . data ) || [ ]
366+ return obj . map ( ( installationData ) => {
367+ return new Installation ( http , { data : installationData } )
368+ } )
369+ }
0 commit comments