@gitkraken/core-gitlens 0.55.0 → 0.56.1

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/dist/git/cache.js +3 -0
  3. package/dist/git/cache.js.map +1 -1
  4. package/dist/git-cli/providers/pausedOperations.d.ts +2 -0
  5. package/dist/git-cli/providers/pausedOperations.js +104 -40
  6. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  7. package/dist/plus/integrations/index.d.ts +2 -1
  8. package/dist/plus/integrations/index.js.map +1 -1
  9. package/dist/plus/integrations/integrationService.d.ts +9 -0
  10. package/dist/plus/integrations/integrationService.js +75 -3
  11. package/dist/plus/integrations/integrationService.js.map +1 -1
  12. package/dist/plus/integrations/manager.d.ts +10 -0
  13. package/dist/plus/integrations/models/bitbucketPullRequestWrites.d.ts +217 -0
  14. package/dist/plus/integrations/models/bitbucketPullRequestWrites.js +0 -0
  15. package/dist/plus/integrations/models/integration.d.ts +2 -1
  16. package/dist/plus/integrations/models/integration.js +6 -0
  17. package/dist/plus/integrations/models/integration.js.map +1 -1
  18. package/dist/plus/integrations/models/publicIntegration.d.ts +0 -1
  19. package/dist/plus/integrations/providers/azure/writeIdentity.d.ts +0 -3
  20. package/dist/plus/integrations/providers/azure/writeIdentity.js +4 -12
  21. package/dist/plus/integrations/providers/azure/writeIdentity.js.map +1 -1
  22. package/dist/plus/integrations/providers/azureDevOps.d.ts +0 -2
  23. package/dist/plus/integrations/providers/azureDevOps.js +1 -7
  24. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  25. package/dist/plus/integrations/providers/azurePullRequestWrites.js +24 -26
  26. package/dist/plus/integrations/providers/azurePullRequestWrites.js.map +1 -1
  27. package/dist/plus/integrations/providers/azureWorkItemWriteErrors.js +4 -3
  28. package/dist/plus/integrations/providers/azureWorkItemWriteErrors.js.map +1 -1
  29. package/dist/plus/integrations/providers/azureWorkItemWrites.js +22 -21
  30. package/dist/plus/integrations/providers/azureWorkItemWrites.js.map +1 -1
  31. package/dist/plus/integrations/providers/bitbucket.d.ts +4 -0
  32. package/dist/plus/integrations/providers/bitbucket.js +8 -0
  33. package/dist/plus/integrations/providers/bitbucket.js.map +1 -1
  34. package/dist/plus/integrations/providers/bitbucketPullRequestWriteErrors.d.ts +13 -0
  35. package/dist/plus/integrations/providers/bitbucketPullRequestWriteErrors.js +88 -0
  36. package/dist/plus/integrations/providers/bitbucketPullRequestWriteErrors.js.map +1 -0
  37. package/dist/plus/integrations/providers/bitbucketPullRequestWriteLedger.d.ts +14 -0
  38. package/dist/plus/integrations/providers/bitbucketPullRequestWriteLedger.js +36 -0
  39. package/dist/plus/integrations/providers/bitbucketPullRequestWriteLedger.js.map +1 -0
  40. package/dist/plus/integrations/providers/bitbucketPullRequestWrites.d.ts +47 -0
  41. package/dist/plus/integrations/providers/bitbucketPullRequestWrites.js +796 -0
  42. package/dist/plus/integrations/providers/bitbucketPullRequestWrites.js.map +1 -0
  43. package/dist/plus/integrations/providers/issueSorts.d.ts +0 -1
  44. package/dist/plus/integrations/providers/providersApi.d.ts +4 -0
  45. package/dist/plus/integrations/providers/providersApi.js +5 -0
  46. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  47. package/dist/plus/integrations/providers/utils/writeInputs.d.ts +7 -0
  48. package/dist/plus/integrations/providers/utils/writeInputs.js +17 -0
  49. package/dist/plus/integrations/providers/utils/writeInputs.js.map +1 -0
  50. package/dist/plus/integrations/reads/drains.d.ts +0 -1
  51. package/docs/integrations.md +155 -0
  52. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import { encodeAzurePathSegment, getAzurePullRequestWebUrl } from "./azure/models.js";
2
2
  import { AzurePullRequestWriteError, toAzurePullRequestWriteFailure } from "./azurePullRequestWriteErrors.js";
3
- import { getAzureWriteOrganizations, getAzureWriteProfile, isAzureGuid, isAzureIdentifier, isAzurePositiveInt, sameAzureIdentifier, verifyAzureServerCollection } from "./azure/writeIdentity.js";
3
+ import { isCommitSha, isPositiveInt32, isWriteIdentifier, sameIdentifier } from "./utils/writeInputs.js";
4
+ import { getAzureWriteOrganizations, getAzureWriteProfile, isAzureGuid, verifyAzureServerCollection } from "./azure/writeIdentity.js";
4
5
  import { isWorkItemWriteScope } from "./azureWorkItemWriteErrors.js";
5
6
  //#region ../plus/integrations/src/providers/azurePullRequestWrites.ts
6
7
  const azureBaseUrl = "https://dev.azure.com";
@@ -19,17 +20,14 @@ const mergeStrategies = [
19
20
  "rebaseMerge"
20
21
  ];
21
22
  function isPathSegment(value) {
22
- return isAzureIdentifier(value) && value !== "." && value !== ".." && !value.includes("/") && !value.includes("\\");
23
+ return isWriteIdentifier(value) && value !== "." && value !== ".." && !value.includes("/") && !value.includes("\\");
23
24
  }
24
25
  function isBranchRef(ref) {
25
26
  return typeof ref === "string" && ref.startsWith(branchRefPrefix) && ref.length > 11 && ![...ref].some((character) => character <= " " || "~^:?*[\\".includes(character)) && !ref.includes("..") && !ref.includes("@{") && !ref.endsWith(".") && ref.split("/").every((part) => part.length > 0 && !part.startsWith(".") && !part.endsWith(".lock"));
26
27
  }
27
- function isCommitId(sha) {
28
- return typeof sha === "string" && /^(?!0{40}$)[0-9a-f]{40}$/i.test(sha);
29
- }
30
28
  function isAzurePullRequestScope(options) {
31
29
  if (options.providerId === "azure-devops-server") return isWorkItemWriteScope(options) && isPathSegment(options.repository);
32
- return (options.providerId === void 0 || options.providerId === "azureDevOps") && isAzureIdentifier(options.connectionId) && typeof options.organization === "string" && /^[a-z0-9][a-z0-9-]*$/i.test(options.organization) && isPathSegment(options.project) && isPathSegment(options.repository) && (options.expectedAccountId === void 0 || isAzureIdentifier(options.expectedAccountId));
30
+ return (options.providerId === void 0 || options.providerId === "azureDevOps") && isWriteIdentifier(options.connectionId) && typeof options.organization === "string" && /^[a-z0-9][a-z0-9-]*$/i.test(options.organization) && isPathSegment(options.project) && isPathSegment(options.repository) && (options.expectedAccountId === void 0 || isWriteIdentifier(options.expectedAccountId));
33
31
  }
