jira-datacenter-api-client 1.0.0
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/LICENSE +21 -0
- package/README.md +274 -0
- package/dist/index.d.mts +1929 -0
- package/dist/index.d.ts +1929 -0
- package/dist/index.js +886 -0
- package/dist/index.mjs +863 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 el_jijuna
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# Jira Data Center API Client
|
|
2
|
+
|
|
3
|
+
A zero-dependency TypeScript client for the **Jira Data Center REST API** (and Jira Software Agile API).
|
|
4
|
+
|
|
5
|
+
[](https://github.com/ElJijuna/JiraDataCenterApiClient/actions/workflows/ci.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/jira-datacenter-api-client)
|
|
7
|
+
[](./LICENSE)
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Full TypeScript** — every request and response is fully typed
|
|
12
|
+
- **Read-only** — covers all major GET endpoints for issues, projects, boards, sprints, users, and metadata
|
|
13
|
+
- **Chainable resources** — `jira.issue('PROJ-42').comments()` pattern
|
|
14
|
+
- **Dual package** — ships CJS + ESM, works in Node.js and browsers
|
|
15
|
+
- **Zero runtime dependencies** — uses native `fetch` and `URLSearchParams`
|
|
16
|
+
- **Request events** — hook into every HTTP request for logging and monitoring
|
|
17
|
+
- **Semantic versioning** — automated releases via Conventional Commits
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install jira-datacenter-api-client
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { JiraClient } from 'jira-datacenter-api-client';
|
|
29
|
+
|
|
30
|
+
const jira = new JiraClient({
|
|
31
|
+
apiUrl: 'https://jira.example.com',
|
|
32
|
+
user: 'my-username',
|
|
33
|
+
token: 'my-personal-access-token',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Search issues with JQL
|
|
37
|
+
const results = await jira.search({
|
|
38
|
+
jql: 'project = PROJ AND status = Open ORDER BY created DESC',
|
|
39
|
+
maxResults: 50,
|
|
40
|
+
});
|
|
41
|
+
console.log(results.total, 'issues found');
|
|
42
|
+
|
|
43
|
+
// Get a single issue
|
|
44
|
+
const issue = await jira.issue('PROJ-42');
|
|
45
|
+
console.log(issue.fields.summary);
|
|
46
|
+
|
|
47
|
+
// Get issue comments
|
|
48
|
+
const { comments } = await jira.issue('PROJ-42').comments();
|
|
49
|
+
|
|
50
|
+
// Get issue changelog
|
|
51
|
+
const changelog = await jira.issue('PROJ-42').changelog();
|
|
52
|
+
|
|
53
|
+
// Get a project with its components
|
|
54
|
+
const project = await jira.project('PROJ');
|
|
55
|
+
const components = await jira.project('PROJ').components();
|
|
56
|
+
|
|
57
|
+
// Get board sprints
|
|
58
|
+
const sprints = await jira.board(42).sprints({ state: 'active' });
|
|
59
|
+
|
|
60
|
+
// Get sprint issues
|
|
61
|
+
const sprintIssues = await jira.board(42).sprint(10).issues();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Authentication
|
|
65
|
+
|
|
66
|
+
The client uses **HTTP Basic Authentication** with a username and personal access token (PAT):
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const jira = new JiraClient({
|
|
70
|
+
apiUrl: 'https://jira.example.com',
|
|
71
|
+
user: 'my-username',
|
|
72
|
+
token: 'my-personal-access-token',
|
|
73
|
+
// Optional — defaults shown:
|
|
74
|
+
apiPath: 'rest/api/latest',
|
|
75
|
+
agileApiPath: 'rest/agile/latest',
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
To generate a personal access token, go to **Jira → Profile → Personal Access Tokens**.
|
|
80
|
+
|
|
81
|
+
## API Reference
|
|
82
|
+
|
|
83
|
+
### `JiraClient`
|
|
84
|
+
|
|
85
|
+
The main client. All methods return Promises.
|
|
86
|
+
|
|
87
|
+
#### Issues
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
// Search with JQL (GET)
|
|
91
|
+
await jira.search({ jql: 'project = PROJ', maxResults: 50, fields: 'summary,status' });
|
|
92
|
+
|
|
93
|
+
// Search with POST (supports larger field lists)
|
|
94
|
+
await jira.searchPost({ jql: 'project = PROJ', fields: ['summary', 'status', 'assignee'] });
|
|
95
|
+
|
|
96
|
+
// Get issue (await directly or call .get())
|
|
97
|
+
const issue = await jira.issue('PROJ-42');
|
|
98
|
+
const issue = await jira.issue('PROJ-42').get({ fields: 'summary,status,assignee' });
|
|
99
|
+
|
|
100
|
+
// Issue sub-resources
|
|
101
|
+
await jira.issue('PROJ-42').comments({ maxResults: 20 });
|
|
102
|
+
await jira.issue('PROJ-42').comment('10001');
|
|
103
|
+
await jira.issue('PROJ-42').worklogs();
|
|
104
|
+
await jira.issue('PROJ-42').worklog('20001');
|
|
105
|
+
await jira.issue('PROJ-42').changelog({ maxResults: 50 });
|
|
106
|
+
await jira.issue('PROJ-42').transitions();
|
|
107
|
+
await jira.issue('PROJ-42').remotelinks();
|
|
108
|
+
await jira.issue('PROJ-42').votes();
|
|
109
|
+
await jira.issue('PROJ-42').watchers();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### Projects
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
// List all projects
|
|
116
|
+
await jira.projects({ expand: 'description,lead' });
|
|
117
|
+
|
|
118
|
+
// Get a single project (await directly or call .get())
|
|
119
|
+
const project = await jira.project('PROJ');
|
|
120
|
+
|
|
121
|
+
// Project sub-resources
|
|
122
|
+
await jira.project('PROJ').components();
|
|
123
|
+
await jira.project('PROJ').versions();
|
|
124
|
+
await jira.project('PROJ').statuses(); // grouped by issue type
|
|
125
|
+
await jira.project('PROJ').roles(); // role name → URL map
|
|
126
|
+
await jira.project('PROJ').role(10002); // role with actors
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
#### Boards & Sprints (Jira Software)
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
// List boards
|
|
133
|
+
await jira.boards({ type: 'scrum', name: 'PROJ Board' });
|
|
134
|
+
|
|
135
|
+
// Get a board (await directly or chain)
|
|
136
|
+
const board = await jira.board(42);
|
|
137
|
+
|
|
138
|
+
// Board sub-resources
|
|
139
|
+
await jira.board(42).sprints({ state: 'active' });
|
|
140
|
+
await jira.board(42).issues({ jql: 'status = "In Progress"' });
|
|
141
|
+
await jira.board(42).backlog({ maxResults: 50 });
|
|
142
|
+
|
|
143
|
+
// Sprint sub-resources
|
|
144
|
+
const sprint = await jira.board(42).sprint(10);
|
|
145
|
+
await jira.board(42).sprint(10).issues({ maxResults: 100 });
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Users
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
await jira.currentUser();
|
|
152
|
+
await jira.user('pilmee');
|
|
153
|
+
await jira.users({ username: 'john', maxResults: 10 });
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### Metadata
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
await jira.issuetypes();
|
|
160
|
+
await jira.issuetype('1');
|
|
161
|
+
await jira.priorities();
|
|
162
|
+
await jira.priority('3');
|
|
163
|
+
await jira.statuses();
|
|
164
|
+
await jira.status('In Progress');
|
|
165
|
+
await jira.fields();
|
|
166
|
+
await jira.issueLinkTypes();
|
|
167
|
+
await jira.favouriteFilters();
|
|
168
|
+
await jira.filter('10000');
|
|
169
|
+
await jira.component('10001');
|
|
170
|
+
await jira.version('20001');
|
|
171
|
+
await jira.versionIssueCounts('20001');
|
|
172
|
+
await jira.versionUnresolvedIssueCount('20001');
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Pagination
|
|
176
|
+
|
|
177
|
+
Most list endpoints return a paginated response:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
interface PagedResponse<T> {
|
|
181
|
+
startAt: number;
|
|
182
|
+
maxResults: number;
|
|
183
|
+
total: number;
|
|
184
|
+
isLast?: boolean; // Agile endpoints
|
|
185
|
+
values: T[];
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
To iterate through pages:
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
let startAt = 0;
|
|
193
|
+
const maxResults = 50;
|
|
194
|
+
let allIssues: JiraIssue[] = [];
|
|
195
|
+
|
|
196
|
+
while (true) {
|
|
197
|
+
const page = await jira.search({ jql: 'project = PROJ', startAt, maxResults });
|
|
198
|
+
allIssues = allIssues.concat(page.issues);
|
|
199
|
+
if (page.startAt + page.issues.length >= page.total) break;
|
|
200
|
+
startAt += maxResults;
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Request Events
|
|
205
|
+
|
|
206
|
+
Subscribe to every HTTP request for logging, metrics, or debugging:
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
jira.on('request', (event) => {
|
|
210
|
+
console.log(`[${event.method}] ${event.url} — ${event.durationMs}ms (${event.statusCode})`);
|
|
211
|
+
if (event.error) {
|
|
212
|
+
console.error('Request failed:', event.error.message);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**Event payload:**
|
|
218
|
+
|
|
219
|
+
| Field | Type | Description |
|
|
220
|
+
|-------|------|-------------|
|
|
221
|
+
| `url` | `string` | Full URL requested |
|
|
222
|
+
| `method` | `'GET' \| 'POST'` | HTTP method |
|
|
223
|
+
| `startedAt` | `Date` | Request start timestamp |
|
|
224
|
+
| `finishedAt` | `Date` | Request end timestamp |
|
|
225
|
+
| `durationMs` | `number` | Duration in milliseconds |
|
|
226
|
+
| `statusCode` | `number?` | HTTP status code |
|
|
227
|
+
| `error` | `Error?` | Error object if the request failed |
|
|
228
|
+
|
|
229
|
+
## Error Handling
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { JiraApiError } from 'jira-datacenter-api-client';
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
await jira.issue('PROJ-9999');
|
|
236
|
+
} catch (err) {
|
|
237
|
+
if (err instanceof JiraApiError) {
|
|
238
|
+
console.log(err.status); // 404
|
|
239
|
+
console.log(err.statusText); // 'Not Found'
|
|
240
|
+
console.log(err.message); // 'Jira API error: 404 Not Found'
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## TypeScript Types
|
|
246
|
+
|
|
247
|
+
All domain types are exported:
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import type {
|
|
251
|
+
JiraIssue,
|
|
252
|
+
JiraIssueFields,
|
|
253
|
+
JiraProject,
|
|
254
|
+
JiraUser,
|
|
255
|
+
JiraComment,
|
|
256
|
+
JiraWorklog,
|
|
257
|
+
JiraChangelogEntry,
|
|
258
|
+
JiraTransition,
|
|
259
|
+
JiraBoard,
|
|
260
|
+
JiraSprint,
|
|
261
|
+
JiraSearchResponse,
|
|
262
|
+
SearchParams,
|
|
263
|
+
PagedResponse,
|
|
264
|
+
// ... and many more
|
|
265
|
+
} from 'jira-datacenter-api-client';
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Contributing
|
|
269
|
+
|
|
270
|
+
See [CONTRIBUTING.md](./.github/CONTRIBUTING.md) for development guidelines.
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
[MIT](./LICENSE)
|