bitbucket-data-center-client 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -17
- package/dist/api/base.d.ts +11 -0
- package/dist/api/base.d.ts.map +1 -0
- package/dist/api/base.js +22 -0
- package/dist/api/base.js.map +1 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +6 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/projects.d.ts +14 -0
- package/dist/api/projects.d.ts.map +1 -0
- package/dist/api/projects.js +17 -0
- package/dist/api/projects.js.map +1 -0
- package/dist/api/pull-requests.d.ts +81 -0
- package/dist/api/pull-requests.d.ts.map +1 -0
- package/dist/api/pull-requests.js +206 -0
- package/dist/api/pull-requests.js.map +1 -0
- package/dist/api/repositories.d.ts +35 -0
- package/dist/api/repositories.d.ts.map +1 -0
- package/dist/api/repositories.js +85 -0
- package/dist/api/repositories.js.map +1 -0
- package/dist/api/users.d.ts +18 -0
- package/dist/api/users.d.ts.map +1 -0
- package/dist/api/users.js +24 -0
- package/dist/api/users.js.map +1 -0
- package/dist/client.d.ts +41 -24
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +44 -215
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/types/common.d.ts +72 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +5 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/project.d.ts +41 -0
- package/dist/types/project.d.ts.map +1 -0
- package/dist/types/project.js +2 -0
- package/dist/types/project.js.map +1 -0
- package/dist/types/pull-request.d.ts +730 -0
- package/dist/types/pull-request.d.ts.map +1 -0
- package/dist/types/pull-request.js +2 -0
- package/dist/types/pull-request.js.map +1 -0
- package/dist/types/repository.d.ts +172 -0
- package/dist/types/repository.d.ts.map +1 -0
- package/dist/types/repository.js +2 -0
- package/dist/types/repository.js.map +1 -0
- package/dist/types/user.d.ts +46 -0
- package/dist/types/user.d.ts.map +1 -0
- package/dist/types/user.js +2 -0
- package/dist/types/user.js.map +1 -0
- package/package.json +21 -12
- package/.claude/settings.local.json +0 -13
- package/AGENTS.md +0 -35
- package/BitbucketServerSwagger.json +0 -67522
- package/LICENSE +0 -21
- package/dist/types.d.ts +0 -498
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -14,43 +14,84 @@ npm install bitbucket-data-center-client
|
|
|
14
14
|
import { BitbucketClient } from 'bitbucket-data-center-client';
|
|
15
15
|
|
|
16
16
|
const client = new BitbucketClient({
|
|
17
|
+
baseUrl: 'https://bitbucket.example.com',
|
|
17
18
|
token: 'your-personal-access-token',
|
|
18
|
-
baseUrl: 'https://bitbucket.example.com'
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
+
// Get user profile
|
|
22
|
+
const user = await client.users.getProfile({ username: 'john.doe' });
|
|
23
|
+
|
|
21
24
|
// List projects
|
|
22
|
-
const projects = await client.
|
|
25
|
+
const projects = await client.projects.list();
|
|
26
|
+
|
|
27
|
+
// List repositories in a project
|
|
28
|
+
const repos = await client.repositories.list({ projectKey: 'PROJ' });
|
|
23
29
|
|
|
24
30
|
// Browse repository contents
|
|
25
|
-
const contents = await client.browse({
|
|
31
|
+
const contents = await client.repositories.browse({
|
|
26
32
|
projectKey: 'PROJ',
|
|
27
33
|
repositorySlug: 'my-repo',
|
|
28
|
-
path: 'src'
|
|
34
|
+
path: 'src',
|
|
29
35
|
});
|
|
30
36
|
|
|
31
37
|
// Get raw file content
|
|
32
|
-
const file = await client.getRawContent({
|
|
38
|
+
const file = await client.repositories.getRawContent({
|
|
39
|
+
projectKey: 'PROJ',
|
|
40
|
+
repositorySlug: 'my-repo',
|
|
41
|
+
path: 'package.json',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Get pull request details
|
|
45
|
+
const pr = await client.pullRequests.get({
|
|
33
46
|
projectKey: 'PROJ',
|
|
34
47
|
repositorySlug: 'my-repo',
|
|
35
|
-
|
|
48
|
+
pullRequestId: 123,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Create a pull request
|
|
52
|
+
const newPr = await client.pullRequests.create({
|
|
53
|
+
projectKey: 'PROJ',
|
|
54
|
+
repositorySlug: 'my-repo',
|
|
55
|
+
fromBranch: 'feature-branch',
|
|
56
|
+
toBranch: 'main',
|
|
57
|
+
title: 'Add new feature',
|
|
58
|
+
reviewers: ['reviewer1', 'reviewer2'],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Add a comment to a PR
|
|
62
|
+
await client.pullRequests.addComment({
|
|
63
|
+
projectKey: 'PROJ',
|
|
64
|
+
repositorySlug: 'my-repo',
|
|
65
|
+
pullRequestId: 123,
|
|
66
|
+
text: 'Looks good!',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Approve a PR
|
|
70
|
+
await client.pullRequests.updateReviewStatus({
|
|
71
|
+
projectKey: 'PROJ',
|
|
72
|
+
repositorySlug: 'my-repo',
|
|
73
|
+
pullRequestId: 123,
|
|
74
|
+
status: 'APPROVED',
|
|
36
75
|
});
|
|
37
76
|
```
|
|
38
77
|
|
|
39
|
-
##
|
|
78
|
+
## API Structure
|
|
40
79
|
|
|
41
|
-
|
|
|
42
|
-
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
| PR Changes | `getPullRequestChanges`, `getPullRequestDiff`, `getPullRequestFileDiff` |
|
|
48
|
-
| PR Comments | `addPullRequestComment`, `deletePullRequestComment`, `getPullRequestActivities` |
|
|
49
|
-
| PR Review | `updateReviewStatus`, `addPullRequestCommentReaction`, `removePullRequestCommentReaction` |
|
|
80
|
+
| Domain | Methods |
|
|
81
|
+
|--------|---------|
|
|
82
|
+
| `client.users` | `getProfile`, `getAll` |
|
|
83
|
+
| `client.projects` | `list` |
|
|
84
|
+
| `client.repositories` | `list`, `get`, `browse`, `getRawContent`, `checkPermissions` |
|
|
85
|
+
| `client.pullRequests` | `getInbox`, `getDashboard`, `get`, `create`, `getChanges`, `getDiff`, `getFileDiff`, `getActivities`, `addComment`, `deleteComment`, `updateReviewStatus`, `addReaction`, `removeReaction`, `getRequiredReviewers` |
|
|
50
86
|
|
|
51
87
|
## Authentication
|
|
52
88
|
|
|
53
|
-
Generate a Personal Access Token in Bitbucket: **Profile
|
|
89
|
+
Generate a Personal Access Token in Bitbucket: **Profile > Manage account > Personal access tokens**
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
export BITBUCKET_URL=https://bitbucket.example.com
|
|
93
|
+
export BITBUCKET_TOKEN=your-personal-access-token
|
|
94
|
+
```
|
|
54
95
|
|
|
55
96
|
## Requirements
|
|
56
97
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type AxiosInstance } from 'axios';
|
|
2
|
+
import type { BitbucketClientConfig } from '../types/common.js';
|
|
3
|
+
/**
|
|
4
|
+
* Base API class providing shared axios configuration for all domain APIs.
|
|
5
|
+
*/
|
|
6
|
+
export declare class BaseApi {
|
|
7
|
+
protected client: AxiosInstance;
|
|
8
|
+
protected baseUrl: string;
|
|
9
|
+
constructor(config: BitbucketClientConfig);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/api/base.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;GAEG;AACH,qBAAa,OAAO;IAClB,SAAS,CAAC,MAAM,EAAE,aAAa,CAAC;IAChC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEP,MAAM,EAAE,qBAAqB;CAcjD"}
|
package/dist/api/base.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* Base API class providing shared axios configuration for all domain APIs.
|
|
4
|
+
*/
|
|
5
|
+
export class BaseApi {
|
|
6
|
+
client;
|
|
7
|
+
baseUrl;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
const { token, baseUrl, axiosConfig = {} } = config;
|
|
10
|
+
this.baseUrl = baseUrl;
|
|
11
|
+
this.client = axios.create({
|
|
12
|
+
...axiosConfig,
|
|
13
|
+
baseURL: `${baseUrl}/rest/api/latest`,
|
|
14
|
+
headers: {
|
|
15
|
+
...axiosConfig.headers,
|
|
16
|
+
Authorization: `Bearer ${token}`,
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/api/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAGlD;;GAEG;AACH,MAAM,OAAO,OAAO;IACR,MAAM,CAAgB;IACtB,OAAO,CAAS;IAE1B,YAAmB,MAA6B;QAC9C,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YACzB,GAAG,WAAW;YACd,OAAO,EAAE,GAAG,OAAO,kBAAkB;YACrC,OAAO,EAAE;gBACP,GAAG,WAAW,CAAC,OAAO;gBACtB,aAAa,EAAE,UAAU,KAAK,EAAE;gBAChC,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BaseApi } from './base.js';
|
|
2
|
+
export { ProjectsApi } from './projects.js';
|
|
3
|
+
export { PullRequestsApi } from './pull-requests.js';
|
|
4
|
+
export { RepositoriesApi } from './repositories.js';
|
|
5
|
+
export { UsersApi } from './users.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BaseApi } from './base.js';
|
|
2
|
+
export { ProjectsApi } from './projects.js';
|
|
3
|
+
export { PullRequestsApi } from './pull-requests.js';
|
|
4
|
+
export { RepositoriesApi } from './repositories.js';
|
|
5
|
+
export { UsersApi } from './users.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseApi } from './base.js';
|
|
2
|
+
import type { PaginatedResponse } from '../types/common.js';
|
|
3
|
+
import type { ListProjectsParams, RestProject } from '../types/project.js';
|
|
4
|
+
/**
|
|
5
|
+
* Projects API for Bitbucket Server.
|
|
6
|
+
* Provides methods for project-related operations.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ProjectsApi extends BaseApi {
|
|
9
|
+
/**
|
|
10
|
+
* List projects, optionally filtered by name or permission
|
|
11
|
+
*/
|
|
12
|
+
list(params?: ListProjectsParams): Promise<PaginatedResponse<RestProject>>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=projects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projects.d.ts","sourceRoot":"","sources":["../../src/api/projects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE3E;;;GAGG;AACH,qBAAa,WAAY,SAAQ,OAAO;IACtC;;OAEG;IACU,IAAI,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;CAMxF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseApi } from './base.js';
|
|
2
|
+
/**
|
|
3
|
+
* Projects API for Bitbucket Server.
|
|
4
|
+
* Provides methods for project-related operations.
|
|
5
|
+
*/
|
|
6
|
+
export class ProjectsApi extends BaseApi {
|
|
7
|
+
/**
|
|
8
|
+
* List projects, optionally filtered by name or permission
|
|
9
|
+
*/
|
|
10
|
+
async list(params) {
|
|
11
|
+
const response = await this.client.get('/projects', {
|
|
12
|
+
params,
|
|
13
|
+
});
|
|
14
|
+
return response.data;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=projects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/api/projects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,OAAO;IACtC;;OAEG;IACI,KAAK,CAAC,IAAI,CAAC,MAA2B;QAC3C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAiC,WAAW,EAAE;YAClF,MAAM;SACP,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { BaseApi } from './base.js';
|
|
2
|
+
import type { PaginatedResponse } from '../types/common.js';
|
|
3
|
+
import type { AddPullRequestCommentParams, AddPullRequestCommentReactionParams, ChangesResponse, CreatePullRequestParams, DeletePullRequestCommentParams, DiffResponse, GetDashboardPullRequestsParams, GetInboxPullRequestsParams, GetPullRequestActivitiesParams, GetPullRequestChangesParams, GetPullRequestDiffParams, GetPullRequestFileDiffParams, GetPullRequestParams, GetRequiredReviewersParams, InboxPullRequest, RemovePullRequestCommentReactionParams, RestComment, RestPullRequest, RestPullRequestActivityApiResponse, RestPullRequestParticipant, RestUserReaction, UpdateReviewStatusParams } from '../types/pull-request.js';
|
|
4
|
+
import type { RestUser } from '../types/user.js';
|
|
5
|
+
/**
|
|
6
|
+
* Pull Requests API for Bitbucket Server.
|
|
7
|
+
* Provides methods for pull request-related operations.
|
|
8
|
+
*/
|
|
9
|
+
export declare class PullRequestsApi extends BaseApi {
|
|
10
|
+
/**
|
|
11
|
+
* Get pull requests in the authenticated user's inbox (where they are assigned as reviewer)
|
|
12
|
+
*/
|
|
13
|
+
getInbox(params?: GetInboxPullRequestsParams): Promise<PaginatedResponse<InboxPullRequest>>;
|
|
14
|
+
/**
|
|
15
|
+
* Get pull requests from the user's dashboard.
|
|
16
|
+
* Can filter by role (AUTHOR, REVIEWER, PARTICIPANT), state, and more.
|
|
17
|
+
*/
|
|
18
|
+
getDashboard(params?: GetDashboardPullRequestsParams): Promise<PaginatedResponse<RestPullRequest>>;
|
|
19
|
+
/**
|
|
20
|
+
* Get pull request details (title, description, author, branches, etc.)
|
|
21
|
+
*/
|
|
22
|
+
get(params: GetPullRequestParams): Promise<RestPullRequest>;
|
|
23
|
+
/**
|
|
24
|
+
* Create a new pull request.
|
|
25
|
+
* Supports both same-repo PRs (default) and cross-repo PRs (when fromRepositorySlug is provided).
|
|
26
|
+
* Branch names are automatically converted to full refs (e.g., "main" → "refs/heads/main").
|
|
27
|
+
*/
|
|
28
|
+
create(params: CreatePullRequestParams): Promise<RestPullRequest>;
|
|
29
|
+
/**
|
|
30
|
+
* Get all changed files in a pull request
|
|
31
|
+
*/
|
|
32
|
+
getChanges(params: GetPullRequestChangesParams): Promise<ChangesResponse>;
|
|
33
|
+
/**
|
|
34
|
+
* Get structured line-by-line diff for a specific file in a pull request
|
|
35
|
+
*/
|
|
36
|
+
getFileDiff(params: GetPullRequestFileDiffParams): Promise<DiffResponse>;
|
|
37
|
+
/**
|
|
38
|
+
* Get diff for a pull request (or specific file).
|
|
39
|
+
* When path is empty or undefined, returns the full PR diff.
|
|
40
|
+
* Format controls the response type:
|
|
41
|
+
* - 'text': Raw diff as plain text string
|
|
42
|
+
* - 'json': Structured diff object (DiffResponse)
|
|
43
|
+
*/
|
|
44
|
+
getDiff(params: GetPullRequestDiffParams): Promise<string | DiffResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* Get activity on a pull request (comments, approvals, merges, reviews, updates)
|
|
47
|
+
*/
|
|
48
|
+
getActivities(params: GetPullRequestActivitiesParams): Promise<PaginatedResponse<RestPullRequestActivityApiResponse>>;
|
|
49
|
+
/**
|
|
50
|
+
* Add a comment to a pull request (supports general comments, replies, and inline file/line comments)
|
|
51
|
+
*/
|
|
52
|
+
addComment(params: AddPullRequestCommentParams): Promise<RestComment>;
|
|
53
|
+
/**
|
|
54
|
+
* Delete a pull request comment. Returns void on success (HTTP 204).
|
|
55
|
+
* Anyone can delete their own comment. Only REPO_ADMIN can delete others' comments.
|
|
56
|
+
* Comments with replies cannot be deleted.
|
|
57
|
+
*/
|
|
58
|
+
deleteComment(params: DeletePullRequestCommentParams): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Update review status for a pull request (approve, request changes, or remove approval)
|
|
61
|
+
*/
|
|
62
|
+
updateReviewStatus(params: UpdateReviewStatusParams): Promise<RestPullRequestParticipant>;
|
|
63
|
+
/**
|
|
64
|
+
* Add an emoticon reaction to a pull request comment
|
|
65
|
+
*/
|
|
66
|
+
addReaction(params: AddPullRequestCommentReactionParams): Promise<RestUserReaction>;
|
|
67
|
+
/**
|
|
68
|
+
* Remove an emoticon reaction from a pull request comment
|
|
69
|
+
*/
|
|
70
|
+
removeReaction(params: RemovePullRequestCommentReactionParams): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Get the list of required/default reviewers for a pull request.
|
|
73
|
+
* Returns users who would be automatically assigned as reviewers based on configured rules.
|
|
74
|
+
* Note: Default reviewers are NOT auto-added when creating PRs via API - you must
|
|
75
|
+
* fetch them with this method and pass them to create().
|
|
76
|
+
* Branch names are automatically converted to full refs (e.g., "main" → "refs/heads/main").
|
|
77
|
+
* Use repositories.get() to obtain the repositoryId.
|
|
78
|
+
*/
|
|
79
|
+
getRequiredReviewers(params: GetRequiredReviewersParams): Promise<RestUser[]>;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=pull-requests.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pull-requests.d.ts","sourceRoot":"","sources":["../../src/api/pull-requests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,E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iB,CAAC,kCAAkC,CAAC,CAAC;IASjE;;OAEG;IACU,UAAU,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,WAAW,CAAC;IAsBlF;;;;OAIG;IACU,aAAa,CAAC,MAAM,EAAE,8BAA8B,GAAG,OAAO,CAAC,IAAI,CAAC;IAWjF;;OAEG;IACU,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,0BAA0B,CAAC;IActG;;OAEG;IACU,WAAW,CAAC,MAAM,EAAE,mCAAmC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAchG;;OAEG;IACU,cAAc,CAAC,MAAM,EAAE,sCAAsC,GAAG,OAAO,CAAC,IAAI,CAAC;IAY1F;;;;;;;OAOG;IACU,oBAAoB,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;CAsB3F"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { BaseApi } from './base.js';
|
|
2
|
+
/**
|
|
3
|
+
* Pull Requests API for Bitbucket Server.
|
|
4
|
+
* Provides methods for pull request-related operations.
|
|
5
|
+
*/
|
|
6
|
+
export class PullRequestsApi extends BaseApi {
|
|
7
|
+
/**
|
|
8
|
+
* Get pull requests in the authenticated user's inbox (where they are assigned as reviewer)
|
|
9
|
+
*/
|
|
10
|
+
async getInbox(params) {
|
|
11
|
+
const response = await this.client.get('/inbox/pull-requests', { params });
|
|
12
|
+
return response.data;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get pull requests from the user's dashboard.
|
|
16
|
+
* Can filter by role (AUTHOR, REVIEWER, PARTICIPANT), state, and more.
|
|
17
|
+
*/
|
|
18
|
+
async getDashboard(params) {
|
|
19
|
+
const response = await this.client.get('/dashboard/pull-requests', {
|
|
20
|
+
params: {
|
|
21
|
+
role: 'AUTHOR',
|
|
22
|
+
state: 'OPEN',
|
|
23
|
+
order: 'NEWEST',
|
|
24
|
+
...params,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return response.data;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get pull request details (title, description, author, branches, etc.)
|
|
31
|
+
*/
|
|
32
|
+
async get(params) {
|
|
33
|
+
const { projectKey, repositorySlug, pullRequestId } = params;
|
|
34
|
+
const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}`);
|
|
35
|
+
return response.data;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create a new pull request.
|
|
39
|
+
* Supports both same-repo PRs (default) and cross-repo PRs (when fromRepositorySlug is provided).
|
|
40
|
+
* Branch names are automatically converted to full refs (e.g., "main" → "refs/heads/main").
|
|
41
|
+
*/
|
|
42
|
+
async create(params) {
|
|
43
|
+
const { projectKey, repositorySlug, title, description, fromBranch, toBranch, fromRepositorySlug, fromProjectKey, reviewers, draft, } = params;
|
|
44
|
+
// Convert branch names to full refs if needed
|
|
45
|
+
const toRefId = (branch) => (branch.startsWith('refs/') ? branch : `refs/heads/${branch}`);
|
|
46
|
+
const body = {
|
|
47
|
+
title,
|
|
48
|
+
...(description && { description }),
|
|
49
|
+
fromRef: {
|
|
50
|
+
id: toRefId(fromBranch),
|
|
51
|
+
...(fromRepositorySlug && {
|
|
52
|
+
repository: {
|
|
53
|
+
slug: fromRepositorySlug,
|
|
54
|
+
project: { key: fromProjectKey || projectKey },
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
toRef: {
|
|
59
|
+
id: toRefId(toBranch),
|
|
60
|
+
},
|
|
61
|
+
...(reviewers &&
|
|
62
|
+
reviewers.length > 0 && {
|
|
63
|
+
reviewers: reviewers.map((username) => ({ user: { name: username } })),
|
|
64
|
+
}),
|
|
65
|
+
...(draft !== undefined && { draft }),
|
|
66
|
+
};
|
|
67
|
+
const response = await this.client.post(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests`, body);
|
|
68
|
+
return response.data;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get all changed files in a pull request
|
|
72
|
+
*/
|
|
73
|
+
async getChanges(params) {
|
|
74
|
+
const { projectKey, repositorySlug, pullRequestId, limit } = params;
|
|
75
|
+
const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/changes`, { params: limit ? { limit } : {} });
|
|
76
|
+
return response.data;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get structured line-by-line diff for a specific file in a pull request
|
|
80
|
+
*/
|
|
81
|
+
async getFileDiff(params) {
|
|
82
|
+
const { projectKey, repositorySlug, pullRequestId, path, contextLines } = params;
|
|
83
|
+
const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/diff/${path}`, { params: contextLines ? { contextLines } : {} });
|
|
84
|
+
return response.data;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get diff for a pull request (or specific file).
|
|
88
|
+
* When path is empty or undefined, returns the full PR diff.
|
|
89
|
+
* Format controls the response type:
|
|
90
|
+
* - 'text': Raw diff as plain text string
|
|
91
|
+
* - 'json': Structured diff object (DiffResponse)
|
|
92
|
+
*/
|
|
93
|
+
async getDiff(params) {
|
|
94
|
+
const { projectKey, repositorySlug, pullRequestId, path, sinceId, untilId, contextLines, whitespace, format = 'text', } = params;
|
|
95
|
+
const queryParams = {};
|
|
96
|
+
if (sinceId)
|
|
97
|
+
queryParams['sinceId'] = sinceId;
|
|
98
|
+
if (untilId)
|
|
99
|
+
queryParams['untilId'] = untilId;
|
|
100
|
+
if (contextLines !== undefined)
|
|
101
|
+
queryParams['contextLines'] = contextLines;
|
|
102
|
+
if (whitespace)
|
|
103
|
+
queryParams['whitespace'] = whitespace;
|
|
104
|
+
const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/diff/${path || ''}`, {
|
|
105
|
+
params: queryParams,
|
|
106
|
+
headers: { Accept: format === 'text' ? 'text/plain' : 'application/json' },
|
|
107
|
+
});
|
|
108
|
+
return response.data;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get activity on a pull request (comments, approvals, merges, reviews, updates)
|
|
112
|
+
*/
|
|
113
|
+
async getActivities(params) {
|
|
114
|
+
const { projectKey, repositorySlug, pullRequestId, ...queryParams } = params;
|
|
115
|
+
const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/activities`, { params: queryParams });
|
|
116
|
+
return response.data;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Add a comment to a pull request (supports general comments, replies, and inline file/line comments)
|
|
120
|
+
*/
|
|
121
|
+
async addComment(params) {
|
|
122
|
+
const { projectKey, repositorySlug, pullRequestId, text, parentId, path, line, lineType, fileType } = params;
|
|
123
|
+
const body = { text };
|
|
124
|
+
if (parentId)
|
|
125
|
+
body.parent = { id: parentId };
|
|
126
|
+
if (path) {
|
|
127
|
+
body.anchor = {
|
|
128
|
+
path,
|
|
129
|
+
diffType: 'EFFECTIVE',
|
|
130
|
+
...(line !== undefined && { line }),
|
|
131
|
+
...(lineType && { lineType }),
|
|
132
|
+
...(fileType && { fileType }),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const response = await this.client.post(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/comments`, body);
|
|
136
|
+
return response.data;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Delete a pull request comment. Returns void on success (HTTP 204).
|
|
140
|
+
* Anyone can delete their own comment. Only REPO_ADMIN can delete others' comments.
|
|
141
|
+
* Comments with replies cannot be deleted.
|
|
142
|
+
*/
|
|
143
|
+
async deleteComment(params) {
|
|
144
|
+
const { projectKey, repositorySlug, pullRequestId, commentId, version } = params;
|
|
145
|
+
await this.client.delete(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/comments/${commentId}`, {
|
|
146
|
+
params: { version },
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Update review status for a pull request (approve, request changes, or remove approval)
|
|
151
|
+
*/
|
|
152
|
+
async updateReviewStatus(params) {
|
|
153
|
+
const { projectKey, repositorySlug, pullRequestId, status } = params;
|
|
154
|
+
// Get authenticated user slug from application properties
|
|
155
|
+
const propertiesResponse = await this.client.get('/application-properties');
|
|
156
|
+
const userSlug = propertiesResponse.headers['x-ausername'];
|
|
157
|
+
const response = await this.client.put(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/participants/${userSlug}`, { status });
|
|
158
|
+
return response.data;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Add an emoticon reaction to a pull request comment
|
|
162
|
+
*/
|
|
163
|
+
async addReaction(params) {
|
|
164
|
+
const { projectKey, repositorySlug, pullRequestId, commentId, emoticon } = params;
|
|
165
|
+
// Use comment-likes plugin API endpoint
|
|
166
|
+
const response = await this.client.put(`/comment-likes/latest/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/comments/${commentId}/reactions/${emoticon}`, {}, {
|
|
167
|
+
baseURL: this.client.defaults.baseURL?.replace('/rest/api/latest', '/rest'),
|
|
168
|
+
});
|
|
169
|
+
return response.data;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Remove an emoticon reaction from a pull request comment
|
|
173
|
+
*/
|
|
174
|
+
async removeReaction(params) {
|
|
175
|
+
const { projectKey, repositorySlug, pullRequestId, commentId, emoticon } = params;
|
|
176
|
+
// Use comment-likes plugin API endpoint
|
|
177
|
+
await this.client.delete(`/comment-likes/latest/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/comments/${commentId}/reactions/${emoticon}`, {
|
|
178
|
+
baseURL: this.client.defaults.baseURL?.replace('/rest/api/latest', '/rest'),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Get the list of required/default reviewers for a pull request.
|
|
183
|
+
* Returns users who would be automatically assigned as reviewers based on configured rules.
|
|
184
|
+
* Note: Default reviewers are NOT auto-added when creating PRs via API - you must
|
|
185
|
+
* fetch them with this method and pass them to create().
|
|
186
|
+
* Branch names are automatically converted to full refs (e.g., "main" → "refs/heads/main").
|
|
187
|
+
* Use repositories.get() to obtain the repositoryId.
|
|
188
|
+
*/
|
|
189
|
+
async getRequiredReviewers(params) {
|
|
190
|
+
const { projectKey, repositorySlug, repositoryId, sourceBranch, targetBranch } = params;
|
|
191
|
+
// Convert branch names to full refs if needed
|
|
192
|
+
const toRefId = (branch) => (branch.startsWith('refs/') ? branch : `refs/heads/${branch}`);
|
|
193
|
+
// Uses /default-reviewers/latest base path (not /rest/api/latest)
|
|
194
|
+
const response = await this.client.get(`/default-reviewers/latest/projects/${projectKey}/repos/${repositorySlug}/reviewers`, {
|
|
195
|
+
params: {
|
|
196
|
+
sourceRepoId: repositoryId,
|
|
197
|
+
targetRepoId: repositoryId,
|
|
198
|
+
sourceRefId: toRefId(sourceBranch),
|
|
199
|
+
targetRefId: toRefId(targetBranch),
|
|
200
|
+
},
|
|
201
|
+
baseURL: this.client.defaults.baseURL?.replace('/rest/api/latest', '/rest'),
|
|
202
|
+
});
|
|
203
|
+
return response.data;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=pull-requests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pull-requests.js","sourceRoot":"","sources":["../../src/api/pull-requests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8BpC;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,OAAO;IAC1C;;OAEG;IACI,KAAK,CAAC,QAAQ,CAAC,MAAmC;QACvD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAsC,sBAAsB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAChH,OAAO,QAAQ,CAAC,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ositoryPermissionsParams, GetRawContentParams, GetRepositoryParams, ListRepositoriesParams, RepositoriesResponse, RepositoryPermissions, RestRepository } from '../types/repository.js';
|
|
3
|
+
/**
|
|
4
|
+
* Repositories API for Bitbucket Server.
|
|
5
|
+
* Provides methods for repository-related operations.
|
|
6
|
+
*/
|
|
7
|
+
export declare class RepositoriesApi extends BaseApi {
|
|
8
|
+
/**
|
|
9
|
+
* List all repositories in a project
|
|
10
|
+
*/
|
|
11
|
+
list(params: ListRepositoriesParams): Promise<RepositoriesResponse>;
|
|
12
|
+
/**
|
|
13
|
+
* Get a repository by project key and slug
|
|
14
|
+
*/
|
|
15
|
+
get(params: GetRepositoryParams): Promise<RestRepository>;
|
|
16
|
+
/**
|
|
17
|
+
* Browse repository contents at a given path (structured JSON response).
|
|
18
|
+
* Returns different response based on path type:
|
|
19
|
+
* - Directory: { children: [...] } with file/folder entries
|
|
20
|
+
* - File: { lines: [...] } with file content
|
|
21
|
+
* Check 'children' in response to determine type.
|
|
22
|
+
*/
|
|
23
|
+
browse(params: BrowseParams): Promise<BrowseResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* Get raw content from repository (plain text).
|
|
26
|
+
* Returns file content as plain text, or git tree listing for directories.
|
|
27
|
+
*/
|
|
28
|
+
getRawContent(params: GetRawContentParams): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Check repository permissions for the authenticated token.
|
|
31
|
+
* Returns read/write access flags without modifying anything.
|
|
32
|
+
*/
|
|
33
|
+
checkPermissions(params: CheckRepositoryPermissionsParams): Promise<RepositoryPermissions>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=repositories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repositories.d.ts","sourceRoot":"","sources":["../../src/api/repositories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,gCAAgC,EAChC,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACf,MAAM,wBAAwB,CAAC;AAEhC;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,OAAO;IAC1C;;OAEG;IACU,IAAI,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAKhF;;OAEG;IACU,GAAG,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,cAAc,CAAC;IAMtE;;;;;;OAMG;IACU,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IAelE;;;OAGG;IACU,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC;IAaxE;;;OAGG;IACU,gBAAgB,CAAC,MAAM,EAAE,gCAAgC,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAyBxG"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { BaseApi } from './base.js';
|
|
2
|
+
/**
|
|
3
|
+
* Repositories API for Bitbucket Server.
|
|
4
|
+
* Provides methods for repository-related operations.
|
|
5
|
+
*/
|
|
6
|
+
export class RepositoriesApi extends BaseApi {
|
|
7
|
+
/**
|
|
8
|
+
* List all repositories in a project
|
|
9
|
+
*/
|
|
10
|
+
async list(params) {
|
|
11
|
+
const response = await this.client.get(`/projects/${params.projectKey}/repos`);
|
|
12
|
+
return response.data;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get a repository by project key and slug
|
|
16
|
+
*/
|
|
17
|
+
async get(params) {
|
|
18
|
+
const { projectKey, repositorySlug } = params;
|
|
19
|
+
const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}`);
|
|
20
|
+
return response.data;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Browse repository contents at a given path (structured JSON response).
|
|
24
|
+
* Returns different response based on path type:
|
|
25
|
+
* - Directory: { children: [...] } with file/folder entries
|
|
26
|
+
* - File: { lines: [...] } with file content
|
|
27
|
+
* Check 'children' in response to determine type.
|
|
28
|
+
*/
|
|
29
|
+
async browse(params) {
|
|
30
|
+
const { projectKey, repositorySlug, path, at, limit, start } = params;
|
|
31
|
+
const queryParams = {};
|
|
32
|
+
if (at)
|
|
33
|
+
queryParams['at'] = at;
|
|
34
|
+
if (limit !== undefined)
|
|
35
|
+
queryParams['limit'] = limit;
|
|
36
|
+
if (start !== undefined)
|
|
37
|
+
queryParams['start'] = start;
|
|
38
|
+
const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/browse/${path || ''}`, { params: queryParams });
|
|
39
|
+
return response.data;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get raw content from repository (plain text).
|
|
43
|
+
* Returns file content as plain text, or git tree listing for directories.
|
|
44
|
+
*/
|
|
45
|
+
async getRawContent(params) {
|
|
46
|
+
const { projectKey, repositorySlug, path, at } = params;
|
|
47
|
+
const queryParams = {};
|
|
48
|
+
if (at)
|
|
49
|
+
queryParams['at'] = at;
|
|
50
|
+
const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/raw/${path}`, {
|
|
51
|
+
params: queryParams,
|
|
52
|
+
headers: { Accept: 'text/plain' },
|
|
53
|
+
});
|
|
54
|
+
return response.data;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check repository permissions for the authenticated token.
|
|
58
|
+
* Returns read/write access flags without modifying anything.
|
|
59
|
+
*/
|
|
60
|
+
async checkPermissions(params) {
|
|
61
|
+
const { projectKey, repositorySlug } = params;
|
|
62
|
+
const repoPath = `/projects/${projectKey}/repos/${repositorySlug}`;
|
|
63
|
+
// Check READ permission
|
|
64
|
+
try {
|
|
65
|
+
await this.client.get(repoPath);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return { read: false, write: false };
|
|
69
|
+
}
|
|
70
|
+
// Check WRITE permission (try creating branch with invalid body)
|
|
71
|
+
try {
|
|
72
|
+
await this.client.post(`${repoPath}/branches`, {});
|
|
73
|
+
return { read: true, write: true }; // Unlikely path
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
// Validation error ("name field is required") = has write
|
|
77
|
+
// Permission error = no write
|
|
78
|
+
const message = error?.response?.data?.errors?.[0]
|
|
79
|
+
?.message || '';
|
|
80
|
+
const write = message.includes('name') && message.includes('required');
|
|
81
|
+
return { read: true, write };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=repositories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repositories.js","sourceRoot":"","sources":["../../src/api/repositories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAapC;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,OAAO;IAC1C;;OAEG;IACI,KAAK,CAAC,IAAI,CAAC,MAA8B;QAC9C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAuB,aAAa,MAAM,CAAC,UAAU,QAAQ,CAAC,CAAC;QACrG,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,GAAG,CAAC,MAA2B;QAC1C,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;QAC9C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAiB,aAAa,UAAU,UAAU,cAAc,EAAE,CAAC,CAAC;QAC1G,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,MAAM,CAAC,MAAoB;QACtC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;QAEtE,MAAM,WAAW,GAAoC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