@gitkraken/core-gitlens 0.45.0 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/CHANGELOG.md +35 -1
  2. package/dist/git/models/remote.js +2 -2
  3. package/dist/git/models/remote.js.map +1 -1
  4. package/dist/git/remotes/matcher.js +25 -3
  5. package/dist/git/remotes/matcher.js.map +1 -1
  6. package/dist/git/utils/branchLanded.utils.d.ts +7 -0
  7. package/dist/git/utils/branchLanded.utils.js +10 -1
  8. package/dist/git/utils/branchLanded.utils.js.map +1 -1
  9. package/dist/git/utils/remote.utils.d.ts +1 -0
  10. package/dist/git/utils/remote.utils.js +14 -5
  11. package/dist/git/utils/remote.utils.js.map +1 -1
  12. package/dist/git-cli/parsers/logParser.js +227 -468
  13. package/dist/git-cli/parsers/logParser.js.map +1 -1
  14. package/dist/git-cli/parsers/refParser.js +4 -4
  15. package/dist/git-cli/parsers/refParser.js.map +1 -1
  16. package/dist/git-cli/providers/branches.d.ts +5 -0
  17. package/dist/git-cli/providers/branches.js +25 -21
  18. package/dist/git-cli/providers/branches.js.map +1 -1
  19. package/dist/git-cli/providers/config.js +2 -2
  20. package/dist/git-cli/providers/pausedOperations.js +2 -2
  21. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  22. package/dist/git-cli/providers/staging.js +1 -1
  23. package/dist/ipc/discovery.js +1 -1
  24. package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
  25. package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
  26. package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
  27. package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.d.ts +31 -0
  28. package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.js +166 -0
  29. package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.js.map +1 -0
  30. package/dist/plus/git-github/api/github.d.ts +13 -5
  31. package/dist/plus/git-github/api/github.js +53 -13
  32. package/dist/plus/git-github/api/github.js.map +1 -1
  33. package/dist/plus/git-github/api/issueWrites.d.ts +7 -1
  34. package/dist/plus/git-github/api/issueWrites.js +62 -32
  35. package/dist/plus/git-github/api/issueWrites.js.map +1 -1
  36. package/dist/plus/git-github/api/pullRequestWrites.d.ts +7 -3
  37. package/dist/plus/git-github/api/pullRequestWrites.js +120 -67
  38. package/dist/plus/git-github/api/pullRequestWrites.js.map +1 -1
  39. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.d.ts +44 -0
  40. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +199 -0
  41. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -0
  42. package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +7 -0
  43. package/dist/plus/integrations/authentication/configuredIntegrationService.js +53 -7
  44. package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
  45. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.d.ts +2 -38
  46. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js +0 -199
  47. package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +4 -2
  48. package/dist/plus/integrations/authentication/integrationAuthenticationService.js +12 -1
  49. package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
  50. package/dist/plus/integrations/authentication/models.d.ts +0 -1
  51. package/dist/plus/integrations/authentication/models.js +1 -2
  52. package/dist/plus/integrations/authentication/models.js.map +1 -1
  53. package/dist/plus/integrations/constants.d.ts +0 -10
  54. package/dist/plus/integrations/constants.js +1 -95
  55. package/dist/plus/integrations/constants.js.map +1 -1
  56. package/dist/plus/integrations/context.d.ts +17 -17
  57. package/dist/plus/integrations/index.d.ts +44 -25
  58. package/dist/plus/integrations/index.js +41 -8
  59. package/dist/plus/integrations/index.js.map +1 -1
  60. package/dist/plus/integrations/integrationService.d.ts +24 -24
  61. package/dist/plus/integrations/integrationService.js +125 -34
  62. package/dist/plus/integrations/integrationService.js.map +1 -1
  63. package/dist/plus/integrations/lite.js +1 -1
  64. package/dist/plus/integrations/lite.js.map +1 -1
  65. package/dist/plus/integrations/manager.d.ts +81 -21
  66. package/dist/plus/integrations/models/actionablePullRequest.d.ts +213 -0
  67. package/dist/plus/integrations/models/actionablePullRequest.js +25 -0
  68. package/dist/plus/integrations/models/actionablePullRequest.js.map +1 -0
  69. package/dist/plus/integrations/models/gitHostIntegration.d.ts +13 -46
  70. package/dist/plus/integrations/models/gitHostIntegration.js +22 -8
  71. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  72. package/dist/plus/integrations/models/integration.d.ts +11 -175
  73. package/dist/plus/integrations/models/integration.js +22 -76
  74. package/dist/plus/integrations/models/integration.js.map +1 -1
  75. package/dist/plus/integrations/models/issueTrackerWrites.d.ts +128 -0
  76. package/dist/plus/integrations/models/issueTrackerWrites.js +0 -0
  77. package/dist/plus/integrations/models/issuesIntegration.d.ts +9 -5
  78. package/dist/plus/integrations/models/issuesIntegration.js +5 -3
  79. package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
  80. package/dist/plus/integrations/models/publicIntegration.d.ts +257 -0
  81. package/dist/plus/integrations/models/publicIntegration.js +21 -0
  82. package/dist/plus/integrations/models/publicIntegration.js.map +1 -0
  83. package/dist/plus/integrations/providerFilters.d.ts +58 -0
  84. package/dist/plus/integrations/providerFilters.js.map +1 -1
  85. package/dist/plus/integrations/providers/actionablePullRequests.d.ts +19 -0
  86. package/dist/plus/integrations/providers/actionablePullRequests.js +32 -0
  87. package/dist/plus/integrations/providers/actionablePullRequests.js.map +1 -0
  88. package/dist/plus/integrations/providers/apiClients.d.ts +1 -2
  89. package/dist/plus/integrations/providers/apiClients.js.map +1 -1
  90. package/dist/plus/integrations/providers/asana.d.ts +3 -2
  91. package/dist/plus/integrations/providers/asana.js +2 -1
  92. package/dist/plus/integrations/providers/asana.js.map +1 -1
  93. package/dist/plus/integrations/providers/azure/azure.d.ts +1 -1
  94. package/dist/plus/integrations/providers/azure/azure.js +1 -1
  95. package/dist/plus/integrations/providers/azure/azure.utils.d.ts +10 -3
  96. package/dist/plus/integrations/providers/azure/azure.utils.js +5 -1
  97. package/dist/plus/integrations/providers/azure/azure.utils.js.map +1 -1
  98. package/dist/plus/integrations/providers/azure/models.d.ts +1 -5
  99. package/dist/plus/integrations/providers/azure/models.js +1 -1
  100. package/dist/plus/integrations/providers/azure/models.js.map +1 -1
  101. package/dist/plus/integrations/providers/azureDevOps.d.ts +8 -5
  102. package/dist/plus/integrations/providers/azureDevOps.js +2 -1
  103. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  104. package/dist/plus/integrations/providers/azureDevOpsServer.d.ts +5 -4
  105. package/dist/plus/integrations/providers/azureDevOpsServer.js +3 -1
  106. package/dist/plus/integrations/providers/azureDevOpsServer.js.map +1 -1
  107. package/dist/plus/integrations/providers/bitbucket/bitbucket.d.ts +2 -2
  108. package/dist/plus/integrations/providers/bitbucket/bitbucket.js.map +1 -1
  109. package/dist/plus/integrations/providers/bitbucket/models.d.ts +1 -1
  110. package/dist/plus/integrations/providers/bitbucket/models.js.map +1 -1
  111. package/dist/plus/integrations/providers/bitbucket-server.d.ts +5 -4
  112. package/dist/plus/integrations/providers/bitbucket-server.js +2 -1
  113. package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
  114. package/dist/plus/integrations/providers/bitbucket.d.ts +4 -3
  115. package/dist/plus/integrations/providers/bitbucket.js +2 -1
  116. package/dist/plus/integrations/providers/bitbucket.js.map +1 -1
  117. package/dist/plus/integrations/providers/github/github.d.ts +0 -1
  118. package/dist/plus/integrations/providers/github/github.js +1 -1
  119. package/dist/plus/integrations/providers/github/github.js.map +1 -1
  120. package/dist/plus/integrations/providers/github.d.ts +29 -11
  121. package/dist/plus/integrations/providers/github.js +195 -78
  122. package/dist/plus/integrations/providers/github.js.map +1 -1
  123. package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +2 -2
  124. package/dist/plus/integrations/providers/gitlab/gitlab.js +1 -2
  125. package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
  126. package/dist/plus/integrations/providers/gitlab/gitlab.utils.d.ts +14 -1
  127. package/dist/plus/integrations/providers/gitlab/gitlab.utils.js.map +1 -1
  128. package/dist/plus/integrations/providers/gitlab/models.d.ts +2 -10
  129. package/dist/plus/integrations/providers/gitlab/models.js.map +1 -1
  130. package/dist/plus/integrations/providers/gitlab.d.ts +7 -5
  131. package/dist/plus/integrations/providers/gitlab.js +2 -1
  132. package/dist/plus/integrations/providers/gitlab.js.map +1 -1
  133. package/dist/plus/integrations/providers/issueSorts.d.ts +1 -0
  134. package/dist/plus/integrations/providers/jira-server.d.ts +4 -4
  135. package/dist/plus/integrations/providers/jira-server.js +3 -2
  136. package/dist/plus/integrations/providers/jira-server.js.map +1 -1
  137. package/dist/plus/integrations/providers/jira.d.ts +3 -3
  138. package/dist/plus/integrations/providers/jira.js +4 -3
  139. package/dist/plus/integrations/providers/jira.js.map +1 -1
  140. package/dist/plus/integrations/providers/jiraIssueByKey.d.ts +3 -1
  141. package/dist/plus/integrations/providers/jiraIssueByKey.js +1 -1
  142. package/dist/plus/integrations/providers/jiraIssueByKey.js.map +1 -1
  143. package/dist/plus/integrations/providers/jiraIssueWriteErrors.d.ts +10 -0
  144. package/dist/plus/integrations/providers/jiraIssueWriteErrors.js +68 -0
  145. package/dist/plus/integrations/providers/jiraIssueWriteErrors.js.map +1 -0
  146. package/dist/plus/integrations/providers/jiraIssueWrites.d.ts +40 -0
  147. package/dist/plus/integrations/providers/jiraIssueWrites.js +397 -0
  148. package/dist/plus/integrations/providers/jiraIssueWrites.js.map +1 -0
  149. package/dist/plus/integrations/providers/linear.d.ts +4 -3
  150. package/dist/plus/integrations/providers/linear.js +3 -2
  151. package/dist/plus/integrations/providers/linear.js.map +1 -1
  152. package/dist/plus/integrations/providers/linearIssuesEtag.d.ts +1 -1
  153. package/dist/plus/integrations/providers/linearIssuesEtag.js +1 -1
  154. package/dist/plus/integrations/providers/linearIssuesEtag.js.map +1 -1
  155. package/dist/plus/integrations/providers/metadata.d.ts +136 -0
  156. package/dist/plus/integrations/providers/metadata.js +513 -0
  157. package/dist/plus/integrations/providers/metadata.js.map +1 -0
  158. package/dist/plus/integrations/providers/models.d.ts +10 -206
  159. package/dist/plus/integrations/providers/models.js +8 -539
  160. package/dist/plus/integrations/providers/models.js.map +1 -1
  161. package/dist/plus/integrations/providers/providersApi.d.ts +7 -3
  162. package/dist/plus/integrations/providers/providersApi.js +23 -11
  163. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  164. package/dist/plus/integrations/providers/trello.d.ts +1 -1
  165. package/dist/plus/integrations/providers/trello.js +2 -1
  166. package/dist/plus/integrations/providers/trello.js.map +1 -1
  167. package/dist/plus/integrations/providers/utils/providerPaging.d.ts +2 -0
  168. package/dist/plus/integrations/providers/utils/providerPaging.js +3 -2
  169. package/dist/plus/integrations/providers/utils/providerPaging.js.map +1 -1
  170. package/dist/plus/integrations/providers/utils.d.ts +119 -10
  171. package/dist/plus/integrations/providers/utils.js +57 -3
  172. package/dist/plus/integrations/providers/utils.js.map +1 -1
  173. package/dist/plus/integrations/reads/autolinks.d.ts +1 -1
  174. package/dist/plus/integrations/reads/autolinks.js +1 -1
  175. package/dist/plus/integrations/reads/autolinks.js.map +1 -1
  176. package/dist/plus/integrations/reads/broaden.d.ts +1 -1
  177. package/dist/plus/integrations/reads/broaden.js +3 -2
  178. package/dist/plus/integrations/reads/broaden.js.map +1 -1
  179. package/dist/plus/integrations/reads/context.d.ts +1 -1
  180. package/dist/plus/integrations/reads/counts.d.ts +1 -88
  181. package/dist/plus/integrations/reads/counts.js +4 -2
  182. package/dist/plus/integrations/reads/counts.js.map +1 -1
  183. package/dist/plus/integrations/reads/currentAccount.d.ts +1 -18
  184. package/dist/plus/integrations/reads/currentAccount.js.map +1 -1
  185. package/dist/plus/integrations/reads/drains.d.ts +4 -3
  186. package/dist/plus/integrations/reads/drains.js +1 -1
  187. package/dist/plus/integrations/reads/drains.js.map +1 -1
  188. package/dist/plus/integrations/reads/etag.d.ts +174 -3
  189. package/dist/plus/integrations/reads/etag.js +69 -14
  190. package/dist/plus/integrations/reads/etag.js.map +1 -1
  191. package/dist/plus/integrations/reads/filters.d.ts +3 -61
  192. package/dist/plus/integrations/reads/filters.js +1 -1
  193. package/dist/plus/integrations/reads/filters.js.map +1 -1
  194. package/dist/plus/integrations/reads/hierarchy.d.ts +1 -1
  195. package/dist/plus/integrations/reads/hierarchy.js +4 -2
  196. package/dist/plus/integrations/reads/hierarchy.js.map +1 -1
  197. package/dist/plus/integrations/reads/issueBatch.d.ts +2 -102
  198. package/dist/plus/integrations/reads/issueBatch.js +3 -4
  199. package/dist/plus/integrations/reads/issueBatch.js.map +1 -1
  200. package/dist/plus/integrations/reads/issueTracker.d.ts +1 -1
  201. package/dist/plus/integrations/reads/issueTracker.js +4 -3
  202. package/dist/plus/integrations/reads/issueTracker.js.map +1 -1
  203. package/dist/plus/integrations/reads/issues.d.ts +1 -1
  204. package/dist/plus/integrations/reads/issues.js +4 -2
  205. package/dist/plus/integrations/reads/issues.js.map +1 -1
  206. package/dist/plus/integrations/reads/paging.d.ts +1 -1
  207. package/dist/plus/integrations/reads/paging.js +1 -1
  208. package/dist/plus/integrations/reads/paging.js.map +1 -1
  209. package/dist/plus/integrations/reads/pullRequestActivity.d.ts +1 -24
  210. package/dist/plus/integrations/reads/pullRequestActivity.js +2 -1
  211. package/dist/plus/integrations/reads/pullRequestActivity.js.map +1 -1
  212. package/dist/plus/integrations/reads/pullRequestBatch.d.ts +2 -56
  213. package/dist/plus/integrations/reads/pullRequestBatch.js +23 -3
  214. package/dist/plus/integrations/reads/pullRequestBatch.js.map +1 -1
  215. package/dist/plus/integrations/reads/pullRequestBranches.d.ts +1 -47
  216. package/dist/plus/integrations/reads/pullRequestBranches.js +2 -1
  217. package/dist/plus/integrations/reads/pullRequestBranches.js.map +1 -1
  218. package/dist/plus/integrations/reads/pullRequestCheckLogs.d.ts +1 -15
  219. package/dist/plus/integrations/reads/pullRequestCheckLogs.js +2 -1
  220. package/dist/plus/integrations/reads/pullRequestCheckLogs.js.map +1 -1
  221. package/dist/plus/integrations/reads/pullRequests.js +4 -2
  222. package/dist/plus/integrations/reads/pullRequests.js.map +1 -1
  223. package/dist/plus/integrations/reads/pullRequestsForCommits.d.ts +1 -16
  224. package/dist/plus/integrations/reads/pullRequestsForCommits.js +2 -1
  225. package/dist/plus/integrations/reads/pullRequestsForCommits.js.map +1 -1
  226. package/dist/plus/integrations/reads/resolveRepository.js +10 -5
  227. package/dist/plus/integrations/reads/resolveRepository.js.map +1 -1
  228. package/dist/plus/integrations/reads/searchIssues.js +2 -1
  229. package/dist/plus/integrations/reads/searchIssues.js.map +1 -1
  230. package/dist/plus/integrations/reads/searchPullRequests.js +2 -1
  231. package/dist/plus/integrations/reads/searchPullRequests.js.map +1 -1
  232. package/dist/plus/integrations/reads/sweeps.d.ts +1 -1
  233. package/dist/plus/integrations/reads/sweeps.js +3 -2
  234. package/dist/plus/integrations/reads/sweeps.js.map +1 -1
  235. package/dist/plus/integrations/reads/warnings.d.ts +1 -1
  236. package/dist/plus/integrations/reads/warnings.js +1 -1
  237. package/dist/plus/integrations/reads/warnings.js.map +1 -1
  238. package/dist/plus/integrations/results.d.ts +324 -2
  239. package/dist/plus/integrations/results.js.map +1 -1
  240. package/dist/plus/integrations/telemetry.d.ts +0 -10
  241. package/dist/plus/integrations/telemetry.js +0 -11
  242. package/dist/plus/integrations/utils/domain.utils.d.ts +1 -0
  243. package/dist/plus/integrations/utils/domain.utils.js +10 -2
  244. package/dist/plus/integrations/utils/domain.utils.js.map +1 -1
  245. package/dist/plus/integrations/utils/integration.utils.d.ts +2 -6
  246. package/dist/plus/integrations/utils/integration.utils.js +8 -9
  247. package/dist/plus/integrations/utils/integration.utils.js.map +1 -1
  248. package/dist/utils/env/node/exec.js +2 -2
  249. package/dist/utils/keys/chord.d.ts +13 -2
  250. package/dist/utils/keys/chord.js +76 -17
  251. package/dist/utils/keys/chord.js.map +1 -1
  252. package/dist/utils/keys/keybinding.d.ts +12 -0
  253. package/dist/utils/keys/keybinding.js +52 -2
  254. package/dist/utils/keys/keybinding.js.map +1 -1
  255. package/dist/utils/markdown.d.ts +21 -0
  256. package/dist/utils/markdown.js +33 -1
  257. package/dist/utils/markdown.js.map +1 -1
  258. package/docs/integrations.md +174 -19
  259. package/package.json +5 -1
  260. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js.map +0 -1
  261. package/dist/plus/integrations/telemetry.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"pullRequestWrites.js","names":[],"sources":["../../../../../plus/git-github/src/api/pullRequestWrites.ts"],"sourcesContent":["import { GraphqlResponseError } from '@octokit/graphql';\nimport type { RequestParameters } from '@octokit/types';\nimport { AuthenticationError, AuthenticationErrorReason, RequestNotFoundError } from '@gitlens/git/errors.js';\nimport type { PullRequestMergeMethod, PullRequestMergeQueueActionResult } from '@gitlens/git/models/pullRequest.js';\nimport { issueWriteFailure } from './issueWrites.js';\n\ntype MergeMethod = `${PullRequestMergeMethod}`;\nexport type GitHubPullRequestCreateTarget = { owner: string; repo: string };\n\nexport type GitHubPullRequestWriteTarget = GitHubPullRequestCreateTarget & { number: number; expectedNodeId: string };\nexport type GitHubPullRequestWrite =\n\t| (GitHubPullRequestCreateTarget & {\n\t\t\taction: 'create';\n\t\t\ttitle: string;\n\t\t\tbody?: string;\n\t\t\theadRef: string;\n\t\t\tbaseRef: string;\n\t\t\texpectedRepositoryId?: string;\n\t })\n\t| (GitHubPullRequestWriteTarget &\n\t\t\t(\n\t\t\t\t| { action: 'edit'; title?: string; body?: string }\n\t\t\t\t| { action: 'set-state'; state: 'open' | 'closed' }\n\t\t\t\t| ({ expectedHeadSha: string; expectedBaseRef: string } & (\n\t\t\t\t\t\t| { action: 'merge'; mergeMethod: MergeMethod }\n\t\t\t\t\t\t| { action: 'enqueue' }\n\t\t\t\t ))\n\t\t\t));\n\nexport type PullRequestWriteFailure = {\n\tok: false;\n\treason:\n\t\t| 'unsupported'\n\t\t| 'no-connection'\n\t\t| 'forbidden'\n\t\t| 'not-found'\n\t\t| 'invalid-input'\n\t\t| 'rate-limit'\n\t\t| 'blocked'\n\t\t| 'head-changed'\n\t\t| 'base-changed'\n\t\t| 'unknown'\n\t\t| 'outcome-unknown';\n};\n\nexport type PullRequestWriteSnapshot = {\n\towner: string;\n\trepo: string;\n\tnumber: number;\n\tnodeId: string;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'open' | 'closed' | 'merged';\n\tclosedAt?: string;\n\tupdatedAt?: string;\n\theadSha: string;\n\tbaseRef: string;\n};\n\nexport type PullRequestCreateCapabilityResult =\n\t| { ok: true; repositoryId: string; canCreate: boolean | undefined }\n\t| PullRequestWriteFailure;\n\ntype MergeCapability =\n\t| { kind: 'direct'; methods: MergeMethod[]; defaultMethod?: MergeMethod }\n\t| { kind: 'queue' }\n\t| { kind: 'unavailable'; reason: PullRequestWriteFailure['reason'] };\n\nexport type PullRequestWriteTargetResult =\n\t| {\n\t\t\tok: true;\n\t\t\tpullRequest: PullRequestWriteSnapshot;\n\t\t\tcapabilities: { edit: boolean; close: boolean; reopen: boolean; merge: MergeCapability };\n\t }\n\t| PullRequestWriteFailure;\n\nexport type PullRequestWriteResult =\n\t| {\n\t\t\tok: true;\n\t\t\tstatus: 'created' | 'updated' | 'closed' | 'reopened' | 'merged' | 'queued';\n\t\t\tpullRequest: PullRequestWriteSnapshot;\n\t }\n\t| PullRequestWriteFailure;\n\ntype RepositoryIdentity = {\n\tid: string;\n\towner: { login: string };\n\tname: string;\n};\n\ntype RepositoryNode = RepositoryIdentity & {\n\tisArchived: boolean;\n\tisDisabled: boolean;\n\tisLocked: boolean;\n\tviewerPermission: 'ADMIN' | 'MAINTAIN' | 'WRITE' | 'MODERATE' | 'TRIAGE' | 'READ' | null;\n};\n\ntype PullRequestNode = {\n\tid: string;\n\tnumber: number;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'OPEN' | 'CLOSED' | 'MERGED';\n\tclosedAt: string | null;\n\tmergedAt: string | null;\n\tupdatedAt: string;\n\theadRefOid: string;\n\tbaseRefName: string;\n\trepository: RepositoryIdentity;\n};\n\ntype WriteNode = PullRequestNode & {\n\t__typename: 'PullRequest';\n\tviewerCanUpdate: boolean;\n\tviewerCanClose: boolean;\n\tviewerCanReopen: boolean;\n\tisDraft: boolean;\n\tisInMergeQueue: boolean;\n\tisMergeQueueEnabled: boolean;\n\tstack: { id: string } | null;\n\tbaseRef: { id: string } | null;\n};\n\ntype MergeRepository = RepositoryNode & {\n\tmergeCommitAllowed: boolean;\n\tsquashMergeAllowed: boolean;\n\trebaseMergeAllowed: boolean;\n\tviewerDefaultMergeMethod: string;\n};\n\ntype ResolvedPullRequest = { ok: true; node: WriteNode; repository: MergeRepository };\ntype GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;\ntype BranchRule = {\n\ttype: string;\n\tparameters: { allowedMergeMethods?: readonly Uppercase<MergeMethod>[] | null } | null;\n};\n\nconst repositoryIdentity = 'id owner { login } name';\nconst repositoryFields = `${repositoryIdentity} isArchived isDisabled isLocked viewerPermission`;\nconst pullRequestFields = `\n\tid number url title body state closedAt mergedAt updatedAt headRefOid baseRefName\n\trepository { ${repositoryIdentity} }\n`;\nconst mergeMethods: readonly MergeMethod[] = ['merge', 'squash', 'rebase'];\n\nfunction isValidRepository({ owner, repo }: GitHubPullRequestCreateTarget): boolean {\n\treturn (\n\t\ttypeof owner === 'string' &&\n\t\t/^[a-z\\d_-]+$/i.test(owner) &&\n\t\ttypeof repo === 'string' &&\n\t\t/^[a-z\\d._-]+$/i.test(repo) &&\n\t\trepo !== '.' &&\n\t\trepo !== '..'\n\t);\n}\n\nfunction isValidTarget(input: GitHubPullRequestWriteTarget): boolean {\n\treturn (\n\t\tisValidRepository(input) &&\n\t\tNumber.isInteger(input.number) &&\n\t\tinput.number >= 1 &&\n\t\tinput.number <= 2147483647 &&\n\t\ttypeof input.expectedNodeId === 'string' &&\n\t\tinput.expectedNodeId.trim().length > 0\n\t);\n}\n\nfunction isBranchName(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === 'string' &&\n\t\tvalue.length > 0 &&\n\t\tvalue.trim() === value &&\n\t\t!value.includes(':') &&\n\t\t!value.startsWith('refs/') &&\n\t\t!value.startsWith('-')\n\t);\n}\n\nfunction isTitle(value: unknown): value is string {\n\treturn typeof value === 'string' && value.trim().length > 0;\n}\n\nfunction isValidWrite(input: GitHubPullRequestWrite): boolean {\n\tif (input.action === 'create') {\n\t\treturn (\n\t\t\tisValidRepository(input) &&\n\t\t\tisTitle(input.title) &&\n\t\t\t(input.body === undefined || typeof input.body === 'string') &&\n\t\t\t(input.expectedRepositoryId === undefined ||\n\t\t\t\t(typeof input.expectedRepositoryId === 'string' && input.expectedRepositoryId.trim().length > 0)) &&\n\t\t\tisBranchName(input.headRef) &&\n\t\t\tisBranchName(input.baseRef) &&\n\t\t\tinput.headRef !== input.baseRef\n\t\t);\n\t}\n\n\tif (!isValidTarget(input)) return false;\n\n\tswitch (input.action) {\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(input.title !== undefined || input.body !== undefined) &&\n\t\t\t\t(input.title === undefined || isTitle(input.title)) &&\n\t\t\t\t(input.body === undefined || typeof input.body === 'string')\n\t\t\t);\n\t\tcase 'set-state':\n\t\t\treturn input.state === 'open' || input.state === 'closed';\n\t\tcase 'merge':\n\t\tcase 'enqueue':\n\t\t\treturn (\n\t\t\t\t(input.action === 'enqueue' || mergeMethods.includes(input.mergeMethod)) &&\n\t\t\t\tisBranchName(input.expectedBaseRef) &&\n\t\t\t\ttypeof input.expectedHeadSha === 'string' &&\n\t\t\t\t/^[a-f\\d]{40}$/i.test(input.expectedHeadSha)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nexport function pullRequestWriteFailure(ex: unknown, phase?: 'write' | 'merge' | 'enqueue'): PullRequestWriteFailure {\n\tif (ex instanceof RequestNotFoundError) return { ok: false, reason: 'not-found' };\n\tif (ex instanceof AuthenticationError) {\n\t\tif (ex.reason === AuthenticationErrorReason.Forbidden) return { ok: false, reason: 'forbidden' };\n\t\treturn { ok: false, reason: 'no-connection' };\n\t}\n\n\tconst failure = issueWriteFailure(ex);\n\tif (failure.reason === 'rate-limit') return failure;\n\n\tif (phase === 'merge' || phase === 'enqueue') {\n\t\tconst error = ex instanceof GraphqlResponseError ? ex.errors?.[0] : undefined;\n\t\tif (error?.type === 'UNPROCESSABLE') {\n\t\t\tif (/\\b(?:expected head oid|head sha) does not match\\b/i.test(error.message)) {\n\t\t\t\treturn { ok: false, reason: 'head-changed' };\n\t\t\t}\n\n\t\t\treturn { ok: false, reason: 'blocked' };\n\t\t}\n\t}\n\n\treturn phase != null && failure.reason === 'unknown' ? { ok: false, reason: 'outcome-unknown' } : failure;\n}\n\nfunction hasWritePermission(repository: RepositoryNode): boolean | undefined {\n\tconst { viewerPermission } = repository;\n\treturn viewerPermission == null\n\t\t? undefined\n\t\t: viewerPermission === 'ADMIN' || viewerPermission === 'MAINTAIN' || viewerPermission === 'WRITE';\n}\n\nfunction isRepositoryWritable(repository: RepositoryNode): boolean {\n\treturn !repository.isArchived && !repository.isDisabled && !repository.isLocked;\n}\n\nfunction sameRepository(a: GitHubPullRequestCreateTarget, b: RepositoryIdentity): boolean {\n\treturn a.owner.toLowerCase() === b.owner.login.toLowerCase() && a.repo.toLowerCase() === b.name.toLowerCase();\n}\n\nfunction toSnapshot(node: PullRequestNode): PullRequestWriteSnapshot {\n\tconst closedAt = node.state === 'MERGED' ? (node.mergedAt ?? node.closedAt) : node.closedAt;\n\treturn {\n\t\towner: node.repository.owner.login,\n\t\trepo: node.repository.name,\n\t\tnumber: node.number,\n\t\tnodeId: node.id,\n\t\turl: node.url,\n\t\ttitle: node.title,\n\t\tbody: node.body,\n\t\tstate: node.state === 'OPEN' ? 'open' : node.state === 'CLOSED' ? 'closed' : 'merged',\n\t\t...(node.state !== 'OPEN' && typeof closedAt === 'string' ? { closedAt: closedAt } : {}),\n\t\t...(typeof node.updatedAt === 'string' ? { updatedAt: node.updatedAt } : {}),\n\t\theadSha: node.headRefOid,\n\t\tbaseRef: node.baseRefName,\n\t};\n}\n\nasync function resolveNode(\n\tinput: GitHubPullRequestWriteTarget,\n\tgraphql: GraphqlRequest,\n): Promise<ResolvedPullRequest | PullRequestWriteFailure> {\n\tconst { owner, repo, expectedNodeId, number } = input;\n\tconst result = await graphql<{ repository: MergeRepository | null; node: WriteNode | null }>(\n\t\t`query PullRequestWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!) {\n\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t${repositoryFields}\n\t\t\t\tmergeCommitAllowed squashMergeAllowed rebaseMergeAllowed viewerDefaultMergeMethod\n\t\t\t}\n\t\t\tnode(id: $expectedNodeId) {\n\t\t\t\t__typename\n\t\t\t\t... on PullRequest {\n\t\t\t\t\t${pullRequestFields}\n\t\t\t\t\tviewerCanUpdate viewerCanClose viewerCanReopen\n\t\t\t\t\tisDraft isInMergeQueue isMergeQueueEnabled\n\t\t\t\t\tstack { id }\n\t\t\t\t\tbaseRef { id }\n\t\t\t\t}\n\t\t\t}\n\t\t}`,\n\t\t{ owner: owner, repo: repo, expectedNodeId: expectedNodeId },\n\t);\n\tconst repository = result?.repository;\n\tconst node = result?.node;\n\tif (\n\t\trepository == null ||\n\t\t!sameRepository(input, repository) ||\n\t\tnode?.__typename !== 'PullRequest' ||\n\t\tnode.number !== number ||\n\t\tnode.repository.id !== repository.id\n\t) {\n\t\treturn { ok: false, reason: 'not-found' };\n\t}\n\n\treturn { ok: true, node: node, repository: repository };\n}\n\nasync function readBranchRules(\n\trefId: string,\n\tgraphql: GraphqlRequest,\n): Promise<{ rules: BranchRule[]; requiresLinearHistory: boolean } | undefined> {\n\ttype Response = {\n\t\tnode: {\n\t\t\tid: string;\n\t\t\trefUpdateRule: { requiresLinearHistory: boolean } | null;\n\t\t\trules: {\n\t\t\t\tnodes: (BranchRule | null)[] | null;\n\t\t\t\tpageInfo: { hasNextPage: boolean; endCursor: string | null };\n\t\t\t};\n\t\t} | null;\n\t};\n\tconst rules: BranchRule[] = [];\n\tconst seen = new Set<string>();\n\tlet requiresLinearHistory = false;\n\tlet cursor: string | undefined;\n\tfor (;;) {\n\t\tconst response = await graphql<Response>(\n\t\t\t`\n\t\t\t\tquery PullRequestBranchRules($id: ID!, $cursor: String) {\n\t\t\t\t\tnode(id: $id) {\n\t\t\t\t\t\t... on Ref {\n\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\trefUpdateRule {\n\t\t\t\t\t\t\t\trequiresLinearHistory\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\trules(first: 100, after: $cursor) {\n\t\t\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\t\t\ttype\n\t\t\t\t\t\t\t\t\tparameters {\n\t\t\t\t\t\t\t\t\t\t... on PullRequestParameters {\n\t\t\t\t\t\t\t\t\t\t\tallowedMergeMethods\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tpageInfo {\n\t\t\t\t\t\t\t\t\thasNextPage\n\t\t\t\t\t\t\t\t\tendCursor\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t`,\n\t\t\t{ id: refId, cursor: cursor },\n\t\t);\n\t\tconst ref = response?.node;\n\t\tconst page = ref?.rules;\n\t\tif (ref?.id !== refId || page?.nodes == null) return undefined;\n\n\t\trequiresLinearHistory ||= ref.refUpdateRule?.requiresLinearHistory === true;\n\n\t\tfor (const rule of page.nodes) {\n\t\t\tif (rule == null) return undefined;\n\n\t\t\trules.push(rule);\n\t\t}\n\n\t\tif (!page.pageInfo.hasNextPage) return { rules: rules, requiresLinearHistory: requiresLinearHistory };\n\n\t\tconst nextCursor = page.pageInfo.endCursor;\n\t\tif (nextCursor == null || seen.has(nextCursor)) return undefined;\n\n\t\tseen.add(nextCursor);\n\t\tcursor = nextCursor;\n\t}\n}\n\nasync function getMergeCapability(\n\t{ node, repository }: ResolvedPullRequest,\n\tgraphql: GraphqlRequest,\n): Promise<MergeCapability> {\n\tif (\n\t\t!isRepositoryWritable(repository) ||\n\t\tnode.state !== 'OPEN' ||\n\t\tnode.isDraft ||\n\t\tnode.isInMergeQueue ||\n\t\tnode.baseRef == null\n\t) {\n\t\treturn { kind: 'unavailable', reason: 'blocked' };\n\t}\n\n\tconst canWrite = hasWritePermission(repository);\n\tif (canWrite !== true) return { kind: 'unavailable', reason: canWrite === false ? 'forbidden' : 'unknown' };\n\tif (node.stack != null) return { kind: 'unavailable', reason: 'unsupported' };\n\tif (node.isMergeQueueEnabled) return { kind: 'queue' };\n\n\ttry {\n\t\tconst branch = await readBranchRules(node.baseRef.id, graphql);\n\t\tif (branch == null) return { kind: 'unavailable', reason: 'unknown' };\n\n\t\tconst { rules, requiresLinearHistory } = branch;\n\t\tif (rules.some(rule => rule.type === 'MERGE_QUEUE')) return { kind: 'queue' };\n\n\t\tconst linearHistory = requiresLinearHistory || rules.some(rule => rule.type === 'REQUIRED_LINEAR_HISTORY');\n\t\tconst methods = mergeMethods.filter(method => {\n\t\t\tconst allowed =\n\t\t\t\tmethod === 'merge'\n\t\t\t\t\t? repository.mergeCommitAllowed && !linearHistory\n\t\t\t\t\t: method === 'squash'\n\t\t\t\t\t\t? repository.squashMergeAllowed\n\t\t\t\t\t\t: repository.rebaseMergeAllowed;\n\t\t\treturn (\n\t\t\t\tallowed &&\n\t\t\t\trules.every(rule => {\n\t\t\t\t\tconst permitted = rule.type === 'PULL_REQUEST' ? rule.parameters?.allowedMergeMethods : undefined;\n\t\t\t\t\treturn permitted == null || permitted.some(allowedMethod => allowedMethod.toLowerCase() === method);\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\t\tif (methods.length === 0) return { kind: 'unavailable', reason: 'blocked' };\n\n\t\tconst preference = repository.viewerDefaultMergeMethod.toLowerCase();\n\t\tconst defaultMethod = methods.find(method => method === preference);\n\t\treturn { kind: 'direct', methods: methods, defaultMethod: defaultMethod };\n\t} catch (ex) {\n\t\treturn { kind: 'unavailable', reason: pullRequestWriteFailure(ex).reason };\n\t}\n}\n\nexport async function resolveGitHubPullRequestWriteTarget(\n\tinput: GitHubPullRequestWriteTarget,\n\tgraphql: GraphqlRequest,\n): Promise<PullRequestWriteTargetResult> {\n\tif (!isValidTarget(input)) return { ok: false, reason: 'invalid-input' };\n\n\ttry {\n\t\tconst resolved = await resolveNode(input, graphql);\n\t\tif (!resolved.ok) return resolved;\n\n\t\tconst { node, repository } = resolved;\n\t\tconst writable = isRepositoryWritable(repository);\n\t\treturn {\n\t\t\tok: true,\n\t\t\tpullRequest: toSnapshot(node),\n\t\t\tcapabilities: {\n\t\t\t\tedit: writable && node.viewerCanUpdate,\n\t\t\t\tclose: writable && node.state === 'OPEN' && node.viewerCanClose,\n\t\t\t\treopen: writable && node.state === 'CLOSED' && node.viewerCanReopen,\n\t\t\t\tmerge: await getMergeCapability(resolved, graphql),\n\t\t\t},\n\t\t};\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex);\n\t}\n}\n\nexport async function getGitHubPullRequestCreateCapability(\n\tinput: GitHubPullRequestCreateTarget,\n\tgraphql: GraphqlRequest,\n): Promise<PullRequestCreateCapabilityResult> {\n\tif (!isValidRepository(input)) return { ok: false, reason: 'invalid-input' };\n\n\ttry {\n\t\tconst result = await graphql<{ repository: RepositoryNode | null }>(\n\t\t\t`query PullRequestCreateCapability($owner: String!, $repo: String!) {\n\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t${repositoryFields}\n\t\t\t\t}\n\t\t\t}`,\n\t\t\t{ owner: input.owner, repo: input.repo },\n\t\t);\n\t\tconst repository = result?.repository;\n\t\tif (repository == null || !sameRepository(input, repository)) return { ok: false, reason: 'not-found' };\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\trepositoryId: repository.id,\n\t\t\t// A repository role only establishes read access. GitHub checks the chosen head branch and organization\n\t\t\t// membership when the pull request is created.\n\t\t\tcanCreate: isRepositoryWritable(repository) && (repository.viewerPermission == null ? undefined : true),\n\t\t};\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex);\n\t}\n}\n\ntype WriteTransport = {\n\tgraphql: GraphqlRequest;\n\tisSessionCurrent: () => Promise<boolean>;\n\tenqueue: (nodeId: string, headSha: string) => Promise<PullRequestMergeQueueActionResult>;\n};\n\nconst mutations = {\n\tcreated: ['createPullRequest', 'CreatePullRequestInput'],\n\tupdated: ['updatePullRequest', 'UpdatePullRequestInput'],\n\tclosed: ['closePullRequest', 'ClosePullRequestInput'],\n\treopened: ['reopenPullRequest', 'ReopenPullRequestInput'],\n\tmerged: ['mergePullRequest', 'MergePullRequestInput'],\n} as const;\n\nasync function sendMutation(\n\ttransport: WriteTransport,\n\tstatus: keyof typeof mutations,\n\trepositoryId: string,\n\tvalues: Record<string, string | undefined>,\n\tprevious?: PullRequestNode,\n): Promise<PullRequestWriteResult> {\n\tif (!(await transport.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\tconst [mutation, inputType] = mutations[status];\n\ttype Payload = { change: { pullRequest: PullRequestNode | null } | null };\n\tlet node: PullRequestNode | null | undefined;\n\ttry {\n\t\tconst response = await transport.graphql<Payload>(\n\t\t\t`mutation WritePullRequest($input: ${inputType}!) {\n\t\t\t\tchange: ${mutation}(input: $input) { pullRequest { ${pullRequestFields} } }\n\t\t\t}`,\n\t\t\t{ input: values },\n\t\t);\n\t\tnode = response?.change?.pullRequest;\n\t} catch (ex) {\n\t\tif (ex instanceof GraphqlResponseError) {\n\t\t\tnode = (ex.data as Payload | undefined)?.change?.pullRequest;\n\t\t\tif (node == null && ex.errors?.some(error => error.path?.[0] === 'change' && error.path.length > 1)) {\n\t\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t\t}\n\t\t}\n\n\t\tif (node == null) return pullRequestWriteFailure(ex, status === 'merged' ? 'merge' : 'write');\n\t}\n\n\tconst expectedState =\n\t\tstatus === 'created' || status === 'reopened'\n\t\t\t? 'OPEN'\n\t\t\t: status === 'closed'\n\t\t\t\t? 'CLOSED'\n\t\t\t\t: status === 'merged'\n\t\t\t\t\t? 'MERGED'\n\t\t\t\t\t: undefined;\n\tif (\n\t\tnode?.repository?.id !== repositoryId ||\n\t\t(previous != null && (node.id !== previous.id || node.number !== previous.number)) ||\n\t\t(expectedState != null && node.state !== expectedState) ||\n\t\ttypeof node.repository.owner?.login !== 'string' ||\n\t\ttypeof node.repository.name !== 'string' ||\n\t\ttypeof node.id !== 'string' ||\n\t\t!Number.isInteger(node.number) ||\n\t\ttypeof node.url !== 'string' ||\n\t\ttypeof node.title !== 'string' ||\n\t\ttypeof node.body !== 'string' ||\n\t\ttypeof node.headRefOid !== 'string' ||\n\t\ttypeof node.baseRefName !== 'string' ||\n\t\t(node.state !== 'OPEN' && node.state !== 'CLOSED' && node.state !== 'MERGED')\n\t) {\n\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t}\n\n\treturn { ok: true, status: status, pullRequest: toSnapshot(node) };\n}\n\nasync function createPullRequest(\n\tinput: Extract<GitHubPullRequestWrite, { action: 'create' }>,\n\ttransport: WriteTransport,\n): Promise<PullRequestWriteResult> {\n\ttype CreateRepository = RepositoryNode & { base: { id: string } | null; head: { id: string } | null };\n\tconst result = await transport.graphql<{ repository: CreateRepository | null }>(\n\t\t`query PullRequestCreateTarget($owner: String!, $repo: String!, $base: String!, $head: String!) {\n\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t${repositoryFields}\n\t\t\t\tbase: ref(qualifiedName: $base) { id }\n\t\t\t\thead: ref(qualifiedName: $head) { id }\n\t\t\t}\n\t\t}`,\n\t\t{\n\t\t\towner: input.owner,\n\t\t\trepo: input.repo,\n\t\t\tbase: `refs/heads/${input.baseRef}`,\n\t\t\thead: `refs/heads/${input.headRef}`,\n\t\t},\n\t);\n\tconst repository = result?.repository;\n\tif (\n\t\trepository == null ||\n\t\t!sameRepository(input, repository) ||\n\t\t(input.expectedRepositoryId != null && input.expectedRepositoryId !== repository.id)\n\t) {\n\t\treturn { ok: false, reason: 'not-found' };\n\t}\n\n\tif (!isRepositoryWritable(repository)) return { ok: false, reason: 'blocked' };\n\tif (repository.base == null || repository.head == null) return { ok: false, reason: 'invalid-input' };\n\n\treturn sendMutation(transport, 'created', repository.id, {\n\t\trepositoryId: repository.id,\n\t\tbaseRefName: input.baseRef,\n\t\theadRefName: input.headRef,\n\t\ttitle: input.title,\n\t\tbody: input.body,\n\t});\n}\n\nasync function mergePullRequest(\n\tinput: Extract<GitHubPullRequestWrite, { action: 'merge' | 'enqueue' }>,\n\tresolved: ResolvedPullRequest,\n\ttransport: WriteTransport,\n): Promise<PullRequestWriteResult> {\n\tconst { node, repository } = resolved;\n\tif (node.headRefOid.toLowerCase() !== input.expectedHeadSha.toLowerCase()) {\n\t\treturn { ok: false, reason: 'head-changed' };\n\t}\n\n\tif (node.baseRefName !== input.expectedBaseRef) return { ok: false, reason: 'base-changed' };\n\n\tconst capability = await getMergeCapability(resolved, transport.graphql);\n\tif (capability.kind === 'unavailable') return { ok: false, reason: capability.reason };\n\n\tif (input.action === 'merge') {\n\t\tif (capability.kind !== 'direct' || !capability.methods.includes(input.mergeMethod)) {\n\t\t\treturn { ok: false, reason: 'blocked' };\n\t\t}\n\n\t\treturn sendMutation(\n\t\t\ttransport,\n\t\t\t'merged',\n\t\t\trepository.id,\n\t\t\t{ pullRequestId: node.id, expectedHeadOid: node.headRefOid, mergeMethod: input.mergeMethod.toUpperCase() },\n\t\t\tnode,\n\t\t);\n\t}\n\n\tif (capability.kind !== 'queue') return { ok: false, reason: 'blocked' };\n\tif (!(await transport.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\ttry {\n\t\tconst result = await transport.enqueue(node.id, node.headRefOid);\n\t\tif (result.status === 'queued' && result.entry != null) {\n\t\t\treturn { ok: true, status: 'queued', pullRequest: toSnapshot(node) };\n\t\t}\n\n\t\tif (result.status !== 'failed') return { ok: false, reason: 'outcome-unknown' };\n\n\t\tswitch (result.reason) {\n\t\t\tcase 'permission':\n\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\tcase 'already-queued':\n\t\t\tcase 'not-allowed':\n\t\t\t\treturn { ok: false, reason: 'blocked' };\n\t\t\tcase 'head-changed':\n\t\t\tcase 'unsupported':\n\t\t\t\treturn { ok: false, reason: result.reason };\n\t\t\tdefault:\n\t\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex, 'enqueue');\n\t}\n}\n\nexport async function writeGitHubPullRequest(\n\tinput: GitHubPullRequestWrite,\n\ttransport: WriteTransport,\n): Promise<PullRequestWriteResult> {\n\tif (!isValidWrite(input)) return { ok: false, reason: 'invalid-input' };\n\n\ttry {\n\t\tif (input.action === 'create') return await createPullRequest(input, transport);\n\n\t\tconst resolved = await resolveNode(input, transport.graphql);\n\t\tif (!resolved.ok) return resolved;\n\n\t\tconst { node, repository } = resolved;\n\t\tif (!isRepositoryWritable(repository)) return { ok: false, reason: 'blocked' };\n\t\tif (input.action === 'merge' || input.action === 'enqueue') {\n\t\t\treturn await mergePullRequest(input, resolved, transport);\n\t\t}\n\n\t\tif (input.action === 'edit') {\n\t\t\tif (!node.viewerCanUpdate) return { ok: false, reason: 'forbidden' };\n\n\t\t\treturn await sendMutation(\n\t\t\t\ttransport,\n\t\t\t\t'updated',\n\t\t\t\trepository.id,\n\t\t\t\t{ pullRequestId: node.id, title: input.title, body: input.body },\n\t\t\t\tnode,\n\t\t\t);\n\t\t}\n\n\t\tconst close = input.state === 'closed';\n\t\tif (node.state !== (close ? 'OPEN' : 'CLOSED')) return { ok: false, reason: 'blocked' };\n\t\tif (close ? !node.viewerCanClose : !node.viewerCanReopen) return { ok: false, reason: 'forbidden' };\n\n\t\treturn await sendMutation(\n\t\t\ttransport,\n\t\t\tclose ? 'closed' : 'reopened',\n\t\t\trepository.id,\n\t\t\t{ pullRequestId: node.id },\n\t\t\tnode,\n\t\t);\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex);\n\t}\n}\n"],"mappings":";;;;AA2IA,MAAM,qBAAqB;AAC3B,MAAM,mBAAmB,GAAG,mBAAmB;AAC/C,MAAM,oBAAoB;;gBAEV,mBAAmB;;AAEnC,MAAM,eAAuC;CAAC;CAAS;CAAU;AAAQ;AAEzE,SAAS,kBAAkB,EAAE,OAAO,QAAgD;CACnF,OACC,OAAO,UAAU,YACjB,gBAAgB,KAAK,KAAK,KAC1B,OAAO,SAAS,YAChB,iBAAiB,KAAK,IAAI,KAC1B,SAAS,OACT,SAAS;AAEX;AAEA,SAAS,cAAc,OAA8C;CACpE,OACC,kBAAkB,KAAK,KACvB,OAAO,UAAU,MAAM,MAAM,KAC7B,MAAM,UAAU,KAChB,MAAM,UAAU,cAChB,OAAO,MAAM,mBAAmB,YAChC,MAAM,eAAe,KAAK,CAAC,CAAC,SAAS;AAEvC;AAEA,SAAS,aAAa,OAAiC;CACtD,OACC,OAAO,UAAU,YACjB,MAAM,SAAS,KACf,MAAM,KAAK,MAAM,SACjB,CAAC,MAAM,SAAS,GAAG,KACnB,CAAC,MAAM,WAAW,OAAO,KACzB,CAAC,MAAM,WAAW,GAAG;AAEvB;AAEA,SAAS,QAAQ,OAAiC;CACjD,OAAO,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,SAAS;AAC3D;AAEA,SAAS,aAAa,OAAwC;CAC7D,IAAI,MAAM,WAAW,UACpB,OACC,kBAAkB,KAAK,KACvB,QAAQ,MAAM,KAAK,MAClB,MAAM,SAAS,KAAA,KAAa,OAAO,MAAM,SAAS,cAClD,MAAM,yBAAyB,KAAA,KAC9B,OAAO,MAAM,yBAAyB,YAAY,MAAM,q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AO;GAAE,IAAI;GAAO,QAAQ;EAAU;EACtF,IAAI,QAAQ,CAAC,KAAK,iBAAiB,CAAC,KAAK,iBAAiB,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAY;EAElG,OAAO,MAAM,aACZ,WACA,QAAQ,WAAW,YACnB,WAAW,IACX,EAAE,eAAe,KAAK,GAAG,GACzB,IACD;CACD,SAAS,IAAI;EACZ,OAAO,wBAAwB,EAAE;CAClC;AACD"}
