Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dba8f48
feat: :sparkles: teams implementation with unit and api tests
harshithad0703 Oct 27, 2023
393d8c0
docs: added teams documentation
harshithad0703 Nov 1, 2023
c575b4b
test: :white_check_mark: updated api and unit test cases for teams su…
harshithad0703 Nov 1, 2023
797ba45
feat: :sparkles: teams users implementation and api test cases
harshithad0703 Nov 1, 2023
fec3852
test: :white_check_mark: added unit test cases for team users
harshithad0703 Nov 2, 2023
99fc8c1
feat: :sparkles: stackrolemapping implementation and api test cases
harshithad0703 Nov 6, 2023
c8425fb
test: changes made in update implementation and its test case
harshithad0703 Nov 6, 2023
cd9dea7
test: update stackrolemapping implementation and api test cases
harshithad0703 Nov 6, 2023
864db84
added assertions to check the response
harshithad0703 Nov 7, 2023
231711f
added unit test cases for stack role mapping
harshithad0703 Nov 7, 2023
4fcf217
replaced query with fetchAll function
harshithad0703 Nov 7, 2023
95d5f86
changing folder name to be same as class name
harshithad0703 Nov 7, 2023
59827bf
ci: :green_heart: fix unit test github action
nadeem-cs Nov 7, 2023
e79409f
ci: fix unit test github action
nadeem-cs Nov 7, 2023
83c136c
feat: types support for teams
harshithad0703 Nov 7, 2023
e66b74e
chore: :arrow_up: update axios lib
nadeem-cs Nov 7, 2023
9e59400
added valid assertions for the test
harshithad0703 Nov 7, 2023
46c0976
teams test cases for types support
harshithad0703 Nov 7, 2023
e5b0807
types support for team Users and api test cases
harshithad0703 Nov 9, 2023
e85be9f
interface changed from User to TeamUser in types
harshithad0703 Nov 9, 2023
0aa565d
types support for stackRoleMapping and test cases
harshithad0703 Nov 9, 2023
8098385
stackRoleMapping test cases in types support
harshithad0703 Nov 10, 2023
a582e8a
stackRoleMapping update test case on types support
harshithad0703 Nov 10, 2023
322f9af
Merge pull request #91 from contentstack/feat/cs-42021-teams-support-…
harshithad0703 Nov 10, 2023
05b005f
Merge branch 'master' into next
harshithad0703 Nov 10, 2023
a3ec18a
docs: :memo: updated version and changeLog
harshithad0703 Nov 10, 2023
9344c09
test: added test cases to improve coverage report
harshithad0703 Nov 10, 2023
9ecb16f
feat: :sparkles: early access headers implementation
harshithad0703 Nov 16, 2023
3d0c78a
Merge pull request #94 from contentstack/feat/early-access-headers
harshithad0703 Nov 16, 2023
2b04ac2
types support for earlyaccess and update changeLog
harshithad0703 Nov 16, 2023
83b90aa
fix: :bug: early_access made optional
nadeem-cs Nov 16, 2023
496735a
fix: :bug: added api_version param which is to be passed in headers
harshithad0703 Nov 20, 2023
78a3c18
test: :white_check_mark: updated response fetchAll unit test case
harshithad0703 Nov 20, 2023
5cdd59d
fix: :bug: create function response data update
harshithad0703 Nov 20, 2023
5251aef
refactor: :recycle: changes users in teams to teamUsers
harshithad0703 Nov 20, 2023
53d7458
Merge pull request #95 from contentstack/fix/api-version-bug-fix
harshithad0703 Nov 20, 2023
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
8 changes: 5 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: Unit Test & Reports
on:
pull_request:
push:
branches:
- master
- main
- next
jobs:
build-test:
name: Build & Test
Expand All @@ -23,6 +26,5 @@ jobs:
reporter: mocha-json # Format of test results
- name: Coverage report
uses: lucassabreu/comment-coverage-clover@main
with:
name: Unit test Coverage report
with:
file: coverage/clover.xml
6 changes: 4 additions & 2 deletions .jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
"lib/stack/roles/index.js",
"lib/stack/webhook/index.js",
"lib/stack/workflow/index.js",
"lib/stack/workflow/publishRules/index.js"

