Skip to content

Commit 3656d0b

Browse files
committed
feat: 🚧 marketplace manifest api [CS-33683]
1 parent d909a3f commit 3656d0b

File tree

10 files changed

+260
-79
lines changed

10 files changed

+260
-79
lines changed

.eslintrc.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
module.exports = {
2-
// "env": {
3-
// "browser": true,
4-
// "amd": true
5-
// },
6-
"extends": "standard",
7-
// "globals": {
8-
// "Atomics": "readonly",
9-
// "SharedArrayBuffer": "readonly"
10-
// },
11-
// "parserOptions": {
12-
// "ecmaFeatures": {
13-
// "jsx": true
14-
// },
15-
// "ecmaVersion": 2015,
16-
// "sourceType": "module"
17-
// },
18-
'plugins': [
19-
'standard',
20-
'promise'
21-
],
22-
"rules": {
23-
}
24-
};
2+
// "env": {
3+
// "browser": true,
4+
// "amd": true
5+
// },
6+
extends: 'standard',
7+
// "globals": {
8+
// "Atomics": "readonly",
9+
// "SharedArrayBuffer": "readonly"
10+
// },
11+
// "parserOptions": {
12+
// "ecmaFeatures": {
13+
// "jsx": true
14+
// },
15+
// "ecmaVersion": 2015,
16+
// "sourceType": "module"
17+
// },
18+
plugins: [
19+
'standard',
20+
'promise'
21+
],
22+
rules: {
23+
}
24+
}

lib/app/hosting/index.js

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import cloneDeep from 'lodash/cloneDeep'
2+
import error from '../../core/contentstackError'
3+
4+
export function Hosting (http, data, params) {
5+
http.defaults.versioningStrategy = undefined
6+
7+
this.params = params | {}
8+
if (data) {
9+
this.urlPath = `/manifests/${data.app_uid}/hosting`
10+
if (data.organization_uid) {
11+
this.params = {
12+
organization_uid: data.organization_uid
13+
}
14+
}
15+
if (data.data) {
16+
Object.assign(this, cloneDeep(data.data))
17+
if (this.organization_uid) {
18+
this.params = {
19+
organization_uid: this.organization_uid
20+
}
21+
}
22+
}
23+
24+
/**
25+
* @description The get hosting call is used to fetch to know whether the hosting is enabled or not.
26+
* @memberof Hosting
27+
* @func isEnable
28+
* @returns {Promise<Response>}
29+
*
30+
* @example
31+
* import * as contentstack from '@contentstack/management'
32+
* const client = contentstack.client({ authtoken: 'TOKEN'})
33+
* client.organization('organization_uid').app('manifest_uid').hosting().isEnable()
34+
* .then((data) => {})
35+
*/
36+
this.isEnable = async () => {
37+
try {
38+
const headers = {
39+
headers: { ...cloneDeep(this.params) }
40+
} || {}
41+
42+
const response = await http.get(this.urlPath, headers)
43+
if (response.data) {
44+
return response.data
45+
} else {
46+
throw error(response)
47+
}
48+
} catch (err) {
49+
throw error(err)
50+
}
51+
}
52+
53+
/**
54+
* @description The toggle hosting call is used to enable the hosting of an app.
55+
* @memberof Hosting
56+
* @func updateOAuth
57+
* @returns {Promise<Response>}
58+
*
59+
* @example
60+
* import * as contentstack from '@contentstack/management'
61+
* const client = contentstack.client({ authtoken: 'TOKEN'})
62+
* client.organization('organization_uid').app('manifest_uid').hosting().enable()
63+
* .then((data) => {})
64+
*/
65+
this.enable = async () => {
66+
try {
67+
const headers = {
68+
headers: { ...cloneDeep(this.params) }
69+
} || {}
70+
71+
const response = await http.put(`${this.urlPath}/enable`, {}, headers)
72+
if (response.data) {
73+
return response.data
74+
} else {
75+
throw error(response)
76+
}
77+
} catch (err) {
78+
throw error(err)
79+
}
80+
}
81+
82+
/**
83+
* @description The toggle hosting call is used to disable the hosting of an app.
84+
* @memberof Hosting
85+
* @func disable
86+
* @returns {Promise<Response>}
87+
*
88+
* @example
89+
* import * as contentstack from '@contentstack/management'
90+
* const client = contentstack.client({ authtoken: 'TOKEN'})
91+
* client.organization('organization_uid').app('manifest_uid').hosting().disable()
92+
* .then((data) => {})
93+
*/
94+
this.disable = async () => {
95+
try {
96+
const headers = {
97+
headers: { ...cloneDeep(this.params) }
98+
} || {}
99+
100+
const response = await http.put(`${this.urlPath}/disable`, {}, headers)
101+
if (response.data) {
102+
return response.data
103+
} else {
104+
throw error(response)
105+
}
106+
} catch (err) {
107+
throw error(err)
108+
}
109+
}
110+
111+
/**
112+
* @descriptionThe create signed upload url call is used to create an signed upload url for the files in hosting.
113+
* @memberof Hosting
114+
* @func createUploadUrl
115+
* @returns {Promise<Response>}
116+
*
117+
* @example
118+
* import * as contentstack from '@contentstack/management'
119+
* const client = contentstack.client({ authtoken: 'TOKEN'})
120+
* client.organization('organization_uid').app('manifest_uid').hosting().createUploadUrl()
121+
* .then((data) => {})
122+
*/
123+
this.createUploadUrl = async () => {
124+
try {
125+
const headers = {
126+
headers: { ...cloneDeep(this.params) }
127+
} || {}
128+
129+
const response = await http.post(`${this.urlPath}/signedUploadUrl`, { }, headers)
130+
if (response.data) {
131+
return response.data
132+
} else {
133+
throw error(response)
134+
}
135+
} catch (err) {
136+
throw error(err)
137+
}
138+
}
139+
}
140+
}

