Skip to content

Commit

Permalink
2.0.2 RC (#104)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MrRefactoring authored Mar 6, 2021
1 parent b4e08d9 commit df3b06d
Show file tree
Hide file tree
Showing 24 changed files with 799 additions and 489 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm install
- run: npm run build
- run: npm test
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Jira.js changelog

### 2.0.2

- `Buffer.from` replaced to raw JS code in Basic authorization
- Telemetry config type fixed
- `noCheckAtlassianToken` flag added to config (`X-Atlassian-Token: no-check`)
- Typing improves

### 2.0.1

- Types bug fixes
Expand Down
43 changes: 21 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jira.js",
"version": "2.0.1",
"version": "2.0.2",
"main": "out/index.js",
"types": "out/index.d.ts",
"repository": "https://github.com/MrRefactoring/jira.js.git",
Expand All @@ -16,7 +16,15 @@
"scripts": {
"build": "tsc",
"prepublishOnly": "npm run build && npm run test && npm run lint",
"lint": "eslint src tests --ext .ts",
"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",
"lint:tests": "npm run lint:base -- tests",
"lint:src:agile": "npm run lint:base -- src/agile",
"lint:src:clients": "npm run lint:base -- src/clients",
"lint:src:services": "npm run lint:base -- src/services",
"lint:src:version2": "npm run lint:base -- src/version2",
"lint:src:version3": "npm run lint:base -- src/version3",
"lint:src:files": "npm run lint:base -- src/*.ts",
"lint:base": "eslint --ext .ts",
"lint:fix": "npm run lint -- --fix",
"doc": "typedoc --name Jira.js --out docs ./src",
"test": "jest tests",
Expand All @@ -40,9 +48,9 @@
"eslint-plugin-import": "^2.22.1",
"jest": "^26.6.3",
"sinon": "^9.2.4",
"ts-jest": "^26.5.2",
"typedoc": "^0.20.28",
"typescript": "^4.2.2"
"ts-jest": "^26.5.3",
"typedoc": "^0.20.30",
"typescript": "^4.2.3"
},
"dependencies": {
"atlassian-jwt": "^1.0.3",
Expand Down
9 changes: 6 additions & 3 deletions src/clients/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { AuthenticationService } from '../services/authenticationService';
import type { RequestConfig } from '../requestConfig';

const STRICT_GDPR_FLAG = 'x-atlassian-force-account-id';
const ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';
const ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';

export class BaseClient implements Client {
private instance: AxiosInstance;
Expand All @@ -20,6 +22,7 @@ export class BaseClient implements Client {
baseURL: config.host,
headers: this.removeUndefinedProperties({
[STRICT_GDPR_FLAG]: config.strictGDPR,
[ATLASSIAN_TOKEN_CHECK_FLAG]: config.noCheckAtlassianToken ? ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE : undefined,
...config.baseRequestConfig?.headers,
}),
});
Expand Down Expand Up @@ -81,8 +84,8 @@ export class BaseClient implements Client {
bodyExists: !!requestConfig.data,
callbackUsed: !!callback,
headersExists: !!requestConfig.headers,
libVersion: '2.0.1',
libVersionHash: 'defcf07630ba5955725c65ac0ca3a7a8',
libVersion: '2.0.2',
libVersionHash: 'e4586172850ecb0954a632168fa0151a',
methodName: telemetryData?.methodName || 'sendRequest',
onErrorMiddlewareUsed: !!this.config.middlewares?.onError,
onResponseMiddlewareUsed: !!this.config.middlewares?.onResponse,
Expand Down Expand Up @@ -129,7 +132,7 @@ export class BaseClient implements Client {

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

telemetry.requestStatusCode = e.response?.status ?? 0;
telemetry.requestStatusCode = e.isAxiosError ? e.response?.status ?? 0 : 418;

return errorHandler(e);
} finally {
Expand Down
5 changes: 3 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { RequestConfig } from './requestConfig';
export interface Config {
host: string;
strictGDPR?: boolean;
noCheckAtlassianToken?: boolean;
baseRequestConfig?: Config.BaseRequestConfig;
authentication?: Config.Authentication;
middlewares?: Config.Middlewares;
telemetry?: TelemetryConfig;
telemetry?: Config.Telemetry;
}

export namespace Config {
export type BaseRequestConfig = RequestConfig;

export type Error = AxiosError;
export type Telemetry = boolean | TelemetryConfig;

export type Authentication = UtilityTypes.XOR<{
jwt: Authentication.JWT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Config } from '../../../config';
import { Base64Encoder } from '../base64Encoder';

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

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

return `Basic ${token}`;
}
69 changes: 69 additions & 0 deletions src/services/authenticationService/base64Encoder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* eslint-disable */
/**
* @copyright The code was taken from the portal http://www.webtoolkit.info/javascript-base64.html
*/

export namespace Base64Encoder {
const base64Sequence = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

const utf8Encode = (value: string) => {
value = value.replace(/\r\n/g, '\n');

let utftext = '';

for (let n = 0; n < value.length; n++) {
const c = value.charCodeAt(n);

if (c < 128) {
utftext += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);

utftext += String.fromCharCode((c & 63) | 128);
} else {
utftext += String.fromCharCode((c >> 12) | 224);

utftext += String.fromCharCode(((c >> 6) & 63) | 128);

utftext += String.fromCharCode((c & 63) | 128);
}
}

return utftext;
};

export const encode = (input: string) => {
let output = '';
let chr1;
let chr2;
let chr3;
let enc1;
let enc2;
let enc3;
let enc4;
let i = 0;

input = utf8Encode(input);

while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);

enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;

if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}

output += `${base64Sequence.charAt(enc1)}${base64Sequence.charAt(enc2)}${base64Sequence.charAt(enc3)}${base64Sequence.charAt(enc4)}`;
}

return output;
};
}
2 changes: 0 additions & 2 deletions src/version2/issueNavigatorSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as Models from './models';
import * as Parameters from './parameters';
import { Client } from '../clients';
import { Callback } from '../callback';
import { RequestConfig } from '../requestConfig';
Expand Down
4 changes: 2 additions & 2 deletions src/version2/models/issueUpdateDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { EntityProperty } from './entityProperty';
* Details of an issue update request. */
export interface IssueUpdateDetails {
/** Details of a transition. Required when performing a transition, optional when creating or editing an issue. */
transition?: IssueTransition[];
transition?: IssueTransition;
/** 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`. */
fields?: {};
/** List of operations to perform on issue screen fields. Note that fields included in here cannot be included in `fields`. */
update?: {};
/** Additional issue history details. */
historyMetadata?: HistoryMetadata[];
historyMetadata?: HistoryMetadata;
/** Details of issue properties to be add or update. */
properties?: EntityProperty[];
}
2 changes: 1 addition & 1 deletion src/version2/models/remoteIssueLinkRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export interface RemoteIssueLinkRequest {
/** Description of the relationship between the issue and the linked item. If not set, the relationship description "links to" is used in Jira. */
relationship?: string;
/** Details of the item linked to. */
object: RemoteObject[];
object: RemoteObject;
}
4 changes: 2 additions & 2 deletions src/version2/models/remoteObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface RemoteObject {
/** The summary details of the item. */
summary?: string;
/** Details of the icon for the item. If no icon is defined, the default link icon is used in Jira. */
icon?: Icon[];
icon?: Icon;
/** The status of the item. */
status?: Status[];
status?: Status;
}
Loading

0 comments on commit df3b06d

Please sign in to comment.