diff --git a/lib/core/concurrency-queue.js b/lib/core/concurrency-queue.js index bef8d88d..2deeac7f 100644 --- a/lib/core/concurrency-queue.js +++ b/lib/core/concurrency-queue.js @@ -203,7 +203,7 @@ export function ConcurrencyQueue ({ axios, config }) { // Cool down the running requests delay(wait, response.status === 401) error.config.retryCount = networkError - + // deepcode ignore Ssrf: URL is dynamic return axios(updateRequestConfig(error, retryErrorType, wait)) } if (this.config.retryCondition && this.config.retryCondition(error)) { @@ -234,6 +234,7 @@ export function ConcurrencyQueue ({ axios, config }) { error.config.retryCount = retryCount return new Promise(function (resolve) { return setTimeout(function () { + // deepcode ignore Ssrf: URL is dynamic return resolve(axios(updateRequestConfig(error, retryErrorType, delaytime))) }, delaytime) }) diff --git a/lib/entity.js b/lib/entity.js index adfb2d49..32f7fbfe 100644 --- a/lib/entity.js +++ b/lib/entity.js @@ -118,7 +118,11 @@ export const exportObject = ({ http }) => { export const query = ({ http, wrapperCollection }) => { return function (params = {}) { + const headers = { + ...cloneDeep(this.stackHeaders) + } if (this.organization_uid) { + headers.organization_uid = this.organization_uid if (!params.query) { params.query = {} } @@ -128,7 +132,7 @@ export const query = ({ http, wrapperCollection }) => { if (this.content_type_uid) { params.content_type_uid = this.content_type_uid } - return Query(http, this.urlPath, params, this.stackHeaders, wrapperCollection) + return Query(http, this.urlPath, params, headers, wrapperCollection) } } @@ -212,6 +216,9 @@ export const fetch = (http, type, params = {}) => { ...cloneDeep(param) } } || {} + if (this.organization_uid) { + headers.headers.organization_uid = this.organization_uid + } const response = await http.get(this.urlPath, headers) if (response.data) { diff --git a/lib/organization/index.js b/lib/organization/index.js index 1c4a6e2d..00090b15 100644 --- a/lib/organization/index.js +++ b/lib/organization/index.js @@ -32,9 +32,7 @@ export function Organization (http, data) { * */ this.fetch = fetch(http, 'organization') - - if ((this.org_roles && (this.org_roles.filter(function (role) { return role.admin === true }).length > 0)) || (this.owner && this.owner === true) || (this.is_owner && this.is_owner === true)) { - /** + /** * @description The Get all stacks in an organization call fetches the list of all stacks in an Organization. * @memberof Organization * @func stacks @@ -53,20 +51,20 @@ export function Organization (http, data) { * .then((collection) => console.log(collection)) * */ - this.stacks = async (param) => { - try { - const response = await http.get(`${this.urlPath}/stacks`, { params: param }) - if (response.data) { - return new ContentstackCollection(response, http, null, StackCollection) - } else { - return error(response) - } - } catch (err) { - return error(err) + this.stacks = async (param) => { + try { + const response = await http.get(`${this.urlPath}/stacks`, { params: param }) + if (response.data) { + return new ContentstackCollection(response, http, null, StackCollection) + } else { + return error(response) } + } catch (err) { + return error(err) } + } - /** + /** * @description The Transfer organization ownership call transfers the ownership of an Organization to another user. * @memberof Organization * @func transferOwnership @@ -80,20 +78,20 @@ export function Organization (http, data) { * .then((response) => console.log(response.notice)) * */ - this.transferOwnership = async (email) => { - try { - const response = await http.post(`${this.urlPath}/transfer_ownership`, { transfer_to: email }) - if (response.data) { - return response.data - } else { - return error(response) - } - } catch (err) { - return error(err) + this.transferOwnership = async (email) => { + try { + const response = await http.post(`${this.urlPath}/transfer_ownership`, { transfer_to: email }) + if (response.data) { + return response.data + } else { + return error(response) } + } catch (err) { + return error(err) } + } - /** + /** * @description The Add users to organization call allows you to send invitations to add users to your organization. Only the owner or the admin of the organization can add users. * @memberof Organization * @func addUser @@ -106,20 +104,20 @@ export function Organization (http, data) { * .then((response) => console.log(response)) * */ - this.addUser = async (data) => { - try { - const response = await http.post(`${this.urlPath}/share`, { share: { ...data } }) - if (response.data) { - return new ContentstackCollection(response, http, null, UserCollection) - } else { - return error(response) - } - } catch (err) { - return error(err) + this.addUser = async (data) => { + try { + const response = await http.post(`${this.urlPath}/share`, { share: { ...data } }) + if (response.data) { + return new ContentstackCollection(response, http, null, UserCollection) + } else { + return error(response) } + } catch (err) { + return error(err) } + } - /** + /** * @description The Get all organization invitations call gives you a list of all the Organization invitations. * @memberof Organization * @func getInvitations @@ -132,20 +130,20 @@ export function Organization (http, data) { * .then((response) => console.log(response.notice)) * */ - this.getInvitations = async (param) => { - try { - const response = await http.get(`${this.urlPath}/share`, { params: param }) - if (response.data) { - return new ContentstackCollection(response, http, null, UserCollection) - } else { - return error(response) - } - } catch (err) { - return error(err) + this.getInvitations = async (param) => { + try { + const response = await http.get(`${this.urlPath}/share`, { params: param }) + if (response.data) { + return new ContentstackCollection(response, http, null, UserCollection) + } else { + return error(response) } + } catch (err) { + return error(err) } + } - /** + /** * @description The Resend pending organization invitation call allows you to resend Organization invitations to users who have not yet accepted the earlier invitation. * @memberof Organization * @func resendInvitition @@ -158,20 +156,20 @@ export function Organization (http, data) { * .then((response) => console.log(response.notice)) * */ - this.resendInvitation = async (invitationUid) => { - try { - const response = await http.get(`${this.urlPath}/${invitationUid}/resend_invitation`) - if (response.data) { - return response.data - } else { - return error(response) - } - } catch (err) { - return error(err) + this.resendInvitation = async (invitationUid) => { + try { + const response = await http.get(`${this.urlPath}/${invitationUid}/resend_invitation`) + if (response.data) { + return response.data + } else { + return error(response) } + } catch (err) { + return error(err) } + } - /** + /** * @description A role is a collection of permissions that will be applicable to all the users who are assigned this role. * @memberof Organization * @func roles @@ -190,19 +188,19 @@ export function Organization (http, data) { * .then((roles) => console.log(roles)) * */ - this.roles = async (param) => { - try { - const response = await http.get(`${this.urlPath}/roles`, { params: param }) - if (response.data) { - return new ContentstackCollection(response, http, null, RoleCollection) - } else { - return error(response) - } - } catch (err) { - return error(err) + this.roles = async (param) => { + try { + const response = await http.get(`${this.urlPath}/roles`, { params: param }) + if (response.data) { + return new ContentstackCollection(response, http, null, RoleCollection) + } else { + return error(response) } + } catch (err) { + return error(err) } } + /** * @description Market place application information * @memberof Organization @@ -229,7 +227,7 @@ export function Organization (http, data) { * @param {Int} skip The ‘skip’ parameter will skip a specific number of organizations in the output. * @param {String} asc The ‘asc’ parameter allows you to sort the list of organizations in the ascending order with respect to the value of a specific field. * @param {String} desc The ‘desc’ parameter allows you to sort the list of Organizations in the descending order with respect to the value of a specific field. - * @param {Boolean}include_count The ‘include_count’ parameter returns the total number of organizations related to the user. + * @param {Boolean}include_count The ‘include_count’ parameter returns the total number of organizations related to the user. * @param {String} typeahead The typeahead parameter is a type of filter that allows you to perform a name-based search on all organizations based on the value provided. * @returns {ContentstackCollection} Result collection of content of specified module. * @example diff --git a/lib/stack/branch/index.js b/lib/stack/branch/index.js index b9e3dd70..127832d0 100644 --- a/lib/stack/branch/index.js +++ b/lib/stack/branch/index.js @@ -44,7 +44,6 @@ export function Branch (http, data = {}) { * */ this.fetch = fetch(http, 'branch') - } else { /** * @description The Create a Branch call creates a new branch in a particular stack of your Contentstack account. diff --git a/lib/stack/index.js b/lib/stack/index.js index 7f55f5d1..5ffa4799 100644 --- a/lib/stack/index.js +++ b/lib/stack/index.js @@ -277,7 +277,6 @@ export function Stack (http, data) { return new Extension(http, data) } - /** * @description Workflow is a tool that allows you to streamline the process of content creation and publishing, and lets you manage the content lifecycle of your project smoothly. * @param {String} workflowUid The UID of the Workflow you want to get details. @@ -435,7 +434,7 @@ export function Stack (http, data) { } /** - * @description The Update User Role API Request updates the roles of an existing user account. + * @description The Update User Role API Request updates the roles of an existing user account. * This API Request will override the existing roles assigned to a user * @memberof Stack * @func updateUsersRoles @@ -447,20 +446,20 @@ export function Stack (http, data) { * const users = { * user_uid: ['role_uid_1', 'role_uid_2' ] * } - * + * * client.stack({ api_key: 'api_key'}).updateUsersRoles(users) * .then((response) => console.log(response.notice)) * */ this.updateUsersRoles = async (users) => { try { - const response = await http.post(`${this.urlPath}/users/roles`, + const response = await http.post(`${this.urlPath}/users/roles`, { users }, { - headers: { - ...cloneDeep(this.stackHeaders) - } - }) + headers: { + ...cloneDeep(this.stackHeaders) + } + }) if (response.data) { return UserCollection(http, response.data.stack) } else { diff --git a/package-lock.json b/package-lock.json index 8b3af747..6e73e780 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.6.0", + "version": "1.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -4364,9 +4364,9 @@ } }, "loader-utils": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.2.tgz", - "integrity": "sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz", + "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==", "dev": true, "requires": { "big.js": "^5.2.2", @@ -8974,9 +8974,9 @@ "dev": true }, "loader-utils": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz", - "integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.2.tgz", + "integrity": "sha512-I5d00Pd/jwMD2QCduo657+YM/6L3KZu++pmX9VFncxaxvHcru9jx1lBaFft+r4Mt2jK0Yhp41XlRAihzPxHNCg==", "dev": true, "requires": { "big.js": "^5.2.2", @@ -9252,9 +9252,9 @@ "dev": true }, "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, "requires": { "brace-expansion": "^1.1.7" diff --git a/package.json b/package.json index d6debefc..2b4617d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.6.0", + "version": "1.6.1", "description": "The Content Management API is used to manage the content of your Contentstack account", "main": "./dist/node/contentstack-management.js", "browser": "./dist/web/contentstack-management.js", diff --git a/test/unit/organization-test.js b/test/unit/organization-test.js index 207961d7..1276b23b 100644 --- a/test/unit/organization-test.js +++ b/test/unit/organization-test.js @@ -30,12 +30,12 @@ describe('Organization Test', () => { } }) expect(organization.fetchAll).to.be.equal(undefined) expect(organization.fetch).to.not.equal(undefined) - expect(organization.stacks).to.be.equal(undefined) - expect(organization.transferOwnership).to.be.equal(undefined) - expect(organization.addUser).to.be.equal(undefined) - expect(organization.getInvitations).to.be.equal(undefined) - expect(organization.resendInvitation).to.be.equal(undefined) - expect(organization.roles).to.be.equal(undefined) + expect(organization.stacks).to.not.equal(undefined) + expect(organization.transferOwnership).to.not.equal(undefined) + expect(organization.addUser).to.not.equal(undefined) + expect(organization.getInvitations).to.not.equal(undefined) + expect(organization.resendInvitation).to.not.equal(undefined) + expect(organization.roles).to.not.equal(undefined) done() }) @@ -255,12 +255,12 @@ function makeOrganization (params = {}) { function checknonAdminFunction (organization) { expect(organization.fetchAll).to.be.equal(undefined) expect(organization.fetch).to.not.equal(undefined) - expect(organization.stacks).to.be.equal(undefined) - expect(organization.transferOwnership).to.be.equal(undefined) - expect(organization.addUser).to.be.equal(undefined) - expect(organization.getInvitations).to.be.equal(undefined) - expect(organization.resendInvitation).to.be.equal(undefined) - expect(organization.roles).to.be.equal(undefined) + expect(organization.stacks).to.not.equal(undefined) + expect(organization.transferOwnership).to.not.equal(undefined) + expect(organization.addUser).to.not.equal(undefined) + expect(organization.getInvitations).to.not.equal(undefined) + expect(organization.resendInvitation).to.not.equal(undefined) + expect(organization.roles).to.not.equal(undefined) } function checkAdminFunction (organization) {