@gitkraken/core-gitlens 0.58.0 → 0.59.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/CHANGELOG.md +13 -1
- package/dist/git/context.d.ts +1 -0
- package/dist/git/context.js.map +1 -1
- package/dist/git/features.d.ts +1 -1
- package/dist/git/features.js +1 -0
- package/dist/git/features.js.map +1 -1
- package/dist/git/models/graph.d.ts +2 -1
- package/dist/git/models/graph.js.map +1 -1
- package/dist/git/models/graphSession.d.ts +8 -0
- package/dist/git/models/graphSession.js.map +1 -1
- package/dist/git/parsers/diffParser.js +1 -1
- package/dist/git/utils/hiddenRefs.utils.d.ts +26 -0
- package/dist/git/utils/hiddenRefs.utils.js +89 -0
- package/dist/git/utils/hiddenRefs.utils.js.map +1 -0
- package/dist/git/utils/search.utils.d.ts +3 -1
- package/dist/git/utils/search.utils.js +3 -1
- package/dist/git/utils/search.utils.js.map +1 -1
- package/dist/git-cli/exec/git.js +2 -1
- package/dist/git-cli/exec/git.js.map +1 -1
- package/dist/git-cli/exec/locator.d.ts +2 -1
- package/dist/git-cli/exec/locator.js +11 -3
- package/dist/git-cli/exec/locator.js.map +1 -1
- package/dist/git-cli/parsers/blameParser.js +1 -1
- package/dist/git-cli/parsers/indexParser.js +1 -1
- package/dist/git-cli/parsers/statusParser.js +1 -1
- package/dist/git-cli/providers/branches.js +1 -1
- package/dist/git-cli/providers/commits.js +3 -2
- package/dist/git-cli/providers/commits.js.map +1 -1
- package/dist/git-cli/providers/config.js +2 -2
- package/dist/git-cli/providers/graph.d.ts +11 -1
- package/dist/git-cli/providers/graph.js +156 -38
- package/dist/git-cli/providers/graph.js.map +1 -1
- package/dist/git-cli/providers/pausedOperations.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js.map +1 -1
- package/dist/git-cli/providers/refs.js +1 -1
- package/dist/git-cli/providers/staging.js +1 -1
- package/dist/git-cli/providers/tags.js +1 -1
- package/dist/git-cli/service.js +1 -1
- package/dist/ipc/discovery.js +1 -1
- package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
- package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
- package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
- package/dist/plus/integrations/integrationService.js +35 -8
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/models/azurePullRequestWrites.d.ts +3 -1
- package/dist/plus/integrations/models/integration.d.ts +1 -1
- package/dist/plus/integrations/models/integration.js +1 -1
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/models/issueTrackerWrites.d.ts +12 -3
- package/dist/plus/integrations/providers/azure/azure.js +1 -1
- package/dist/plus/integrations/providers/azure/models.d.ts +1 -1
- package/dist/plus/integrations/providers/azure/models.js.map +1 -1
- package/dist/plus/integrations/providers/azurePullRequestWriteErrors.d.ts +6 -2
- package/dist/plus/integrations/providers/azurePullRequestWriteErrors.js +44 -10
- package/dist/plus/integrations/providers/azurePullRequestWriteErrors.js.map +1 -1
- package/dist/plus/integrations/providers/azurePullRequestWrites.d.ts +1 -0
- package/dist/plus/integrations/providers/azurePullRequestWrites.js +28 -13
- package/dist/plus/integrations/providers/azurePullRequestWrites.js.map +1 -1
- package/dist/plus/integrations/providers/github.js +1 -1
- package/dist/plus/integrations/providers/jira-server.d.ts +10 -0
- package/dist/plus/integrations/providers/jira-server.js +16 -1
- package/dist/plus/integrations/providers/jira-server.js.map +1 -1
- package/dist/plus/integrations/providers/jiraIssueWrites.d.ts +6 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.js +60 -11
- package/dist/plus/integrations/providers/jiraIssueWrites.js.map +1 -1
- package/dist/plus/integrations/providers/providerApiClient.js +6 -2
- package/dist/plus/integrations/providers/providerApiClient.js.map +1 -1
- package/dist/plus/integrations/providers/providersApi.d.ts +3 -0
- package/dist/plus/integrations/providers/providersApi.js +13 -0
- package/dist/plus/integrations/providers/providersApi.js.map +1 -1
- package/dist/plus/integrations/reads/currentAccount.d.ts +1 -1
- package/dist/plus/integrations/reads/currentAccount.js +1 -1
- package/dist/plus/integrations/reads/currentAccount.js.map +1 -1
- package/dist/plus/integrations/reads/issueTracker.js +4 -1
- package/dist/plus/integrations/reads/issueTracker.js.map +1 -1
- package/dist/utils/env/node/exec.js +2 -2
- package/docs/integrations.md +40 -5
- package/docs/kepler-read-api-parity.md +2 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { baseUrlFromDomain, hostFromDomain, matchesInstallationOrigin } from "../utils/domain.utils.js";
|
|
1
2
|
import { JiraIssueWriteError, toJiraIssueWriteFailure } from "./jiraIssueWriteErrors.js";
|
|
2
3
|
import { toIssueWebUrl, toStatusCategory } from "./jiraIssueByKey.js";
|
|
3
4
|
//#region ../plus/integrations/src/providers/jiraIssueWrites.ts
|
|
@@ -73,13 +74,34 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
73
74
|
if (site == null) throw new JiraIssueWriteError("not-found");
|
|
74
75
|
const resourceUrl = new URL(site.url);
|
|
75
76
|
if (resourceUrl.protocol !== "https:" || resourceUrl.username || resourceUrl.password) throw new JiraIssueWriteError("unknown");
|
|
76
|
-
const
|
|
77
|
+
const { id, url, scopes } = site;
|
|
78
|
+
const writer = new JiraIssueWriter(request, accessToken, {
|
|
79
|
+
id,
|
|
80
|
+
url,
|
|
81
|
+
scopes
|
|
82
|
+
}, isSessionCurrent);
|
|
77
83
|
const { accountId } = await writer.read("/myself");
|
|
78
84
|
if (typeof accountId !== "string" || !accountId) throw new JiraIssueWriteError("unknown");
|
|
79
85
|
if (options.expectedAccountId !== void 0 && options.expectedAccountId !== accountId) throw new JiraIssueWriteError("forbidden");
|
|
80
86
|
writer.accountId = accountId;
|
|
81
87
|
return writer;
|
|
82
88
|
}
|
|
89
|
+
static async connectServer(request, session, options, isSessionCurrent) {
|
|
90
|
+
const siteUrl = normalizeJiraServerSiteUrl(session.baseUrl ?? session.domain, session.protocol);
|
|
91
|
+
if (normalizeJiraServerSiteUrl(options.siteUrl) !== siteUrl || options.siteUrl !== siteUrl) throw new JiraIssueWriteError("conflict");
|
|
92
|
+
if (hostFromDomain(session.domain) !== options.resourceId || !matchesInstallationOrigin(session.domain, siteUrl)) throw new JiraIssueWriteError("conflict");
|
|
93
|
+
const writer = new JiraIssueWriter(request, session.accessToken, {
|
|
94
|
+
id: options.resourceId,
|
|
95
|
+
url: siteUrl,
|
|
96
|
+
scopes: [],
|
|
97
|
+
server: true
|
|
98
|
+
}, isSessionCurrent);
|
|
99
|
+
const { key } = await writer.read("/myself");
|
|
100
|
+
if (!isJiraWriteIdentifier(key)) throw new JiraIssueWriteError("unknown");
|
|
101
|
+
if (options.expectedAccountId !== void 0 && options.expectedAccountId !== key) throw new JiraIssueWriteError("forbidden");
|
|
102
|
+
writer.accountId = key;
|
|
103
|
+
return writer;
|
|
104
|
+
}
|
|
83
105
|
accountId = "";
|
|
84
106
|
constructor(request, accessToken, site, isSessionCurrent) {
|
|
85
107
|
this.request = request;
|
|
@@ -97,7 +119,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
97
119
|
project
|
|
98
120
|
};
|
|
99
121
|
if (options.issueTypeId === void 0) {
|
|
100
|
-
const { values, truncated } = await this.readPages(this.createMetadataPath(project.id), (page) => page.issueTypes);
|
|
122
|
+
const { values, truncated } = await this.readPages(this.createMetadataPath(project.id), (page) => this.site.server ? page.values : page.issueTypes);
|
|
101
123
|
return {
|
|
102
124
|
...result,
|
|
103
125
|
issueTypes: values.map(({ id, name }) => ({
|
|
@@ -153,8 +175,11 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
153
175
|
}
|
|
154
176
|
async delete(options) {
|
|
155
177
|
if (!isJiraWriteIdentifier(options.expectedAccountId) || !isNumericId(options.expectedIssueId)) throw new JiraIssueWriteError("invalid-input");
|
|
156
|
-
const
|
|
157
|
-
await this.ensureDeletable(
|
|
178
|
+
const resolved = await this.resolveMutationIssue(options);
|
|
179
|
+
await this.ensureDeletable(resolved);
|
|
180
|
+
const issue = this.site.server ? await this.resolveMutationIssue(options) : resolved;
|
|
181
|
+
const reason = this.getDeleteRefusal(true, issue);
|
|
182
|
+
if (reason !== void 0) throw new JiraIssueWriteError(reason);
|
|
158
183
|
const receipt = this.toReceipt(issue);
|
|
159
184
|
return this.dispatch("DELETE", `/issue/${issue.id}?deleteSubtasks=false`, 204, () => receipt);
|
|
160
185
|
}
|
|
@@ -176,7 +201,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
176
201
|
}
|
|
177
202
|
async updateIssue(options) {
|
|
178
203
|
if (!isNumericId(options.expectedIssueId)) throw new JiraIssueWriteError("invalid-input");
|
|
179
|
-
const issue = await this.
|
|
204
|
+
const issue = await this.resolveMutationIssue(options);
|
|
180
205
|
const path = `/issue/${issue.id}`;
|
|
181
206
|
const readReceipt = async () => this.toReceipt(await this.readIssue(issue.id));
|
|
182
207
|
const permissions = await this.readPermissions(issue.id);
|
|
@@ -184,6 +209,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
184
209
|
if (!permissions.edit) throw new JiraIssueWriteError("forbidden");
|
|
185
210
|
const fields = validateFields(options.fields, this.editableFields(options), await this.readEditFields(issue.id));
|
|
186
211
|
if (Object.keys(fields).length === 0) throw new JiraIssueWriteError("invalid-input");
|
|
212
|
+
if (this.site.server) await this.resolveMutationIssue(options);
|
|
187
213
|
return this.dispatch("PUT", path, 204, readReceipt, { fields });
|
|
188
214
|
}
|
|
189
215
|
if (!isNumericId(options.transitionId)) throw new JiraIssueWriteError("invalid-input");
|
|
@@ -191,6 +217,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
191
217
|
const transition = (await this.readTransitions(issue.id)).find((item) => item.id === options.transitionId);
|
|
192
218
|
if (transition?.isAvailable !== true) throw new JiraIssueWriteError("transition-unavailable");
|
|
193
219
|
const fields = validateFields(options.fields, this.editableFields(options), transition.hasScreen ? transition.fields : []);
|
|
220
|
+
if (this.site.server) await this.resolveMutationIssue(options);
|
|
194
221
|
return this.dispatch("POST", `${path}/transitions`, 204, readReceipt, {
|
|
195
222
|
transition: { id: transition.id },
|
|
196
223
|
fields
|
|
@@ -204,6 +231,13 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
204
231
|
...description !== void 0 && { description }
|
|
205
232
|
};
|
|
206
233
|
}
|
|
234
|
+
async resolveMutationIssue(options) {
|
|
235
|
+
const expectedProjectId = "expectedProjectId" in options ? options.expectedProjectId : void 0;
|
|
236
|
+
if (this.site.server && !isNumericId(expectedProjectId)) throw new JiraIssueWriteError("invalid-input");
|
|
237
|
+
const issue = await this.resolveIssue(options);
|
|
238
|
+
if (this.site.server && expectedProjectId !== issue.fields.project.id) throw new JiraIssueWriteError("conflict");
|
|
239
|
+
return issue;
|
|
240
|
+
}
|
|
207
241
|
async resolveIssue(options) {
|
|
208
242
|
if (!isJiraWriteIdentifier(options.issue) || options.expectedIssueId !== void 0 && !isNumericId(options.expectedIssueId)) throw new JiraIssueWriteError("invalid-input");
|
|
209
243
|
const issue = await this.readIssue(options.issue);
|
|
@@ -241,8 +275,9 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
241
275
|
}
|
|
242
276
|
async readPermissionsFor(params) {
|
|
243
277
|
const query = new URLSearchParams(params);
|
|
278
|
+
if (this.site.server) query.delete("permissions");
|
|
244
279
|
const { permissions } = await this.read(`/mypermissions?${query.toString()}`);
|
|
245
|
-
return permissions;
|
|
280
|
+
return this.site.server ? Object.fromEntries(Object.entries(permissions).map(([key, permission]) => [permission.key ?? key, permission])) : permissions;
|
|
246
281
|
}
|
|
247
282
|
async readTransitions(issueId) {
|
|
248
283
|
const { transitions } = await this.read(`/issue/${issueId}/transitions?expand=transitions.fields`);
|
|
@@ -250,7 +285,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
250
285
|
id: transition.id,
|
|
251
286
|
name: transition.name,
|
|
252
287
|
to: toStatus(transition.to),
|
|
253
|
-
hasScreen: transition.hasScreen === true,
|
|
288
|
+
hasScreen: transition.hasScreen === true || this.site.server === true && Object.keys(transition.fields ?? {}).length > 0,
|
|
254
289
|
isAvailable: transition.isAvailable !== false,
|
|
255
290
|
isConditional: transition.isConditional === true,
|
|
256
291
|
fields: toFields(transition.fields ?? {})
|
|
@@ -262,7 +297,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
262
297
|
}
|
|
263
298
|
async readCreateFields(projectId, issueTypeId) {
|
|
264
299
|
if (!isNumericId(issueTypeId)) throw new JiraIssueWriteError("invalid-input");
|
|
265
|
-
const { values, truncated } = await this.readPages(`${this.createMetadataPath(projectId)}/${issueTypeId}`, (page) => page.fields ?? page.results);
|
|
300
|
+
const { values, truncated } = await this.readPages(`${this.createMetadataPath(projectId)}/${issueTypeId}`, (page) => this.site.server ? page.values : page.fields ?? page.results);
|
|
266
301
|
return {
|
|
267
302
|
values: values.map((field) => {
|
|
268
303
|
const id = field.fieldId ?? field.key;
|
|
@@ -281,9 +316,9 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
281
316
|
const startAt = values.length;
|
|
282
317
|
const page = await this.read(`${path}?startAt=${startAt}&maxResults=${pageSize}`);
|
|
283
318
|
const rows = items(page);
|
|
284
|
-
if (!Array.isArray(rows) || !Number.isSafeInteger(page.total) || page.total < 0 || page.startAt !== startAt) throw new Error("Jira returned invalid create metadata pagination");
|
|
319
|
+
if (!Array.isArray(rows) || (this.site.server ? typeof (page.last ?? page.isLast) !== "boolean" : !Number.isSafeInteger(page.total) || (page.total ?? -1) < 0) || (this.site.server ? page.start ?? page.startAt : page.startAt) !== startAt) throw new Error("Jira returned invalid create metadata pagination");
|
|
285
320
|
values.push(...rows);
|
|
286
|
-
if (values.length >= page.total) return {
|
|
321
|
+
if (this.site.server ? page.last ?? page.isLast : values.length >= page.total) return {
|
|
287
322
|
values,
|
|
288
323
|
truncated: false
|
|
289
324
|
};
|
|
@@ -296,7 +331,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
296
331
|
}
|
|
297
332
|
getDeleteRefusal(allowed, issue) {
|
|
298
333
|
if (!allowed) return "forbidden";
|
|
299
|
-
if (!this.site.scopes?.some((scope) => scope === "delete:issue:jira" || scope === "write:jira-work")) return "insufficient-scope";
|
|
334
|
+
if (!this.site.server && !this.site.scopes?.some((scope) => scope === "delete:issue:jira" || scope === "write:jira-work")) return "insufficient-scope";
|
|
300
335
|
if (!Array.isArray(issue.fields.subtasks) || issue.fields.subtasks.length !== 0) return "invalid-input";
|
|
301
336
|
}
|
|
302
337
|
async ensureDeletable(issue) {
|
|
@@ -382,6 +417,7 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
382
417
|
}
|
|
383
418
|
}
|
|
384
419
|
url(path) {
|
|
420
|
+
if (this.site.server) return `${this.site.url}/rest/api/2${path}`;
|
|
385
421
|
return `https://api.atlassian.com/ex/jira/${encodeURIComponent(this.site.id)}/rest/api/2${path}`;
|
|
386
422
|
}
|
|
387
423
|
headers() {
|
|
@@ -391,6 +427,19 @@ var JiraIssueWriter = class JiraIssueWriter {
|
|
|
391
427
|
};
|
|
392
428
|
}
|
|
393
429
|
};
|
|
430
|
+
function normalizeJiraServerSiteUrl(value, protocol = "https:") {
|
|
431
|
+
if (typeof value !== "string" || value.trim() !== value || /[\\?#]/.test(value)) throw new JiraIssueWriteError("invalid-input");
|
|
432
|
+
let url;
|
|
433
|
+
try {
|
|
434
|
+
url = new URL(/^[a-z][a-z\d+.-]*:\/\//i.test(value) ? value : `${protocol}//${value}`);
|
|
435
|
+
} catch {
|
|
436
|
+
throw new JiraIssueWriteError("invalid-input");
|
|
437
|
+
}
|
|
438
|
+
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || /%|(?:^|\/)\.\.?(?:\/|$)/.test(value.replace(/^[a-z]+:\/\/[^/]+/i, ""))) throw new JiraIssueWriteError("invalid-input");
|
|
439
|
+
const normalized = baseUrlFromDomain(value, protocol);
|
|
440
|
+
if (normalized == null) throw new JiraIssueWriteError("invalid-input");
|
|
441
|
+
return normalized;
|
|
442
|
+
}
|
|
394
443
|
//#endregion
|
|
395
444
|
export { JiraIssueWriter, isJiraWriteIdentifier };
|
|
396
445
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jiraIssueWrites.js","names":[],"sources":["../../../../../plus/integrations/src/providers/jiraIssueWrites.ts"],"sourcesContent":["import type {\n\tIssueTrackerCreateOptions,\n\tIssueTrackerCreateOptionsResult,\n\tIssueTrackerDeleteOptions,\n\tIssueTrackerField,\n\tIssueTrackerIssueReceipt,\n\tIssueTrackerIssueWriteOptions,\n\tIssueTrackerIssueWriteOptionsResult,\n\tIssueTrackerStatus,\n\tIssueTrackerTransition,\n\tIssueTrackerWriteConnection,\n\tIssueTrackerWriteOptions,\n\tIssueTrackerWriteResult,\n\tIssueTrackerWriteTargetOptions,\n\tIssueTrackerWriteTargetResult,\n} from '../models/issueTrackerWrites.js';\nimport { toIssueWebUrl, toStatusCategory } from './jiraIssueByKey.js';\nimport { JiraIssueWriteError, toJiraIssueWriteFailure } from './jiraIssueWriteErrors.js';\nimport type { ProviderRequestFunction } from './models.js';\n\ntype Project = IssueTrackerIssueReceipt['project'];\ntype IssueType = IssueTrackerIssueReceipt['issueType'];\ntype JiraStatus = { id: string; name: string; statusCategory: { key: string } };\ntype JiraIssue = {\n\tid: string;\n\tkey: string;\n\tfields: { project: Project; issuetype: IssueType; summary: string; status: JiraStatus; subtasks?: unknown[] };\n};\ntype JiraField = Omit<IssueTrackerField, 'fieldId' | 'hasDefaultValue'> & {\n\tfieldId?: string;\n\tkey?: string;\n\thasDefaultValue?: boolean;\n};\ntype JiraTransition = Omit<IssueTrackerTransition, 'to' | 'fields' | 'isAvailable' | 'isConditional' | 'hasScreen'> & {\n\tto: JiraStatus;\n\tfields?: Record<string, JiraField>;\n\tisAvailable?: boolean;\n\tisConditional?: boolean;\n\thasScreen?: boolean;\n};\ntype JiraPage = {\n\tstartAt: number;\n\ttotal: number;\n\tfields?: JiraField[];\n\tresults?: JiraField[];\n\tissueTypes?: IssueType[];\n};\ntype JiraSite = { id: string; url: string; scopes: string[] };\ntype JiraPermissions = Record<string, { havePermission?: boolean }>;\n\nconst pageSize = 50;\nconst maxPages = 20;\nconst createPermission = 'CREATE_ISSUES';\nconst permissionKeys = { edit: 'EDIT_ISSUES', transition: 'TRANSITION_ISSUES', delete: 'DELETE_ISSUES' };\nconst reservedFields = new Set(['summary', 'description', 'project', 'issuetype']);\nconst numericId = /^\\d+$/;\n\nfunction isNumericId(value: unknown): value is string {\n\treturn typeof value === 'string' && numericId.test(value);\n}\n\nexport function isJiraWriteIdentifier(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === 'string' &&\n\t\tvalue.length > 0 &&\n\t\tvalue.trim() === value &&\n\t\tvalue !== '.' &&\n\t\tvalue !== '..' &&\n\t\t!/[\\\\/?#]/.test(value)\n\t);\n}\n\nfunction toStatus(status: JiraStatus): IssueTrackerStatus {\n\tif (\n\t\ttypeof status?.id !== 'string' ||\n\t\ttypeof status.name !== 'string' ||\n\t\ttypeof status.statusCategory?.key !== 'string'\n\t) {\n\t\tthrow new Error('Jira returned incomplete status metadata');\n\t}\n\n\treturn { id: status.id, name: status.name, category: toStatusCategory(status.statusCategory.key) };\n}\n\nfunction toField(fieldId: string, field: JiraField): IssueTrackerField {\n\treturn {\n\t\tfieldId: fieldId,\n\t\tname: field.name,\n\t\trequired: field.required,\n\t\tschema: structuredClone(field.schema),\n\t\tallowedValues: structuredClone(field.allowedValues),\n\t\thasDefaultValue: field.hasDefaultValue ?? false,\n\t\toperations: field.operations,\n\t};\n}\n\nfunction toFields(fields: Record<string, JiraField>): IssueTrackerField[] {\n\treturn Object.entries(fields).map(([id, field]) => toField(id, field));\n}\n\nfunction validateFields(\n\tfields: Readonly<Record<string, unknown>> | undefined,\n\ttopLevel: { summary?: string; description?: string },\n\tscreen: readonly IssueTrackerField[],\n): Record<string, unknown> {\n\tif (fields !== undefined && (fields == null || typeof fields !== 'object' || Array.isArray(fields))) {\n\t\tthrow new JiraIssueWriteError('invalid-input');\n\t}\n\n\tconst values = { ...fields, ...topLevel };\n\tconst settable = new Set(screen.filter(field => field.operations.includes('set')).map(field => field.fieldId));\n\tconst invalid = Object.keys(values).filter(\n\t\tkey => !settable.has(key) || (reservedFields.has(key) && Object.hasOwn(fields ?? {}, key)),\n\t);\n\tif (invalid.length !== 0) {\n\t\tthrow new JiraIssueWriteError(\n\t\t\t'invalid-input',\n\t\t\tObject.fromEntries(invalid.map(key => [key, 'field-not-settable'])),\n\t\t);\n\t}\n\n\treturn values;\n}\n\nexport class JiraIssueWriter {\n\tstatic async connect(\n\t\trequest: ProviderRequestFunction,\n\t\taccessToken: string,\n\t\toptions: IssueTrackerWriteConnection,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t): Promise<JiraIssueWriter> {\n\t\tconst { body: sites } = await request<JiraSite[]>({\n\t\t\turl: 'https://api.atlassian.com/oauth/token/accessible-resources',\n\t\t\tredirect: 'error',\n\t\t\theaders: { Authorization: `Bearer ${accessToken}`, Accept: 'application/json' },\n\t\t});\n\t\tconst site = sites.find(\n\t\t\tresource =>\n\t\t\t\tresource.id === options.resourceId && resource.scopes?.some(scope => /:jira(?:-|$)/.test(scope)),\n\t\t);\n\t\tif (site == null) throw new JiraIssueWriteError('not-found');\n\n\t\tconst resourceUrl = new URL(site.url);\n\t\tif (resourceUrl.protocol !== 'https:' || resourceUrl.username || resourceUrl.password) {\n\t\t\tthrow new JiraIssueWriteError('unknown');\n\t\t}\n\n\t\tconst writer = new JiraIssueWriter(request, accessToken, site, isSessionCurrent);\n\t\tconst { accountId } = await writer.read<{ accountId: string }>('/myself');\n\t\tif (typeof accountId !== 'string' || !accountId) throw new JiraIssueWriteError('unknown');\n\n\t\tif (options.expectedAccountId !== undefined && options.expectedAccountId !== accountId) {\n\t\t\tthrow new JiraIssueWriteError('forbidden');\n\t\t}\n\n\t\twriter.accountId = accountId;\n\t\treturn writer;\n\t}\n\n\tprivate accountId = '';\n\n\tprivate constructor(\n\t\tprivate readonly request: ProviderRequestFunction,\n\t\tprivate readonly accessToken: string,\n\t\tprivate readonly site: JiraSite,\n\t\tprivate readonly isSessionCurrent: () => Promise<boolean>,\n\t) {}\n\n\tasync getCreateOptions(options: IssueTrackerCreateOptions): Promise<IssueTrackerCreateOptionsResult> {\n\t\tconst project = await this.readCreateProject(options.project);\n\t\tconst result = {\n\t\t\tok: true as const,\n\t\t\tresourceId: this.site.id,\n\t\t\tsiteUrl: this.site.url,\n\t\t\taccountId: this.accountId,\n\t\t\tproject: project,\n\t\t};\n\t\tif (options.issueTypeId === undefined) {\n\t\t\tconst { values, truncated } = await this.readPages(\n\t\t\t\tthis.createMetadataPath(project.id),\n\t\t\t\tpage => page.issueTypes,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\tissueTypes: values.map(({ id, name }) => ({ id: id, name: name })),\n\t\t\t\ttruncated: truncated,\n\t\t\t};\n\t\t}\n\n\t\tconst { values, truncated } = await this.readCreateFields(project.id, options.issueTypeId);\n\t\treturn { ...result, issueTypeId: options.issueTypeId, fields: values, truncated: truncated };\n\t}\n\n\tasync getIssueOptions(options: IssueTrackerIssueWriteOptions): Promise<IssueTrackerIssueWriteOptionsResult> {\n\t\tconst issue = await this.resolveIssue(options);\n\t\tconst permissions = await this.readPermissions(issue.id);\n\t\tconst [fields, transitions] = await Promise.all([\n\t\t\tpermissions.edit ? this.readEditFields(issue.id) : [],\n\t\t\tpermissions.transition ? this.readTransitions(issue.id) : [],\n\t\t]);\n\t\tconst reason = this.getDeleteRefusal(permissions.delete, issue);\n\t\treturn {\n\t\t\tok: true,\n\t\t\tissue: this.toReceipt(issue),\n\t\t\taccountId: this.accountId,\n\t\t\tfields: fields,\n\t\t\ttransitions: transitions,\n\t\t\tpermissions: permissions,\n\t\t\tdeleteCapability: reason === undefined ? { allowed: true } : { allowed: false, reason: reason },\n\t\t};\n\t}\n\n\tasync resolveTarget(options: IssueTrackerWriteTargetOptions): Promise<IssueTrackerWriteTargetResult> {\n\t\tif (options.intent !== undefined && options.intent !== 'delete') throw new JiraIssueWriteError('invalid-input');\n\n\t\tconst issue = await this.resolveIssue(options);\n\t\tif (options.intent === 'delete') {\n\t\t\tawait this.ensureDeletable(issue);\n\t\t}\n\n\t\treturn { ok: true, issue: this.toReceipt(issue), accountId: this.accountId };\n\t}\n\n\tasync write(options: IssueTrackerWriteOptions): Promise<IssueTrackerWriteResult> {\n\t\tswitch (options.action) {\n\t\t\tcase 'create':\n\t\t\t\treturn this.createIssue(options);\n\t\t\tcase 'edit':\n\t\t\tcase 'transition':\n\t\t\t\treturn this.updateIssue(options);\n\t\t\tdefault:\n\t\t\t\tthrow new JiraIssueWriteError('invalid-input');\n\t\t}\n\t}\n\n\tasync delete(options: IssueTrackerDeleteOptions): Promise<IssueTrackerWriteResult> {\n\t\tif (!isJiraWriteIdentifier(options.expectedAccountId) || !isNumericId(options.expectedIssueId)) {\n\t\t\tthrow new JiraIssueWriteError('invalid-input');\n\t\t}\n\n\t\tconst issue = await this.resolveIssue(options);\n\t\tawait this.ensureDeletable(issue);\n\t\tconst receipt = this.toReceipt(issue);\n\t\treturn this.dispatch('DELETE', `/issue/${issue.id}?deleteSubtasks=false`, 204, () => receipt);\n\t}\n\n\tprivate async createIssue(\n\t\toptions: Extract<IssueTrackerWriteOptions, { action: 'create' }>,\n\t): Promise<IssueTrackerWriteResult> {\n\t\tif (typeof options.summary !== 'string' || !options.summary.trim()) {\n\t\t\tthrow new JiraIssueWriteError('invalid-input');\n\t\t}\n\n\t\tconst topLevel = this.editableFields(options);\n\t\tconst project = await this.readCreateProject(options.project);\n\t\tconst screen = await this.readCreateFields(project.id, options.issueTypeId);\n\t\tconst fields = validateFields(options.fields, topLevel, screen.values);\n\t\treturn this.dispatch(\n\t\t\t'POST',\n\t\t\t'/issue',\n\t\t\t201,\n\t\t\tasync response => {\n\t\t\t\tconst created = response as { id: string };\n\t\t\t\tif (!isNumericId(created.id)) throw new Error('Jira returned no issue ID');\n\n\t\t\t\treturn this.toReceipt(await this.readIssue(created.id));\n\t\t\t},\n\t\t\t{ fields: { ...fields, project: { id: project.id }, issuetype: { id: options.issueTypeId } } },\n\t\t);\n\t}\n\n\tprivate async updateIssue(\n\t\toptions: Extract<IssueTrackerWriteOptions, { action: 'edit' | 'transition' }>,\n\t): Promise<IssueTrackerWriteResult> {\n\t\tif (!isNumericId(options.expectedIssueId)) throw new JiraIssueWriteError('invalid-input');\n\n\t\tconst issue = await this.resolveIssue(options);\n\t\tconst path = `/issue/${issue.id}`;\n\t\tconst readReceipt = async () => this.toReceipt(await this.readIssue(issue.id));\n\t\tconst permissions = await this.readPermissions(issue.id);\n\t\tif (options.action === 'edit') {\n\t\t\tif (!permissions.edit) throw new JiraIssueWriteError('forbidden');\n\n\t\t\tconst fields = validateFields(\n\t\t\t\toptions.fields,\n\t\t\t\tthis.editableFields(options),\n\t\t\t\tawait this.readEditFields(issue.id),\n\t\t\t);\n\t\t\tif (Object.keys(fields).length === 0) throw new JiraIssueWriteError('invalid-input');\n\n\t\t\treturn this.dispatch('PUT', path, 204, readReceipt, { fields: fields });\n\t\t}\n\n\t\tif (!isNumericId(options.transitionId)) throw new JiraIssueWriteError('invalid-input');\n\t\tif (!permissions.transition) throw new JiraIssueWriteError('forbidden');\n\n\t\tconst transition = (await this.readTransitions(issue.id)).find(item => item.id === options.transitionId);\n\t\tif (transition?.isAvailable !== true) throw new JiraIssueWriteError('transition-unavailable');\n\n\t\tconst fields = validateFields(\n\t\t\toptions.fields,\n\t\t\tthis.editableFields(options),\n\t\t\ttransition.hasScreen ? transition.fields : [],\n\t\t);\n\t\treturn this.dispatch('POST', `${path}/transitions`, 204, readReceipt, {\n\t\t\ttransition: { id: transition.id },\n\t\t\tfields: fields,\n\t\t});\n\t}\n\n\tprivate editableFields(options: { summary?: string; description?: string }): {\n\t\tsummary?: string;\n\t\tdescription?: string;\n\t} {\n\t\tconst { summary, description } = options;\n\t\tif (\n\t\t\t(summary !== undefined && (typeof summary !== 'string' || !summary.trim())) ||\n\t\t\t(description !== undefined && typeof description !== 'string')\n\t\t) {\n\t\t\tthrow new JiraIssueWriteError('invalid-input');\n\t\t}\n\n\t\treturn {\n\t\t\t...(summary !== undefined && { summary: summary }),\n\t\t\t...(description !== undefined && { description: description }),\n\t\t};\n\t}\n\n\tprivate async resolveIssue(options: IssueTrackerIssueWriteOptions): Promise<JiraIssue> {\n\t\tif (\n\t\t\t!isJiraWriteIdentifier(options.issue) ||\n\t\t\t(options.expectedIssueId !== undefined && !isNumericId(options.expectedIssueId))\n\t\t) {\n\t\t\tthrow new JiraIssueWriteError('invalid-input');\n\t\t}\n\n\t\tconst issue = await this.readIssue(options.issue);\n\t\tif (\n\t\t\t(options.expectedIssueId !== undefined && options.expectedIssueId !== issue.id) ||\n\t\t\t(!numericId.test(options.issue) && options.issue.toUpperCase() !== issue.key.toUpperCase())\n\t\t) {\n\t\t\tthrow new JiraIssueWriteError('conflict');\n\t\t}\n\n\t\treturn issue;\n\t}\n\n\tprivate async readIssue(idOrKey: string): Promise<JiraIssue> {\n\t\tconst issue = await this.read<JiraIssue>(\n\t\t\t`/issue/${encodeURIComponent(idOrKey)}?fields=project,issuetype,summary,status,subtasks`,\n\t\t);\n\t\tif (\n\t\t\t!isNumericId(issue.id) ||\n\t\t\t(numericId.test(idOrKey) && issue.id !== idOrKey) ||\n\t\t\t!isJiraWriteIdentifier(issue.key) ||\n\t\t\t!isJiraWriteIdentifier(issue.fields?.project?.key) ||\n\t\t\t!issue.key.startsWith(`${issue.fields.project.key}-`) ||\n\t\t\t!isNumericId(issue.fields.project.id)\n\t\t) {\n\t\t\tthrow new Error('Jira returned inconsistent issue identity');\n\t\t}\n\n\t\treturn issue;\n\t}\n\n\tprivate async readCreateProject(idOrKey: string): Promise<Project> {\n\t\tif (!isJiraWriteIdentifier(idOrKey)) throw new JiraIssueWriteError('invalid-input');\n\n\t\tconst { id, key } = await this.read<Project>(`/project/${encodeURIComponent(idOrKey)}`);\n\t\tif (\n\t\t\t!isNumericId(id) ||\n\t\t\t!isJiraWriteIdentifier(key) ||\n\t\t\t(numericId.test(idOrKey) ? id !== idOrKey : key.toUpperCase() !== idOrKey.toUpperCase())\n\t\t) {\n\t\t\tthrow new JiraIssueWriteError('conflict');\n\t\t}\n\n\t\tconst permissions = await this.readPermissionsFor({ projectId: id, permissions: createPermission });\n\t\tif (permissions[createPermission]?.havePermission !== true) throw new JiraIssueWriteError('forbidden');\n\n\t\treturn { id: id, key: key };\n\t}\n\n\tprivate async readPermissions(issueId: string): Promise<IssueTrackerIssueWriteOptionsSuccess['permissions']> {\n\t\tconst permissions = await this.readPermissionsFor({\n\t\t\tissueId: issueId,\n\t\t\tpermissions: Object.values(permissionKeys).join(','),\n\t\t});\n\t\treturn {\n\t\t\tedit: permissions[permissionKeys.edit]?.havePermission === true,\n\t\t\ttransition: permissions[permissionKeys.transition]?.havePermission === true,\n\t\t\tdelete: permissions[permissionKeys.delete]?.havePermission === true,\n\t\t};\n\t}\n\n\tprivate async readPermissionsFor(params: Record<string, string>): Promise<JiraPermissions> {\n\t\tconst query = new URLSearchParams(params);\n\t\tconst { permissions } = await this.read<{ permissions: JiraPermissions }>(`/mypermissions?${query.toString()}`);\n\t\treturn permissions;\n\t}\n\n\tprivate async readTransitions(issueId: string): Promise<IssueTrackerTransition[]> {\n\t\tconst { transitions } = await this.read<{ transitions: JiraTransition[] }>(\n\t\t\t`/issue/${issueId}/transitions?expand=transitions.fields`,\n\t\t);\n\t\treturn transitions.map(transition => ({\n\t\t\tid: transition.id,\n\t\t\tname: transition.name,\n\t\t\tto: toStatus(transition.to),\n\t\t\thasScreen: transition.hasScreen === true,\n\t\t\tisAvailable: transition.isAvailable !== false,\n\t\t\tisConditional: transition.isConditional === true,\n\t\t\tfields: toFields(transition.fields ?? {}),\n\t\t}));\n\t}\n\n\tprivate async readEditFields(issueId: string): Promise<IssueTrackerField[]> {\n\t\tconst { fields } = await this.read<{ fields: Record<string, JiraField> }>(`/issue/${issueId}/editmeta`);\n\t\treturn toFields(fields);\n\t}\n\n\tprivate async readCreateFields(\n\t\tprojectId: string,\n\t\tissueTypeId: string,\n\t): Promise<{ values: IssueTrackerField[]; truncated: boolean }> {\n\t\tif (!isNumericId(issueTypeId)) throw new JiraIssueWriteError('invalid-input');\n\n\t\tconst { values, truncated } = await this.readPages(\n\t\t\t`${this.createMetadataPath(projectId)}/${issueTypeId}`,\n\t\t\tpage => page.fields ?? page.results,\n\t\t);\n\t\treturn {\n\t\t\tvalues: values.map(field => {\n\t\t\t\tconst id = field.fieldId ?? field.key;\n\t\t\t\tif (!id) throw new Error('Jira returned metadata with no field ID');\n\n\t\t\t\treturn toField(id, field);\n\t\t\t}),\n\t\t\ttruncated: truncated,\n\t\t};\n\t}\n\n\tprivate createMetadataPath(projectId: string): string {\n\t\treturn `/issue/createmeta/${projectId}/issuetypes`;\n\t}\n\n\tprivate async readPages<T>(\n\t\tpath: string,\n\t\titems: (page: JiraPage) => T[] | undefined,\n\t): Promise<{ values: T[]; truncated: boolean }> {\n\t\tconst values: T[] = [];\n\t\tfor (let index = 0; index < maxPages; index++) {\n\t\t\tconst startAt = values.length;\n\t\t\tconst page = await this.read<JiraPage>(`${path}?startAt=${startAt}&maxResults=${pageSize}`);\n\t\t\tconst rows = items(page);\n\t\t\tif (\n\t\t\t\t!Array.isArray(rows) ||\n\t\t\t\t!Number.isSafeInteger(page.total) ||\n\t\t\t\tpage.total < 0 ||\n\t\t\t\tpage.startAt !== startAt\n\t\t\t) {\n\t\t\t\tthrow new Error('Jira returned invalid create metadata pagination');\n\t\t\t}\n\n\t\t\tvalues.push(...rows);\n\t\t\tif (values.length >= page.total) return { values: values, truncated: false };\n\t\t\tif (rows.length === 0) break;\n\t\t}\n\n\t\treturn { values: values, truncated: true };\n\t}\n\n\tprivate getDeleteRefusal(\n\t\tallowed: boolean,\n\t\tissue: JiraIssue,\n\t): 'forbidden' | 'insufficient-scope' | 'invalid-input' | undefined {\n\t\tif (!allowed) return 'forbidden';\n\t\tif (!this.site.scopes?.some(scope => scope === 'delete:issue:jira' || scope === 'write:jira-work')) {\n\t\t\treturn 'insufficient-scope';\n\t\t}\n\t\tif (!Array.isArray(issue.fields.subtasks) || issue.fields.subtasks.length !== 0) return 'invalid-input';\n\n\t\treturn undefined;\n\t}\n\n\tprivate async ensureDeletable(issue: JiraIssue): Promise<void> {\n\t\tconst reason = this.getDeleteRefusal((await this.readPermissions(issue.id)).delete, issue);\n\t\tif (reason !== undefined) throw new JiraIssueWriteError(reason);\n\t}\n\n\tprivate toReceipt(issue: JiraIssue): IssueTrackerIssueReceipt {\n\t\tconst { project, issuetype, summary, status } = issue.fields;\n\t\tif (!isNumericId(issuetype?.id) || typeof issuetype.name !== 'string' || typeof summary !== 'string') {\n\t\t\tthrow new Error('Jira returned incomplete issue metadata');\n\t\t}\n\n\t\treturn {\n\t\t\tresourceId: this.site.id,\n\t\t\tsiteUrl: this.site.url,\n\t\t\tid: issue.id,\n\t\t\tkey: issue.key,\n\t\t\turl: toIssueWebUrl(this.site.url, issue.key),\n\t\t\tproject: { id: project.id, key: project.key },\n\t\t\tissueType: { id: issuetype.id, name: issuetype.name },\n\t\t\tsummary: summary,\n\t\t\tstatus: toStatus(status),\n\t\t};\n\t}\n\n\tprivate async read<T>(path: string): Promise<T> {\n\t\treturn (await this.request<T>({ url: this.url(path), headers: this.headers(), redirect: 'error' })).body;\n\t}\n\n\tprivate async dispatch(\n\t\tmethod: 'POST' | 'PUT' | 'DELETE',\n\t\tpath: string,\n\t\texpectedStatus: number,\n\t\treceipt: (response: unknown) => IssueTrackerIssueReceipt | Promise<IssueTrackerIssueReceipt>,\n\t\tpayload?: object,\n\t): Promise<IssueTrackerWriteResult> {\n\t\tlet body: string | undefined;\n\t\ttry {\n\t\t\tbody = payload === undefined ? undefined : JSON.stringify(payload);\n\t\t} catch {\n\t\t\treturn { ok: false, reason: 'invalid-input', mutationDispatched: false };\n\t\t}\n\n\t\tif (!(await this.isSessionCurrent())) return { ok: false, reason: 'no-connection', mutationDispatched: false };\n\n\t\tlet response;\n\t\ttry {\n\t\t\tresponse = await this.request<unknown>({\n\t\t\t\turl: this.url(path),\n\t\t\t\tmethod: method,\n\t\t\t\theaders: { ...this.headers(), ...(body !== undefined && { 'Content-Type': 'application/json' }) },\n\t\t\t\tbody: body,\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t} catch (ex) {\n\t\t\treturn toJiraIssueWriteFailure(ex, true);\n\t\t}\n\n\t\tif (response.status !== expectedStatus) return { ok: false, reason: 'unknown', applied: 'maybe' };\n\n\t\ttry {\n\t\t\treturn { ok: true, issue: await receipt(response.body), accountId: this.accountId };\n\t\t} catch {\n\t\t\treturn { ok: false, reason: 'unknown', applied: 'maybe' };\n\t\t}\n\t}\n\n\tprivate url(path: string): string {\n\t\treturn `https://api.atlassian.com/ex/jira/${encodeURIComponent(this.site.id)}/rest/api/2${path}`;\n\t}\n\n\tprivate headers(): Record<string, string> {\n\t\treturn { Authorization: `Bearer ${this.accessToken}`, Accept: 'application/json' };\n\t}\n}\n\ntype IssueTrackerIssueWriteOptionsSuccess = Extract<IssueTrackerIssueWriteOptionsResult, { ok: true }>;\n"],"mappings":";;;AAkDA,MAAM,WAAW;AACjB,MAAM,WAAW;AACjB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;CAAE,MAAM;CAAe,YAAY;CAAqB,QAAQ;AAAgB;AACvG,MAAM,iCAAiB,IAAI,IAAI;CAAC;CAAW;CAAe;CAAW;AAAW,CAAC;AACjF,MAAM,YAAY;AAElB,SAAS,YAAY,OAAiC;CACrD,OAAO,OAAO,UAAU,YAAY,UAAU,KAAK,KAAK;AACzD;AAEA,SAAgB,sBAAsB,OAAiC;CACtE,OACC,OAAO,UAAU,YACjB,MAAM,SAAS,KACf,MAAM,KAAK,MAAM,SACjB,UAAU,OACV,UAAU,QACV,CAAC,UAAU,KAAK,KAAK;AAEvB;AAEA,SAAS,SAAS,QAAwC;CACzD,IAC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AAQ;GAAW,SAAS;EAAQ;EAEhG,IAAI;GACH,OAAO;IAAE,IAAI;IAAM,OAAO,MAAM,QAAQ,SAAS,IAAI;IAAG,WAAW,KAAK;GAAU;EACnF,QAAQ;GACP,OAAO;IAAE,IAAI;IAAO,QAAQ;IAAW,SAAS;GAAQ;EACzD;CACD;CAEA,IAAY,MAAsB;EACjC,OAAO,qCAAqC,mBAAmB,KAAK,KAAK,EAAE,EAAE,aAAa;CAC3F;CAEA,UAA0C;EACzC,OAAO;GAAE,eAAe,UAAU,KAAK;GAAe,QAAQ;EAAmB;CAClF;AACD"}
|
|
1
|
+
{"version":3,"file":"jiraIssueWrites.js","names":[],"sources":["../../../../../plus/integrations/src/providers/jiraIssueWrites.ts"],"sourcesContent":["import type { ProviderAuthenticationSession } from '../authentication/models.js';\nimport type { IssuesSelfManagedHostIntegrationId } from '../constants.js';\nimport type {\n\tIssueTrackerCreateOptions,\n\tIssueTrackerCreateOptionsResult,\n\tIssueTrackerDeleteOptions,\n\tIssueTrackerField,\n\tIssueTrackerIssueReceipt,\n\tIssueTrackerIssueWriteOptions,\n\tIssueTrackerIssueWriteOptionsResult,\n\tIssueTrackerStatus,\n\tIssueTrackerTransition,\n\tIssueTrackerWriteConnection,\n\tIssueTrackerWriteOptions,\n\tIssueTrackerWriteResult,\n\tIssueTrackerWriteTargetOptions,\n\tIssueTrackerWriteTargetResult,\n} from '../models/issueTrackerWrites.js';\nimport { baseUrlFromDomain, hostFromDomain, matchesInstallationOrigin } from '../utils/domain.utils.js';\nimport { toIssueWebUrl, toStatusCategory } from './jiraIssueByKey.js';\nimport { JiraIssueWriteError, toJiraIssueWriteFailure } from './jiraIssueWriteErrors.js';\nimport type { ProviderRequestFunction } from './models.js';\n\ntype Project = IssueTrackerIssueReceipt['project'];\ntype IssueType = IssueTrackerIssueReceipt['issueType'];\ntype JiraStatus = { id: string; name: string; statusCategory: { key: string } };\ntype JiraIssue = {\n\tid: string;\n\tkey: string;\n\tfields: { project: Project; issuetype: IssueType; summary: string; status: JiraStatus; subtasks?: unknown[] };\n};\ntype JiraField = Omit<IssueTrackerField, 'fieldId' | 'hasDefaultValue'> & {\n\tfieldId?: string;\n\tkey?: string;\n\thasDefaultValue?: boolean;\n};\ntype JiraTransition = Omit<IssueTrackerTransition, 'to' | 'fields' | 'isAvailable' | 'isConditional' | 'hasScreen'> & {\n\tto: JiraStatus;\n\tfields?: Record<string, JiraField>;\n\tisAvailable?: boolean;\n\tisConditional?: boolean;\n\thasScreen?: boolean;\n};\ntype JiraPage<T> = {\n\tstartAt?: number;\n\tstart?: number;\n\ttotal?: number;\n\tlast?: boolean;\n\tisLast?: boolean;\n\tfields?: JiraField[];\n\tresults?: JiraField[];\n\tissueTypes?: IssueType[];\n\tvalues?: T[];\n};\ntype JiraSite = { id: string; url: string; scopes: string[]; server?: boolean };\ntype JiraPermissions = Record<string, { havePermission?: boolean; key?: string }>;\n\nconst pageSize = 50;\nconst maxPages = 20;\nconst createPermission = 'CREATE_ISSUES';\nconst permissionKeys = { edit: 'EDIT_ISSUES', transition: 'TRANSITION_ISSUES', delete: 'DELETE_ISSUES' };\nconst reservedFields = new Set(['summary', 'description', 'project', 'issuetype']);\nconst numericId = /^\\d+$/;\n\nfunction isNumericId(value: unknown): value is string {\n\treturn typeof value === 'string' && numericId.test(value);\n}\n\nexport function isJiraWriteIdentifier(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === 'string' &&\n\t\tvalue.length > 0 &&\n\t\tvalue.trim() === value &&\n\t\tvalue !== '.' &&\n\t\tvalue !== '..' &&\n\t\t!/[\\\\/?#]/.test(value)\n\t);\n}\n\nfunction toStatus(status: JiraStatus): IssueTrackerStatus {\n\tif (\n\t\ttypeof status?.id !== 'string' ||\n\t\ttypeof status.name !== 'string' ||\n\t\ttypeof status.statusCategory?.key !== 'string'\n\t) {\n\t\tthrow new Error('Jira returned incomplete status metadata');\n\t}\n\n\treturn { id: status.id, name: status.name, category: toStatusCategory(status.statusCategory.key) };\n}\n\nfunction toField(fieldId: string, field: JiraField): IssueTrackerField {\n\treturn {\n\t\tfieldId: fieldId,\n\t\tname: field.name,\n\t\trequired: field.required,\n\t\tschema: structuredClone(field.schema),\n\t\tallowedValues: structuredClone(field.allowedValues),\n\t\thasDefaultValue: field.hasDefaultValue ?? false,\n\t\toperations: field.operations,\n\t};\n}\n\nfunction toFields(fields: Record<string, JiraField>): IssueTrackerField[] {\n\treturn Object.entries(fields).map(([id, field]) => toField(id, field));\n}\n\nfunction validateFields(\n\tfields: Readonly<Record<string, unknown>> | undefined,\n\ttopLevel: { summary?: string; description?: string },\n\tscreen: readonly IssueTrackerField[],\n): Record<string, unknown> {\n\tif (fields !== undefined && (fields == null || typeof fields !== 'object' || Array.isArray(fields))) {\n\t\tthrow new JiraIssueWriteError('invalid-input');\n\t}\n\n\tconst values = { ...fields, ...topLevel };\n\tconst settable = new Set(screen.filter(field => field.operations.includes('set')).map(field => field.fieldId));\n\tconst invalid = Object.keys(values).filter(\n\t\tkey => !settable.has(key) || (reservedFields.has(key) && Object.hasOwn(fields ?? {}, key)),\n\t);\n\tif (invalid.length !== 0) {\n\t\tthrow new JiraIssueWriteError(\n\t\t\t'invalid-input',\n\t\t\tObject.fromEntries(invalid.map(key => [key, 'field-not-settable'])),\n\t\t);\n\t}\n\n\treturn values;\n}\n\nexport class JiraIssueWriter {\n\tstatic async connect(\n\t\trequest: ProviderRequestFunction,\n\t\taccessToken: string,\n\t\toptions: IssueTrackerWriteConnection,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t): Promise<JiraIssueWriter> {\n\t\tconst { body: sites } = await request<Omit<JiraSite, 'server'>[]>({\n\t\t\turl: 'https://api.atlassian.com/oauth/token/accessible-resources',\n\t\t\tredirect: 'error',\n\t\t\theaders: { Authorization: `Bearer ${accessToken}`, Accept: 'application/json' },\n\t\t});\n\t\tconst site = sites.find(\n\t\t\tresource =>\n\t\t\t\tresource.id === options.resourceId && resource.scopes?.some(scope => /:jira(?:-|$)/.test(scope)),\n\t\t);\n\t\tif (site == null) throw new JiraIssueWriteError('not-found');\n\n\t\tconst resourceUrl = new URL(site.url);\n\t\tif (resourceUrl.protocol !== 'https:' || resourceUrl.username || resourceUrl.password) {\n\t\t\tthrow new JiraIssueWriteError('unknown');\n\t\t}\n\n\t\tconst { id, url, scopes } = site;\n\t\tconst writer = new JiraIssueWriter(\n\t\t\trequest,\n\t\t\taccessToken,\n\t\t\t{ id: id, url: url, scopes: scopes },\n\t\t\tisSessionCurrent,\n\t\t);\n\t\tconst { accountId } = await writer.read<{ accountId: string }>('/myself');\n\t\tif (typeof accountId !== 'string' || !accountId) throw new JiraIssueWriteError('unknown');\n\n\t\tif (options.expectedAccountId !== undefined && options.expectedAccountId !== accountId) {\n\t\t\tthrow new JiraIssueWriteError('forbidden');\n\t\t}\n\n\t\twriter.accountId = accountId;\n\t\treturn writer;\n\t}\n\n\tstatic async connectServer(\n\t\trequest: ProviderRequestFunction,\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions: Extract<IssueTrackerWriteConnection, { providerId: IssuesSelfManagedHostIntegrationId.JiraServer }>,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t): Promise<JiraIssueWriter> {\n\t\tconst siteUrl = normalizeJiraServerSiteUrl(session.baseUrl ?? session.domain, session.protocol);\n\t\tif (normalizeJiraServerSiteUrl(options.siteUrl) !== siteUrl || options.siteUrl !== siteUrl) {\n\t\t\tthrow new JiraIssueWriteError('conflict');\n\t\t}\n\t\tif (\n\t\t\thostFromDomain(session.domain) !== options.resourceId ||\n\t\t\t!matchesInstallationOrigin(session.domain, siteUrl)\n\t\t) {\n\t\t\tthrow new JiraIssueWriteError('conflict');\n\t\t}\n\n\t\tconst writer = new JiraIssueWriter(\n\t\t\trequest,\n\t\t\tsession.accessToken,\n\t\t\t{ id: options.resourceId, url: siteUrl, scopes: [], server: true },\n\t\t\tisSessionCurrent,\n\t\t);\n\t\tconst { key } = await writer.read<{ key: string }>('/myself');\n\t\tif (!isJiraWriteIdentifier(key)) throw new JiraIssueWriteError('unknown');\n\t\tif (options.expectedAccountId !== undefined && options.expectedAccountId !== key) {\n\t\t\tthrow new JiraIssueWriteError('forbidden');\n\t\t}\n\n\t\twriter.accountId = key;\n\t\treturn writer;\n\t}\n\n\tprivate accountId = '';\n\n\tprivate constructor(\n\t\tprivate readonly request: ProviderRequestFunction,\n\t\tprivate readonly accessToken: string,\n\t\tprivate readonly site: JiraSite,\n\t\tprivate readonly isSessionCurrent: () => Promise<boolean>,\n\t) {}\n\n\tasync getCreateOptions(options: IssueTrackerCreateOptions): Promise<IssueTrackerCreateOptionsResult> {\n\t\tconst project = await this.readCreateProject(options.project);\n\t\tconst result = {\n\t\t\tok: true as const,\n\t\t\tresourceId: this.site.id,\n\t\t\tsiteUrl: this.site.url,\n\t\t\taccountId: this.accountId,\n\t\t\tproject: project,\n\t\t};\n\t\tif (options.issueTypeId === undefined) {\n\t\t\tconst { values, truncated } = await this.readPages<IssueType>(this.createMetadataPath(project.id), page =>\n\t\t\t\tthis.site.server ? page.values : page.issueTypes,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\tissueTypes: values.map(({ id, name }) => ({ id: id, name: name })),\n\t\t\t\ttruncated: truncated,\n\t\t\t};\n\t\t}\n\n\t\tconst { values, truncated } = await this.readCreateFields(project.id, options.issueTypeId);\n\t\treturn { ...result, issueTypeId: options.issueTypeId, fields: values, truncated: truncated };\n\t}\n\n\tasync getIssueOptions(options: IssueTrackerIssueWriteOptions): Promise<IssueTrackerIssueWriteOptionsResult> {\n\t\tconst issue = await this.resolveIssue(options);\n\t\tconst permissions = await this.readPermissions(issue.id);\n\t\tconst [fields, transitions] = await Promise.all([\n\t\t\tpermissions.edit ? this.readEditFields(issue.id) : [],\n\t\t\tpermissions.transition ? this.readTransitions(issue.id) : [],\n\t\t]);\n\t\tconst reason = this.getDeleteRefusal(permissions.delete, issue);\n\t\treturn {\n\t\t\tok: true,\n\t\t\tissue: this.toReceipt(issue),\n\t\t\taccountId: this.accountId,\n\t\t\tfields: fields,\n\t\t\ttransitions: transitions,\n\t\t\tpermissions: permissions,\n\t\t\tdeleteCapability: reason === undefined ? { allowed: true } : { allowed: false, reason: reason },\n\t\t};\n\t}\n\n\tasync resolveTarget(options: IssueTrackerWriteTargetOptions): Promise<IssueTrackerWriteTargetResult> {\n\t\tif (options.intent !== undefined && options.intent !== 'delete') throw new JiraIssueWriteError('invalid-input');\n\n\t\tconst issue = await this.resolveIssue(options);\n\t\tif (options.intent === 'delete') {\n\t\t\tawait this.ensureDeletable(issue);\n\t\t}\n\n\t\treturn { ok: true, issue: this.toReceipt(issue), accountId: this.accountId };\n\t}\n\n\tasync write(options: IssueTrackerWriteOptions): Promise<IssueTrackerWriteResult> {\n\t\tswitch (options.action) {\n\t\t\tcase 'create':\n\t\t\t\treturn this.createIssue(options);\n\t\t\tcase 'edit':\n\t\t\tcase 'transition':\n\t\t\t\treturn this.updateIssue(options);\n\t\t\tdefault:\n\t\t\t\tthrow new JiraIssueWriteError('invalid-input');\n\t\t}\n\t}\n\n\tasync delete(options: IssueTrackerDeleteOptions): Promise<IssueTrackerWriteResult> {\n\t\tif (!isJiraWriteIdentifier(options.expectedAccountId) || !isNumericId(options.expectedIssueId)) {\n\t\t\tthrow new JiraIssueWriteError('invalid-input');\n\t\t}\n\n\t\tconst resolved = await this.resolveMutationIssue(options);\n\t\tawait this.ensureDeletable(resolved);\n\t\tconst issue = this.site.server ? await this.resolveMutationIssue(options) : resolved;\n\t\tconst reason = this.getDeleteRefusal(true, issue);\n\t\tif (reason !== undefined) throw new JiraIssueWriteError(reason);\n\n\t\tconst receipt = this.toReceipt(issue);\n\t\treturn this.dispatch('DELETE', `/issue/${issue.id}?deleteSubtasks=false`, 204, () => receipt);\n\t}\n\n\tprivate async createIssue(\n\t\toptions: Extract<IssueTrackerWriteOptions, { action: 'create' }>,\n\t): Promise<IssueTrackerWriteResult> {\n\t\tif (typeof options.summary !== 'string' || !options.summary.trim()) {\n\t\t\tthrow new JiraIssueWriteError('invalid-input');\n\t\t}\n\n\t\tconst topLevel = this.editableFields(options);\n\t\tconst project = await this.readCreateProject(options.project);\n\t\tconst screen = await this.readCreateFields(project.id, options.issueTypeId);\n\t\tconst fields = validateFields(options.fields, topLevel, screen.values);\n\t\treturn this.dispatch(\n\t\t\t'POST',\n\t\t\t'/issue',\n\t\t\t201,\n\t\t\tasync response => {\n\t\t\t\tconst created = response as { id: string };\n\t\t\t\tif (!isNumericId(created.id)) throw new Error('Jira returned no issue ID');\n\n\t\t\t\treturn this.toReceipt(await this.readIssue(created.id));\n\t\t\t},\n\t\t\t{ fields: { ...fields, project: { id: project.id }, issuetype: { id: options.issueTypeId } } },\n\t\t);\n\t}\n\n\tprivate async updateIssue(\n\t\toptions: Extract<IssueTrackerWriteOptions, { action: 'edit' | 'transition' }>,\n\t): Promise<IssueTrackerWriteResult> {\n\t\tif (!isNumericId(options.expectedIssueId)) throw new JiraIssueWriteError('invalid-input');\n\n\t\tconst issue = await this.resolveMutationIssue(options);\n\t\tconst path = `/issue/${issue.id}`;\n\t\tconst readReceipt = async () => this.toReceipt(await this.readIssue(issue.id));\n\t\tconst permissions = await this.readPermissions(issue.id);\n\t\tif (options.action === 'edit') {\n\t\t\tif (!permissions.edit) throw new JiraIssueWriteError('forbidden');\n\n\t\t\tconst fields = validateFields(\n\t\t\t\toptions.fields,\n\t\t\t\tthis.editableFields(options),\n\t\t\t\tawait this.readEditFields(issue.id),\n\t\t\t);\n\t\t\tif (Object.keys(fields).length === 0) throw new JiraIssueWriteError('invalid-input');\n\n\t\t\tif (this.site.server) {\n\t\t\t\tawait this.resolveMutationIssue(options);\n\t\t\t}\n\n\t\t\treturn this.dispatch('PUT', path, 204, readReceipt, { fields: fields });\n\t\t}\n\n\t\tif (!isNumericId(options.transitionId)) throw new JiraIssueWriteError('invalid-input');\n\t\tif (!permissions.transition) throw new JiraIssueWriteError('forbidden');\n\n\t\tconst transition = (await this.readTransitions(issue.id)).find(item => item.id === options.transitionId);\n\t\tif (transition?.isAvailable !== true) throw new JiraIssueWriteError('transition-unavailable');\n\n\t\tconst fields = validateFields(\n\t\t\toptions.fields,\n\t\t\tthis.editableFields(options),\n\t\t\ttransition.hasScreen ? transition.fields : [],\n\t\t);\n\t\tif (this.site.server) {\n\t\t\tawait this.resolveMutationIssue(options);\n\t\t}\n\n\t\treturn this.dispatch('POST', `${path}/transitions`, 204, readReceipt, {\n\t\t\ttransition: { id: transition.id },\n\t\t\tfields: fields,\n\t\t});\n\t}\n\n\tprivate editableFields(options: { summary?: string; description?: string }): {\n\t\tsummary?: string;\n\t\tdescription?: string;\n\t} {\n\t\tconst { summary, description } = options;\n\t\tif (\n\t\t\t(summary !== undefined && (typeof summary !== 'string' || !summary.trim())) ||\n\t\t\t(description !== undefined && typeof description !== 'string')\n\t\t) {\n\t\t\tthrow new JiraIssueWriteError('invalid-input');\n\t\t}\n\n\t\treturn {\n\t\t\t...(summary !== undefined && { summary: summary }),\n\t\t\t...(description !== undefined && { description: description }),\n\t\t};\n\t}\n\n\tprivate async resolveMutationIssue(\n\t\toptions: Exclude<IssueTrackerWriteOptions, { action: 'create' }> | IssueTrackerDeleteOptions,\n\t): Promise<JiraIssue> {\n\t\tconst expectedProjectId = 'expectedProjectId' in options ? options.expectedProjectId : undefined;\n\t\tif (this.site.server && !isNumericId(expectedProjectId)) {\n\t\t\tthrow new JiraIssueWriteError('invalid-input');\n\t\t}\n\n\t\tconst issue = await this.resolveIssue(options);\n\t\tif (this.site.server && expectedProjectId !== issue.fields.project.id) {\n\t\t\tthrow new JiraIssueWriteError('conflict');\n\t\t}\n\n\t\treturn issue;\n\t}\n\n\tprivate async resolveIssue(options: IssueTrackerIssueWriteOptions): Promise<JiraIssue> {\n\t\tif (\n\t\t\t!isJiraWriteIdentifier(options.issue) ||\n\t\t\t(options.expectedIssueId !== undefined && !isNumericId(options.expectedIssueId))\n\t\t) {\n\t\t\tthrow new JiraIssueWriteError('invalid-input');\n\t\t}\n\n\t\tconst issue = await this.readIssue(options.issue);\n\t\tif (\n\t\t\t(options.expectedIssueId !== undefined && options.expectedIssueId !== issue.id) ||\n\t\t\t(!numericId.test(options.issue) && options.issue.toUpperCase() !== issue.key.toUpperCase())\n\t\t) {\n\t\t\tthrow new JiraIssueWriteError('conflict');\n\t\t}\n\n\t\treturn issue;\n\t}\n\n\tprivate async readIssue(idOrKey: string): Promise<JiraIssue> {\n\t\tconst issue = await this.read<JiraIssue>(\n\t\t\t`/issue/${encodeURIComponent(idOrKey)}?fields=project,issuetype,summary,status,subtasks`,\n\t\t);\n\t\tif (\n\t\t\t!isNumericId(issue.id) ||\n\t\t\t(numericId.test(idOrKey) && issue.id !== idOrKey) ||\n\t\t\t!isJiraWriteIdentifier(issue.key) ||\n\t\t\t!isJiraWriteIdentifier(issue.fields?.project?.key) ||\n\t\t\t!issue.key.startsWith(`${issue.fields.project.key}-`) ||\n\t\t\t!isNumericId(issue.fields.project.id)\n\t\t) {\n\t\t\tthrow new Error('Jira returned inconsistent issue identity');\n\t\t}\n\n\t\treturn issue;\n\t}\n\n\tprivate async readCreateProject(idOrKey: string): Promise<Project> {\n\t\tif (!isJiraWriteIdentifier(idOrKey)) throw new JiraIssueWriteError('invalid-input');\n\n\t\tconst { id, key } = await this.read<Project>(`/project/${encodeURIComponent(idOrKey)}`);\n\t\tif (\n\t\t\t!isNumericId(id) ||\n\t\t\t!isJiraWriteIdentifier(key) ||\n\t\t\t(numericId.test(idOrKey) ? id !== idOrKey : key.toUpperCase() !== idOrKey.toUpperCase())\n\t\t) {\n\t\t\tthrow new JiraIssueWriteError('conflict');\n\t\t}\n\n\t\tconst permissions = await this.readPermissionsFor({ projectId: id, permissions: createPermission });\n\t\tif (permissions[createPermission]?.havePermission !== true) throw new JiraIssueWriteError('forbidden');\n\n\t\treturn { id: id, key: key };\n\t}\n\n\tprivate async readPermissions(issueId: string): Promise<IssueTrackerIssueWriteOptionsSuccess['permissions']> {\n\t\tconst permissions = await this.readPermissionsFor({\n\t\t\tissueId: issueId,\n\t\t\tpermissions: Object.values(permissionKeys).join(','),\n\t\t});\n\t\treturn {\n\t\t\tedit: permissions[permissionKeys.edit]?.havePermission === true,\n\t\t\ttransition: permissions[permissionKeys.transition]?.havePermission === true,\n\t\t\tdelete: permissions[permissionKeys.delete]?.havePermission === true,\n\t\t};\n\t}\n\n\tprivate async readPermissionsFor(params: Record<string, string>): Promise<JiraPermissions> {\n\t\tconst query = new URLSearchParams(params);\n\t\tif (this.site.server) {\n\t\t\tquery.delete('permissions');\n\t\t}\n\t\tconst { permissions } = await this.read<{ permissions: JiraPermissions }>(`/mypermissions?${query.toString()}`);\n\t\treturn this.site.server\n\t\t\t? Object.fromEntries(\n\t\t\t\t\tObject.entries(permissions).map(([key, permission]) => [permission.key ?? key, permission]),\n\t\t\t\t)\n\t\t\t: permissions;\n\t}\n\n\tprivate async readTransitions(issueId: string): Promise<IssueTrackerTransition[]> {\n\t\tconst { transitions } = await this.read<{ transitions: JiraTransition[] }>(\n\t\t\t`/issue/${issueId}/transitions?expand=transitions.fields`,\n\t\t);\n\t\treturn transitions.map(transition => ({\n\t\t\tid: transition.id,\n\t\t\tname: transition.name,\n\t\t\tto: toStatus(transition.to),\n\t\t\thasScreen:\n\t\t\t\ttransition.hasScreen === true ||\n\t\t\t\t(this.site.server === true && Object.keys(transition.fields ?? {}).length > 0),\n\t\t\tisAvailable: transition.isAvailable !== false,\n\t\t\tisConditional: transition.isConditional === true,\n\t\t\tfields: toFields(transition.fields ?? {}),\n\t\t}));\n\t}\n\n\tprivate async readEditFields(issueId: string): Promise<IssueTrackerField[]> {\n\t\tconst { fields } = await this.read<{ fields: Record<string, JiraField> }>(`/issue/${issueId}/editmeta`);\n\t\treturn toFields(fields);\n\t}\n\n\tprivate async readCreateFields(\n\t\tprojectId: string,\n\t\tissueTypeId: string,\n\t): Promise<{ values: IssueTrackerField[]; truncated: boolean }> {\n\t\tif (!isNumericId(issueTypeId)) throw new JiraIssueWriteError('invalid-input');\n\n\t\tconst { values, truncated } = await this.readPages<JiraField>(\n\t\t\t`${this.createMetadataPath(projectId)}/${issueTypeId}`,\n\t\t\tpage => (this.site.server ? page.values : (page.fields ?? page.results)),\n\t\t);\n\t\treturn {\n\t\t\tvalues: values.map(field => {\n\t\t\t\tconst id = field.fieldId ?? field.key;\n\t\t\t\tif (!id) throw new Error('Jira returned metadata with no field ID');\n\n\t\t\t\treturn toField(id, field);\n\t\t\t}),\n\t\t\ttruncated: truncated,\n\t\t};\n\t}\n\n\tprivate createMetadataPath(projectId: string): string {\n\t\treturn `/issue/createmeta/${projectId}/issuetypes`;\n\t}\n\n\tprivate async readPages<T>(\n\t\tpath: string,\n\t\titems: (page: JiraPage<T>) => T[] | undefined,\n\t): Promise<{ values: T[]; truncated: boolean }> {\n\t\tconst values: T[] = [];\n\t\tfor (let index = 0; index < maxPages; index++) {\n\t\t\tconst startAt = values.length;\n\t\t\tconst page = await this.read<JiraPage<T>>(`${path}?startAt=${startAt}&maxResults=${pageSize}`);\n\t\t\tconst rows = items(page);\n\t\t\tif (\n\t\t\t\t!Array.isArray(rows) ||\n\t\t\t\t(this.site.server\n\t\t\t\t\t? typeof (page.last ?? page.isLast) !== 'boolean'\n\t\t\t\t\t: !Number.isSafeInteger(page.total) || (page.total ?? -1) < 0) ||\n\t\t\t\t(this.site.server ? (page.start ?? page.startAt) : page.startAt) !== startAt\n\t\t\t) {\n\t\t\t\tthrow new Error('Jira returned invalid create metadata pagination');\n\t\t\t}\n\n\t\t\tvalues.push(...rows);\n\t\t\tif (this.site.server ? (page.last ?? page.isLast) : values.length >= page.total!) {\n\t\t\t\treturn { values: values, truncated: false };\n\t\t\t}\n\n\t\t\tif (rows.length === 0) break;\n\t\t}\n\n\t\treturn { values: values, truncated: true };\n\t}\n\n\tprivate getDeleteRefusal(\n\t\tallowed: boolean,\n\t\tissue: JiraIssue,\n\t): 'forbidden' | 'insufficient-scope' | 'invalid-input' | undefined {\n\t\tif (!allowed) return 'forbidden';\n\t\tif (\n\t\t\t!this.site.server &&\n\t\t\t!this.site.scopes?.some(scope => scope === 'delete:issue:jira' || scope === 'write:jira-work')\n\t\t) {\n\t\t\treturn 'insufficient-scope';\n\t\t}\n\t\tif (!Array.isArray(issue.fields.subtasks) || issue.fields.subtasks.length !== 0) return 'invalid-input';\n\n\t\treturn undefined;\n\t}\n\n\tprivate async ensureDeletable(issue: JiraIssue): Promise<void> {\n\t\tconst reason = this.getDeleteRefusal((await this.readPermissions(issue.id)).delete, issue);\n\t\tif (reason !== undefined) throw new JiraIssueWriteError(reason);\n\t}\n\n\tprivate toReceipt(issue: JiraIssue): IssueTrackerIssueReceipt {\n\t\tconst { project, issuetype, summary, status } = issue.fields;\n\t\tif (!isNumericId(issuetype?.id) || typeof issuetype.name !== 'string' || typeof summary !== 'string') {\n\t\t\tthrow new Error('Jira returned incomplete issue metadata');\n\t\t}\n\n\t\treturn {\n\t\t\tresourceId: this.site.id,\n\t\t\tsiteUrl: this.site.url,\n\t\t\tid: issue.id,\n\t\t\tkey: issue.key,\n\t\t\turl: toIssueWebUrl(this.site.url, issue.key),\n\t\t\tproject: { id: project.id, key: project.key },\n\t\t\tissueType: { id: issuetype.id, name: issuetype.name },\n\t\t\tsummary: summary,\n\t\t\tstatus: toStatus(status),\n\t\t};\n\t}\n\n\tprivate async read<T>(path: string): Promise<T> {\n\t\treturn (await this.request<T>({ url: this.url(path), headers: this.headers(), redirect: 'error' })).body;\n\t}\n\n\tprivate async dispatch(\n\t\tmethod: 'POST' | 'PUT' | 'DELETE',\n\t\tpath: string,\n\t\texpectedStatus: number,\n\t\treceipt: (response: unknown) => IssueTrackerIssueReceipt | Promise<IssueTrackerIssueReceipt>,\n\t\tpayload?: object,\n\t): Promise<IssueTrackerWriteResult> {\n\t\tlet body: string | undefined;\n\t\ttry {\n\t\t\tbody = payload === undefined ? undefined : JSON.stringify(payload);\n\t\t} catch {\n\t\t\treturn { ok: false, reason: 'invalid-input', mutationDispatched: false };\n\t\t}\n\n\t\tif (!(await this.isSessionCurrent())) return { ok: false, reason: 'no-connection', mutationDispatched: false };\n\n\t\tlet response;\n\t\ttry {\n\t\t\tresponse = await this.request<unknown>({\n\t\t\t\turl: this.url(path),\n\t\t\t\tmethod: method,\n\t\t\t\theaders: { ...this.headers(), ...(body !== undefined && { 'Content-Type': 'application/json' }) },\n\t\t\t\tbody: body,\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t} catch (ex) {\n\t\t\treturn toJiraIssueWriteFailure(ex, true);\n\t\t}\n\n\t\tif (response.status !== expectedStatus) return { ok: false, reason: 'unknown', applied: 'maybe' };\n\n\t\ttry {\n\t\t\treturn { ok: true, issue: await receipt(response.body), accountId: this.accountId };\n\t\t} catch {\n\t\t\treturn { ok: false, reason: 'unknown', applied: 'maybe' };\n\t\t}\n\t}\n\n\tprivate url(path: string): string {\n\t\tif (this.site.server) return `${this.site.url}/rest/api/2${path}`;\n\n\t\treturn `https://api.atlassian.com/ex/jira/${encodeURIComponent(this.site.id)}/rest/api/2${path}`;\n\t}\n\n\tprivate headers(): Record<string, string> {\n\t\treturn { Authorization: `Bearer ${this.accessToken}`, Accept: 'application/json' };\n\t}\n}\n\ntype IssueTrackerIssueWriteOptionsSuccess = Extract<IssueTrackerIssueWriteOptionsResult, { ok: true }>;\n\nfunction normalizeJiraServerSiteUrl(value: string, protocol = 'https:'): string {\n\tif (typeof value !== 'string' || value.trim() !== value || /[\\\\?#]/.test(value)) {\n\t\tthrow new JiraIssueWriteError('invalid-input');\n\t}\n\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(/^[a-z][a-z\\d+.-]*:\\/\\//i.test(value) ? value : `${protocol}//${value}`);\n\t} catch {\n\t\tthrow new JiraIssueWriteError('invalid-input');\n\t}\n\tif (\n\t\t!['https:', 'http:'].includes(url.protocol) ||\n\t\turl.username ||\n\t\turl.password ||\n\t\t/%|(?:^|\\/)\\.\\.?(?:\\/|$)/.test(value.replace(/^[a-z]+:\\/\\/[^/]+/i, ''))\n\t) {\n\t\tthrow new JiraIssueWriteError('invalid-input');\n\t}\n\n\tconst normalized = baseUrlFromDomain(value, protocol);\n\tif (normalized == null) throw new JiraIssueWriteError('invalid-input');\n\n\treturn normalized;\n}\n"],"mappings":";;;;AAyDA,MAAM,WAAW;AACjB,MAAM,WAAW;AACjB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;CAAE,MAAM;CAAe,YAAY;CAAqB,QAAQ;AAAgB;AACvG,MAAM,iCAAiB,IAAI,IAAI;CAAC;CAAW;CAAe;CAAW;AAAW,CAAC;AACjF,MAAM,YAAY;AAElB,SAAS,YAAY,OAAiC;CACrD,OAAO,OAAO,UAAU,YAAY,UAAU,KAAK,KAAK;AACzD;AAEA,SAAgB,sBAAsB,OAAiC;CACtE,OACC,OAAO,UAAU,YACjB,MAAM,SAAS,KACf,MAAM,KAAK,MAAM,SACjB,UAAU,OACV,UAAU,QACV,CAAC,UAAU,KAAK,KAAK;AAEvB;AAEA,SAAS,SAAS,QAAwC;CACzD,IACC,OAAO,QAAQ,OAAO,YACtB,OAAO,OAAO,SAAS,YACvB,OAAO,OAAO,gBAAgB,QAAQ,UAEtC,MAAM,IAAI,MAAM,0CAA0C;CAG3D,OAAO;EAAE,IAAI,OAAO;EAAI,MAAM,OAAO;EAAM,UAAU,iBAAiB,OAAO,eAAe,GAAG;CAAE;AAClG;AAEA,SAAS,QAAQ,SAAiB,OAAqC;CACtE,OAAO;EACG;EACT,MAAM,MAAM;EACZ,UAAU,MAAM;EAChB,QAAQ,gBAAgB,MAAM,MAAM;EACpC,eAAe,gBAAgB,MAAM,aAAa;EAClD,iBAAiB,MAAM,mBAAmB;EAC1C,YAAY,MAAM;CACnB;AACD;AAEA,SAAS,SAAS,QAAwD;CACzE,OAAO,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,WAAW,QAAQ,IAAI,KAAK,CAAC;AACtE;AAEA,SAAS,eACR,QACA,UACA,QAC0B;CAC1B,IAAI,WAAW,KAAA,MAAc,UAAU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O,QAAQ;GAAW,SAAS;EAAQ;EAEhG,IAAI;GACH,OAAO;IAAE,IAAI;IAAM,OAAO,MAAM,QAAQ,SAAS,IAAI;IAAG,WAAW,KAAK;GAAU;EACnF,QAAQ;GACP,OAAO;IAAE,IAAI;IAAO,QAAQ;IAAW,SAAS;GAAQ;EACzD;CACD;CAEA,IAAY,MAAsB;EACjC,IAAI,KAAK,KAAK,QAAQ,OAAO,GAAG,KAAK,KAAK,IAAI,aAAa;EAE3D,OAAO,qCAAqC,mBAAmB,KAAK,KAAK,EAAE,EAAE,aAAa;CAC3F;CAEA,UAA0C;EACzC,OAAO;GAAE,eAAe,UAAU,KAAK;GAAe,QAAQ;EAAmB;CAClF;AACD;AAIA,SAAS,2BAA2B,OAAe,WAAW,UAAkB;CAC/E,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,SAAS,SAAS,KAAK,KAAK,GAC7E,MAAM,IAAI,oBAAoB,eAAe;CAG9C,IAAI;CACJ,IAAI;EACH,MAAM,IAAI,IAAI,0BAA0B,KAAK,KAAK,IAAI,QAAQ,GAAG,SAAS,IAAI,OAAO;CACtF,QAAQ;EACP,MAAM,IAAI,oBAAoB,eAAe;CAC9C;CACA,IACC,CAAC,CAAC,UAAU,OAAO,CAAC,CAAC,SAAS,IAAI,QAAQ,KAC1C,IAAI,YACJ,IAAI,YACJ,0BAA0B,KAAK,MAAM,QAAQ,sBAAsB,EAAE,CAAC,GAEtE,MAAM,IAAI,oBAAoB,eAAe;CAG9C,MAAM,aAAa,kBAAkB,OAAO,QAAQ;CACpD,IAAI,cAAc,MAAM,MAAM,IAAI,oBAAoB,eAAe;CAErE,OAAO;AACR"}
|
|
@@ -56,11 +56,15 @@ async function parseFetchResponseForApi(response, sentCredential, requestUrl = r
|
|
|
56
56
|
if (response.ok) throw ex;
|
|
57
57
|
const header = response.status === 401 ? "x-ausername" : "retry-after";
|
|
58
58
|
const value = response.status === 401 || response.status === 403 ? response.headers.get(header) : null;
|
|
59
|
+
const insufficientScope = (response.status === 401 || response.status === 403) && /\binsufficient[_ -]scope\b|scope does not match|does not have (?:the )?required scope/i.test(response.headers.get("www-authenticate") ?? "");
|
|
59
60
|
throw Object.assign(/* @__PURE__ */ new Error(`(${response.status}) Unable to decode the provider response.`), {
|
|
60
61
|
statusCode: response.status,
|
|
61
|
-
...value != null && { response: {
|
|
62
|
+
...(value != null || insufficientScope) && { response: {
|
|
62
63
|
status: response.status,
|
|
63
|
-
headers: {
|
|
64
|
+
headers: {
|
|
65
|
+
...value != null && { [header]: value },
|
|
66
|
+
...insufficientScope && { "www-authenticate": "Bearer error=\"insufficient_scope\"" }
|
|
67
|
+
}
|
|
64
68
|
} }
|
|
65
69
|
});
|
|
66
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providerApiClient.js","names":[],"sources":["../../../../../plus/integrations/src/providers/providerApiClient.ts"],"sourcesContent":["import { captureProviderRead } from '@gitkraken/provider-apis/read-provenance';\nimport { getAuthenticatedUser } from '../errors.js';\nimport type { ProviderRequestFunction, ProviderRequestOptions, ProviderRequestResponse } from './models.js';\nimport {\n\tAnonymousResponseError,\n\tgetProviderResponseBodyMessage,\n\tmarkRequestError,\n\tUnexpectedHtmlResponseError,\n} from './providerErrors.js';\n\nexport function createProviderApiRequest(\n\tfetch: (input: string | URL, init?: RequestInit) => Promise<Response>,\n\tuserAgent?: string,\n): ProviderRequestFunction {\n\treturn async <T>({ url, ...options }: ProviderRequestOptions): Promise<ProviderRequestResponse<T>> => {\n\t\ttry {\n\t\t\treturn await captureProviderRead(async () => {\n\t\t\t\tconst response = await fetch(url, {\n\t\t\t\t\t...options,\n\t\t\t\t\theaders: { ...(userAgent != null ? { 'User-Agent': userAgent } : {}), ...options.headers },\n\t\t\t\t});\n\t\t\t\treturn parseFetchResponseForApi<T>(response, () => hasAuthorization(options.headers), url);\n\t\t\t});\n\t\t} catch (ex) {\n\t\t\tthrow markRequestError(ex, { url: url, method: options.method });\n\t\t}\n\t};\n}\n\nexport async function parseFetchResponseForApi<T>(\n\tresponse: Response,\n\tsentCredential?: () => boolean,\n\trequestUrl = response.url,\n): Promise<ProviderRequestResponse<T>> {\n\tconst contentType = (response.headers.get('content-type') || '').toLowerCase();\n\n\tif (\n\t\tresponse.status !== 401 &&\n\t\tresponse.status !== 429 &&\n\t\tresponse.status < 500 &&\n\t\tgetAuthenticatedUser(response.headers) === 'anonymous' &&\n\t\tsentCredential?.() === true\n\t) {\n\t\tvoid response.body?.cancel().catch(() => undefined);\n\t\tthrow new AnonymousResponseError(response.status, {\n\t\t\theaders: Object.fromEntries(response.headers.entries()),\n\t\t\tstatus: response.status,\n\t\t});\n\t}\n\n\tlet body;\n\tlet servedHtml = false;\n\n\tconst headers = Object.fromEntries(response.headers.entries());\n\ttry {\n\t\tif (!response.ok && requestUrl === 'https://api.github.com/graphql') {\n\t\t\t// KEEP: GraphQL execution evidence can arrive with a missing or incorrect media type.\n\t\t\tbody = await response.json();\n\t\t\tif (body == null || typeof body !== 'object' || Array.isArray(body)) {\n\t\t\t\tthrow new Error('Expected a GitHub GraphQL response object.');\n\t\t\t}\n\t\t} else if (contentType.startsWith('application/json')) {\n\t\t\tconst text = await response.text();\n\t\t\tif (text.trimStart().startsWith('<')) {\n\t\t\t\tservedHtml = true;\n\t\t\t\tbody = text;\n\t\t\t} else {\n\t\t\t\tbody = text.trim().length > 0 ? JSON.parse(text) : null;\n\t\t\t}\n\t\t} else if (contentType.startsWith('text/') || contentType === '') {\n\t\t\tbody = await response.text();\n\t\t\tservedHtml = contentType.startsWith('text/html') && body.trim().length > 0;\n\t\t} else if (contentType.startsWith('application/vnd.github.raw+json')) {\n\t\t\tbody = await response.arrayBuffer();\n\t\t} else {\n\t\t\tvoid response.body?.cancel().catch(() => undefined);\n\t\t\tthrow new Error(`Unsupported content-type: ${contentType}`);\n\t\t}\n\t} catch (ex) {\n\t\tif (response.ok) throw ex;\n\n\t\tconst header = response.status === 401 ? 'x-ausername' : 'retry-after';\n\t\tconst value = response.status === 401 || response.status === 403 ? response.headers.get(header) : null;\n\t\tthrow Object.assign(new Error(`(${response.status}) Unable to decode the provider response.`), {\n\t\t\tstatusCode: response.status,\n\t\t\t...(value != null && {
|
|
1
|
+
{"version":3,"file":"providerApiClient.js","names":[],"sources":["../../../../../plus/integrations/src/providers/providerApiClient.ts"],"sourcesContent":["import { captureProviderRead } from '@gitkraken/provider-apis/read-provenance';\nimport { getAuthenticatedUser } from '../errors.js';\nimport type { ProviderRequestFunction, ProviderRequestOptions, ProviderRequestResponse } from './models.js';\nimport {\n\tAnonymousResponseError,\n\tgetProviderResponseBodyMessage,\n\tmarkRequestError,\n\tUnexpectedHtmlResponseError,\n} from './providerErrors.js';\n\nexport function createProviderApiRequest(\n\tfetch: (input: string | URL, init?: RequestInit) => Promise<Response>,\n\tuserAgent?: string,\n): ProviderRequestFunction {\n\treturn async <T>({ url, ...options }: ProviderRequestOptions): Promise<ProviderRequestResponse<T>> => {\n\t\ttry {\n\t\t\treturn await captureProviderRead(async () => {\n\t\t\t\tconst response = await fetch(url, {\n\t\t\t\t\t...options,\n\t\t\t\t\theaders: { ...(userAgent != null ? { 'User-Agent': userAgent } : {}), ...options.headers },\n\t\t\t\t});\n\t\t\t\treturn parseFetchResponseForApi<T>(response, () => hasAuthorization(options.headers), url);\n\t\t\t});\n\t\t} catch (ex) {\n\t\t\tthrow markRequestError(ex, { url: url, method: options.method });\n\t\t}\n\t};\n}\n\nexport async function parseFetchResponseForApi<T>(\n\tresponse: Response,\n\tsentCredential?: () => boolean,\n\trequestUrl = response.url,\n): Promise<ProviderRequestResponse<T>> {\n\tconst contentType = (response.headers.get('content-type') || '').toLowerCase();\n\n\tif (\n\t\tresponse.status !== 401 &&\n\t\tresponse.status !== 429 &&\n\t\tresponse.status < 500 &&\n\t\tgetAuthenticatedUser(response.headers) === 'anonymous' &&\n\t\tsentCredential?.() === true\n\t) {\n\t\tvoid response.body?.cancel().catch(() => undefined);\n\t\tthrow new AnonymousResponseError(response.status, {\n\t\t\theaders: Object.fromEntries(response.headers.entries()),\n\t\t\tstatus: response.status,\n\t\t});\n\t}\n\n\tlet body;\n\tlet servedHtml = false;\n\n\tconst headers = Object.fromEntries(response.headers.entries());\n\ttry {\n\t\tif (!response.ok && requestUrl === 'https://api.github.com/graphql') {\n\t\t\t// KEEP: GraphQL execution evidence can arrive with a missing or incorrect media type.\n\t\t\tbody = await response.json();\n\t\t\tif (body == null || typeof body !== 'object' || Array.isArray(body)) {\n\t\t\t\tthrow new Error('Expected a GitHub GraphQL response object.');\n\t\t\t}\n\t\t} else if (contentType.startsWith('application/json')) {\n\t\t\tconst text = await response.text();\n\t\t\tif (text.trimStart().startsWith('<')) {\n\t\t\t\tservedHtml = true;\n\t\t\t\tbody = text;\n\t\t\t} else {\n\t\t\t\tbody = text.trim().length > 0 ? JSON.parse(text) : null;\n\t\t\t}\n\t\t} else if (contentType.startsWith('text/') || contentType === '') {\n\t\t\tbody = await response.text();\n\t\t\tservedHtml = contentType.startsWith('text/html') && body.trim().length > 0;\n\t\t} else if (contentType.startsWith('application/vnd.github.raw+json')) {\n\t\t\tbody = await response.arrayBuffer();\n\t\t} else {\n\t\t\tvoid response.body?.cancel().catch(() => undefined);\n\t\t\tthrow new Error(`Unsupported content-type: ${contentType}`);\n\t\t}\n\t} catch (ex) {\n\t\tif (response.ok) throw ex;\n\n\t\tconst header = response.status === 401 ? 'x-ausername' : 'retry-after';\n\t\tconst value = response.status === 401 || response.status === 403 ? response.headers.get(header) : null;\n\t\tconst insufficientScope =\n\t\t\t(response.status === 401 || response.status === 403) &&\n\t\t\t/\\binsufficient[_ -]scope\\b|scope does not match|does not have (?:the )?required scope/i.test(\n\t\t\t\tresponse.headers.get('www-authenticate') ?? '',\n\t\t\t);\n\t\tthrow Object.assign(new Error(`(${response.status}) Unable to decode the provider response.`), {\n\t\t\tstatusCode: response.status,\n\t\t\t...((value != null || insufficientScope) && {\n\t\t\t\tresponse: {\n\t\t\t\t\tstatus: response.status,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t...(value != null && { [header]: value }),\n\t\t\t\t\t\t...(insufficientScope && { 'www-authenticate': 'Bearer error=\"insufficient_scope\"' }),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t});\n\t}\n\n\tconst result = {\n\t\tbody: body,\n\t\theaders: headers,\n\t\tstatus: response.status,\n\t\tstatusText: response.statusText,\n\t};\n\n\tif (response.ok && servedHtml) {\n\t\tthrow new UnexpectedHtmlResponseError(response.status, contentType, result);\n\t}\n\n\tif (!response.ok) {\n\t\tconst status = `(${response.status})${response.statusText ? ` ${response.statusText}` : ''}.`;\n\t\tconst detail = getProviderResponseBodyMessage(body);\n\t\tconst error = new Error(detail != null ? `${status} ${detail}` : status);\n\t\tObject.assign(error, { response: result });\n\t\tthrow error;\n\t}\n\n\treturn result;\n}\n\nfunction hasAuthorization(headers: ProviderRequestOptions['headers']): boolean {\n\tif (headers == null) return false;\n\n\treturn Object.entries(headers).some(([name, value]) => name.toLowerCase() === 'authorization' && Boolean(value));\n}\n"],"mappings":";;;;AAUA,SAAgB,yBACf,OACA,WAC0B;CAC1B,OAAO,OAAU,EAAE,KAAK,GAAG,cAA2E;EACrG,IAAI;GACH,OAAO,MAAM,oBAAoB,YAAY;IAK5C,OAAO,yBAA4B,MAJZ,MAAM,KAAK;KACjC,GAAG;KACH,SAAS;MAAE,GAAI,aAAa,OAAO,EAAE,cAAc,UAAU,IAAI,CAAC;MAAI,GAAG,QAAQ;KAAQ;IAC1F,CAAC,SACkD,iBAAiB,QAAQ,OAAO,GAAG,GAAG;GAC1F,CAAC;EACF,SAAS,IAAI;GACZ,MAAM,iBAAiB,IAAI;IAAO;IAAK,QAAQ,QAAQ;GAAO,CAAC;EAChE;CACD;AACD;AAEA,eAAsB,yBACrB,UACA,gBACA,aAAa,SAAS,KACgB;CACtC,MAAM,eAAe,SAAS,QAAQ,IAAI,cAAc,KAAK,GAAA,CAAI,YAAY;CAE7E,IACC,SAAS,WAA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,WAAW,OAAO,SAAS,WAAW,MAAM,SAAS,QAAQ,IAAI,MAAM,IAAI;EAClG,MAAM,qBACJ,SAAS,WAAW,OAAO,SAAS,WAAW,QAChD,yFAAyF,KACxF,SAAS,QAAQ,IAAI,kBAAkB,KAAK,EAC7C;EACD,MAAM,OAAO,uBAAO,IAAI,MAAM,IAAI,SAAS,OAAO,0CAA0C,GAAG;GAC9F,YAAY,SAAS;GACrB,IAAK,SAAS,QAAQ,sBAAsB,EAC3C,UAAU;IACT,QAAQ,SAAS;IACjB,SAAS;KACR,GAAI,SAAS,QAAQ,GAAG,SAAS,MAAM;KACvC,GAAI,qBAAqB,EAAE,oBAAoB,sCAAoC;IACpF;GACD,EACD;EACD,CAAC;CACF;CAEA,MAAM,SAAS;EACR;EACG;EACT,QAAQ,SAAS;EACjB,YAAY,SAAS;CACtB;CAEA,IAAI,SAAS,MAAM,YAClB,MAAM,IAAI,4BAA4B,SAAS,QAAQ,aAAa,MAAM;CAG3E,IAAI,CAAC,SAAS,IAAI;EACjB,MAAM,SAAS,IAAI,SAAS,OAAO,GAAG,SAAS,aAAa,IAAI,SAAS,eAAe,GAAG;EAC3F,MAAM,SAAS,+BAA+B,IAAI;EAClD,MAAM,QAAQ,IAAI,MAAM,UAAU,OAAO,GAAG,OAAO,GAAG,WAAW,MAAM;EACvE,OAAO,OAAO,OAAO,EAAE,UAAU,OAAO,CAAC;EACzC,MAAM;CACP;CAEA,OAAO;AACR;AAEA,SAAS,iBAAiB,SAAqD;CAC9E,IAAI,WAAW,MAAM,OAAO;CAE5B,OAAO,OAAO,QAAQ,OAAO,CAAC,CAAC,MAAM,CAAC,MAAM,WAAW,KAAK,YAAY,MAAM,mBAAmB,QAAQ,KAAK,CAAC;AAChH"}
|
|
@@ -204,6 +204,9 @@ export declare class ProvidersApi implements Disposable {
|
|
|
204
204
|
getAzureServerWorkItemWriter(options: AzureServerWorkItemWriteScope, connection: AzureServerWriteConnection): Promise<AzureWorkItemWriter>;
|
|
205
205
|
private createAzureServerDiscoveryApi;
|
|
206
206
|
private getAzureServerWriteTransport;
|
|
207
|
+
getJiraServerIssueWriter(options: Extract<IssueTrackerWriteConnection, {
|
|
208
|
+
providerId: IssuesSelfManagedHostIntegrationId.JiraServer;
|
|
209
|
+
}>, session: ProviderAuthenticationSession, isCurrent: () => boolean, isSessionCurrent: () => Promise<boolean>, getIgnoreSSLErrors: () => boolean | 'force'): Promise<JiraIssueWriter>;
|
|
207
210
|
getJiraIssueWriter(options: IssueTrackerWriteConnection): Promise<JiraIssueWriter | undefined>;
|
|
208
211
|
getJiraResourcesForCurrentUser(tokenOptInfo: TokenWithInfo<IssuesCloudHostIntegrationId.Jira>): Promise<ProviderJiraResource[] | undefined>;
|
|
209
212
|
getLinearOrganization(tokenOptInfo: TokenWithInfo<IssuesCloudHostIntegrationId.Linear>): Promise<ProviderLinearOrganization | undefined>;
|
|
@@ -21,6 +21,7 @@ import { BitbucketPullRequestWriteError } from "./bitbucketPullRequestWriteError
|
|
|
21
21
|
import { BitbucketPullRequestWriter } from "./bitbucketPullRequestWrites.js";
|
|
22
22
|
import { BitbucketServerPullRequestWriteError } from "./bitbucketServerPullRequestWriteErrors.js";
|
|
23
23
|
import { BitbucketServerPullRequestWriter } from "./bitbucketServerPullRequestWrites.js";
|
|
24
|
+
import { JiraIssueWriteError } from "./jiraIssueWriteErrors.js";
|
|
24
25
|
import { requestJiraIssueByKey, requestJiraIssuesEtagFields } from "./jiraIssueByKey.js";
|
|
25
26
|
import { JiraIssueWriter } from "./jiraIssueWrites.js";
|
|
26
27
|
import { createProviderApiRequest } from "./providerApiClient.js";
|
|
@@ -900,6 +901,18 @@ var ProvidersApi = class {
|
|
|
900
901
|
})))?.apiVersion
|
|
901
902
|
};
|
|
902
903
|
}
|
|
904
|
+
async getJiraServerIssueWriter(options, session, isCurrent, isSessionCurrent, getIgnoreSSLErrors) {
|
|
905
|
+
const verify = async () => isCurrent() && await isSessionCurrent() && isCurrent();
|
|
906
|
+
if (session.id !== options.connectionId || !session.accessToken || !await verify()) throw new JiraIssueWriteError("no-connection");
|
|
907
|
+
const request = (o) => {
|
|
908
|
+
const ignoreSSLErrors = getIgnoreSSLErrors();
|
|
909
|
+
return this.authenticationService.ctx.http.wrapForForcedInsecureSSL(ignoreSSLErrors, () => {
|
|
910
|
+
if (!isCurrent() || ignoreSSLErrors !== getIgnoreSSLErrors()) return Promise.reject(new JiraIssueWriteError("no-connection"));
|
|
911
|
+
return this.request(o);
|
|
912
|
+
});
|
|
913
|
+
};
|
|
914
|
+
return JiraIssueWriter.connectServer(request, session, options, verify);
|
|
915
|
+
}
|
|
903
916
|
async getJiraIssueWriter(options) {
|
|
904
917
|
const provider = this.providers[options.providerId];
|
|
905
918
|
if (provider == null || provider.id !== options.providerId) return void 0;
|