@gitkraken/core-gitlens 0.45.0 → 0.46.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 (235) hide show
  1. package/CHANGELOG.md +27 -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/plus/git-github/api/github.d.ts +6 -1
  20. package/dist/plus/git-github/api/github.js +14 -4
  21. package/dist/plus/git-github/api/github.js.map +1 -1
  22. package/dist/plus/git-github/api/issueWrites.d.ts +6 -1
  23. package/dist/plus/git-github/api/issueWrites.js +61 -31
  24. package/dist/plus/git-github/api/issueWrites.js.map +1 -1
  25. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.d.ts +44 -0
  26. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +199 -0
  27. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -0
  28. package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +7 -0
  29. package/dist/plus/integrations/authentication/configuredIntegrationService.js +53 -7
  30. package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
  31. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.d.ts +2 -38
  32. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js +0 -199
  33. package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +4 -2
  34. package/dist/plus/integrations/authentication/integrationAuthenticationService.js +12 -1
  35. package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
  36. package/dist/plus/integrations/authentication/models.d.ts +0 -1
  37. package/dist/plus/integrations/authentication/models.js +1 -2
  38. package/dist/plus/integrations/authentication/models.js.map +1 -1
  39. package/dist/plus/integrations/constants.d.ts +0 -10
  40. package/dist/plus/integrations/constants.js +1 -95
  41. package/dist/plus/integrations/constants.js.map +1 -1
  42. package/dist/plus/integrations/context.d.ts +13 -13
  43. package/dist/plus/integrations/index.d.ts +39 -24
  44. package/dist/plus/integrations/index.js +40 -8
  45. package/dist/plus/integrations/index.js.map +1 -1
  46. package/dist/plus/integrations/integrationService.d.ts +15 -22
  47. package/dist/plus/integrations/integrationService.js +39 -12
  48. package/dist/plus/integrations/integrationService.js.map +1 -1
  49. package/dist/plus/integrations/lite.js +1 -1
  50. package/dist/plus/integrations/lite.js.map +1 -1
  51. package/dist/plus/integrations/manager.d.ts +65 -17
  52. package/dist/plus/integrations/models/actionablePullRequest.d.ts +213 -0
  53. package/dist/plus/integrations/models/actionablePullRequest.js +25 -0
  54. package/dist/plus/integrations/models/actionablePullRequest.js.map +1 -0
  55. package/dist/plus/integrations/models/gitHostIntegration.d.ts +13 -46
  56. package/dist/plus/integrations/models/gitHostIntegration.js +15 -4
  57. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  58. package/dist/plus/integrations/models/integration.d.ts +10 -175
  59. package/dist/plus/integrations/models/integration.js +11 -72
  60. package/dist/plus/integrations/models/integration.js.map +1 -1
  61. package/dist/plus/integrations/models/issuesIntegration.d.ts +9 -5
  62. package/dist/plus/integrations/models/issuesIntegration.js +5 -3
  63. package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
  64. package/dist/plus/integrations/models/publicIntegration.d.ts +252 -0
  65. package/dist/plus/integrations/models/publicIntegration.js +21 -0
  66. package/dist/plus/integrations/models/publicIntegration.js.map +1 -0
  67. package/dist/plus/integrations/providerFilters.d.ts +58 -0
  68. package/dist/plus/integrations/providerFilters.js.map +1 -1
  69. package/dist/plus/integrations/providers/actionablePullRequests.d.ts +19 -0
  70. package/dist/plus/integrations/providers/actionablePullRequests.js +32 -0
  71. package/dist/plus/integrations/providers/actionablePullRequests.js.map +1 -0
  72. package/dist/plus/integrations/providers/apiClients.d.ts +1 -2
  73. package/dist/plus/integrations/providers/apiClients.js.map +1 -1
  74. package/dist/plus/integrations/providers/asana.d.ts +3 -2
  75. package/dist/plus/integrations/providers/asana.js +2 -1
  76. package/dist/plus/integrations/providers/asana.js.map +1 -1
  77. package/dist/plus/integrations/providers/azure/azure.d.ts +1 -1
  78. package/dist/plus/integrations/providers/azure/azure.utils.d.ts +10 -3
  79. package/dist/plus/integrations/providers/azure/azure.utils.js +5 -1
  80. package/dist/plus/integrations/providers/azure/azure.utils.js.map +1 -1
  81. package/dist/plus/integrations/providers/azure/models.d.ts +1 -5
  82. package/dist/plus/integrations/providers/azure/models.js +1 -1
  83. package/dist/plus/integrations/providers/azure/models.js.map +1 -1
  84. package/dist/plus/integrations/providers/azureDevOps.d.ts +8 -5
  85. package/dist/plus/integrations/providers/azureDevOps.js +2 -1
  86. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  87. package/dist/plus/integrations/providers/azureDevOpsServer.d.ts +5 -4
  88. package/dist/plus/integrations/providers/azureDevOpsServer.js +3 -1
  89. package/dist/plus/integrations/providers/azureDevOpsServer.js.map +1 -1
  90. package/dist/plus/integrations/providers/bitbucket/bitbucket.d.ts +2 -2
  91. package/dist/plus/integrations/providers/bitbucket/bitbucket.js.map +1 -1
  92. package/dist/plus/integrations/providers/bitbucket/models.d.ts +1 -1
  93. package/dist/plus/integrations/providers/bitbucket/models.js.map +1 -1
  94. package/dist/plus/integrations/providers/bitbucket-server.d.ts +5 -4
  95. package/dist/plus/integrations/providers/bitbucket-server.js +2 -1
  96. package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
  97. package/dist/plus/integrations/providers/bitbucket.d.ts +4 -3
  98. package/dist/plus/integrations/providers/bitbucket.js +2 -1
  99. package/dist/plus/integrations/providers/bitbucket.js.map +1 -1
  100. package/dist/plus/integrations/providers/github/github.d.ts +0 -1
  101. package/dist/plus/integrations/providers/github/github.js +1 -1
  102. package/dist/plus/integrations/providers/github/github.js.map +1 -1
  103. package/dist/plus/integrations/providers/github.d.ts +11 -6
  104. package/dist/plus/integrations/providers/github.js +70 -26
  105. package/dist/plus/integrations/providers/github.js.map +1 -1
  106. package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +2 -2
  107. package/dist/plus/integrations/providers/gitlab/gitlab.js +1 -2
  108. package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
  109. package/dist/plus/integrations/providers/gitlab/gitlab.utils.d.ts +14 -1
  110. package/dist/plus/integrations/providers/gitlab/gitlab.utils.js.map +1 -1
  111. package/dist/plus/integrations/providers/gitlab/models.d.ts +2 -10
  112. package/dist/plus/integrations/providers/gitlab/models.js.map +1 -1
  113. package/dist/plus/integrations/providers/gitlab.d.ts +7 -5
  114. package/dist/plus/integrations/providers/gitlab.js +2 -1
  115. package/dist/plus/integrations/providers/gitlab.js.map +1 -1
  116. package/dist/plus/integrations/providers/jira-server.d.ts +4 -4
  117. package/dist/plus/integrations/providers/jira-server.js +3 -2
  118. package/dist/plus/integrations/providers/jira-server.js.map +1 -1
  119. package/dist/plus/integrations/providers/jira.d.ts +3 -3
  120. package/dist/plus/integrations/providers/jira.js +3 -2
  121. package/dist/plus/integrations/providers/jira.js.map +1 -1
  122. package/dist/plus/integrations/providers/jiraIssueByKey.d.ts +1 -1
  123. package/dist/plus/integrations/providers/jiraIssueByKey.js.map +1 -1
  124. package/dist/plus/integrations/providers/linear.d.ts +4 -3
  125. package/dist/plus/integrations/providers/linear.js +3 -2
  126. package/dist/plus/integrations/providers/linear.js.map +1 -1
  127. package/dist/plus/integrations/providers/linearIssuesEtag.d.ts +1 -1
  128. package/dist/plus/integrations/providers/linearIssuesEtag.js +1 -1
  129. package/dist/plus/integrations/providers/linearIssuesEtag.js.map +1 -1
  130. package/dist/plus/integrations/providers/metadata.d.ts +136 -0
  131. package/dist/plus/integrations/providers/metadata.js +513 -0
  132. package/dist/plus/integrations/providers/metadata.js.map +1 -0
  133. package/dist/plus/integrations/providers/models.d.ts +10 -206
  134. package/dist/plus/integrations/providers/models.js +8 -539
  135. package/dist/plus/integrations/providers/models.js.map +1 -1
  136. package/dist/plus/integrations/providers/providersApi.d.ts +3 -2
  137. package/dist/plus/integrations/providers/providersApi.js +2 -1
  138. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  139. package/dist/plus/integrations/providers/trello.d.ts +1 -1
  140. package/dist/plus/integrations/providers/trello.js +2 -1
  141. package/dist/plus/integrations/providers/trello.js.map +1 -1
  142. package/dist/plus/integrations/providers/utils/providerPaging.d.ts +2 -0
  143. package/dist/plus/integrations/providers/utils/providerPaging.js +3 -2
  144. package/dist/plus/integrations/providers/utils/providerPaging.js.map +1 -1
  145. package/dist/plus/integrations/providers/utils.d.ts +119 -10
  146. package/dist/plus/integrations/providers/utils.js +57 -3
  147. package/dist/plus/integrations/providers/utils.js.map +1 -1
  148. package/dist/plus/integrations/reads/autolinks.d.ts +1 -1
  149. package/dist/plus/integrations/reads/autolinks.js +1 -1
  150. package/dist/plus/integrations/reads/autolinks.js.map +1 -1
  151. package/dist/plus/integrations/reads/broaden.d.ts +1 -1
  152. package/dist/plus/integrations/reads/broaden.js +3 -2
  153. package/dist/plus/integrations/reads/broaden.js.map +1 -1
  154. package/dist/plus/integrations/reads/context.d.ts +1 -1
  155. package/dist/plus/integrations/reads/counts.d.ts +1 -88
  156. package/dist/plus/integrations/reads/counts.js +4 -2
  157. package/dist/plus/integrations/reads/counts.js.map +1 -1
  158. package/dist/plus/integrations/reads/currentAccount.d.ts +1 -18
  159. package/dist/plus/integrations/reads/currentAccount.js.map +1 -1
  160. package/dist/plus/integrations/reads/drains.d.ts +3 -3
  161. package/dist/plus/integrations/reads/drains.js +1 -1
  162. package/dist/plus/integrations/reads/drains.js.map +1 -1
  163. package/dist/plus/integrations/reads/etag.d.ts +174 -3
  164. package/dist/plus/integrations/reads/etag.js +69 -14
  165. package/dist/plus/integrations/reads/etag.js.map +1 -1
  166. package/dist/plus/integrations/reads/filters.d.ts +3 -61
  167. package/dist/plus/integrations/reads/filters.js +1 -1
  168. package/dist/plus/integrations/reads/filters.js.map +1 -1
  169. package/dist/plus/integrations/reads/hierarchy.d.ts +1 -1
  170. package/dist/plus/integrations/reads/hierarchy.js +4 -2
  171. package/dist/plus/integrations/reads/hierarchy.js.map +1 -1
  172. package/dist/plus/integrations/reads/issueBatch.d.ts +2 -102
  173. package/dist/plus/integrations/reads/issueBatch.js +3 -4
  174. package/dist/plus/integrations/reads/issueBatch.js.map +1 -1
  175. package/dist/plus/integrations/reads/issueTracker.d.ts +1 -1
  176. package/dist/plus/integrations/reads/issueTracker.js +4 -3
  177. package/dist/plus/integrations/reads/issueTracker.js.map +1 -1
  178. package/dist/plus/integrations/reads/issues.d.ts +1 -1
  179. package/dist/plus/integrations/reads/issues.js +4 -2
  180. package/dist/plus/integrations/reads/issues.js.map +1 -1
  181. package/dist/plus/integrations/reads/paging.d.ts +1 -1
  182. package/dist/plus/integrations/reads/paging.js +1 -1
  183. package/dist/plus/integrations/reads/paging.js.map +1 -1
  184. package/dist/plus/integrations/reads/pullRequestActivity.d.ts +1 -24
  185. package/dist/plus/integrations/reads/pullRequestActivity.js +2 -1
  186. package/dist/plus/integrations/reads/pullRequestActivity.js.map +1 -1
  187. package/dist/plus/integrations/reads/pullRequestBatch.d.ts +2 -56
  188. package/dist/plus/integrations/reads/pullRequestBatch.js +23 -3
  189. package/dist/plus/integrations/reads/pullRequestBatch.js.map +1 -1
  190. package/dist/plus/integrations/reads/pullRequestBranches.d.ts +1 -47
  191. package/dist/plus/integrations/reads/pullRequestBranches.js +2 -1
  192. package/dist/plus/integrations/reads/pullRequestBranches.js.map +1 -1
  193. package/dist/plus/integrations/reads/pullRequestCheckLogs.d.ts +1 -15
  194. package/dist/plus/integrations/reads/pullRequestCheckLogs.js +2 -1
  195. package/dist/plus/integrations/reads/pullRequestCheckLogs.js.map +1 -1
  196. package/dist/plus/integrations/reads/pullRequests.js +4 -2
  197. package/dist/plus/integrations/reads/pullRequests.js.map +1 -1
  198. package/dist/plus/integrations/reads/pullRequestsForCommits.d.ts +1 -16
  199. package/dist/plus/integrations/reads/pullRequestsForCommits.js +2 -1
  200. package/dist/plus/integrations/reads/pullRequestsForCommits.js.map +1 -1
  201. package/dist/plus/integrations/reads/resolveRepository.js +10 -5
  202. package/dist/plus/integrations/reads/resolveRepository.js.map +1 -1
  203. package/dist/plus/integrations/reads/searchIssues.js +2 -1
  204. package/dist/plus/integrations/reads/searchIssues.js.map +1 -1
  205. package/dist/plus/integrations/reads/searchPullRequests.js +2 -1
  206. package/dist/plus/integrations/reads/searchPullRequests.js.map +1 -1
  207. package/dist/plus/integrations/reads/sweeps.d.ts +1 -1
  208. package/dist/plus/integrations/reads/sweeps.js +3 -2
  209. package/dist/plus/integrations/reads/sweeps.js.map +1 -1
  210. package/dist/plus/integrations/reads/warnings.d.ts +1 -1
  211. package/dist/plus/integrations/reads/warnings.js +1 -1
  212. package/dist/plus/integrations/reads/warnings.js.map +1 -1
  213. package/dist/plus/integrations/results.d.ts +324 -2
  214. package/dist/plus/integrations/results.js.map +1 -1
  215. package/dist/plus/integrations/telemetry.d.ts +0 -10
  216. package/dist/plus/integrations/telemetry.js +0 -11
  217. package/dist/plus/integrations/utils/domain.utils.d.ts +1 -0
  218. package/dist/plus/integrations/utils/domain.utils.js +10 -2
  219. package/dist/plus/integrations/utils/domain.utils.js.map +1 -1
  220. package/dist/plus/integrations/utils/integration.utils.d.ts +1 -6
  221. package/dist/plus/integrations/utils/integration.utils.js +2 -9
  222. package/dist/plus/integrations/utils/integration.utils.js.map +1 -1
  223. package/dist/utils/keys/chord.d.ts +13 -2
  224. package/dist/utils/keys/chord.js +76 -17
  225. package/dist/utils/keys/chord.js.map +1 -1
  226. package/dist/utils/keys/keybinding.d.ts +12 -0
  227. package/dist/utils/keys/keybinding.js +52 -2
  228. package/dist/utils/keys/keybinding.js.map +1 -1
  229. package/dist/utils/markdown.d.ts +21 -0
  230. package/dist/utils/markdown.js +33 -1
  231. package/dist/utils/markdown.js.map +1 -1
  232. package/docs/integrations.md +99 -16
  233. package/package.json +5 -1
  234. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js.map +0 -1
  235. package/dist/plus/integrations/telemetry.js.map +0 -1
