From f3ba8535bef2e1499bebc092dfcaaf6d4155aae1 Mon Sep 17 00:00:00 2001 From: Vladislav Tupikin Date: Tue, 7 Jan 2025 23:27:21 +0300 Subject: [PATCH] CHANGELOG updated --- .eslintrc.yml | 2 ++ CHANGELOG.md | 15 ++++++++++++ examples/src/credentials.ts | 7 +++--- src/clients/baseClient.ts | 4 ++-- src/clients/httpException.ts | 1 + src/version2/filters.ts | 4 ++-- src/version2/groups.ts | 8 +++---- src/version2/issueFieldConfigurations.ts | 20 ++++++++-------- src/version2/issueTypeSchemes.ts | 24 +++++++++---------- src/version2/issueTypeScreenSchemes.ts | 12 +++++----- src/version2/jQL.ts | 10 ++++---- src/version2/timeTracking.ts | 14 +++++------ .../workflowSchemeProjectAssociations.ts | 10 ++++---- src/version3/issueTypeSchemes.ts | 10 ++++---- src/version3/timeTracking.ts | 14 +++++------ .../workflowSchemeProjectAssociations.ts | 10 ++++---- tests/unit/clients/baseClient.test.ts | 6 ++--- 17 files changed, 95 insertions(+), 76 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index e5ba51a3b2..e1bc60f939 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -6,11 +6,13 @@ parserOptions: project: ./tsconfig.lint.json plugins: - import + - '@typescript-eslint' env: node: true browser: true rules: "@typescript-eslint/lines-between-class-members": off + '@typescript-eslint/no-unnecessary-condition': [ 'error', { allowConstantLoopConditions: false } ] arrow-parens: - error - as-needed diff --git a/CHANGELOG.md b/CHANGELOG.md index 852d155d4b..f9715f2ec9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Jira.js changelog +### 4.1.0 + +- **General Improvements:** Enhanced JSDoc documentation across the project for better clarity and developer experience. +- **Fix:** Updated the following methods in `Version2Client` and `Version3Client` to make the `parameters` argument mandatory (as it should have been initially): + - `IssueFieldConfigurations.createFieldConfiguration` + - `IssueFieldConfigurations.createFieldConfigurationScheme` + - `IssueLinks.linkIssues` + - `IssueTypeSchemes.createIssueTypeScheme` + - `IssueTypeSchemes.assignIssueTypeSchemeToProject` + - `IssueTypeScreenSchemes.createIssueTypeScreenScheme` + - `JQL.parseJqlQueries` + - `TimeTracking.setSharedTimeTrackingConfiguration` + - `WorkflowSchemeProjectAssociations.assignSchemeToProject` +- **Improvement:** Changed the return type of `ProjectKeyAndNameValidation.getValidProjectKey` and `ProjectKeyAndNameValidation.getValidProjectName` from `unknown` to `string` for improved type safety and usability. + ### 4.0.5 - **#344:** Replaced the `mime-types` library with `mime` to ensure browser compatibility, as `mime-types` relies on the `path` module from Node.js. Thanks to [kang](https://github.com/kang8) for [reporting the issue](https://github.com/MrRefactoring/jira.js/issues/344) and proposing the fix. diff --git a/examples/src/credentials.ts b/examples/src/credentials.ts index cfb10bf39b..d237665ca6 100644 --- a/examples/src/credentials.ts +++ b/examples/src/credentials.ts @@ -1,6 +1,7 @@ -export const host = 'https://jira-js.atlassian.net/'; -export const email = 'mrrefactoring@yandex.ru'; -export const apiToken = 'ATATT3xFfGF0CQo3Ed8gqWxZmT2nlOEinQZJkp7hVY-ynttVtAsRwGF5JYD1vBcSu0i3RNfilR_RbksRFBxU33tsWTi7R5ontSouy0mwNqPhTazoZiVm5ah3_Emcy9g7-KB0rW7XTm5uLHeCdUW9X-Fv1jqWUHjtrOgCr4pXtcV6DmJPyBLa3Jg=582DE538'; +/* eslint-disable @typescript-eslint/no-unnecessary-condition */ +export const host = ''; +export const email = ''; +export const apiToken = ''; if (!host) { throw new Error('Please specify host'); diff --git a/src/clients/baseClient.ts b/src/clients/baseClient.ts index 5ade7e0b4b..6fc11d33be 100644 --- a/src/clients/baseClient.ts +++ b/src/clients/baseClient.ts @@ -140,8 +140,8 @@ export class BaseClient implements Client { code: e.code, message: e.message, data: e.response.data, - status: e.response?.status, - statusText: e.response?.statusText, + status: e.response.status, + statusText: e.response.statusText, }, e.response.status, { cause: e }, diff --git a/src/clients/httpException.ts b/src/clients/httpException.ts index 0e71522f8c..f0828e9deb 100644 --- a/src/clients/httpException.ts +++ b/src/clients/httpException.ts @@ -80,6 +80,7 @@ export class HttpException extends Error { return (response as Record).message; } + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (this.constructor) { return this.constructor.name.match(/[A-Z][a-z]+|[0-9]+/g)?.join(' ') ?? 'Error'; } diff --git a/src/version2/filters.ts b/src/version2/filters.ts index 65e0895154..26e71b0666 100644 --- a/src/version2/filters.ts +++ b/src/version2/filters.ts @@ -31,8 +31,8 @@ export class Filters { url: '/rest/api/2/filter', method: 'POST', params: { - expand: parameters?.expand, - overrideSharePermissions: parameters?.overrideSharePermissions, + expand: parameters.expand, + overrideSharePermissions: parameters.overrideSharePermissions, }, data: { description: parameters.description, diff --git a/src/version2/groups.ts b/src/version2/groups.ts index 2aeba04980..cff346dc5f 100644 --- a/src/version2/groups.ts +++ b/src/version2/groups.ts @@ -50,10 +50,10 @@ export class Groups { url: '/rest/api/2/group', method: 'DELETE', params: { - groupname: parameters?.groupname, - groupId: parameters?.groupId, - swapGroup: parameters?.swapGroup, - swapGroupId: parameters?.swapGroupId, + groupname: parameters.groupname, + groupId: parameters.groupId, + swapGroup: parameters.swapGroup, + swapGroupId: parameters.swapGroupId, }, }; diff --git a/src/version2/issueFieldConfigurations.ts b/src/version2/issueFieldConfigurations.ts index 5ebf33d4e3..74c801a325 100644 --- a/src/version2/issueFieldConfigurations.ts +++ b/src/version2/issueFieldConfigurations.ts @@ -72,7 +72,7 @@ export class IssueFieldConfigurations { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async createFieldConfiguration( - parameters: Parameters.CreateFieldConfiguration | undefined, + parameters: Parameters.CreateFieldConfiguration, callback: Callback, ): Promise; /** @@ -85,19 +85,19 @@ export class IssueFieldConfigurations { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async createFieldConfiguration( - parameters?: Parameters.CreateFieldConfiguration, + parameters: Parameters.CreateFieldConfiguration, callback?: never, ): Promise; async createFieldConfiguration( - parameters?: Parameters.CreateFieldConfiguration, + parameters: Parameters.CreateFieldConfiguration, callback?: Callback, ): Promise { const config: RequestConfig = { url: '/rest/api/2/fieldconfiguration', method: 'POST', data: { - name: parameters?.name, - description: parameters?.description, + name: parameters.name, + description: parameters.description, }, }; @@ -327,7 +327,7 @@ export class IssueFieldConfigurations { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async createFieldConfigurationScheme( - parameters: Parameters.CreateFieldConfigurationScheme | undefined, + parameters: Parameters.CreateFieldConfigurationScheme, callback: Callback, ): Promise; /** @@ -339,19 +339,19 @@ export class IssueFieldConfigurations { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async createFieldConfigurationScheme( - parameters?: Parameters.CreateFieldConfigurationScheme, + parameters: Parameters.CreateFieldConfigurationScheme, callback?: never, ): Promise; async createFieldConfigurationScheme( - parameters?: Parameters.CreateFieldConfigurationScheme, + parameters: Parameters.CreateFieldConfigurationScheme, callback?: Callback, ): Promise { const config: RequestConfig = { url: '/rest/api/2/fieldconfigurationscheme', method: 'POST', data: { - name: parameters?.name, - description: parameters?.description, + name: parameters.name, + description: parameters.description, }, }; diff --git a/src/version2/issueTypeSchemes.ts b/src/version2/issueTypeSchemes.ts index 1f9e7cfe95..5932fa3fcb 100644 --- a/src/version2/issueTypeSchemes.ts +++ b/src/version2/issueTypeSchemes.ts @@ -60,7 +60,7 @@ export class IssueTypeSchemes { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async createIssueTypeScheme( - parameters: Parameters.CreateIssueTypeScheme | undefined, + parameters: Parameters.CreateIssueTypeScheme, callback: Callback, ): Promise; /** @@ -70,21 +70,21 @@ export class IssueTypeSchemes { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async createIssueTypeScheme( - parameters?: Parameters.CreateIssueTypeScheme, + parameters: Parameters.CreateIssueTypeScheme, callback?: never, ): Promise; async createIssueTypeScheme( - parameters?: Parameters.CreateIssueTypeScheme, + parameters: Parameters.CreateIssueTypeScheme, callback?: Callback, ): Promise { const config: RequestConfig = { url: '/rest/api/2/issuetypescheme', method: 'POST', data: { - name: parameters?.name, - description: parameters?.description, - defaultIssueTypeId: parameters?.defaultIssueTypeId, - issueTypeIds: parameters?.issueTypeIds, + name: parameters.name, + description: parameters.description, + defaultIssueTypeId: parameters.defaultIssueTypeId, + issueTypeIds: parameters.issueTypeIds, }, }; @@ -189,7 +189,7 @@ export class IssueTypeSchemes { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async assignIssueTypeSchemeToProject( - parameters: Parameters.AssignIssueTypeSchemeToProject | undefined, + parameters: Parameters.AssignIssueTypeSchemeToProject, callback: Callback, ): Promise; /** @@ -204,19 +204,19 @@ export class IssueTypeSchemes { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async assignIssueTypeSchemeToProject( - parameters?: Parameters.AssignIssueTypeSchemeToProject, + parameters: Parameters.AssignIssueTypeSchemeToProject, callback?: never, ): Promise; async assignIssueTypeSchemeToProject( - parameters?: Parameters.AssignIssueTypeSchemeToProject, + parameters: Parameters.AssignIssueTypeSchemeToProject, callback?: Callback, ): Promise { const config: RequestConfig = { url: '/rest/api/2/issuetypescheme/project', method: 'PUT', data: { - issueTypeSchemeId: parameters?.issueTypeSchemeId, - projectId: parameters?.projectId, + issueTypeSchemeId: parameters.issueTypeSchemeId, + projectId: parameters.projectId, }, }; diff --git a/src/version2/issueTypeScreenSchemes.ts b/src/version2/issueTypeScreenSchemes.ts index 34dacadc5f..27e33bdc23 100644 --- a/src/version2/issueTypeScreenSchemes.ts +++ b/src/version2/issueTypeScreenSchemes.ts @@ -60,7 +60,7 @@ export class IssueTypeScreenSchemes { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async createIssueTypeScreenScheme( - parameters: Parameters.CreateIssueTypeScreenScheme | undefined, + parameters: Parameters.CreateIssueTypeScreenScheme, callback: Callback, ): Promise; /** @@ -70,20 +70,20 @@ export class IssueTypeScreenSchemes { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async createIssueTypeScreenScheme( - parameters?: Parameters.CreateIssueTypeScreenScheme, + parameters: Parameters.CreateIssueTypeScreenScheme, callback?: never, ): Promise; async createIssueTypeScreenScheme( - parameters?: Parameters.CreateIssueTypeScreenScheme, + parameters: Parameters.CreateIssueTypeScreenScheme, callback?: Callback, ): Promise { const config: RequestConfig = { url: '/rest/api/2/issuetypescreenscheme', method: 'POST', data: { - name: parameters?.name, - description: parameters?.description, - issueTypeMappings: parameters?.issueTypeMappings, + name: parameters.name, + description: parameters.description, + issueTypeMappings: parameters.issueTypeMappings, }, }; diff --git a/src/version2/jQL.ts b/src/version2/jQL.ts index a5dd54bb97..6325de5e9f 100644 --- a/src/version2/jQL.ts +++ b/src/version2/jQL.ts @@ -170,7 +170,7 @@ export class JQL { * **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#permissions) required:** None. */ async parseJqlQueries( - parameters: Parameters.ParseJqlQueries | undefined, + parameters: Parameters.ParseJqlQueries, callback: Callback, ): Promise; /** @@ -183,21 +183,21 @@ export class JQL { * **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#permissions) required:** None. */ async parseJqlQueries( - parameters?: Parameters.ParseJqlQueries, + parameters: Parameters.ParseJqlQueries, callback?: never, ): Promise; async parseJqlQueries( - parameters?: Parameters.ParseJqlQueries, + parameters: Parameters.ParseJqlQueries, callback?: Callback, ): Promise { const config: RequestConfig = { url: '/rest/api/2/jql/parse', method: 'POST', params: { - validation: parameters?.validation, + validation: parameters.validation, }, data: { - queries: parameters?.queries, + queries: parameters.queries, }, }; diff --git a/src/version2/timeTracking.ts b/src/version2/timeTracking.ts index 87358e0fd4..2a51bcc0f1 100644 --- a/src/version2/timeTracking.ts +++ b/src/version2/timeTracking.ts @@ -136,7 +136,7 @@ export class TimeTracking { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async setSharedTimeTrackingConfiguration( - parameters: Parameters.SetSharedTimeTrackingConfiguration | undefined, + parameters: Parameters.SetSharedTimeTrackingConfiguration, callback: Callback, ): Promise; /** @@ -146,21 +146,21 @@ export class TimeTracking { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async setSharedTimeTrackingConfiguration( - parameters?: Parameters.SetSharedTimeTrackingConfiguration, + parameters: Parameters.SetSharedTimeTrackingConfiguration, callback?: never, ): Promise; async setSharedTimeTrackingConfiguration( - parameters?: Parameters.SetSharedTimeTrackingConfiguration, + parameters: Parameters.SetSharedTimeTrackingConfiguration, callback?: Callback, ): Promise { const config: RequestConfig = { url: '/rest/api/2/configuration/timetracking/options', method: 'PUT', data: { - workingHoursPerDay: parameters?.workingHoursPerDay, - workingDaysPerWeek: parameters?.workingDaysPerWeek, - timeFormat: parameters?.timeFormat, - defaultUnit: parameters?.defaultUnit, + workingHoursPerDay: parameters.workingHoursPerDay, + workingDaysPerWeek: parameters.workingDaysPerWeek, + timeFormat: parameters.timeFormat, + defaultUnit: parameters.defaultUnit, }, }; diff --git a/src/version2/workflowSchemeProjectAssociations.ts b/src/version2/workflowSchemeProjectAssociations.ts index cda7595756..50c4a0391a 100644 --- a/src/version2/workflowSchemeProjectAssociations.ts +++ b/src/version2/workflowSchemeProjectAssociations.ts @@ -61,7 +61,7 @@ export class WorkflowSchemeProjectAssociations { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async assignSchemeToProject( - parameters: Parameters.AssignSchemeToProject | undefined, + parameters: Parameters.AssignSchemeToProject, callback: Callback, ): Promise; /** @@ -72,17 +72,17 @@ export class WorkflowSchemeProjectAssociations { * **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#permissions) required:** * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ - async assignSchemeToProject(parameters?: Parameters.AssignSchemeToProject, callback?: never): Promise; + async assignSchemeToProject(parameters: Parameters.AssignSchemeToProject, callback?: never): Promise; async assignSchemeToProject( - parameters?: Parameters.AssignSchemeToProject, + parameters: Parameters.AssignSchemeToProject, callback?: Callback, ): Promise { const config: RequestConfig = { url: '/rest/api/2/workflowscheme/project', method: 'PUT', data: { - workflowSchemeId: parameters?.workflowSchemeId, - projectId: parameters?.projectId, + workflowSchemeId: parameters.workflowSchemeId, + projectId: parameters.projectId, }, }; diff --git a/src/version3/issueTypeSchemes.ts b/src/version3/issueTypeSchemes.ts index 3e238d7d42..461def6959 100644 --- a/src/version3/issueTypeSchemes.ts +++ b/src/version3/issueTypeSchemes.ts @@ -189,7 +189,7 @@ export class IssueTypeSchemes { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async assignIssueTypeSchemeToProject( - parameters: Parameters.AssignIssueTypeSchemeToProject | undefined, + parameters: Parameters.AssignIssueTypeSchemeToProject, callback: Callback, ): Promise; /** @@ -204,19 +204,19 @@ export class IssueTypeSchemes { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async assignIssueTypeSchemeToProject( - parameters?: Parameters.AssignIssueTypeSchemeToProject, + parameters: Parameters.AssignIssueTypeSchemeToProject, callback?: never, ): Promise; async assignIssueTypeSchemeToProject( - parameters?: Parameters.AssignIssueTypeSchemeToProject, + parameters: Parameters.AssignIssueTypeSchemeToProject, callback?: Callback, ): Promise { const config: RequestConfig = { url: '/rest/api/3/issuetypescheme/project', method: 'PUT', data: { - issueTypeSchemeId: parameters?.issueTypeSchemeId, - projectId: parameters?.projectId, + issueTypeSchemeId: parameters.issueTypeSchemeId, + projectId: parameters.projectId, }, }; diff --git a/src/version3/timeTracking.ts b/src/version3/timeTracking.ts index cd9a868e92..3ef6089f9d 100644 --- a/src/version3/timeTracking.ts +++ b/src/version3/timeTracking.ts @@ -136,7 +136,7 @@ export class TimeTracking { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async setSharedTimeTrackingConfiguration( - parameters: Parameters.SetSharedTimeTrackingConfiguration | undefined, + parameters: Parameters.SetSharedTimeTrackingConfiguration, callback: Callback, ): Promise; /** @@ -146,21 +146,21 @@ export class TimeTracking { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async setSharedTimeTrackingConfiguration( - parameters?: Parameters.SetSharedTimeTrackingConfiguration, + parameters: Parameters.SetSharedTimeTrackingConfiguration, callback?: never, ): Promise; async setSharedTimeTrackingConfiguration( - parameters?: Parameters.SetSharedTimeTrackingConfiguration, + parameters: Parameters.SetSharedTimeTrackingConfiguration, callback?: Callback, ): Promise { const config: RequestConfig = { url: '/rest/api/3/configuration/timetracking/options', method: 'PUT', data: { - defaultUnit: parameters?.defaultUnit, - timeFormat: parameters?.timeFormat, - workingDaysPerWeek: parameters?.workingDaysPerWeek, - workingHoursPerDay: parameters?.workingHoursPerDay, + defaultUnit: parameters.defaultUnit, + timeFormat: parameters.timeFormat, + workingDaysPerWeek: parameters.workingDaysPerWeek, + workingHoursPerDay: parameters.workingHoursPerDay, }, }; diff --git a/src/version3/workflowSchemeProjectAssociations.ts b/src/version3/workflowSchemeProjectAssociations.ts index 74f20cd0f8..67d242713b 100644 --- a/src/version3/workflowSchemeProjectAssociations.ts +++ b/src/version3/workflowSchemeProjectAssociations.ts @@ -61,7 +61,7 @@ export class WorkflowSchemeProjectAssociations { * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ async assignSchemeToProject( - parameters: Parameters.AssignSchemeToProject | undefined, + parameters: Parameters.AssignSchemeToProject, callback: Callback, ): Promise; /** @@ -72,17 +72,17 @@ export class WorkflowSchemeProjectAssociations { * **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#permissions) required:** * _Administer Jira_ [global permission](https://confluence.atlassian.com/x/x4dKLg). */ - async assignSchemeToProject(parameters?: Parameters.AssignSchemeToProject, callback?: never): Promise; + async assignSchemeToProject(parameters: Parameters.AssignSchemeToProject, callback?: never): Promise; async assignSchemeToProject( - parameters?: Parameters.AssignSchemeToProject, + parameters: Parameters.AssignSchemeToProject, callback?: Callback, ): Promise { const config: RequestConfig = { url: '/rest/api/3/workflowscheme/project', method: 'PUT', data: { - projectId: parameters?.projectId, - workflowSchemeId: parameters?.workflowSchemeId, + projectId: parameters.projectId, + workflowSchemeId: parameters.workflowSchemeId, }, }; diff --git a/tests/unit/clients/baseClient.test.ts b/tests/unit/clients/baseClient.test.ts index 27e97e0481..b87e0237a8 100644 --- a/tests/unit/clients/baseClient.test.ts +++ b/tests/unit/clients/baseClient.test.ts @@ -11,7 +11,7 @@ test('should create X-Atlassian-Token: no-check header in requests', ({ expect } }); // @ts-ignore - const defaultHeaders: Record = client.instance.defaults.headers || {}; + const defaultHeaders: Record = client.instance.defaults.headers; expect(defaultHeaders[XAtlassianToken]).toBe('no-check'); @@ -33,7 +33,7 @@ test('should not create X-Atlassian-Token: no-check header in requests case 1', noCheckAtlassianToken: false, }); // @ts-ignore - const defaultHeaders: Record = client.instance.defaults.headers || {}; + const defaultHeaders: Record = client.instance.defaults.headers; expect(defaultHeaders[XAtlassianToken]).toBe(undefined); @@ -54,7 +54,7 @@ test('should create X-Atlassian-Token: no-check header in requests case 2', ({ e }); // @ts-ignore - const defaultHeaders: Record = client.instance.defaults.headers || {}; + const defaultHeaders: Record = client.instance.defaults.headers; expect(defaultHeaders[XAtlassianToken]).toBe(undefined);