Skip to content

Commit df3b06d

Browse files
* endpoint types changed * type definition changed * version 2.0.1 * changelog added * issueTypeIds fixed * models types changed * - `Buffer.from` replaced to raw JS code in Basic authorization - Telemetry config type fixed - `noCheckAtlassianToken` flag added to config - Typing improves * tests added * The principles of running linter have been changed * 2.0.2 RC
1 parent b4e08d9 commit df3b06d

24 files changed

+799
-489
lines changed

.github/workflows/ci.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
uses: actions/setup-node@v1
1818
with:
1919
node-version: ${{ matrix.node-version }}
20+
- run: npm ci
2021
- run: npm install
2122
- run: npm run build
2223
- run: npm test

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Jira.js changelog
22

3+
### 2.0.2
4+
5+
- `Buffer.from` replaced to raw JS code in Basic authorization
6+
- Telemetry config type fixed
7+
- `noCheckAtlassianToken` flag added to config (`X-Atlassian-Token: no-check`)
8+
- Typing improves
9+
310
### 2.0.1
411

512
- Types bug fixes

package-lock.json

+21-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jira.js",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"main": "out/index.js",
55
"types": "out/index.d.ts",
66
"repository": "https://github.com/MrRefactoring/jira.js.git",
@@ -16,7 +16,15 @@
1616
"scripts": {
1717
"build": "tsc",
1818
"prepublishOnly": "npm run build && npm run test && npm run lint",
19-
"lint": "eslint src tests --ext .ts",
19+
"lint": "npm run lint:tests && npm run lint:src:agile && npm run lint:src:clients && npm run lint:src:services && npm run lint:src:version2 && npm run lint:src:version3 && npm run lint:src:files",
20+
"lint:tests": "npm run lint:base -- tests",
21+
"lint:src:agile": "npm run lint:base -- src/agile",
22+
"lint:src:clients": "npm run lint:base -- src/clients",
23+
"lint:src:services": "npm run lint:base -- src/services",
24+
"lint:src:version2": "npm run lint:base -- src/version2",
25+
"lint:src:version3": "npm run lint:base -- src/version3",
26+
"lint:src:files": "npm run lint:base -- src/*.ts",
27+
"lint:base": "eslint --ext .ts",
2028
"lint:fix": "npm run lint -- --fix",
2129
"doc": "typedoc --name Jira.js --out docs ./src",
2230
"test": "jest tests",
@@ -40,9 +48,9 @@
4048
"eslint-plugin-import": "^2.22.1",
4149
"jest": "^26.6.3",
4250
"sinon": "^9.2.4",
43-
"ts-jest": "^26.5.2",
44-
"typedoc": "^0.20.28",
45-
"typescript": "^4.2.2"
51+
"ts-jest": "^26.5.3",
52+
"typedoc": "^0.20.30",
53+
"typescript": "^4.2.3"
4654
},
4755
"dependencies": {
4856
"atlassian-jwt": "^1.0.3",

src/clients/baseClient.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { AuthenticationService } from '../services/authenticationService';
77
import type { RequestConfig } from '../requestConfig';
88

99
const STRICT_GDPR_FLAG = 'x-atlassian-force-account-id';
10+
const ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';
11+
const ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';
1012

1113
export class BaseClient implements Client {
1214
private instance: AxiosInstance;
@@ -20,6 +22,7 @@ export class BaseClient implements Client {
2022
baseURL: config.host,
2123
headers: this.removeUndefinedProperties({
2224
[STRICT_GDPR_FLAG]: config.strictGDPR,
25+
[ATLASSIAN_TOKEN_CHECK_FLAG]: config.noCheckAtlassianToken ? ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE : undefined,
2326
...config.baseRequestConfig?.headers,
2427
}),
2528
});
@@ -81,8 +84,8 @@ export class BaseClient implements Client {
8184
bodyExists: !!requestConfig.data,
8285
callbackUsed: !!callback,
8386
headersExists: !!requestConfig.headers,
84-
libVersion: '2.0.1',
85-
libVersionHash: 'defcf07630ba5955725c65ac0ca3a7a8',
87+
libVersion: '2.0.2',
88+
libVersionHash: 'e4586172850ecb0954a632168fa0151a',
8689
methodName: telemetryData?.methodName || 'sendRequest',
8790
onErrorMiddlewareUsed: !!this.config.middlewares?.onError,
8891
onResponseMiddlewareUsed: !!this.config.middlewares?.onResponse,
@@ -129,7 +132,7 @@ export class BaseClient implements Client {
129132

130133
this.config.middlewares?.onError?.(e);
131134

132-
telemetry.requestStatusCode = e.response?.status ?? 0;
135+
telemetry.requestStatusCode = e.isAxiosError ? e.response?.status ?? 0 : 418;
133136

134137
return errorHandler(e);
135138
} finally {

src/config.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import { RequestConfig } from './requestConfig';
66
export interface Config {
77
host: string;
88
strictGDPR?: boolean;
9+
noCheckAtlassianToken?: boolean;
910
baseRequestConfig?: Config.BaseRequestConfig;
1011
authentication?: Config.Authentication;
1112
middlewares?: Config.Middlewares;
12-
telemetry?: TelemetryConfig;
13+
telemetry?: Config.Telemetry;
1314
}
1415

1516
export namespace Config {
1617
export type BaseRequestConfig = RequestConfig;
17-
1818
export type Error = AxiosError;
19+
export type Telemetry = boolean | TelemetryConfig;
1920

2021
export type Authentication = UtilityTypes.XOR<{
2122
jwt: Authentication.JWT;

src/services/authenticationService/authentications/createBasicAuthenticationToken.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Config } from '../../../config';
2+
import { Base64Encoder } from '../base64Encoder';
23

34
export function createBasicAuthenticationToken(authenticationData: Config.Authentication.Basic) {
45
let login;
@@ -12,8 +13,7 @@ export function createBasicAuthenticationToken(authenticationData: Config.Authen
1213
secret = authenticationData.apiToken;
1314
}
1415

15-
const buffer = Buffer.from(`${login}:${secret}`);
16-
const token = buffer.toString('base64');
16+
const token = Base64Encoder.encode(`${login}:${secret}`);
1717

1818
return `Basic ${token}`;
1919
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* eslint-disable */
2+
/**
3+
* @copyright The code was taken from the portal http://www.webtoolkit.info/javascript-base64.html
4+
*/
5+
6+
export namespace Base64Encoder {
7+
const base64Sequence = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
8+
9+
const utf8Encode = (value: string) => {
10+
value = value.replace(/\r\n/g, '\n');
11+
12+
let utftext = '';
13+
14+
for (let n = 0; n < value.length; n++) {
15+
const c = value.charCodeAt(n);
16+
17+
if (c < 128) {
18+
utftext += String.fromCharCode(c);
19+
} else if ((c > 127) && (c < 2048)) {
20+
utftext += String.fromCharCode((c >> 6) | 192);
21+
22+
utftext += String.fromCharCode((c & 63) | 128);
23+
} else {
24+
utftext += String.fromCharCode((c >> 12) | 224);
25+
26+
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
27+
28+
utftext += String.fromCharCode((c & 63) | 128);
29+
}
30+
}
31+
32+
return utftext;
33+
};
34+
35+
export const encode = (input: string) => {
36+
let output = '';
37+
let chr1;
38+
let chr2;
39+
let chr3;
40+
let enc1;
41+
let enc2;
42+
let enc3;
43+
let enc4;
44+
let i = 0;
45+
46+
input = utf8Encode(input);
47+
48+
while (i < input.length) {
49+
chr1 = input.charCodeAt(i++);
50+
chr2 = input.charCodeAt(i++);
51+
chr3 = input.charCodeAt(i++);
52+
53+
enc1 = chr1 >> 2;
54+
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
55+
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
56+
enc4 = chr3 & 63;
57+
58+
if (isNaN(chr2)) {
59+
enc3 = enc4 = 64;
60+
} else if (isNaN(chr3)) {
61+
enc4 = 64;
62+
}
63+
64+
output += `${base64Sequence.charAt(enc1)}${base64Sequence.charAt(enc2)}${base64Sequence.charAt(enc3)}${base64Sequence.charAt(enc4)}`;
65+
}
66+
67+
return output;
68+
};
69+
}

src/version2/issueNavigatorSettings.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as Models from './models';
2-
import * as Parameters from './parameters';
31
import { Client } from '../clients';
42
import { Callback } from '../callback';
53
import { RequestConfig } from '../requestConfig';

src/version2/models/issueUpdateDetails.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { EntityProperty } from './entityProperty';
66
* Details of an issue update request. */
77
export interface IssueUpdateDetails {
88
/** Details of a transition. Required when performing a transition, optional when creating or editing an issue. */
9-
transition?: IssueTransition[];
9+
transition?: IssueTransition;
1010
/** List of issue screen fields to update, specifying the sub-field to update and its value for each field. This field provides a straightforward option when setting a sub-field. When multiple sub-fields or other operations are required, use `update`. Fields included in here cannot be included in `update`. */
1111
fields?: {};
1212
/** List of operations to perform on issue screen fields. Note that fields included in here cannot be included in `fields`. */
1313
update?: {};
1414
/** Additional issue history details. */
15-
historyMetadata?: HistoryMetadata[];
15+
historyMetadata?: HistoryMetadata;
1616
/** Details of issue properties to be add or update. */
1717
properties?: EntityProperty[];
1818
}

src/version2/models/remoteIssueLinkRequest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ export interface RemoteIssueLinkRequest {
1515
/** Description of the relationship between the issue and the linked item. If not set, the relationship description "links to" is used in Jira. */
1616
relationship?: string;
1717
/** Details of the item linked to. */
18-
object: RemoteObject[];
18+
object: RemoteObject;
1919
}

src/version2/models/remoteObject.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface RemoteObject {
1111
/** The summary details of the item. */
1212
summary?: string;
1313
/** Details of the icon for the item. If no icon is defined, the default link icon is used in Jira. */
14-
icon?: Icon[];
14+
icon?: Icon;
1515
/** The status of the item. */
16-
status?: Status[];
16+
status?: Status;
1717
}

0 commit comments

Comments
 (0)