1
+ {"version":3,"file":"pullRequestWrites.js","names":[],"sources":["../../../../../plus/git-github/src/api/pullRequestWrites.ts"],"sourcesContent":["import { GraphqlResponseError } from '@octokit/graphql';\nimport { AuthenticationError, AuthenticationErrorReason, RequestNotFoundError } from '@gitlens/git/errors.js';\nimport type { PullRequestMergeMethod, PullRequestMergeQueueActionResult } from '@gitlens/git/models/pullRequest.js';\nimport type {\n\tBranchPolicy,\n\tBranchRule,\n\tEnterprisePullRequestWriteOptions,\n\tGraphqlRequest,\n} from './enterprisePullRequestMergePolicy.js';\nimport { readEnterprisePullRequestMergePolicy } from './enterprisePullRequestMergePolicy.js';\nimport { isGitHubWriteUrlOnInstallation, issueWriteFailure } from './issueWrites.js';\n\ntype MergeMethod = `${PullRequestMergeMethod}`;\nexport type GitHubPullRequestCreateTarget = { owner: string; repo: string };\n\nexport type GitHubPullRequestWriteTarget = GitHubPullRequestCreateTarget & { number: number; expectedNodeId: string };\nexport type GitHubPullRequestWrite =\n\t| (GitHubPullRequestCreateTarget & {\n\t\t\taction: 'create';\n\t\t\ttitle: string;\n\t\t\tbody?: string;\n\t\t\theadRef: string;\n\t\t\tbaseRef: string;\n\t\t\texpectedRepositoryId?: string;\n\t })\n\t| (GitHubPullRequestWriteTarget &\n\t\t\t(\n\t\t\t\t| { action: 'edit'; title?: string; body?: string }\n\t\t\t\t| { action: 'set-state'; state: 'open' | 'closed' }\n\t\t\t\t| ({ expectedHeadSha: string; expectedBaseRef: string } & (\n\t\t\t\t\t\t| { action: 'merge'; mergeMethod: MergeMethod }\n\t\t\t\t\t\t| { action: 'enqueue' }\n\t\t\t\t ))\n\t\t\t));\n\nexport type PullRequestWriteFailure = {\n\tok: false;\n\treason:\n\t\t| 'unsupported'\n\t\t| 'no-connection'\n\t\t| 'forbidden'\n\t\t| 'not-found'\n\t\t| 'invalid-input'\n\t\t| 'rate-limit'\n\t\t| 'blocked'\n\t\t| 'head-changed'\n\t\t| 'base-changed'\n\t\t| 'unknown'\n\t\t| 'outcome-unknown';\n};\n\nexport type PullRequestWriteSnapshot = {\n\t/** The installation origin for GitHub Enterprise Server pull requests. */\n\tdomain?: string;\n\towner: string;\n\trepo: string;\n\tnumber: number;\n\tnodeId: string;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'open' | 'closed' | 'merged';\n\tclosedAt?: string;\n\tupdatedAt?: string;\n\theadSha: string;\n\tbaseRef: string;\n};\n\nexport type PullRequestCreateCapabilityResult =\n\t| { ok: true; repositoryId: string; canCreate: boolean | undefined }\n\t| PullRequestWriteFailure;\n\ntype MergeCapability =\n\t| { kind: 'direct'; methods: MergeMethod[]; defaultMethod?: MergeMethod }\n\t| { kind: 'queue' }\n\t| { kind: 'unavailable'; reason: PullRequestWriteFailure['reason'] };\n\nexport type PullRequestWriteTargetResult =\n\t| {\n\t\t\tok: true;\n\t\t\tpullRequest: PullRequestWriteSnapshot;\n\t\t\tcapabilities: { edit: boolean; close: boolean; reopen: boolean; merge: MergeCapability };\n\t }\n\t| PullRequestWriteFailure;\n\nexport type PullRequestWriteResult =\n\t| {\n\t\t\tok: true;\n\t\t\tstatus: 'created' | 'updated' | 'closed' | 'reopened' | 'merged' | 'queued';\n\t\t\tpullRequest: PullRequestWriteSnapshot;\n\t\t\t/** The result is confirmed, but its snapshot belongs to a replaced or disconnected credential. */\n\t\t\tcredentialChanged?: true;\n\t }\n\t| PullRequestWriteFailure;\n\ntype RepositoryIdentity = {\n\tid: string;\n\towner: { login: string };\n\tname: string;\n};\n\ntype RepositoryNode = RepositoryIdentity & {\n\tisArchived: boolean;\n\tisDisabled: boolean;\n\tisLocked: boolean;\n\tviewerPermission: 'ADMIN' | 'MAINTAIN' | 'WRITE' | 'MODERATE' | 'TRIAGE' | 'READ' | null;\n};\n\ntype PullRequestNode = {\n\tid: string;\n\tnumber: number;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'OPEN' | 'CLOSED' | 'MERGED';\n\tclosedAt: string | null;\n\tmergedAt: string | null;\n\tupdatedAt: string;\n\theadRefOid: string;\n\theadRefName?: string;\n\tbaseRefName: string;\n\trepository: RepositoryIdentity;\n};\n\ntype WriteNode = PullRequestNode & {\n\t__typename: 'PullRequest';\n\tviewerCanUpdate: boolean;\n\tviewerCanClose: boolean;\n\tviewerCanReopen: boolean;\n\tisDraft: boolean;\n\tisInMergeQueue?: boolean;\n\tisMergeQueueEnabled?: boolean;\n\tstack?: { id: string } | null;\n\tbaseRef: { id: string } | null;\n};\n\ntype MergeRepository = RepositoryNode & {\n\tmergeCommitAllowed: boolean;\n\tsquashMergeAllowed: boolean;\n\trebaseMergeAllowed: boolean;\n\tviewerDefaultMergeMethod?: string;\n};\n\ntype ResolvedPullRequest = { ok: true; node: WriteNode; repository: MergeRepository };\n\nconst repositoryIdentity = 'id owner { login } name';\nconst repositoryFields = `${repositoryIdentity} isArchived isDisabled isLocked viewerPermission`;\nconst pullRequestFields = `\n\tid number url title body state closedAt mergedAt updatedAt headRefOid baseRefName\n\trepository { ${repositoryIdentity} }\n`;\nconst mergeMethods: readonly MergeMethod[] = ['merge', 'squash', 'rebase'];\n\nfunction isValidRepository({ owner, repo }: GitHubPullRequestCreateTarget): boolean {\n\treturn (\n\t\ttypeof owner === 'string' &&\n\t\t/^[a-z\\d_-]+$/i.test(owner) &&\n\t\ttypeof repo === 'string' &&\n\t\t/^[a-z\\d._-]+$/i.test(repo) &&\n\t\trepo !== '.' &&\n\t\trepo !== '..'\n\t);\n}\n\nfunction isValidTarget(input: GitHubPullRequestWriteTarget): boolean {\n\treturn (\n\t\tisValidRepository(input) &&\n\t\tNumber.isInteger(input.number) &&\n\t\tinput.number >= 1 &&\n\t\tinput.number <= 2147483647 &&\n\t\ttypeof input.expectedNodeId === 'string' &&\n\t\tinput.expectedNodeId.trim().length > 0\n\t);\n}\n\nfunction isBranchName(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === 'string' &&\n\t\tvalue.length > 0 &&\n\t\tvalue.trim() === value &&\n\t\t!value.includes(':') &&\n\t\t!value.startsWith('refs/') &&\n\t\t!value.startsWith('-')\n\t);\n}\n\nfunction isTitle(value: unknown): value is string {\n\treturn typeof value === 'string' && value.trim().length > 0;\n}\n\nfunction isValidWrite(input: GitHubPullRequestWrite): boolean {\n\tif (input.action === 'create') {\n\t\treturn (\n\t\t\tisValidRepository(input) &&\n\t\t\tisTitle(input.title) &&\n\t\t\t(input.body === undefined || typeof input.body === 'string') &&\n\t\t\t(input.expectedRepositoryId === undefined ||\n\t\t\t\t(typeof input.expectedRepositoryId === 'string' && input.expectedRepositoryId.trim().length > 0)) &&\n\t\t\tisBranchName(input.headRef) &&\n\t\t\tisBranchName(input.baseRef) &&\n\t\t\tinput.headRef !== input.baseRef\n\t\t);\n\t}\n\n\tif (!isValidTarget(input)) return false;\n\n\tswitch (input.action) {\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(input.title !== undefined || input.body !== undefined) &&\n\t\t\t\t(input.title === undefined || isTitle(input.title)) &&\n\t\t\t\t(input.body === undefined || typeof input.body === 'string')\n\t\t\t);\n\t\tcase 'set-state':\n\t\t\treturn input.state === 'open' || input.state === 'closed';\n\t\tcase 'merge':\n\t\tcase 'enqueue':\n\t\t\treturn (\n\t\t\t\t(input.action === 'enqueue' || mergeMethods.includes(input.mergeMethod)) &&\n\t\t\t\tisBranchName(input.expectedBaseRef) &&\n\t\t\t\ttypeof input.expectedHeadSha === 'string' &&\n\t\t\t\t/^[a-f\\d]{40}$/i.test(input.expectedHeadSha)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nexport function pullRequestWriteFailure(ex: unknown, phase?: 'write' | 'merge' | 'enqueue'): PullRequestWriteFailure {\n\tif (ex instanceof RequestNotFoundError) return { ok: false, reason: 'not-found' };\n\tif (ex instanceof AuthenticationError) {\n\t\tif (ex.reason === AuthenticationErrorReason.Forbidden) return { ok: false, reason: 'forbidden' };\n\t\treturn { ok: false, reason: 'no-connection' };\n\t}\n\n\tconst failure = issueWriteFailure(ex);\n\tif (failure.reason === 'rate-limit') return failure;\n\n\tif (phase === 'merge' || phase === 'enqueue') {\n\t\tconst error = ex instanceof GraphqlResponseError ? ex.errors?.[0] : undefined;\n\t\tif (error?.type === 'UNPROCESSABLE') {\n\t\t\tif (/\\b(?:expected head oid|head sha) does not match\\b/i.test(error.message)) {\n\t\t\t\treturn { ok: false, reason: 'head-changed' };\n\t\t\t}\n\n\t\t\treturn { ok: false, reason: 'blocked' };\n\t\t}\n\t}\n\n\treturn phase != null && failure.reason === 'unknown' ? { ok: false, reason: 'outcome-unknown' } : failure;\n}\n\nfunction hasWritePermission(repository: RepositoryNode): boolean | undefined {\n\tconst { viewerPermission } = repository;\n\treturn viewerPermission == null\n\t\t? undefined\n\t\t: viewerPermission === 'ADMIN' || viewerPermission === 'MAINTAIN' || viewerPermission === 'WRITE';\n}\n\nfunction isRepositoryWritable(repository: RepositoryNode): boolean {\n\treturn !repository.isArchived && !repository.isDisabled && !repository.isLocked;\n}\n\nfunction sameRepository(a: GitHubPullRequestCreateTarget, b: RepositoryIdentity): boolean {\n\treturn a.owner.toLowerCase() === b.owner.login.toLowerCase() && a.repo.toLowerCase() === b.name.toLowerCase();\n}\n\nfunction toSnapshot(node: PullRequestNode, origin?: string): PullRequestWriteSnapshot {\n\tconst closedAt = node.state === 'MERGED' ? (node.mergedAt ?? node.closedAt) : node.closedAt;\n\treturn {\n\t\towner: node.repository.owner.login,\n\t\trepo: node.repository.name,\n\t\tnumber: node.number,\n\t\tnodeId: node.id,\n\t\turl: node.url,\n\t\t...(origin != null && { domain: origin }),\n\t\ttitle: node.title,\n\t\tbody: node.body,\n\t\tstate: node.state === 'OPEN' ? 'open' : node.state === 'CLOSED' ? 'closed' : 'merged',\n\t\t...(node.state !== 'OPEN' && typeof closedAt === 'string' ? { closedAt: closedAt } : {}),\n\t\t...(typeof node.updatedAt === 'string' ? { updatedAt: node.updatedAt } : {}),\n\t\theadSha: node.headRefOid,\n\t\tbaseRef: node.baseRefName,\n\t};\n}\n\nasync function resolveNode(\n\tinput: GitHubPullRequestWriteTarget,\n\tgraphql: GraphqlRequest,\n\torigin?: string,\n): Promise<ResolvedPullRequest | PullRequestWriteFailure> {\n\tconst { owner, repo, expectedNodeId, number } = input;\n\tconst result = await graphql<{ repository: MergeRepository | null; node: WriteNode | null }>(\n\t\t`query PullRequestWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!) {\n\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t${repositoryFields}\n\t\t\t\tmergeCommitAllowed squashMergeAllowed rebaseMergeAllowed ${origin == null ? 'viewerDefaultMergeMethod' : ''}\n\t\t\t}\n\t\t\tnode(id: $expectedNodeId) {\n\t\t\t\t__typename\n\t\t\t\t... on PullRequest {\n\t\t\t\t\t${pullRequestFields}\n\t\t\t\t\tviewerCanUpdate viewerCanClose viewerCanReopen\n\t\t\t\t\tisDraft baseRef { id }\n\t\t\t\t\t${origin == null ? 'isInMergeQueue isMergeQueueEnabled stack { id }' : ''}\n\t\t\t\t}\n\t\t\t}\n\t\t}`,\n\t\t{ owner: owner, repo: repo, expectedNodeId: expectedNodeId },\n\t);\n\tconst repository = result?.repository;\n\tconst node = result?.node;\n\tif (\n\t\trepository == null ||\n\t\t!sameRepository(input, repository) ||\n\t\tnode?.__typename !== 'PullRequest' ||\n\t\tnode.number !== number ||\n\t\tnode.repository.id !== repository.id ||\n\t\t!sameRepository(input, node.repository) ||\n\t\t!isGitHubWriteUrlOnInstallation(node.url, origin)\n\t) {\n\t\treturn { ok: false, reason: 'not-found' };\n\t}\n\n\treturn { ok: true, node: node, repository: repository };\n}\n\nasync function readBranchRules(refId: string, graphql: GraphqlRequest): Promise<BranchPolicy | undefined> {\n\ttype Response = {\n\t\tnode: {\n\t\t\tid: string;\n\t\t\trefUpdateRule: { requiresLinearHistory: boolean } | null;\n\t\t\trules: {\n\t\t\t\tnodes: (BranchRule | null)[] | null;\n\t\t\t\tpageInfo: { hasNextPage: boolean; endCursor: string | null };\n\t\t\t};\n\t\t} | null;\n\t};\n\tconst rules: BranchRule[] = [];\n\tconst seen = new Set<string>();\n\tlet requiresLinearHistory = false;\n\tlet cursor: string | undefined;\n\tfor (;;) {\n\t\tconst response = await graphql<Response>(\n\t\t\t`\n\t\t\t\tquery PullRequestBranchRules($id: ID!, $cursor: String) {\n\t\t\t\t\tnode(id: $id) {\n\t\t\t\t\t\t... on Ref {\n\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\trefUpdateRule {\n\t\t\t\t\t\t\t\trequiresLinearHistory\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\trules(first: 100, after: $cursor) {\n\t\t\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\t\t\ttype\n\t\t\t\t\t\t\t\t\tparameters {\n\t\t\t\t\t\t\t\t\t\t... on PullRequestParameters {\n\t\t\t\t\t\t\t\t\t\t\tallowedMergeMethods\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tpageInfo {\n\t\t\t\t\t\t\t\t\thasNextPage\n\t\t\t\t\t\t\t\t\tendCursor\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t`,\n\t\t\t{ id: refId, cursor: cursor },\n\t\t);\n\t\tconst ref = response?.node;\n\t\tconst page = ref?.rules;\n\t\tif (ref?.id !== refId || page?.nodes == null) return undefined;\n\n\t\trequiresLinearHistory ||= ref.refUpdateRule?.requiresLinearHistory === true;\n\n\t\tfor (const rule of page.nodes) {\n\t\t\tif (rule == null) return undefined;\n\n\t\t\trules.push(rule);\n\t\t}\n\n\t\tif (!page.pageInfo.hasNextPage) return { rules: rules, requiresLinearHistory: requiresLinearHistory };\n\n\t\tconst nextCursor = page.pageInfo.endCursor;\n\t\tif (nextCursor == null || seen.has(nextCursor)) return undefined;\n\n\t\tseen.add(nextCursor);\n\t\tcursor = nextCursor;\n\t}\n}\n\nasync function getMergeCapability(\n\tresolved: ResolvedPullRequest,\n\tgraphql: GraphqlRequest,\n\tenterprise?: EnterprisePullRequestWriteOptions,\n): Promise<MergeCapability> {\n\tconst { node, repository } = resolved;\n\tif (\n\t\t!isRepositoryWritable(repository) ||\n\t\tnode.state !== 'OPEN' ||\n\t\tnode.isDraft ||\n\t\tnode.isInMergeQueue ||\n\t\tnode.baseRef == null\n\t) {\n\t\treturn { kind: 'unavailable', reason: 'blocked' };\n\t}\n\n\tconst canWrite = hasWritePermission(repository);\n\tif (canWrite !== true) return { kind: 'unavailable', reason: canWrite === false ? 'forbidden' : 'unknown' };\n\tif (node.stack != null) return { kind: 'unavailable', reason: 'unsupported' };\n\tif (node.isMergeQueueEnabled) return { kind: 'queue' };\n\n\ttry {\n\t\tif (enterprise != null) {\n\t\t\tconst policy = await readEnterprisePullRequestMergePolicy(\n\t\t\t\t{ id: node.id, baseRef: node.baseRefName, baseRefId: node.baseRef.id },\n\t\t\t\t{ owner: repository.owner.login, repo: repository.name },\n\t\t\t\tgraphql,\n\t\t\t\tenterprise.readBranchRules,\n\t\t\t);\n\t\t\treturn 'kind' in policy ? policy : getDirectMergeCapability(repository, policy);\n\t\t}\n\n\t\tconst policy = await readBranchRules(node.baseRef.id, graphql);\n\t\tif (policy == null) return { kind: 'unavailable', reason: 'unknown' };\n\t\tif (policy.rules.some(rule => rule.type === 'MERGE_QUEUE')) return { kind: 'queue' };\n\n\t\treturn getDirectMergeCapability(repository, policy);\n\t} catch (ex) {\n\t\treturn { kind: 'unavailable', reason: pullRequestWriteFailure(ex).reason };\n\t}\n}\n\nfunction getDirectMergeCapability(\n\trepository: MergeRepository,\n\t{ rules, requiresLinearHistory }: BranchPolicy,\n): MergeCapability {\n\tconst linearHistory = requiresLinearHistory || rules.some(rule => rule.type === 'REQUIRED_LINEAR_HISTORY');\n\tconst methods = mergeMethods.filter(method => {\n\t\tconst allowed =\n\t\t\tmethod === 'merge'\n\t\t\t\t? repository.mergeCommitAllowed && !linearHistory\n\t\t\t\t: method === 'squash'\n\t\t\t\t\t? repository.squashMergeAllowed\n\t\t\t\t\t: repository.rebaseMergeAllowed;\n\t\treturn (\n\t\t\tallowed &&\n\t\t\trules.every(rule => {\n\t\t\t\tconst permitted = rule.type === 'PULL_REQUEST' ? rule.parameters?.allowedMergeMethods : undefined;\n\t\t\t\treturn permitted == null || permitted.some(allowedMethod => allowedMethod.toLowerCase() === method);\n\t\t\t})\n\t\t);\n\t});\n\tif (methods.length === 0) return { kind: 'unavailable', reason: 'blocked' };\n\n\tconst preference = repository.viewerDefaultMergeMethod?.toLowerCase();\n\tconst defaultMethod = methods.find(method => method === preference);\n\treturn { kind: 'direct', methods: methods, defaultMethod: defaultMethod };\n}\n\nexport async function resolveGitHubPullRequestWriteTarget(\n\tinput: GitHubPullRequestWriteTarget,\n\tgraphql: GraphqlRequest,\n\tenterprise?: EnterprisePullRequestWriteOptions,\n): Promise<PullRequestWriteTargetResult> {\n\tif (!isValidTarget(input)) return { ok: false, reason: 'invalid-input' };\n\n\ttry {\n\t\tconst resolved = await resolveNode(input, graphql, enterprise?.origin);\n\t\tif (!resolved.ok) return resolved;\n\n\t\tconst { node, repository } = resolved;\n\t\tconst writable = isRepositoryWritable(repository);\n\t\treturn {\n\t\t\tok: true,\n\t\t\tpullRequest: toSnapshot(node, enterprise?.origin),\n\t\t\tcapabilities: {\n\t\t\t\tedit: writable && node.viewerCanUpdate,\n\t\t\t\tclose: writable && node.state === 'OPEN' && node.viewerCanClose,\n\t\t\t\treopen: writable && node.state === 'CLOSED' && node.viewerCanReopen,\n\t\t\t\tmerge: await getMergeCapability(resolved, graphql, enterprise),\n\t\t\t},\n\t\t};\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex);\n\t}\n}\n\nexport async function getGitHubPullRequestCreateCapability(\n\tinput: GitHubPullRequestCreateTarget,\n\tgraphql: GraphqlRequest,\n): Promise<PullRequestCreateCapabilityResult> {\n\tif (!isValidRepository(input)) return { ok: false, reason: 'invalid-input' };\n\n\ttry {\n\t\tconst result = await graphql<{ repository: RepositoryNode | null }>(\n\t\t\t`query PullRequestCreateCapability($owner: String!, $repo: String!) {\n\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t${repositoryFields}\n\t\t\t\t}\n\t\t\t}`,\n\t\t\t{ owner: input.owner, repo: input.repo },\n\t\t);\n\t\tconst repository = result?.repository;\n\t\tif (repository == null || !sameRepository(input, repository)) return { ok: false, reason: 'not-found' };\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\trepositoryId: repository.id,\n\t\t\tcanCreate: isRepositoryWritable(repository) && (repository.viewerPermission == null ? undefined : true),\n\t\t};\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex);\n\t}\n}\n\ntype WriteTransport = {\n\tgraphql: GraphqlRequest;\n\tenterprise?: EnterprisePullRequestWriteOptions;\n\tisSessionCurrent: () => Promise<boolean>;\n\tenqueue: (nodeId: string, headSha: string) => Promise<PullRequestMergeQueueActionResult>;\n};\n\nconst mutations = {\n\tcreated: ['createPullRequest', 'CreatePullRequestInput'],\n\tupdated: ['updatePullRequest', 'UpdatePullRequestInput'],\n\tclosed: ['closePullRequest', 'ClosePullRequestInput'],\n\treopened: ['reopenPullRequest', 'ReopenPullRequestInput'],\n\tmerged: ['mergePullRequest', 'MergePullRequestInput'],\n\tqueued: ['enqueuePullRequest', 'EnqueuePullRequestInput'],\n} as const;\n\nasync function sendMutation(\n\ttransport: WriteTransport,\n\tstatus: keyof typeof mutations,\n\trepository: RepositoryIdentity,\n\tvalues: Record<string, string | undefined>,\n\tprevious?: PullRequestNode,\n): Promise<PullRequestWriteResult> {\n\tif (!(await transport.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\tconst [mutation, inputType] = mutations[status];\n\tconst fields =\n\t\tstatus === 'created' && transport.enterprise?.origin != null\n\t\t\t? `${pullRequestFields} headRefName`\n\t\t\t: pullRequestFields;\n\tconst pullRequest = `pullRequest { ${fields} }`;\n\tconst selection = status === 'queued' ? `mergeQueueEntry { id ${pullRequest} }` : pullRequest;\n\ttype Payload = {\n\t\tchange: {\n\t\t\tpullRequest?: PullRequestNode | null;\n\t\t\tmergeQueueEntry?: { id: string; pullRequest: PullRequestNode | null } | null;\n\t\t} | null;\n\t};\n\tlet payload: Payload | undefined;\n\tlet error: unknown;\n\ttry {\n\t\tpayload = await transport.graphql<Payload>(\n\t\t\t`mutation WritePullRequest($input: ${inputType}!) {\n\t\t\t\tchange: ${mutation}(input: $input) { ${selection} }\n\t\t\t}`,\n\t\t\t{ input: values },\n\t\t);\n\t} catch (ex) {\n\t\terror = ex;\n\t\tif (ex instanceof GraphqlResponseError) {\n\t\t\tpayload = ex.data as Payload | undefined;\n\t\t}\n\t}\n\n\tconst entry = payload?.change?.mergeQueueEntry;\n\tconst node =\n\t\tstatus === 'queued'\n\t\t\t? typeof entry?.id === 'string' && entry.id\n\t\t\t\t? entry.pullRequest\n\t\t\t\t: undefined\n\t\t\t: payload?.change?.pullRequest;\n\tif (node == null && error != null) {\n\t\tif (\n\t\t\terror instanceof GraphqlResponseError &&\n\t\t\terror.errors?.some(item => item.path?.[0] === 'change' && item.path.length > 1)\n\t\t) {\n\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\n\t\treturn pullRequestWriteFailure(\n\t\t\terror,\n\t\t\tstatus === 'merged' ? 'merge' : status === 'queued' ? 'enqueue' : 'write',\n\t\t);\n\t}\n\n\tconst expectedState =\n\t\tstatus === 'created' || status === 'reopened' || status === 'queued'\n\t\t\t? 'OPEN'\n\t\t\t: status === 'closed'\n\t\t\t\t? 'CLOSED'\n\t\t\t\t: status === 'merged'\n\t\t\t\t\t? 'MERGED'\n\t\t\t\t\t: undefined;\n\tif (\n\t\tnode?.repository?.id !== repository.id ||\n\t\t(previous != null && (node.id !== previous.id || node.number !== previous.number)) ||\n\t\t(expectedState != null && node.state !== expectedState) ||\n\t\ttypeof node.repository.owner?.login !== 'string' ||\n\t\ttypeof node.repository.name !== 'string' ||\n\t\ttypeof node.id !== 'string' ||\n\t\t!Number.isInteger(node.number) ||\n\t\ttypeof node.url !== 'string' ||\n\t\ttypeof node.title !== 'string' ||\n\t\ttypeof node.body !== 'string' ||\n\t\ttypeof node.headRefOid !== 'string' ||\n\t\ttypeof node.baseRefName !== 'string' ||\n\t\t!isGitHubWriteUrlOnInstallation(node.url, transport.enterprise?.origin) ||\n\t\t(node.state !== 'OPEN' && node.state !== 'CLOSED' && node.state !== 'MERGED')\n\t) {\n\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t}\n\n\tif (transport.enterprise?.origin != null) {\n\t\tif (\n\t\t\tstatus === 'created' &&\n\t\t\t(node.baseRefName !== values.baseRefName || node.headRefName !== values.headRefName)\n\t\t) {\n\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\t\tif (\n\t\t\t(status === 'merged' || status === 'queued') &&\n\t\t\t(node.baseRefName !== previous?.baseRefName ||\n\t\t\t\tnode.headRefOid.toLowerCase() !== previous.headRefOid.toLowerCase())\n\t\t) {\n\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\t}\n\n\treturn { ok: true, status: status, pullRequest: toSnapshot(node, transport.enterprise?.origin) };\n}\n\nasync function createPullRequest(\n\tinput: Extract<GitHubPullRequestWrite, { action: 'create' }>,\n\ttransport: WriteTransport,\n): Promise<PullRequestWriteResult> {\n\ttype CreateRepository = RepositoryNode & { base: { id: string } | null; head: { id: string } | null };\n\tconst result = await transport.graphql<{ repository: CreateRepository | null }>(\n\t\t`query PullRequestCreateTarget($owner: String!, $repo: String!, $base: String!, $head: String!) {\n\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t${repositoryFields}\n\t\t\t\tbase: ref(qualifiedName: $base) { id }\n\t\t\t\thead: ref(qualifiedName: $head) { id }\n\t\t\t}\n\t\t}`,\n\t\t{\n\t\t\towner: input.owner,\n\t\t\trepo: input.repo,\n\t\t\tbase: `refs/heads/${input.baseRef}`,\n\t\t\thead: `refs/heads/${input.headRef}`,\n\t\t},\n\t);\n\tconst repository = result?.repository;\n\tif (\n\t\trepository == null ||\n\t\t!sameRepository(input, repository) ||\n\t\t(input.expectedRepositoryId != null && input.expectedRepositoryId !== repository.id)\n\t) {\n\t\treturn { ok: false, reason: 'not-found' };\n\t}\n\n\tif (!isRepositoryWritable(repository)) return { ok: false, reason: 'blocked' };\n\tif (repository.base == null || repository.head == null) return { ok: false, reason: 'invalid-input' };\n\n\treturn sendMutation(transport, 'created', repository, {\n\t\trepositoryId: repository.id,\n\t\tbaseRefName: input.baseRef,\n\t\theadRefName: input.headRef,\n\t\ttitle: input.title,\n\t\tbody: input.body,\n\t});\n}\n\nasync function mergePullRequest(\n\tinput: Extract<GitHubPullRequestWrite, { action: 'merge' | 'enqueue' }>,\n\tresolved: ResolvedPullRequest,\n\ttransport: WriteTransport,\n): Promise<PullRequestWriteResult> {\n\tconst { node, repository } = resolved;\n\tif (node.headRefOid.toLowerCase() !== input.expectedHeadSha.toLowerCase()) {\n\t\treturn { ok: false, reason: 'head-changed' };\n\t}\n\n\tif (node.baseRefName !== input.expectedBaseRef) return { ok: false, reason: 'base-changed' };\n\n\tconst capability = await getMergeCapability(resolved, transport.graphql, transport.enterprise);\n\tif (capability.kind === 'unavailable') return { ok: false, reason: capability.reason };\n\n\tif (\n\t\tinput.action === 'merge'\n\t\t\t? capability.kind !== 'direct' || !capability.methods.includes(input.mergeMethod)\n\t\t\t: capability.kind !== 'queue'\n\t) {\n\t\treturn { ok: false, reason: 'blocked' };\n\t}\n\n\tif (transport.enterprise?.origin != null) {\n\t\tconst current = await resolveNode(\n\t\t\t{ ...input, expectedNodeId: node.id },\n\t\t\ttransport.graphql,\n\t\t\ttransport.enterprise.origin,\n\t\t);\n\t\tif (!current.ok) return current;\n\t\tif (current.node.id !== node.id || current.repository.id !== repository.id) {\n\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t}\n\n\t\tif (current.node.baseRefName !== input.expectedBaseRef || current.node.baseRef?.id !== node.baseRef?.id) {\n\t\t\treturn { ok: false, reason: 'base-changed' };\n\t\t}\n\t\tif (current.node.headRefOid.toLowerCase() !== input.expectedHeadSha.toLowerCase()) {\n\t\t\treturn { ok: false, reason: 'head-changed' };\n\t\t}\n\t\tif (current.node.state !== 'OPEN' || current.node.isDraft || !isRepositoryWritable(current.repository)) {\n\t\t\treturn { ok: false, reason: 'blocked' };\n\t\t}\n\t}\n\n\tconst values = { pullRequestId: node.id, expectedHeadOid: node.headRefOid };\n\tif (input.action === 'merge') {\n\t\treturn sendMutation(\n\t\t\ttransport,\n\t\t\t'merged',\n\t\t\trepository,\n\t\t\t{ ...values, mergeMethod: input.mergeMethod.toUpperCase() },\n\t\t\tnode,\n\t\t);\n\t}\n\n\tif (transport.enterprise?.origin != null) return sendMutation(transport, 'queued', repository, values, node);\n\n\tif (!(await transport.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\ttry {\n\t\tconst result = await transport.enqueue(node.id, node.headRefOid);\n\t\tif (result.status === 'queued' && result.entry != null) {\n\t\t\treturn { ok: true, status: 'queued', pullRequest: toSnapshot(node) };\n\t\t}\n\n\t\tif (result.status !== 'failed') return { ok: false, reason: 'outcome-unknown' };\n\n\t\tswitch (result.reason) {\n\t\t\tcase 'permission':\n\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\tcase 'already-queued':\n\t\t\tcase 'not-allowed':\n\t\t\t\treturn { ok: false, reason: 'blocked' };\n\t\t\tcase 'head-changed':\n\t\t\tcase 'unsupported':\n\t\t\t\treturn { ok: false, reason: result.reason };\n\t\t\tdefault:\n\t\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex, 'enqueue');\n\t}\n}\n\nexport async function writeGitHubPullRequest(\n\tinput: GitHubPullRequestWrite,\n\ttransport: WriteTransport,\n): Promise<PullRequestWriteResult> {\n\tif (\n\t\t!isValidWrite(input) ||\n\t\t(transport.enterprise?.origin != null && input.action === 'create' && input.expectedRepositoryId == null)\n\t) {\n\t\treturn { ok: false, reason: 'invalid-input' };\n\t}\n\n\ttry {\n\t\tif (input.action === 'create') return await createPullRequest(input, transport);\n\n\t\tconst resolved = await resolveNode(input, transport.graphql, transport.enterprise?.origin);\n\t\tif (!resolved.ok) return resolved;\n\n\t\tconst { node, repository } = resolved;\n\t\tif (!isRepositoryWritable(repository)) return { ok: false, reason: 'blocked' };\n\t\tif (input.action === 'merge' || input.action === 'enqueue') {\n\t\t\treturn await mergePullRequest(input, resolved, transport);\n\t\t}\n\n\t\tif (input.action === 'edit') {\n\t\t\tif (!node.viewerCanUpdate) return { ok: false, reason: 'forbidden' };\n\n\t\t\treturn await sendMutation(\n\t\t\t\ttransport,\n\t\t\t\t'updated',\n\t\t\t\trepository,\n\t\t\t\t{ pullRequestId: node.id, title: input.title, body: input.body },\n\t\t\t\tnode,\n\t\t\t);\n\t\t}\n\n\t\tconst close = input.state === 'closed';\n\t\tif (node.state !== (close ? 'OPEN' : 'CLOSED')) return { ok: false, reason: 'blocked' };\n\t\tif (close ? !node.viewerCanClose : !node.viewerCanReopen) return { ok: false, reason: 'forbidden' };\n\n\t\treturn await sendMutation(\n\t\t\ttransport,\n\t\t\tclose ? 'closed' : 'reopened',\n\t\t\trepository,\n\t\t\t{ pullRequestId: node.id },\n\t\t\tnode,\n\t\t);\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex);\n\t}\n}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MAAM,WAAW,UAAU,OAAO,MAAM,kBAAkB,OAAO,SAAS;EAE9E,MAAM,WAAW,MAAM,YAAY,OAAO,UAAU,SAAS,UAAU,YAAY,MAAM;EACzF,IAAI,CAAC,SAAS,IAAI,OAAO;EAEzB,MAAM,EAAE,MAAM,eAAe;EAC7B,IAAI,CAAC,qBAAqB,UAAU,GAAG,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAU;EAC7E,IAAI,MAAM,WAAW,WAAW,MAAM,WAAW,WAChD,OAAO,MAAM,iBAAiB,OAAO,UAAU,SAAS;EAGzD,IAAI,MAAM,WAAW,QAAQ;GAC5B,IAAI,CAAC,KAAK,iBAAiB,OAAO;IAAE,IAAI;IAAO,QAAQ;GAAY;GAEnE,OAAO,MAAM,aACZ,WACA,WACA,YACA;IAAE,eAAe,KAAK;IAAI,OAAO,MAAM;IAAO,MAAM,MAAM;GAAK,GAC/D,IACD;EACD;EAEA,MAAM,QAAQ,MAAM,UAAU;EAC9B,IAAI,KAAK,WAAW,QAAQ,SAAS,WAAW,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAU;EACtF,IAAI,QAAQ,CAAC,KAAK,iBAAiB,CAAC,KAAK,iBAAiB,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAY;EAElG,OAAO,MAAM,aACZ,WACA,QAAQ,WAAW,YACnB,YACA,EAAE,eAAe,KAAK,GAAG,GACzB,IACD;CACD,SAAS,IAAI;EACZ,OAAO,wBAAwB,EAAE;CAClC;AACD"}
@@ -0,0 +1,44 @@
1
+ import { Disposable } from "../../../utils/disposable.js";
2
+ import { Event } from "../../../utils/event.js";
3
+ import { ProviderAuthenticationSession } from "./models.js";
4
+ import { IntegrationIds } from "../constants.js";
5
+ import { GetSessionOptions, IntegrationAuthenticationProvider, IntegrationAuthenticationSessionDescriptor } from "./integrationAuthenticationProvider.js";
6
+ import { ConfiguredIntegrationService } from "./configuredIntegrationService.js";
7
+ import { IntegrationAuthenticationService } from "./integrationAuthenticationService.js";
8
+ //#region ../plus/integrations/src/authentication/cloudIntegrationAuthenticationProvider.d.ts
9
+ /**
10
+ * What {@link IntegrationAuthenticationProviderBase.getSession} passes down once it has decided the stored
11
+ * session can't be served as-is. `refreshIfExpired` is its own conclusion, not a caller's option.
12
+ */
13
+ type GetNewSessionOptions = GetSessionOptions & {
14
+ refreshIfExpired?: boolean;
15
+ };
16
+ declare abstract class IntegrationAuthenticationProviderBase<ID extends IntegrationIds = IntegrationIds> implements IntegrationAuthenticationProvider {
17
+ protected readonly authenticationService: IntegrationAuthenticationService;
18
+ protected readonly configuredIntegrationService: ConfiguredIntegrationService;
19
+ protected readonly disposables: Disposable[];
20
+ constructor(authenticationService: IntegrationAuthenticationService, configuredIntegrationService: ConfiguredIntegrationService);
21
+ dispose(): void;
22
+ private readonly _onDidChange;
23
+ get onDidChange(): Event<void>;
24
+ protected abstract get authProviderId(): ID;
25
+ deleteSession(descriptor: IntegrationAuthenticationSessionDescriptor, options?: {
26
+ preserveConfigured?: boolean;
27
+ signOutMark?: number;
28
+ }): Promise<void>;
29
+ deleteAllSessions(descriptor?: IntegrationAuthenticationSessionDescriptor): Promise<void>;
30
+ getSession(descriptor: IntegrationAuthenticationSessionDescriptor, options?: GetSessionOptions): Promise<ProviderAuthenticationSession | undefined>;
31
+ protected abstract getNewSession(descriptor: IntegrationAuthenticationSessionDescriptor, options?: GetNewSessionOptions): Promise<ProviderAuthenticationSession | undefined>;
32
+ protected fireChange(): void;
33
+ }
34
+ export declare class CloudIntegrationAuthenticationProvider<ID extends IntegrationIds = IntegrationIds> extends IntegrationAuthenticationProviderBase<ID> {
35
+ private readonly _authProviderId;
36
+ constructor(authenticationService: IntegrationAuthenticationService, configuredIntegrationService: ConfiguredIntegrationService, _authProviderId: ID);
37
+ protected get authProviderId(): ID;
38
+ protected getNewSession(descriptor: IntegrationAuthenticationSessionDescriptor, options?: GetNewSessionOptions): Promise<ProviderAuthenticationSession | undefined>;
39
+ private connectCloudSession;
40
+ private getCloudSession;
41
+ private disconnectCloudSession;
42
+ }
43
+ //#endregion
44
+ //# sourceMappingURL=cloudIntegrationAuthenticationProvider.d.ts.map
@@ -0,0 +1,199 @@
1
+ import { CancellationError } from "../../../utils/cancellation.js";
2
+ import { trace } from "../../../utils/decorators/log.js";
3
+ import { Emitter } from "../../../utils/event.js";
4
+ import __decorate from "../../../_virtual/@oxc-project+runtime/helpers/esm/decorate.js";
5
+ import { areDomainsOnSameHost } from "../utils/domain.utils.js";
6
+ import { isNonExpiringZeroTokenIntegrationId, isSelfManagedHostIntegrationId } from "../utils/integration.utils.js";
7
+ import { isSupportedCloudIntegrationId } from "./models.js";
8
+ //#region ../plus/integrations/src/authentication/cloudIntegrationAuthenticationProvider.ts
9
+ const maxSmallIntegerV8 = 2 ** 30 - 1;
10
+ var IntegrationAuthenticationProviderBase = class {
11
+ authenticationService;
12
+ configuredIntegrationService;
13
+ disposables = [];
14
+ constructor(authenticationService, configuredIntegrationService) {
15
+ this.authenticationService = authenticationService;
16
+ this.configuredIntegrationService = configuredIntegrationService;
17
+ }
18
+ dispose() {
19
+ this.disposables.forEach((d) => d.dispose());
20
+ }
21
+ _onDidChange = new Emitter();
22
+ get onDidChange() {
23
+ return this._onDidChange.event;
24
+ }
25
+ async deleteSession(descriptor, options) {
26
+ const domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : void 0;
27
+ const configured = this.configuredIntegrationService.getConfigured(this.authProviderId, { domain });
28
+ if (await this.configuredIntegrationService.deleteStoredSessions(this.authProviderId, {
29
+ ...descriptor,
30
+ cloud: true
31
+ }, true, {
32
+ preserveConfigured: options?.preserveConfigured ?? true,
33
+ signOutMark: options?.signOutMark
34
+ }) && configured?.length) this.fireChange();
35
+ }
36
+ async deleteAllSessions(descriptor) {
37
+ const domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : void 0;
38
+ const configured = this.configuredIntegrationService.getConfigured(this.authProviderId, { domain });
39
+ await this.configuredIntegrationService.deleteAllStoredSessions(this.authProviderId, void 0, domain);
40
+ if (configured?.length) this.fireChange();
41
+ }
42
+ async getSession(descriptor, options) {
43
+ let session;
44
+ let previousToken;
45
+ let refetched;
46
+ let signOutMark;
47
+ if (options?.forceNewSession) {
48
+ if (isSelfManagedHostIntegrationId(this.authProviderId)) {
49
+ const connectionId = descriptor.connectionId || this.configuredIntegrationService.getConfiguredConnectionId(this.authProviderId, descriptor.domain, true);
50
+ if (!this.configuredIntegrationService.isConnectionConfiguredForHost(this.authProviderId, connectionId, descriptor.domain)) return;
51
+ descriptor = {
52
+ ...descriptor,
53
+ connectionId
54
+ };
55
+ }
56
+ await this.configuredIntegrationService.deleteStoredSessions(this.authProviderId, {
57
+ ...descriptor,
58
+ cloud: true
59
+ }, true, {
60
+ signOut: true,
61
+ preserveConfigured: isSelfManagedHostIntegrationId(this.authProviderId)
62
+ });
63
+ signOutMark = this.configuredIntegrationService.getSignOutMark();
64
+ } else {
65
+ signOutMark = this.configuredIntegrationService.getSignOutMark();
66
+ const stored = await this.configuredIntegrationService.getStoredSession(this.authProviderId, options?.sync ? {
67
+ ...descriptor,
68
+ cloud: true
69
+ } : descriptor);
70
+ previousToken = stored?.accessToken;
71
+ if (options?.sync && options.refetch) refetched = stored;
72
+ else session = stored;
73
+ }
74
+ const isExpiredSession = session?.expiresAt != null && new Date(session.expiresAt).getTime() < Date.now();
75
+ const scopedRecovery = options?.isRejectedToken?.(session?.accessToken) === true;
76
+ const refreshRejectedToken = scopedRecovery || options?.refreshRejectedToken === true && session != null;
77
+ if (session == null || isExpiredSession || refreshRejectedToken) {
78
+ session = await this.getNewSession(descriptor, {
79
+ ...options,
80
+ refreshIfExpired: isExpiredSession,
81
+ refreshRejectedToken,
82
+ isRejectedToken: scopedRecovery ? options?.isRejectedToken : void 0
83
+ });
84
+ if (session == null && options?.refetch && refetched != null && this.configuredIntegrationService.isSessionRetiredSince(this.authProviderId, refetched, signOutMark)) throw new CancellationError();
85
+ if (session != null) {
86
+ if (!await this.configuredIntegrationService.storeSession(this.authProviderId, session, {
87
+ signOutMark,
88
+ expectedStoredAccessToken: scopedRecovery ? previousToken : void 0
89
+ })) {
90
+ session = await this.configuredIntegrationService.getStoredSession(this.authProviderId, {
91
+ ...descriptor,
92
+ connectionId: session.id,
93
+ cloud: session.cloud
94
+ });
95
+ options?.isRejectedToken?.(session?.accessToken);
96
+ } else if (refetched?.id != null && refetched.id !== session.id) await this.configuredIntegrationService.deleteStoredSessions(this.authProviderId, {
97
+ ...descriptor,
98
+ connectionId: refetched.id,
99
+ cloud: true
100
+ }, true, { preserveConfigured: true });
101
+ }
102
+ }
103
+ if (previousToken !== session?.accessToken) this.fireChange();
104
+ return session;
105
+ }
106
+ fireChange() {
107
+ queueMicrotask(() => this._onDidChange.fire());
108
+ }
109
+ };
110
+ __decorate([trace()], IntegrationAuthenticationProviderBase.prototype, "deleteSession", null);
111
+ __decorate([trace()], IntegrationAuthenticationProviderBase.prototype, "deleteAllSessions", null);
112
+ __decorate([trace()], IntegrationAuthenticationProviderBase.prototype, "getSession", null);
113
+ var CloudIntegrationAuthenticationProvider = class extends IntegrationAuthenticationProviderBase {
114
+ _authProviderId;
115
+ constructor(authenticationService, configuredIntegrationService, _authProviderId) {
116
+ super(authenticationService, configuredIntegrationService);
117
+ this._authProviderId = _authProviderId;
118
+ }
119
+ get authProviderId() {
120
+ return this._authProviderId;
121
+ }
122
+ async getNewSession(descriptor, options) {
123
+ if (options?.forceNewSession) {
124
+ if (await this.disconnectCloudSession(descriptor) === "failure") return;
125
+ this.connectCloudSession(false, options?.source);
126
+ return;
127
+ }
128
+ let session = options?.refreshIfExpired || options?.refreshRejectedToken || options?.createIfNeeded || options?.forceNewSession || options?.sync ? await this.getCloudSession(descriptor, options) : void 0;
129
+ if (options?.createIfNeeded && session == null) {
130
+ if (!await this.connectCloudSession(true, options?.source)) return void 0;
131
+ session = await this.getSession(descriptor, { source: options?.source });
132
+ }
133
+ return session;
134
+ }
135
+ connectCloudSession(skipIfConnected, source) {
136
+ const id = this.authProviderId;
137
+ if (isSupportedCloudIntegrationId(id)) return this.authenticationService.connectCloudIntegrations({
138
+ integrationIds: [id],
139
+ skipIfConnected,
140
+ skipPreSync: true
141
+ }, {
142
+ source: source ?? "integrations",
143
+ detail: {
144
+ action: "connect",
145
+ integration: id
146
+ }
147
+ });
148
+ return Promise.resolve(false);
149
+ }
150
+ async getCloudSession(descriptor, options) {
151
+ if (!(await this.authenticationService.ctx.account.getAccount() != null)) return void 0;
152
+ const cloudIntegrations = this.authenticationService.cloudIntegrations;
153
+ const connectionId = descriptor.connectionId ?? (isSelfManagedHostIntegrationId(this.authProviderId) ? this.configuredIntegrationService.getConfiguredConnectionId(this.authProviderId, descriptor.domain, true) : void 0);
154
+ const scopedToThisHost = this.configuredIntegrationService.isConnectionConfiguredForHost(this.authProviderId, connectionId, descriptor.domain);
155
+ const isForAnotherHost = (session) => session != null && isSelfManagedHostIntegrationId(this.authProviderId) && (!scopedToThisHost || Boolean(session.domain?.trim())) && !areDomainsOnSameHost(session.domain, descriptor.domain);
156
+ let session = await cloudIntegrations.getConnectionSession(this.authProviderId, void 0, connectionId);
157
+ if (isForAnotherHost(session)) return void 0;
158
+ if (options?.isRejectedToken != null && session?.id != null && session.id !== connectionId) return void 0;
159
+ if (session?.expiresIn === 0 && isNonExpiringZeroTokenIntegrationId(this.authProviderId)) session.expiresIn = maxSmallIntegerV8;
160
+ if (session != null && (session.expiresIn < 60 || options?.refreshRejectedToken && (options.isRejectedToken?.(session.accessToken) ?? true))) {
161
+ session = await cloudIntegrations.getConnectionSession(this.authProviderId, session.accessToken, connectionId);
162
+ if (isForAnotherHost(session)) return void 0;
163
+ if (options?.isRejectedToken != null && session?.id != null && session.id !== connectionId) return;
164
+ }
165
+ if (!session) return void 0;
166
+ let sessionProtocol;
167
+ if (/^[a-z][a-z\d+\-.]*:\/\//i.test(session.domain)) try {
168
+ sessionProtocol = new URL(session.domain).protocol;
169
+ } catch {
170
+ sessionProtocol = void 0;
171
+ }
172
+ return {
173
+ id: session.id ?? this.configuredIntegrationService.resolveConnectionId(this.authProviderId, descriptor),
174
+ accessToken: session.accessToken,
175
+ scopes: descriptor.scopes,
176
+ account: {
177
+ id: "",
178
+ label: ""
179
+ },
180
+ cloud: true,
181
+ type: session.type,
182
+ expiresAt: new Date(session.expiresIn * 1e3 + Date.now()),
183
+ domain: descriptor.domain,
184
+ baseUrl: session.domain || this.configuredIntegrationService.getConfiguredBaseUrl(this.authProviderId, connectionId, descriptor.domain),
185
+ protocol: sessionProtocol ?? void 0,
186
+ appKey: session.appKey
187
+ };
188
+ }
189
+ async disconnectCloudSession(descriptor) {
190
+ if (!(await this.authenticationService.ctx.account.getAccount() != null)) return "skip";
191
+ if (!await this.authenticationService.cloudIntegrations.disconnect(this.authProviderId, descriptor.connectionId)) return "failure";
192
+ if (isSelfManagedHostIntegrationId(this.authProviderId)) await this.deleteSession(descriptor, { preserveConfigured: false });
193
+ return "success";
194
+ }
195
+ };
196
+ //#endregion
197
+ export { CloudIntegrationAuthenticationProvider };
198
+
199
+ //# sourceMappingURL=cloudIntegrationAuthenticationProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudIntegrationAuthenticationProvider.js","names":[],"sources":["../../../../../plus/integrations/src/authentication/cloudIntegrationAuthenticationProvider.ts"],"sourcesContent":["import { CancellationError } from '@gitlens/utils/cancellation.js';\nimport { trace } from '@gitlens/utils/decorators/log.js';\nimport type { Disposable } from '@gitlens/utils/disposable.js';\nimport type { Event } from '@gitlens/utils/event.js';\nimport { Emitter } from '@gitlens/utils/event.js';\nimport type { IntegrationIds } from '../constants.js';\nimport type { Sources } from '../telemetry.js';\nimport { areDomainsOnSameHost } from '../utils/domain.utils.js';\nimport { isNonExpiringZeroTokenIntegrationId, isSelfManagedHostIntegrationId } from '../utils/integration.utils.js';\nimport type { ConfiguredIntegrationService } from './configuredIntegrationService.js';\nimport type {\n\tGetSessionOptions,\n\tIntegrationAuthenticationProvider,\n\tIntegrationAuthenticationSessionDescriptor,\n\tRejectedTokenRefreshOptions,\n} from './integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from './integrationAuthenticationService.js';\nimport type { ProviderAuthenticationSession } from './models.js';\nimport { isSupportedCloudIntegrationId } from './models.js';\n\n// The package's implementation of the public `IntegrationAuthenticationProvider` contract, kept out of that module so\n// the contract's declarations never reach the internal services these classes are built on.\n\nconst maxSmallIntegerV8 = 2 ** 30 - 1; // Max number that can be stored in V8's smis (small integers)\n\n/**\n * What {@link IntegrationAuthenticationProviderBase.getSession} passes down once it has decided the stored\n * session can't be served as-is. `refreshIfExpired` is its own conclusion, not a caller's option.\n */\ntype GetNewSessionOptions = GetSessionOptions & { refreshIfExpired?: boolean };\n\nabstract class IntegrationAuthenticationProviderBase<\n\tID extends IntegrationIds = IntegrationIds,\n> implements IntegrationAuthenticationProvider {\n\tprotected readonly disposables: Disposable[] = [];\n\n\tconstructor(\n\t\tprotected readonly authenticationService: IntegrationAuthenticationService,\n\t\tprotected readonly configuredIntegrationService: ConfiguredIntegrationService,\n\t) {}\n\n\tdispose(): void {\n\t\tthis.disposables.forEach(d => d.dispose());\n\t}\n\n\tprivate readonly _onDidChange = new Emitter<void>();\n\tget onDidChange(): Event<void> {\n\t\treturn this._onDidChange.event;\n\t}\n\n\tprotected abstract get authProviderId(): ID;\n\n\t@trace()\n\tasync deleteSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: { preserveConfigured?: boolean; signOutMark?: number },\n\t): Promise<void> {\n\t\tconst domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : undefined;\n\t\tconst configured = this.configuredIntegrationService.getConfigured(this.authProviderId, {\n\t\t\tdomain: domain,\n\t\t});\n\n\t\t// Scope the descriptor to cloud so resolveConnectionId targets the cloud variant's id: this is a\n\t\t// cloud-only delete, and a mixed local+cloud connection whose local descriptor is primary would\n\t\t// otherwise resolve the local id and leave the cloud secret intact.\n\t\tconst deleted = await this.configuredIntegrationService.deleteStoredSessions(\n\t\t\tthis.authProviderId,\n\t\t\t{ ...descriptor, cloud: true },\n\t\t\ttrue,\n\t\t\t{ preserveConfigured: options?.preserveConfigured ?? true, signOutMark: options?.signOutMark },\n\t\t);\n\n\t\tif (deleted && configured?.length) {\n\t\t\tthis.fireChange();\n\t\t}\n\t}\n\n\t@trace()\n\tasync deleteAllSessions(descriptor?: IntegrationAuthenticationSessionDescriptor): Promise<void> {\n\t\t// Self-managed providers group every host under one provider id, so scope the clear to this\n\t\t// descriptor's host when given; for cloud providers the domain stays undefined here, clearing every account.\n\t\tconst domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : undefined;\n\t\tconst configured = this.configuredIntegrationService.getConfigured(this.authProviderId, {\n\t\t\tdomain: domain,\n\t\t});\n\n\t\tawait this.configuredIntegrationService.deleteAllStoredSessions(this.authProviderId, undefined, domain);\n\n\t\tif (configured?.length) {\n\t\t\tthis.fireChange();\n\t\t}\n\t}\n\n\t@trace()\n\tasync getSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetSessionOptions,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tlet session;\n\t\tlet previousToken;\n\t\tlet refetched: ProviderAuthenticationSession | undefined;\n\t\tlet signOutMark: number;\n\t\tif (options?.forceNewSession) {\n\t\t\tif (isSelfManagedHostIntegrationId(this.authProviderId)) {\n\t\t\t\tconst connectionId =\n\t\t\t\t\tdescriptor.connectionId ||\n\t\t\t\t\tthis.configuredIntegrationService.getConfiguredConnectionId(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\t!this.configuredIntegrationService.isConnectionConfiguredForHost(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tconnectionId,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tdescriptor = { ...descriptor, connectionId: connectionId };\n\t\t\t}\n\t\t\t// Cloud-only delete (see deleteSession): scope to cloud so the cloud variant's id is cleared even\n\t\t\t// when a mixed local+cloud connection's local descriptor is primary. A sign-out, so a token fetched before\n\t\t\t// it is not stored back; the mark is taken after it, so this session's own fetch is not refused.\n\t\t\tawait this.configuredIntegrationService.deleteStoredSessions(\n\t\t\t\tthis.authProviderId,\n\t\t\t\t{ ...descriptor, cloud: true },\n\t\t\t\ttrue,\n\t\t\t\t{ signOut: true, preserveConfigured: isSelfManagedHostIntegrationId(this.authProviderId) },\n\t\t\t);\n\t\t\tsignOutMark = this.configuredIntegrationService.getSignOutMark();\n\t\t} else {\n\t\t\t// Taken before the stored-token read (a sign-out landing during the read is ordered after it by the storage\n\t\t\t// lock, so it counts either way).\n\t\t\tsignOutMark = this.configuredIntegrationService.getSignOutMark();\n\t\t\tconst stored = await this.configuredIntegrationService.getStoredSession(\n\t\t\t\tthis.authProviderId,\n\t\t\t\toptions?.sync ? { ...descriptor, cloud: true } : descriptor,\n\t\t\t);\n\t\t\tpreviousToken = stored?.accessToken;\n\t\t\tif (options?.sync && options.refetch) {\n\t\t\t\trefetched = stored;\n\t\t\t} else {\n\t\t\t\tsession = stored;\n\t\t\t}\n\t\t}\n\n\t\tconst isExpiredSession = session?.expiresAt != null && new Date(session.expiresAt).getTime() < Date.now();\n\t\t// A rejected token has to re-resolve even when the stored session looks perfectly healthy: that is\n\t\t// the whole point — the provider refused it while its expiry still says valid. Without this the\n\t\t// stored session short-circuits here and the refresh below is never reached.\n\t\tconst scopedRecovery = options?.isRejectedToken?.(session?.accessToken) === true;\n\t\tconst refreshRejectedToken = scopedRecovery || (options?.refreshRejectedToken === true && session != null);\n\t\tif (session == null || isExpiredSession || refreshRejectedToken) {\n\t\t\tsession = await this.getNewSession(descriptor, {\n\t\t\t\t...options,\n\t\t\t\trefreshIfExpired: isExpiredSession,\n\t\t\t\trefreshRejectedToken: refreshRejectedToken,\n\t\t\t\tisRejectedToken: scopedRecovery ? options?.isRejectedToken : undefined,\n\t\t\t});\n\t\t\tif (\n\t\t\t\tsession == null &&\n\t\t\t\toptions?.refetch &&\n\t\t\t\trefetched != null &&\n\t\t\t\tthis.configuredIntegrationService.isSessionRetiredSince(this.authProviderId, refetched, signOutMark)\n\t\t\t) {\n\t\t\t\tthrow new CancellationError();\n\t\t\t}\n\n\t\t\tif (session != null) {\n\t\t\t\tconst stored = await this.configuredIntegrationService.storeSession(this.authProviderId, session, {\n\t\t\t\t\tsignOutMark: signOutMark,\n\t\t\t\t\texpectedStoredAccessToken: scopedRecovery ? previousToken : undefined,\n\t\t\t\t});\n\t\t\t\tif (!stored) {\n\t\t\t\t\t// A disconnect leaves no credential here. A recovery can leave a replacement for this same\n\t\t\t\t\t// connection, which a forced sync must not interpret as a disconnect and delete.\n\t\t\t\t\tsession = await this.configuredIntegrationService.getStoredSession(this.authProviderId, {\n\t\t\t\t\t\t...descriptor,\n\t\t\t\t\t\tconnectionId: session.id,\n\t\t\t\t\t\tcloud: session.cloud,\n\t\t\t\t\t});\n\t\t\t\t\toptions?.isRejectedToken?.(session?.accessToken);\n\t\t\t\t} else if (refetched?.id != null && refetched.id !== session.id) {\n\t\t\t\t\t// The replacement belongs to a different connection (the cloud's primary moved to another\n\t\t\t\t\t// account), so it was stored beside the one it replaces rather than over it. Drop the old token\n\t\t\t\t\t// as the up-front delete used to, or an unscoped read would keep resolving it until the next sync.\n\t\t\t\t\tawait this.configuredIntegrationService.deleteStoredSessions(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\t{ ...descriptor, connectionId: refetched.id, cloud: true },\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t{ preserveConfigured: true },\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (previousToken !== session?.accessToken) {\n\t\t\tthis.fireChange();\n\t\t}\n\n\t\treturn session;\n\t}\n\n\tprotected abstract getNewSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetNewSessionOptions,\n\t): Promise<ProviderAuthenticationSession | undefined>;\n\n\tprotected fireChange(): void {\n\t\tqueueMicrotask(() => this._onDidChange.fire());\n\t}\n}\n\nexport class CloudIntegrationAuthenticationProvider<\n\tID extends IntegrationIds = IntegrationIds,\n> extends IntegrationAuthenticationProviderBase<ID> {\n\tconstructor(\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tconfiguredIntegrationService: ConfiguredIntegrationService,\n\t\tprivate readonly _authProviderId: ID,\n\t) {\n\t\tsuper(authenticationService, configuredIntegrationService);\n\t}\n\n\tprotected get authProviderId(): ID {\n\t\treturn this._authProviderId;\n\t}\n\n\tprotected override async getNewSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetNewSessionOptions,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tif (options?.forceNewSession) {\n\t\t\tif ((await this.disconnectCloudSession(descriptor)) === 'failure') {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tvoid this.connectCloudSession(false, options?.source);\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// TODO: This is a stopgap to make sure we're not hammering the api on automatic calls to get the session.\n\t\t// Ultimately we want to timestamp calls to syncCloudIntegrations and use that to determine whether we should\n\t\t// make the call or not.\n\t\t// `refreshRejectedToken` joins the list for the same reason `refreshIfExpired` is on it: both mean the\n\t\t// session in hand is known-unusable, so skipping the cloud round trip would just re-serve it.\n\t\tlet session =\n\t\t\toptions?.refreshIfExpired ||\n\t\t\toptions?.refreshRejectedToken ||\n\t\t\toptions?.createIfNeeded ||\n\t\t\toptions?.forceNewSession ||\n\t\t\toptions?.sync\n\t\t\t\t? await this.getCloudSession(descriptor, options)\n\t\t\t\t: undefined;\n\n\t\tconst shouldCreateSession = options?.createIfNeeded && session == null;\n\t\tif (shouldCreateSession) {\n\t\t\tconst connected = await this.connectCloudSession(true, options?.source);\n\t\t\tif (!connected) return undefined;\n\n\t\t\t// This should get us the session we just created with connectCloudSession, because a syncCloudIntegrations run from\n\t\t\t// integration service should have resulted in it being created and stored by this provider\n\t\t\tsession = await this.getSession(descriptor, { source: options?.source });\n\t\t}\n\t\treturn session;\n\t}\n\n\tprivate connectCloudSession(skipIfConnected: boolean, source: Sources | undefined): Promise<boolean> {\n\t\t// Capture in a const so the type guard narrows it to `SupportedCloudIntegrationIds` (a getter\n\t\t// access wouldn't narrow), letting us call the service directly without a cast.\n\t\tconst id = this.authProviderId;\n\t\tif (isSupportedCloudIntegrationId(id)) {\n\t\t\treturn this.authenticationService.connectCloudIntegrations(\n\t\t\t\t{ integrationIds: [id], skipIfConnected: skipIfConnected, skipPreSync: true },\n\t\t\t\t{\n\t\t\t\t\tsource: source ?? 'integrations',\n\t\t\t\t\tdetail: {\n\t\t\t\t\t\taction: 'connect',\n\t\t\t\t\t\tintegration: id,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\treturn Promise.resolve(false);\n\t}\n\n\tprivate async getCloudSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: RejectedTokenRefreshOptions,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tconst loggedIn = (await this.authenticationService.ctx.account.getAccount()) != null;\n\t\tif (!loggedIn) return undefined;\n\n\t\tconst cloudIntegrations = this.authenticationService.cloudIntegrations;\n\t\t// An unscoped descriptor (no explicit connectionId) would fetch the provider-global primary via\n\t\t// `v1/provider-tokens/<provider>`. For a self-managed provider spanning multiple hosts that primary\n\t\t// can belong to a different host, so a forced sync of host A would hydrate host B's token here (before\n\t\t// reconcile corrects storage). Scope to this host's own configured connection when we have one; fall\n\t\t// through to the provider-scoped path only when nothing is configured yet (legacy/first sync).\n\t\tconst connectionId =\n\t\t\tdescriptor.connectionId ??\n\t\t\t(isSelfManagedHostIntegrationId(this.authProviderId)\n\t\t\t\t? this.configuredIntegrationService.getConfiguredConnectionId(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t)\n\t\t\t\t: undefined);\n\t\t// Refuses a session issued for a DIFFERENT host than the one this connection is keyed by, which would\n\t\t// otherwise let host B's token serve host A.\n\t\t//\n\t\t// A session that names no host is accepted ONLY when it was fetched by a connection id WE have stored\n\t\t// for this host. That descriptor is what ties the token to the host, so an absent domain then means the\n\t\t// backend did not say rather than that the token belongs elsewhere, and refusing it would strand the\n\t\t// refresh.\n\t\t//\n\t\t// A non-null id is not enough on its own: `descriptor.connectionId` can come from the caller, and with\n\t\t// no id at all the fetch goes to the provider-GLOBAL primary endpoint whose token can belong to any\n\t\t// configured host. In both of those cases a domainless response must be refused, or a token would be\n\t\t// bound to — and sent to — a host it was never issued for.\n\t\tconst scopedToThisHost = this.configuredIntegrationService.isConnectionConfiguredForHost(\n\t\t\tthis.authProviderId,\n\t\t\tconnectionId,\n\t\t\tdescriptor.domain,\n\t\t);\n\t\tconst isForAnotherHost = (session: { domain: string } | undefined) =>\n\t\t\tsession != null &&\n\t\t\tisSelfManagedHostIntegrationId(this.authProviderId) &&\n\t\t\t(!scopedToThisHost || Boolean(session.domain?.trim())) &&\n\t\t\t!areDomainsOnSameHost(session.domain, descriptor.domain);\n\n\t\tlet session = await cloudIntegrations.getConnectionSession(this.authProviderId, undefined, connectionId);\n\t\tif (isForAnotherHost(session)) return undefined;\n\t\tif (options?.isRejectedToken != null && session?.id != null && session.id !== connectionId) return undefined;\n\n\t\t// GitHub, the cloud self-managed hosts, and Trello return `expiresIn: 0` for a token that never\n\t\t// expires; left as 0 the session would be built with `expiresAt = now` and rejected as expired on the\n\t\t// next resolution. Map it to the maximum expiry so it isn't refreshed frequently.\n\t\tif (session?.expiresIn === 0 && isNonExpiringZeroTokenIntegrationId(this.authProviderId)) {\n\t\t\tsession.expiresIn = maxSmallIntegerV8; // maximum expiration length\n\t\t}\n\n\t\t// `expiresIn < 60` is a PREDICTION that the token is about to lapse, and it is the only trigger the\n\t\t// refresh used to have. It cannot see a token the provider has already refused while the backend\n\t\t// still believes it is valid — a revoked grant, retired scopes, an app removed from the org — where\n\t\t// `expiresIn` stays high and the doomed token is re-sent on every read. `refreshRejectedToken` is\n\t\t// the observed counterpart: the caller saw the provider reject this exact token, so refresh it\n\t\t// regardless of what its expiry claims.\n\t\tif (\n\t\t\tsession != null &&\n\t\t\t(session.expiresIn < 60 ||\n\t\t\t\t(options?.refreshRejectedToken && (options.isRejectedToken?.(session.accessToken) ?? true)))\n\t\t) {\n\t\t\tsession = await cloudIntegrations.getConnectionSession(\n\t\t\t\tthis.authProviderId,\n\t\t\t\tsession.accessToken,\n\t\t\t\tconnectionId,\n\t\t\t);\n\t\t\tif (isForAnotherHost(session)) return undefined;\n\t\t\tif (options?.isRejectedToken != null && session?.id != null && session.id !== connectionId) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\n\t\tif (!session) return undefined;\n\n\t\tlet sessionProtocol;\n\t\t// Only derive a protocol from a domain carrying an explicit scheme; a bare `host:port` (e.g. a\n\t\t// self-managed `ghe.example.com:8443`) parses the host as the protocol, corrupting the value.\n\t\tif (/^[a-z][a-z\\d+\\-.]*:\\/\\//i.test(session.domain)) {\n\t\t\ttry {\n\t\t\t\tsessionProtocol = new URL(session.domain).protocol;\n\t\t\t} catch {\n\t\t\t\tsessionProtocol = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t// Prefer the backend's per-connection token id (multi-account); fall back to the resolved\n\t\t\t// primary/legacy connection id so existing single-connection storage keys are preserved.\n\t\t\tid: session.id ?? this.configuredIntegrationService.resolveConnectionId(this.authProviderId, descriptor),\n\t\t\taccessToken: session.accessToken,\n\t\t\tscopes: descriptor.scopes,\n\t\t\taccount: {\n\t\t\t\tid: '',\n\t\t\t\tlabel: '',\n\t\t\t},\n\t\t\tcloud: true,\n\t\t\ttype: session.type,\n\t\t\texpiresAt: new Date(session.expiresIn * 1000 + Date.now()),\n\t\t\t// Note: do not use the session's domain, because the format is different than in our model\n\t\t\tdomain: descriptor.domain,\n\t\t\t// That format difference is exactly what `baseUrl` is for: the descriptor's domain is the\n\t\t\t// normalized host this connection is keyed by, so a context path only survives on the wire value.\n\t\t\t// When the backend reports no domain at all, KEEP the address already configured rather than\n\t\t\t// writing `undefined` — `writeSecret` mirrors this onto the descriptor, so falling back to the\n\t\t\t// bare host here would drop a context path the user never changed on the next refresh.\n\t\t\tbaseUrl:\n\t\t\t\tsession.domain ||\n\t\t\t\tthis.configuredIntegrationService.getConfiguredBaseUrl(\n\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\tconnectionId,\n\t\t\t\t\tdescriptor.domain,\n\t\t\t\t),\n\t\t\tprotocol: sessionProtocol ?? undefined,\n\t\t\t// Carried for providers whose client needs an app key alongside the token (e.g. Trello).\n\t\t\tappKey: session.appKey,\n\t\t};\n\t}\n\n\tprivate async disconnectCloudSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t): Promise<'skip' | 'success' | 'failure'> {\n\t\tconst loggedIn = (await this.authenticationService.ctx.account.getAccount()) != null;\n\t\tif (!loggedIn) return 'skip';\n\n\t\tconst cloudIntegrations = this.authenticationService.cloudIntegrations;\n\t\tif (!(await cloudIntegrations.disconnect(this.authProviderId, descriptor.connectionId))) return 'failure';\n\n\t\tif (isSelfManagedHostIntegrationId(this.authProviderId)) {\n\t\t\tawait this.deleteSession(descriptor, { preserveConfigured: false });\n\t\t}\n\n\t\treturn 'success';\n\t}\n}\n"],"mappings":";;;;;;;;AAuBA,MAAM,oBAAoB,KAAK,KAAK;AAQpC,IAAe,wCAAf,MAE+C;CAI1B;CACA;CAJpB,cAA+C,CAAC;CAEhD,YACC,uBACA,8BACC;EAFkB,KAAA,wBAAA;EACA,KAAA,+BAAA;CACjB;CAEH,UAAgB;EACf,KAAK,YAAY,SAAQ,MAAK,EAAE,QAAQ,CAAC;CAC1C;CAEA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;GACP,kBAAkB,KAAA;EACnB;EAGD,OAAO;GAGN,IAAI,QAAQ,MAAM,KAAK,6BAA6B,oBAAoB,KAAK,gBAAgB,UAAU;GACvG,aAAa,QAAQ;GACrB,QAAQ,WAAW;GACnB,SAAS;IACR,IAAI;IACJ,OAAO;GACR;GACA,OAAO;GACP,MAAM,QAAQ;GACd,WAAW,IAAI,KAAK,QAAQ,YAAY,MAAO,KAAK,IAAI,CAAC;GAEzD,QAAQ,WAAW;GAMnB,SACC,QAAQ,UACR,KAAK,6BAA6B,qBACjC,KAAK,gBACL,cACA,WAAW,MACZ;GACD,UAAU,mBAAmB,KAAA;GAE7B,QAAQ,QAAQ;EACjB;CACD;CAEA,MAAc,uBACb,YAC0C;EAE1C,IAAI,EADc,MAAM,KAAK,sBAAsB,IAAI,QAAQ,WAAW,KAAM,OACjE,OAAO;EAGtB,IAAI,CAAE,MADoB,KAAK,sBAAsB,kBACvB,WAAW,KAAK,gBAAgB,WAAW,YAAY,GAAI,OAAO;EAEhG,IAAI,+BAA+B,KAAK,cAAc,GACrD,MAAM,KAAK,cAAc,YAAY,EAAE,oBAAoB,MAAM,CAAC;EAGnE,OAAO;CACR;AACD"}
@@ -30,6 +30,8 @@ export declare class ConfiguredIntegrationService implements Disposable {
30
30
  private _signOutEpoch;
31
31
  /** The latest retirement of pending stores per provider, self-managed host, or connection. */
32
32
  private readonly _signOuts;
33
+ private readonly _storedWriteRetirements;
34
+ private _disposed;
33
35
  get onDidChange(): Event<ConfiguredIntegrationsChangeEvent>;
34
36
  get onWillChangeSession(): Event<IntegrationSessionChangeEvent>;
35
37
  get onWillRemoveSessions(): typeof this._onWillRemoveSessions.event;
@@ -51,8 +53,12 @@ export declare class ConfiguredIntegrationService implements Disposable {
51
53
  */
52
54
  getSignOutMark(): number;
53
55
  private retirePendingStores;
56
+ getStoredWriteMark(): number;
57
+ isStoredWriteRetiredSince(id: IntegrationIds, session: Pick<ProviderAuthenticationSession, 'id' | 'domain'>, mark: number): boolean;
58
+ private retireStoredWrites;
54
59
  private getHostScope;
55
60
  isSessionRetiredSince(id: IntegrationIds, session: Pick<ProviderAuthenticationSession, 'id' | 'domain'>, mark: number): boolean;
61
+ private hasRetirement;
56
62
  /**
57
63
  * Stores the session's secret and descriptor together. A pending store can be invalidated by a sign-out or a
58
64
  * credential recovery. A recovery must still own the stored credential when it publishes its replacement.
@@ -62,6 +68,7 @@ export declare class ConfiguredIntegrationService implements Disposable {
62
68
  resource?: ConnectionResource;
63
69
  expectedStoredAccessToken?: string;
64
70
  }): Promise<boolean>;
71
+ peekStoredSession(id: IntegrationIds, connectionId: string, cloud: boolean, domain: string): Promise<ProviderAuthenticationSession | undefined>;
65
72
  getStoredSession(id: IntegrationIds, descriptor: IntegrationAuthenticationSessionDescriptor): Promise<ProviderAuthenticationSession | undefined>;
66
73
  /**
67
74
  * Deletes one connection's stored session. `signOut` is for a delete that signs the integration out (a forced new