@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,400 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
|
|
5
|
+
// src/auth/types.ts
|
|
6
|
+
var ApiTokenAuthConfigSchema = zod.z.object({
|
|
7
|
+
email: zod.z.email({ error: "Invalid email address" }),
|
|
8
|
+
apiToken: zod.z.string().min(1, { error: "API token is required" })
|
|
9
|
+
});
|
|
10
|
+
var PatAuthConfigSchema = zod.z.object({
|
|
11
|
+
token: zod.z.string().min(1, "Personal access token is required")
|
|
12
|
+
});
|
|
13
|
+
var BasicAuthConfigSchema = zod.z.object({
|
|
14
|
+
username: zod.z.string().min(1, "Username is required"),
|
|
15
|
+
password: zod.z.string().min(1, "Password is required")
|
|
16
|
+
});
|
|
17
|
+
var OAuth2AuthConfigSchema = zod.z.object({
|
|
18
|
+
clientId: zod.z.string().min(1, "Client ID is required"),
|
|
19
|
+
clientSecret: zod.z.string().min(1, "Client secret is required"),
|
|
20
|
+
accessToken: zod.z.string().optional(),
|
|
21
|
+
refreshToken: zod.z.string().optional(),
|
|
22
|
+
tokenEndpoint: zod.z.url().optional(),
|
|
23
|
+
scopes: zod.z.array(zod.z.string()).optional(),
|
|
24
|
+
expiresAt: zod.z.number().int().optional()
|
|
25
|
+
});
|
|
26
|
+
var OAuth2TokenResponseSchema = zod.z.object({
|
|
27
|
+
access_token: zod.z.string(),
|
|
28
|
+
token_type: zod.z.string(),
|
|
29
|
+
expires_in: zod.z.number().int().optional(),
|
|
30
|
+
refresh_token: zod.z.string().optional(),
|
|
31
|
+
scope: zod.z.string().optional()
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// src/utils/runtime.ts
|
|
35
|
+
function captureStackTrace(target, constructor) {
|
|
36
|
+
const capture = Error.captureStackTrace;
|
|
37
|
+
capture?.(target, constructor);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/errors/base.error.ts
|
|
41
|
+
var JiraSdkError = class extends Error {
|
|
42
|
+
/** HTTP status code if applicable */
|
|
43
|
+
statusCode;
|
|
44
|
+
/** Original cause of the error */
|
|
45
|
+
cause;
|
|
46
|
+
/** Additional context/metadata */
|
|
47
|
+
context;
|
|
48
|
+
constructor(message, options) {
|
|
49
|
+
super(message, options?.cause !== void 0 ? { cause: options.cause } : void 0);
|
|
50
|
+
this.name = this.constructor.name;
|
|
51
|
+
if (options?.cause !== void 0) {
|
|
52
|
+
this.cause = options.cause;
|
|
53
|
+
}
|
|
54
|
+
if (options?.statusCode !== void 0) {
|
|
55
|
+
this.statusCode = options.statusCode;
|
|
56
|
+
}
|
|
57
|
+
if (options?.context !== void 0) {
|
|
58
|
+
this.context = options.context;
|
|
59
|
+
}
|
|
60
|
+
captureStackTrace(this, this.constructor);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Returns a JSON representation of the error
|
|
64
|
+
*/
|
|
65
|
+
toJSON() {
|
|
66
|
+
return {
|
|
67
|
+
name: this.name,
|
|
68
|
+
code: this.code,
|
|
69
|
+
message: this.message,
|
|
70
|
+
statusCode: this.statusCode,
|
|
71
|
+
context: this.context,
|
|
72
|
+
cause: this.cause?.message,
|
|
73
|
+
stack: this.stack
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/errors/auth.error.ts
|
|
79
|
+
var AuthError = class extends JiraSdkError {
|
|
80
|
+
code = "AUTH_ERROR";
|
|
81
|
+
constructor(message, context) {
|
|
82
|
+
super(message, { statusCode: 401, ...context !== void 0 && { context } });
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var TokenRefreshError = class extends AuthError {
|
|
86
|
+
code = "TOKEN_REFRESH_ERROR";
|
|
87
|
+
};
|
|
88
|
+
var TokenExpiredError = class extends AuthError {
|
|
89
|
+
code = "TOKEN_EXPIRED_ERROR";
|
|
90
|
+
constructor(message = "Access token has expired", context) {
|
|
91
|
+
super(message, context);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var AuthConfigError = class extends AuthError {
|
|
95
|
+
code = "AUTH_CONFIG_ERROR";
|
|
96
|
+
validationErrors;
|
|
97
|
+
constructor(message, validationErrors) {
|
|
98
|
+
super(message, validationErrors !== void 0 ? { validationErrors } : void 0);
|
|
99
|
+
this.validationErrors = validationErrors;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/auth/api-token.ts
|
|
104
|
+
var ApiTokenAuth = class {
|
|
105
|
+
type = "api-token";
|
|
106
|
+
email;
|
|
107
|
+
apiToken;
|
|
108
|
+
encodedCredentials;
|
|
109
|
+
constructor(config) {
|
|
110
|
+
const result = ApiTokenAuthConfigSchema.safeParse(config);
|
|
111
|
+
if (!result.success) {
|
|
112
|
+
throw new AuthConfigError("Invalid API token auth configuration", result.error.issues);
|
|
113
|
+
}
|
|
114
|
+
this.email = result.data.email;
|
|
115
|
+
this.apiToken = result.data.apiToken;
|
|
116
|
+
const credentials = `${this.email}:${this.apiToken}`;
|
|
117
|
+
this.encodedCredentials = this.encodeBase64(credentials);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns the Authorization header with Basic auth
|
|
121
|
+
*/
|
|
122
|
+
getAuthHeaders() {
|
|
123
|
+
return {
|
|
124
|
+
Authorization: `Basic ${this.encodedCredentials}`
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* API token auth is always valid (no expiration)
|
|
129
|
+
*/
|
|
130
|
+
isValid() {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Encode string to base64 (works in both browser and Node.js)
|
|
135
|
+
*/
|
|
136
|
+
encodeBase64(str) {
|
|
137
|
+
if (typeof btoa === "function") {
|
|
138
|
+
return btoa(str);
|
|
139
|
+
} else if (typeof Buffer !== "undefined") {
|
|
140
|
+
return Buffer.from(str, "utf-8").toString("base64");
|
|
141
|
+
}
|
|
142
|
+
throw new Error("No base64 encoding method available");
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
function createApiTokenAuth(config) {
|
|
146
|
+
return new ApiTokenAuth(config);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/auth/pat.ts
|
|
150
|
+
var PatAuth = class {
|
|
151
|
+
type = "pat";
|
|
152
|
+
token;
|
|
153
|
+
constructor(config) {
|
|
154
|
+
const result = PatAuthConfigSchema.safeParse(config);
|
|
155
|
+
if (!result.success) {
|
|
156
|
+
throw new AuthConfigError("Invalid PAT auth configuration", result.error.issues);
|
|
157
|
+
}
|
|
158
|
+
this.token = result.data.token;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns the Authorization header with Bearer token
|
|
162
|
+
*/
|
|
163
|
+
getAuthHeaders() {
|
|
164
|
+
return {
|
|
165
|
+
Authorization: `Bearer ${this.token}`
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* PAT auth is always valid (no automatic expiration check)
|
|
170
|
+
*/
|
|
171
|
+
isValid() {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
function createPatAuth(config) {
|
|
176
|
+
return new PatAuth(config);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/auth/basic.ts
|
|
180
|
+
var BasicAuth = class {
|
|
181
|
+
type = "basic";
|
|
182
|
+
encodedCredentials;
|
|
183
|
+
constructor(config) {
|
|
184
|
+
const result = BasicAuthConfigSchema.safeParse(config);
|
|
185
|
+
if (!result.success) {
|
|
186
|
+
throw new AuthConfigError("Invalid basic auth configuration", result.error.issues);
|
|
187
|
+
}
|
|
188
|
+
const { username, password } = result.data;
|
|
189
|
+
const credentials = `${username}:${password}`;
|
|
190
|
+
this.encodedCredentials = this.encodeBase64(credentials);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Returns the Authorization header with Basic auth
|
|
194
|
+
*/
|
|
195
|
+
getAuthHeaders() {
|
|
196
|
+
return {
|
|
197
|
+
Authorization: `Basic ${this.encodedCredentials}`
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Basic auth is always valid (no expiration)
|
|
202
|
+
*/
|
|
203
|
+
isValid() {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Encode string to base64 (works in both browser and Node.js)
|
|
208
|
+
*/
|
|
209
|
+
encodeBase64(str) {
|
|
210
|
+
if (typeof btoa === "function") {
|
|
211
|
+
return btoa(str);
|
|
212
|
+
} else if (typeof Buffer !== "undefined") {
|
|
213
|
+
return Buffer.from(str, "utf-8").toString("base64");
|
|
214
|
+
}
|
|
215
|
+
throw new Error("No base64 encoding method available");
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
function createBasicAuth(config) {
|
|
219
|
+
return new BasicAuth(config);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/auth/oauth2.ts
|
|
223
|
+
var ATLASSIAN_TOKEN_ENDPOINT = "https://auth.atlassian.com/oauth/token";
|
|
224
|
+
var TOKEN_EXPIRY_BUFFER_MS = 5 * 60 * 1e3;
|
|
225
|
+
var OAuth2Auth = class {
|
|
226
|
+
type = "oauth2";
|
|
227
|
+
clientId;
|
|
228
|
+
clientSecret;
|
|
229
|
+
tokenEndpoint;
|
|
230
|
+
accessToken;
|
|
231
|
+
refreshToken;
|
|
232
|
+
expiresAt;
|
|
233
|
+
/**
|
|
234
|
+
* Promise for in-flight token refresh (prevents concurrent refreshes)
|
|
235
|
+
*/
|
|
236
|
+
refreshPromise;
|
|
237
|
+
/**
|
|
238
|
+
* Callback invoked when tokens are refreshed
|
|
239
|
+
* Useful for persisting new tokens
|
|
240
|
+
*/
|
|
241
|
+
onTokenRefresh;
|
|
242
|
+
constructor(config) {
|
|
243
|
+
const result = OAuth2AuthConfigSchema.safeParse(config);
|
|
244
|
+
if (!result.success) {
|
|
245
|
+
throw new AuthConfigError("Invalid OAuth2 auth configuration", result.error.issues);
|
|
246
|
+
}
|
|
247
|
+
const data = result.data;
|
|
248
|
+
this.clientId = data.clientId;
|
|
249
|
+
this.clientSecret = data.clientSecret;
|
|
250
|
+
this.tokenEndpoint = data.tokenEndpoint ?? ATLASSIAN_TOKEN_ENDPOINT;
|
|
251
|
+
this.accessToken = data.accessToken;
|
|
252
|
+
this.refreshToken = data.refreshToken;
|
|
253
|
+
this.expiresAt = data.expiresAt;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Returns the Authorization header with Bearer token
|
|
257
|
+
* Uses a mutex to prevent concurrent token refreshes
|
|
258
|
+
*/
|
|
259
|
+
async getAuthHeaders() {
|
|
260
|
+
if (this.shouldRefreshToken()) {
|
|
261
|
+
if (!this.refreshPromise) {
|
|
262
|
+
this.refreshPromise = this.refresh().finally(() => {
|
|
263
|
+
this.refreshPromise = void 0;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
await this.refreshPromise;
|
|
267
|
+
}
|
|
268
|
+
if (!this.accessToken) {
|
|
269
|
+
throw new TokenExpiredError("No access token available");
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
Authorization: `Bearer ${this.accessToken}`
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Check if the current token is valid
|
|
277
|
+
*/
|
|
278
|
+
isValid() {
|
|
279
|
+
if (!this.accessToken) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
if (this.expiresAt && Date.now() >= this.expiresAt) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Refresh the access token using the refresh token
|
|
289
|
+
*/
|
|
290
|
+
async refresh() {
|
|
291
|
+
if (!this.refreshToken) {
|
|
292
|
+
throw new TokenRefreshError("No refresh token available");
|
|
293
|
+
}
|
|
294
|
+
const body = new URLSearchParams({
|
|
295
|
+
grant_type: "refresh_token",
|
|
296
|
+
client_id: this.clientId,
|
|
297
|
+
client_secret: this.clientSecret,
|
|
298
|
+
refresh_token: this.refreshToken
|
|
299
|
+
});
|
|
300
|
+
try {
|
|
301
|
+
const response = await fetch(this.tokenEndpoint, {
|
|
302
|
+
method: "POST",
|
|
303
|
+
headers: {
|
|
304
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
305
|
+
},
|
|
306
|
+
body: body.toString()
|
|
307
|
+
});
|
|
308
|
+
if (!response.ok) {
|
|
309
|
+
const errorText = await response.text();
|
|
310
|
+
throw new TokenRefreshError(
|
|
311
|
+
`Token refresh failed: ${response.status} ${response.statusText}`,
|
|
312
|
+
{ responseBody: errorText }
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
const data = await response.json();
|
|
316
|
+
const parsed = OAuth2TokenResponseSchema.safeParse(data);
|
|
317
|
+
if (!parsed.success) {
|
|
318
|
+
throw new TokenRefreshError("Invalid token response from server", {
|
|
319
|
+
validationErrors: parsed.error.issues
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
const tokens = parsed.data;
|
|
323
|
+
this.accessToken = tokens.access_token;
|
|
324
|
+
if (tokens.refresh_token) {
|
|
325
|
+
this.refreshToken = tokens.refresh_token;
|
|
326
|
+
}
|
|
327
|
+
if (tokens.expires_in) {
|
|
328
|
+
this.expiresAt = Date.now() + tokens.expires_in * 1e3;
|
|
329
|
+
}
|
|
330
|
+
if (this.onTokenRefresh) {
|
|
331
|
+
await this.onTokenRefresh({
|
|
332
|
+
accessToken: this.accessToken,
|
|
333
|
+
refreshToken: this.refreshToken,
|
|
334
|
+
expiresAt: this.expiresAt
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
} catch (error) {
|
|
338
|
+
if (error instanceof TokenRefreshError) {
|
|
339
|
+
throw error;
|
|
340
|
+
}
|
|
341
|
+
throw new TokenRefreshError("Failed to refresh token", { cause: error });
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Set a new access token
|
|
346
|
+
*/
|
|
347
|
+
setAccessToken(token, expiresIn) {
|
|
348
|
+
this.accessToken = token;
|
|
349
|
+
if (expiresIn) {
|
|
350
|
+
this.expiresAt = Date.now() + expiresIn * 1e3;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Set a new refresh token
|
|
355
|
+
*/
|
|
356
|
+
setRefreshToken(token) {
|
|
357
|
+
this.refreshToken = token;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Get current tokens (for persistence)
|
|
361
|
+
*/
|
|
362
|
+
getTokens() {
|
|
363
|
+
return {
|
|
364
|
+
accessToken: this.accessToken,
|
|
365
|
+
refreshToken: this.refreshToken,
|
|
366
|
+
expiresAt: this.expiresAt
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Check if we should proactively refresh the token
|
|
371
|
+
*/
|
|
372
|
+
shouldRefreshToken() {
|
|
373
|
+
if (!this.accessToken) {
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
if (!this.expiresAt) {
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
return Date.now() >= this.expiresAt - TOKEN_EXPIRY_BUFFER_MS;
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
function createOAuth2Auth(config) {
|
|
383
|
+
return new OAuth2Auth(config);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
exports.ApiTokenAuth = ApiTokenAuth;
|
|
387
|
+
exports.ApiTokenAuthConfigSchema = ApiTokenAuthConfigSchema;
|
|
388
|
+
exports.BasicAuth = BasicAuth;
|
|
389
|
+
exports.BasicAuthConfigSchema = BasicAuthConfigSchema;
|
|
390
|
+
exports.OAuth2Auth = OAuth2Auth;
|
|
391
|
+
exports.OAuth2AuthConfigSchema = OAuth2AuthConfigSchema;
|
|
392
|
+
exports.OAuth2TokenResponseSchema = OAuth2TokenResponseSchema;
|
|
393
|
+
exports.PatAuth = PatAuth;
|
|
394
|
+
exports.PatAuthConfigSchema = PatAuthConfigSchema;
|
|
395
|
+
exports.createApiTokenAuth = createApiTokenAuth;
|
|
396
|
+
exports.createBasicAuth = createBasicAuth;
|
|
397
|
+
exports.createOAuth2Auth = createOAuth2Auth;
|
|
398
|
+
exports.createPatAuth = createPatAuth;
|
|
399
|
+
//# sourceMappingURL=index.cjs.map
|
|
400
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/types.ts","../../src/utils/runtime.ts","../../src/errors/base.error.ts","../../src/errors/auth.error.ts","../../src/auth/api-token.ts","../../src/auth/pat.ts","../../src/auth/basic.ts","../../src/auth/oauth2.ts"],"names":["z"],"mappings":";;;;;AAoCO,IAAM,wBAAA,GAA2BA,MAAE,MAAA,CAAO;AAAA,EAC/C,OAAOA,KAAA,CAAE,KAAA,CAAM,EAAE,KAAA,EAAO,yBAAyB,CAAA;AAAA,EACjD,QAAA,EAAUA,MAAE,MAAA,EAAO,CAAE,IAAI,CAAA,EAAG,EAAE,KAAA,EAAO,uBAAA,EAAyB;AAChE,CAAC;AAOM,IAAM,mBAAA,GAAsBA,MAAE,MAAA,CAAO;AAAA,EAC1C,OAAOA,KAAA,CAAE,MAAA,EAAO,CAAE,GAAA,CAAI,GAAG,mCAAmC;AAC9D,CAAC;AAOM,IAAM,qBAAA,GAAwBA,MAAE,MAAA,CAAO;AAAA,EAC5C,UAAUA,KAAA,CAAE,MAAA,EAAO,CAAE,GAAA,CAAI,GAAG,sBAAsB,CAAA;AAAA,EAClD,UAAUA,KAAA,CAAE,MAAA,EAAO,CAAE,GAAA,CAAI,GAAG,sBAAsB;AACpD,CAAC;AAOM,IAAM,sBAAA,GAAyBA,MAAE,MAAA,CAAO;AAAA,EAC7C,UAAUA,KAAA,CAAE,MAAA,EAAO,CAAE,GAAA,CA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AA,CAAe,OAAe,SAAA,EAA0B;AACtD,IAAA,IAAA,CAAK,WAAA,GAAc,KAAA;AACnB,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,IAAA,CAAK,SAAA,GAAY,IAAA,CAAK,GAAA,EAAI,GAAI,SAAA,GAAY,GAAA;AAAA,IAC5C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAgB,KAAA,EAAqB;AACnC,IAAA,IAAA,CAAK,YAAA,GAAe,KAAA;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA,GAIE;AACA,IAAA,OAAO;AAAA,MACL,aAAa,IAAA,CAAK,WAAA;AAAA,MAClB,cAAc,IAAA,CAAK,YAAA;AAAA,MACnB,WAAW,IAAA,CAAK;AAAA,KAClB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,kBAAA,GAA8B;AACpC,IAAA,IAAI,CAAC,KAAK,WAAA,EAAa;AACrB,MAAA,OAAO,IAAA;AAAA,IACT;AAEA,IAAA,IAAI,CAAC,KAAK,SAAA,EAAW;AACnB,MAAA,OAAO,KAAA;AAAA,IACT;AAGA,IAAA,OAAO,IAAA,CAAK,GAAA,EAAI,IAAK,IAAA,CAAK,SAAA,GAAY,sBAAA;AAAA,EACxC;AACF;AAKO,SAAS,iBAAiB,MAAA,EAAsC;AACrE,EAAA,OAAO,IAAI,WAAW,MAAM,CAAA;AAC9B","file":"index.cjs","sourcesContent":["import { z } from 'zod';\n\n/**\n * Authentication provider interface\n * All auth providers must implement this interface\n */\nexport interface AuthProvider {\n /**\n * Returns the authentication headers to be added to requests\n */\n getAuthHeaders(): Promise<Record<string, string>> | Record<string, string>;\n\n /**\n * Returns the auth type identifier\n */\n readonly type: AuthType;\n\n /**\n * Optional: Check if the auth is still valid\n */\n isValid?(): Promise<boolean> | boolean;\n\n /**\n * Optional: Refresh the authentication (for OAuth2)\n */\n refresh?(): Promise<void>;\n}\n\n/**\n * Auth type enum\n */\nexport type AuthType = 'api-token' | 'pat' | 'basic' | 'oauth2' | 'none';\n\n/**\n * API Token auth configuration schema\n */\nexport const ApiTokenAuthConfigSchema = z.object({\n email: z.email({ error: 'Invalid email address' }),\n apiToken: z.string().min(1, { error: 'API token is required' }),\n});\n\nexport type ApiTokenAuthConfig = z.infer<typeof ApiTokenAuthConfigSchema>;\n\n/**\n * Personal Access Token (PAT) auth configuration schema\n */\nexport const PatAuthConfigSchema = z.object({\n token: z.string().min(1, 'Personal access token is required'),\n});\n\nexport type PatAuthConfig = z.infer<typeof PatAuthConfigSchema>;\n\n/**\n * Basic auth configuration schema\n */\nexport const BasicAuthConfigSchema = z.object({\n username: z.string().min(1, 'Username is required'),\n password: z.string().min(1, 'Password is required'),\n});\n\nexport type BasicAuthConfig = z.infer<typeof BasicAuthConfigSchema>;\n\n/**\n * OAuth2 auth configuration schema\n */\nexport const OAuth2AuthConfigSchema = z.object({\n clientId: z.string().min(1, 'Client ID is required'),\n clientSecret: z.string().min(1, 'Client secret is required'),\n accessToken: z.string().optional(),\n refreshToken: z.string().optional(),\n tokenEndpoint: z.url().optional(),\n scopes: z.array(z.string()).optional(),\n expiresAt: z.number().int().optional(),\n});\n\nexport type OAuth2AuthConfig = z.infer<typeof OAuth2AuthConfigSchema>;\n\n/**\n * OAuth2 token response schema\n */\nexport const OAuth2TokenResponseSchema = z.object({\n access_token: z.string(),\n token_type: z.string(),\n expires_in: z.number().int().optional(),\n refresh_token: z.string().optional(),\n scope: z.string().optional(),\n});\n\nexport type OAuth2TokenResponse = z.infer<typeof OAuth2TokenResponseSchema>;\n\n/**\n * Union of all auth configs\n */\nexport type AuthConfig =\n | { type: 'api-token'; config: ApiTokenAuthConfig }\n | { type: 'pat'; config: PatAuthConfig }\n | { type: 'basic'; config: BasicAuthConfig }\n | { type: 'oauth2'; config: OAuth2AuthConfig }\n | { type: 'none' };\n","/**\n * Feature detection for host globals that TypeScript's DOM/Node lib types\n * declare as always present, but which are genuinely absent in some runtimes\n * this SDK supports (browsers, Workers, Deno, edge functions).\n *\n * Reading them through a widened view of `globalThis` keeps the runtime guard —\n * removing it would crash outside Node — while letting the type system see that\n * the check is meaningful, so it no longer reports the guard as an unnecessary\n * condition.\n */\ninterface RuntimeGlobals {\n process?: { env?: Record<string, string | undefined> };\n console?: { warn?: (...args: unknown[]) => void };\n crypto?: { randomUUID?: () => string };\n}\n\nfunction runtime(): RuntimeGlobals {\n return globalThis;\n}\n\n/**\n * Read `process.env`, or an empty object where `process` is unavailable.\n */\nexport function processEnv(): Record<string, string | undefined> {\n return runtime().process?.env ?? {};\n}\n\n/**\n * Read a single environment variable, or `undefined` where unavailable.\n */\nexport function readEnvVar(name: string): string | undefined {\n return processEnv()[name];\n}\n\n/**\n * Emit a warning through `console.warn` where one exists, otherwise do nothing.\n */\nexport function warn(message: string): void {\n runtime().console?.warn?.(message);\n}\n\n/**\n * Generate a UUID using `crypto.randomUUID` where available, falling back to a\n * timestamp-and-random identifier. The fallback is not cryptographically\n * random and is only used for request correlation IDs.\n */\nexport function randomId(): string {\n const uuid = runtime().crypto?.randomUUID?.();\n if (uuid !== undefined) {\n return uuid;\n }\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 11)}`;\n}\n\n/**\n * V8-only API used to trim the constructor frame from error stacks. Absent on\n * SpiderMonkey and JavaScriptCore.\n */\ntype CaptureStackTrace = (target: object, constructor?: unknown) => void;\n\n/**\n * Trim the constructor frame from an error's stack where the engine supports\n * it; a no-op elsewhere.\n *\n * `constructor` is typed `unknown` rather than `Function` so the signature does\n * not widen to \"any callable\" for callers. V8 expects a constructor function\n * there, and every call site passes `this.constructor`.\n */\nexport function captureStackTrace(target: object, constructor?: unknown): void {\n const capture = (Error as unknown as { captureStackTrace?: CaptureStackTrace }).captureStackTrace;\n capture?.(target, constructor);\n}\n","import { captureStackTrace } from '../utils/runtime.js';\n/**\n * Base error class for all SDK errors.\n * Provides consistent error structure with error codes and cause chaining.\n */\nexport abstract class JiraSdkError extends Error {\n /** Unique error code for programmatic handling */\n abstract readonly code: string;\n\n /** HTTP status code if applicable */\n readonly statusCode?: number;\n\n /** Original cause of the error */\n readonly cause?: Error;\n\n /** Additional context/metadata */\n readonly context?: Record<string, unknown>;\n\n constructor(\n message: string,\n options?: {\n cause?: Error | undefined;\n statusCode?: number | undefined;\n context?: Record<string, unknown> | undefined;\n }\n ) {\n super(message, options?.cause !== undefined ? { cause: options.cause } : undefined);\n this.name = this.constructor.name;\n\n // Only assign properties when values are defined (for exactOptionalPropertyTypes)\n if (options?.cause !== undefined) {\n this.cause = options.cause;\n }\n if (options?.statusCode !== undefined) {\n this.statusCode = options.statusCode;\n }\n if (options?.context !== undefined) {\n this.context = options.context;\n }\n\n // Maintains proper stack trace for where our error was thrown (V8 only)\n captureStackTrace(this, this.constructor);\n }\n\n /**\n * Returns a JSON representation of the error\n */\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n statusCode: this.statusCode,\n context: this.context,\n cause: this.cause?.message,\n stack: this.stack,\n };\n }\n}\n","import type { z } from 'zod';\nimport { JiraSdkError } from './base.error.js';\n\n/**\n * Error thrown when authentication fails or is misconfigured.\n */\nexport class AuthError extends JiraSdkError {\n readonly code: string = 'AUTH_ERROR';\n\n constructor(message: string, context?: Record<string, unknown>) {\n super(message, { statusCode: 401, ...(context !== undefined && { context }) });\n }\n}\n\n/**\n * Error thrown when OAuth2 token refresh fails.\n */\nexport class TokenRefreshError extends AuthError {\n override readonly code: string = 'TOKEN_REFRESH_ERROR';\n}\n\n/**\n * Error thrown when OAuth2 token is expired.\n */\nexport class TokenExpiredError extends AuthError {\n override readonly code: string = 'TOKEN_EXPIRED_ERROR';\n\n constructor(message = 'Access token has expired', context?: Record<string, unknown>) {\n super(message, context);\n }\n}\n\n/**\n * Error thrown when auth configuration is invalid.\n */\nexport class AuthConfigError extends AuthError {\n override readonly code: string = 'AUTH_CONFIG_ERROR';\n readonly validationErrors: z.core.$ZodIssue[] | undefined;\n\n constructor(message: string, validationErrors?: z.core.$ZodIssue[]) {\n super(message, validationErrors !== undefined ? { validationErrors } : undefined);\n this.validationErrors = validationErrors;\n }\n}\n","import {\n type AuthProvider,\n type AuthType,\n type ApiTokenAuthConfig,\n ApiTokenAuthConfigSchema,\n} from './types.js';\nimport { AuthConfigError } from '../errors/auth.error.js';\n\n/**\n * API Token authentication provider for Atlassian Cloud\n *\n * Uses email + API token authentication which creates a Basic auth header.\n * This is the recommended auth method for Atlassian Cloud APIs.\n *\n * @see https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/\n *\n * @example\n * ```typescript\n * const auth = new ApiTokenAuth({\n * email: 'user@example.com',\n * apiToken: 'your-api-token'\n * });\n * ```\n */\nexport class ApiTokenAuth implements AuthProvider {\n public readonly type: AuthType = 'api-token';\n private readonly email: string;\n private readonly apiToken: string;\n private readonly encodedCredentials: string;\n\n constructor(config: ApiTokenAuthConfig) {\n const result = ApiTokenAuthConfigSchema.safeParse(config);\n if (!result.success) {\n throw new AuthConfigError('Invalid API token auth configuration', result.error.issues);\n }\n\n this.email = result.data.email;\n this.apiToken = result.data.apiToken;\n\n // Pre-compute the base64 encoded credentials\n // In browser, use btoa; in Node.js, use Buffer\n const credentials = `${this.email}:${this.apiToken}`;\n this.encodedCredentials = this.encodeBase64(credentials);\n }\n\n /**\n * Returns the Authorization header with Basic auth\n */\n getAuthHeaders(): Record<string, string> {\n return {\n Authorization: `Basic ${this.encodedCredentials}`,\n };\n }\n\n /**\n * API token auth is always valid (no expiration)\n */\n isValid(): boolean {\n return true;\n }\n\n /**\n * Encode string to base64 (works in both browser and Node.js)\n */\n private encodeBase64(str: string): string {\n if (typeof btoa === 'function') {\n // Browser environment\n return btoa(str);\n } else if (typeof Buffer !== 'undefined') {\n // Node.js environment\n return Buffer.from(str, 'utf-8').toString('base64');\n }\n throw new Error('No base64 encoding method available');\n }\n}\n\n/**\n * Factory function to create API Token auth provider\n */\nexport function createApiTokenAuth(config: ApiTokenAuthConfig): ApiTokenAuth {\n return new ApiTokenAuth(config);\n}\n","import {\n type AuthProvider,\n type AuthType,\n type PatAuthConfig,\n PatAuthConfigSchema,\n} from './types.js';\nimport { AuthConfigError } from '../errors/auth.error.js';\n\n/**\n * Personal Access Token (PAT) authentication provider\n *\n * Uses Bearer token authentication with a PAT.\n * Supported by Jira Server/Data Center and some Cloud APIs.\n *\n * @see https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html\n *\n * @example\n * ```typescript\n * const auth = new PatAuth({\n * token: 'your-personal-access-token'\n * });\n * ```\n */\nexport class PatAuth implements AuthProvider {\n public readonly type: AuthType = 'pat';\n private readonly token: string;\n\n constructor(config: PatAuthConfig) {\n const result = PatAuthConfigSchema.safeParse(config);\n if (!result.success) {\n throw new AuthConfigError('Invalid PAT auth configuration', result.error.issues);\n }\n\n this.token = result.data.token;\n }\n\n /**\n * Returns the Authorization header with Bearer token\n */\n getAuthHeaders(): Record<string, string> {\n return {\n Authorization: `Bearer ${this.token}`,\n };\n }\n\n /**\n * PAT auth is always valid (no automatic expiration check)\n */\n isValid(): boolean {\n return true;\n }\n}\n\n/**\n * Factory function to create PAT auth provider\n */\nexport function createPatAuth(config: PatAuthConfig): PatAuth {\n return new PatAuth(config);\n}\n","import {\n type AuthProvider,\n type AuthType,\n type BasicAuthConfig,\n BasicAuthConfigSchema,\n} from './types.js';\nimport { AuthConfigError } from '../errors/auth.error.js';\n\n/**\n * Basic authentication provider\n *\n * Uses HTTP Basic authentication with username and password.\n * Primarily used with Jira Server/Data Center instances.\n *\n * @example\n * ```typescript\n * const auth = new BasicAuth({\n * username: 'admin',\n * password: 'password123'\n * });\n * ```\n */\nexport class BasicAuth implements AuthProvider {\n public readonly type: AuthType = 'basic';\n private readonly encodedCredentials: string;\n\n constructor(config: BasicAuthConfig) {\n const result = BasicAuthConfigSchema.safeParse(config);\n if (!result.success) {\n throw new AuthConfigError('Invalid basic auth configuration', result.error.issues);\n }\n\n const { username, password } = result.data;\n const credentials = `${username}:${password}`;\n this.encodedCredentials = this.encodeBase64(credentials);\n }\n\n /**\n * Returns the Authorization header with Basic auth\n */\n getAuthHeaders(): Record<string, string> {\n return {\n Authorization: `Basic ${this.encodedCredentials}`,\n };\n }\n\n /**\n * Basic auth is always valid (no expiration)\n */\n isValid(): boolean {\n return true;\n }\n\n /**\n * Encode string to base64 (works in both browser and Node.js)\n */\n private encodeBase64(str: string): string {\n if (typeof btoa === 'function') {\n // Browser environment\n return btoa(str);\n } else if (typeof Buffer !== 'undefined') {\n // Node.js environment\n return Buffer.from(str, 'utf-8').toString('base64');\n }\n throw new Error('No base64 encoding method available');\n }\n}\n\n/**\n * Factory function to create Basic auth provider\n */\nexport function createBasicAuth(config: BasicAuthConfig): BasicAuth {\n return new BasicAuth(config);\n}\n","import {\n type AuthProvider,\n type AuthType,\n type OAuth2AuthConfig,\n OAuth2AuthConfigSchema,\n OAuth2TokenResponseSchema,\n} from './types.js';\nimport { AuthConfigError, TokenRefreshError, TokenExpiredError } from '../errors/auth.error.js';\n\n/**\n * Default token endpoint for Atlassian Cloud OAuth2\n */\nconst ATLASSIAN_TOKEN_ENDPOINT = 'https://auth.atlassian.com/oauth/token';\n\n/**\n * Buffer time (in ms) before token expiration to trigger refresh\n * Default: 5 minutes\n */\nconst TOKEN_EXPIRY_BUFFER_MS = 5 * 60 * 1000;\n\n/**\n * OAuth2 authentication provider\n *\n * Supports OAuth 2.0 with automatic token refresh for Atlassian Cloud.\n *\n * @see https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps/\n *\n * @example\n * ```typescript\n * const auth = new OAuth2Auth({\n * clientId: 'your-client-id',\n * clientSecret: 'your-client-secret',\n * accessToken: 'current-access-token',\n * refreshToken: 'refresh-token',\n * });\n * ```\n */\nexport class OAuth2Auth implements AuthProvider {\n public readonly type: AuthType = 'oauth2';\n private readonly clientId: string;\n private readonly clientSecret: string;\n private readonly tokenEndpoint: string;\n\n private accessToken: string | undefined;\n private refreshToken: string | undefined;\n private expiresAt: number | undefined;\n\n /**\n * Promise for in-flight token refresh (prevents concurrent refreshes)\n */\n private refreshPromise: Promise<void> | undefined;\n\n /**\n * Callback invoked when tokens are refreshed\n * Useful for persisting new tokens\n */\n public onTokenRefresh?: (tokens: {\n accessToken: string;\n refreshToken: string | undefined;\n expiresAt: number | undefined;\n }) => void | Promise<void>;\n\n constructor(config: OAuth2AuthConfig) {\n const result = OAuth2AuthConfigSchema.safeParse(config);\n if (!result.success) {\n throw new AuthConfigError('Invalid OAuth2 auth configuration', result.error.issues);\n }\n\n const data = result.data;\n this.clientId = data.clientId;\n this.clientSecret = data.clientSecret;\n this.tokenEndpoint = data.tokenEndpoint ?? ATLASSIAN_TOKEN_ENDPOINT;\n this.accessToken = data.accessToken;\n this.refreshToken = data.refreshToken;\n this.expiresAt = data.expiresAt;\n }\n\n /**\n * Returns the Authorization header with Bearer token\n * Uses a mutex to prevent concurrent token refreshes\n */\n async getAuthHeaders(): Promise<Record<string, string>> {\n // Check if we need to refresh the token\n if (this.shouldRefreshToken()) {\n // Use existing refresh promise if one is in flight (prevents concurrent refreshes)\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- ??= can't be used with side effects\n if (!this.refreshPromise) {\n this.refreshPromise = this.refresh().finally(() => {\n this.refreshPromise = undefined;\n });\n }\n await this.refreshPromise;\n }\n\n if (!this.accessToken) {\n throw new TokenExpiredError('No access token available');\n }\n\n return {\n Authorization: `Bearer ${this.accessToken}`,\n };\n }\n\n /**\n * Check if the current token is valid\n */\n isValid(): boolean {\n if (!this.accessToken) {\n return false;\n }\n\n if (this.expiresAt && Date.now() >= this.expiresAt) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Refresh the access token using the refresh token\n */\n async refresh(): Promise<void> {\n if (!this.refreshToken) {\n throw new TokenRefreshError('No refresh token available');\n }\n\n const body = new URLSearchParams({\n grant_type: 'refresh_token',\n client_id: this.clientId,\n client_secret: this.clientSecret,\n refresh_token: this.refreshToken,\n });\n\n try {\n const response = await fetch(this.tokenEndpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: body.toString(),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new TokenRefreshError(\n `Token refresh failed: ${response.status} ${response.statusText}`,\n { responseBody: errorText }\n );\n }\n\n const data: unknown = await response.json();\n const parsed = OAuth2TokenResponseSchema.safeParse(data);\n\n if (!parsed.success) {\n throw new TokenRefreshError('Invalid token response from server', {\n validationErrors: parsed.error.issues,\n });\n }\n\n const tokens = parsed.data;\n this.accessToken = tokens.access_token;\n\n if (tokens.refresh_token) {\n this.refreshToken = tokens.refresh_token;\n }\n\n if (tokens.expires_in) {\n this.expiresAt = Date.now() + tokens.expires_in * 1000;\n }\n\n // Invoke callback if provided\n if (this.onTokenRefresh) {\n await this.onTokenRefresh({\n accessToken: this.accessToken,\n refreshToken: this.refreshToken,\n expiresAt: this.expiresAt,\n });\n }\n } catch (error) {\n if (error instanceof TokenRefreshError) {\n throw error;\n }\n throw new TokenRefreshError('Failed to refresh token', { cause: error });\n }\n }\n\n /**\n * Set a new access token\n */\n setAccessToken(token: string, expiresIn?: number): void {\n this.accessToken = token;\n if (expiresIn) {\n this.expiresAt = Date.now() + expiresIn * 1000;\n }\n }\n\n /**\n * Set a new refresh token\n */\n setRefreshToken(token: string): void {\n this.refreshToken = token;\n }\n\n /**\n * Get current tokens (for persistence)\n */\n getTokens(): {\n accessToken: string | undefined;\n refreshToken: string | undefined;\n expiresAt: number | undefined;\n } {\n return {\n accessToken: this.accessToken,\n refreshToken: this.refreshToken,\n expiresAt: this.expiresAt,\n };\n }\n\n /**\n * Check if we should proactively refresh the token\n */\n private shouldRefreshToken(): boolean {\n if (!this.accessToken) {\n return true;\n }\n\n if (!this.expiresAt) {\n return false;\n }\n\n // Refresh if within buffer time of expiration\n return Date.now() >= this.expiresAt - TOKEN_EXPIRY_BUFFER_MS;\n }\n}\n\n/**\n * Factory function to create OAuth2 auth provider\n */\nexport function createOAuth2Auth(config: OAuth2AuthConfig): OAuth2Auth {\n return new OAuth2Auth(config);\n}\n"]}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { A as AuthProvider, d as AuthType, a as ApiTokenAuthConfig, P as PatAuthConfig, B as BasicAuthConfig, O as OAuth2AuthConfig } from '../types-E6djPHpW.cjs';
|
|
2
|
+
export { b as ApiTokenAuthConfigSchema, c as AuthConfig, e as BasicAuthConfigSchema, f as OAuth2AuthConfigSchema, g as OAuth2TokenResponse, h as OAuth2TokenResponseSchema, i as PatAuthConfigSchema } from '../types-E6djPHpW.cjs';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* API Token authentication provider for Atlassian Cloud
|
|
7
|
+
*
|
|
8
|
+
* Uses email + API token authentication which creates a Basic auth header.
|
|
9
|
+
* This is the recommended auth method for Atlassian Cloud APIs.
|
|
10
|
+
*
|
|
11
|
+
* @see https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const auth = new ApiTokenAuth({
|
|
16
|
+
* email: 'user@example.com',
|
|
17
|
+
* apiToken: 'your-api-token'
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare class ApiTokenAuth implements AuthProvider {
|
|
22
|
+
readonly type: AuthType;
|
|
23
|
+
private readonly email;
|
|
24
|
+
private readonly apiToken;
|
|
25
|
+
private readonly encodedCredentials;
|
|
26
|
+
constructor(config: ApiTokenAuthConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Returns the Authorization header with Basic auth
|
|
29
|
+
*/
|
|
30
|
+
getAuthHeaders(): Record<string, string>;
|
|
31
|
+
/**
|
|
32
|
+
* API token auth is always valid (no expiration)
|
|
33
|
+
*/
|
|
34
|
+
isValid(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Encode string to base64 (works in both browser and Node.js)
|
|
37
|
+
*/
|
|
38
|
+
private encodeBase64;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Factory function to create API Token auth provider
|
|
42
|
+
*/
|
|
43
|
+
declare function createApiTokenAuth(config: ApiTokenAuthConfig): ApiTokenAuth;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Personal Access Token (PAT) authentication provider
|
|
47
|
+
*
|
|
48
|
+
* Uses Bearer token authentication with a PAT.
|
|
49
|
+
* Supported by Jira Server/Data Center and some Cloud APIs.
|
|
50
|
+
*
|
|
51
|
+
* @see https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const auth = new PatAuth({
|
|
56
|
+
* token: 'your-personal-access-token'
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare class PatAuth implements AuthProvider {
|
|
61
|
+
readonly type: AuthType;
|
|
62
|
+
private readonly token;
|
|
63
|
+
constructor(config: PatAuthConfig);
|
|
64
|
+
/**
|
|
65
|
+
* Returns the Authorization header with Bearer token
|
|
66
|
+
*/
|
|
67
|
+
getAuthHeaders(): Record<string, string>;
|
|
68
|
+
/**
|
|
69
|
+
* PAT auth is always valid (no automatic expiration check)
|
|
70
|
+
*/
|
|
71
|
+
isValid(): boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Factory function to create PAT auth provider
|
|
75
|
+
*/
|
|
76
|
+
declare function createPatAuth(config: PatAuthConfig): PatAuth;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Basic authentication provider
|
|
80
|
+
*
|
|
81
|
+
* Uses HTTP Basic authentication with username and password.
|
|
82
|
+
* Primarily used with Jira Server/Data Center instances.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const auth = new BasicAuth({
|
|
87
|
+
* username: 'admin',
|
|
88
|
+
* password: 'password123'
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare class BasicAuth implements AuthProvider {
|
|
93
|
+
readonly type: AuthType;
|
|
94
|
+
private readonly encodedCredentials;
|
|
95
|
+
constructor(config: BasicAuthConfig);
|
|
96
|
+
/**
|
|
97
|
+
* Returns the Authorization header with Basic auth
|
|
98
|
+
*/
|
|
99
|
+
getAuthHeaders(): Record<string, string>;
|
|
100
|
+
/**
|
|
101
|
+
* Basic auth is always valid (no expiration)
|
|
102
|
+
*/
|
|
103
|
+
isValid(): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Encode string to base64 (works in both browser and Node.js)
|
|
106
|
+
*/
|
|
107
|
+
private encodeBase64;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Factory function to create Basic auth provider
|
|
111
|
+
*/
|
|
112
|
+
declare function createBasicAuth(config: BasicAuthConfig): BasicAuth;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* OAuth2 authentication provider
|
|
116
|
+
*
|
|
117
|
+
* Supports OAuth 2.0 with automatic token refresh for Atlassian Cloud.
|
|
118
|
+
*
|
|
119
|
+
* @see https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps/
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const auth = new OAuth2Auth({
|
|
124
|
+
* clientId: 'your-client-id',
|
|
125
|
+
* clientSecret: 'your-client-secret',
|
|
126
|
+
* accessToken: 'current-access-token',
|
|
127
|
+
* refreshToken: 'refresh-token',
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare class OAuth2Auth implements AuthProvider {
|
|
132
|
+
readonly type: AuthType;
|
|
133
|
+
private readonly clientId;
|
|
134
|
+
private readonly clientSecret;
|
|
135
|
+
private readonly tokenEndpoint;
|
|
136
|
+
private accessToken;
|
|
137
|
+
private refreshToken;
|
|
138
|
+
private expiresAt;
|
|
139
|
+
/**
|
|
140
|
+
* Promise for in-flight token refresh (prevents concurrent refreshes)
|
|
141
|
+
*/
|
|
142
|
+
private refreshPromise;
|
|
143
|
+
/**
|
|
144
|
+
* Callback invoked when tokens are refreshed
|
|
145
|
+
* Useful for persisting new tokens
|
|
146
|
+
*/
|
|
147
|
+
onTokenRefresh?: (tokens: {
|
|
148
|
+
accessToken: string;
|
|
149
|
+
refreshToken: string | undefined;
|
|
150
|
+
expiresAt: number | undefined;
|
|
151
|
+
}) => void | Promise<void>;
|
|
152
|
+
constructor(config: OAuth2AuthConfig);
|
|
153
|
+
/**
|
|
154
|
+
* Returns the Authorization header with Bearer token
|
|
155
|
+
* Uses a mutex to prevent concurrent token refreshes
|
|
156
|
+
*/
|
|
157
|
+
getAuthHeaders(): Promise<Record<string, string>>;
|
|
158
|
+
/**
|
|
159
|
+
* Check if the current token is valid
|
|
160
|
+
*/
|
|
161
|
+
isValid(): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Refresh the access token using the refresh token
|
|
164
|
+
*/
|
|
165
|
+
refresh(): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Set a new access token
|
|
168
|
+
*/
|
|
169
|
+
setAccessToken(token: string, expiresIn?: number): void;
|
|
170
|
+
/**
|
|
171
|
+
* Set a new refresh token
|
|
172
|
+
*/
|
|
173
|
+
setRefreshToken(token: string): void;
|
|
174
|
+
/**
|
|
175
|
+
* Get current tokens (for persistence)
|
|
176
|
+
*/
|
|
177
|
+
getTokens(): {
|
|
178
|
+
accessToken: string | undefined;
|
|
179
|
+
refreshToken: string | undefined;
|
|
180
|
+
expiresAt: number | undefined;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Check if we should proactively refresh the token
|
|
184
|
+
*/
|
|
185
|
+
private shouldRefreshToken;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Factory function to create OAuth2 auth provider
|
|
189
|
+
*/
|
|
190
|
+
declare function createOAuth2Auth(config: OAuth2AuthConfig): OAuth2Auth;
|
|
191
|
+
|
|
192
|
+
export { ApiTokenAuth, ApiTokenAuthConfig, AuthProvider, AuthType, BasicAuth, BasicAuthConfig, OAuth2Auth, OAuth2AuthConfig, PatAuth, PatAuthConfig, createApiTokenAuth, createBasicAuth, createOAuth2Auth, createPatAuth };
|