@gitkraken/core-gitlens 0.44.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 (255) hide show
  1. package/CHANGELOG.md +34 -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/github.d.ts +13 -1
  28. package/dist/plus/git-github/api/github.js +99 -30
  29. package/dist/plus/git-github/api/github.js.map +1 -1
  30. package/dist/plus/git-github/api/issueWrites.d.ts +9 -2
  31. package/dist/plus/git-github/api/issueWrites.js +61 -31
  32. package/dist/plus/git-github/api/issueWrites.js.map +1 -1
  33. package/dist/plus/git-github/api/pullRequestWrites.d.ts +95 -0
  34. package/dist/plus/git-github/api/pullRequestWrites.js +469 -0
  35. package/dist/plus/git-github/api/pullRequestWrites.js.map +1 -0
  36. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.d.ts +44 -0
  37. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +199 -0
  38. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -0
  39. package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +17 -9
  40. package/dist/plus/integrations/authentication/configuredIntegrationService.js +71 -19
  41. package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
  42. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.d.ts +9 -40
  43. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js +0 -182
  44. package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +5 -2
  45. package/dist/plus/integrations/authentication/integrationAuthenticationService.js +15 -1
  46. package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
  47. package/dist/plus/integrations/authentication/models.d.ts +0 -1
  48. package/dist/plus/integrations/authentication/models.js +1 -2
  49. package/dist/plus/integrations/authentication/models.js.map +1 -1
  50. package/dist/plus/integrations/authentication/observedAuthenticationProvider.d.ts +1 -0
  51. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js +14 -4
  52. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js.map +1 -1
  53. package/dist/plus/integrations/authentication/rejectedTokenTracker.d.ts +2 -2
  54. package/dist/plus/integrations/authentication/rejectedTokenTracker.js +19 -5
  55. package/dist/plus/integrations/authentication/rejectedTokenTracker.js.map +1 -1
  56. package/dist/plus/integrations/constants.d.ts +0 -10
  57. package/dist/plus/integrations/constants.js +1 -95
  58. package/dist/plus/integrations/constants.js.map +1 -1
  59. package/dist/plus/integrations/context.d.ts +13 -13
  60. package/dist/plus/integrations/index.d.ts +41 -25
  61. package/dist/plus/integrations/index.js +40 -8
  62. package/dist/plus/integrations/index.js.map +1 -1
  63. package/dist/plus/integrations/integrationService.d.ts +20 -22
  64. package/dist/plus/integrations/integrationService.js +80 -9
  65. package/dist/plus/integrations/integrationService.js.map +1 -1
  66. package/dist/plus/integrations/lite.js +1 -1
  67. package/dist/plus/integrations/lite.js.map +1 -1
  68. package/dist/plus/integrations/manager.d.ts +70 -15
  69. package/dist/plus/integrations/models/actionablePullRequest.d.ts +213 -0
  70. package/dist/plus/integrations/models/actionablePullRequest.js +25 -0
  71. package/dist/plus/integrations/models/actionablePullRequest.js.map +1 -0
  72. package/dist/plus/integrations/models/gitHostIntegration.d.ts +13 -46
  73. package/dist/plus/integrations/models/gitHostIntegration.js +15 -4
  74. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  75. package/dist/plus/integrations/models/integration.d.ts +12 -177
  76. package/dist/plus/integrations/models/integration.js +21 -77
  77. package/dist/plus/integrations/models/integration.js.map +1 -1
  78. package/dist/plus/integrations/models/issuesIntegration.d.ts +9 -5
  79. package/dist/plus/integrations/models/issuesIntegration.js +5 -3
  80. package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
  81. package/dist/plus/integrations/models/publicIntegration.d.ts +252 -0
  82. package/dist/plus/integrations/models/publicIntegration.js +21 -0
  83. package/dist/plus/integrations/models/publicIntegration.js.map +1 -0
  84. package/dist/plus/integrations/providerFilters.d.ts +58 -0
  85. package/dist/plus/integrations/providerFilters.js.map +1 -1
  86. package/dist/plus/integrations/providers/actionablePullRequests.d.ts +19 -0
  87. package/dist/plus/integrations/providers/actionablePullRequests.js +32 -0
  88. package/dist/plus/integrations/providers/actionablePullRequests.js.map +1 -0
  89. package/dist/plus/integrations/providers/apiClients.d.ts +1 -2
  90. package/dist/plus/integrations/providers/apiClients.js.map +1 -1
  91. package/dist/plus/integrations/providers/asana.d.ts +3 -2
  92. package/dist/plus/integrations/providers/asana.js +2 -1
  93. package/dist/plus/integrations/providers/asana.js.map +1 -1
  94. package/dist/plus/integrations/providers/azure/azure.d.ts +1 -1
  95. package/dist/plus/integrations/providers/azure/azure.js +1 -1
  96. package/dist/plus/integrations/providers/azure/azure.utils.d.ts +10 -3
  97. package/dist/plus/integrations/providers/azure/azure.utils.js +5 -1
  98. package/dist/plus/integrations/providers/azure/azure.utils.js.map +1 -1
  99. package/dist/plus/integrations/providers/azure/models.d.ts +1 -5
  100. package/dist/plus/integrations/providers/azure/models.js +1 -1
  101. package/dist/plus/integrations/providers/azure/models.js.map +1 -1
  102. package/dist/plus/integrations/providers/azureDevOps.d.ts +8 -5
  103. package/dist/plus/integrations/providers/azureDevOps.js +2 -1
  104. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  105. package/dist/plus/integrations/providers/azureDevOpsServer.d.ts +5 -4
  106. package/dist/plus/integrations/providers/azureDevOpsServer.js +3 -1
  107. package/dist/plus/integrations/providers/azureDevOpsServer.js.map +1 -1
  108. package/dist/plus/integrations/providers/bitbucket/bitbucket.d.ts +2 -2
  109. package/dist/plus/integrations/providers/bitbucket/bitbucket.js.map +1 -1
  110. package/dist/plus/integrations/providers/bitbucket/models.d.ts +1 -1
  111. package/dist/plus/integrations/providers/bitbucket/models.js.map +1 -1
  112. package/dist/plus/integrations/providers/bitbucket-server.d.ts +5 -4
  113. package/dist/plus/integrations/providers/bitbucket-server.js +2 -1
  114. package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
  115. package/dist/plus/integrations/providers/bitbucket.d.ts +4 -3
  116. package/dist/plus/integrations/providers/bitbucket.js +2 -1
  117. package/dist/plus/integrations/providers/bitbucket.js.map +1 -1
  118. package/dist/plus/integrations/providers/github/github.d.ts +0 -1
  119. package/dist/plus/integrations/providers/github/github.js +1 -1
  120. package/dist/plus/integrations/providers/github/github.js.map +1 -1
  121. package/dist/plus/integrations/providers/github.d.ts +16 -6
  122. package/dist/plus/integrations/providers/github.js +109 -12
  123. package/dist/plus/integrations/providers/github.js.map +1 -1
  124. package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +2 -2
  125. package/dist/plus/integrations/providers/gitlab/gitlab.js +1 -2
  126. package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
  127. package/dist/plus/integrations/providers/gitlab/gitlab.utils.d.ts +14 -1
  128. package/dist/plus/integrations/providers/gitlab/gitlab.utils.js.map +1 -1
  129. package/dist/plus/integrations/providers/gitlab/models.d.ts +2 -10
  130. package/dist/plus/integrations/providers/gitlab/models.js.map +1 -1
  131. package/dist/plus/integrations/providers/gitlab.d.ts +7 -5
  132. package/dist/plus/integrations/providers/gitlab.js +2 -1
  133. package/dist/plus/integrations/providers/gitlab.js.map +1 -1
  134. package/dist/plus/integrations/providers/issueSorts.d.ts +0 -1
  135. package/dist/plus/integrations/providers/jira-server.d.ts +4 -4
  136. package/dist/plus/integrations/providers/jira-server.js +3 -2
  137. package/dist/plus/integrations/providers/jira-server.js.map +1 -1
  138. package/dist/plus/integrations/providers/jira.d.ts +3 -3
  139. package/dist/plus/integrations/providers/jira.js +3 -2
  140. package/dist/plus/integrations/providers/jira.js.map +1 -1
  141. package/dist/plus/integrations/providers/jiraIssueByKey.d.ts +1 -1
  142. package/dist/plus/integrations/providers/jiraIssueByKey.js.map +1 -1
  143. package/dist/plus/integrations/providers/linear.d.ts +4 -3
  144. package/dist/plus/integrations/providers/linear.js +3 -2
  145. package/dist/plus/integrations/providers/linear.js.map +1 -1
  146. package/dist/plus/integrations/providers/linearIssuesEtag.d.ts +1 -1
  147. package/dist/plus/integrations/providers/linearIssuesEtag.js +1 -1
  148. package/dist/plus/integrations/providers/linearIssuesEtag.js.map +1 -1
  149. package/dist/plus/integrations/providers/metadata.d.ts +136 -0
  150. package/dist/plus/integrations/providers/metadata.js +513 -0
  151. package/dist/plus/integrations/providers/metadata.js.map +1 -0
  152. package/dist/plus/integrations/providers/models.d.ts +10 -206
  153. package/dist/plus/integrations/providers/models.js +8 -539
  154. package/dist/plus/integrations/providers/models.js.map +1 -1
  155. package/dist/plus/integrations/providers/providersApi.d.ts +3 -2
  156. package/dist/plus/integrations/providers/providersApi.js +2 -1
  157. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  158. package/dist/plus/integrations/providers/trello.d.ts +1 -1
  159. package/dist/plus/integrations/providers/trello.js +2 -1
  160. package/dist/plus/integrations/providers/trello.js.map +1 -1
  161. package/dist/plus/integrations/providers/utils/providerPaging.d.ts +2 -0
  162. package/dist/plus/integrations/providers/utils/providerPaging.js +3 -2
  163. package/dist/plus/integrations/providers/utils/providerPaging.js.map +1 -1
  164. package/dist/plus/integrations/providers/utils.d.ts +119 -10
  165. package/dist/plus/integrations/providers/utils.js +57 -3
  166. package/dist/plus/integrations/providers/utils.js.map +1 -1
  167. package/dist/plus/integrations/reads/autolinks.d.ts +1 -1
  168. package/dist/plus/integrations/reads/autolinks.js +1 -1
  169. package/dist/plus/integrations/reads/autolinks.js.map +1 -1
  170. package/dist/plus/integrations/reads/broaden.d.ts +1 -1
  171. package/dist/plus/integrations/reads/broaden.js +3 -2
  172. package/dist/plus/integrations/reads/broaden.js.map +1 -1
  173. package/dist/plus/integrations/reads/context.d.ts +1 -1
  174. package/dist/plus/integrations/reads/counts.d.ts +1 -88
  175. package/dist/plus/integrations/reads/counts.js +4 -2
  176. package/dist/plus/integrations/reads/counts.js.map +1 -1
  177. package/dist/plus/integrations/reads/currentAccount.d.ts +1 -18
  178. package/dist/plus/integrations/reads/currentAccount.js.map +1 -1
  179. package/dist/plus/integrations/reads/drains.d.ts +3 -4
  180. package/dist/plus/integrations/reads/drains.js +1 -1
  181. package/dist/plus/integrations/reads/drains.js.map +1 -1
  182. package/dist/plus/integrations/reads/etag.d.ts +174 -3
  183. package/dist/plus/integrations/reads/etag.js +69 -14
  184. package/dist/plus/integrations/reads/etag.js.map +1 -1
  185. package/dist/plus/integrations/reads/filters.d.ts +3 -61
  186. package/dist/plus/integrations/reads/filters.js +1 -1
  187. package/dist/plus/integrations/reads/filters.js.map +1 -1
  188. package/dist/plus/integrations/reads/hierarchy.d.ts +1 -1
  189. package/dist/plus/integrations/reads/hierarchy.js +4 -2
  190. package/dist/plus/integrations/reads/hierarchy.js.map +1 -1
  191. package/dist/plus/integrations/reads/issueBatch.d.ts +2 -102
  192. package/dist/plus/integrations/reads/issueBatch.js +3 -4
  193. package/dist/plus/integrations/reads/issueBatch.js.map +1 -1
  194. package/dist/plus/integrations/reads/issueTracker.d.ts +1 -1
  195. package/dist/plus/integrations/reads/issueTracker.js +4 -3
  196. package/dist/plus/integrations/reads/issueTracker.js.map +1 -1
  197. package/dist/plus/integrations/reads/issues.d.ts +1 -1
  198. package/dist/plus/integrations/reads/issues.js +4 -2
  199. package/dist/plus/integrations/reads/issues.js.map +1 -1
  200. package/dist/plus/integrations/reads/paging.d.ts +1 -1
  201. package/dist/plus/integrations/reads/paging.js +1 -1
  202. package/dist/plus/integrations/reads/paging.js.map +1 -1
  203. package/dist/plus/integrations/reads/pullRequestActivity.d.ts +1 -24
  204. package/dist/plus/integrations/reads/pullRequestActivity.js +2 -1
  205. package/dist/plus/integrations/reads/pullRequestActivity.js.map +1 -1
  206. package/dist/plus/integrations/reads/pullRequestBatch.d.ts +2 -56
  207. package/dist/plus/integrations/reads/pullRequestBatch.js +23 -3
  208. package/dist/plus/integrations/reads/pullRequestBatch.js.map +1 -1
  209. package/dist/plus/integrations/reads/pullRequestBranches.d.ts +1 -47
  210. package/dist/plus/integrations/reads/pullRequestBranches.js +2 -1
  211. package/dist/plus/integrations/reads/pullRequestBranches.js.map +1 -1
  212. package/dist/plus/integrations/reads/pullRequestCheckLogs.d.ts +1 -15
  213. package/dist/plus/integrations/reads/pullRequestCheckLogs.js +2 -1
  214. package/dist/plus/integrations/reads/pullRequestCheckLogs.js.map +1 -1
  215. package/dist/plus/integrations/reads/pullRequests.js +4 -2
  216. package/dist/plus/integrations/reads/pullRequests.js.map +1 -1
  217. package/dist/plus/integrations/reads/pullRequestsForCommits.d.ts +1 -16
  218. package/dist/plus/integrations/reads/pullRequestsForCommits.js +2 -1
  219. package/dist/plus/integrations/reads/pullRequestsForCommits.js.map +1 -1
  220. package/dist/plus/integrations/reads/resolveRepository.js +10 -5
  221. package/dist/plus/integrations/reads/resolveRepository.js.map +1 -1
  222. package/dist/plus/integrations/reads/searchIssues.js +2 -1
  223. package/dist/plus/integrations/reads/searchIssues.js.map +1 -1
  224. package/dist/plus/integrations/reads/searchPullRequests.js +2 -1
  225. package/dist/plus/integrations/reads/searchPullRequests.js.map +1 -1
  226. package/dist/plus/integrations/reads/sweeps.d.ts +1 -1
  227. package/dist/plus/integrations/reads/sweeps.js +3 -2
  228. package/dist/plus/integrations/reads/sweeps.js.map +1 -1
  229. package/dist/plus/integrations/reads/warnings.d.ts +1 -1
  230. package/dist/plus/integrations/reads/warnings.js +1 -1
  231. package/dist/plus/integrations/reads/warnings.js.map +1 -1
  232. package/dist/plus/integrations/results.d.ts +324 -2
  233. package/dist/plus/integrations/results.js.map +1 -1
  234. package/dist/plus/integrations/telemetry.d.ts +0 -10
  235. package/dist/plus/integrations/telemetry.js +0 -11
  236. package/dist/plus/integrations/utils/domain.utils.d.ts +1 -0
  237. package/dist/plus/integrations/utils/domain.utils.js +10 -2
  238. package/dist/plus/integrations/utils/domain.utils.js.map +1 -1
  239. package/dist/plus/integrations/utils/integration.utils.d.ts +1 -6
  240. package/dist/plus/integrations/utils/integration.utils.js +2 -9
  241. package/dist/plus/integrations/utils/integration.utils.js.map +1 -1
  242. package/dist/utils/env/node/exec.js +2 -2
  243. package/dist/utils/keys/chord.d.ts +13 -2
  244. package/dist/utils/keys/chord.js +76 -17
  245. package/dist/utils/keys/chord.js.map +1 -1
  246. package/dist/utils/keys/keybinding.d.ts +12 -0
  247. package/dist/utils/keys/keybinding.js +52 -2
  248. package/dist/utils/keys/keybinding.js.map +1 -1
  249. package/dist/utils/markdown.d.ts +21 -0
  250. package/dist/utils/markdown.js +33 -1
  251. package/dist/utils/markdown.js.map +1 -1
  252. package/docs/integrations.md +135 -16
  253. package/package.json +5 -1
  254. package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js.map +0 -1
  255. package/dist/plus/integrations/telemetry.js.map +0 -1