lib/app/index.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import cloneDeep from 'lodash/cloneDeep'
22
import error from '../core/contentstackError'
33
import { create, deleteEntity, fetch, fetchAll, update } from '../entity'
4+
import { Hosting } from './hosting'
45
import { Installation } from './installation'
6+
57
export function App (http, data) {
68
http.defaults.versioningStrategy = undefined
7-
this.urlPath = '/apps'
9+
this.urlPath = '/manifests'
810
this.params = {}
911
if (data) {
1012
if (data.organization_uid) {
@@ -19,10 +21,10 @@ export function App (http, data) {
1921
organization_uid: this.organization_uid
2022
}
2123
}
22-
this.urlPath = `/apps/${this.uid}`
24+
this.urlPath = `/manifests/${this.uid}`
2325

2426
/**
25-
* @description The update an app call is used to update the app details such as name, description, icon, and so on.
27+
* @description The update manifest call is used to update the app details such as name, description, icon, and so on.
2628
* @memberof App
2729
* @func update
2830
* @returns {Promise<App>}
@@ -35,7 +37,7 @@ export function App (http, data) {
3537
* description: 'APP_DESCRIPTION',
3638
* target_type: 'stack'/'organization',
3739
* }
38-
* const app = client.organization('organization_uid').app('app_uid')
40+
* const app = client.organization('organization_uid').app('manifest_uid')
3941
* app = Object.assign(app, updateApp)
4042
* app.update()
4143
* .then((app) => console.log(app))
@@ -44,7 +46,7 @@ export function App (http, data) {
4446
this.update = update(http, undefined, this.params)
4547

4648
/**
47-
* @description The get app details call is used to fetch details of a particular app with its ID.
49+
* @description The get manifest call is used to fetch details of a particular app with its ID.
4850
* @memberof App
4951
* @func fetch
5052
* @returns {Promise<App>}
@@ -53,14 +55,14 @@ export function App (http, data) {
5355
* import * as contentstack from '@contentstack/management'
5456
* const client = contentstack.client({ authtoken: 'TOKEN'})
5557
*
56-
* client.organization('organization_uid').app('app_uid').fetch()
58+
* client.organization('organization_uid').app('manifest_uid').fetch()
5759
* .then((app) => console.log(app))
5860
*
5961
*/
6062
this.fetch = fetch(http, 'data', this.params)
6163

6264
/**
63-
* @description The delete an app call is used to delete the app.
65+
* @description The delete manifest call is used to delete the app.
6466
* @memberof App
6567
* @func delete
6668
* @returns {Promise<Response>}
@@ -69,7 +71,7 @@ export function App (http, data) {
6971
* import * as contentstack from '@contentstack/management'
7072
* const client = contentstack.client({ authtoken: 'TOKEN'})
7173
*
72-
* client.organization('organization_uid').app('app_uid').delete()
74+
* client.organization('organization_uid').app('manifest_uid').delete()
7375
* .then((response) => console.log(response))
7476
*/
7577
this.delete = deleteEntity(http, false, this.params)
@@ -84,7 +86,7 @@ export function App (http, data) {
8486
* import * as contentstack from '@contentstack/management'
8587
* const client = contentstack.client({ authtoken: 'TOKEN'})
8688
*
87-
* client.organization('organization_uid').app('app_uid').fetchOAuth()
89+
* client.organization('organization_uid').app('manifest_uid').fetchOAuth()
8890
* .then((oAuthConfig) => console.log(oAuthConfig))
8991
*/
9092
this.fetchOAuth = async (param = {}) => {
@@ -127,7 +129,7 @@ export function App (http, data) {
127129
* scopes: ['scope1', 'scope2']
128130
* }
129131
* }
130-
* client.organization('organization_uid').app('app_uid').updateOAuth({ config })
132+
* client.organization('organization_uid').app('manifest_uid').updateOAuth({ config })
131133
* .then((oAuthConfig) => console.log(oAuthConfig))
132134
*/
133135
this.updateOAuth = async ({ config, param = {} }) => {
@@ -150,6 +152,22 @@ export function App (http, data) {
150152
}
151153
}
152154

155+
/**
156+
* @description The hosting will allow you get, update, deploy manifest.
157+
* @memberof App
158+
* @func updateOAuth
159+
* @returns {Promise<AppOAuth>}
160+
* @returns {Hosting}
161+
*
162+
* @example
163+
* import * as contentstack from '@contentstack/management'
164+
* const client = contentstack.client({ authtoken: 'TOKEN'})
165+
* client.organization('organization_uid').app('manifest_uid').hosting()
166+
*/
167+
this.hosting = () => {
168+
return new Hosting(http, { app_uid: this.uid }, this.params)
169+
}
170+
153171
/**
154172
* @description The install call is used to initiate the installation of the app
155173
* @memberof App
@@ -161,7 +179,7 @@ export function App (http, data) {
161179
* @example
162180
* import * as contentstack from '@contentstack/management'
163181
* const client = contentstack.client({ authtoken: 'TOKEN'})
164-
* client.organization('organization_uid').app('app_uid').install({ targetUid: 'STACK_API_KEY', targetType: 'stack' })
182+
* client.organization('organization_uid').app('manifest_uid').install({ targetUid: 'STACK_API_KEY', targetType: 'stack' })
165183
* .then((installation) => console.log(installation))
166184
*/
167185
this.install = async ({ targetUid, targetType }) => {
@@ -191,21 +209,21 @@ export function App (http, data) {
191209
* @example
192210
* import * as contentstack from '@contentstack/management'
193211
* const client = contentstack.client({ authtoken: 'TOKEN'})
194-
* client.organization('organization_uid').app('app_uid').installation().findAll()
212+
* client.organization('organization_uid').app('manifest_uid').installation().findAll()
195213
* .then((installations) => console.log(installations))
196214
*
197215
* @example
198216
* import * as contentstack from '@contentstack/management'
199217
* const client = contentstack.client({ authtoken: 'TOKEN'})
200-
* client.organization('organization_uid').app('app_uid').installation('installation_uid').fetch()
218+
* client.organization('organization_uid').app('manifest_uid').installation('installation_uid').fetch()
201219
* .then((installation) => console.log(installation))
202220
*/
203221
this.installation = (uid = null) => {
204222
return new Installation(http, uid ? { data: { uid } } : { app_uid: this.uid }, this.params)
205223
}
206224
} else {
207225
/**
208-
* @description The create an app call is used for creating a new app in your Contentstack organization.
226+
* @description The create manifest call is used for creating a new app/manifest in your Contentstack organization.
209227
* @memberof App
210228
* @func create
211229
* @returns {Promise<App>}
@@ -236,7 +254,7 @@ export function App (http, data) {
236254
this.create = create({ http, params: this.params })
237255

238256
/**
239-
* @description The get all apps call is used to fetch all the apps in your Contentstack organization.
257+
* @description The get all manifest call is used to fetch all the apps in your Contentstack organization.
240258
* @memberof App
241259
* @func findAll
242260
* @returns {Promise<ContentstackCollection<App>>}

lib/contentstackClient.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export default function contentstackClient ({ http }) {
2626
*
2727
*/
2828
function login (requestBody, params = {}) {
29+
http.defaults.versioningStrategy = 'path'
30+
2931
return http.post('/user-session', { user: requestBody }, { params: params })
3032
.then((response) => {
3133
if (response.data.user != null && response.data.user.authtoken != null) {
@@ -51,6 +53,7 @@ export default function contentstackClient ({ http }) {
5153
*
5254
*/
5355
function getUser (params = {}) {
56+
http.defaults.versioningStrategy = 'path'
5457
return http.get('/user', { params: params })
5558
.then((response) => {
5659
return new User(http, response.data)
@@ -94,6 +97,7 @@ export default function contentstackClient ({ http }) {
9497
* .then((stack) => console.log(stack))
9598
*/
9699
function stack (params = {}) {
100+
http.defaults.versioningStrategy = 'path'
97101
const stack = { ...cloneDeep(params) }
98102
return new Stack(http, { stack })
99103
}
@@ -121,6 +125,7 @@ export default function contentstackClient ({ http }) {
121125
*
122126
*/
123127
function organization (uid = null) {
128+
http.defaults.versioningStrategy = 'path'
124129
return new Organization(http, uid !== null ? { organization: { uid: uid } } : null)
125130
}
126131

@@ -144,6 +149,7 @@ export default function contentstackClient ({ http }) {
144149
* .then((response) => console.log(response))
145150
* */
146151
function logout (authtoken) {
152+
http.defaults.versioningStrategy = 'path'
147153
if (authtoken !== undefined) {
148154
return http.delete('/user-session', {
149155
headers: {

lib/organization/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export function Organization (http, data) {
205205
* @description Market place application information
206206
* @memberof Organization
207207
* @func app
208-
* @param {String} uid: App uid.
208+
* @param {String} uid: The ID of the app that you want to fetch details of.
209209
* @returns {App} Instance of App
210210
*
211211
* @example

0 commit comments

Comments
 (0)