"lib/stack/workflow/publishRules/index.js",
"lib/organization/teams/index.js",
"lib/organization/teams/stackRoleMappings/index.js",
"lib/organization/teams/teamUsers/index.js"
],
"excludePattern": "(node_modules/|jsdocs)"
},
Expand Down
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threshold: medium
fileignoreconfig:
- filename: package-lock.json
checksum: ef5d374553f431b5a952069f46184ec7e49efd7d72143e1a1642994758db4359
checksum: 9a7bec9513834a0fc7db31b9a312ec35980600415c04f0d404e1370cfce1ef1b
version: ""
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [v1.13.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.0) (2023-11-21)
- Feature
- Teams API support
- Early Access Header support
## [v1.12.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.12.0) (2023-10-17)
- Feature
- Types support for Taxonomy feature
Expand Down
8 changes: 8 additions & 0 deletions lib/contentstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ import httpClient from './core/contentstackHTTPClient.js'
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ authtoken: 'value' })
*
* @prop {string=} params.early_access - Optional early_access is a token used for early access of new features in CMA requests.
* @example //Set the `early_access`
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ early_access: ['ea1', 'ea2'] })
*
* @prop {string=} params.authorization - Optional authorization token is a read-write token used to make authorized CMA requests, but it is a user-specific token.
* @example //Set the `authorization`
* import * as contentstack from '@contentstack/management'
Expand Down Expand Up @@ -177,6 +182,9 @@ export function client (params = {}) {
if (params.authorization) {
requiredHeaders.authorization = params.authorization
}
if (params.early_access) {
requiredHeaders.early_access = params.early_access.join(',')
}
params = {
...defaultParameter,
...clonedeep(params)
Expand Down
4 changes: 4 additions & 0 deletions lib/core/contentstackHTTPClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export default function contentstackHttpClient (options) {
config.headers['accessToken'] = config.accessToken
}

if (config.early_access) {
config.headers['x-header-ea'] = config.early_access
}

const protocol = config.insecure ? 'http' : 'https'
let hostname = config.defaultHostName
let port = config.port || 443
Expand Down
11 changes: 9 additions & 2 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ export const create = ({ http, params }) => {
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
} else {
throw error(response)
if (response.status >= 200 && response.status < 300) {
return {
status: response.status,
statusText: response.statusText
}
} else {
throw error(response)
}
}
} catch (err) {
throw error(err)
Expand Down Expand Up @@ -301,4 +308,4 @@ export const move = (http, type, force = false, params = {}) => {
throw error(err)
}
}
}
}
21 changes: 21 additions & 0 deletions lib/organization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { StackCollection } from '../stack'
import { UserCollection } from '../user'
import { App } from '../app'
import { AppRequest } from '../app/request'
import { Teams } from './teams'
/**
* Organization is the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources, and users. Organization allows easy management of projects as well as users within the Organization. Read more about <a href='https://www.contentstack.com/docs/guide/organization'>Organizations.</a>.
* @namespace Organization
Expand All @@ -18,6 +19,26 @@ export function Organization (http, data) {
Object.assign(this, cloneDeep(data.organization))
this.urlPath = `/organizations/${this.uid}`

/**
* @description The teams call fetches teams details.
* @memberof Organization
* @func teams
* @returns {Promise<Organization.Organization>} Promise for Organization instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organization_uid').teams('teamsUid').fetch()
* .then((organization) => console.log(organization))
*
*/
this.teams = (teamUid = null) => {
data.organizationUid = this.uid
if (teamUid) {
data.uid = teamUid
}
return new Teams(http, data)
}
/**
* @description The fetch Organization call fetches Organization details.
* @memberof Organization
Expand Down
165 changes: 165 additions & 0 deletions lib/organization/teams/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import cloneDeep from 'lodash/cloneDeep'
import {
create,
fetch,
deleteEntity,
fetchAll
} from '../../entity'
import { TeamUsers } from './teamUsers'
import { StackRoleMappings } from './stackRoleMappings'
import error from '../../core/contentstackError'

export function Teams (http, data) {
this.organizationUid = data.organizationUid
this.urlPath = `/organizations/${this.organizationUid}/teams`
if (data && data.uid) {
Object.assign(this, cloneDeep(data))

this.urlPath = `/organizations/${this.organizationUid}/teams/${this.uid}`

/**
* @description The update call on team will allow to update details of team.
* @memberof Teams
* @func update
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const updateData = {
* name: 'updatedname',
* users: [
* {
* email: '[email protected]'
* }
* ],
* organizationRole: 'blt09e5dfced326aaea',
* stackRoleMapping: []
* }
* client.organization(s'organizationUid').teams('teamUid').update(updateData)
* .then((response) => console.log(response))
*
*/
this.update = async (updateData) => {
try {
const response = await http.put(this.urlPath, updateData)
if (response.data) {
return response.data
}
} catch (err) {
throw error(err)
}
}

/**
* @description The delete call on team will delete the existing team.
* @memberof Teams
* @func delete
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.organization('organizationUid').teams('teamUid').delete()
* .then((response) => console.log(response))
*
*/
this.delete = deleteEntity(http)

/**
* @description The fetch call on team will delete the existing team.
* @memberof Teams
* @func fetch
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.organization('organizationUid').teams('teamUid').fetch()
* .then((response) => console.log(response))
*
*/
this.fetch = fetch(http, 'team')

/**
* @description The users call on team will get users details.
* @memberof Teams
* @func users
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.organization('organizationUid').teams('teamUid').teamUsers().fetchAll()
* .then((response) => console.log(response))
*
*/
this.teamUsers = (userId = null) => {
data.organizationUid = this.organizationUid
data.teamUid = this.uid
if (userId) {
data.userId = userId
}
return new TeamUsers(http, data)
}

/**
* @description The stackRoleMappings call on team will get the stack role Mapping.
* @memberof Teams
* @func users
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().fetchAll()
* .then((response) => console.log(response))
*
*/
this.stackRoleMappings = (stackApiKey = null) => {
data.organizationUid = this.organizationUid
data.teamUid = this.uid
if (stackApiKey) {
data.stackApiKey = stackApiKey
}
return new StackRoleMappings(http, data)
}
} else {
/**
* @description The fetch call on team will delete the existing team.
* @memberof Teams
* @func create
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const team = {
* name: 'name',
* organizationUid: 'organization_uid',
* users: [],
* stackRoleMapping: [],
* organizationRole: 'organizationRole'
* }
* client.organization('organizationUid').teams().create(team)
* .then((response) => console.log(response))
*
*/
this.create = create({ http })

/**
* @description The fetchAll on team will allow to fetch details of all teams.
* @memberof Teams
* @func fetchAll
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organizationUid').teams().fetchAll()
* .then((response) => console.log(response))
*/
this.fetchAll = fetchAll(http, TeamsCollection, { api_version: 1.1 })
}
}
export function TeamsCollection (http, teamsData) {
const obj = cloneDeep(teamsData.teams) || []
const teamsCollection = obj.map((team) => {
return new Teams(http, team)
})
return teamsCollection
}
Loading