@@ -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,IAA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B,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"}
@@ -28,8 +28,10 @@ export declare class ConfiguredIntegrationService implements Disposable {
28
28
  private readonly _locks;
29
29
  /** Monotonic across providers; see {@link getSignOutMark}. */
30
30
  private _signOutEpoch;
31
- /** The epoch of the latest sign-out per scope: a provider, a self-managed host, or a single connection. */
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;
@@ -46,22 +48,27 @@ export declare class ConfiguredIntegrationService implements Disposable {
46
48
  private removeConfigured;
47
49
  private withLock;
48
50
  /**
49
- * Taken before a token is read or fetched, and handed to {@link storeSession}: a sign-out that lands after it
50
- * (a disconnect, a reauthentication, the connection being removed) refuses the store, so a token fetched across
51
- * it is not written back and reconnected on the next resolution (gitkraken/kepler#3546).
51
+ * Taken before a token is read or fetched and handed to {@link storeSession}. A later sign-out or a recovery
52
+ * that replaces the credential invalidates the pending store.
52
53
  */
53
54
  getSignOutMark(): number;
54
- private markSignOut;
55
+ private retirePendingStores;
56
+ getIssueWriteMark(): number;
57
+ isIssueWriteRetiredSince(id: IntegrationIds, session: Pick<ProviderAuthenticationSession, 'id' | 'domain'>, mark: number): boolean;
58
+ private retireIssueWrites;
55
59
  private getHostScope;
56
- private isSignedOutSince;
60
+ isSessionRetiredSince(id: IntegrationIds, session: Pick<ProviderAuthenticationSession, 'id' | 'domain'>, mark: number): boolean;
61
+ private hasRetirement;
57
62
  /**
58
- * Stores the session's secret and descriptor together. With a `signOutMark`, nothing is stored, and `false` is
59
- * returned, when a sign-out covering the session landed after the mark was taken.
63
+ * Stores the session's secret and descriptor together. A pending store can be invalidated by a sign-out or a
64
+ * credential recovery. A recovery must still own the stored credential when it publishes its replacement.
60
65
  */
61
66
  storeSession(id: IntegrationIds, session: ProviderAuthenticationSession, options?: {
62
67
  signOutMark?: number;
63
68
  resource?: ConnectionResource;
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
@@ -71,7 +78,8 @@ export declare class ConfiguredIntegrationService implements Disposable {
71
78
  deleteStoredSessions(id: IntegrationIds, descriptor: IntegrationAuthenticationSessionDescriptor, cloud?: boolean, options?: {
72
79
  preserveConfigured?: boolean;
73
80
  signOut?: boolean;
74
- }): Promise<void>;
81
+ signOutMark?: number;
82
+ }): Promise<boolean>;
75
83
  /** Signs out of every stored session of the provider, or of one self-managed host when `domain` is given. */
76
84
  deleteAllStoredSessions(id: IntegrationIds, cloud?: boolean, domain?: string): Promise<void>;
77
85
  /**
@@ -1,11 +1,12 @@
1
1
  import { flatten } from "../../../utils/iterable.js";
2
2
  import { Emitter } from "../../../utils/event.js";
3
3
  import { debounce } from "../../../utils/debounce.js";
4
+ import { providersMetadata } from "../providers/metadata.js";
4
5
  import { areDomainsOnSameHost, baseUrlFromDomain, hostFromDomain, sameConfiguredBaseUrl } from "../utils/domain.utils.js";
5
- import { providersMetadata } from "../providers/models.js";
6
6
  import { isSelfManagedHostIntegrationId } from "../utils/integration.utils.js";
7
7
  import { getSessionIdentity } from "./models.js";
8
8
  //#region ../plus/integrations/src/authentication/configuredIntegrationService.ts
9
+ const issueWriteRetirements = /* @__PURE__ */ new WeakMap();
9
10
  var ConfiguredIntegrationService = class {
10
11
  ctx;
11
12
  _onDidChange = new Emitter();
@@ -20,8 +21,10 @@ var ConfiguredIntegrationService = class {
20
21
  _locks = /* @__PURE__ */ new Map();
21
22
  /** Monotonic across providers; see {@link getSignOutMark}. */
22
23
  _signOutEpoch = 0;
23
- /** The epoch of the latest sign-out per scope: a provider, a self-managed host, or a single connection. */
24
+ /** The latest retirement of pending stores per provider, self-managed host, or connection. */
24
25
  _signOuts = /* @__PURE__ */ new Map();
26
+ _issueWriteRetirements;
27
+ _disposed = false;
25
28
  get onDidChange() {
26
29
  return this._onDidChange.event;
27
30
  }
@@ -33,8 +36,18 @@ var ConfiguredIntegrationService = class {
33
36
  }
34
37
  constructor(ctx) {
35
38
  this.ctx = ctx;
39
+ let retirements = issueWriteRetirements.get(ctx.storage);
40
+ if (retirements == null) {
41
+ retirements = {
42
+ epoch: 0,
43
+ scopes: /* @__PURE__ */ new Map()
44
+ };
45
+ issueWriteRetirements.set(ctx.storage, retirements);
46
+ }
47
+ this._issueWriteRetirements = retirements;
36
48
  }
37
49
  dispose() {
50
+ this._disposed = true;
38
51
  this._onDidChange.dispose();
39
52
  this._onWillChangeSession.dispose();
40
53
  this._onWillRemoveSessions.dispose();
@@ -146,42 +159,75 @@ var ConfiguredIntegrationService = class {
146
159
  return run;
147
160
  }
148
161
  /**
149
- * Taken before a token is read or fetched, and handed to {@link storeSession}: a sign-out that lands after it
150
- * (a disconnect, a reauthentication, the connection being removed) refuses the store, so a token fetched across
151
- * it is not written back and reconnected on the next resolution (gitkraken/kepler#3546).
162
+ * Taken before a token is read or fetched and handed to {@link storeSession}. A later sign-out or a recovery
163
+ * that replaces the credential invalidates the pending store.
152
164
  */
153
165
  getSignOutMark() {
154
166
  return this._signOutEpoch;
155
167
  }
156
- markSignOut(scope) {
168
+ retirePendingStores(scope) {
157
169
  this._signOuts.set(scope, ++this._signOutEpoch);
170
+ this.retireIssueWrites(scope);
171
+ }
172
+ getIssueWriteMark() {
173
+ return this._issueWriteRetirements.epoch;
174
+ }
175
+ isIssueWriteRetiredSince(id, session, mark) {
176
+ return this._disposed || this.hasRetirement(this._issueWriteRetirements.scopes, id, session, mark);
177
+ }
178
+ retireIssueWrites(scope) {
179
+ const retirements = this._issueWriteRetirements;
180
+ retirements.scopes.set(scope, ++retirements.epoch);
158
181
  }
159
182
  getHostScope(id, domain) {
160
183
  return `${id}|host:${hostFromDomain(domain) ?? domain}`;
161
184
  }
162
- isSignedOutSince(id, session, mark) {
163
- const since = (scope) => (this._signOuts.get(scope) ?? 0) > mark;
185
+ isSessionRetiredSince(id, session, mark) {
186
+ return this.hasRetirement(this._signOuts, id, session, mark);
187
+ }
188
+ hasRetirement(scopes, id, session, mark) {
189
+ const since = (scope) => (scopes.get(scope) ?? 0) > mark;
164
190
  if (since(id)) return true;
165
191
  if (isSelfManagedHostIntegrationId(id) && session.domain && since(this.getHostScope(id, session.domain))) return true;
166
192
  return since(`${id}|connection:${session.id}`);
167
193
  }
168
194
  /**
169
- * Stores the session's secret and descriptor together. With a `signOutMark`, nothing is stored, and `false` is
170
- * returned, when a sign-out covering the session landed after the mark was taken.
195
+ * Stores the session's secret and descriptor together. A pending store can be invalidated by a sign-out or a
196
+ * credential recovery. A recovery must still own the stored credential when it publishes its replacement.
171
197
  */
172
198
  storeSession(id, session, options) {
173
199
  return this.withLock(id, async () => {
174
- if (options?.signOutMark != null && this.isSignedOutSince(id, session, options.signOutMark)) return false;
200
+ if (options?.signOutMark != null && this.isSessionRetiredSince(id, session, options.signOutMark)) return false;
175
201
  const previous = await this.readSecret(id, session.id, session.cloud);
176
- if (getSessionIdentity(previous) !== getSessionIdentity(session)) this._onWillChangeSession.fire({
177
- integrationId: id,
178
- session,
179
- previousDomain: previous?.domain
180
- });
202
+ if (options?.expectedStoredAccessToken != null && previous?.accessToken !== options.expectedStoredAccessToken) return false;
203
+ if (getSessionIdentity(previous) !== getSessionIdentity(session)) {
204
+ if (previous != null) this.retireIssueWrites(`${id}|connection:${session.id}`);
205
+ this._onWillChangeSession.fire({
206
+ integrationId: id,
207
+ session,
208
+ previousDomain: previous?.domain
209
+ });
210
+ }
181
211
  await this.writeSecret(id, session, options?.resource);
212
+ if (options?.expectedStoredAccessToken != null && session.accessToken !== options.expectedStoredAccessToken) this.retirePendingStores(`${id}|connection:${session.id}`);
182
213
  return true;
183
214
  });
184
215
  }
216
+ async peekStoredSession(id, connectionId, cloud, domain) {
217
+ return this.withLock(id, async () => {
218
+ const json = await this.ctx.storage.getSecret(this.getSecretKey(id, connectionId, cloud));
219
+ if (json == null) return void 0;
220
+ try {
221
+ return convertStoredSessionToSession(JSON.parse(json), {
222
+ connectionId,
223
+ domain,
224
+ scopes: []
225
+ }, cloud);
226
+ } catch {
227
+ return;
228
+ }
229
+ });
230
+ }
185
231
  getStoredSession(id, descriptor) {
186
232
  return this.withLock(id, async () => {
187
233
  const sessionId = this.resolveConnectionId(id, descriptor);
@@ -210,8 +256,12 @@ var ConfiguredIntegrationService = class {
210
256
  */
211
257
  deleteStoredSessions(id, descriptor, cloud, options) {
212
258
  return this.withLock(id, async () => {
213
- if (options?.signOut) this.markSignOut(isSelfManagedHostIntegrationId(id) && descriptor.domain ? this.getHostScope(id, descriptor.domain) : id);
214
259
  const connectionId = this.resolveConnectionId(id, descriptor);
260
+ if (options?.signOutMark != null && this.isSessionRetiredSince(id, {
261
+ id: connectionId,
262
+ domain: descriptor.domain
263
+ }, options.signOutMark)) return false;
264
+ if (options?.signOut) this.retirePendingStores(isSelfManagedHostIntegrationId(id) && descriptor.domain ? this.getHostScope(id, descriptor.domain) : id);
215
265
  this._onWillRemoveSessions.fire({
216
266
  integrationId: id,
217
267
  connectionId,
@@ -219,12 +269,13 @@ var ConfiguredIntegrationService = class {
219
269
  domain: descriptor.domain
220
270
  });
221
271
  await this.deleteSecrets(id, connectionId, cloud, options);
272
+ return true;
222
273
  });
223
274
  }
224
275
  /** Signs out of every stored session of the provider, or of one self-managed host when `domain` is given. */
225
276
  deleteAllStoredSessions(id, cloud, domain) {
226
277
  return this.withLock(id, async () => {
227
- this.markSignOut(isSelfManagedHostIntegrationId(id) && domain != null ? this.getHostScope(id, domain) : id);
278
+ this.retirePendingStores(isSelfManagedHostIntegrationId(id) && domain != null ? this.getHostScope(id, domain) : id);
228
279
  this._onWillRemoveSessions.fire({
229
280
  integrationId: id,
230
281
  cloud,
@@ -259,6 +310,7 @@ var ConfiguredIntegrationService = class {
259
310
  await this.ctx.storage.store("integrations:configured", remaining);
260
311
  }
261
312
  async deleteSecrets(id, connectionId, cloud, options) {
313
+ this.retireIssueWrites(`${id}|connection:${connectionId}`);
262
314
  if (cloud == null || cloud === false) await this.ctx.storage.deleteSecret(this.getLocalSecretKey(id, connectionId));
263
315
  if (cloud == null || cloud === true) await this.ctx.storage.deleteSecret(this.getCloudSecretKey(id, connectionId));
264
316
  if (options?.preserveConfigured) return;
@@ -450,7 +502,7 @@ var ConfiguredIntegrationService = class {
450
502
  */
451
503
  deleteConnection(id, connectionId, cloud) {
452
504
  return this.withLock(id, async () => {
453
- this.markSignOut(`${id}|connection:${connectionId}`);
505
+ this.retirePendingStores(`${id}|connection:${connectionId}`);
454
506
  this._onWillRemoveSessions.fire({
455
507
  integrationId: id,
456
508
  connectionId,