Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions .jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"lib/stack/asset/index.js",
"lib/stack/asset/folders/index.js",
"lib/stack/branch/index.js",
"lib/stack/branch/compare.js",
"lib/stack/branch/mergeQueue.js",
"lib/stack/branchAlias/index.js",
"lib/stack/bulkOperation/index.js",
"lib/stack/extension/index.js",
Expand All @@ -29,23 +27,15 @@
"lib/stack/environment/index.js",
"lib/stack/deliveryToken/index.js",
"lib/stack/roles/index.js",
"lib/stack/webhook/index.js",
"lib/stack/workflow/index.js",
"lib/stack/workflow/publishRules/index.js",
"lib/marketplace/app/oauth/index.js",
"lib/marketplace/app/index.js",
"lib/marketplace/app/hosting/deployment.js",
"lib/marketplace/app/hosting/index.js",
"lib/marketplace/index.js",
"lib/marketplace/installation/index.js",
"lib/marketplace/installation/webhooks/index.js",
"lib/marketplace/apprequest/index.js",
"lib/marketplace/authorization/index.js"
"lib/stack/workflow/publishRules/index.js"

],
"excludePattern": "(node_modules/|jsdocs)"
},
"opts": {
"template": "./node_modules/docdash",
"template": "docdash-template",
"destination": "./jsdocs/",
"encoding": "utf8",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ contentstackClient.stack({ api_key: 'API_KEY' }).asset().create({ asset })
- [Content Management API Docs](https://www.contentstack.com/docs/developers/apis/content-management-api)

### The MIT License (MIT)
Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved
Copyright © 2012-2022 [Contentstack](https://www.contentstack.com/). All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cloneDeep from 'lodash/cloneDeep'
import ContentstackCollection from '../../../contentstackCollection'
import error from '../../../core/contentstackError'
import ContentstackCollection from '../../contentstackCollection'
import error from '../../core/contentstackError'

export function Deployment (http, data, params) {
http.defaults.versioningStrategy = undefined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cloneDeep from 'lodash/cloneDeep'
import error from '../../../core/contentstackError'
import error from '../../core/contentstackError'
import { Deployment } from './deployment'

export function Hosting (http, data, params) {
Expand Down
241 changes: 158 additions & 83 deletions lib/marketplace/app/index.js → lib/app/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import cloneDeep from 'lodash/cloneDeep'
import error from '../../core/contentstackError'
import { create, deleteEntity, fetch, update } from '../../entity'
import { Authorization } from '../authorization'
import error from '../core/contentstackError'
import { create, deleteEntity, fetch, fetchAll, update } from '../entity'
import { Authorization } from './authorization'
import { Hosting } from './hosting'
import { Installation, InstallationCollection } from '../installation'
import { Oauth } from './oauth'
import ContentstackCollection from '../../contentstackCollection'
import { Installation } from './installation'

export function App (http, data) {
http.defaults.versioningStrategy = undefined
Expand All @@ -27,25 +25,25 @@ export function App (http, data) {
this.urlPath = `/manifests/${this.uid}`

/**
* @description The update manifest call is used to update the app details such as name, description, icon, and so on.
* @memberof App
* @func update
* @returns {Promise<App>}
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ authtoken: 'TOKEN'})
* const updateApp = {
* name: 'APP_NAME',
* description: 'APP_DESCRIPTION',
* target_type: 'stack'/'organization',
* }
* const app = client.organization('organization_uid').app('manifest_uid')
* app = Object.assign(app, updateApp)
* app.update()
* .then((app) => console.log(app))
*
*/
* @description The update manifest call is used to update the app details such as name, description, icon, and so on.
* @memberof App
* @func update
* @returns {Promise<App>}
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ authtoken: 'TOKEN'})
* const updateApp = {
* name: 'APP_NAME',
* description: 'APP_DESCRIPTION',
* target_type: 'stack'/'organization',
* }
* const app = client.organization('organization_uid').app('manifest_uid')
* app = Object.assign(app, updateApp)
* app.update()
* .then((app) => console.log(app))
*
*/
this.update = update(http, undefined, this.params)

/**
Expand Down Expand Up @@ -80,25 +78,85 @@ export function App (http, data) {
this.delete = deleteEntity(http, false, this.params)

/**
* @description Oauth will allow to get, update auth and get scopes.
* @description The get oauth call is used to fetch the OAuth details of the app.
* @memberof App
* @func oauth
* @func fetchOAuth
* @returns {Promise<AppOAuth>}
* @returns {Oauth}
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ authtoken: 'TOKEN'})
* client.organization('organization_uid').app('manifest_uid').oauth()
*
* client.organization('organization_uid').app('manifest_uid').fetchOAuth()
* .then((oAuthConfig) => console.log(oAuthConfig))
*/
this.oauth = () => {
return new Oauth(http, { app_uid: this.uid, organization_uid: this.organization_uid }, this.params)
this.fetchOAuth = async (param = {}) => {
try {
const headers = {
headers: { ...cloneDeep(this.params) },
params: {
...cloneDeep(param)
}
} || {}

const response = await http.get(`${this.urlPath}/oauth`, headers)
if (response.data) {
return response.data.data || {}
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}

/**
* @description The change oauth details call is used to update the OAuth details, (redirect url and permission scope) of an app.
* @memberof App
* @func updateOAuth
* @returns {Promise<AppOAuth>}
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ authtoken: 'TOKEN'})
* const config = {
* redirect_uri: 'REDIRECT_URI',
* app_token_config: {
* enabled: true,
* scopes: ['scope1', 'scope2']
* },
* user_token_config: {
* enabled: true,
* scopes: ['scope1', 'scope2']
* }
* }
* client.organization('organization_uid').app('manifest_uid').updateOAuth({ config })
* .then((oAuthConfig) => console.log(oAuthConfig))
*/
this.updateOAuth = async ({ config, param = {} }) => {
try {
const headers = {
headers: { ...cloneDeep(this.params) },
params: {
...cloneDeep(param)
}
} || {}

const response = await http.put(`${this.urlPath}/oauth`, config, headers)
if (response.data) {
return response.data.data || {}
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}

/**
* @description The hosting will allow you get, update, deploy manifest.
* @memberof App
* @func hosting
* @func updateOAuth
* @returns {Promise<AppOAuth>}
* @returns {Hosting}
*
Expand Down Expand Up @@ -143,34 +201,26 @@ export function App (http, data) {
}

/**
* @description The upgrade call is used to upgrade the installation of an app
* @description The Installation will allow you to fetch, update and delete of the app installation.
* @memberof App
* @func upgrade
* @param {String} param.targetType - The target on which app needs to be installed, stack or ogranization.
* @param {String} param.targetUid - The uid of the target, on which the app will be installed
* @returns Promise<Installation>
* @func installation
* @param {String} uid Installation uid
* @returns Installation
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ authtoken: 'TOKEN'})
* client.organization('organization_uid').app('manifest_uid').install({ targetUid: 'STACK_API_KEY', targetType: 'stack' })
* client.organization('organization_uid').app('manifest_uid').installation().findAll()
* .then((installations) => console.log(installations))
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ authtoken: 'TOKEN'})
* client.organization('organization_uid').app('manifest_uid').installation('installation_uid').fetch()
* .then((installation) => console.log(installation))
*/
this.upgrade = 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)
}
this.installation = (uid = null) => {
return new Installation(http, uid ? { data: { uid } } : { app_uid: this.uid }, this.params)
}
/**
* @description The GET app requests of an app call is used to retrieve all requests of an app.
Expand Down Expand Up @@ -260,36 +310,6 @@ export function App (http, data) {
this.authorization = () => {
return new Authorization(http, { app_uid: this.uid }, this.params)
}

/**
* @description The list installation call is used to retrieve all installations of your Contentstack organization.
* @memberof App
* @func listInstallations
* @returns {Promise<ContentstackCollection<Installation>>}
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ authtoken: 'TOKEN'})
*
* client.organization('organization_uid').app('app_uid').listInstallations()
* .then((collection) => console.log(collection))
*
*/
this.listInstallations = async () => {
try {
const headers = {
headers: { ...cloneDeep(this.params), ...cloneDeep(this.headers) }
}
const response = await http.get(`manifests/${this.uid}/installations`, headers)
if (response.data) {
return new ContentstackCollection(response, http, this.stackHeaders, InstallationCollection)
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}
} else {
/**
* @description The create manifest call is used for creating a new app/manifest in your Contentstack organization.
Expand Down Expand Up @@ -321,7 +341,62 @@ export function App (http, data) {
*
*/
this.create = create({ http, params: this.params })

/**
* @description The get all manifest call is used to fetch all the apps in your Contentstack organization.
* @memberof App
* @func findAll
* @returns {Promise<ContentstackCollection<App>>}
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ authtoken: 'TOKEN'})
*
* client.organization('organization_uid').app().fetchAll()
* .then((collection) => console.log(collection))
*
*/
this.findAll = fetchAll(http, AppCollection, this.params)

/**
* @description To get the apps list of authorized apps for the particular organization
* @memberof Organization
* @func authorizedApps
* @param {number} skip - Offset for skipping content in the response.
* @param {number} limit - Limit on api response to provide content in list.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organization_uid').authorizedApps({ skip: 10 })
* .then((roles) => console.log(roles))
*
*/
this.findAllAuthorized = async (param = {}) => {
const headers = {
headers: { ...cloneDeep(this.params) }
}

headers.params = { ...param }
try {
const response = await http.get(`/authorized-apps`, headers)
if (response.data) {
return response.data
} else {
return error(response)
}
} catch (err) {
return error(err)
}
}
}
}
return this
}

export function AppCollection (http, data) {
const obj = cloneDeep(data.data) || []
return obj.map((appData) => {
return new App(http, { data: appData })
})
}
Loading