Skip to content

Commit b8013ac

Browse files
authored
Merge pull request #42 from contentstack/feature/marketplace-api
Feature marketplace API [CS-34240]
2 parents d909a3f + b1aadcc commit b8013ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2691
-100
lines changed

.eslintrc.js

+23-23
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+
}

.github/workflows/unit-test.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Unit Test & Reports
2+
on:
3+
pull_request:
4+
push:
5+
jobs:
6+
build-test:
7+
name: Build & Test
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2 # checkout the repo
11+
- uses: actions/setup-node@v3
12+
with:
13+
node-version: '12.x'
14+
registry-url: 'https://registry.npmjs.org'
15+
- run: npm ci # install packages
16+
- run: npm run test:unit:report:json # run tests (configured to use jest-junit reporter)
17+
- name: Test Report
18+
uses: dorny/test-reporter@v1
19+
if: success() || failure() # run this step even if previous step failed
20+
with:
21+
name: Mocha Unit test # Name of the check run which will be created
22+
path: report.json # Path to test results
23+
reporter: mocha-json # Format of test results
24+
- name: Coverage report
25+
uses: lucassabreu/comment-coverage-clover@main
26+
with:
27+
name: Unit test Coverage report
28+
file: coverage/clover.xml

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jspm_packages/
3939
mochawesome-report/
4040
coverage/
4141
test/utility/dataFiles/
42+
report.json
4243

4344
# TypeScript v1 declaration files
4445
typings/

CHANGELOG.md

+24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
# Changelog
22

3+
## [v1.7.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.7.0) (2023-04-04)
4+
- Feature
5+
- Marketplace API support added.
6+
## [v1.6.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.6.1) (2022-12-09)
7+
- Bug Fix
8+
- SSO get stack details Latest
9+
10+
## [v1.6.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.6.0) (2022-10-19)
11+
- Feature
12+
- OAuth token refresh function added
13+
14+
## [v1.5.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.5.0) (2022-08-10)
15+
- Feature
16+
- App creation, fetch and update
17+
- App configuration
18+
- App Installation and getting installation details
19+
20+
## [v1.4.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.4.0) (2022-07-26)
21+
- Bug Fix
22+
- Delete: Set entry workflow and asset download
23+
- Asset Download
24+
- Set Entry workflow stages
25+
- OAuth token authorisation
26+
327
## [v1.2.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.2.4) (2021-07-19)
428
- Bug Fix
529
- Form data upload timeout on retrying rate limit error issue resolved

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2012-2022 Contentstack
3+
Copyright (c) 2012-2023 Contentstack
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

lib/app/authorization/index.js

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import cloneDeep from 'lodash/cloneDeep'
2+
import error from '../../core/contentstackError'
3+
4+
export function Authorization (http, data, params) {
5+
http.defaults.versioningStrategy = undefined
6+
this.params = params || {}
7+
if (data) {
8+
if (data.organization_uid) {
9+
this.params = {
10+
organization_uid: data.organization_uid
11+
}
12+
}
13+
if (data.app_uid) {
14+
this.urlPath = `/manifests/${data.app_uid}/authorizations`
15+
/**
16+
* @description List all user authorizations made to an authorized app under a particular organization
17+
* @memberof Authorization
18+
* @func findAll
19+
* @returns {Promise<Response>}
20+
*
21+
* @example
22+
* import * as contentstack from '@contentstack/management'
23+
* const client = contentstack.client({ authtoken: 'TOKEN'})
24+
*
25+
* client.organization('organization_uid').app('manifest_uid').authorization().findAll()
26+
* .then((response) => console.log(response))
27+
*/
28+
this.findAll = async (param = {}) => {
29+
try {
30+
const headers = {
31+
headers: { ...cloneDeep(this.params) },
32+
params: {
33+
...cloneDeep(param)
34+
}
35+
}
36+
37+
const response = await http.get(this.urlPath, headers)
38+
if (response.data) {
39+
return response.data
40+
} else {
41+
throw error(response)
42+
}
43+
} catch (err) {
44+
throw error(err)
45+
}
46+
}
47+
/**
48+
* @description Revoke all users tokens issued to an authorized app for the particular organization
49+
* @memberof Authorization
50+
* @func revokeAll
51+
* @returns {Promise<Response>}
52+
*
53+
* @example
54+
* import * as contentstack from '@contentstack/management'
55+
* const client = contentstack.client({ authtoken: 'TOKEN'})
56+
*
57+
* client.organization('organization_uid').app('manifest_uid').authorization().revokeAll()
58+
* .then((response) => console.log(response))
59+
*/
60+
this.revokeAll = async () => {
61+
try {
62+
const headers = {
63+
headers: { ...cloneDeep(this.params) }
64+
}
65+
66+
const response = await http.delete(this.urlPath, headers)
67+
if (response.data) {
68+
return response.data
69+
} else {
70+
throw error(response)
71+
}
72+
} catch (err) {
73+
throw error(err)
74+
}
75+
}
76+
/**
77+
* @description Revoke user token issued to an authorized app for the particular organization
78+
* @memberof Authorization
79+
* @func revoke
80+
* @returns {Promise<Response>}
81+
*
82+
* @example
83+
* import * as contentstack from '@contentstack/management'
84+
* const client = contentstack.client({ authtoken: 'TOKEN'})
85+
*
86+
* client.organization('organization_uid').app('manifest_uid').authorization().revoke('authorization_uid')
87+
* .then((response) => console.log(response))
88+
*/
89+
this.revoke = async (authorizationUid) => {
90+
try {
91+
const headers = {
92+
headers: { ...cloneDeep(this.params) }
93+
}
94+
95+
const response = await http.delete(`${this.urlPath}/${authorizationUid}`, headers)
96+
if (response.data) {
97+
return response.data
98+
} else {
99+
throw error(response)
100+
}
101+
} catch (err) {
102+
throw error(err)
103+
}
104+
}
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)