From 18b698f84ad89e4f3729839961526c5385bbbde0 Mon Sep 17 00:00:00 2001 From: Yann Jouanin Date: Tue, 18 Sep 2018 16:01:11 +0200 Subject: [PATCH 01/14] Add method for ServiceDesk (makeServiceDeskUri) and retreive getOrganizations, getOrganization, addUsersToOrganization --- src/jira.js | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/src/jira.js b/src/jira.js index 7d78710a..5089a935 100644 --- a/src/jira.js +++ b/src/jira.js @@ -21,7 +21,7 @@ export default class JiraApi { this.base = options.base || ''; this.intermediatePath = options.intermediatePath; this.strictSSL = options.hasOwnProperty('strictSSL') ? options.strictSSL : true; - // This is so we can fake during unit tests + // This is so we can fake during unit tests this.request = options.request || request; this.webhookVersion = options.webHookVersion || '1.0'; this.greenhopperVersion = options.greenhopperVersion || '1.0'; @@ -252,6 +252,25 @@ export default class JiraApi { return decodeURIComponent(uri); } + /** + * @name makeServiceDeskUri + * @function + * Creates a URI object for a given pathname + * @param {UriOptions} object + */ + makeServiceDeskUri(object) { + const intermediateToUse = this.intermediatePath || object.intermediatePath; + const tempPath = intermediateToUse || '/rest/servicedeskapi'; + const uri = url.format({ + protocol: this.protocol, + hostname: this.host, + port: this.port, + pathname: `${this.base}${tempPath}${object.pathname}`, + query: object.query, + }); + return decodeURIComponent(uri); + } + /** * @name doRequest * @function @@ -330,7 +349,7 @@ export default class JiraApi { }))); } -/** + /** * @name createProject * @function * Create a new Project @@ -774,7 +793,7 @@ export default class JiraApi { }))); } - /** Add an option for a select list issue field. + /** Add an option for a select list issue field. * [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#api/2/field/{fieldKey}/option-createOption) * @name createFieldOption * @function @@ -1521,4 +1540,64 @@ export default class JiraApi { }, }))); } + + /** Get Organizations + * [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-getOrganizations) + * @name getOrganization + * @function + * @param {number} [start=0] - The starting index of the returned versions. Base index: 0. + * @param {number} [limit=50] - The maximum number of versions to return per page. + * Default: 50. + */ + getOrganizations(start = 0, limit = 50) { + return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ + pathname: '/organization', + query: { + start, + limit, + }, + }), { + headers: { + 'X-ExperimentalApi': 'opt-in', + }, + })); + } + + /** Get Organization + * [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-getOrganization) + * @name getOrganization + * @function + * @param {string} organizationId - The organization indentifier. + */ + getOrganization(organizationId) { + return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ + pathname: `/organization/${organizationId}`, + }), { + headers: { + 'X-ExperimentalApi': 'opt-in', + }, + })); + } + + /** Add users to an Organization + * [Jira Doc] (https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-addUsersToOrganization) + * @name addUsersToOrganization + * @function + * @param {string} usernames - the list of usernames of users to add + * @param {string} organizationId - the id of the organization to them it to + */ + addUsersToOrganization(usernames, organizationId) { + return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ + pathname: `/organization/${organizationId}/user`, + }), { + method: 'POST', + followAllRedirects: true, + body: { + usernames: usernames, + }, + headers: { + 'X-ExperimentalApi': 'opt-in', + }, + })); + } } From e4e997ef8a7ffd75f2843fa713702cc1a9d34abc Mon Sep 17 00:00:00 2001 From: Yann Jouanin Date: Wed, 19 Sep 2018 11:16:02 +0200 Subject: [PATCH 02/14] Add method getUsersInOrganization from Service desk api --- src/jira.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/jira.js b/src/jira.js index 5089a935..75937f8b 100644 --- a/src/jira.js +++ b/src/jira.js @@ -1579,6 +1579,22 @@ export default class JiraApi { })); } + /** Get Users in an Organization + * [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-getUsersInOrganization) + * @name getUsersInOrganization + * @function + * @param {string} organizationId - The organization indentifier. + */ + getUsersInOrganization(organizationId) { + return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ + pathname: `/organization/${organizationId}/user`, + }), { + headers: { + 'X-ExperimentalApi': 'opt-in', + }, + })); + } + /** Add users to an Organization * [Jira Doc] (https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-addUsersToOrganization) * @name addUsersToOrganization From a425641c5b2fe47c77b9884a015606221c61f08a Mon Sep 17 00:00:00 2001 From: Yann Jouanin Date: Thu, 11 Oct 2018 16:17:59 +0200 Subject: [PATCH 03/14] Add method Add Organization --- src/jira.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/jira.js b/src/jira.js index 75937f8b..5190913a 100644 --- a/src/jira.js +++ b/src/jira.js @@ -1541,6 +1541,23 @@ export default class JiraApi { }))); } + /** Add an organization. + * [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-createOrganization) + * @name createOrganization + */ + createOrganization(name) { + return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ + pathname: `/organization`, + }), { + method: 'POST', + followAllRedirects: true, + body: {'name': name}, + headers: { + 'X-ExperimentalApi': 'opt-in' + } + })); + } + /** Get Organizations * [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-getOrganizations) * @name getOrganization From ec321962011f180ea289f573168ae15527f96547 Mon Sep 17 00:00:00 2001 From: Yann Jouanin Date: Thu, 17 Jan 2019 11:35:48 +0100 Subject: [PATCH 04/14] add removeUsersFromOrganization method --- src/jira.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/jira.js b/src/jira.js index 5190913a..e4a7aab7 100644 --- a/src/jira.js +++ b/src/jira.js @@ -1617,7 +1617,7 @@ export default class JiraApi { * @name addUsersToOrganization * @function * @param {string} usernames - the list of usernames of users to add - * @param {string} organizationId - the id of the organization to them it to + * @param {string} organizationId - the id of the organization to add them to */ addUsersToOrganization(usernames, organizationId) { return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ @@ -1633,4 +1633,26 @@ export default class JiraApi { }, })); } + + /** Remove users from an Organization + * [Jira Doc] (https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-removeUsersFromOrganization) + * @name aUsersToOrganization + * @function + * @param {string} usernames - the list of usernames of users to remove + * @param {string} organizationId - the id of the organization to remove them from + */ + removeUsersFromOrganization(usernames, organizationId) { + return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ + pathname: `/organization/${organizationId}/user`, + }), { + method: 'DELETE', + followAllRedirects: true, + body: { + usernames: usernames, + }, + headers: { + 'X-ExperimentalApi': 'opt-in', + }, + })); + } } From 383cc22b57bbf3dca4d37bb8410ea8864feb7bff Mon Sep 17 00:00:00 2001 From: Yann Jouanin Date: Thu, 17 Jan 2019 11:43:53 +0100 Subject: [PATCH 05/14] add deleteUser method --- src/jira.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/jira.js b/src/jira.js index e4a7aab7..2e301975 100644 --- a/src/jira.js +++ b/src/jira.js @@ -592,6 +592,22 @@ export default class JiraApi { })); } + /** Delete a Jira user + * [Jira Doc](https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-api-2-user-delete) + * @name deleteUser + * @function + * @param {object} user - an object containing user reference : accou + */ + deleteUser(accountId) { + return this.doRequest(this.makeRequestHeader(this.makeUri({ + pathname: '/user', + }), { + method: 'DELETE', + followAllRedirects: true, + query: {accountId: accountId}, + })); + } + /** Search user on Jira * [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#d2e3756) * @name searchUsers From 954db5018d960c17cd3a3fabd95863b9a0baf930 Mon Sep 17 00:00:00 2001 From: wbu Date: Mon, 21 Jan 2019 11:37:05 +0100 Subject: [PATCH 06/14] Add addOrganization route --- src/jira.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/jira.js b/src/jira.js index 2e301975..5ba1f4b6 100644 --- a/src/jira.js +++ b/src/jira.js @@ -1652,7 +1652,7 @@ export default class JiraApi { /** Remove users from an Organization * [Jira Doc] (https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-removeUsersFromOrganization) - * @name aUsersToOrganization + * @name removeUsersFromOrganization * @function * @param {string} usernames - the list of usernames of users to remove * @param {string} organizationId - the id of the organization to remove them from @@ -1671,4 +1671,26 @@ export default class JiraApi { }, })); } + + /** Adds an organization to a servicedesk for a given servicedesk id and organization id + * [Jira Doc] (https://docs.atlassian.com/jira-servicedesk/REST/3.15.0/#servicedeskapi/servicedesk/{serviceDeskId}/organization-addOrganization) + * @name addOrganization + * @function + * @param {string} serviceDeskId - the servicedesk in which to add the organization + * @param {string} organizationId - the id of the organization to remove them from + */ + addOrganization(serviceDeskId, organizationId) { + return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ + pathname: `/servicedesk/${serviceDeskId}/organization`, + }), { + method: 'POST', + followAllRedirects: true, + body: { + organizationId: organizationId, + }, + headers: { + 'X-ExperimentalApi': 'opt-in', + }, + })); + } } From 72b536077ace587ea8508d67ca1df38b21ed8ba0 Mon Sep 17 00:00:00 2001 From: dlb Date: Thu, 23 Jun 2022 11:45:16 +0000 Subject: [PATCH 07/14] Add update User method --- src/jira.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/jira.js b/src/jira.js index 4bd3a940..29fe6f32 100644 --- a/src/jira.js +++ b/src/jira.js @@ -711,6 +711,22 @@ export default class JiraApi { body: user, })); } + + /** Update a Jira user + * [Jira Doc](https://docs.atlassian.com/software/jira/docs/api/REST/latest/#user-updateUser) + * @name updateUser + * @function + * @param {object} user - Properly Formatted User object + */ + updateUser(user) { + return this.doRequest(this.makeRequestHeader(this.makeUri({ + pathname: '/user', + }), { + method: 'PUT', + followAllRedirects: true, + body: user, + })); + } /** Delete a Jira user * [Jira Doc](https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-api-2-user-delete) @@ -2145,7 +2161,7 @@ export default class JiraApi { }, })); } - + /** Get Filter * [Jira Doc](https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/filter) * @name getFilter From 0fa27bb06411cef9c8fc692f6f195babc96210c3 Mon Sep 17 00:00:00 2001 From: dlb Date: Tue, 28 Jun 2022 08:19:07 +0000 Subject: [PATCH 08/14] Add userkey in query params --- src/jira.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/jira.js b/src/jira.js index 29fe6f32..7ee00a8e 100644 --- a/src/jira.js +++ b/src/jira.js @@ -718,9 +718,12 @@ export default class JiraApi { * @function * @param {object} user - Properly Formatted User object */ - updateUser(user) { + updateUser(user, userKey) { return this.doRequest(this.makeRequestHeader(this.makeUri({ pathname: '/user', + query: { + userKey, + }, }), { method: 'PUT', followAllRedirects: true, From 4c1d1976be63007fee1fe2ed0068af9ca4991e9e Mon Sep 17 00:00:00 2001 From: dlb Date: Tue, 28 Jun 2022 08:22:30 +0000 Subject: [PATCH 09/14] Add userkey in query params --- src/jira.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/jira.js b/src/jira.js index 7ee00a8e..07d08bb3 100644 --- a/src/jira.js +++ b/src/jira.js @@ -718,12 +718,12 @@ export default class JiraApi { * @function * @param {object} user - Properly Formatted User object */ - updateUser(user, userKey) { + updateUser(user, key) { return this.doRequest(this.makeRequestHeader(this.makeUri({ pathname: '/user', - query: { - userKey, - }, + query: { + key, + }, }), { method: 'PUT', followAllRedirects: true, From 692ffb302967fb2d6e45b0b39e66c7b8fb8081f9 Mon Sep 17 00:00:00 2001 From: ake Date: Mon, 13 Nov 2023 16:56:22 +0100 Subject: [PATCH 10/14] Added optional parameters start and limit in getUsersInOrganization --- src/jira.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/jira.js b/src/jira.js index 07d08bb3..4e4fd95d 100644 --- a/src/jira.js +++ b/src/jira.js @@ -2133,9 +2133,13 @@ export default class JiraApi { * @function * @param {string} organizationId - The organization indentifier. */ - getUsersInOrganization(organizationId) { + getUsersInOrganization(organizationId, start = 0, limit = 50) { return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ pathname: `/organization/${organizationId}/user`, + query: { + start, + limit, + }, }), { headers: { 'X-ExperimentalApi': 'opt-in', From ae677ab35373d61487ed2c88311724cd674c045d Mon Sep 17 00:00:00 2001 From: ake Date: Mon, 13 Nov 2023 17:07:07 +0100 Subject: [PATCH 11/14] Fixed lint errors --- src/jira.js | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/jira.js b/src/jira.js index 4e4fd95d..e43ad938 100644 --- a/src/jira.js +++ b/src/jira.js @@ -711,25 +711,25 @@ export default class JiraApi { body: user, })); } - + /** Update a Jira user * [Jira Doc](https://docs.atlassian.com/software/jira/docs/api/REST/latest/#user-updateUser) * @name updateUser * @function * @param {object} user - Properly Formatted User object */ - updateUser(user, key) { - return this.doRequest(this.makeRequestHeader(this.makeUri({ - pathname: '/user', - query: { - key, - }, - }), { - method: 'PUT', - followAllRedirects: true, - body: user, - })); - } + updateUser(user, key) { + return this.doRequest(this.makeRequestHeader(this.makeUri({ + pathname: '/user', + query: { + key, + }, + }), { + method: 'PUT', + followAllRedirects: true, + body: user, + })); + } /** Delete a Jira user * [Jira Doc](https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-api-2-user-delete) @@ -743,7 +743,7 @@ export default class JiraApi { }), { method: 'DELETE', followAllRedirects: true, - query: {accountId: accountId}, + query: { accountId }, })); } @@ -2078,14 +2078,14 @@ export default class JiraApi { */ createOrganization(name) { return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ - pathname: `/organization`, + pathname: '/organization', }), { method: 'POST', followAllRedirects: true, - body: {'name': name}, + body: { name }, headers: { - 'X-ExperimentalApi': 'opt-in' - } + 'X-ExperimentalApi': 'opt-in', + }, })); } @@ -2132,6 +2132,9 @@ export default class JiraApi { * @name getUsersInOrganization * @function * @param {string} organizationId - The organization indentifier. + * @param {number} [start=0] - The starting index of the returned versions. Base index: 0. + * @param {number} [limit=50] - The maximum number of versions to return per page. + * Default: 50. */ getUsersInOrganization(organizationId, start = 0, limit = 50) { return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ @@ -2161,7 +2164,7 @@ export default class JiraApi { method: 'POST', followAllRedirects: true, body: { - usernames: usernames, + usernames, }, headers: { 'X-ExperimentalApi': 'opt-in', @@ -2276,7 +2279,7 @@ export default class JiraApi { method: 'DELETE', followAllRedirects: true, body: { - usernames: usernames, + usernames, }, headers: { 'X-ExperimentalApi': 'opt-in', @@ -2298,13 +2301,14 @@ export default class JiraApi { method: 'POST', followAllRedirects: true, body: { - organizationId: organizationId, + organizationId, }, headers: { 'X-ExperimentalApi': 'opt-in', }, })); } + /** Rank Epics * [Jira Doc](https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/epic-rankEpics) * @name rankEpics From 3ca7271a352b7b4b93d56d09ed295317eb647747 Mon Sep 17 00:00:00 2001 From: ake Date: Fri, 12 Jan 2024 10:51:47 +0100 Subject: [PATCH 12/14] Added renameOrganization function --- package-lock.json | 2 +- src/jira.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 89d27730..db12b3c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "jira-client", - "version": "7.2.0", + "version": "8.1.0", "license": "MIT", "dependencies": { "@babel/runtime": "^7.6.0", diff --git a/src/jira.js b/src/jira.js index e43ad938..ca7dac8c 100644 --- a/src/jira.js +++ b/src/jira.js @@ -2089,6 +2089,26 @@ export default class JiraApi { })); } + /** Rename an organization. + * [Jira Doc](https://youtu.be/dQw4w9WgXcQ?si=RWwWdNwZ2xBfY9dI) + * @name renameOrganization + * @function + * @param {string} organizationId - The organization identifier. + * @param {string} name - The new organization name. + */ + renameOrganization(organizationId, name) { + return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ + pathname: `/organisations/${organizationId}/update`, + }), { + method: 'PUT', + followAllRedirects: true, + body: { newName: name }, + headers: { + 'X-ExperimentalApi': 'opt-in', + }, + })); + } + /** Get Organizations * [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-getOrganizations) * @name getOrganization From 61b0400e872f574b231fc1a21659f3cdcd3b7c79 Mon Sep 17 00:00:00 2001 From: ake Date: Fri, 12 Jan 2024 11:44:46 +0100 Subject: [PATCH 13/14] Fixed rename function --- src/jira.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/jira.js b/src/jira.js index ca7dac8c..ec8505a5 100644 --- a/src/jira.js +++ b/src/jira.js @@ -2098,6 +2098,7 @@ export default class JiraApi { */ renameOrganization(organizationId, name) { return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ + intermediatePath: 'rest/servicedesk/1', pathname: `/organisations/${organizationId}/update`, }), { method: 'PUT', From 09b6e899d4523b55a5501392f4065420e74d0fa1 Mon Sep 17 00:00:00 2001 From: ake Date: Fri, 19 Jan 2024 16:05:47 +0100 Subject: [PATCH 14/14] Added deleteOrg function --- src/jira.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/jira.js b/src/jira.js index ec8505a5..62f8edd1 100644 --- a/src/jira.js +++ b/src/jira.js @@ -2112,7 +2112,7 @@ export default class JiraApi { /** Get Organizations * [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-getOrganizations) - * @name getOrganization + * @name getOrganizations * @function * @param {number} [start=0] - The starting index of the returned versions. Base index: 0. * @param {number} [limit=50] - The maximum number of versions to return per page. @@ -2148,6 +2148,23 @@ export default class JiraApi { })); } + /** Delete Organization + * [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-deleteOrganization) + * @name deleteOrganization + * @function + * @param {string} organizationId - The organization indentifier. + */ + deleteOrganization(organizationId) { + return this.doRequest(this.makeRequestHeader(this.makeServiceDeskUri({ + pathname: `/organization/${organizationId}`, + }), { + method: 'DELETE', + headers: { + 'X-ExperimentalApi': 'opt-in', + }, + })); + } + /** Get Users in an Organization * [Jira Doc](https://docs.atlassian.com/jira-servicedesk/REST/3.15.1/#servicedeskapi/organization-getUsersInOrganization) * @name getUsersInOrganization