Skip to content

Commit ce2d3f5

Browse files
committed
incremental fixes
1 parent c92cce3 commit ce2d3f5

18 files changed

+424
-535
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,26 @@
116116
"code:formatting": "pnpm run replace:all && pnpm run prettier && pnpm run lint:fix && pnpm run replace:fixCodeBlockSemicolons"
117117
},
118118
"dependencies": {
119-
"axios": "^1.10.0",
119+
"axios": "^1.11.0",
120120
"mime": "^4.0.7",
121121
"zod": "^3.25.76"
122122
},
123123
"devDependencies": {
124-
"@eslint/js": "^9.31.0",
124+
"@eslint/js": "^9.32.0",
125125
"@rollup/plugin-alias": "^5.1.1",
126126
"@rollup/plugin-commonjs": "^28.0.6",
127127
"@rollup/plugin-node-resolve": "^16.0.1",
128128
"@rollup/plugin-typescript": "^12.1.4",
129129
"@stylistic/eslint-plugin": "^5.2.2",
130130
"@types/node": "^20.19.9",
131131
"@types/sinon": "^17.0.4",
132-
"dotenv": "^17.2.0",
133-
"eslint": "^9.31.0",
132+
"dotenv": "^17.2.1",
133+
"eslint": "^9.32.0",
134134
"globals": "^16.3.0",
135-
"jiti": "^2.4.2",
135+
"jiti": "^2.5.1",
136136
"prettier": "^3.6.2",
137137
"prettier-plugin-jsdoc": "^1.3.3",
138-
"rollup": "^4.45.1",
138+
"rollup": "^4.45.3",
139139
"rollup-plugin-esnext-to-nodenext": "^1.0.1",
140140
"rollup-plugin-node-externals": "^8.0.1",
141141
"sinon": "^21.0.0",

pnpm-lock.yaml

Lines changed: 180 additions & 180 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: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import type { Client } from './client';
2+
import { Client } from './client';
33
import type { Config } from '../config';
44
import { ConfigSchema } from '../config';
55
import { getAuthenticationToken } from '../services/authenticationService';
@@ -10,8 +10,10 @@ const STRICT_GDPR_FLAG = 'x-atlassian-force-account-id';
1010
const ATLASSIAN_TOKEN_CHECK_FLAG = 'X-Atlassian-Token';
1111
const ATLASSIAN_TOKEN_CHECK_NOCHECK_VALUE = 'no-check';
1212

13-
export class BaseClient implements Client {
13+
export class BaseClient extends Client {
1414
constructor(protected readonly config: Config) {
15+
super();
16+
1517
try {
1618
this.config = ConfigSchema.parse(config);
1719
} catch (e) {
@@ -73,13 +75,7 @@ export class BaseClient implements Client {
7375
}, {});
7476
}
7577

76-
async sendRequest<T>(request: Request): Promise<T> {
77-
const response = await this.sendRequestFullResponse(request);
78-
79-
return this.handleFetchResponse(response);
80-
}
81-
82-
async sendRequestFullResponse(request: Request): Promise<Response> {
78+
async sendRequestWithRawResponse(request: Request): Promise<Response> {
8379
const url = new URL(request.url, this.config.host);
8480

8581
url.search = this.paramSerializer(request.query ?? {});
@@ -131,33 +127,6 @@ export class BaseClient implements Client {
131127
throw new Error(errorMessage);
132128
}
133129

134-
private async handleFetchResponse<T>(response: Response): Promise<T> {
135-
const contentType = response.headers.get('content-type') || '';
136-
137-
try {
138-
if (contentType.includes('application/json')) {
139-
return await response.json().catch(async () => {
140-
console.log('LLLL', await response.text());
141-
142-
return null;
143-
});
144-
} else if (contentType.includes('text/')) {
145-
return (await response.text()) as T;
146-
} else if (
147-
contentType.includes('application/octet-stream') ||
148-
contentType.includes('application/x-www-form-urlencoded') ||
149-
!contentType
150-
) {
151-
return (await response.arrayBuffer()) as T;
152-
} else {
153-
return response as T;
154-
}
155-
} catch (error) {
156-
// todo
157-
throw new Error(`Failed to parse response: ${error instanceof Error ? error.message : String(error)}`);
158-
}
159-
}
160-
161130
// handleSuccessResponse<T>(response: any): T {
162131
// this.config.middlewares?.onResponse?.(response.data);
163132
//

src/clients/client.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
import type { Request } from '../request';
22

3-
export interface Client {
4-
sendRequest<T>(requestConfig: Request): Promise<T>;
3+
export abstract class Client {
4+
async sendRequest<T>(request: Request): Promise<T> {
5+
const response = await this.sendRequestWithRawResponse(request);
6+
7+
return this.handleFetchResponse(response);
8+
}
9+
10+
abstract sendRequestWithRawResponse(request: Request): Promise<Response>;
11+
12+
async handleFetchResponse<T>(response: Response): Promise<T> {
13+
const contentType = response.headers.get('content-type') || '';
14+
15+
try {
16+
if (contentType.includes('application/json')) {
17+
return await response.json().catch(async () => {
18+
return undefined;
19+
});
20+
} else if (contentType.includes('text/')) {
21+
return (await response.text()) as T;
22+
} else if (
23+
contentType.includes('application/octet-stream') ||
24+
contentType.includes('application/x-www-form-urlencoded') ||
25+
!contentType
26+
) {
27+
return (await response.arrayBuffer()) as T;
28+
} else {
29+
return response as T;
30+
}
31+
} catch (error) {
32+
// todo
33+
throw new Error(`Failed to parse response: ${error instanceof Error ? error.message : String(error)}`);
34+
}
35+
}
536
}

src/version2/issueAttachments.ts

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,49 +28,24 @@ export class IssueAttachments {
2828
* to view the issue.
2929
* - If attachments are added in private comments, the comment-level restriction will be applied.
3030
*/
31-
async getAttachmentContent<T = Buffer>(
32-
parameters: Parameters.GetAttachmentContent | string,
33-
callback: Callback<T>,
34-
): Promise<void>;
35-
/**
36-
* Returns the contents of an attachment. A `Range` header can be set to define a range of bytes within the attachment
37-
* to download. See the [HTTP Range header standard](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range)
38-
* for details.
39-
*
40-
* To return a thumbnail of the attachment, use [Get attachment
41-
* thumbnail](#api-rest-api-2-attachment-thumbnail-id-get).
42-
*
43-
* This operation can be accessed anonymously.
44-
*
45-
* **[Permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#permissions) required:** For the
46-
* issue containing the attachment:
47-
*
48-
* - _Browse projects_ [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is
49-
* in.
50-
* - If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission
51-
* to view the issue.
52-
* - If attachments are added in private comments, the comment-level restriction will be applied.
53-
*/
54-
async getAttachmentContent<T = Buffer>(
55-
parameters: Parameters.GetAttachmentContent | string,
56-
callback?: never,
57-
): Promise<T>;
58-
async getAttachmentContent<T = Buffer>(
59-
parameters: Parameters.GetAttachmentContent | string,
60-
callback?: Callback<T>,
61-
): Promise<void | T> {
62-
const id = typeof parameters === 'string' ? parameters : parameters.id;
63-
31+
async getAttachmentContent<T = Models.AttachmentContent>(
32+
parameters: Parameters.GetAttachmentContent,
33+
): Promise<T> {
34+
// todo add Range header
6435
const config: Request = {
65-
url: `/rest/api/2/attachment/content/${id}`,
36+
url: `/rest/api/2/attachment/content/${parameters.id}`,
6637
method: 'GET',
6738
query: {
68-
redirect: typeof parameters !== 'string' && parameters.redirect,
39+
redirect: parameters.redirect,
6940
},
70-
// responseType: 'arraybuffer', // todo
7141
};
7242

73-
return this.client.sendRequest(config);
43+
const response = await this.client.sendRequestWithRawResponse(config);
44+
45+
const contentType = response.headers.get('content-type');
46+
const content = await response.arrayBuffer();
47+
48+
return { contentType, content } as T;
7449
}
7550

7651
/**
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface AttachmentContent {
2+
contentType: string | null;
3+
content: ArrayBuffer;
4+
}

src/version2/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './attachmentContent';
12
export * from './actorInput';
23
export * from './actorsMap';
34
export * from './addAtlassianTeamRequest';

0 commit comments

Comments
 (0)