34
32
  function isTitle(title) {
35
33
  return typeof title === "string" && title.trim().length > 0;
@@ -38,14 +36,14 @@ function isDescription(description) {
38
36
  return description === void 0 || typeof description === "string" && description.length <= 4e3;
39
37
  }
40
38
  function isAzurePullRequestWrite(options) {
41
- if (options.providerId !== void 0 && options.providerId !== "azureDevOps" && options.providerId !== "azure-devops-server" || !isAzureGuid(options.projectId) || !isAzureGuid(options.repositoryId) || !isAzureIdentifier(options.expectedAccountId)) return false;
39
+ if (options.providerId !== void 0 && options.providerId !== "azureDevOps" && options.providerId !== "azure-devops-server" || !isAzureGuid(options.projectId) || !isAzureGuid(options.repositoryId) || !isWriteIdentifier(options.expectedAccountId)) return false;
42
40
  if (options.action === "create") return isBranchRef(options.sourceRef) && isBranchRef(options.targetRef) && options.sourceRef !== options.targetRef && isTitle(options.title) && isDescription(options.description);
43
- if (!isAzurePositiveInt(options.number)) return false;
41
+ if (!isPositiveInt32(options.number)) return false;
44
42
  switch (options.action) {
45
43
  case "edit": return (options.title !== void 0 || options.description !== void 0) && (options.title === void 0 || isTitle(options.title)) && isDescription(options.description);
46
44
  case "abandon":
47
45
  case "reactivate": return true;
48
- case "complete": return mergeStrategies.includes(options.strategy) && isBranchRef(options.expectedSourceRef) && isBranchRef(options.expectedTargetRef) && options.expectedSourceRef !== options.expectedTargetRef && isCommitId(options.expectedSourceSha) && isCommitId(options.expectedTargetSha);
46
+ case "complete": return mergeStrategies.includes(options.strategy) && isBranchRef(options.expectedSourceRef) && isBranchRef(options.expectedTargetRef) && options.expectedSourceRef !== options.expectedTargetRef && isCommitSha(options.expectedSourceSha) && isCommitSha(options.expectedTargetSha);
49
47
  default: return false;
50
48
  }
51
49
  }
@@ -56,7 +54,7 @@ function allowsStrategy(policy, strategy) {
56
54
  return strategy === "squash" && settings.useSquashMerge === true || strategy === "noFastForward" && settings.useSquashMerge === false;
57
55
  }
58
56
  function getCompletionRefFailure(options, pullRequest) {
59
- if (pullRequest.sourceRef !== options.expectedSourceRef || !sameAzureIdentifier(pullRequest.sourceSha, options.expectedSourceSha)) return "source-changed";
57
+ if (pullRequest.sourceRef !== options.expectedSourceRef || !sameIdentifier(pullRequest.sourceSha, options.expectedSourceSha)) return "source-changed";
60
58
  if (pullRequest.targetRef !== options.expectedTargetRef) return "target-changed";
61
59
  }
62
60
  function getCompletionStateFailure(raw) {
@@ -67,8 +65,8 @@ function getCompletionStateFailure(raw) {
67
65
  function getMergePreviewFailure(raw, targetSha) {
68
66
  if (raw.mergeStatus !== "conflicts" && raw.mergeStatus !== "failure") return void 0;
69
67
  const previewTargetSha = raw.lastMergeTargetCommit?.commitId;
70
- if (!isCommitId(previewTargetSha)) return "unknown";
71
- if (!sameAzureIdentifier(previewTargetSha, targetSha)) return void 0;
68
+ if (!isCommitSha(previewTargetSha)) return "unknown";
69
+ if (!sameIdentifier(previewTargetSha, targetSha)) return void 0;
72
70
  return raw.mergeStatus === "conflicts" ? "conflict" : "unknown";
73
71
  }
74
72
  function getReportedMergeFailure(mergeStatus) {
@@ -90,10 +88,10 @@ var AzurePullRequestWriter = class AzurePullRequestWriter {
90
88
  static async connect(request, credential, options, isSessionCurrent) {
91
89
  const { body: profile } = await getAzureWriteProfile(request, credential.accessToken);
92
90
  const accountId = profile?.id;
93
- if (!isAzureIdentifier(accountId) || options.expectedAccountId !== void 0 && !sameAzureIdentifier(accountId, options.expectedAccountId)) throw new AzurePullRequestWriteError("no-connection");
91
+ if (!isWriteIdentifier(accountId) || options.expectedAccountId !== void 0 && !sameIdentifier(accountId, options.expectedAccountId)) throw new AzurePullRequestWriteError("no-connection");
94
92
  const { body: accounts } = await getAzureWriteOrganizations(request, credential.accountsAuthorization, accountId);
95
93
  if (!Array.isArray(accounts?.value)) throw new AzurePullRequestWriteError("unknown");
96
- const organization = accounts.value.find((account) => sameAzureIdentifier(account?.accountName, options.organization))?.accountName;
94
+ const organization = accounts.value.find((account) => sameIdentifier(account?.accountName, options.organization))?.accountName;
97
95
  if (organization == null) throw new AzurePullRequestWriteError("not-found");
98
96
  const headers = { Authorization: credential.gitAuthorization };
99
97
  const { body: repo } = await request({
@@ -101,7 +99,7 @@ var AzurePullRequestWriter = class AzurePullRequestWriter {
101
99
  headers,
102
100
  redirect: "error"
103
101
  });
104
- if (!isAzureGuid(repo?.id) || !isAzureGuid(repo.project?.id) || !isPathSegment(repo.name) || !isPathSegment(repo.project.name) || !sameAzureIdentifier(isAzureGuid(options.repository) ? repo.id : repo.name, options.repository) || !sameAzureIdentifier(isAzureGuid(options.project) ? repo.project.id : repo.project.name, options.project)) throw new AzurePullRequestWriteError("not-found");
102
+ if (!isAzureGuid(repo?.id) || !isAzureGuid(repo.project?.id) || !isPathSegment(repo.name) || !isPathSegment(repo.project.name) || !sameIdentifier(isAzureGuid(options.repository) ? repo.id : repo.name, options.repository) || !sameIdentifier(isAzureGuid(options.project) ? repo.project.id : repo.project.name, options.project)) throw new AzurePullRequestWriteError("not-found");
105
103
  if (repo.isDisabled || repo.isInMaintenance) throw new AzurePullRequestWriteError("unsupported");
106
104
  return new AzurePullRequestWriter(request, headers, accountId, {
107
105
  organization,
@@ -122,7 +120,7 @@ var AzurePullRequestWriter = class AzurePullRequestWriter {
122
120
  headers,
123
121
  redirect: "error"
124
122
  });
125
- if (!isAzureGuid(repo?.id) || !sameAzureIdentifier(repo.project?.id, options.projectId) || !sameAzureIdentifier(isAzureGuid(options.repository) ? repo.id : repo.name, options.repository) || !isPathSegment(repo.name) || !isPathSegment(repo.project.name)) throw new AzurePullRequestWriteError("not-found");
123
+ if (!isAzureGuid(repo?.id) || !sameIdentifier(repo.project?.id, options.projectId) || !sameIdentifier(isAzureGuid(options.repository) ? repo.id : repo.name, options.repository) || !isPathSegment(repo.name) || !isPathSegment(repo.project.name)) throw new AzurePullRequestWriteError("not-found");
126
124
  if (repo.isDisabled || repo.isInMaintenance) throw new AzurePullRequestWriteError("unsupported");
127
125
  return new AzurePullRequestWriter(request, headers, collection.accountId, {
128
126
  organization: collection.name,
@@ -160,7 +158,7 @@ var AzurePullRequestWriter = class AzurePullRequestWriter {
160
158
  };
161
159
  }
162
160
  async resolveTarget(number) {
163
- if (!isAzurePositiveInt(number)) return {
161
+ if (!isPositiveInt32(number)) return {
164
162
  ok: false,
165
163
  reason: "invalid-input"
166
164
  };
@@ -231,11 +229,11 @@ var AzurePullRequestWriter = class AzurePullRequestWriter {
231
229
  reason: "policy-blocked"
232
230
  };
233
231
  const [source, target] = await this.readCompletionRefs(pullRequest);
234
- if (!sameAzureIdentifier(source, options.expectedSourceSha)) return {
232
+ if (!sameIdentifier(source, options.expectedSourceSha)) return {
235
233
  ok: false,
236
234
  reason: "source-changed"
237
235
  };
238
- if (!sameAzureIdentifier(target, options.expectedTargetSha)) return {
236
+ if (!sameIdentifier(target, options.expectedTargetSha)) return {
239
237
  ok: false,
240
238
  reason: "target-changed"
241
239
  };
@@ -246,7 +244,7 @@ var AzurePullRequestWriter = class AzurePullRequestWriter {
246
244
  reason: latestFailure
247
245
  };
248
246
  const latestTarget = await this.readRef(options.expectedTargetRef);
249
- if (!sameAzureIdentifier(latestTarget, options.expectedTargetSha)) return {
247
+ if (!sameIdentifier(latestTarget, options.expectedTargetSha)) return {
250
248
  ok: false,
251
249
  reason: "target-changed"
252
250
  };
@@ -284,7 +282,7 @@ var AzurePullRequestWriter = class AzurePullRequestWriter {
284
282
  reason: "policy-blocked"
285
283
  } };
286
284
  const [source, targetSha] = await this.readCompletionRefs(pullRequest);
287
- if (!sameAzureIdentifier(source, pullRequest.sourceSha)) return {
285
+ if (!sameIdentifier(source, pullRequest.sourceSha)) return {
288
286
  capability: {
289
287
  kind: "unavailable",
290
288
  reason: "source-changed"
@@ -337,7 +335,7 @@ var AzurePullRequestWriter = class AzurePullRequestWriter {
337
335
  });
338
336
  for await (const refs of this.readPages(`${this.repoUrl}/refs`, query)) {
339
337
  const match = refs.find((row) => row.name === ref);
340
- if (match != null) return isCommitId(match.objectId) ? match.objectId : void 0;
338
+ if (match != null) return isCommitSha(match.objectId) ? match.objectId : void 0;
341
339
  }
342
340
  }
343
341
  async *readPages(url, query) {
@@ -378,8 +376,8 @@ var AzurePullRequestWriter = class AzurePullRequestWriter {
378
376
  return `${this.repoUrl}/pullrequests${number === void 0 ? "" : `/${number}`}?api-version=${this.apiVersion}`;
379
377
  }
380
378
  toPullRequestSnapshot(raw, number) {
381
- if (!sameAzureIdentifier(raw?.repository?.id, this.repository.repositoryId) || !sameAzureIdentifier(raw.repository.project?.id, this.repository.projectId) || number !== void 0 && raw.pullRequestId !== number) throw new AzurePullRequestWriteError("not-found");
382
- if (!isAzurePositiveInt(raw.pullRequestId) || raw.status !== "active" && raw.status !== "abandoned" && raw.status !== "completed" || typeof raw.title !== "string" || raw.description != null && typeof raw.description !== "string" || !isBranchRef(raw.sourceRefName) || !isBranchRef(raw.targetRefName)) throw new AzurePullRequestWriteError("unknown");
379
+ if (!sameIdentifier(raw?.repository?.id, this.repository.repositoryId) || !sameIdentifier(raw.repository.project?.id, this.repository.projectId) || number !== void 0 && raw.pullRequestId !== number) throw new AzurePullRequestWriteError("not-found");
380
+ if (!isPositiveInt32(raw.pullRequestId) || raw.status !== "active" && raw.status !== "abandoned" && raw.status !== "completed" || typeof raw.title !== "string" || raw.description != null && typeof raw.description !== "string" || !isBranchRef(raw.sourceRefName) || !isBranchRef(raw.targetRefName)) throw new AzurePullRequestWriteError("unknown");
383
381
  const sourceSha = raw.lastMergeSourceCommit?.commitId;
384
382
  const targetSha = raw.lastMergeTargetCommit?.commitId;
385
383
  let state = raw.status;
@@ -403,8 +401,8 @@ var AzurePullRequestWriter = class AzurePullRequestWriter {
403
401
  state,
404
402
  sourceRef: raw.sourceRefName,
405
403
  targetRef: raw.targetRefName,
406
- sourceSha: isCommitId(sourceSha) ? sourceSha : void 0,
407
- targetSha: isCommitId(targetSha) ? targetSha : void 0
404
+ sourceSha: isCommitSha(sourceSha) ? sourceSha : void 0,
405
+ targetSha: isCommitSha(targetSha) ? targetSha : void 0
408
406
  };
409
407
  }
410
408
  async save(options, body) {
@@ -1 +1 @@
1
- {"version":3,"file":"azurePullRequestWrites.js","names":[],"sources":["../../../../../plus/integrations/src/providers/azurePullRequestWrites.ts"],"sourcesContent":["import type {\n\tAzurePullRequestCreateCapabilityOptions,\n\tAzurePullRequestCreateCapabilityResult,\n\tAzurePullRequestMergeStrategy,\n\tAzurePullRequestRepository,\n\tAzurePullRequestWriteFailure,\n\tAzurePullRequestWriteOptions,\n\tAzurePullRequestWriteResult,\n\tAzurePullRequestWriteTargetResult,\n\tAzureServerPullRequestWriteOptions,\n\tAzureServerPullRequestWriteScope,\n\tAzureWrittenPullRequest,\n} from '../models/azurePullRequestWrites.js';\nimport type { AzurePullRequest, AzureRepository } from './azure/models.js';\nimport { encodeAzurePathSegment, getAzurePullRequestWebUrl } from './azure/models.js';\nimport {\n\tgetAzureWriteOrganizations,\n\tgetAzureWriteProfile,\n\tisAzureGuid,\n\tisAzureIdentifier,\n\tisAzurePositiveInt,\n\tsameAzureIdentifier,\n\tverifyAzureServerCollection,\n} from './azure/writeIdentity.js';\nimport { AzurePullRequestWriteError, toAzurePullRequestWriteFailure } from './azurePullRequestWriteErrors.js';\nimport { isWorkItemWriteScope } from './azureWorkItemWriteErrors.js';\nimport type { ProviderRequestFunction } from './models.js';\n\nconst azureBaseUrl = 'https://dev.azure.com';\nconst branchRefPrefix = 'refs/heads/';\nconst mergeStrategyPolicyId = 'fa4e907d-c16b-4a4c-9dfa-4916e5d171ab';\nconst strategySettings = {\n\tnoFastForward: 'allowNoFastForward',\n\tsquash: 'allowSquash',\n\trebase: 'allowRebase',\n\trebaseMerge: 'allowRebaseMerge',\n} as const;\nconst mergeStrategies: AzurePullRequestMergeStrategy[] = ['noFastForward', 'squash', 'rebase', 'rebaseMerge'];\n\ntype MergePolicy = {\n\tisEnabled?: boolean;\n\tisDeleted?: boolean;\n\tisBlocking?: boolean;\n\tsettings?: Partial<Record<(typeof strategySettings)[AzurePullRequestMergeStrategy] | 'useSquashMerge', boolean>>;\n};\n\ntype CompletionCapability = Extract<AzurePullRequestWriteTargetResult, { ok: true }>['capabilities']['complete'];\ntype WriteOptions = AzurePullRequestWriteOptions | AzureServerPullRequestWriteOptions;\ntype CompletionOptions = Extract<WriteOptions, { action: 'complete' }>;\ntype FailureReason = AzurePullRequestWriteFailure['reason'];\ntype PullRequestSnapshot = Omit<AzureWrittenPullRequest, 'state'> & {\n\tstate: AzureWrittenPullRequest['state'] | undefined;\n};\ntype WriteStatus = Extract<AzurePullRequestWriteResult, { ok: true }>['status'];\n\nfunction isPathSegment(value: unknown): value is string {\n\treturn isAzureIdentifier(value) && value !== '.' && value !== '..' && !value.includes('/') && !value.includes('\\\\');\n}\n\nfunction isBranchRef(ref: unknown): ref is string {\n\treturn (\n\t\ttypeof ref === 'string' &&\n\t\tref.startsWith(branchRefPrefix) &&\n\t\tref.length > branchRefPrefix.length &&\n\t\t![...ref].some(character => character <= ' ' || '~^:?*[\\\\\\x7f'.includes(character)) &&\n\t\t!ref.includes('..') &&\n\t\t!ref.includes('@{') &&\n\t\t!ref.endsWith('.') &&\n\t\tref.split('/').every(part => part.length > 0 && !part.startsWith('.') && !part.endsWith('.lock'))\n\t);\n}\n\nfunction isCommitId(sha: unknown): sha is string {\n\treturn typeof sha === 'string' && /^(?!0{40}$)[0-9a-f]{40}$/i.test(sha);\n}\n\nexport function isAzurePullRequestScope(\n\toptions: AzurePullRequestCreateCapabilityOptions | AzureServerPullRequestWriteScope,\n): boolean {\n\tif (options.providerId === 'azure-devops-server') {\n\t\treturn isWorkItemWriteScope(options) && isPathSegment(options.repository);\n\t}\n\n\treturn (\n\t\t(options.providerId === undefined || options.providerId === 'azureDevOps') &&\n\t\tisAzureIdentifier(options.connectionId) &&\n\t\ttypeof options.organization === 'string' &&\n\t\t/^[a-z0-9][a-z0-9-]*$/i.test(options.organization) &&\n\t\tisPathSegment(options.project) &&\n\t\tisPathSegment(options.repository) &&\n\t\t(options.expectedAccountId === undefined || isAzureIdentifier(options.expectedAccountId))\n\t);\n}\n\nfunction isTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nfunction isDescription(description: unknown): boolean {\n\treturn description === undefined || (typeof description === 'string' && description.length <= 4000);\n}\n\nexport function isAzurePullRequestWrite(options: WriteOptions): boolean {\n\tif (\n\t\t(options.providerId !== undefined &&\n\t\t\toptions.providerId !== 'azureDevOps' &&\n\t\t\toptions.providerId !== 'azure-devops-server') ||\n\t\t!isAzureGuid(options.projectId) ||\n\t\t!isAzureGuid(options.repositoryId) ||\n\t\t!isAzureIdentifier(options.expectedAccountId)\n\t) {\n\t\treturn false;\n\t}\n\n\tif (options.action === 'create') {\n\t\treturn (\n\t\t\tisBranchRef(options.sourceRef) &&\n\t\t\tisBranchRef(options.targetRef) &&\n\t\t\toptions.sourceRef !== options.targetRef &&\n\t\t\tisTitle(options.title) &&\n\t\t\tisDescription(options.description)\n\t\t);\n\t}\n\n\tif (!isAzurePositiveInt(options.number)) return false;\n\n\tswitch (options.action) {\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(options.title !== undefined || options.description !== undefined) &&\n\t\t\t\t(options.title === undefined || isTitle(options.title)) &&\n\t\t\t\tisDescription(options.description)\n\t\t\t);\n\t\tcase 'abandon':\n\t\tcase 'reactivate':\n\t\t\treturn true;\n\t\tcase 'complete':\n\t\t\treturn (\n\t\t\t\tmergeStrategies.includes(options.strategy) &&\n\t\t\t\tisBranchRef(options.expectedSourceRef) &&\n\t\t\t\tisBranchRef(options.expectedTargetRef) &&\n\t\t\t\toptions.expectedSourceRef !== options.expectedTargetRef &&\n\t\t\t\tisCommitId(options.expectedSourceSha) &&\n\t\t\t\tisCommitId(options.expectedTargetSha)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction allowsStrategy(policy: MergePolicy, strategy: AzurePullRequestMergeStrategy): boolean {\n\tconst settings = policy.settings;\n\tif (settings == null) return false;\n\tif (mergeStrategies.some(type => settings[strategySettings[type]] != null)) {\n\t\treturn settings[strategySettings[strategy]] === true;\n\t}\n\n\treturn (\n\t\t(strategy === 'squash' && settings.useSquashMerge === true) ||\n\t\t(strategy === 'noFastForward' && settings.useSquashMerge === false)\n\t);\n}\n\nfunction getCompletionRefFailure(\n\toptions: CompletionOptions,\n\tpullRequest: AzureWrittenPullRequest,\n): FailureReason | undefined {\n\tif (\n\t\tpullRequest.sourceRef !== options.expectedSourceRef ||\n\t\t!sameAzureIdentifier(pullRequest.sourceSha, options.expectedSourceSha)\n\t) {\n\t\treturn 'source-changed';\n\t}\n\tif (pullRequest.targetRef !== options.expectedTargetRef) return 'target-changed';\n\n\treturn undefined;\n}\n\nfunction getCompletionStateFailure(raw: AzurePullRequest): FailureReason | undefined {\n\tif (raw.forkSource != null) return 'unsupported';\n\tif (raw.isDraft) return 'policy-blocked';\n\tif (raw.status !== 'active' || raw.mergeStatus === 'queued') return 'conflict';\n\n\treturn undefined;\n}\n\nfunction getMergePreviewFailure(raw: AzurePullRequest, targetSha: string): FailureReason | undefined {\n\tif (raw.mergeStatus !== 'conflicts' && raw.mergeStatus !== 'failure') return undefined;\n\n\tconst previewTargetSha = raw.lastMergeTargetCommit?.commitId;\n\tif (!isCommitId(previewTargetSha)) return 'unknown';\n\tif (!sameAzureIdentifier(previewTargetSha, targetSha)) return undefined;\n\n\treturn raw.mergeStatus === 'conflicts' ? 'conflict' : 'unknown';\n}\n\nfunction getReportedMergeFailure(mergeStatus: AzurePullRequest['mergeStatus']): FailureReason | undefined {\n\tswitch (mergeStatus) {\n\t\tcase 'rejectedByPolicy':\n\t\t\treturn 'policy-blocked';\n\t\tcase 'conflicts':\n\t\t\treturn 'conflict';\n\t\tcase 'failure':\n\t\t\treturn 'unknown';\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nexport class AzurePullRequestWriter {\n\tstatic async connect(\n\t\trequest: ProviderRequestFunction,\n\t\tcredential: { accessToken: string; accountsAuthorization: string; gitAuthorization: string },\n\t\toptions: AzurePullRequestCreateCapabilityOptions,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t): Promise<AzurePullRequestWriter> {\n\t\tconst { body: profile } = await getAzureWriteProfile(request, credential.accessToken);\n\t\tconst accountId = profile?.id;\n\t\tif (\n\t\t\t!isAzureIdentifier(accountId) ||\n\t\t\t(options.expectedAccountId !== undefined && !sameAzureIdentifier(accountId, options.expectedAccountId))\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('no-connection');\n\t\t}\n\n\t\tconst { body: accounts } = await getAzureWriteOrganizations(\n\t\t\trequest,\n\t\t\tcredential.accountsAuthorization,\n\t\t\taccountId,\n\t\t);\n\t\tif (!Array.isArray(accounts?.value)) throw new AzurePullRequestWriteError('unknown');\n\n\t\tconst organization = accounts.value.find(account =>\n\t\t\tsameAzureIdentifier(account?.accountName, options.organization),\n\t\t)?.accountName;\n\t\tif (organization == null) throw new AzurePullRequestWriteError('not-found');\n\n\t\tconst headers = { Authorization: credential.gitAuthorization };\n\t\tconst { body: repo } = await request<AzureRepository>({\n\t\t\turl: `${azureBaseUrl}/${organization}/${encodeAzurePathSegment(options.project)}/_apis/git/repositories/${encodeAzurePathSegment(options.repository)}?api-version=7.1`,\n\t\t\theaders: headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tif (\n\t\t\t!isAzureGuid(repo?.id) ||\n\t\t\t!isAzureGuid(repo.project?.id) ||\n\t\t\t!isPathSegment(repo.name) ||\n\t\t\t!isPathSegment(repo.project.name) ||\n\t\t\t!sameAzureIdentifier(isAzureGuid(options.repository) ? repo.id : repo.name, options.repository) ||\n\t\t\t!sameAzureIdentifier(isAzureGuid(options.project) ? repo.project.id : repo.project.name, options.project)\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('not-found');\n\t\t}\n\t\tif (repo.isDisabled || repo.isInMaintenance) throw new AzurePullRequestWriteError('unsupported');\n\n\t\treturn new AzurePullRequestWriter(\n\t\t\trequest,\n\t\t\theaders,\n\t\t\taccountId,\n\t\t\t{\n\t\t\t\torganization: organization,\n\t\t\t\tprojectId: repo.project.id,\n\t\t\t\tprojectName: repo.project.name,\n\t\t\t\trepositoryId: repo.id,\n\t\t\t\trepositoryName: repo.name,\n\t\t\t},\n\t\t\tisSessionCurrent,\n\t\t);\n\t}\n\n\tstatic async connectServer(\n\t\trequest: ProviderRequestFunction,\n\t\tauthorization: string,\n\t\toptions: AzureServerPullRequestWriteScope,\n\t\troute: { collectionUrl: string; collectionBaseUrl: string },\n\t\tresolveApiVersion: () => Promise<string | undefined>,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t): Promise<AzurePullRequestWriter> {\n\t\tconst headers = { Authorization: authorization };\n\t\tconst collection = await verifyAzureServerCollection(request, headers, route.collectionUrl, options);\n\t\tif (typeof collection === 'string') throw new AzurePullRequestWriteError(collection);\n\n\t\tconst apiVersion = await resolveApiVersion();\n\t\tif (apiVersion == null) throw new AzurePullRequestWriteError('unsupported');\n\n\t\tconst { body: repo } = await request<AzureRepository>({\n\t\t\turl: `${route.collectionUrl}/${options.projectId}/_apis/git/repositories/${encodeAzurePathSegment(options.repository)}?api-version=${apiVersion}`,\n\t\t\theaders: headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tif (\n\t\t\t!isAzureGuid(repo?.id) ||\n\t\t\t!sameAzureIdentifier(repo.project?.id, options.projectId) ||\n\t\t\t!sameAzureIdentifier(isAzureGuid(options.repository) ? repo.id : repo.name, options.repository) ||\n\t\t\t!isPathSegment(repo.name) ||\n\t\t\t!isPathSegment(repo.project.name)\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('not-found');\n\t\t}\n\t\tif (repo.isDisabled || repo.isInMaintenance) throw new AzurePullRequestWriteError('unsupported');\n\n\t\treturn new AzurePullRequestWriter(\n\t\t\trequest,\n\t\t\theaders,\n\t\t\tcollection.accountId,\n\t\t\t{\n\t\t\t\torganization: collection.name,\n\t\t\t\tprojectId: repo.project.id,\n\t\t\t\tprojectName: repo.project.name,\n\t\t\t\trepositoryId: repo.id,\n\t\t\t\trepositoryName: repo.name,\n\t\t\t\tserver: {\n\t\t\t\t\tproviderId: options.providerId,\n\t\t\t\t\tconnectionId: options.connectionId,\n\t\t\t\t\tbaseUrl: options.baseUrl,\n\t\t\t\t\tcollectionUrl: route.collectionUrl,\n\t\t\t\t\torganizationId: collection.id,\n\t\t\t\t},\n\t\t\t},\n\t\t\tisSessionCurrent,\n\t\t\troute.collectionBaseUrl,\n\t\t\tapiVersion,\n\t\t);\n\t}\n\n\tprivate readonly gitApiUrl: string;\n\tprivate readonly repoUrl: string;\n\n\tprivate constructor(\n\t\tprivate readonly request: ProviderRequestFunction,\n\t\tprivate readonly headers: { Authorization: string },\n\t\tprivate readonly accountId: string,\n\t\tprivate readonly repository: AzurePullRequestRepository,\n\t\tprivate readonly isSessionCurrent: () => Promise<boolean>,\n\t\tprivate readonly baseUrl: string = azureBaseUrl,\n\t\tprivate readonly apiVersion: string = '7.1',\n\t) {\n\t\tthis.gitApiUrl = `${baseUrl}/${encodeAzurePathSegment(repository.organization)}/${repository.projectId}/_apis/git`;\n\t\tthis.repoUrl = `${this.gitApiUrl}/repositories/${repository.repositoryId}`;\n\t}\n\n\tgetCreateCapability(): AzurePullRequestCreateCapabilityResult {\n\t\treturn { ok: true, accountId: this.accountId, repository: this.repository };\n\t}\n\n\tasync resolveTarget(number: number): Promise<AzurePullRequestWriteTargetResult> {\n\t\tif (!isAzurePositiveInt(number)) return { ok: false, reason: 'invalid-input' };\n\n\t\tconst { raw, pullRequest } = await this.readPullRequest(number);\n\t\tconst state = raw.status;\n\t\tconst { capability, targetSha } = await this.getCompletionTarget(raw, pullRequest);\n\t\treturn {\n\t\t\tok: true,\n\t\t\taccountId: this.accountId,\n\t\t\tpullRequest: targetSha === undefined ? pullRequest : { ...pullRequest, targetSha: targetSha },\n\t\t\tcapabilities: {\n\t\t\t\tedit: state === 'active' || state === 'abandoned',\n\t\t\t\tabandon: state === 'active',\n\t\t\t\treactivate: state === 'abandoned',\n\t\t\t\tcomplete: capability,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync write(options: WriteOptions): Promise<AzurePullRequestWriteResult> {\n\t\tif (options.action === 'create') {\n\t\t\treturn this.save(options, {\n\t\t\t\tsourceRefName: options.sourceRef,\n\t\t\t\ttargetRefName: options.targetRef,\n\t\t\t\ttitle: options.title,\n\t\t\t\tdescription: options.description,\n\t\t\t});\n\t\t}\n\n\t\tconst current = await this.readPullRequest(options.number);\n\t\tconst state = current.raw.status;\n\t\tswitch (options.action) {\n\t\t\tcase 'edit':\n\t\t\t\tif (state === 'completed') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.save(options, { title: options.title, description: options.description });\n\t\t\tcase 'abandon':\n\t\t\t\tif (state !== 'active') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.save(options, { status: 'abandoned' });\n\t\t\tcase 'reactivate':\n\t\t\t\tif (state !== 'abandoned') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.save(options, { status: 'active' });\n\t\t\tcase 'complete':\n\t\t\t\treturn this.complete(options, current.raw, current.pullRequest);\n\t\t}\n\t}\n\n\tprivate async complete(\n\t\toptions: CompletionOptions,\n\t\traw: AzurePullRequest,\n\t\tpullRequest: AzureWrittenPullRequest,\n\t): Promise<AzurePullRequestWriteResult> {\n\t\tconst failure = getCompletionRefFailure(options, pullRequest) ?? getCompletionStateFailure(raw);\n\t\tif (failure != null) return { ok: false, reason: failure };\n\n\t\tif (!this.supportedStrategies.includes(options.strategy)) return { ok: false, reason: 'unsupported' };\n\n\t\tconst strategies = await this.getAllowedStrategies(options.expectedTargetRef);\n\t\tif (!strategies.includes(options.strategy)) return { ok: false, reason: 'policy-blocked' };\n\n\t\tconst [source, target] = await this.readCompletionRefs(pullRequest);\n\t\tif (!sameAzureIdentifier(source, options.expectedSourceSha)) return { ok: false, reason: 'source-changed' };\n\t\tif (!sameAzureIdentifier(target, options.expectedTargetSha)) return { ok: false, reason: 'target-changed' };\n\n\t\tconst latest = await this.readPullRequest(options.number);\n\t\tconst latestFailure =\n\t\t\tgetCompletionRefFailure(options, latest.pullRequest) ?? getCompletionStateFailure(latest.raw);\n\t\tif (latestFailure != null) return { ok: false, reason: latestFailure };\n\n\t\tconst latestTarget = await this.readRef(options.expectedTargetRef);\n\t\tif (!sameAzureIdentifier(latestTarget, options.expectedTargetSha)) {\n\t\t\treturn { ok: false, reason: 'target-changed' };\n\t\t}\n\n\t\tconst previewFailure = getMergePreviewFailure(latest.raw, options.expectedTargetSha);\n\t\tif (previewFailure != null) return { ok: false, reason: previewFailure };\n\n\t\treturn this.save(options, {\n\t\t\tstatus: 'completed',\n\t\t\tcompletionOptions:\n\t\t\t\tthis.apiVersion === '5.0'\n\t\t\t\t\t? { squashMerge: options.strategy === 'squash', bypassPolicy: false }\n\t\t\t\t\t: { mergeStrategy: options.strategy, bypassPolicy: false },\n\t\t\tlastMergeSourceCommit: { commitId: options.expectedSourceSha },\n\t\t});\n\t}\n\n\tprivate async getCompletionTarget(\n\t\traw: AzurePullRequest,\n\t\tpullRequest: AzureWrittenPullRequest,\n\t): Promise<{ capability: CompletionCapability; targetSha?: string }> {\n\t\tconst stateFailure = getCompletionStateFailure(raw);\n\t\tif (stateFailure != null) return { capability: { kind: 'unavailable', reason: stateFailure } };\n\t\tif (!pullRequest.sourceSha) return { capability: { kind: 'unavailable', reason: 'unknown' } };\n\n\t\ttry {\n\t\t\tconst strategies = await this.getAllowedStrategies(pullRequest.targetRef);\n\t\t\tif (!strategies.length) return { capability: { kind: 'unavailable', reason: 'policy-blocked' } };\n\n\t\t\tconst [source, targetSha] = await this.readCompletionRefs(pullRequest);\n\t\t\tif (!sameAzureIdentifier(source, pullRequest.sourceSha)) {\n\t\t\t\treturn { capability: { kind: 'unavailable', reason: 'source-changed' }, targetSha: targetSha };\n\t\t\t}\n\t\t\tif (targetSha === undefined) return { capability: { kind: 'unavailable', reason: 'target-changed' } };\n\n\t\t\tconst previewFailure = getMergePreviewFailure(raw, targetSha);\n\t\t\treturn {\n\t\t\t\tcapability:\n\t\t\t\t\tpreviewFailure === undefined\n\t\t\t\t\t\t? { kind: 'available', strategies: strategies }\n\t\t\t\t\t\t: { kind: 'unavailable', reason: previewFailure },\n\t\t\t\ttargetSha: targetSha,\n\t\t\t};\n\t\t} catch (ex) {\n\t\t\treturn { capability: { kind: 'unavailable', reason: toAzurePullRequestWriteFailure(ex).reason } };\n\t\t}\n\t}\n\n\tprivate readCompletionRefs(\n\t\tpullRequest: AzureWrittenPullRequest,\n\t): Promise<[string | undefined, string | undefined]> {\n\t\treturn Promise.all([this.readRef(pullRequest.sourceRef), this.readRef(pullRequest.targetRef)]);\n\t}\n\n\tprivate get supportedStrategies(): AzurePullRequestMergeStrategy[] {\n\t\treturn this.apiVersion === '5.0' ? ['noFastForward', 'squash'] : mergeStrategies;\n\t}\n\n\tprivate async getAllowedStrategies(ref: string): Promise<AzurePullRequestMergeStrategy[]> {\n\t\tconst query = new URLSearchParams({\n\t\t\t'api-version': this.repository.server == null ? '7.1' : '5.0-preview.1',\n\t\t\trepositoryId: this.repository.repositoryId,\n\t\t\trefName: ref,\n\t\t\tpolicyType: mergeStrategyPolicyId,\n\t\t});\n\t\tlet strategies = this.supportedStrategies.slice();\n\t\tfor await (const policies of this.readPages<MergePolicy>(`${this.gitApiUrl}/policy/configurations`, query)) {\n\t\t\tfor (const policy of policies) {\n\t\t\t\tif (policy.isEnabled === true && policy.isDeleted !== true && policy.isBlocking === true) {\n\t\t\t\t\tstrategies = strategies.filter(strategy => allowsStrategy(policy, strategy));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn strategies;\n\t}\n\n\tprivate async readRef(ref: string): Promise<string | undefined> {\n\t\tconst query = new URLSearchParams({ 'api-version': this.apiVersion, filter: ref.slice('refs/'.length) });\n\t\tfor await (const refs of this.readPages<{ name: string; objectId: string }>(`${this.repoUrl}/refs`, query)) {\n\t\t\tconst match = refs.find(row => row.name === ref);\n\t\t\tif (match != null) return isCommitId(match.objectId) ? match.objectId : undefined;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate async *readPages<T>(url: string, query: URLSearchParams): AsyncGenerator<T[]> {\n\t\tconst seen = new Set<string>();\n\t\twhile (true) {\n\t\t\tconst { body, headers } = await this.request<{ value?: T[] }>({\n\t\t\t\turl: `${url}?${query.toString()}`,\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t\tif (!Array.isArray(body?.value)) throw new AzurePullRequestWriteError('unknown');\n\n\t\t\tyield body.value;\n\n\t\t\tconst next = headers['x-ms-continuationtoken'];\n\t\t\tif (!next) return;\n\t\t\tif (seen.has(next)) throw new AzurePullRequestWriteError('unknown');\n\n\t\t\tseen.add(next);\n\t\t\tquery.set('continuationToken', next);\n\t\t}\n\t}\n\n\tprivate async readPullRequest(\n\t\tnumber: number,\n\t): Promise<{ raw: AzurePullRequest; pullRequest: AzureWrittenPullRequest }> {\n\t\tconst { body: raw } = await this.request<AzurePullRequest>({\n\t\t\turl: this.pullRequestUrl(number),\n\t\t\theaders: this.headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tconst snapshot = this.toPullRequestSnapshot(raw, number);\n\t\tconst { state } = snapshot;\n\t\tif (state === undefined) {\n\t\t\tthrow new AzurePullRequestWriteError(getReportedMergeFailure(raw.mergeStatus) ?? 'unknown');\n\t\t}\n\t\treturn { raw: raw, pullRequest: { ...snapshot, state: state } };\n\t}\n\n\tprivate pullRequestUrl(number?: number): string {\n\t\treturn `${this.repoUrl}/pullrequests${number === undefined ? '' : `/${number}`}?api-version=${this.apiVersion}`;\n\t}\n\n\tprivate toPullRequestSnapshot(raw: AzurePullRequest, number?: number): PullRequestSnapshot {\n\t\tif (\n\t\t\t!sameAzureIdentifier(raw?.repository?.id, this.repository.repositoryId) ||\n\t\t\t!sameAzureIdentifier(raw.repository.project?.id, this.repository.projectId) ||\n\t\t\t(number !== undefined && raw.pullRequestId !== number)\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('not-found');\n\t\t}\n\n\t\tif (\n\t\t\t!isAzurePositiveInt(raw.pullRequestId) ||\n\t\t\t(raw.status !== 'active' && raw.status !== 'abandoned' && raw.status !== 'completed') ||\n\t\t\ttypeof raw.title !== 'string' ||\n\t\t\t(raw.description != null && typeof raw.description !== 'string') ||\n\t\t\t!isBranchRef(raw.sourceRefName) ||\n\t\t\t!isBranchRef(raw.targetRefName)\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('unknown');\n\t\t}\n\n\t\tconst sourceSha = raw.lastMergeSourceCommit?.commitId;\n\t\tconst targetSha = raw.lastMergeTargetCommit?.commitId;\n\t\tlet state: PullRequestSnapshot['state'] = raw.status;\n\t\tif (state === 'completed' && raw.mergeStatus !== 'succeeded') {\n\t\t\tstate = raw.mergeStatus === 'queued' ? 'active' : undefined;\n\t\t}\n\t\treturn {\n\t\t\trepository: this.repository,\n\t\t\tnumber: raw.pullRequestId,\n\t\t\turl: getAzurePullRequestWebUrl(\n\t\t\t\t{\n\t\t\t\t\tpullRequestId: raw.pullRequestId,\n\t\t\t\t\trepository: {\n\t\t\t\t\t\t...raw.repository,\n\t\t\t\t\t\tname: this.repository.repositoryName,\n\t\t\t\t\t\tproject: { id: this.repository.projectId, name: this.repository.projectName },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tthis.baseUrl,\n\t\t\t\tthis.repository.organization,\n\t\t\t),\n\t\t\ttitle: raw.title,\n\t\t\tdescription: raw.description ?? '',\n\t\t\tstate: state,\n\t\t\tsourceRef: raw.sourceRefName,\n\t\t\ttargetRef: raw.targetRefName,\n\t\t\tsourceSha: isCommitId(sourceSha) ? sourceSha : undefined,\n\t\t\ttargetSha: isCommitId(targetSha) ? targetSha : undefined,\n\t\t};\n\t}\n\n\tprivate async save(options: WriteOptions, body: object): Promise<AzurePullRequestWriteResult> {\n\t\tif (!(await this.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\t\tconst create = options.action === 'create';\n\t\tconst number = create ? undefined : options.number;\n\t\tlet raw: AzurePullRequest;\n\t\ttry {\n\t\t\t({ body: raw } = await this.request<AzurePullRequest>({\n\t\t\t\turl: this.pullRequestUrl(number),\n\t\t\t\tmethod: create ? 'POST' : 'PATCH',\n\t\t\t\theaders: { ...this.headers, 'Content-Type': 'application/json' },\n\t\t\t\tbody: JSON.stringify(body),\n\t\t\t\tredirect: 'error',\n\t\t\t}));\n\t\t} catch (ex) {\n\t\t\treturn toAzurePullRequestWriteFailure(ex, { complete: options.action === 'complete' });\n\t\t}\n\n\t\tlet snapshot: PullRequestSnapshot;\n\t\ttry {\n\t\t\tsnapshot = this.toPullRequestSnapshot(raw, number);\n\t\t} catch {\n\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\n\t\treturn this.getReceipt(options, raw, snapshot);\n\t}\n\n\tprivate getReceipt(\n\t\toptions: WriteOptions,\n\t\traw: AzurePullRequest,\n\t\tsnapshot: PullRequestSnapshot,\n\t): AzurePullRequestWriteResult {\n\t\tconst { state, sourceRef, targetRef } = snapshot;\n\t\tlet status: WriteStatus | undefined;\n\t\tswitch (options.action) {\n\t\t\tcase 'create':\n\t\t\t\tif (state === 'active' && sourceRef === options.sourceRef && targetRef === options.targetRef) {\n\t\t\t\t\tstatus = 'created';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'edit':\n\t\t\t\tif (\n\t\t\t\t\t(options.title === undefined || snapshot.title === options.title) &&\n\t\t\t\t\t(options.description === undefined || snapshot.description === options.description)\n\t\t\t\t) {\n\t\t\t\t\tstatus = 'updated';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'abandon':\n\t\t\t\tif (state === 'abandoned') {\n\t\t\t\t\tstatus = 'abandoned';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'reactivate':\n\t\t\t\tif (state === 'active') {\n\t\t\t\t\tstatus = 'reactivated';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'complete': {\n\t\t\t\tif (sourceRef !== options.expectedSourceRef || targetRef !== options.expectedTargetRef) break;\n\n\t\t\t\tconst failure = getReportedMergeFailure(raw.mergeStatus);\n\t\t\t\tif (failure != null) return { ok: false, reason: failure };\n\n\t\t\t\tif (state === 'active' && raw.mergeStatus === 'queued') {\n\t\t\t\t\tstatus = 'pending';\n\t\t\t\t} else if (state === 'completed') {\n\t\t\t\t\tstatus = 'completed';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn status === undefined || state === undefined\n\t\t\t? { ok: false, reason: 'outcome-unknown' }\n\t\t\t: { ok: true, status: status, pullRequest: { ...snapshot, state: state } };\n\t}\n}\n"],"mappings":";;;;;AA4BA,MAAM,eAAe;AACrB,MAAM,kBAAkB;AACxB,MAAM,wBAAwB;AAC9B,MAAM,mBAAmB;CACxB,eAAe;CACf,QAAQ;CACR,QAAQ;CACR,aAAa;AACd;AACA,MAAM,kBAAmD;CAAC;CAAiB;CAAU;CAAU;AAAa;AAkB5G,SAAS,cAAc,OAAiC;CACvD,OAAO,kBAAkB,KAAK,KAAK,UAAU,OAAO,UAAU,QAAQ,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,SAAS,IAAI;AACnH;AAEA,SAAS,YAAY,KAA6B;CACjD,OACC,OAAO,QAAQ,YACf,IAAI,WAAW,eAAe,KAC9B,IAAI,SAAS,MACb,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,MAAK,cAAa,aAAa,OAAO,YAAe,SAAS,SAAS,CAAC,KAClF,CAAC,IAAI,SAAS,IAAI,KAClB,CAAC,IAAI,SAAS,IAAI,KAClB,CAAC,IAAI,SAAS,GAAG,KACjB,IAAI,MAAM,GAAG,CAAC,CAAC,OAAM,SAAQ,KAAK,SAAS,KAAK,CAAC,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,SAAS,OAAO,CAAC;AAElG;AAEA,SAAS,WAAW,KAA6B;CAChD,OAAO,OAAO,QA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ent":["import type {\n\tAzurePullRequestCreateCapabilityOptions,\n\tAzurePullRequestCreateCapabilityResult,\n\tAzurePullRequestMergeStrategy,\n\tAzurePullRequestRepository,\n\tAzurePullRequestWriteFailure,\n\tAzurePullRequestWriteOptions,\n\tAzurePullRequestWriteResult,\n\tAzurePullRequestWriteTargetResult,\n\tAzureServerPullRequestWriteOptions,\n\tAzureServerPullRequestWriteScope,\n\tAzureWrittenPullRequest,\n} from '../models/azurePullRequestWrites.js';\nimport type { AzurePullRequest, AzureRepository } from './azure/models.js';\nimport { encodeAzurePathSegment, getAzurePullRequestWebUrl } from './azure/models.js';\nimport {\n\tgetAzureWriteOrganizations,\n\tgetAzureWriteProfile,\n\tisAzureGuid,\n\tverifyAzureServerCollection,\n} from './azure/writeIdentity.js';\nimport { AzurePullRequestWriteError, toAzurePullRequestWriteFailure } from './azurePullRequestWriteErrors.js';\nimport { isWorkItemWriteScope } from './azureWorkItemWriteErrors.js';\nimport type { ProviderRequestFunction } from './models.js';\nimport { isCommitSha, isPositiveInt32, isWriteIdentifier, sameIdentifier } from './utils/writeInputs.js';\n\nconst azureBaseUrl = 'https://dev.azure.com';\nconst branchRefPrefix = 'refs/heads/';\nconst mergeStrategyPolicyId = 'fa4e907d-c16b-4a4c-9dfa-4916e5d171ab';\nconst strategySettings = {\n\tnoFastForward: 'allowNoFastForward',\n\tsquash: 'allowSquash',\n\trebase: 'allowRebase',\n\trebaseMerge: 'allowRebaseMerge',\n} as const;\nconst mergeStrategies: AzurePullRequestMergeStrategy[] = ['noFastForward', 'squash', 'rebase', 'rebaseMerge'];\n\ntype MergePolicy = {\n\tisEnabled?: boolean;\n\tisDeleted?: boolean;\n\tisBlocking?: boolean;\n\tsettings?: Partial<Record<(typeof strategySettings)[AzurePullRequestMergeStrategy] | 'useSquashMerge', boolean>>;\n};\n\ntype CompletionCapability = Extract<AzurePullRequestWriteTargetResult, { ok: true }>['capabilities']['complete'];\ntype WriteOptions = AzurePullRequestWriteOptions | AzureServerPullRequestWriteOptions;\ntype CompletionOptions = Extract<WriteOptions, { action: 'complete' }>;\ntype FailureReason = AzurePullRequestWriteFailure['reason'];\ntype PullRequestSnapshot = Omit<AzureWrittenPullRequest, 'state'> & {\n\tstate: AzureWrittenPullRequest['state'] | undefined;\n};\ntype WriteStatus = Extract<AzurePullRequestWriteResult, { ok: true }>['status'];\n\nfunction isPathSegment(value: unknown): value is string {\n\treturn isWriteIdentifier(value) && value !== '.' && value !== '..' && !value.includes('/') && !value.includes('\\\\');\n}\n\nfunction isBranchRef(ref: unknown): ref is string {\n\treturn (\n\t\ttypeof ref === 'string' &&\n\t\tref.startsWith(branchRefPrefix) &&\n\t\tref.length > branchRefPrefix.length &&\n\t\t![...ref].some(character => character <= ' ' || '~^:?*[\\\\\\x7f'.includes(character)) &&\n\t\t!ref.includes('..') &&\n\t\t!ref.includes('@{') &&\n\t\t!ref.endsWith('.') &&\n\t\tref.split('/').every(part => part.length > 0 && !part.startsWith('.') && !part.endsWith('.lock'))\n\t);\n}\n\nexport function isAzurePullRequestScope(\n\toptions: AzurePullRequestCreateCapabilityOptions | AzureServerPullRequestWriteScope,\n): boolean {\n\tif (options.providerId === 'azure-devops-server') {\n\t\treturn isWorkItemWriteScope(options) && isPathSegment(options.repository);\n\t}\n\n\treturn (\n\t\t(options.providerId === undefined || options.providerId === 'azureDevOps') &&\n\t\tisWriteIdentifier(options.connectionId) &&\n\t\ttypeof options.organization === 'string' &&\n\t\t/^[a-z0-9][a-z0-9-]*$/i.test(options.organization) &&\n\t\tisPathSegment(options.project) &&\n\t\tisPathSegment(options.repository) &&\n\t\t(options.expectedAccountId === undefined || isWriteIdentifier(options.expectedAccountId))\n\t);\n}\n\nfunction isTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nfunction isDescription(description: unknown): boolean {\n\treturn description === undefined || (typeof description === 'string' && description.length <= 4000);\n}\n\nexport function isAzurePullRequestWrite(options: WriteOptions): boolean {\n\tif (\n\t\t(options.providerId !== undefined &&\n\t\t\toptions.providerId !== 'azureDevOps' &&\n\t\t\toptions.providerId !== 'azure-devops-server') ||\n\t\t!isAzureGuid(options.projectId) ||\n\t\t!isAzureGuid(options.repositoryId) ||\n\t\t!isWriteIdentifier(options.expectedAccountId)\n\t) {\n\t\treturn false;\n\t}\n\n\tif (options.action === 'create') {\n\t\treturn (\n\t\t\tisBranchRef(options.sourceRef) &&\n\t\t\tisBranchRef(options.targetRef) &&\n\t\t\toptions.sourceRef !== options.targetRef &&\n\t\t\tisTitle(options.title) &&\n\t\t\tisDescription(options.description)\n\t\t);\n\t}\n\n\tif (!isPositiveInt32(options.number)) return false;\n\n\tswitch (options.action) {\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(options.title !== undefined || options.description !== undefined) &&\n\t\t\t\t(options.title === undefined || isTitle(options.title)) &&\n\t\t\t\tisDescription(options.description)\n\t\t\t);\n\t\tcase 'abandon':\n\t\tcase 'reactivate':\n\t\t\treturn true;\n\t\tcase 'complete':\n\t\t\treturn (\n\t\t\t\tmergeStrategies.includes(options.strategy) &&\n\t\t\t\tisBranchRef(options.expectedSourceRef) &&\n\t\t\t\tisBranchRef(options.expectedTargetRef) &&\n\t\t\t\toptions.expectedSourceRef !== options.expectedTargetRef &&\n\t\t\t\tisCommitSha(options.expectedSourceSha) &&\n\t\t\t\tisCommitSha(options.expectedTargetSha)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction allowsStrategy(policy: MergePolicy, strategy: AzurePullRequestMergeStrategy): boolean {\n\tconst settings = policy.settings;\n\tif (settings == null) return false;\n\tif (mergeStrategies.some(type => settings[strategySettings[type]] != null)) {\n\t\treturn settings[strategySettings[strategy]] === true;\n\t}\n\n\treturn (\n\t\t(strategy === 'squash' && settings.useSquashMerge === true) ||\n\t\t(strategy === 'noFastForward' && settings.useSquashMerge === false)\n\t);\n}\n\nfunction getCompletionRefFailure(\n\toptions: CompletionOptions,\n\tpullRequest: AzureWrittenPullRequest,\n): FailureReason | undefined {\n\tif (\n\t\tpullRequest.sourceRef !== options.expectedSourceRef ||\n\t\t!sameIdentifier(pullRequest.sourceSha, options.expectedSourceSha)\n\t) {\n\t\treturn 'source-changed';\n\t}\n\tif (pullRequest.targetRef !== options.expectedTargetRef) return 'target-changed';\n\n\treturn undefined;\n}\n\nfunction getCompletionStateFailure(raw: AzurePullRequest): FailureReason | undefined {\n\tif (raw.forkSource != null) return 'unsupported';\n\tif (raw.isDraft) return 'policy-blocked';\n\tif (raw.status !== 'active' || raw.mergeStatus === 'queued') return 'conflict';\n\n\treturn undefined;\n}\n\nfunction getMergePreviewFailure(raw: AzurePullRequest, targetSha: string): FailureReason | undefined {\n\tif (raw.mergeStatus !== 'conflicts' && raw.mergeStatus !== 'failure') return undefined;\n\n\tconst previewTargetSha = raw.lastMergeTargetCommit?.commitId;\n\tif (!isCommitSha(previewTargetSha)) return 'unknown';\n\tif (!sameIdentifier(previewTargetSha, targetSha)) return undefined;\n\n\treturn raw.mergeStatus === 'conflicts' ? 'conflict' : 'unknown';\n}\n\nfunction getReportedMergeFailure(mergeStatus: AzurePullRequest['mergeStatus']): FailureReason | undefined {\n\tswitch (mergeStatus) {\n\t\tcase 'rejectedByPolicy':\n\t\t\treturn 'policy-blocked';\n\t\tcase 'conflicts':\n\t\t\treturn 'conflict';\n\t\tcase 'failure':\n\t\t\treturn 'unknown';\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nexport class AzurePullRequestWriter {\n\tstatic async connect(\n\t\trequest: ProviderRequestFunction,\n\t\tcredential: { accessToken: string; accountsAuthorization: string; gitAuthorization: string },\n\t\toptions: AzurePullRequestCreateCapabilityOptions,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t): Promise<AzurePullRequestWriter> {\n\t\tconst { body: profile } = await getAzureWriteProfile(request, credential.accessToken);\n\t\tconst accountId = profile?.id;\n\t\tif (\n\t\t\t!isWriteIdentifier(accountId) ||\n\t\t\t(options.expectedAccountId !== undefined && !sameIdentifier(accountId, options.expectedAccountId))\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('no-connection');\n\t\t}\n\n\t\tconst { body: accounts } = await getAzureWriteOrganizations(\n\t\t\trequest,\n\t\t\tcredential.accountsAuthorization,\n\t\t\taccountId,\n\t\t);\n\t\tif (!Array.isArray(accounts?.value)) throw new AzurePullRequestWriteError('unknown');\n\n\t\tconst organization = accounts.value.find(account =>\n\t\t\tsameIdentifier(account?.accountName, options.organization),\n\t\t)?.accountName;\n\t\tif (organization == null) throw new AzurePullRequestWriteError('not-found');\n\n\t\tconst headers = { Authorization: credential.gitAuthorization };\n\t\tconst { body: repo } = await request<AzureRepository>({\n\t\t\turl: `${azureBaseUrl}/${organization}/${encodeAzurePathSegment(options.project)}/_apis/git/repositories/${encodeAzurePathSegment(options.repository)}?api-version=7.1`,\n\t\t\theaders: headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tif (\n\t\t\t!isAzureGuid(repo?.id) ||\n\t\t\t!isAzureGuid(repo.project?.id) ||\n\t\t\t!isPathSegment(repo.name) ||\n\t\t\t!isPathSegment(repo.project.name) ||\n\t\t\t!sameIdentifier(isAzureGuid(options.repository) ? repo.id : repo.name, options.repository) ||\n\t\t\t!sameIdentifier(isAzureGuid(options.project) ? repo.project.id : repo.project.name, options.project)\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('not-found');\n\t\t}\n\t\tif (repo.isDisabled || repo.isInMaintenance) throw new AzurePullRequestWriteError('unsupported');\n\n\t\treturn new AzurePullRequestWriter(\n\t\t\trequest,\n\t\t\theaders,\n\t\t\taccountId,\n\t\t\t{\n\t\t\t\torganization: organization,\n\t\t\t\tprojectId: repo.project.id,\n\t\t\t\tprojectName: repo.project.name,\n\t\t\t\trepositoryId: repo.id,\n\t\t\t\trepositoryName: repo.name,\n\t\t\t},\n\t\t\tisSessionCurrent,\n\t\t);\n\t}\n\n\tstatic async connectServer(\n\t\trequest: ProviderRequestFunction,\n\t\tauthorization: string,\n\t\toptions: AzureServerPullRequestWriteScope,\n\t\troute: { collectionUrl: string; collectionBaseUrl: string },\n\t\tresolveApiVersion: () => Promise<string | undefined>,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t): Promise<AzurePullRequestWriter> {\n\t\tconst headers = { Authorization: authorization };\n\t\tconst collection = await verifyAzureServerCollection(request, headers, route.collectionUrl, options);\n\t\tif (typeof collection === 'string') throw new AzurePullRequestWriteError(collection);\n\n\t\tconst apiVersion = await resolveApiVersion();\n\t\tif (apiVersion == null) throw new AzurePullRequestWriteError('unsupported');\n\n\t\tconst { body: repo } = await request<AzureRepository>({\n\t\t\turl: `${route.collectionUrl}/${options.projectId}/_apis/git/repositories/${encodeAzurePathSegment(options.repository)}?api-version=${apiVersion}`,\n\t\t\theaders: headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tif (\n\t\t\t!isAzureGuid(repo?.id) ||\n\t\t\t!sameIdentifier(repo.project?.id, options.projectId) ||\n\t\t\t!sameIdentifier(isAzureGuid(options.repository) ? repo.id : repo.name, options.repository) ||\n\t\t\t!isPathSegment(repo.name) ||\n\t\t\t!isPathSegment(repo.project.name)\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('not-found');\n\t\t}\n\t\tif (repo.isDisabled || repo.isInMaintenance) throw new AzurePullRequestWriteError('unsupported');\n\n\t\treturn new AzurePullRequestWriter(\n\t\t\trequest,\n\t\t\theaders,\n\t\t\tcollection.accountId,\n\t\t\t{\n\t\t\t\torganization: collection.name,\n\t\t\t\tprojectId: repo.project.id,\n\t\t\t\tprojectName: repo.project.name,\n\t\t\t\trepositoryId: repo.id,\n\t\t\t\trepositoryName: repo.name,\n\t\t\t\tserver: {\n\t\t\t\t\tproviderId: options.providerId,\n\t\t\t\t\tconnectionId: options.connectionId,\n\t\t\t\t\tbaseUrl: options.baseUrl,\n\t\t\t\t\tcollectionUrl: route.collectionUrl,\n\t\t\t\t\torganizationId: collection.id,\n\t\t\t\t},\n\t\t\t},\n\t\t\tisSessionCurrent,\n\t\t\troute.collectionBaseUrl,\n\t\t\tapiVersion,\n\t\t);\n\t}\n\n\tprivate readonly gitApiUrl: string;\n\tprivate readonly repoUrl: string;\n\n\tprivate constructor(\n\t\tprivate readonly request: ProviderRequestFunction,\n\t\tprivate readonly headers: { Authorization: string },\n\t\tprivate readonly accountId: string,\n\t\tprivate readonly repository: AzurePullRequestRepository,\n\t\tprivate readonly isSessionCurrent: () => Promise<boolean>,\n\t\tprivate readonly baseUrl: string = azureBaseUrl,\n\t\tprivate readonly apiVersion: string = '7.1',\n\t) {\n\t\tthis.gitApiUrl = `${baseUrl}/${encodeAzurePathSegment(repository.organization)}/${repository.projectId}/_apis/git`;\n\t\tthis.repoUrl = `${this.gitApiUrl}/repositories/${repository.repositoryId}`;\n\t}\n\n\tgetCreateCapability(): AzurePullRequestCreateCapabilityResult {\n\t\treturn { ok: true, accountId: this.accountId, repository: this.repository };\n\t}\n\n\tasync resolveTarget(number: number): Promise<AzurePullRequestWriteTargetResult> {\n\t\tif (!isPositiveInt32(number)) return { ok: false, reason: 'invalid-input' };\n\n\t\tconst { raw, pullRequest } = await this.readPullRequest(number);\n\t\tconst state = raw.status;\n\t\tconst { capability, targetSha } = await this.getCompletionTarget(raw, pullRequest);\n\t\treturn {\n\t\t\tok: true,\n\t\t\taccountId: this.accountId,\n\t\t\tpullRequest: targetSha === undefined ? pullRequest : { ...pullRequest, targetSha: targetSha },\n\t\t\tcapabilities: {\n\t\t\t\tedit: state === 'active' || state === 'abandoned',\n\t\t\t\tabandon: state === 'active',\n\t\t\t\treactivate: state === 'abandoned',\n\t\t\t\tcomplete: capability,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync write(options: WriteOptions): Promise<AzurePullRequestWriteResult> {\n\t\tif (options.action === 'create') {\n\t\t\treturn this.save(options, {\n\t\t\t\tsourceRefName: options.sourceRef,\n\t\t\t\ttargetRefName: options.targetRef,\n\t\t\t\ttitle: options.title,\n\t\t\t\tdescription: options.description,\n\t\t\t});\n\t\t}\n\n\t\tconst current = await this.readPullRequest(options.number);\n\t\tconst state = current.raw.status;\n\t\tswitch (options.action) {\n\t\t\tcase 'edit':\n\t\t\t\tif (state === 'completed') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.save(options, { title: options.title, description: options.description });\n\t\t\tcase 'abandon':\n\t\t\t\tif (state !== 'active') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.save(options, { status: 'abandoned' });\n\t\t\tcase 'reactivate':\n\t\t\t\tif (state !== 'abandoned') return { ok: false, reason: 'conflict' };\n\n\t\t\t\treturn this.save(options, { status: 'active' });\n\t\t\tcase 'complete':\n\t\t\t\treturn this.complete(options, current.raw, current.pullRequest);\n\t\t}\n\t}\n\n\tprivate async complete(\n\t\toptions: CompletionOptions,\n\t\traw: AzurePullRequest,\n\t\tpullRequest: AzureWrittenPullRequest,\n\t): Promise<AzurePullRequestWriteResult> {\n\t\tconst failure = getCompletionRefFailure(options, pullRequest) ?? getCompletionStateFailure(raw);\n\t\tif (failure != null) return { ok: false, reason: failure };\n\n\t\tif (!this.supportedStrategies.includes(options.strategy)) return { ok: false, reason: 'unsupported' };\n\n\t\tconst strategies = await this.getAllowedStrategies(options.expectedTargetRef);\n\t\tif (!strategies.includes(options.strategy)) return { ok: false, reason: 'policy-blocked' };\n\n\t\tconst [source, target] = await this.readCompletionRefs(pullRequest);\n\t\tif (!sameIdentifier(source, options.expectedSourceSha)) return { ok: false, reason: 'source-changed' };\n\t\tif (!sameIdentifier(target, options.expectedTargetSha)) return { ok: false, reason: 'target-changed' };\n\n\t\tconst latest = await this.readPullRequest(options.number);\n\t\tconst latestFailure =\n\t\t\tgetCompletionRefFailure(options, latest.pullRequest) ?? getCompletionStateFailure(latest.raw);\n\t\tif (latestFailure != null) return { ok: false, reason: latestFailure };\n\n\t\tconst latestTarget = await this.readRef(options.expectedTargetRef);\n\t\tif (!sameIdentifier(latestTarget, options.expectedTargetSha)) {\n\t\t\treturn { ok: false, reason: 'target-changed' };\n\t\t}\n\n\t\tconst previewFailure = getMergePreviewFailure(latest.raw, options.expectedTargetSha);\n\t\tif (previewFailure != null) return { ok: false, reason: previewFailure };\n\n\t\treturn this.save(options, {\n\t\t\tstatus: 'completed',\n\t\t\tcompletionOptions:\n\t\t\t\tthis.apiVersion === '5.0'\n\t\t\t\t\t? { squashMerge: options.strategy === 'squash', bypassPolicy: false }\n\t\t\t\t\t: { mergeStrategy: options.strategy, bypassPolicy: false },\n\t\t\tlastMergeSourceCommit: { commitId: options.expectedSourceSha },\n\t\t});\n\t}\n\n\tprivate async getCompletionTarget(\n\t\traw: AzurePullRequest,\n\t\tpullRequest: AzureWrittenPullRequest,\n\t): Promise<{ capability: CompletionCapability; targetSha?: string }> {\n\t\tconst stateFailure = getCompletionStateFailure(raw);\n\t\tif (stateFailure != null) return { capability: { kind: 'unavailable', reason: stateFailure } };\n\t\tif (!pullRequest.sourceSha) return { capability: { kind: 'unavailable', reason: 'unknown' } };\n\n\t\ttry {\n\t\t\tconst strategies = await this.getAllowedStrategies(pullRequest.targetRef);\n\t\t\tif (!strategies.length) return { capability: { kind: 'unavailable', reason: 'policy-blocked' } };\n\n\t\t\tconst [source, targetSha] = await this.readCompletionRefs(pullRequest);\n\t\t\tif (!sameIdentifier(source, pullRequest.sourceSha)) {\n\t\t\t\treturn { capability: { kind: 'unavailable', reason: 'source-changed' }, targetSha: targetSha };\n\t\t\t}\n\t\t\tif (targetSha === undefined) return { capability: { kind: 'unavailable', reason: 'target-changed' } };\n\n\t\t\tconst previewFailure = getMergePreviewFailure(raw, targetSha);\n\t\t\treturn {\n\t\t\t\tcapability:\n\t\t\t\t\tpreviewFailure === undefined\n\t\t\t\t\t\t? { kind: 'available', strategies: strategies }\n\t\t\t\t\t\t: { kind: 'unavailable', reason: previewFailure },\n\t\t\t\ttargetSha: targetSha,\n\t\t\t};\n\t\t} catch (ex) {\n\t\t\treturn { capability: { kind: 'unavailable', reason: toAzurePullRequestWriteFailure(ex).reason } };\n\t\t}\n\t}\n\n\tprivate readCompletionRefs(\n\t\tpullRequest: AzureWrittenPullRequest,\n\t): Promise<[string | undefined, string | undefined]> {\n\t\treturn Promise.all([this.readRef(pullRequest.sourceRef), this.readRef(pullRequest.targetRef)]);\n\t}\n\n\tprivate get supportedStrategies(): AzurePullRequestMergeStrategy[] {\n\t\treturn this.apiVersion === '5.0' ? ['noFastForward', 'squash'] : mergeStrategies;\n\t}\n\n\tprivate async getAllowedStrategies(ref: string): Promise<AzurePullRequestMergeStrategy[]> {\n\t\tconst query = new URLSearchParams({\n\t\t\t'api-version': this.repository.server == null ? '7.1' : '5.0-preview.1',\n\t\t\trepositoryId: this.repository.repositoryId,\n\t\t\trefName: ref,\n\t\t\tpolicyType: mergeStrategyPolicyId,\n\t\t});\n\t\tlet strategies = this.supportedStrategies.slice();\n\t\tfor await (const policies of this.readPages<MergePolicy>(`${this.gitApiUrl}/policy/configurations`, query)) {\n\t\t\tfor (const policy of policies) {\n\t\t\t\tif (policy.isEnabled === true && policy.isDeleted !== true && policy.isBlocking === true) {\n\t\t\t\t\tstrategies = strategies.filter(strategy => allowsStrategy(policy, strategy));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn strategies;\n\t}\n\n\tprivate async readRef(ref: string): Promise<string | undefined> {\n\t\tconst query = new URLSearchParams({ 'api-version': this.apiVersion, filter: ref.slice('refs/'.length) });\n\t\tfor await (const refs of this.readPages<{ name: string; objectId: string }>(`${this.repoUrl}/refs`, query)) {\n\t\t\tconst match = refs.find(row => row.name === ref);\n\t\t\tif (match != null) return isCommitSha(match.objectId) ? match.objectId : undefined;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate async *readPages<T>(url: string, query: URLSearchParams): AsyncGenerator<T[]> {\n\t\tconst seen = new Set<string>();\n\t\twhile (true) {\n\t\t\tconst { body, headers } = await this.request<{ value?: T[] }>({\n\t\t\t\turl: `${url}?${query.toString()}`,\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t\tif (!Array.isArray(body?.value)) throw new AzurePullRequestWriteError('unknown');\n\n\t\t\tyield body.value;\n\n\t\t\tconst next = headers['x-ms-continuationtoken'];\n\t\t\tif (!next) return;\n\t\t\tif (seen.has(next)) throw new AzurePullRequestWriteError('unknown');\n\n\t\t\tseen.add(next);\n\t\t\tquery.set('continuationToken', next);\n\t\t}\n\t}\n\n\tprivate async readPullRequest(\n\t\tnumber: number,\n\t): Promise<{ raw: AzurePullRequest; pullRequest: AzureWrittenPullRequest }> {\n\t\tconst { body: raw } = await this.request<AzurePullRequest>({\n\t\t\turl: this.pullRequestUrl(number),\n\t\t\theaders: this.headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tconst snapshot = this.toPullRequestSnapshot(raw, number);\n\t\tconst { state } = snapshot;\n\t\tif (state === undefined) {\n\t\t\tthrow new AzurePullRequestWriteError(getReportedMergeFailure(raw.mergeStatus) ?? 'unknown');\n\t\t}\n\t\treturn { raw: raw, pullRequest: { ...snapshot, state: state } };\n\t}\n\n\tprivate pullRequestUrl(number?: number): string {\n\t\treturn `${this.repoUrl}/pullrequests${number === undefined ? '' : `/${number}`}?api-version=${this.apiVersion}`;\n\t}\n\n\tprivate toPullRequestSnapshot(raw: AzurePullRequest, number?: number): PullRequestSnapshot {\n\t\tif (\n\t\t\t!sameIdentifier(raw?.repository?.id, this.repository.repositoryId) ||\n\t\t\t!sameIdentifier(raw.repository.project?.id, this.repository.projectId) ||\n\t\t\t(number !== undefined && raw.pullRequestId !== number)\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('not-found');\n\t\t}\n\n\t\tif (\n\t\t\t!isPositiveInt32(raw.pullRequestId) ||\n\t\t\t(raw.status !== 'active' && raw.status !== 'abandoned' && raw.status !== 'completed') ||\n\t\t\ttypeof raw.title !== 'string' ||\n\t\t\t(raw.description != null && typeof raw.description !== 'string') ||\n\t\t\t!isBranchRef(raw.sourceRefName) ||\n\t\t\t!isBranchRef(raw.targetRefName)\n\t\t) {\n\t\t\tthrow new AzurePullRequestWriteError('unknown');\n\t\t}\n\n\t\tconst sourceSha = raw.lastMergeSourceCommit?.commitId;\n\t\tconst targetSha = raw.lastMergeTargetCommit?.commitId;\n\t\tlet state: PullRequestSnapshot['state'] = raw.status;\n\t\tif (state === 'completed' && raw.mergeStatus !== 'succeeded') {\n\t\t\tstate = raw.mergeStatus === 'queued' ? 'active' : undefined;\n\t\t}\n\t\treturn {\n\t\t\trepository: this.repository,\n\t\t\tnumber: raw.pullRequestId,\n\t\t\turl: getAzurePullRequestWebUrl(\n\t\t\t\t{\n\t\t\t\t\tpullRequestId: raw.pullRequestId,\n\t\t\t\t\trepository: {\n\t\t\t\t\t\t...raw.repository,\n\t\t\t\t\t\tname: this.repository.repositoryName,\n\t\t\t\t\t\tproject: { id: this.repository.projectId, name: this.repository.projectName },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tthis.baseUrl,\n\t\t\t\tthis.repository.organization,\n\t\t\t),\n\t\t\ttitle: raw.title,\n\t\t\tdescription: raw.description ?? '',\n\t\t\tstate: state,\n\t\t\tsourceRef: raw.sourceRefName,\n\t\t\ttargetRef: raw.targetRefName,\n\t\t\tsourceSha: isCommitSha(sourceSha) ? sourceSha : undefined,\n\t\t\ttargetSha: isCommitSha(targetSha) ? targetSha : undefined,\n\t\t};\n\t}\n\n\tprivate async save(options: WriteOptions, body: object): Promise<AzurePullRequestWriteResult> {\n\t\tif (!(await this.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\t\tconst create = options.action === 'create';\n\t\tconst number = create ? undefined : options.number;\n\t\tlet raw: AzurePullRequest;\n\t\ttry {\n\t\t\t({ body: raw } = await this.request<AzurePullRequest>({\n\t\t\t\turl: this.pullRequestUrl(number),\n\t\t\t\tmethod: create ? 'POST' : 'PATCH',\n\t\t\t\theaders: { ...this.headers, 'Content-Type': 'application/json' },\n\t\t\t\tbody: JSON.stringify(body),\n\t\t\t\tredirect: 'error',\n\t\t\t}));\n\t\t} catch (ex) {\n\t\t\treturn toAzurePullRequestWriteFailure(ex, { complete: options.action === 'complete' });\n\t\t}\n\n\t\tlet snapshot: PullRequestSnapshot;\n\t\ttry {\n\t\t\tsnapshot = this.toPullRequestSnapshot(raw, number);\n\t\t} catch {\n\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\n\t\treturn this.getReceipt(options, raw, snapshot);\n\t}\n\n\tprivate getReceipt(\n\t\toptions: WriteOptions,\n\t\traw: AzurePullRequest,\n\t\tsnapshot: PullRequestSnapshot,\n\t): AzurePullRequestWriteResult {\n\t\tconst { state, sourceRef, targetRef } = snapshot;\n\t\tlet status: WriteStatus | undefined;\n\t\tswitch (options.action) {\n\t\t\tcase 'create':\n\t\t\t\tif (state === 'active' && sourceRef === options.sourceRef && targetRef === options.targetRef) {\n\t\t\t\t\tstatus = 'created';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'edit':\n\t\t\t\tif (\n\t\t\t\t\t(options.title === undefined || snapshot.title === options.title) &&\n\t\t\t\t\t(options.description === undefined || snapshot.description === options.description)\n\t\t\t\t) {\n\t\t\t\t\tstatus = 'updated';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'abandon':\n\t\t\t\tif (state === 'abandoned') {\n\t\t\t\t\tstatus = 'abandoned';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'reactivate':\n\t\t\t\tif (state === 'active') {\n\t\t\t\t\tstatus = 'reactivated';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'complete': {\n\t\t\t\tif (sourceRef !== options.expectedSourceRef || targetRef !== options.expectedTargetRef) break;\n\n\t\t\t\tconst failure = getReportedMergeFailure(raw.mergeStatus);\n\t\t\t\tif (failure != null) return { ok: false, reason: failure };\n\n\t\t\t\tif (state === 'active' && raw.mergeStatus === 'queued') {\n\t\t\t\t\tstatus = 'pending';\n\t\t\t\t} else if (state === 'completed') {\n\t\t\t\t\tstatus = 'completed';\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn status === undefined || state === undefined\n\t\t\t? { ok: false, reason: 'outcome-unknown' }\n\t\t\t: { ok: true, status: status, pullRequest: { ...snapshot, state: state } };\n\t}\n}\n"],"mappings":";;;;;;AA0BA,MAAM,eAAe;AACrB,MAAM,kBAAkB;AACxB,MAAM,wBAAwB;AAC9B,MAAM,mBAAmB;CACxB,eAAe;CACf,QAAQ;CACR,QAAQ;CACR,aAAa;AACd;AACA,MAAM,kBAAmD;CAAC;CAAiB;CAAU;CAAU;AAAa;AAkB5G,SAAS,cAAc,OAAiC;CACvD,OAAO,kBAAkB,KAAK,KAAK,UAAU,OAAO,UAAU,QAAQ,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,SAAS,IAAI;AACnH;AAEA,SAAS,YAAY,KAA6B;CACjD,OACC,OAAO,QAAQ,YACf,IAAI,WAAW,eAAe,KAC9B,IAAI,SAAS,MACb,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,MAAK,cAAa,aAAa,OAAO,YAAe,SAAS,SAAS,CAAC,KAClF,CAAC,IAAI,SAAS,IAAI,KAClB,CAAC,IAAI,SAAS,IAAI,KAClB,CAAC,IAAI,SAAS,GAAG,KACjB,IAAI,MAAM,GAAG,CAAC,CAAC,OAAM,SAAQ,KAAK,SAAS,KAAK,CAAC,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,SAAS,OAAO,CAAC;AAElG;AAEA,SAAgB,wBACf,SACU;CACV,IAAI,QAAQ,eAAe,uBAC1B,OAAO,qBAAqB,OAAO,KAAK,cAAc,QAAQ,UAAU;CAGzE,QACE,QAAQ,eAAe,KAAA,KAAa,QAAQ,eAAe,kBAC5D,kBAAkB,QAAQ,YAAY,KACtC,OAAO,QAAQ,iBAAiB,YAChC,wBAAwB,KAAK,QAAQ,YAAY,KACjD,cAAc,QAAQ,OAAO,KAC7B,cAAc,QAAQ,UAAU,MAC/B,QAAQ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,QAAhB;GACC,KAAK;IACJ,IAAI,UAAU,YAAY,cAAc,QAAQ,aAAa,cAAc,QAAQ,WAClF,SAAS;IAEV;GACD,KAAK;IACJ,KACE,QAAQ,UAAU,KAAA,KAAa,SAAS,UAAU,QAAQ,WAC1D,QAAQ,gBAAgB,KAAA,KAAa,SAAS,gBAAgB,QAAQ,cAEvE,SAAS;IAEV;GACD,KAAK;IACJ,IAAI,UAAU,aACb,SAAS;IAEV;GACD,KAAK;IACJ,IAAI,UAAU,UACb,SAAS;IAEV;GACD,KAAK,YAAY;IAChB,IAAI,cAAc,QAAQ,qBAAqB,cAAc,QAAQ,mBAAmB;IAExF,MAAM,UAAU,wBAAwB,IAAI,WAAW;IACvD,IAAI,WAAW,MAAM,OAAO;KAAE,IAAI;KAAO,QAAQ;IAAQ;IAEzD,IAAI,UAAU,YAAY,IAAI,gBAAgB,UAC7C,SAAS;SACH,IAAI,UAAU,aACpB,SAAS;IAEV;GACD;EACD;EAEA,OAAO,WAAW,KAAA,KAAa,UAAU,KAAA,IACtC;GAAE,IAAI;GAAO,QAAQ;EAAkB,IACvC;GAAE,IAAI;GAAc;GAAQ,aAAa;IAAE,GAAG;IAAiB;GAAM;EAAE;CAC3E;AACD"}
@@ -1,7 +1,8 @@
1
1
  import "../constants.js";
2
2
  import { AnonymousResponseError, UnexpectedHtmlResponseError, getProviderResponseBodyMessage } from "./providerErrors.js";
3
3
  import { isAzureCloudDomain } from "./metadata.js";
4
- import { isAzureGuid, isAzureIdentifier } from "./azure/writeIdentity.js";
4
+ import { isWriteIdentifier } from "./utils/writeInputs.js";
5
+ import { isAzureGuid } from "./azure/writeIdentity.js";
5
6
  //#region ../plus/integrations/src/providers/azureWorkItemWriteErrors.ts
6
7
  function isServerUrl(value) {
7
8
  if (typeof value !== "string") return false;
@@ -14,9 +15,9 @@ function isServerUrl(value) {
14
15
  }
15
16
  }
16
17
  function isWorkItemWriteScope(options) {
17
- if (!isAzureIdentifier(options.connectionId) || !isAzureGuid(options.organizationId) || !isAzureGuid(options.projectId) || options.expectedAccountId !== void 0 && !isAzureIdentifier(options.expectedAccountId)) return false;
18
+ if (!isWriteIdentifier(options.connectionId) || !isAzureGuid(options.organizationId) || !isAzureGuid(options.projectId) || options.expectedAccountId !== void 0 && !isWriteIdentifier(options.expectedAccountId)) return false;
18
19
  if (options.providerId === "azureDevOps") return typeof options.organizationName === "string" && /^[a-z0-9][a-z0-9-]*$/i.test(options.organizationName);
19
- return isAzureIdentifier(options.organizationName) && options.organizationName !== "." && options.organizationName !== ".." && !/[/\\]/.test(options.organizationName) && (options.domain === void 0 || isAzureIdentifier(options.domain)) && isServerUrl(options.baseUrl) && isServerUrl(options.collectionUrl);
20
+ return isWriteIdentifier(options.organizationName) && options.organizationName !== "." && options.organizationName !== ".." && !/[/\\]/.test(options.organizationName) && (options.domain === void 0 || isWriteIdentifier(options.domain)) && isServerUrl(options.baseUrl) && isServerUrl(options.collectionUrl);
20
21
  }
21
22
  function isSameAzureRoute(actual, expected) {
22
23
  const normalize = (value) => {
@@ -1 +1 @@
1
- {"version":3,"file":"azureWorkItemWriteErrors.js","names":[],"sources":["../../../../../plus/integrations/src/providers/azureWorkItemWriteErrors.ts"],"sourcesContent":["import { GitCloudHostIntegrationId } from '../constants.js';\nimport type { IssueTrackerWriteFailure } from '../models/issueTrackerWrites.js';\nimport type { WorkItemWriteField, WorkItemWriteScope } from '../models/workItemWrites.js';\nimport { isAzureGuid, isAzureIdentifier } from './azure/writeIdentity.js';\nimport { isAzureCloudDomain } from './metadata.js';\nimport {\n\tAnonymousResponseError,\n\tgetProviderResponseBodyMessage,\n\tUnexpectedHtmlResponseError,\n} from './providerErrors.js';\n\nfunction isServerUrl(value: unknown): value is string {\n\tif (typeof value !== 'string') return false;\n\n\ttry {\n\t\tconst url = new URL(value);\n\t\tconst host = url.hostname.replace(/\\.+$/, '').toLowerCase();\n\t\treturn (\n\t\t\t(url.protocol === 'https:' || url.protocol === 'http:') &&\n\t\t\t!url.username &&\n\t\t\t!url.password &&\n\t\t\t!isAzureCloudDomain(host) &&\n\t\t\t!host.endsWith('.dev.azure.com')\n\t\t);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function isWorkItemWriteScope(options: WorkItemWriteScope): boolean {\n\tif (\n\t\t!isAzureIdentifier(options.connectionId) ||\n\t\t!isAzureGuid(options.organizationId) ||\n\t\t!isAzureGuid(options.projectId) ||\n\t\t(options.expectedAccountId !== undefined && !isAzureIdentifier(options.expectedAccountId))\n\t) {\n\t\treturn false;\n\t}\n\tif (options.providerId === GitCloudHostIntegrationId.AzureDevOps) {\n\t\treturn typeof options.organizationName === 'string' && /^[a-z0-9][a-z0-9-]*$/i.test(options.organizationName);\n\t}\n\n\treturn (\n\t\tisAzureIdentifier(options.organizationName) &&\n\t\toptions.organizationName !== '.' &&\n\t\toptions.organizationName !== '..' &&\n\t\t!/[/\\\\]/.test(options.organizationName) &&\n\t\t(options.domain === undefined || isAzureIdentifier(options.domain)) &&\n\t\tisServerUrl(options.baseUrl) &&\n\t\tisServerUrl(options.collectionUrl)\n\t);\n}\n\nexport function isSameAzureRoute(actual: string, expected: string): boolean {\n\tconst normalize = (value: string) => {\n\t\tconst url = new URL(value);\n\t\tif (url.search || url.hash) return undefined;\n\n\t\treturn `${url.protocol}//${url.host}${url.pathname.replace(/\\/+$/, '')}`.toLowerCase();\n\t};\n\ttry {\n\t\tconst left = normalize(actual);\n\t\treturn left != null && left === normalize(expected);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport class WorkItemWriteError extends Error {\n\tconstructor(\n\t\treadonly reason: IssueTrackerWriteFailure['reason'],\n\t\treadonly fieldErrors?: Readonly<Record<string, string>>,\n\t) {\n\t\tsuper(reason);\n\t}\n}\n\nexport class WorkItemWriteNotDispatchedError extends WorkItemWriteError {\n\tconstructor() {\n\t\tsuper('no-connection');\n\t}\n}\n\nfunction getRuleErrors(body: unknown, fields: readonly WorkItemWriteField[]) {\n\tconst data = body as\n\t\t| {\n\t\t\t\truleValidationErrors?: unknown;\n\t\t\t\tcustomProperties?: { ruleValidationErrors?: unknown; RuleValidationErrors?: unknown };\n\t\t }\n\t\t| undefined;\n\tconst rows =\n\t\tdata?.ruleValidationErrors ??\n\t\tdata?.customProperties?.ruleValidationErrors ??\n\t\tdata?.customProperties?.RuleValidationErrors;\n\tconst message = getProviderResponseBodyMessage(body);\n\tconst messages = new Set<string>();\n\tconst fieldErrors = new Map<string, string>();\n\tif (message) {\n\t\tmessages.add(message);\n\t}\n\n\tif (Array.isArray(rows)) {\n\t\tfor (const row of rows) {\n\t\t\tconst error = row as { fieldReferenceName?: unknown; errorMessage?: unknown } | null;\n\t\t\tif (typeof error?.errorMessage !== 'string') continue;\n\n\t\t\tmessages.add(error.errorMessage);\n\t\t\tif (typeof error.fieldReferenceName === 'string') {\n\t\t\t\tfieldErrors.set(error.fieldReferenceName, error.errorMessage);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst fieldName = /TF401320:\\s*Rule Error for field (.+?)\\.\\s+Error code:/i.exec(message ?? '')?.[1];\n\tif (fieldName != null) {\n\t\tconst matches = fields.filter(field => field.name === fieldName || field.referenceName === fieldName);\n\t\tif (matches.length === 1 && message && !fieldErrors.has(matches[0].referenceName)) {\n\t\t\tfieldErrors.set(matches[0].referenceName, message);\n\t\t}\n\t}\n\treturn {\n\t\t...(messages.size && { messages: [...messages] }),\n\t\t...(fieldErrors.size && { fieldErrors: Object.fromEntries(fieldErrors) }),\n\t};\n}\n\nexport function toWorkItemWriteFailure(\n\tex: unknown,\n\tdispatched?: { fields: readonly WorkItemWriteField[] },\n): IssueTrackerWriteFailure {\n\tif (ex instanceof WorkItemWriteError && dispatched == null) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\treason: ex.reason,\n\t\t\tmutationDispatched: false,\n\t\t\t...(ex.fieldErrors && { fieldErrors: ex.fieldErrors }),\n\t\t};\n\t}\n\n\tif (dispatched == null && (UnexpectedHtmlResponseError.is(ex) || AnonymousResponseError.is(ex))) {\n\t\treturn { ok: false, reason: 'no-connection', mutationDispatched: false };\n\t}\n\n\tconst response = (\n\t\tex as\n\t\t\t| {\n\t\t\t\t\tresponse?: { status?: number; body?: unknown; headers?: Record<string, string> };\n\t\t\t }\n\t\t\t| undefined\n\t)?.response;\n\tconst status = response?.status;\n\tconst body = response?.body;\n\tconst type = (body as { typeKey?: unknown } | undefined)?.typeKey;\n\tconst message = getProviderResponseBodyMessage(body) ?? '';\n\tlet reason: IssueTrackerWriteFailure['reason'];\n\tswitch (status) {\n\t\tcase 400:\n\t\tcase 413:\n\t\tcase 422:\n\t\t\treason = type === 'WorkItemRevisionMismatchException' ? 'conflict' : 'invalid-input';\n\t\t\tbreak;\n\t\tcase 401:\n\t\tcase 403:\n\t\t\tif (\n\t\t\t\t/\\binsufficient[_ -]scope\\b|scope does not match|\\bvso\\.work_write\\b/i.test(\n\t\t\t\t\t`${response?.headers?.['www-authenticate'] ?? ''} ${message}`,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treason = 'insufficient-scope';\n\t\t\t} else {\n\t\t\t\treason = status === 401 && dispatched == null ? 'no-connection' : 'forbidden';\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 404:\n\t\t\treason = 'not-found';\n\t\t\tbreak;\n\t\tcase 409:\n\t\tcase 412:\n\t\t\treason = 'conflict';\n\t\t\tbreak;\n\t\tcase 429:\n\t\t\treason = 'rate-limit';\n\t\t\tbreak;\n\t\tdefault:\n\t\t\treason = 'unknown';\n\t}\n\n\treturn {\n\t\tok: false,\n\t\treason: reason,\n\t\t...(dispatched == null && { mutationDispatched: false }),\n\t\t...(dispatched != null && reason === 'unknown' && { applied: 'maybe' }),\n\t\t...(reason === 'invalid-input' && getRuleErrors(body, dispatched?.fields ?? [])),\n\t};\n}\n"],"mappings":";;;;;AAWA,SAAS,YAAY,OAAiC;CACrD,IAAI,OAAO,UAAU,UAAU,OAAO;CAEtC,IAAI;EACH,MAAM,MAAM,IAAI,IAAI,KAAK;EACzB,MAAM,OAA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,EAAE,KAAK,uBAAuB,GAAG,EAAE,IAC5F,OAAO;EAAE,IAAI;EAAO,QAAQ;EAAiB,oBAAoB;CAAM;CAGxE,MAAM,WACL,IAKE;CACH,MAAM,SAAS,UAAU;CACzB,MAAM,OAAO,UAAU;CACvB,MAAM,OAAQ,MAA4C;CAC1D,MAAM,UAAU,+BAA+B,IAAI,KAAK;CACxD,IAAI;CACJ,QAAQ,QAAR;EACC,KAAK;EACL,KAAK;EACL,KAAK;GACJ,SAAS,SAAS,sCAAsC,aAAa;GACrE;EACD,KAAK;EACL,KAAK;GACJ,IACC,uEAAuE,KACtE,GAAG,UAAU,UAAU,uBAAuB,GAAG,GAAG,SACrD,GAEA,SAAS;QAET,SAAS,WAAW,OAAO,cAAc,OAAO,kBAAkB;GAEnE;EACD,KAAK;GACJ,SAAS;GACT;EACD,KAAK;EACL,KAAK;GACJ,SAAS;GACT;EACD,KAAK;GACJ,SAAS;GACT;EACD,SACC,SAAS;CACX;CAEA,OAAO;EACN,IAAI;EACI;EACR,GAAI,cAAc,QAAQ,EAAE,oBAAoB,MAAM;EACtD,GAAI,cAAc,QAAQ,WAAW,aAAa,EAAE,SAAS,QAAQ;EACrE,GAAI,WAAW,mBAAmB,cAAc,MAAM,YAAY,UAAU,CAAC,CAAC;CAC/E;AACD"}
1
+ {"version":3,"file":"azureWorkItemWriteErrors.js","names":[],"sources":["../../../../../plus/integrations/src/providers/azureWorkItemWriteErrors.ts"],"sourcesContent":["import { GitCloudHostIntegrationId } from '../constants.js';\nimport type { IssueTrackerWriteFailure } from '../models/issueTrackerWrites.js';\nimport type { WorkItemWriteField, WorkItemWriteScope } from '../models/workItemWrites.js';\nimport { isAzureGuid } from './azure/writeIdentity.js';\nimport { isAzureCloudDomain } from './metadata.js';\nimport {\n\tAnonymousResponseError,\n\tgetProviderResponseBodyMessage,\n\tUnexpectedHtmlResponseError,\n} from './providerErrors.js';\nimport { isWriteIdentifier } from './utils/writeInputs.js';\n\nfunction isServerUrl(value: unknown): value is string {\n\tif (typeof value !== 'string') return false;\n\n\ttry {\n\t\tconst url = new URL(value);\n\t\tconst host = url.hostname.replace(/\\.+$/, '').toLowerCase();\n\t\treturn (\n\t\t\t(url.protocol === 'https:' || url.protocol === 'http:') &&\n\t\t\t!url.username &&\n\t\t\t!url.password &&\n\t\t\t!isAzureCloudDomain(host) &&\n\t\t\t!host.endsWith('.dev.azure.com')\n\t\t);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function isWorkItemWriteScope(options: WorkItemWriteScope): boolean {\n\tif (\n\t\t!isWriteIdentifier(options.connectionId) ||\n\t\t!isAzureGuid(options.organizationId) ||\n\t\t!isAzureGuid(options.projectId) ||\n\t\t(options.expectedAccountId !== undefined && !isWriteIdentifier(options.expectedAccountId))\n\t) {\n\t\treturn false;\n\t}\n\tif (options.providerId === GitCloudHostIntegrationId.AzureDevOps) {\n\t\treturn typeof options.organizationName === 'string' && /^[a-z0-9][a-z0-9-]*$/i.test(options.organizationName);\n\t}\n\n\treturn (\n\t\tisWriteIdentifier(options.organizationName) &&\n\t\toptions.organizationName !== '.' &&\n\t\toptions.organizationName !== '..' &&\n\t\t!/[/\\\\]/.test(options.organizationName) &&\n\t\t(options.domain === undefined || isWriteIdentifier(options.domain)) &&\n\t\tisServerUrl(options.baseUrl) &&\n\t\tisServerUrl(options.collectionUrl)\n\t);\n}\n\nexport function isSameAzureRoute(actual: string, expected: string): boolean {\n\tconst normalize = (value: string) => {\n\t\tconst url = new URL(value);\n\t\tif (url.search || url.hash) return undefined;\n\n\t\treturn `${url.protocol}//${url.host}${url.pathname.replace(/\\/+$/, '')}`.toLowerCase();\n\t};\n\ttry {\n\t\tconst left = normalize(actual);\n\t\treturn left != null && left === normalize(expected);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport class WorkItemWriteError extends Error {\n\tconstructor(\n\t\treadonly reason: IssueTrackerWriteFailure['reason'],\n\t\treadonly fieldErrors?: Readonly<Record<string, string>>,\n\t) {\n\t\tsuper(reason);\n\t}\n}\n\nexport class WorkItemWriteNotDispatchedError extends WorkItemWriteError {\n\tconstructor() {\n\t\tsuper('no-connection');\n\t}\n}\n\nfunction getRuleErrors(body: unknown, fields: readonly WorkItemWriteField[]) {\n\tconst data = body as\n\t\t| {\n\t\t\t\truleValidationErrors?: unknown;\n\t\t\t\tcustomProperties?: { ruleValidationErrors?: unknown; RuleValidationErrors?: unknown };\n\t\t }\n\t\t| undefined;\n\tconst rows =\n\t\tdata?.ruleValidationErrors ??\n\t\tdata?.customProperties?.ruleValidationErrors ??\n\t\tdata?.customProperties?.RuleValidationErrors;\n\tconst message = getProviderResponseBodyMessage(body);\n\tconst messages = new Set<string>();\n\tconst fieldErrors = new Map<string, string>();\n\tif (message) {\n\t\tmessages.add(message);\n\t}\n\n\tif (Array.isArray(rows)) {\n\t\tfor (const row of rows) {\n\t\t\tconst error = row as { fieldReferenceName?: unknown; errorMessage?: unknown } | null;\n\t\t\tif (typeof error?.errorMessage !== 'string') continue;\n\n\t\t\tmessages.add(error.errorMessage);\n\t\t\tif (typeof error.fieldReferenceName === 'string') {\n\t\t\t\tfieldErrors.set(error.fieldReferenceName, error.errorMessage);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst fieldName = /TF401320:\\s*Rule Error for field (.+?)\\.\\s+Error code:/i.exec(message ?? '')?.[1];\n\tif (fieldName != null) {\n\t\tconst matches = fields.filter(field => field.name === fieldName || field.referenceName === fieldName);\n\t\tif (matches.length === 1 && message && !fieldErrors.has(matches[0].referenceName)) {\n\t\t\tfieldErrors.set(matches[0].referenceName, message);\n\t\t}\n\t}\n\treturn {\n\t\t...(messages.size && { messages: [...messages] }),\n\t\t...(fieldErrors.size && { fieldErrors: Object.fromEntries(fieldErrors) }),\n\t};\n}\n\nexport function toWorkItemWriteFailure(\n\tex: unknown,\n\tdispatched?: { fields: readonly WorkItemWriteField[] },\n): IssueTrackerWriteFailure {\n\tif (ex instanceof WorkItemWriteError && dispatched == null) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\treason: ex.reason,\n\t\t\tmutationDispatched: false,\n\t\t\t...(ex.fieldErrors && { fieldErrors: ex.fieldErrors }),\n\t\t};\n\t}\n\n\tif (dispatched == null && (UnexpectedHtmlResponseError.is(ex) || AnonymousResponseError.is(ex))) {\n\t\treturn { ok: false, reason: 'no-connection', mutationDispatched: false };\n\t}\n\n\tconst response = (\n\t\tex as\n\t\t\t| {\n\t\t\t\t\tresponse?: { status?: number; body?: unknown; headers?: Record<string, string> };\n\t\t\t }\n\t\t\t| undefined\n\t)?.response;\n\tconst status = response?.status;\n\tconst body = response?.body;\n\tconst type = (body as { typeKey?: unknown } | undefined)?.typeKey;\n\tconst message = getProviderResponseBodyMessage(body) ?? '';\n\tlet reason: IssueTrackerWriteFailure['reason'];\n\tswitch (status) {\n\t\tcase 400:\n\t\tcase 413:\n\t\tcase 422:\n\t\t\treason = type === 'WorkItemRevisionMismatchException' ? 'conflict' : 'invalid-input';\n\t\t\tbreak;\n\t\tcase 401:\n\t\tcase 403:\n\t\t\tif (\n\t\t\t\t/\\binsufficient[_ -]scope\\b|scope does not match|\\bvso\\.work_write\\b/i.test(\n\t\t\t\t\t`${response?.headers?.['www-authenticate'] ?? ''} ${message}`,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treason = 'insufficient-scope';\n\t\t\t} else {\n\t\t\t\treason = status === 401 && dispatched == null ? 'no-connection' : 'forbidden';\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 404:\n\t\t\treason = 'not-found';\n\t\t\tbreak;\n\t\tcase 409:\n\t\tcase 412:\n\t\t\treason = 'conflict';\n\t\t\tbreak;\n\t\tcase 429:\n\t\t\treason = 'rate-limit';\n\t\t\tbreak;\n\t\tdefault:\n\t\t\treason = 'unknown';\n\t}\n\n\treturn {\n\t\tok: false,\n\t\treason: reason,\n\t\t...(dispatched == null && { mutationDispatched: false }),\n\t\t...(dispatched != null && reason === 'unknown' && { applied: 'maybe' }),\n\t\t...(reason === 'invalid-input' && getRu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C3B,IAAI,cAAc,sBAAsB,cAAc,MACrD,OAAO;EACN,IAAI;EACJ,QAAQ,GAAG;EACX,oBAAoB;EACpB,GAAI,GAAG,eAAe,EAAE,aAAa,GAAG,YAAY;CACrD;CAGD,IAAI,cAAc,SAAS,4BAA4B,GAAG,EAAE,KAAK,uBAAuB,GAAG,EAAE,IAC5F,OAAO;EAAE,IAAI;EAAO,QAAQ;EAAiB,oBAAoB;CAAM;CAGxE,MAAM,WACL,IAKE;CACH,MAAM,SAAS,UAAU;CACzB,MAAM,OAAO,UAAU;CACvB,MAAM,OAAQ,MAA4C;CAC1D,MAAM,UAAU,+BAA+B,IAAI,KAAK;CACxD,IAAI;CACJ,QAAQ,QAAR;EACC,KAAK;EACL,KAAK;EACL,KAAK;GACJ,SAAS,SAAS,sCAAsC,aAAa;GACrE;EACD,KAAK;EACL,KAAK;GACJ,IACC,uEAAuE,KACtE,GAAG,UAAU,UAAU,uBAAuB,GAAG,GAAG,SACrD,GAEA,SAAS;QAET,SAAS,WAAW,OAAO,cAAc,OAAO,kBAAkB;GAEnE;EACD,KAAK;GACJ,SAAS;GACT;EACD,KAAK;EACL,KAAK;GACJ,SAAS;GACT;EACD,KAAK;GACJ,SAAS;GACT;EACD,SACC,SAAS;CACX;CAEA,OAAO;EACN,IAAI;EACI;EACR,GAAI,cAAc,QAAQ,EAAE,oBAAoB,MAAM;EACtD,GAAI,cAAc,QAAQ,WAAW,aAAa,EAAE,SAAS,QAAQ;EACrE,GAAI,WAAW,mBAAmB,cAAc,MAAM,YAAY,UAAU,CAAC,CAAC;CAC/E;AACD"}
@@ -1,5 +1,6 @@
1
1
  import { encodeAzurePathSegment } from "./azure/models.js";
2
- import { getAzureWriteOrganizations, getAzureWriteProfile, isAzureGuid, isAzureIdentifier, isAzurePositiveInt, sameAzureIdentifier, verifyAzureServerCollection } from "./azure/writeIdentity.js";
2
+ import { isPositiveInt32, isWriteIdentifier, sameIdentifier } from "./utils/writeInputs.js";
3
+ import { getAzureWriteOrganizations, getAzureWriteProfile, isAzureGuid, verifyAzureServerCollection } from "./azure/writeIdentity.js";
3
4
  import { WorkItemWriteError, WorkItemWriteNotDispatchedError, toWorkItemWriteFailure } from "./azureWorkItemWriteErrors.js";
4
5
  import { getAzureWorkItemBodyField, getAzureWorkItemTransitionTargets, isAzureProjectPathField, isAzureTestArtifact, toAzureWorkItemWriteFields } from "./azure/workItemWriteMetadata.js";
5
6
  //#region ../plus/integrations/src/providers/azureWorkItemWrites.ts
@@ -8,12 +9,12 @@ function isSameId(actual, id) {
8
9
  return actual === id || actual === String(id);
9
10
  }
10
11
  function isDeletedItem(item, id) {
11
- if (item == null || !isSameId(item.id, id) || !isAzureIdentifier(item.project)) return false;
12
+ if (item == null || !isSameId(item.id, id) || !isWriteIdentifier(item.project)) return false;
12
13
  return item.code == null || item.code === 0 || typeof item.code === "number" && item.code >= 200 && item.code < 300;
13
14
  }
14
15
  function getDeletedRevision(item, id) {
15
16
  const resource = item.resource;
16
- return resource != null && isSameId(resource.id, id) && isAzurePositiveInt(resource.rev) ? resource.rev : void 0;
17
+ return resource != null && isSameId(resource.id, id) && isPositiveInt32(resource.rev) ? resource.rev : void 0;
17
18
  }
18
19
  const azureDeletedDate = /^(\d{1,2})\/(\d{1,2})\/([12]\d{3}) (\d{1,2}):([0-5]\d):([0-5]\d) (AM|PM)$/;
19
20
  function toDeletedAt(value) {
@@ -30,13 +31,13 @@ function readValues(body) {
30
31
  return body.value;
31
32
  }
32
33
  function assertExistingAddress(address) {
33
- if (!isAzurePositiveInt(address.workItemId)) throw new WorkItemWriteError("invalid-input");
34
+ if (!isPositiveInt32(address.workItemId)) throw new WorkItemWriteError("invalid-input");
34
35
  }
35
36
  function assertMutationIdentity(expectedAccountId) {
36
- if (!isAzureIdentifier(expectedAccountId)) throw new WorkItemWriteError("invalid-input");
37
+ if (!isWriteIdentifier(expectedAccountId)) throw new WorkItemWriteError("invalid-input");
37
38
  }
38
39
  function assertSameRevision(item, expectedRevision) {
39
- if (!isAzurePositiveInt(expectedRevision)) throw new WorkItemWriteError("invalid-input");
40
+ if (!isPositiveInt32(expectedRevision)) throw new WorkItemWriteError("invalid-input");
40
41
  if (item.rev !== expectedRevision) throw new WorkItemWriteError("conflict");
41
42
  }
42
43
  function isJsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
@@ -94,7 +95,7 @@ async function readProject(request, headers, collectionUrl, projectId, apiVersio
94
95
  headers,
95
96
  redirect: "error"
96
97
  });
97
- if (!sameAzureIdentifier(project?.id, projectId) || !isAzureIdentifier(project?.name)) throw new WorkItemWriteError("not-found");
98
+ if (!sameIdentifier(project?.id, projectId) || !isWriteIdentifier(project?.name)) throw new WorkItemWriteError("not-found");
98
99
  return {
99
100
  id: project.id,
100
101
  name: project.name
@@ -111,10 +112,10 @@ var AzureWorkItemWriter = class AzureWorkItemWriter {
111
112
  static async connect(request, credential, options, isSessionCurrent) {
112
113
  const { body: profile } = await getAzureWriteProfile(request, credential.accessToken);
113
114
  const accountId = profile?.id;
114
- if (!isAzureIdentifier(accountId) || options.expectedAccountId !== void 0 && !sameAzureIdentifier(accountId, options.expectedAccountId)) throw new WorkItemWriteError("no-connection");
115
+ if (!isWriteIdentifier(accountId) || options.expectedAccountId !== void 0 && !sameIdentifier(accountId, options.expectedAccountId)) throw new WorkItemWriteError("no-connection");
115
116
  const headers = { Authorization: credential.authorization };
116
117
  const { body: accounts } = await getAzureWriteOrganizations(request, credential.authorization, accountId);
117
- const organization = readValues(accounts).find((account) => sameAzureIdentifier(account.accountId, options.organizationId) && sameAzureIdentifier(account.accountName, options.organizationName));
118
+ const organization = readValues(accounts).find((account) => sameIdentifier(account.accountId, options.organizationId) && sameIdentifier(account.accountName, options.organizationName));
118
119
  if (organization == null) throw new WorkItemWriteError("not-found");
119
120
  const organizationUrl = `https://dev.azure.com/${encodeAzurePathSegment(organization.accountName)}`;
120
121
  const project = await readProject(request, headers, organizationUrl, options.projectId, "7.1");
@@ -166,7 +167,7 @@ var AzureWorkItemWriter = class AzureWorkItemWriter {
166
167
  }
167
168
  async getCreateOptions(options) {
168
169
  if (options.workItemType === void 0) {
169
- const enabled = readValues(await this.read("/workitemtypes")).filter((type) => isAzureIdentifier(type.name) && !type.isDisabled);
170
+ const enabled = readValues(await this.read("/workitemtypes")).filter((type) => isWriteIdentifier(type.name) && !type.isDisabled);
170
171
  return {
171
172
  ok: true,
172
173
  ...this.context,
@@ -286,8 +287,8 @@ var AzureWorkItemWriter = class AzureWorkItemWriter {
286
287
  ...revision !== void 0 && { revision },
287
288
  ...deletedAt !== void 0 && { deletedAt }
288
289
  };
289
- const project = sameAzureIdentifier(deleted.project, isAzureGuid(deleted.project) ? this.context.project.id : this.context.project.name) ? this.context.project : await this.findProject(deleted.project);
290
- if (sameAzureIdentifier(project.id, this.context.project.id) && revision === expectedRevision + 1) return {
290
+ const project = sameIdentifier(deleted.project, isAzureGuid(deleted.project) ? this.context.project.id : this.context.project.name) ? this.context.project : await this.findProject(deleted.project);
291
+ if (sameIdentifier(project.id, this.context.project.id) && revision === expectedRevision + 1) return {
291
292
  ok: true,
292
293
  ...this.context,
293
294
  issue,
@@ -312,7 +313,7 @@ var AzureWorkItemWriter = class AzureWorkItemWriter {
312
313
  async findProject(nameOrId) {
313
314
  try {
314
315
  const project = await this.readOrganization(`/projects/${encodeAzurePathSegment(nameOrId)}`);
315
- if (isAzureGuid(project?.id) && isAzureIdentifier(project.name) && (sameAzureIdentifier(project.name, nameOrId) || sameAzureIdentifier(project.id, nameOrId))) return {
316
+ if (isAzureGuid(project?.id) && isWriteIdentifier(project.name) && (sameIdentifier(project.name, nameOrId) || sameIdentifier(project.id, nameOrId))) return {
316
317
  id: project.id,
317
318
  name: project.name
318
319
  };
@@ -336,8 +337,8 @@ var AzureWorkItemWriter = class AzureWorkItemWriter {
336
337
  reason: "unsupported"
337
338
  };
338
339
  try {
339
- const bit = readValues(await this.readOrganization(`/securitynamespaces/${projectSecurityNamespaceId}`)).find((namespace) => sameAzureIdentifier(namespace?.namespaceId, projectSecurityNamespaceId))?.actions?.find((action) => action?.name === "WORK_ITEM_DELETE")?.bit;
340
- if (!isAzurePositiveInt(bit)) return { allowed: "unknown" };
340
+ const bit = readValues(await this.readOrganization(`/securitynamespaces/${projectSecurityNamespaceId}`)).find((namespace) => sameIdentifier(namespace?.namespaceId, projectSecurityNamespaceId))?.actions?.find((action) => action?.name === "WORK_ITEM_DELETE")?.bit;
341
+ if (!isPositiveInt32(bit)) return { allowed: "unknown" };
341
342
  const [allowed, ...rest] = readValues(await this.readOrganization(`/permissions/${projectSecurityNamespaceId}/${bit}`, {
342
343
  tokens: `$PROJECT:vstfs:///Classification/TeamProject/${this.context.project.id}`,
343
344
  alwaysAllowAdministrators: "false"
@@ -352,17 +353,17 @@ var AzureWorkItemWriter = class AzureWorkItemWriter {
352
353
  }
353
354
  }
354
355
  async getMetadata(name) {
355
- if (!isAzureIdentifier(name) || name === "." || name === ".." || /[/\\]/.test(name)) throw new WorkItemWriteError("invalid-input");
356
+ if (!isWriteIdentifier(name) || name === "." || name === ".." || /[/\\]/.test(name)) throw new WorkItemWriteError("invalid-input");
356
357
  const path = `/workitemtypes/${encodeAzurePathSegment(name)}`;
357
358
  const [type, typeFields, definitions] = await Promise.all([
358
359
  this.read(path),
359
360
  this.read(`${path}/fields`, { $expand: "All" }),
360
361
  this.read("/fields")
361
362
  ]);
362
- if (!sameAzureIdentifier(type?.name, name) || !isAzureIdentifier(type?.referenceName)) throw new WorkItemWriteError("unknown");
363
+ if (!sameIdentifier(type?.name, name) || !isWriteIdentifier(type?.referenceName)) throw new WorkItemWriteError("unknown");
363
364
  if (type.transitions == null || typeof type.transitions !== "object" || Array.isArray(type.transitions)) throw new WorkItemWriteError("unknown");
364
365
  const states = Array.isArray(type.states) && type.states.length !== 0 ? type.states : readValues(await this.read(`${path}/states`, { "api-version": await this.getStatesApiVersion() }));
365
- if (states.some((state) => !isAzureIdentifier(state?.name) || !isAzureIdentifier(state.category))) throw new WorkItemWriteError("unknown");
366
+ if (states.some((state) => !isWriteIdentifier(state?.name) || !isWriteIdentifier(state.category))) throw new WorkItemWriteError("unknown");
366
367
  const catalog = readValues(definitions);
367
368
  return {
368
369
  type,
@@ -382,17 +383,17 @@ var AzureWorkItemWriter = class AzureWorkItemWriter {
382
383
  return data;
383
384
  }
384
385
  isInProject(item) {
385
- return sameAzureIdentifier(item?.fields?.["System.TeamProject"], this.context.project.name);
386
+ return sameIdentifier(item?.fields?.["System.TeamProject"], this.context.project.name);
386
387
  }
387
388
  itemType(item) {
388
389
  const type = item.fields["System.WorkItemType"];
389
- if (!isAzureIdentifier(type)) throw new WorkItemWriteError("unknown");
390
+ if (!isWriteIdentifier(type)) throw new WorkItemWriteError("unknown");
390
391
  return type;
391
392
  }
392
393
  getReceipt(item, metadata) {
393
394
  const title = item.fields["System.Title"];
394
395
  const state = metadata.states.find((candidate) => candidate.name === item.fields["System.State"]);
395
- if (!isAzurePositiveInt(item.id) || !isAzurePositiveInt(item.rev) || typeof title !== "string" || state == null || this.itemType(item) !== metadata.type.name) throw new WorkItemWriteError("unknown");
396
+ if (!isPositiveInt32(item.id) || !isPositiveInt32(item.rev) || typeof title !== "string" || state == null || this.itemType(item) !== metadata.type.name) throw new WorkItemWriteError("unknown");
396
397
  return {
397
398
  id: item.id,
398
399
  revision: item.rev,