Skip to content

Commit aa90e71

Browse files
committed
Docs generation fixes
1 parent b7c916d commit aa90e71

File tree

7 files changed

+233
-88
lines changed

7 files changed

+233
-88
lines changed

src/clients/baseClient.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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';
@@ -15,13 +15,7 @@ export class BaseClient implements Client {
1515
private instance: AxiosInstance;
1616

1717
constructor(protected readonly config: Config) {
18-
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-
);
24-
}
18+
this.config = ConfigSchema.parse(config);
2519

2620
this.instance = axios.create({
2721
paramsSerializer: this.paramSerializer.bind(this),

src/config.ts

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

12-
const BasicAuthSchema = z.object({
12+
export const BasicAuthSchema = z.object({
1313
email: z.string(),
1414
apiToken: z.string(),
15-
});
15+
}).strict();
1616

1717
export type BasicAuth = z.infer<typeof BasicAuthSchema>;
1818

19-
const OAuth2Schema = z.object({
19+
export const OAuth2Schema = z.object({
2020
accessToken: z.string(),
21-
});
21+
}).strict();
2222

2323
export type OAuth2 = z.infer<typeof OAuth2Schema>;
2424

2525
// Middlewares schemas
26-
const MiddlewaresSchema = z.object({
26+
export const MiddlewaresSchema = z.object({
2727
onError: z.function().args(z.any()).returns(z.void()).optional(),
2828
onResponse: z.function().args(z.any()).returns(z.void()).optional(),
29-
});
29+
}).strict();
3030

3131
export type Middlewares = z.infer<typeof MiddlewaresSchema>;
3232

@@ -38,7 +38,7 @@ export const ConfigSchema = z.object({
3838
baseRequestConfig: z.any().optional(),
3939
authentication: z.union([z.object({ basic: BasicAuthSchema }), z.object({ oauth2: OAuth2Schema })]).optional(),
4040
middlewares: MiddlewaresSchema.optional(),
41-
});
41+
}).strict();
4242

4343
export type Config = z.infer<typeof ConfigSchema>;
4444

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)