Skip to content

Commit bc34a79

Browse files
MrRefactoringVladislav Tupikin
authored andcommitted
Docs generation fixes
1 parent b7c916d commit bc34a79

File tree

14 files changed

+476
-252
lines changed

14 files changed

+476
-252
lines changed

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default defineConfig([
1717
rules: {
1818
'@stylistic/ts/indent': ['error', 2],
1919
'@stylistic/js/no-trailing-spaces': 'error',
20+
'@stylistic/ts/quotes': ['error', 'single'],
2021
'@typescript-eslint/no-empty-object-type': 'off', // todo fix it
2122
}
2223
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,19 @@
9292
"@rollup/plugin-typescript": "^12.1.2",
9393
"@stylistic/eslint-plugin-js": "^4.2.0",
9494
"@stylistic/eslint-plugin-ts": "^4.2.0",
95-
"@types/node": "^20.17.31",
95+
"@types/node": "^20.17.32",
9696
"@types/sinon": "^17.0.4",
9797
"dotenv": "^16.5.0",
9898
"eslint": "^9.25.1",
9999
"globals": "^16.0.0",
100100
"prettier": "^3.5.3",
101101
"prettier-plugin-jsdoc": "^1.3.2",
102-
"rollup": "^4.40.0",
102+
"rollup": "^4.40.1",
103103
"sinon": "^20.0.0",
104104
"tslib": "^2.8.1",
105105
"typedoc": "^0.28.3",
106106
"typescript": "^5.8.3",
107-
"typescript-eslint": "^8.31.0",
107+
"typescript-eslint": "^8.31.1",
108108
"vitest": "^3.1.2"
109109
}
110110
}

pnpm-lock.yaml

Lines changed: 207 additions & 145 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/clients/baseClient.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import axios, { AxiosInstance, AxiosResponse } from 'axios';
33
import type { Callback } from '../callback';
44
import type { Client } from './client';
5-
import type { Config, JiraError } from '../config';
5+
import { Config, ConfigSchema, JiraError } from '../config';
66
import { getAuthenticationToken } from '../services/authenticationService';
77
import type { RequestConfig } from '../requestConfig';
88
import { HttpException, isObject } from './httpException';
9+
import { ZodError } from 'zod';
910

