Skip to content

Commit

Permalink
Merge pull request #75 from contentstack/next
Browse files Browse the repository at this point in the history
Master Merge: fix: users, collection, other fixes, coverage improvements
  • Loading branch information
nadeem-cs authored Aug 1, 2023
2 parents 86d65bc + 42c6432 commit 06c5ff8
Show file tree
Hide file tree
Showing 32 changed files with 7,189 additions and 10,463 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/secrets-scan.yml

This file was deleted.

4 changes: 3 additions & 1 deletion .jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"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 @@ -35,7 +37,7 @@
"excludePattern": "(node_modules/|jsdocs)"
},
"opts": {
"template": "docdash-template",
"template": "./node_modules/docdash",
"destination": "./jsdocs/",
"encoding": "utf8",
"private": true,
Expand Down
6 changes: 5 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
threshold: medium
threshold: medium
fileignoreconfig:
- filename: package-lock.json
checksum: 87a65198a53dfe59b81776d26882e419edaeb321003b2d03c06d396a8c673038
version: ""
33 changes: 32 additions & 1 deletion lib/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import error from '../core/contentstackError'
import { create, deleteEntity, fetch, fetchAll, update } from '../entity'
import { Authorization } from './authorization'
import { Hosting } from './hosting'
import { Installation } from './installation'
import { Installation, InstallationCollection } from './installation'
import ContentstackCollection from '../contentstackCollection'

export function App (http, data) {
http.defaults.versioningStrategy = undefined
Expand Down Expand Up @@ -310,6 +311,36 @@ 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
26 changes: 13 additions & 13 deletions lib/app/installation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ export function Installation (http, data, params = {}) {
}
}
/**
* @description To update server side organization level config required for the app.
* @memberof Installation
* @func setServerConfig
* @param {*} config Config that needs to be updated
* @returns {Promise<Response>}
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ authtoken: 'TOKEN'})
*
* client.organization('organization_uid').app('app_uid').installation('installation_uid').setServerConfig({<configuration_details>})
* .then((response) => console.log(response))
*/
* @description To update server side organization level config required for the app.
* @memberof Installation
* @func setServerConfig
* @param {*} config Config that needs to be updated
* @returns {Promise<Response>}
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client({ authtoken: 'TOKEN'})
*
* client.organization('organization_uid').app('app_uid').installation('installation_uid').setServerConfig({<configuration_details>})
* .then((response) => console.log(response))
*/
this.setServerConfig = async (config) => {
try {
const headers = {
Expand Down
23 changes: 0 additions & 23 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,6 @@ export const create = ({ http, params }) => {
}
}

export const exportObject = ({ http }) => {
return async function (param) {
const headers = {
params: {
...cloneDeep(param)
},
headers: {
...cloneDeep(this.stackHeaders)
}
} || {}
try {
const response = await http.get(this.urlPath, headers)
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid))
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}
}

export const query = ({ http, wrapperCollection }) => {
return function (params = {}) {
const headers = {
Expand Down
75 changes: 75 additions & 0 deletions lib/stack/auditlog/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import cloneDeep from 'lodash/cloneDeep'
import error from '../../core/contentstackError'
import { fetchAll, parseData } from '../../entity'

/**
*
* @namespace AuditLog
*/
export function AuditLog (http, data = {}) {
this.stackHeaders = data.stackHeaders
this.urlPath = `/audit-logs`
if (data.logs) {
Object.assign(this, cloneDeep(data.logs))
this.urlPath = `/audit-logs/${this.uid}`

/**
* @description The fetch AuditLog call fetches AuditLog details.
* @memberof AuditLog
* @func fetch
* @returns {Promise<Branch.Branch>} Promise for Branch instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).auditLog('audit_log_item_uid').fetch()
* .then((log) => console.log(log))
*
*/
this.fetch = async function (param = {}) {
try {
const headers = {
headers: { ...cloneDeep(this.stackHeaders) },
params: {
...cloneDeep(param)
}
} || {}
const response = await http.get(this.urlPath, headers)
if (response.data) {
return new AuditLog(http, parseData(response, this.stackHeaders))
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}
} else {
/**
* @description The Get all AuditLog request retrieves the details of all the Branch of a stack.
* @memberof AuditLog
* @func fetchAll
* @param {Int} limit The limit parameter will return a specific number of Branch in the output.
* @param {Int} skip The skip parameter will skip a specific number of Branch in the output.
* @param {Boolean}include_count To retrieve the count of Branch.
* @returns {ContentstackCollection} Result collection of content of specified module.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).auditLog().fetchAll()
* .then((logs) => console.log(logs))
*
*/
this.fetchAll = fetchAll(http, LogCollection)
}
return this
}

export function LogCollection (http, data) {
const obj = cloneDeep(data.logs) || []
const logCollection = obj.map((userdata) => {
return new AuditLog(http, { logs: userdata, stackHeaders: data.stackHeaders })
})
return logCollection
}
85 changes: 68 additions & 17 deletions lib/stack/bulkOperation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ export function BulkOperation (http, data = {}) {
* // Bulk nested publish
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* {
* environments:["{{env_uid}}","{{env_uid}}"],
* locales:["en-us"],
* items:[
* {
* _content_type_uid: '{{content_type_uid}}',
* uid: '{{entry_uid}}'
* },
* {
* _content_type_uid: '{{content_type_uid}}',
* uid: '{{entry_uid}}'
* },
* {
* _content_type_uid: '{{content_type_uid}}',
* uid: '{{entry_uid}}'
* }
* ]
* const publishDetails = {
* environments:["{{env_uid}}","{{env_uid}}"],
* locales:["en-us"],
* entries:[
* {
* _content_type_uid: '{{content_type_uid}}',
* uid: '{{entry_uid}}'
* },
* {
* _content_type_uid: '{{content_type_uid}}',
* uid: '{{entry_uid}}'
* },
* {
* _content_type_uid: '{{content_type_uid}}',
* uid: '{{entry_uid}}'
* }
* ]
* }
* client.stack({ api_key: 'api_key'}).bulkOperation().publish({ details: publishDetails, is_nested: true })
* .then((response) => { console.log(response.notice) })
Expand Down Expand Up @@ -220,4 +220,55 @@ export function BulkOperation (http, data = {}) {
}
return publishUnpublish(http, '/bulk/delete', httpBody, headers)
}

/**
* The Delete entries and assets in bulk request allows you to delete multiple entries and assets at the same time.
* @memberof BulkOperation
* @func update
* @returns {Promise<String>} Success message
* @param {Boolean} updateBody - Set this with details specifing the content type UIDs, entry UIDs or asset UIDs, and locales of which the entries or assets you want to update.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* const updateBody = {
* "entries": [{
* "content_type": "content_type_uid1",
* "uid": "entry_uid",
* "locale": "en-us"
* }, {
* "content_type": "content_type_uid2",
* "uid": "entry_uid",
* "locale": "en-us"
* }],
* "workflow": {
* "workflow_stage": {
* "comment": "Workflow-related Comments",
* "due_date": "Thu Dec 01 2018",
* "notify": false,
* "uid": "workflow_stage_uid",
* "assigned_to": [{
* "uid": "user_uid",
* "name": "user_name",
* "email": "user_email_id"
* }],
* "assigned_by_roles": [{
* "uid": "role_uid",
* "name": "role_name"
* }]
* }
* }
* }
* client.stack({ api_key: 'api_key'}).bulkOperation().update(updateBody)
* .then((response) => { console.log(response.notice) })
*
*/
this.update = async (updateBody = {}) => {
const headers = {
headers: {
...cloneDeep(this.stackHeaders)
}
}
return publishUnpublish(http, '/bulk/workflow', updateBody, headers)
}
}
Loading

0 comments on commit 06c5ff8

Please sign in to comment.