@felixgeelhaar/jira-sdk 0.2.0 → 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/README.md +214 -374
- package/dist/auth/index.cjs +400 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +192 -0
- package/dist/auth/index.d.ts +192 -0
- package/dist/auth/index.js +386 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/errors/index.cjs +272 -0
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.d.cts +203 -0
- package/dist/errors/index.d.ts +203 -0
- package/dist/errors/index.js +254 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/http-client-BSzRYQZa.d.cts +317 -0
- package/dist/http-client-erRvYNs-.d.ts +317 -0
- package/dist/index.cjs +9582 -13466
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1242 -76
- package/dist/index.d.ts +1242 -76
- package/dist/index.js +9166 -13318
- package/dist/index.js.map +1 -1
- package/dist/schemas/index.cjs +2481 -13092
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +335 -207
- package/dist/schemas/index.d.ts +335 -207
- package/dist/schemas/index.js +2138 -13047
- package/dist/schemas/index.js.map +1 -1
- package/dist/services/index.cjs +6375 -13323
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +3852 -299
- package/dist/services/index.d.ts +3852 -299
- package/dist/services/index.js +6350 -13321
- package/dist/services/index.js.map +1 -1
- package/dist/transport/index.cjs +1016 -0
- package/dist/transport/index.cjs.map +1 -0
- package/dist/transport/index.d.cts +372 -0
- package/dist/transport/index.d.ts +372 -0
- package/dist/transport/index.js +997 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/types-E6djPHpW.d.cts +95 -0
- package/dist/types-E6djPHpW.d.ts +95 -0
- package/dist/webhook-Bn8gme6Y.d.cts +6959 -0
- package/dist/webhook-Bn8gme6Y.d.ts +6959 -0
- package/package.json +73 -27
- package/dist/project-BtUx-eSv.d.cts +0 -1480
- package/dist/project-BtUx-eSv.d.ts +0 -1480
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { g as MiddlewareContext, M as Middleware } from '../http-client-erRvYNs-.js';
|
|
2
|
+
export { H as HttpClient, c as HttpClientConfig, d as HttpMethod, e as HttpRequest, f as HttpResponse, L as Logger, h as MiddlewareNext, Q as QueryParamValue, R as RequestOptions, i as createHttpClient } from '../http-client-erRvYNs-.js';
|
|
3
|
+
import '../types-E6djPHpW.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Logging middleware configuration
|
|
8
|
+
*/
|
|
9
|
+
interface LoggingMiddlewareConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Log request details
|
|
12
|
+
*/
|
|
13
|
+
logRequests?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Log response details
|
|
16
|
+
*/
|
|
17
|
+
logResponses?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Log errors
|
|
20
|
+
*/
|
|
21
|
+
logErrors?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Redact sensitive headers (authorization, etc.)
|
|
24
|
+
*/
|
|
25
|
+
redactHeaders?: string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a logging middleware
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const client = new HttpClient({
|
|
33
|
+
* baseUrl: '...',
|
|
34
|
+
* middleware: [
|
|
35
|
+
* createLoggingMiddleware({ logRequests: true, logResponses: true }),
|
|
36
|
+
* ],
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function createLoggingMiddleware(config?: LoggingMiddlewareConfig): Middleware;
|
|
41
|
+
/**
|
|
42
|
+
* Retry middleware configuration
|
|
43
|
+
*/
|
|
44
|
+
interface RetryMiddlewareConfig {
|
|
45
|
+
/**
|
|
46
|
+
* Maximum number of retries (default: 3)
|
|
47
|
+
*/
|
|
48
|
+
maxRetries?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Initial delay in ms (default: 1000)
|
|
51
|
+
*/
|
|
52
|
+
initialDelayMs?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Maximum delay in ms (default: 30000)
|
|
55
|
+
*/
|
|
56
|
+
maxDelayMs?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Backoff multiplier (default: 2)
|
|
59
|
+
*/
|
|
60
|
+
multiplier?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Add random jitter (default: true)
|
|
63
|
+
*/
|
|
64
|
+
jitter?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Custom retry condition
|
|
67
|
+
*/
|
|
68
|
+
shouldRetry?: (error: unknown, context: MiddlewareContext) => boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a retry middleware with exponential backoff
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const client = new HttpClient({
|
|
76
|
+
* baseUrl: '...',
|
|
77
|
+
* middleware: [
|
|
78
|
+
* createRetryMiddleware({ maxRetries: 3 }),
|
|
79
|
+
* ],
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare function createRetryMiddleware(config?: RetryMiddlewareConfig): Middleware;
|
|
84
|
+
/**
|
|
85
|
+
* Rate limit middleware configuration
|
|
86
|
+
*/
|
|
87
|
+
interface RateLimitMiddlewareConfig {
|
|
88
|
+
/**
|
|
89
|
+
* Maximum requests per window
|
|
90
|
+
*/
|
|
91
|
+
maxRequests: number;
|
|
92
|
+
/**
|
|
93
|
+
* Window duration in ms
|
|
94
|
+
*/
|
|
95
|
+
windowMs: number;
|
|
96
|
+
/**
|
|
97
|
+
* Wait for slot instead of throwing error
|
|
98
|
+
*/
|
|
99
|
+
waitForSlot?: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create a client-side rate limiting middleware
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const client = new HttpClient({
|
|
107
|
+
* baseUrl: '...',
|
|
108
|
+
* middleware: [
|
|
109
|
+
* createRateLimitMiddleware({ maxRequests: 100, windowMs: 60000 }),
|
|
110
|
+
* ],
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare function createRateLimitMiddleware(config: RateLimitMiddlewareConfig): Middleware;
|
|
115
|
+
/**
|
|
116
|
+
* Request ID middleware - adds a unique ID to each request
|
|
117
|
+
*/
|
|
118
|
+
declare function createRequestIdMiddleware(headerName?: string): Middleware;
|
|
119
|
+
/**
|
|
120
|
+
* User-Agent middleware configuration
|
|
121
|
+
*/
|
|
122
|
+
interface UserAgentMiddlewareConfig {
|
|
123
|
+
/**
|
|
124
|
+
* SDK name
|
|
125
|
+
*/
|
|
126
|
+
sdkName: string;
|
|
127
|
+
/**
|
|
128
|
+
* SDK version
|
|
129
|
+
*/
|
|
130
|
+
sdkVersion: string;
|
|
131
|
+
/**
|
|
132
|
+
* Additional user agent suffix
|
|
133
|
+
*/
|
|
134
|
+
suffix?: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Create a User-Agent middleware
|
|
138
|
+
*/
|
|
139
|
+
declare function createUserAgentMiddleware(config: UserAgentMiddlewareConfig): Middleware;
|
|
140
|
+
/**
|
|
141
|
+
* Compose multiple middleware into a single middleware
|
|
142
|
+
*/
|
|
143
|
+
declare function composeMiddleware(...middlewares: Middleware[]): Middleware;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Circuit breaker states
|
|
147
|
+
*/
|
|
148
|
+
declare enum CircuitState {
|
|
149
|
+
CLOSED = "CLOSED",// Normal operation, requests flow through
|
|
150
|
+
OPEN = "OPEN",// Circuit is open, requests fail fast
|
|
151
|
+
HALF_OPEN = "HALF_OPEN"
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Circuit breaker configuration
|
|
155
|
+
*/
|
|
156
|
+
interface CircuitBreakerConfig {
|
|
157
|
+
/**
|
|
158
|
+
* Number of failures before opening the circuit (default: 5)
|
|
159
|
+
*/
|
|
160
|
+
failureThreshold?: number;
|
|
161
|
+
/**
|
|
162
|
+
* Time in ms to wait before testing recovery (default: 30000)
|
|
163
|
+
*/
|
|
164
|
+
resetTimeoutMs?: number;
|
|
165
|
+
/**
|
|
166
|
+
* Time window in ms to count failures (default: 60000)
|
|
167
|
+
*/
|
|
168
|
+
failureWindowMs?: number;
|
|
169
|
+
/**
|
|
170
|
+
* Number of successful requests in half-open state to close circuit (default: 1)
|
|
171
|
+
*/
|
|
172
|
+
successThreshold?: number;
|
|
173
|
+
/**
|
|
174
|
+
* Custom function to determine if an error should count as a failure
|
|
175
|
+
*/
|
|
176
|
+
isFailure?: (error: unknown) => boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Callback when state changes
|
|
179
|
+
*/
|
|
180
|
+
onStateChange?: (from: CircuitState, to: CircuitState) => void;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Circuit breaker error thrown when circuit is open
|
|
184
|
+
*/
|
|
185
|
+
declare class CircuitBreakerOpenError extends Error {
|
|
186
|
+
readonly code = "CIRCUIT_BREAKER_OPEN";
|
|
187
|
+
readonly remainingMs: number;
|
|
188
|
+
constructor(message: string, remainingMs: number);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Circuit breaker state manager
|
|
192
|
+
*/
|
|
193
|
+
declare class CircuitBreaker {
|
|
194
|
+
private state;
|
|
195
|
+
private failures;
|
|
196
|
+
private lastFailureTime;
|
|
197
|
+
private successCount;
|
|
198
|
+
private readonly failureThreshold;
|
|
199
|
+
private readonly resetTimeoutMs;
|
|
200
|
+
private readonly failureWindowMs;
|
|
201
|
+
private readonly successThreshold;
|
|
202
|
+
private readonly isFailure;
|
|
203
|
+
private readonly onStateChange;
|
|
204
|
+
constructor(config?: CircuitBreakerConfig);
|
|
205
|
+
/**
|
|
206
|
+
* Get current circuit state
|
|
207
|
+
*/
|
|
208
|
+
getState(): CircuitState;
|
|
209
|
+
/**
|
|
210
|
+
* Check if request is allowed
|
|
211
|
+
*/
|
|
212
|
+
canExecute(): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Record a successful request
|
|
215
|
+
*/
|
|
216
|
+
recordSuccess(): void;
|
|
217
|
+
/**
|
|
218
|
+
* Record a failed request
|
|
219
|
+
*/
|
|
220
|
+
recordFailure(error: unknown): void;
|
|
221
|
+
/**
|
|
222
|
+
* Get remaining time until circuit can transition to half-open
|
|
223
|
+
*/
|
|
224
|
+
getRemainingOpenTime(): number;
|
|
225
|
+
/**
|
|
226
|
+
* Force reset the circuit breaker
|
|
227
|
+
*/
|
|
228
|
+
reset(): void;
|
|
229
|
+
/**
|
|
230
|
+
* Get circuit breaker statistics
|
|
231
|
+
*/
|
|
232
|
+
getStats(): {
|
|
233
|
+
state: CircuitState;
|
|
234
|
+
failureCount: number;
|
|
235
|
+
successCount: number;
|
|
236
|
+
remainingOpenTimeMs: number;
|
|
237
|
+
};
|
|
238
|
+
private updateState;
|
|
239
|
+
private transitionTo;
|
|
240
|
+
private cleanupFailures;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Create a circuit breaker middleware
|
|
244
|
+
*
|
|
245
|
+
* The circuit breaker pattern prevents cascading failures by:
|
|
246
|
+
* 1. Tracking failures within a time window
|
|
247
|
+
* 2. Opening the circuit when failure threshold is reached
|
|
248
|
+
* 3. Failing fast while circuit is open
|
|
249
|
+
* 4. Testing recovery with half-open state
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const circuitBreaker = new CircuitBreaker({
|
|
254
|
+
* failureThreshold: 5,
|
|
255
|
+
* resetTimeoutMs: 30000,
|
|
256
|
+
* onStateChange: (from, to) => console.log(`Circuit: ${from} -> ${to}`),
|
|
257
|
+
* });
|
|
258
|
+
*
|
|
259
|
+
* const client = new HttpClient({
|
|
260
|
+
* baseUrl: '...',
|
|
261
|
+
* middleware: [
|
|
262
|
+
* createCircuitBreakerMiddleware(circuitBreaker),
|
|
263
|
+
* ],
|
|
264
|
+
* });
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
declare function createCircuitBreakerMiddleware(circuitBreaker: CircuitBreaker): Middleware;
|
|
268
|
+
/**
|
|
269
|
+
* Create a circuit breaker with default configuration
|
|
270
|
+
*/
|
|
271
|
+
declare function createDefaultCircuitBreaker(config?: Partial<CircuitBreakerConfig>): CircuitBreaker;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Rate-limit budget advertised by Jira's `Beta-RateLimit-Policy` header.
|
|
275
|
+
*/
|
|
276
|
+
interface RateLimitPolicy {
|
|
277
|
+
/** Total cost budget for the window. */
|
|
278
|
+
limit: number;
|
|
279
|
+
/** Window length in seconds. */
|
|
280
|
+
windowSeconds: number;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* A point-in-time read of the rate-limit headers on a single response.
|
|
284
|
+
*
|
|
285
|
+
* Every field is optional: Jira does not send these headers on all endpoints,
|
|
286
|
+
* and the beta headers in particular are only present on APIs enrolled in the
|
|
287
|
+
* cost-based rate-limiting rollout (Atlassian CHANGE-3045).
|
|
288
|
+
*/
|
|
289
|
+
interface RateLimitSnapshot {
|
|
290
|
+
/** `X-RateLimit-Remaining` — legacy request-count budget. */
|
|
291
|
+
remainingRequests?: number;
|
|
292
|
+
/** `Retry-After` — seconds to wait, present on 429 responses. */
|
|
293
|
+
retryAfterSeconds?: number;
|
|
294
|
+
/** Parsed `Beta-RateLimit-Policy`. */
|
|
295
|
+
policy?: RateLimitPolicy;
|
|
296
|
+
/** Parsed `r=` value from `Beta-RateLimit` — remaining cost points. */
|
|
297
|
+
remainingPoints?: number;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Parse the `Beta-RateLimit-Policy` header.
|
|
301
|
+
*
|
|
302
|
+
* Format: `"100;w=60"` — a limit followed by `;w=<window seconds>`.
|
|
303
|
+
*
|
|
304
|
+
* @param header Raw header value.
|
|
305
|
+
* @returns The parsed policy, or `undefined` if absent or malformed.
|
|
306
|
+
*/
|
|
307
|
+
declare function parseBetaRateLimitPolicy(header: string | null | undefined): RateLimitPolicy | undefined;
|
|
308
|
+
/**
|
|
309
|
+
* Parse the `Beta-RateLimit` header.
|
|
310
|
+
*
|
|
311
|
+
* Format: `r=85;policy="100;w=60"` — `r` is the remaining cost points.
|
|
312
|
+
*
|
|
313
|
+
* @param header Raw header value.
|
|
314
|
+
* @returns Remaining points, or `undefined` if absent or malformed.
|
|
315
|
+
*/
|
|
316
|
+
declare function parseBetaRateLimit(header: string | null | undefined): number | undefined;
|
|
317
|
+
/**
|
|
318
|
+
* Parse a `Retry-After` header, which may be either a number of seconds or an
|
|
319
|
+
* HTTP-date.
|
|
320
|
+
*
|
|
321
|
+
* @param header Raw header value.
|
|
322
|
+
* @param now Reference time for HTTP-date values; defaults to the current time.
|
|
323
|
+
* @returns Seconds to wait, or `undefined` if absent or malformed.
|
|
324
|
+
*/
|
|
325
|
+
declare function parseRetryAfterSeconds(header: string | null | undefined, now?: number): number | undefined;
|
|
326
|
+
/**
|
|
327
|
+
* Read every rate-limit signal Jira exposes from a response's headers.
|
|
328
|
+
*
|
|
329
|
+
* @param headers Response headers.
|
|
330
|
+
* @returns A snapshot with whichever fields were present.
|
|
331
|
+
*/
|
|
332
|
+
declare function readRateLimitHeaders(headers: Headers): RateLimitSnapshot;
|
|
333
|
+
/**
|
|
334
|
+
* Configuration for {@link createRateLimitHeaderMiddleware}.
|
|
335
|
+
*/
|
|
336
|
+
interface RateLimitHeaderMiddlewareConfig {
|
|
337
|
+
/**
|
|
338
|
+
* Called after every response that carries at least one rate-limit header.
|
|
339
|
+
*
|
|
340
|
+
* Use it to drive adaptive throttling, emit metrics, or warn as the budget
|
|
341
|
+
* runs low. Errors thrown here are swallowed so observability never breaks a
|
|
342
|
+
* request.
|
|
343
|
+
*/
|
|
344
|
+
onRateLimit: (snapshot: RateLimitSnapshot) => void;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Observe Jira's rate-limit headers on every response.
|
|
348
|
+
*
|
|
349
|
+
* The Go SDK parses these headers and only logs them. This middleware hands
|
|
350
|
+
* them to a callback instead, so a consumer can react — for example by backing
|
|
351
|
+
* off before Jira starts returning 429s.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```typescript
|
|
355
|
+
* const client = createJiraClient({
|
|
356
|
+
* host,
|
|
357
|
+
* auth,
|
|
358
|
+
* middleware: [
|
|
359
|
+
* createRateLimitHeaderMiddleware({
|
|
360
|
+
* onRateLimit: (snapshot) => {
|
|
361
|
+
* if (snapshot.remainingPoints !== undefined && snapshot.remainingPoints < 10) {
|
|
362
|
+
* logger.warn('Jira rate-limit budget nearly exhausted', snapshot);
|
|
363
|
+
* }
|
|
364
|
+
* },
|
|
365
|
+
* }),
|
|
366
|
+
* ],
|
|
367
|
+
* });
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
declare function createRateLimitHeaderMiddleware(config: RateLimitHeaderMiddlewareConfig): Middleware;
|
|
371
|
+
|
|
372
|
+
export { CircuitBreaker, type CircuitBreakerConfig, CircuitBreakerOpenError, CircuitState, type LoggingMiddlewareConfig, Middleware, MiddlewareContext, type RateLimitHeaderMiddlewareConfig, type RateLimitMiddlewareConfig, type RateLimitPolicy, type RateLimitSnapshot, type RetryMiddlewareConfig, type UserAgentMiddlewareConfig, composeMiddleware, createCircuitBreakerMiddleware, createDefaultCircuitBreaker, createLoggingMiddleware, createRateLimitHeaderMiddleware, createRateLimitMiddleware, createRequestIdMiddleware, createRetryMiddleware, createUserAgentMiddleware, parseBetaRateLimit, parseBetaRateLimitPolicy, parseRetryAfterSeconds, readRateLimitHeaders };
|