1011
const STRICT_GDPR_FLAG = 'x-atlassian-force-account-id';
1112
const ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';
@@ -16,11 +17,13 @@ export class BaseClient implements Client {
1617

1718
constructor(protected readonly config: Config) {
1819
try {
19-
new URL(config.host);
20-
} catch {
21-
throw new Error(
22-
"Couldn't parse the host URL. Perhaps you forgot to add 'http://' or 'https://' at the beginning of the URL?",
23-
);
20+
this.config = ConfigSchema.parse(config);
21+
} catch (e) {
22+
if (e instanceof ZodError && e.errors[0].message === 'Invalid url') {
23+
throw new Error('Couldn\'t parse the host URL. Perhaps you forgot to add \'http://\' or \'https://\' at the beginning of the URL?');
24+
}
25+
26+
throw e;
2427
}
2528

2629
this.instance = axios.create({

src/config.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,44 @@ import { HttpException } from './clients';
99
// expiryTimeSeconds: z.number().optional()
1010
// });
1111

12-
const BasicAuthSchema = z.object({
13-
email: z.string(),
14-
apiToken: z.string(),
15-
});
12+
export const BasicAuthSchema = z
13+
.object({
14+
email: z.string(),
15+
apiToken: z.string(),
16+
})
17+
.strict();
1618

1719
export type BasicAuth = z.infer<typeof BasicAuthSchema>;
1820

19-
const OAuth2Schema = z.object({
20-
accessToken: z.string(),
21-
});
21+
export const OAuth2Schema = z
22+
.object({
23+
accessToken: z.string(),
24+
})
25+
.strict();
2226

2327
export type OAuth2 = z.infer<typeof OAuth2Schema>;
2428

2529
// Middlewares schemas
26-
const MiddlewaresSchema = z.object({
27-
onError: z.function().args(z.any()).returns(z.void()).optional(),
28-
onResponse: z.function().args(z.any()).returns(z.void()).optional(),
29-
});
30+
export const MiddlewaresSchema = z
31+
.object({
32+
onError: z.function().args(z.any()).returns(z.void()).optional(),
33+
onResponse: z.function().args(z.any()).returns(z.void()).optional(),
34+
})
35+
.strict();
3036

3137
export type Middlewares = z.infer<typeof MiddlewaresSchema>;
3238

33-
export const ConfigSchema = z.object({
34-
host: z.string(),
35-
strictGDPR: z.boolean().optional(),
36-
/** Adds `'X-Atlassian-Token': 'no-check'` to each request header */
37-
noCheckAtlassianToken: z.boolean().optional(),
38-
baseRequestConfig: z.any().optional(),
39-
authentication: z.union([z.object({ basic: BasicAuthSchema }), z.object({ oauth2: OAuth2Schema })]).optional(),
40-
middlewares: MiddlewaresSchema.optional(),
41-
});
39+
export const ConfigSchema = z
40+
.object({
41+
host: z.string().url(),
42+
strictGDPR: z.boolean().optional(),
43+
/** Adds `'X-Atlassian-Token': 'no-check'` to each request header */
44+
noCheckAtlassianToken: z.boolean().optional(),
45+
baseRequestConfig: z.any().optional(),
46+
authentication: z.union([z.object({ basic: BasicAuthSchema }), z.object({ oauth2: OAuth2Schema })]).optional(),
47+
middlewares: MiddlewaresSchema.optional(),
48+
})
49+
.strict();
4250

4351
export type Config = z.infer<typeof ConfigSchema>;
4452

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Base64Encoder } from '../base64Encoder';
1+
import { encode } from '../base64Encoder';
22
import { BasicAuth } from '../../../config';
33

44
export function createBasicAuthenticationToken(authenticationData: BasicAuth) {
55
const login = authenticationData.email;
66
const secret = authenticationData.apiToken;
77

8-
const token = Base64Encoder.encode(`${login}:${secret}`);
8+
const token = encode(`${login}:${secret}`);
99

1010
return `Basic ${token}`;
1111
}
Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,66 @@
1-
/* eslint-disable */
21
/** @copyright The code was taken from the portal http://www.webtoolkit.info/javascript-base64.html */
32

4-
export namespace Base64Encoder {
5-
const base64Sequence = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
3+
const base64Sequence = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
64

7-
const utf8Encode = (value: string) => {
8-
value = value.replace(/\r\n/g, '\n');
5+
const utf8Encode = (value: string) => {
6+
value = value.replace(/\r\n/g, '\n');
97

10-
let utftext = '';
8+
let utftext = '';
119

12-
for (let n = 0; n < value.length; n++) {
13-
const c = value.charCodeAt(n);
10+
for (let n = 0; n < value.length; n++) {
11+
const c = value.charCodeAt(n);
1412

15-
if (c < 128) {
16-
utftext += String.fromCharCode(c);
17-
} else if (c > 127 && c < 2048) {
18-
utftext += String.fromCharCode((c >> 6) | 192);
13+
if (c < 128) {
14+
utftext += String.fromCharCode(c);
15+
} else if (c > 127 && c < 2048) {
16+
utftext += String.fromCharCode((c >> 6) | 192);
1917

20-
utftext += String.fromCharCode((c & 63) | 128);
21-
} else {
22-
utftext += String.fromCharCode((c >> 12) | 224);
18+
utftext += String.fromCharCode((c & 63) | 128);
19+
} else {
20+
utftext += String.fromCharCode((c >> 12) | 224);
2321

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

26-
utftext += String.fromCharCode((c & 63) | 128);
27-
}
24+
utftext += String.fromCharCode((c & 63) | 128);
2825
}
29-
30-
return utftext;
31-
};
32-
33-
export const encode = (input: string) => {
34-
let output = '';
35-
let chr1;
36-
let chr2;
37-
let chr3;
38-
let enc1;
39-
let enc2;
40-
let enc3;
41-
let enc4;
42-
let i = 0;
43-
44-
input = utf8Encode(input);
45-
46-
while (i < input.length) {
47-
chr1 = input.charCodeAt(i++);
48-
chr2 = input.charCodeAt(i++);
49-
chr3 = input.charCodeAt(i++);
50-
51-
enc1 = chr1 >> 2;
52-
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
53-
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
54-
enc4 = chr3 & 63;
55-
56-
if (isNaN(chr2)) {
57-
enc3 = enc4 = 64;
58-
} else if (isNaN(chr3)) {
59-
enc4 = 64;
60-
}
61-
62-
output += `${base64Sequence.charAt(enc1)}${base64Sequence.charAt(enc2)}${base64Sequence.charAt(
63-
enc3,
64-
)}${base64Sequence.charAt(enc4)}`;
26+
}
27+
28+
return utftext;
29+
};
30+
31+
export const encode = (input: string) => {
32+
let output = '';
33+
let chr1;
34+
let chr2;
35+
let chr3;
36+
let enc1;
37+
let enc2;
38+
let enc3;
39+
let enc4;
40+
let i = 0;
41+
42+
input = utf8Encode(input);
43+
44+
while (i < input.length) {
45+
chr1 = input.charCodeAt(i++);
46+
chr2 = input.charCodeAt(i++);
47+
chr3 = input.charCodeAt(i++);
48+
49+
enc1 = chr1 >> 2;
50+
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
51+
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
52+
enc4 = chr3 & 63;
53+
54+
if (isNaN(chr2)) {
55+
enc3 = enc4 = 64;
56+
} else if (isNaN(chr3)) {
57+
enc4 = 64;
6558
}
6659

67-
return output;
68-
};
69-
}
60+
output += `${base64Sequence.charAt(enc1)}${base64Sequence.charAt(enc2)}${base64Sequence.charAt(
61+
enc3,
62+
)}${base64Sequence.charAt(enc4)}`;
63+
}
64+
65+
return output;
66+
};

0 commit comments

Comments
 (0)