@@ -40,6 +40,8 @@ export type IssueWriteResult = {
40
40
  } | {
41
41
  ok: false;
42
42
  reason: 'unsupported' | 'no-connection' | 'forbidden' | 'not-found' | 'invalid-input' | 'rate-limit' | 'unknown';
43
+ /** An unconfirmed result that failed before the mutation could be sent. */
44
+ mutationDispatched?: false;
43
45
  };
44
46
  export type GitHubIssueMutation = GitHubIssueWrite | (GitHubIssueDelete & {
45
47
  action: 'delete';
@@ -52,6 +54,9 @@ export declare function isValidGitHubIssueMutation(input: GitHubIssueMutation):
52
54
  export declare function issueWriteFailure(ex: unknown): Extract<IssueWriteResult, {
53
55
  ok: false;
54
56
  }>;
55
- export declare function mutateGitHubIssue(input: GitHubIssueMutation, graphql: GraphqlRequest): Promise<IssueWriteResult>;
57
+ export declare function mutateGitHubIssue(input: GitHubIssueMutation, graphql: GraphqlRequest, { origin, isSessionCurrent }: {
58
+ origin?: string;
59
+ isSessionCurrent?: () => Promise<boolean>;
60
+ }): Promise<IssueWriteResult>;
56
61
  //#endregion
57
62
  //# sourceMappingURL=issueWrites.d.ts.map
@@ -77,9 +77,15 @@ function issueWriteFailure(ex) {
77
77
  reason: "unknown"
78
78
  };
79
79
  }
80
- async function mutateGitHubIssue(input, graphql) {
80
+ async function mutateGitHubIssue(input, graphql, { origin, isSessionCurrent }) {
81
+ let dispatched = false;
82
+ const mutate = (query, variables) => {
83
+ dispatched = true;
84
+ return graphql(query, variables);
85
+ };
81
86
  try {
82
87
  const { owner, repo } = input;
88
+ const checkDelete = input.action === "delete" || input.action === "resolve" && input.intent === "delete";
83
89
  const target = input.action === "create" ? await graphql(`
84
90
  query IssueCreateTarget($owner: String!, $repo: String!) {
85
91
  repository(owner: $owner, name: $repo, followRenames: false) {
@@ -91,7 +97,7 @@ async function mutateGitHubIssue(input, graphql) {
91
97
  `, {
92
98
  owner,
93
99
  repo
94
- }) : await graphql(`query IssueWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!, $checkDelete: Boolean!) {
100
+ }) : await graphql(`query IssueWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!) {
95
101
  repository(owner: $owner, name: $repo, followRenames: false) {
96
102
  id hasIssuesEnabled isArchived
97
103
  }
@@ -99,14 +105,13 @@ async function mutateGitHubIssue(input, graphql) {
99
105
  __typename
100
106
  ... on Issue {
101
107
  ${issueFields}
102
- viewerCanDelete @include(if: $checkDelete)
108
+ ${checkDelete ? "viewerCanDelete" : ""}
103
109
  }
104
110
  }
105
111
  }`, {
106
112
  owner,
107
113
  repo,
108
- expectedNodeId: input.expectedNodeId,
109
- checkDelete: input.action === "delete" || input.action === "resolve" && input.intent === "delete"
114
+ expectedNodeId: input.expectedNodeId
110
115
  });
111
116
  const repository = target?.repository;
112
117
  if (repository == null) return {
@@ -121,38 +126,43 @@ async function mutateGitHubIssue(input, graphql) {
121
126
  ok: false,
122
127
  reason: "unsupported"
123
128
  };
124
- if (input.action === "create") return await writeIssue(graphql, "createIssue", "CreateIssueInput", {
125
- repositoryId: repository.id,
126
- title: input.title,
127
- body: input.body
128
- });
129
+ if (input.action === "create") {
130
+ if (isSessionCurrent != null && !await isSessionCurrent()) return {
131
+ ok: false,
132
+ reason: "no-connection"
133
+ };
134
+ return await writeIssue(mutate, "createIssue", "CreateIssueInput", {
135
+ repositoryId: repository.id,
136
+ title: input.title,
137
+ body: input.body
138
+ }, origin);
139
+ }
129
140
  const issue = target?.node;
130
- if (issue?.__typename !== "Issue" || issue.number !== input.number || issue.repository.id !== repository.id || issue.repository.owner.login.toLowerCase() !== owner.toLowerCase() || issue.repository.name.toLowerCase() !== repo.toLowerCase()) return {
141
+ if (issue?.__typename !== "Issue" || !isIssueOnInstallation(issue, origin) || issue.number !== input.number || issue.repository.id !== repository.id || issue.repository.owner.login.toLowerCase() !== owner.toLowerCase() || issue.repository.name.toLowerCase() !== repo.toLowerCase()) return {
131
142
  ok: false,
132
143
  reason: "not-found"
133
144
  };
145
+ if (checkDelete && issue.viewerCanDelete !== true) return {
146
+ ok: false,
147
+ reason: "forbidden"
148
+ };
149
+ if (input.action === "resolve") return toIssueWriteResult(issue);
150
+ if (isSessionCurrent != null && !await isSessionCurrent()) return {
151
+ ok: false,
152
+ reason: "no-connection"
153
+ };
134
154
  switch (input.action) {
135
- case "resolve":
136
- if (input.intent === "delete" && issue.viewerCanDelete !== true) return {
137
- ok: false,
138
- reason: "forbidden"
139
- };
140
- return toIssueWriteResult(issue);
141
- case "edit": return await writeIssue(graphql, "updateIssue", "UpdateIssueInput", {
155
+ case "edit": return await writeIssue(mutate, "updateIssue", "UpdateIssueInput", {
142
156
  id: issue.id,
143
157
  title: input.title,
144
158
  body: input.body
145
- });
146
- case "set-state": return input.state === "open" ? await writeIssue(graphql, "reopenIssue", "ReopenIssueInput", { issueId: issue.id }) : await writeIssue(graphql, "closeIssue", "CloseIssueInput", {
159
+ }, origin);
160
+ case "set-state": return input.state === "open" ? await writeIssue(mutate, "reopenIssue", "ReopenIssueInput", { issueId: issue.id }, origin) : await writeIssue(mutate, "closeIssue", "CloseIssueInput", {
147
161
  issueId: issue.id,
148
162
  stateReason: input.reason === "completed" ? "COMPLETED" : "NOT_PLANNED"
149
- });
163
+ }, origin);
150
164
  case "delete": {
151
- if (issue.viewerCanDelete !== true) return {
152
- ok: false,
153
- reason: "forbidden"
154
- };
155
- const deletedRepositoryId = (await graphql(`
165
+ const deletedRepositoryId = (await mutate(`
156
166
  mutation DeleteIssue($issueId: ID!) {
157
167
  deleteIssue(input: { issueId: $issueId }) {
158
168
  repository {
@@ -168,18 +178,38 @@ async function mutateGitHubIssue(input, graphql) {
168
178
  }
169
179
  }
170
180
  } catch (ex) {
171
- return issueWriteFailure(ex);
181
+ if (origin != null && ex instanceof GraphqlResponseError && ex.data == null && ex.errors?.some((error) => {
182
+ const code = error.extensions?.code;
183
+ return code === "undefinedField" || code === "argumentNotAccepted" || code === "variableRequiresValidType";
184
+ })) return {
185
+ ok: false,
186
+ reason: "unsupported"
187
+ };
188
+ if (dispatched && ex instanceof GraphqlResponseError && ex.errors?.some((error) => error.path != null && error.path.length > 1)) return {
189
+ ok: false,
190
+ reason: "unknown"
191
+ };
192
+ const failure = issueWriteFailure(ex);
193
+ return origin != null && failure.reason === "unknown" && !dispatched ? {
194
+ ...failure,
195
+ mutationDispatched: false
196
+ } : failure;
172
197
  }
173
198
  }
174
- async function writeIssue(graphql, mutation, inputType, input) {
175
- const result = await graphql(`mutation WriteIssue($input: ${inputType}!) {
199
+ async function writeIssue(graphql, mutation, inputType, input, origin) {
200
+ const issue = (await graphql(`mutation WriteIssue($input: ${inputType}!) {
176
201
  change: ${mutation}(input: $input) { issue { ${issueFields} } }
177
- }`, { input });
178
- return result?.change?.issue != null ? toIssueWriteResult(result.change.issue) : {
202
+ }`, { input }))?.change?.issue;
203
+ return issue != null && isIssueOnInstallation(issue, origin) ? toIssueWriteResult(issue) : {
179
204
  ok: false,
180
205
  reason: "unknown"
181
206
  };
182
207
  }
208
+ function isIssueOnInstallation(issue, origin) {
209
+ if (origin == null) return true;
210
+ const url = typeof issue.url === "string" ? URL.parse(issue.url) : null;
211
+ return url?.origin === origin && (url.protocol === "https:" || url.protocol === "http:") && !url.username && !url.password;
212
+ }
183
213
  function toIssueWriteResult(issue, deletedFromDifferentRepository = false) {
184
214
  return {
185
215
  ok: true,
@@ -1 +1 @@
1
- {"version":3,"file":"issueWrites.js","names":[],"sources":["../../../../../plus/git-github/src/api/issueWrites.ts"],"sourcesContent":["import { GraphqlResponseError } from '@octokit/graphql';\nimport { RequestError } from '@octokit/request-error';\nimport type { RequestParameters } from '@octokit/types';\nimport { RequestRateLimitError } from '@gitlens/git/errors.js';\n\ntype GitHubIssueWriteTarget = { owner: string; repo: string };\n\nexport type GitHubIssueDelete = GitHubIssueWriteTarget & { number: number; expectedNodeId: string };\n\nexport type GitHubIssueWrite =\n\t| (GitHubIssueWriteTarget & { action: 'create'; title: string; body?: string })\n\t| (GitHubIssueDelete &\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' }\n\t\t\t\t| { action: 'set-state'; state: 'closed'; reason: 'completed' | 'not_planned' }\n\t\t\t));\n\nexport type IssueWriteResult =\n\t| {\n\t\t\tok: true;\n\t\t\tissue: {\n\t\t\t\towner: string;\n\t\t\t\trepo: string;\n\t\t\t\tnumber: number;\n\t\t\t\tnodeId: string;\n\t\t\t\turl: string;\n\t\t\t\ttitle: string;\n\t\t\t\tbody: string;\n\t\t\t\tstate: 'open' | 'closed';\n\t\t\t};\n\t\t\tdeletedFromDifferentRepository?: true;\n\t }\n\t| {\n\t\t\tok: false;\n\t\t\treason:\n\t\t\t\t| 'unsupported'\n\t\t\t\t| 'no-connection'\n\t\t\t\t| 'forbidden'\n\t\t\t\t| 'not-found'\n\t\t\t\t| 'invalid-input'\n\t\t\t\t| 'rate-limit'\n\t\t\t\t| 'unknown';\n\t };\n\nexport type GitHubIssueMutation =\n\t| GitHubIssueWrite\n\t| (GitHubIssueDelete & { action: 'delete' })\n\t| (GitHubIssueDelete & { action: 'resolve'; intent?: 'delete' });\ntype GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;\n\nconst issueFields = `\n\tid number url title body state\n\trepository { id owner { login } name }\n`;\n\ntype IssueNode = {\n\tid: string;\n\tnumber: number;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'OPEN' | 'CLOSED';\n\trepository: { id: string; owner: { login: string }; name: string };\n};\n\ntype RepositoryNode = {\n\tid: string;\n\thasIssuesEnabled: boolean;\n\tisArchived: boolean;\n};\n\ntype WriteTarget = {\n\trepository: RepositoryNode | null;\n\tnode?: (IssueNode & { __typename: string; viewerCanDelete?: boolean }) | null;\n};\n\nexport function isValidGitHubIssueMutation(input: GitHubIssueMutation): boolean {\n\tif (\n\t\ttypeof input.owner !== 'string' ||\n\t\t!/^[a-z\\d_-]+$/i.test(input.owner) ||\n\t\ttypeof input.repo !== 'string' ||\n\t\t!/^[a-z\\d._-]+$/i.test(input.repo) ||\n\t\tinput.repo === '.' ||\n\t\tinput.repo === '..'\n\t) {\n\t\treturn false;\n\t}\n\n\tif (\n\t\tinput.action !== 'create' &&\n\t\t(!Number.isInteger(input.number) ||\n\t\t\tinput.number < 1 ||\n\t\t\tinput.number > 2147483647 ||\n\t\t\ttypeof input.expectedNodeId !== 'string' ||\n\t\t\t!input.expectedNodeId.trim())\n\t) {\n\t\treturn false;\n\t}\n\n\tswitch (input.action) {\n\t\tcase 'create':\n\t\t\treturn isIssueTitle(input.title) && (input.body === undefined || typeof input.body === 'string');\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 || isIssueTitle(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 (\n\t\t\t\tinput.state === 'open' ||\n\t\t\t\t(input.state === 'closed' && (input.reason === 'completed' || input.reason === 'not_planned'))\n\t\t\t);\n\t\tcase 'delete':\n\t\t\treturn true;\n\t\tcase 'resolve':\n\t\t\treturn input.intent === undefined || input.intent === 'delete';\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isIssueTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nexport function issueWriteFailure(ex: unknown): Extract<IssueWriteResult, { ok: false }> {\n\tif (RequestRateLimitError.is(ex)) return { ok: false, reason: 'rate-limit' };\n\n\tif (ex instanceof GraphqlResponseError) {\n\t\tif (ex.errors?.some(error => error.type === 'RATE_LIMIT' || error.type === 'RATE_LIMITED')) {\n\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\n\t\tswitch (ex.errors?.[0]?.type) {\n\t\t\tcase 'NOT_FOUND':\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 'FORBIDDEN':\n\t\t\tcase 'INSUFFICIENT_SCOPES':\n\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\tcase 'BAD_USER_INPUT':\n\t\t\tcase 'UNPROCESSABLE':\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t}\n\t}\n\n\tif (ex instanceof RequestError) {\n\t\tswitch (ex.status) {\n\t\t\tcase 400:\n\t\t\tcase 422:\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t\tcase 401:\n\t\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t\tcase 403:\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\treason: ex.message.toLowerCase().includes('rate limit') ? 'rate-limit' : 'forbidden',\n\t\t\t\t};\n\t\t\tcase 404:\n\t\t\tcase 410:\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 429:\n\t\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\t}\n\n\treturn { ok: false, reason: 'unknown' };\n}\n\nexport async function mutateGitHubIssue(\n\tinput: GitHubIssueMutation,\n\tgraphql: GraphqlRequest,\n): Promise<IssueWriteResult> {\n\ttry {\n\t\tconst { owner, repo } = input;\n\t\tconst target =\n\t\t\tinput.action === 'create'\n\t\t\t\t? await graphql<WriteTarget>(\n\t\t\t\t\t\t`\n\t\t\t\t\t\t\tquery IssueCreateTarget($owner: String!, $repo: String!) {\n\t\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t\thasIssuesEnabled\n\t\t\t\t\t\t\t\t\tisArchived\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\t{ owner: owner, repo: repo },\n\t\t\t\t\t)\n\t\t\t\t: await graphql<WriteTarget>(\n\t\t\t\t\t\t`query IssueWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!, $checkDelete: Boolean!) {\n\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\tid hasIssuesEnabled isArchived\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnode(id: $expectedNodeId) {\n\t\t\t\t\t\t\t\t__typename\n\t\t\t\t\t\t\t\t... on Issue {\n\t\t\t\t\t\t\t\t\t${issueFields}\n\t\t\t\t\t\t\t\t\tviewerCanDelete @include(if: $checkDelete)\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\t{\n\t\t\t\t\t\t\towner: owner,\n\t\t\t\t\t\t\trepo: repo,\n\t\t\t\t\t\t\texpectedNodeId: input.expectedNodeId,\n\t\t\t\t\t\t\tcheckDelete:\n\t\t\t\t\t\t\t\tinput.action === 'delete' || (input.action === 'resolve' && input.intent === 'delete'),\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\tconst repository = target?.repository;\n\t\tif (repository == null) return { ok: false, reason: 'not-found' };\n\t\tif (repository.isArchived) return { ok: false, reason: 'forbidden' };\n\t\tif (!repository.hasIssuesEnabled) return { ok: false, reason: 'unsupported' };\n\n\t\tif (input.action === 'create') {\n\t\t\treturn await writeIssue(graphql, 'createIssue', 'CreateIssueInput', {\n\t\t\t\trepositoryId: repository.id,\n\t\t\t\ttitle: input.title,\n\t\t\t\tbody: input.body,\n\t\t\t});\n\t\t}\n\n\t\tconst issue = target?.node;\n\t\tif (\n\t\t\tissue?.__typename !== 'Issue' ||\n\t\t\tissue.number !== input.number ||\n\t\t\tissue.repository.id !== repository.id ||\n\t\t\tissue.repository.owner.login.toLowerCase() !== owner.toLowerCase() ||\n\t\t\tissue.repository.name.toLowerCase() !== repo.toLowerCase()\n\t\t) {\n\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t}\n\n\t\tswitch (input.action) {\n\t\t\tcase 'resolve':\n\t\t\t\tif (input.intent === 'delete' && issue.viewerCanDelete !== true) {\n\t\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\t\t}\n\t\t\t\treturn toIssueWriteResult(issue);\n\t\t\tcase 'edit':\n\t\t\t\treturn await writeIssue(graphql, 'updateIssue', 'UpdateIssueInput', {\n\t\t\t\t\tid: issue.id,\n\t\t\t\t\ttitle: input.title,\n\t\t\t\t\tbody: input.body,\n\t\t\t\t});\n\t\t\tcase 'set-state':\n\t\t\t\treturn input.state === 'open'\n\t\t\t\t\t? await writeIssue(graphql, 'reopenIssue', 'ReopenIssueInput', { issueId: issue.id })\n\t\t\t\t\t: await writeIssue(graphql, 'closeIssue', 'CloseIssueInput', {\n\t\t\t\t\t\t\tissueId: issue.id,\n\t\t\t\t\t\t\tstateReason: input.reason === 'completed' ? 'COMPLETED' : 'NOT_PLANNED',\n\t\t\t\t\t\t});\n\t\t\tcase 'delete': {\n\t\t\t\tif (issue.viewerCanDelete !== true) return { ok: false, reason: 'forbidden' };\n\n\t\t\t\tconst result = await graphql<{ deleteIssue: { repository: { id: string } | null } | null }>(\n\t\t\t\t\t`\n\t\t\t\t\t\tmutation DeleteIssue($issueId: ID!) {\n\t\t\t\t\t\t\tdeleteIssue(input: { issueId: $issueId }) {\n\t\t\t\t\t\t\t\trepository {\n\t\t\t\t\t\t\t\t\tid\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\t{ issueId: issue.id },\n\t\t\t\t);\n\t\t\t\tconst deletedRepositoryId = result?.deleteIssue?.repository?.id;\n\t\t\t\treturn typeof deletedRepositoryId === 'string' && deletedRepositoryId.length > 0\n\t\t\t\t\t? toIssueWriteResult(issue, deletedRepositoryId !== repository.id)\n\t\t\t\t\t: { ok: false, reason: 'unknown' };\n\t\t\t}\n\t\t}\n\t} catch (ex) {\n\t\treturn issueWriteFailure(ex);\n\t}\n}\n\nasync function writeIssue(\n\tgraphql: GraphqlRequest,\n\tmutation: 'createIssue' | 'updateIssue' | 'closeIssue' | 'reopenIssue',\n\tinputType: string,\n\tinput: Record<string, string | undefined>,\n): Promise<IssueWriteResult> {\n\tconst result = await graphql<{ change: { issue: IssueNode | null } | null }>(\n\t\t`mutation WriteIssue($input: ${inputType}!) {\n\t\t\tchange: ${mutation}(input: $input) { issue { ${issueFields} } }\n\t\t}`,\n\t\t{ input: input },\n\t);\n\treturn result?.change?.issue != null ? toIssueWriteResult(result.change.issue) : { ok: false, reason: 'unknown' };\n}\n\nfunction toIssueWriteResult(issue: IssueNode, deletedFromDifferentRepository = false): IssueWriteResult {\n\treturn {\n\t\tok: true,\n\t\t...(deletedFromDifferentRepository && { deletedFromDifferentRepository: true }),\n\t\tissue: {\n\t\t\towner: issue.repository.owner.login,\n\t\t\trepo: issue.repository.name,\n\t\t\tnumber: issue.number,\n\t\t\tnodeId: issue.id,\n\t\t\turl: issue.url,\n\t\t\ttitle: issue.title,\n\t\t\tbody: issue.body,\n\t\t\tstate: issue.state === 'CLOSED' ? 'closed' : 'open',\n\t\t},\n\t};\n}\n"],"mappings":";;;;AAmDA,MAAM,cAAc;;;;AA0BpB,SAAgB,2BAA2B,OAAqC;CAC/E,IACC,OAAO,MAAM,UAAU,YACvB,CAAC,gBAAgB,KAAK,MAAM,KAAK,KACjC,OAAO,MAAM,SAAS,YACtB,CAAC,iBAAiB,KAAK,M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B,OAAO,OAAO,KAAK,IAAI;EAAE,IAAI;EAAO,QAAQ;CAAU;AACjH;AAEA,SAAS,mBAAmB,OAAkB,iCAAiC,OAAyB;CACvG,OAAO;EACN,IAAI;EACJ,GAAI,kCAAkC,EAAE,gCAAgC,KAAK;EAC7E,OAAO;GACN,OAAO,MAAM,WAAW,MAAM;GAC9B,MAAM,MAAM,WAAW;GACvB,QAAQ,MAAM;GACd,QAAQ,MAAM;GACd,KAAK,MAAM;GACX,OAAO,MAAM;GACb,MAAM,MAAM;GACZ,OAAO,MAAM,UAAU,WAAW,WAAW;EAC9C;CACD;AACD"}
1
+ {"version":3,"file":"issueWrites.js","names":[],"sources":["../../../../../plus/git-github/src/api/issueWrites.ts"],"sourcesContent":["import { GraphqlResponseError } from '@octokit/graphql';\nimport { RequestError } from '@octokit/request-error';\nimport type { RequestParameters } from '@octokit/types';\nimport { RequestRateLimitError } from '@gitlens/git/errors.js';\n\ntype GitHubIssueWriteTarget = { owner: string; repo: string };\n\nexport type GitHubIssueDelete = GitHubIssueWriteTarget & { number: number; expectedNodeId: string };\n\nexport type GitHubIssueWrite =\n\t| (GitHubIssueWriteTarget & { action: 'create'; title: string; body?: string })\n\t| (GitHubIssueDelete &\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' }\n\t\t\t\t| { action: 'set-state'; state: 'closed'; reason: 'completed' | 'not_planned' }\n\t\t\t));\n\nexport type IssueWriteResult =\n\t| {\n\t\t\tok: true;\n\t\t\tissue: {\n\t\t\t\towner: string;\n\t\t\t\trepo: string;\n\t\t\t\tnumber: number;\n\t\t\t\tnodeId: string;\n\t\t\t\turl: string;\n\t\t\t\ttitle: string;\n\t\t\t\tbody: string;\n\t\t\t\tstate: 'open' | 'closed';\n\t\t\t};\n\t\t\tdeletedFromDifferentRepository?: true;\n\t }\n\t| {\n\t\t\tok: false;\n\t\t\treason:\n\t\t\t\t| 'unsupported'\n\t\t\t\t| 'no-connection'\n\t\t\t\t| 'forbidden'\n\t\t\t\t| 'not-found'\n\t\t\t\t| 'invalid-input'\n\t\t\t\t| 'rate-limit'\n\t\t\t\t| 'unknown';\n\t\t\t/** An unconfirmed result that failed before the mutation could be sent. */\n\t\t\tmutationDispatched?: false;\n\t };\n\nexport type GitHubIssueMutation =\n\t| GitHubIssueWrite\n\t| (GitHubIssueDelete & { action: 'delete' })\n\t| (GitHubIssueDelete & { action: 'resolve'; intent?: 'delete' });\ntype GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;\n\nconst issueFields = `\n\tid number url title body state\n\trepository { id owner { login } name }\n`;\n\ntype IssueNode = {\n\tid: string;\n\tnumber: number;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'OPEN' | 'CLOSED';\n\trepository: { id: string; owner: { login: string }; name: string };\n};\n\ntype RepositoryNode = {\n\tid: string;\n\thasIssuesEnabled: boolean;\n\tisArchived: boolean;\n};\n\ntype WriteTarget = {\n\trepository: RepositoryNode | null;\n\tnode?: (IssueNode & { __typename: string; viewerCanDelete?: boolean }) | null;\n};\n\nexport function isValidGitHubIssueMutation(input: GitHubIssueMutation): boolean {\n\tif (\n\t\ttypeof input.owner !== 'string' ||\n\t\t!/^[a-z\\d_-]+$/i.test(input.owner) ||\n\t\ttypeof input.repo !== 'string' ||\n\t\t!/^[a-z\\d._-]+$/i.test(input.repo) ||\n\t\tinput.repo === '.' ||\n\t\tinput.repo === '..'\n\t) {\n\t\treturn false;\n\t}\n\n\tif (\n\t\tinput.action !== 'create' &&\n\t\t(!Number.isInteger(input.number) ||\n\t\t\tinput.number < 1 ||\n\t\t\tinput.number > 2147483647 ||\n\t\t\ttypeof input.expectedNodeId !== 'string' ||\n\t\t\t!input.expectedNodeId.trim())\n\t) {\n\t\treturn false;\n\t}\n\n\tswitch (input.action) {\n\t\tcase 'create':\n\t\t\treturn isIssueTitle(input.title) && (input.body === undefined || typeof input.body === 'string');\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 || isIssueTitle(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 (\n\t\t\t\tinput.state === 'open' ||\n\t\t\t\t(input.state === 'closed' && (input.reason === 'completed' || input.reason === 'not_planned'))\n\t\t\t);\n\t\tcase 'delete':\n\t\t\treturn true;\n\t\tcase 'resolve':\n\t\t\treturn input.intent === undefined || input.intent === 'delete';\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isIssueTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nexport function issueWriteFailure(ex: unknown): Extract<IssueWriteResult, { ok: false }> {\n\tif (RequestRateLimitError.is(ex)) return { ok: false, reason: 'rate-limit' };\n\n\tif (ex instanceof GraphqlResponseError) {\n\t\tif (ex.errors?.some(error => error.type === 'RATE_LIMIT' || error.type === 'RATE_LIMITED')) {\n\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\n\t\tswitch (ex.errors?.[0]?.type) {\n\t\t\tcase 'NOT_FOUND':\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 'FORBIDDEN':\n\t\t\tcase 'INSUFFICIENT_SCOPES':\n\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\tcase 'BAD_USER_INPUT':\n\t\t\tcase 'UNPROCESSABLE':\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t}\n\t}\n\n\tif (ex instanceof RequestError) {\n\t\tswitch (ex.status) {\n\t\t\tcase 400:\n\t\t\tcase 422:\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t\tcase 401:\n\t\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t\tcase 403:\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\treason: ex.message.toLowerCase().includes('rate limit') ? 'rate-limit' : 'forbidden',\n\t\t\t\t};\n\t\t\tcase 404:\n\t\t\tcase 410:\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 429:\n\t\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\t}\n\n\treturn { ok: false, reason: 'unknown' };\n}\n\nexport async function mutateGitHubIssue(\n\tinput: GitHubIssueMutation,\n\tgraphql: GraphqlRequest,\n\t{ origin, isSessionCurrent }: { origin?: string; isSessionCurrent?: () => Promise<boolean> },\n): Promise<IssueWriteResult> {\n\tlet dispatched = false;\n\tconst mutate: GraphqlRequest = (query, variables) => {\n\t\tdispatched = true;\n\t\treturn graphql(query, variables);\n\t};\n\ttry {\n\t\tconst { owner, repo } = input;\n\t\tconst checkDelete = input.action === 'delete' || (input.action === 'resolve' && input.intent === 'delete');\n\t\tconst target =\n\t\t\tinput.action === 'create'\n\t\t\t\t? await graphql<WriteTarget>(\n\t\t\t\t\t\t`\n\t\t\t\t\t\t\tquery IssueCreateTarget($owner: String!, $repo: String!) {\n\t\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t\thasIssuesEnabled\n\t\t\t\t\t\t\t\t\tisArchived\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\t{ owner: owner, repo: repo },\n\t\t\t\t\t)\n\t\t\t\t: await graphql<WriteTarget>(\n\t\t\t\t\t\t`query IssueWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!) {\n\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\tid hasIssuesEnabled isArchived\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnode(id: $expectedNodeId) {\n\t\t\t\t\t\t\t\t__typename\n\t\t\t\t\t\t\t\t... on Issue {\n\t\t\t\t\t\t\t\t\t${issueFields}\n\t\t\t\t\t\t\t\t\t${checkDelete ? 'viewerCanDelete' : ''}\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\t{\n\t\t\t\t\t\t\towner: owner,\n\t\t\t\t\t\t\trepo: repo,\n\t\t\t\t\t\t\texpectedNodeId: input.expectedNodeId,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\tconst repository = target?.repository;\n\t\tif (repository == null) return { ok: false, reason: 'not-found' };\n\t\tif (repository.isArchived) return { ok: false, reason: 'forbidden' };\n\t\tif (!repository.hasIssuesEnabled) return { ok: false, reason: 'unsupported' };\n\n\t\tif (input.action === 'create') {\n\t\t\tif (isSessionCurrent != null && !(await isSessionCurrent())) {\n\t\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t\t}\n\n\t\t\treturn await writeIssue(\n\t\t\t\tmutate,\n\t\t\t\t'createIssue',\n\t\t\t\t'CreateIssueInput',\n\t\t\t\t{\n\t\t\t\t\trepositoryId: repository.id,\n\t\t\t\t\ttitle: input.title,\n\t\t\t\t\tbody: input.body,\n\t\t\t\t},\n\t\t\t\torigin,\n\t\t\t);\n\t\t}\n\n\t\tconst issue = target?.node;\n\t\tif (\n\t\t\tissue?.__typename !== 'Issue' ||\n\t\t\t!isIssueOnInstallation(issue, origin) ||\n\t\t\tissue.number !== input.number ||\n\t\t\tissue.repository.id !== repository.id ||\n\t\t\tissue.repository.owner.login.toLowerCase() !== owner.toLowerCase() ||\n\t\t\tissue.repository.name.toLowerCase() !== repo.toLowerCase()\n\t\t) {\n\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t}\n\n\t\tif (checkDelete && issue.viewerCanDelete !== true) return { ok: false, reason: 'forbidden' };\n\n\t\tif (input.action === 'resolve') return toIssueWriteResult(issue);\n\n\t\tif (isSessionCurrent != null && !(await isSessionCurrent())) {\n\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t}\n\n\t\tswitch (input.action) {\n\t\t\tcase 'edit':\n\t\t\t\treturn await writeIssue(\n\t\t\t\t\tmutate,\n\t\t\t\t\t'updateIssue',\n\t\t\t\t\t'UpdateIssueInput',\n\t\t\t\t\t{\n\t\t\t\t\t\tid: issue.id,\n\t\t\t\t\t\ttitle: input.title,\n\t\t\t\t\t\tbody: input.body,\n\t\t\t\t\t},\n\t\t\t\t\torigin,\n\t\t\t\t);\n\t\t\tcase 'set-state':\n\t\t\t\treturn input.state === 'open'\n\t\t\t\t\t? await writeIssue(mutate, 'reopenIssue', 'ReopenIssueInput', { issueId: issue.id }, origin)\n\t\t\t\t\t: await writeIssue(\n\t\t\t\t\t\t\tmutate,\n\t\t\t\t\t\t\t'closeIssue',\n\t\t\t\t\t\t\t'CloseIssueInput',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tissueId: issue.id,\n\t\t\t\t\t\t\t\tstateReason: input.reason === 'completed' ? 'COMPLETED' : 'NOT_PLANNED',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\torigin,\n\t\t\t\t\t\t);\n\t\t\tcase 'delete': {\n\t\t\t\tconst result = await mutate<{ deleteIssue: { repository: { id: string } | null } | null }>(\n\t\t\t\t\t`\n\t\t\t\t\t\tmutation DeleteIssue($issueId: ID!) {\n\t\t\t\t\t\t\tdeleteIssue(input: { issueId: $issueId }) {\n\t\t\t\t\t\t\t\trepository {\n\t\t\t\t\t\t\t\t\tid\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\t{ issueId: issue.id },\n\t\t\t\t);\n\t\t\t\tconst deletedRepositoryId = result?.deleteIssue?.repository?.id;\n\t\t\t\treturn typeof deletedRepositoryId === 'string' && deletedRepositoryId.length > 0\n\t\t\t\t\t? toIssueWriteResult(issue, deletedRepositoryId !== repository.id)\n\t\t\t\t\t: { ok: false, reason: 'unknown' };\n\t\t\t}\n\t\t}\n\t} catch (ex) {\n\t\tif (\n\t\t\torigin != null &&\n\t\t\tex instanceof GraphqlResponseError &&\n\t\t\tex.data == null &&\n\t\t\tex.errors?.some(error => {\n\t\t\t\tconst code: unknown = error.extensions?.code;\n\t\t\t\treturn (\n\t\t\t\t\tcode === 'undefinedField' || code === 'argumentNotAccepted' || code === 'variableRequiresValidType'\n\t\t\t\t);\n\t\t\t})\n\t\t) {\n\t\t\treturn { ok: false, reason: 'unsupported' };\n\t\t}\n\n\t\tif (\n\t\t\tdispatched &&\n\t\t\tex instanceof GraphqlResponseError &&\n\t\t\tex.errors?.some(error => error.path != null && error.path.length > 1)\n\t\t) {\n\t\t\treturn { ok: false, reason: 'unknown' };\n\t\t}\n\n\t\tconst failure = issueWriteFailure(ex);\n\t\treturn origin != null && failure.reason === 'unknown' && !dispatched\n\t\t\t? { ...failure, mutationDispatched: false }\n\t\t\t: failure;\n\t}\n}\n\nasync function writeIssue(\n\tgraphql: GraphqlRequest,\n\tmutation: 'createIssue' | 'updateIssue' | 'closeIssue' | 'reopenIssue',\n\tinputType: string,\n\tinput: Record<string, string | undefined>,\n\torigin: string | undefined,\n): Promise<IssueWriteResult> {\n\tconst result = await graphql<{ change: { issue: IssueNode | null } | null }>(\n\t\t`mutation WriteIssue($input: ${inputType}!) {\n\t\t\tchange: ${mutation}(input: $input) { issue { ${issueFields} } }\n\t\t}`,\n\t\t{ input: input },\n\t);\n\tconst issue = result?.change?.issue;\n\treturn issue != null && isIssueOnInstallation(issue, origin)\n\t\t? toIssueWriteResult(issue)\n\t\t: { ok: false, reason: 'unknown' };\n}\n\nfunction isIssueOnInstallation(issue: IssueNode, origin: string | undefined): boolean {\n\tif (origin == null) return true;\n\n\tconst url = typeof issue.url === 'string' ? URL.parse(issue.url) : null;\n\treturn (\n\t\turl?.origin === origin &&\n\t\t(url.protocol === 'https:' || url.protocol === 'http:') &&\n\t\t!url.username &&\n\t\t!url.password\n\t);\n}\n\nfunction toIssueWriteResult(issue: IssueNode, deletedFromDifferentRepository = false): IssueWriteResult {\n\treturn {\n\t\tok: true,\n\t\t...(deletedFromDifferentRepository && { deletedFromDifferentRepository: true }),\n\t\tissue: {\n\t\t\towner: issue.repository.owner.login,\n\t\t\trepo: issue.repository.name,\n\t\t\tnumber: issue.number,\n\t\t\tnodeId: issue.id,\n\t\t\turl: issue.url,\n\t\t\ttitle: issue.title,\n\t\t\tbody: issue.body,\n\t\t\tstate: issue.state === 'CLOSED' ? 'closed' : 'open',\n\t\t},\n\t};\n}\n"],"mappings":";;;;AAqDA,MAAM,cAAc;;;;AA0BpB,SAAgB,2BAA2B,OAAqC;CAC/E,IACC,OAAO,MAAM,UAAU,YACvB,CAAC,gBAAgB,KAAK,MAAM,KAAK,KACjC,OAAO,MAAM,SAAS,YACtB,CAAC,iBAAiB,KAAK,MAAM,IAAI,KACjC,MAAM,SAAS,OACf,MAAM,SAAS,MAEf,OAAO;CAGR,IACC,MAAM,WAAW,aAChB,CAAC,OAAO,UAAU,MAAM,MAAM,KAC9B,MAAM,SAAS,KACf,MAAM,SAAS,cACf,OAAO,MAAM,mBAAmB,YAChC,CAAC,MAAM,eAAe,KAAK,IAE5B,OAAO;CAGR,QAAQ,MAAM,QAAd;EACC,KAAK,UACJ,OAAO,aAAa,MAAM,KAAK,MAAM,MAAM,SAAS,KAAA,KAAa,OAAO,MAAM,SAAS;EACxF,KAAK,QACJ,QACE,MAAM,UAAU,KAAA,KAAa,MAAM,SAAS,KAAA,OAC5C,MAAM,UAAU,KAAA,KAAa,aAAa,MAAM,KAAK,OACrD,MAAM,SAAS,KAAA,KAAa,OAAO,MAAM,SAAS;EAErD,KAAK,aACJ,OACC,MAAM,UAAU,UACf,MAAM,UAAU,aAAa,MAAM,WAAW,eAAe,MAAM,WAAW;EAEjF,KAAK,UACJ,OAAO;EACR,KAAK,WACJ,OAAO,MAAM,WAAW,KAAA,KAAa,MAAM,WAAW;EACvD,SACC,OAAO;CACT;AACD;AAEA,SAAS,aAAa,OAAiC;CACtD,OAAO,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,SAAS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AM,IACxD,mBAAmB,KAAK,IACxB;EAAE,IAAI;EAAO,QAAQ;CAAU;AACnC;AAEA,SAAS,sBAAsB,OAAkB,QAAqC;CACrF,IAAI,UAAU,MAAM,OAAO;CAE3B,MAAM,MAAM,OAAO,MAAM,QAAQ,WAAW,IAAI,MAAM,MAAM,GAAG,IAAI;CACnE,OACC,KAAK,WAAW,WACf,IAAI,aAAa,YAAY,IAAI,aAAa,YAC/C,CAAC,IAAI,YACL,CAAC,IAAI;AAEP;AAEA,SAAS,mBAAmB,OAAkB,iCAAiC,OAAyB;CACvG,OAAO;EACN,IAAI;EACJ,GAAI,kCAAkC,EAAE,gCAAgC,KAAK;EAC7E,OAAO;GACN,OAAO,MAAM,WAAW,MAAM;GAC9B,MAAM,MAAM,WAAW;GACvB,QAAQ,MAAM;GACd,QAAQ,MAAM;GACd,KAAK,MAAM;GACX,OAAO,MAAM;GACb,MAAM,MAAM;GACZ,OAAO,MAAM,UAAU,WAAW,WAAW;EAC9C;CACD;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,eAAgC,IAAI,QAAc;CAClD,IAAI,cAA2B;EAC9B,OAAO,KAAK,aAAa;CAC1B;CAIA,MACM,cACL,YACA,SACgB;EAChB,MAAM,SAAS,+BAA+B,KAAK,cAAc,IAAI,YAAY,SAAS,KAAA;EAC1F,MAAM,aAAa,KAAK,6BAA6B,cAAc,KAAK,gBAAgB,EAC/E,OACT,CAAC;EAYD,IAAI,MAPkB,KAAK,6BAA6B,qBACvD,KAAK,gBACL;GAAE,GAAG;GA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,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 _issueWriteRetirements;
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
+ getIssueWriteMark(): number;
57
+ isIssueWriteRetiredSince(id: IntegrationIds, session: Pick<ProviderAuthenticationSession, 'id' | 'domain'>, mark: number): boolean;
58
+ private retireIssueWrites;
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