@gitkraken/core-gitlens 0.67.0 → 0.69.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 (50) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +1 -1
  3. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -1
  4. package/dist/plus/integrations/authentication/configuredIntegrationService.js +2 -2
  5. package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
  6. package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +4 -2
  7. package/dist/plus/integrations/authentication/integrationAuthenticationService.js +5 -4
  8. package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
  9. package/dist/plus/integrations/index.d.ts +3 -1
  10. package/dist/plus/integrations/index.js +18 -0
  11. package/dist/plus/integrations/index.js.map +1 -1
  12. package/dist/plus/integrations/integrationService.d.ts +29 -0
  13. package/dist/plus/integrations/integrationService.js +84 -0
  14. package/dist/plus/integrations/integrationService.js.map +1 -1
  15. package/dist/plus/integrations/manager.d.ts +12 -0
  16. package/dist/plus/integrations/models/asanaTaskWrites.d.ts +155 -0
  17. package/dist/plus/integrations/models/asanaTaskWrites.js +0 -0
  18. package/dist/plus/integrations/models/issuesIntegration.d.ts +6 -1
  19. package/dist/plus/integrations/models/issuesIntegration.js +25 -0
  20. package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
  21. package/dist/plus/integrations/models/trelloCardWrites.d.ts +117 -0
  22. package/dist/plus/integrations/models/trelloCardWrites.js +0 -0
  23. package/dist/plus/integrations/providers/asana.d.ts +3 -1
  24. package/dist/plus/integrations/providers/asana.js +10 -0
  25. package/dist/plus/integrations/providers/asana.js.map +1 -1
  26. package/dist/plus/integrations/providers/asanaTaskWriteTransport.d.ts +40 -0
  27. package/dist/plus/integrations/providers/asanaTaskWriteTransport.js +122 -0
  28. package/dist/plus/integrations/providers/asanaTaskWriteTransport.js.map +1 -0
  29. package/dist/plus/integrations/providers/asanaTaskWrites.d.ts +38 -0
  30. package/dist/plus/integrations/providers/asanaTaskWrites.js +521 -0
  31. package/dist/plus/integrations/providers/asanaTaskWrites.js.map +1 -0
  32. package/dist/plus/integrations/providers/providersApi.js +1 -4
  33. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  34. package/dist/plus/integrations/providers/trello.d.ts +3 -1
  35. package/dist/plus/integrations/providers/trello.js +11 -0
  36. package/dist/plus/integrations/providers/trello.js.map +1 -1
  37. package/dist/plus/integrations/providers/trelloApi.d.ts +5 -0
  38. package/dist/plus/integrations/providers/trelloApi.js +9 -0
  39. package/dist/plus/integrations/providers/trelloApi.js.map +1 -0
  40. package/dist/plus/integrations/providers/trelloCardWriteTransport.d.ts +27 -0
  41. package/dist/plus/integrations/providers/trelloCardWriteTransport.js +73 -0
  42. package/dist/plus/integrations/providers/trelloCardWriteTransport.js.map +1 -0
  43. package/dist/plus/integrations/providers/trelloCardWrites.d.ts +26 -0
  44. package/dist/plus/integrations/providers/trelloCardWrites.js +342 -0
  45. package/dist/plus/integrations/providers/trelloCardWrites.js.map +1 -0
  46. package/dist/plus/integrations/providers/utils/writeTransport.d.ts +28 -0
  47. package/dist/plus/integrations/providers/utils/writeTransport.js +60 -0
  48. package/dist/plus/integrations/providers/utils/writeTransport.js.map +1 -0
  49. package/docs/integrations.md +51 -0
  50. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -6,6 +6,26 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.69.0] - 2026-12-05
10
+
11
+ ### Added
12
+
13
+ - Adds Asana task write discovery, point reads by GID or URL, creation, editing, completion, same-project section moves, and confirmed deletion to `IntegrationManager`; task receipts include the assignee and a subtask's inherited projects ([#6275](https://github.com/gitkraken/vscode-gitlens/issues/6275)).
14
+
15
+ ### Changed
16
+
17
+ - Changes refreshed cloud integration sessions to report the scopes the GitKraken backend stores for the connection instead of the integration's default scopes ([#6275](https://github.com/gitkraken/vscode-gitlens/issues/6275)).
18
+
19
+ ## [0.68.0] - 2026-12-05
20
+
21
+ ### Added
22
+
23
+ - Adds Trello card write discovery, creation, editing, same-board moves, archiving, restoration, and confirmed permanent deletion to `IntegrationManager` ([#6274](https://github.com/gitkraken/vscode-gitlens/issues/6274)).
24
+
25
+ ### Fixed
26
+
27
+ - Preserves configured credentials when secret storage temporarily fails to read them.
28
+
9
29
  ## [0.67.0] - 2026-12-05
10
30
 
11
31
  ### Added
@@ -222,7 +222,7 @@ var CloudIntegrationAuthenticationProvider = class extends IntegrationAuthentica
222
222
  const resolved = {
223
223
  id: session.id ?? fallbackId,
224
224
  accessToken: session.accessToken,
225
- scopes: descriptor.scopes,
225
+ scopes: session.scopes ? session.scopes.split(",") : descriptor.scopes,
226
226
  account: {
227
227
  id: "",
228
228
  label: ""
@@ -1 +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 { CloudIntegrationSync } from './cloudIntegrationObservations.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; skipConnect?: boolean };\n\nabstract class IntegrationAuthenticationProviderBase<\n\tID extends IntegrationIds = IntegrationIds,\n> implements IntegrationAuthenticationProvider {\n\tprotected readonly disposables: Disposable[] = [];\n\tprotected readonly primaryResponses = new WeakMap<ProviderAuthenticationSession, 'named' | 'legacy'>();\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; sync?: CloudIntegrationSync },\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{\n\t\t\t\tpreserveConfigured: options?.preserveConfigured ?? true,\n\t\t\t\tsignOutMark: options?.signOutMark,\n\t\t\t\tsync: options?.sync,\n\t\t\t},\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\tawait this.clearSessions(descriptor);\n\t}\n\n\tasync clearSessions(\n\t\tdescriptor?: IntegrationAuthenticationSessionDescriptor,\n\t\tsync?: CloudIntegrationSync,\n\t): Promise<boolean> {\n\t\tconst domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : undefined;\n\t\tconst configured = this.configuredIntegrationService.getConfigured(this.authProviderId, { domain: domain });\n\t\tconst cleared = await this.configuredIntegrationService.deleteAllStoredSessions(\n\t\t\tthis.authProviderId,\n\t\t\tundefined,\n\t\t\tdomain,\n\t\t\tsync,\n\t\t);\n\t\tif (cleared && configured.length) {\n\t\t\tthis.fireChange();\n\t\t}\n\t\treturn cleared;\n\t}\n\n\t@trace()\n\tasync getSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetSessionOptions,\n\t\tauthority?: CloudIntegrationSync,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\t// KEEP: taken before queueing, so a sign-out while this waits refuses its store.\n\t\tconst signOutMark = this.configuredIntegrationService.getSignOutMark();\n\t\tif (!this.configuredIntegrationService.serializesCredentialAcquisition(this.authProviderId)) {\n\t\t\treturn this.acquireSession(descriptor, options, signOutMark, signOutMark, authority);\n\t\t}\n\n\t\tconst connectionId = descriptor.connectionId || this.getImplicitCloudConnectionId(descriptor, options);\n\t\t// KEEP: connecting reaches this provider's own getSession again, so it runs after the queued acquisition.\n\t\tconst session = await this.configuredIntegrationService.withCredentialAcquisition(\n\t\t\tthis.authProviderId,\n\t\t\tconnectionId,\n\t\t\t() =>\n\t\t\t\tthis.acquireSession(\n\t\t\t\t\tconnectionId != null ? { ...descriptor, connectionId: connectionId } : descriptor,\n\t\t\t\t\t{ ...options, skipConnect: true },\n\t\t\t\t\tsignOutMark,\n\t\t\t\t\tthis.configuredIntegrationService.getStoredWriteMark(),\n\t\t\t\t\tauthority,\n\t\t\t\t),\n\t\t);\n\t\tif (session != null || !options?.createIfNeeded || options.forceNewSession) return session;\n\t\t// KEEP: a sign-out or replacement since the mark refused the fetched credential; it is not a missing one.\n\t\tif (\n\t\t\tthis.configuredIntegrationService.isSessionRetiredSince(\n\t\t\t\tthis.authProviderId,\n\t\t\t\t{ id: connectionId ?? '', domain: descriptor.domain, cloud: descriptor.cloud },\n\t\t\t\tsignOutMark,\n\t\t\t)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.connectNewSession(descriptor, options);\n\t}\n\n\tprivate getImplicitCloudConnectionId(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions: GetSessionOptions | undefined,\n\t): string | undefined {\n\t\tconst connectionId = this.configuredIntegrationService.getConfiguredConnectionId(\n\t\t\tthis.authProviderId,\n\t\t\tdescriptor.domain,\n\t\t\ttrue,\n\t\t);\n\t\tconst stored = this.configuredIntegrationService.resolveConnectionId(\n\t\t\tthis.authProviderId,\n\t\t\toptions?.sync ? { ...descriptor, cloud: true } : descriptor,\n\t\t);\n\t\treturn connectionId === stored ? connectionId : undefined;\n\t}\n\n\tprivate async acquireSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions: (GetSessionOptions & { skipConnect?: boolean }) | undefined,\n\t\tinitialSignOutMark: number,\n\t\tacquisitionMark: number,\n\t\tauthority?: CloudIntegrationSync,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tlet signOutMark = initialSignOutMark;\n\t\tlet session;\n\t\tlet previousToken;\n\t\tlet refetched: ProviderAuthenticationSession | undefined;\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\tacquisitionMark = signOutMark;\n\t\t} else {\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(\n\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\trefetched,\n\t\t\t\t\tsignOutMark,\n\t\t\t\t\tacquisitionMark,\n\t\t\t\t)\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 primaryResponse = this.primaryResponses.get(session);\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\tacquisitionMark: acquisitionMark,\n\t\t\t\t\texpectedStoredAccessToken: scopedRecovery ? previousToken : undefined,\n\t\t\t\t\tprimaryResponse: primaryResponse,\n\t\t\t\t\tsync: authority,\n\t\t\t\t});\n\t\t\t\tif (authority?.isCurrent() === false) throw new CancellationError();\n\n\t\t\t\tconst primary =\n\t\t\t\t\tprimaryResponse === 'named'\n\t\t\t\t\t\t? this.configuredIntegrationService.supersedingPrimary(\n\t\t\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\t\tsignOutMark,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (primary != null) {\n\t\t\t\t\tconst current = await this.configuredIntegrationService.peekStoredSession(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tprimary,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t);\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrent == null ||\n\t\t\t\t\t\tthis.configuredIntegrationService.supersedingPrimary(\n\t\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\tsignOutMark,\n\t\t\t\t\t\t) !== primary\n\t\t\t\t\t) {\n\t\t\t\t\t\tthrow new CancellationError();\n\t\t\t\t\t}\n\n\t\t\t\t\tsession = current;\n\t\t\t\t} else if (!stored) {\n\t\t\t\t\tsession = await this.configuredIntegrationService.peekStoredSession(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tsession.id,\n\t\t\t\t\t\tsession.cloud,\n\t\t\t\t\t\tdescriptor.domain,\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{\n\t\t\t\t\t\t\tpreserveConfigured: true,\n\t\t\t\t\t\t\tsignOutMark: signOutMark,\n\t\t\t\t\t\t\tunobservedSince: signOutMark,\n\t\t\t\t\t\t\tsync: authority,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (session?.cloud && this.configuredIntegrationService.lastCloudLogout > signOutMark) {\n\t\t\tthrow new CancellationError();\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 connectNewSession(\n\t\t_descriptor: IntegrationAuthenticationSessionDescriptor,\n\t\t_options: GetSessionOptions | undefined,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\treturn Promise.resolve(undefined);\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\tconst 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\tif (options?.createIfNeeded && session == null && !options.skipConnect) {\n\t\t\treturn this.connectNewSession(descriptor, options);\n\t\t}\n\n\t\treturn session;\n\t}\n\n\tprotected override async connectNewSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions: GetSessionOptions | undefined,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tconst connected = await this.connectCloudSession(true, options?.source);\n\t\tif (!connected) return undefined;\n\n\t\treturn this.getSession(descriptor, { source: options?.source });\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\tconst fallbackId =\n\t\t\tconnectionId ?? this.configuredIntegrationService.resolveConnectionId(this.authProviderId, descriptor);\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\tconst resolved: ProviderAuthenticationSession = {\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 ?? fallbackId,\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\tif (connectionId == null) {\n\t\t\tthis.primaryResponses.set(resolved, session.id == null ? 'legacy' : 'named');\n\t\t}\n\t\treturn resolved;\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":";;;;;;;;AAwBA,MAAM,oBAAoB,KAAK,KAAK;AAQpC,IAAe,wCAAf,MAE+C;CAK1B;CACA;CALpB,cAA+C,CAAC;CAChD,mCAAsC,IAAI,QAA2D;CAErG,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;EAgBD,IAAI,MAXkB,KAAK,6BAA6B,qBACvD,KAAK,gBACL;GAAE,GAAG;GAAY,OAAO;EAAK,GAC7B,MACA;GACC,oBAAoB,SAAS,sBAAsB;GACnD,aAAa,SAAS;GACtB,MAAM,SAAS;EAChB,CACD,KAEe,YAAY,QAC1B,KAAK,WAAW;CAElB;CAEA,MACM,kBAAkB,YAAwE;EAC/F,MAAM,KAAK,cAAc,UAAU;CACpC;CAEA,MAAM,cACL,YACA,MACmB;EACnB,MAAM,SAAS,+BAA+B,KAAK,cAAc,IAAI,YAAY,SAAS,KAAA;EAC1F,MAAM,aAAa,KAAK,6BAA6B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AW;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;EACA,IAAI,gBAAgB,MACnB,KAAK,iBAAiB,IAAI,UAAU,QAAQ,MAAM,OAAO,WAAW,OAAO;EAE5E,OAAO;CACR;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"}
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 { CloudIntegrationSync } from './cloudIntegrationObservations.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; skipConnect?: boolean };\n\nabstract class IntegrationAuthenticationProviderBase<\n\tID extends IntegrationIds = IntegrationIds,\n> implements IntegrationAuthenticationProvider {\n\tprotected readonly disposables: Disposable[] = [];\n\tprotected readonly primaryResponses = new WeakMap<ProviderAuthenticationSession, 'named' | 'legacy'>();\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; sync?: CloudIntegrationSync },\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{\n\t\t\t\tpreserveConfigured: options?.preserveConfigured ?? true,\n\t\t\t\tsignOutMark: options?.signOutMark,\n\t\t\t\tsync: options?.sync,\n\t\t\t},\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\tawait this.clearSessions(descriptor);\n\t}\n\n\tasync clearSessions(\n\t\tdescriptor?: IntegrationAuthenticationSessionDescriptor,\n\t\tsync?: CloudIntegrationSync,\n\t): Promise<boolean> {\n\t\tconst domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : undefined;\n\t\tconst configured = this.configuredIntegrationService.getConfigured(this.authProviderId, { domain: domain });\n\t\tconst cleared = await this.configuredIntegrationService.deleteAllStoredSessions(\n\t\t\tthis.authProviderId,\n\t\t\tundefined,\n\t\t\tdomain,\n\t\t\tsync,\n\t\t);\n\t\tif (cleared && configured.length) {\n\t\t\tthis.fireChange();\n\t\t}\n\t\treturn cleared;\n\t}\n\n\t@trace()\n\tasync getSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetSessionOptions,\n\t\tauthority?: CloudIntegrationSync,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\t// KEEP: taken before queueing, so a sign-out while this waits refuses its store.\n\t\tconst signOutMark = this.configuredIntegrationService.getSignOutMark();\n\t\tif (!this.configuredIntegrationService.serializesCredentialAcquisition(this.authProviderId)) {\n\t\t\treturn this.acquireSession(descriptor, options, signOutMark, signOutMark, authority);\n\t\t}\n\n\t\tconst connectionId = descriptor.connectionId || this.getImplicitCloudConnectionId(descriptor, options);\n\t\t// KEEP: connecting reaches this provider's own getSession again, so it runs after the queued acquisition.\n\t\tconst session = await this.configuredIntegrationService.withCredentialAcquisition(\n\t\t\tthis.authProviderId,\n\t\t\tconnectionId,\n\t\t\t() =>\n\t\t\t\tthis.acquireSession(\n\t\t\t\t\tconnectionId != null ? { ...descriptor, connectionId: connectionId } : descriptor,\n\t\t\t\t\t{ ...options, skipConnect: true },\n\t\t\t\t\tsignOutMark,\n\t\t\t\t\tthis.configuredIntegrationService.getStoredWriteMark(),\n\t\t\t\t\tauthority,\n\t\t\t\t),\n\t\t);\n\t\tif (session != null || !options?.createIfNeeded || options.forceNewSession) return session;\n\t\t// KEEP: a sign-out or replacement since the mark refused the fetched credential; it is not a missing one.\n\t\tif (\n\t\t\tthis.configuredIntegrationService.isSessionRetiredSince(\n\t\t\t\tthis.authProviderId,\n\t\t\t\t{ id: connectionId ?? '', domain: descriptor.domain, cloud: descriptor.cloud },\n\t\t\t\tsignOutMark,\n\t\t\t)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.connectNewSession(descriptor, options);\n\t}\n\n\tprivate getImplicitCloudConnectionId(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions: GetSessionOptions | undefined,\n\t): string | undefined {\n\t\tconst connectionId = this.configuredIntegrationService.getConfiguredConnectionId(\n\t\t\tthis.authProviderId,\n\t\t\tdescriptor.domain,\n\t\t\ttrue,\n\t\t);\n\t\tconst stored = this.configuredIntegrationService.resolveConnectionId(\n\t\t\tthis.authProviderId,\n\t\t\toptions?.sync ? { ...descriptor, cloud: true } : descriptor,\n\t\t);\n\t\treturn connectionId === stored ? connectionId : undefined;\n\t}\n\n\tprivate async acquireSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions: (GetSessionOptions & { skipConnect?: boolean }) | undefined,\n\t\tinitialSignOutMark: number,\n\t\tacquisitionMark: number,\n\t\tauthority?: CloudIntegrationSync,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tlet signOutMark = initialSignOutMark;\n\t\tlet session;\n\t\tlet previousToken;\n\t\tlet refetched: ProviderAuthenticationSession | undefined;\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\tacquisitionMark = signOutMark;\n\t\t} else {\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(\n\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\trefetched,\n\t\t\t\t\tsignOutMark,\n\t\t\t\t\tacquisitionMark,\n\t\t\t\t)\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 primaryResponse = this.primaryResponses.get(session);\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\tacquisitionMark: acquisitionMark,\n\t\t\t\t\texpectedStoredAccessToken: scopedRecovery ? previousToken : undefined,\n\t\t\t\t\tprimaryResponse: primaryResponse,\n\t\t\t\t\tsync: authority,\n\t\t\t\t});\n\t\t\t\tif (authority?.isCurrent() === false) throw new CancellationError();\n\n\t\t\t\tconst primary =\n\t\t\t\t\tprimaryResponse === 'named'\n\t\t\t\t\t\t? this.configuredIntegrationService.supersedingPrimary(\n\t\t\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\t\tsignOutMark,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (primary != null) {\n\t\t\t\t\tconst current = await this.configuredIntegrationService.peekStoredSession(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tprimary,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t);\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrent == null ||\n\t\t\t\t\t\tthis.configuredIntegrationService.supersedingPrimary(\n\t\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\tsignOutMark,\n\t\t\t\t\t\t) !== primary\n\t\t\t\t\t) {\n\t\t\t\t\t\tthrow new CancellationError();\n\t\t\t\t\t}\n\n\t\t\t\t\tsession = current;\n\t\t\t\t} else if (!stored) {\n\t\t\t\t\tsession = await this.configuredIntegrationService.peekStoredSession(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tsession.id,\n\t\t\t\t\t\tsession.cloud,\n\t\t\t\t\t\tdescriptor.domain,\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{\n\t\t\t\t\t\t\tpreserveConfigured: true,\n\t\t\t\t\t\t\tsignOutMark: signOutMark,\n\t\t\t\t\t\t\tunobservedSince: signOutMark,\n\t\t\t\t\t\t\tsync: authority,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (session?.cloud && this.configuredIntegrationService.lastCloudLogout > signOutMark) {\n\t\t\tthrow new CancellationError();\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 connectNewSession(\n\t\t_descriptor: IntegrationAuthenticationSessionDescriptor,\n\t\t_options: GetSessionOptions | undefined,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\treturn Promise.resolve(undefined);\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\tconst 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\tif (options?.createIfNeeded && session == null && !options.skipConnect) {\n\t\t\treturn this.connectNewSession(descriptor, options);\n\t\t}\n\n\t\treturn session;\n\t}\n\n\tprotected override async connectNewSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions: GetSessionOptions | undefined,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tconst connected = await this.connectCloudSession(true, options?.source);\n\t\tif (!connected) return undefined;\n\n\t\treturn this.getSession(descriptor, { source: options?.source });\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\tconst fallbackId =\n\t\t\tconnectionId ?? this.configuredIntegrationService.resolveConnectionId(this.authProviderId, descriptor);\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\tconst resolved: ProviderAuthenticationSession = {\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 ?? fallbackId,\n\t\t\taccessToken: session.accessToken,\n\t\t\tscopes: session.scopes ? session.scopes.split(',') : 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\tif (connectionId == null) {\n\t\t\tthis.primaryResponses.set(resolved, session.id == null ? 'legacy' : 'named');\n\t\t}\n\t\treturn resolved;\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":";;;;;;;;AAwBA,MAAM,oBAAoB,KAAK,KAAK;AAQpC,IAAe,wCAAf,MAE+C;CAK1B;CACA;CALpB,cAA+C,CAAC;CAChD,mCAAsC,IAAI,QAA2D;CAErG,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;EAgBD,IAAI,MAXkB,KAAK,6BAA6B,qBACvD,KAAK,gBACL;GAAE,GAAG;GAAY,OAAO;EAAK,GAC7B,MACA;GACC,oBAAoB,SAAS,sBAAsB;GACnD,aAAa,SAAS;GACtB,MAAM,SAAS;EAChB,CACD,KAEe,YAAY,QAC1B,KAAK,WAAW;CAElB;CAEA,MACM,kBAAkB,YAAwE;EAC/F,MAAM,KAAK,cAAc,UAAU;CACpC;CAEA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C3C,QAAQ;GACP,kBAAkB,KAAA;EACnB;EAGD,MAAM,WAA0C;GAG/C,IAAI,QAAQ,MAAM;GAClB,aAAa,QAAQ;GACrB,QAAQ,QAAQ,SAAS,QAAQ,OAAO,MAAM,GAAG,IAAI,WAAW;GAChE,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;EACA,IAAI,gBAAgB,MACnB,KAAK,iBAAiB,IAAI,UAAU,QAAQ,MAAM,OAAO,WAAW,OAAO;EAE5E,OAAO;CACR;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"}
@@ -600,10 +600,10 @@ var ConfiguredIntegrationService = class {
600
600
  });
601
601
  }
602
602
  async readSecret(id, sessionId, cloud = false) {
603
+ const sessionJSON = await this.ctx.storage.getSecret(this.getSecretKey(id, sessionId, cloud));
604
+ if (this._disposed) return void 0;
603
605
  let storedSession;
604
606
  try {
605
- const sessionJSON = await this.ctx.storage.getSecret(this.getSecretKey(id, sessionId, cloud));
606
- if (this._disposed) return void 0;
607
607
  if (sessionJSON) {
608
608
  storedSession = JSON.parse(sessionJSON);
609
609
  if (storedSession != null) {
@@ -1 +1 @@
1
- {"version":3,"file":"configuredIntegrationService.js","names":[],"sources":["../../../../../plus/integrations/src/authentication/configuredIntegrationService.ts"],"sourcesContent":["import { debounce } from '@gitlens/utils/debounce.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 { flatten } from '@gitlens/utils/iterable.js';\nimport type {\n\tIntegrationIds,\n\tStoredConfiguredIntegrationDescriptor,\n\tStoredIntegrationConfigurations,\n} from '../constants.js';\nimport { GitSelfManagedHostIntegrationId } from '../constants.js';\nimport type { IntegrationServiceContext } from '../context.js';\nimport { providersMetadata } from '../providers/metadata.js';\nimport {\n\tareDomainsOnSameHost,\n\tbaseUrlFromDomain,\n\thostFromDomain,\n\tsameConfiguredBaseUrl,\n} from '../utils/domain.utils.js';\nimport { isSelfManagedHostIntegrationId } from '../utils/integration.utils.js';\nimport type { CloudCredentialOrigin, CloudIntegrationSync } from './cloudIntegrationObservations.js';\nimport { CloudIntegrationObservations } from './cloudIntegrationObservations.js';\nimport type { IntegrationAuthenticationSessionDescriptor } from './integrationAuthenticationProvider.js';\nimport type {\n\tCloudIntegrationAuthType,\n\tCloudIntegrationConnection,\n\tConfiguredIntegrationDescriptor,\n\tConnectionResource,\n\tProviderAuthenticationSession,\n} from './models.js';\nimport {\n\tgetSessionIdentity,\n\tgetSupportedCloudIntegrationIds,\n\tisSameAuthenticationSession,\n\tsessionExpiry,\n} from './models.js';\n\nconst cloudLogoutKey = 'integrations:cloudLogout';\n\ninterface StoredSession {\n\tcloudOrigin?: CloudCredentialOrigin;\n\tid: string;\n\taccessToken: string;\n\taccount?: { label?: string; displayName?: string; id: string };\n\tscopes: string[];\n\tcloud?: boolean;\n\ttype: CloudIntegrationAuthType | undefined;\n\texpiresAt?: string;\n\tdomain?: string;\n\t/** See {@link ProviderAuthenticationSession.baseUrl}: the configured address, path included. */\n\tbaseUrl?: string;\n\tprotocol?: string;\n\t/** The provider app key paired with the token for providers whose client needs one (e.g. Trello). */\n\tappKey?: string;\n}\n\nexport interface ConfiguredIntegrationsChangeEvent {\n\treadonly added: readonly IntegrationIds[];\n\treadonly removed: readonly IntegrationIds[];\n}\n\ntype IntegrationSessionChangeEvent = {\n\treadonly integrationId: IntegrationIds;\n\treadonly session: ProviderAuthenticationSession;\n\treadonly previousDomain?: string;\n};\n\ntype CredentialAcquisitions = { unscoped?: Promise<void>; connections: Map<string, Promise<void>> };\n\ntype CloudLogoutConnection = ConfiguredIntegrationDescriptor & { retained: boolean };\n\ntype ConfiguredStorageState = {\n\tconfigured?: Map<IntegrationIds, ConfiguredIntegrationDescriptor[]>;\n\tpersistence: Promise<void>;\n\tlocks: Map<IntegrationIds, Promise<void>>;\n\tepoch: number;\n\tscopes: Map<string, number>;\n\tsignOuts: Map<string, number>;\n\tpublications: Map<string, number>;\n\tremovals: Map<string, number>;\n\tcloud: CloudIntegrationObservations;\n\tonCloudLogout: Emitter<readonly CloudLogoutConnection[]>;\n\t// KEEP: A partial secret/descriptor write blocks this variant until both are stored successfully.\n\texpiries: Map<string, number | null>;\n};\nconst configuredStorageState = new WeakMap<IntegrationServiceContext['storage'], ConfiguredStorageState>();\n\nexport class ConfiguredIntegrationService implements Disposable {\n\tprivate readonly _onDidChange = new Emitter<ConfiguredIntegrationsChangeEvent>();\n\tprivate readonly _onWillChangeSession = new Emitter<IntegrationSessionChangeEvent>();\n\tprivate readonly _onWillRemoveSessions = new Emitter<{\n\t\tintegrationId: IntegrationIds;\n\t\tconnectionId?: string;\n\t\tcloud?: boolean;\n\t\tdomain?: string;\n\t}>();\n\tprivate readonly _acquisitions = new Map<IntegrationIds, CredentialAcquisitions>();\n\tprivate readonly state: ConfiguredStorageState;\n\tprivate _disposed = false;\n\tget onDidChange(): Event<ConfiguredIntegrationsChangeEvent> {\n\t\treturn this._onDidChange.event;\n\t}\n\tget onCloudLogout(): Event<readonly CloudLogoutConnection[]> {\n\t\treturn this.state.onCloudLogout.event;\n\t}\n\tget onWillChangeSession(): Event<IntegrationSessionChangeEvent> {\n\t\treturn this._onWillChangeSession.event;\n\t}\n\tget onWillRemoveSessions(): typeof this._onWillRemoveSessions.event {\n\t\treturn this._onWillRemoveSessions.event;\n\t}\n\n\tconstructor(private readonly ctx: IntegrationServiceContext) {\n\t\tlet state = configuredStorageState.get(ctx.storage);\n\t\tif (state == null) {\n\t\t\tstate = {\n\t\t\t\tpersistence: Promise.resolve(),\n\t\t\t\tlocks: new Map(),\n\t\t\t\tepoch: 0,\n\t\t\t\tscopes: new Map(),\n\t\t\t\tsignOuts: new Map(),\n\t\t\t\tpublications: new Map(),\n\t\t\t\tremovals: new Map(),\n\t\t\t\tcloud: new CloudIntegrationObservations(ctx.storage.get(cloudLogoutKey)),\n\t\t\t\tonCloudLogout: new Emitter<readonly CloudLogoutConnection[]>(),\n\t\t\t\texpiries: new Map(),\n\t\t\t};\n\t\t\tconfiguredStorageState.set(ctx.storage, state);\n\t\t}\n\t\tthis.state = state;\n\t}\n\n\tdispose(): void {\n\t\tthis._disposed = true;\n\t\tthis._onDidChange.dispose();\n\t\tthis._onWillChangeSession.dispose();\n\t\tthis._onWillRemoveSessions.dispose();\n\t}\n\n\tprivate get configured(): Map<IntegrationIds, ConfiguredIntegrationDescriptor[]> {\n\t\tif (this.state.configured == null) {\n\t\t\tthis.state.configured = new Map<IntegrationIds, ConfiguredIntegrationDescriptor[]>();\n\n\t\t\tconst storedConfigured = this.ctx.storage.get('integrations:configured');\n\t\t\tfor (const [id, configured] of Object.entries(storedConfigured ?? {}) as [\n\t\t\t\tIntegrationIds,\n\t\t\t\tStoredConfiguredIntegrationDescriptor[],\n\t\t\t][]) {\n\t\t\t\tif (configured == null) continue;\n\n\t\t\t\tconst descriptors = configured.map(d => ({\n\t\t\t\t\t...d,\n\t\t\t\t\tbaseUrl: isSelfManagedHostIntegrationId(id) ? getStoredBaseUrl(d.baseUrl, d.domain) : d.baseUrl,\n\t\t\t\t\tdomain: this.normalizeConfiguredDomain(id, d.domain),\n\t\t\t\t\tid: d.id || d.domain || providersMetadata[id]?.domain || id,\n\t\t\t\t\texpiresAt: d.expiresAt ? new Date(d.expiresAt) : undefined,\n\t\t\t\t}));\n\t\t\t\tthis.state.configured.set(id, descriptors);\n\t\t\t}\n\t\t}\n\n\t\treturn this.state.configured;\n\t}\n\n\tgetConfigured(\n\t\tid?: IntegrationIds,\n\t\toptions?: { cloud?: boolean; domain?: string },\n\t): ConfiguredIntegrationDescriptor[] {\n\t\tconst descriptors: ConfiguredIntegrationDescriptor[] = [];\n\n\t\tconst configured =\n\t\t\tid != null\n\t\t\t\t? this.configured.get(id)\n\t\t\t\t: [...flatten<ConfiguredIntegrationDescriptor>(this.configured.values())];\n\t\tif (!configured?.length) return descriptors;\n\n\t\tif (options?.domain != null || options?.cloud != null) {\n\t\t\tfor (const descriptor of configured) {\n\t\t\t\tif (\n\t\t\t\t\t(options?.domain != null &&\n\t\t\t\t\t\t!this.domainsMatch(id ?? descriptor.integrationId, descriptor.domain, options.domain)) ||\n\t\t\t\t\t(options?.cloud === true && !descriptor.cloud) ||\n\t\t\t\t\t(options?.cloud === false && descriptor.cloud)\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tdescriptors.push(descriptor);\n\t\t\t}\n\t\t} else {\n\t\t\tdescriptors.push(...configured);\n\t\t}\n\n\t\treturn descriptors;\n\t}\n\n\tprivate storeConfigured(id: IntegrationIds, descriptors?: ConfiguredIntegrationDescriptor[]): Promise<void> {\n\t\tconst pending = this.state.persistence.then(async () => {\n\t\t\tconst updated = new Map(this.configured);\n\t\t\tif (descriptors == null) {\n\t\t\t\tupdated.delete(id);\n\t\t\t} else {\n\t\t\t\tupdated.set(id, descriptors);\n\t\t\t}\n\n\t\t\tconst record: Partial<StoredIntegrationConfigurations> = {};\n\t\t\tfor (const [providerId, connections] of updated) {\n\t\t\t\trecord[providerId] = connections.map(connection => ({\n\t\t\t\t\t...connection,\n\t\t\t\t\texpiresAt:\n\t\t\t\t\t\tconnection.expiresAt instanceof Date\n\t\t\t\t\t\t\t? connection.expiresAt.toISOString()\n\t\t\t\t\t\t\t: connection.expiresAt,\n\t\t\t\t}));\n\t\t\t}\n\t\t\tawait this.ctx.storage.store('integrations:configured', record);\n\t\t\tthis.state.configured = updated;\n\t\t});\n\t\tthis.state.persistence = pending.catch(() => {});\n\t\treturn pending;\n\t}\n\n\tprivate async addOrUpdateConfigured(descriptor: ConfiguredIntegrationDescriptor): Promise<void> {\n\t\tdescriptor = {\n\t\t\t...descriptor,\n\t\t\tbaseUrl: isSelfManagedHostIntegrationId(descriptor.integrationId)\n\t\t\t\t? getStoredBaseUrl(descriptor.baseUrl, descriptor.domain)\n\t\t\t\t: descriptor.baseUrl,\n\t\t\tdomain: this.normalizeConfiguredDomain(descriptor.integrationId, descriptor.domain),\n\t\t};\n\t\tconst descriptors = [...(this.configured.get(descriptor.integrationId) ?? [])];\n\t\tconst existing = descriptors.find(d => d.id === descriptor.id && d.cloud === descriptor.cloud);\n\n\t\t// The first connection for a provider/domain is primary by default; an explicit flag (or the\n\t\t// existing value) always wins. Self-managed providers can span multiple hosts under the same\n\t\t// integration id, so each host needs its own primary.\n\t\tconst primaryScope = this.getPrimaryScope(descriptor.integrationId, descriptors, descriptor.domain);\n\t\tconst primary = descriptor.primary ?? existing?.primary ?? !primaryScope.some(d => d.primary);\n\t\t// Preserve a previously-resolved type/accountName when the incoming write doesn't carry them (e.g.\n\t\t// the model re-stores the primary session with an empty account, after reconcile enriched it).\n\t\tconst type = descriptor.type ?? existing?.type;\n\t\tconst accountName = descriptor.accountName ?? existing?.accountName;\n\t\t// A write without a workspace (a failed lookup, or a session re-store) keeps the stored pair whole.\n\t\tconst resource = descriptor.resourceId != null ? descriptor : existing;\n\t\tconst normalized: ConfiguredIntegrationDescriptor = {\n\t\t\t...descriptor,\n\t\t\tprimary: primary,\n\t\t\ttype: type,\n\t\t\taccountName: accountName,\n\t\t\tresourceName: resource?.resourceName,\n\t\t\tresourceId: resource?.resourceId,\n\t\t};\n\n\t\tlet changed: boolean;\n\t\tif (existing != null) {\n\t\t\t// `baseUrl` is compared alongside `domain`, not folded into it: `domain` is normalized to a bare\n\t\t\t// host, so a connection re-pointed to another context path on the SAME host is identical by domain\n\t\t\t// and would otherwise be treated as unchanged — leaving the stored descriptor, and every warm\n\t\t\t// integration listening for the change, on the old address.\n\t\t\tif (\n\t\t\t\texisting.domain === normalized.domain &&\n\t\t\t\tsameConfiguredBaseUrl(existing.baseUrl, normalized.baseUrl) &&\n\t\t\t\texisting.expiresAt === normalized.expiresAt &&\n\t\t\t\texisting.scopes === normalized.scopes &&\n\t\t\t\t(existing.primary ?? false) === (normalized.primary ?? false) &&\n\t\t\t\texisting.type === normalized.type &&\n\t\t\t\texisting.accountName === normalized.accountName &&\n\t\t\t\texisting.resourceName === normalized.resourceName &&\n\t\t\t\texisting.resourceId === normalized.resourceId\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Only fire the change event on address/scopes/primary/type/accountName changes (ignore expiresAt churn)\n\t\t\tchanged =\n\t\t\t\texisting.domain !== normalized.domain ||\n\t\t\t\t!sameConfiguredBaseUrl(existing.baseUrl, normalized.baseUrl) ||\n\t\t\t\texisting.scopes !== normalized.scopes ||\n\t\t\t\t(existing.primary ?? false) !== (normalized.primary ?? false) ||\n\t\t\t\texisting.type !== normalized.type ||\n\t\t\t\texisting.accountName !== normalized.accountName ||\n\t\t\t\texisting.resourceName !== normalized.resourceName ||\n\t\t\t\texisting.resourceId !== normalized.resourceId;\n\n\t\t\tdescriptors.splice(descriptors.indexOf(existing), 1);\n\t\t} else {\n\t\t\tchanged = true;\n\t\t}\n\n\t\tdescriptors.push(normalized);\n\t\tawait this.storeConfigured(descriptor.integrationId, descriptors);\n\n\t\tif (changed) {\n\t\t\tthis.fireChange(descriptor.integrationId);\n\t\t}\n\t}\n\n\tprivate async removeConfigured(\n\t\tid: IntegrationIds,\n\t\toptions: { connectionId: string; cloud: boolean | undefined },\n\t): Promise<void> {\n\t\tconst existing = this.configured.get(id);\n\t\tif (existing == null || existing.length === 0) return;\n\n\t\tconst removedPrimaryDomains = new Set<string | undefined>();\n\t\tconst descriptors: ConfiguredIntegrationDescriptor[] = [];\n\t\tfor (const d of existing) {\n\t\t\tif (\n\t\t\t\td.id === options.connectionId &&\n\t\t\t\t(options?.cloud == null ||\n\t\t\t\t\t(options?.cloud === true && d.cloud === true) ||\n\t\t\t\t\t(options?.cloud === false && d.cloud === false))\n\t\t\t) {\n\t\t\t\tif (d.primary) {\n\t\t\t\t\tremovedPrimaryDomains.add(d.domain);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tdescriptors.push(d);\n\t\t}\n\n\t\tif (descriptors.length === existing.length) return; // nothing matched\n\n\t\t// Promote a secondary to primary when the removed connection was the primary and others remain\n\t\t// in the same primary scope, so the provider/host stays in a well-defined connected state.\n\t\tfor (const domain of removedPrimaryDomains) {\n\t\t\tif (descriptors.some(d => this.isInPrimaryScope(id, d, domain) && d.primary)) continue;\n\n\t\t\tconst index = descriptors.findIndex(d => this.isInPrimaryScope(id, d, domain));\n\t\t\tif (index !== -1) {\n\t\t\t\tdescriptors[index] = { ...descriptors[index], primary: true };\n\t\t\t}\n\t\t}\n\n\t\tawait this.storeConfigured(id, descriptors);\n\t\tthis.fireChange(undefined, id);\n\t}\n\n\tprivate withLock<T>(id: IntegrationIds, fn: () => Promise<T> | T): Promise<T> {\n\t\tconst locks = this.state.locks;\n\t\tconst run = (locks.get(id) ?? Promise.resolve()).then(fn);\n\t\tconst settled = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\tlocks.set(id, settled);\n\t\tvoid settled.then(() => {\n\t\t\tif (locks.get(id) === settled) {\n\t\t\t\tlocks.delete(id);\n\t\t\t}\n\t\t});\n\t\treturn run;\n\t}\n\n\tserializesCredentialAcquisition(id: IntegrationIds): boolean {\n\t\treturn id === GitSelfManagedHostIntegrationId.AzureDevOpsServer;\n\t}\n\n\t/**\n\t * KEEP: not reentrant. A `connectionId` acquisition waits for that connection's and every earlier unscoped one;\n\t * an unscoped acquisition waits for every earlier acquisition of `id`.\n\t */\n\twithCredentialAcquisition<T>(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string | undefined,\n\t\tfn: () => Promise<T>,\n\t): Promise<T> {\n\t\tif (!this.serializesCredentialAcquisition(id)) return fn();\n\n\t\tlet queue = this._acquisitions.get(id);\n\t\tif (queue == null) {\n\t\t\tqueue = { connections: new Map() };\n\t\t\tthis._acquisitions.set(id, queue);\n\t\t}\n\n\t\tconst predecessors = (\n\t\t\tconnectionId != null\n\t\t\t\t? [queue.unscoped, queue.connections.get(connectionId)]\n\t\t\t\t: [queue.unscoped, ...queue.connections.values()]\n\t\t).filter(p => p != null);\n\t\tconst run = Promise.all(predecessors).then(() => fn());\n\t\tconst settled = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\tif (connectionId != null) {\n\t\t\tqueue.connections.set(connectionId, settled);\n\t\t} else {\n\t\t\tqueue.unscoped = settled;\n\t\t\tqueue.connections.clear();\n\t\t}\n\n\t\tconst current = queue;\n\t\tvoid settled.then(() => {\n\t\t\tif (connectionId != null) {\n\t\t\t\tif (current.connections.get(connectionId) === settled) {\n\t\t\t\t\tcurrent.connections.delete(connectionId);\n\t\t\t\t}\n\t\t\t} else if (current.unscoped === settled) {\n\t\t\t\tcurrent.unscoped = undefined;\n\t\t\t}\n\n\t\t\tif (current.unscoped == null && current.connections.size === 0 && this._acquisitions.get(id) === current) {\n\t\t\t\tthis._acquisitions.delete(id);\n\t\t\t}\n\t\t});\n\t\treturn run;\n\t}\n\n\t/**\n\t * Taken before a token is read or fetched and handed to {@link storeSession}. A later sign-out or a recovery\n\t * that replaces the credential invalidates the pending store.\n\t */\n\tgetSignOutMark(): number {\n\t\treturn ++this.state.epoch;\n\t}\n\n\tprivate retirePendingStores(scope: string, cloud?: boolean): void {\n\t\tthis.retireStoredWrites(scope, cloud);\n\t\tthis.state.signOuts.set(cloud == null ? scope : `${scope}|${cloud}`, this.getStoredWriteMark());\n\t}\n\n\tbeginCloudSync(): number {\n\t\treturn ++this.state.epoch;\n\t}\n\n\tget lastCloudLogout(): number {\n\t\treturn this.state.cloud.lastLogout;\n\t}\n\n\tget hasCloudLogout(): boolean {\n\t\treturn this.state.cloud.hasLogout;\n\t}\n\n\tasync retireCloudAccount(mark: number): Promise<CloudIntegrationSync | undefined> {\n\t\tif (this._disposed) return undefined;\n\n\t\tconst connections = this.getConfigured(undefined, { cloud: true });\n\t\tconst sync = this.state.cloud.acceptLogout(mark, ++this.state.epoch, connections);\n\t\tif (sync == null) return undefined;\n\n\t\tconst persist = this.persistCloudLogout();\n\n\t\tconst departing = connections.map(c => ({\n\t\t\t...c,\n\t\t\tretained: this.state.cloud.acquiredAfter(`${c.integrationId}|connection:${c.id}`, mark),\n\t\t}));\n\t\t// KEEP: Reserve all provider locks before notifying observers that can start publishing the next account.\n\t\tconst cleanup = getSupportedCloudIntegrationIds().map(id =>\n\t\t\tthis.withLock(id, () => this.clearDepartedCloudCredentials(id, mark, sync.mark)),\n\t\t);\n\t\tthis.state.onCloudLogout.fire(departing);\n\t\tconst results = await Promise.allSettled([persist, ...cleanup]);\n\t\tconst failure = results.find(result => result.status === 'rejected');\n\t\tif (failure != null) throw failure.reason;\n\t\treturn this._disposed ? undefined : sync;\n\t}\n\n\tprivate persistCloudLogout(): Promise<void> {\n\t\tconst pending = this.state.persistence.then(() =>\n\t\t\tthis.ctx.storage.store(cloudLogoutKey, this.state.cloud.snapshotLogout()),\n\t\t);\n\t\tthis.state.persistence = pending.catch(() => {});\n\t\treturn pending;\n\t}\n\n\tprivate async clearDepartedCloudCredentials(id: IntegrationIds, cutoff: number, logout: number): Promise<void> {\n\t\tconst connections = this.getConfigured(id);\n\t\tconst ids = new Set(connections.map(c => c.id));\n\t\tids.add(providersMetadata[id]?.domain || id);\n\t\tconst failures: unknown[] = [];\n\t\tfor (const connectionId of ids) {\n\t\t\ttry {\n\t\t\t\tconst localKey = this.getLocalSecretKey(id, connectionId);\n\t\t\t\tconst raw = await this.ctx.storage.getSecret(localKey);\n\t\t\t\tif (raw != null && isLegacyCloudSecret(raw)) {\n\t\t\t\t\tawait this.ctx.storage.deleteSecret(localKey);\n\t\t\t\t\tawait this.removeConfigured(id, { connectionId: connectionId, cloud: false });\n\t\t\t\t}\n\t\t\t\tconst scope = `${id}|connection:${connectionId}`;\n\t\t\t\tif (this.state.cloud.acquiredAfter(scope, cutoff)) continue;\n\n\t\t\t\tconst departed = connections.find(c => c.id === connectionId && c.cloud);\n\t\t\t\tif (departed != null && this.state.cloud.depart(id, departed.domain, connectionId, logout)) {\n\t\t\t\t\tawait this.persistCloudLogout();\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tawait this.ctx.storage.deleteSecret(this.getCloudSecretKey(id, connectionId));\n\t\t\t\t} finally {\n\t\t\t\t\tthis.state.cloud.remove(scope);\n\t\t\t\t\tawait this.removeConfigured(id, { connectionId: connectionId, cloud: true });\n\t\t\t\t}\n\t\t\t} catch (ex) {\n\t\t\t\tfailures.push(ex);\n\t\t\t}\n\t\t}\n\t\tif (failures.length) throw new AggregateError(failures, 'Unable to clear retired cloud credentials.');\n\t}\n\n\tgetCloudDeparture(id: IntegrationIds, session: ProviderAuthenticationSession): number | undefined {\n\t\treturn session.cloud ? this.state.cloud.departedAt(id, session.domain, session.id) : undefined;\n\t}\n\n\tconfirmHostCloudSession(\n\t\tid: IntegrationIds,\n\t\tsession: ProviderAuthenticationSession,\n\t\tlogout: number,\n\t): Promise<boolean> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (this._disposed) return false;\n\n\t\t\tconst departure = this.getCloudDeparture(id, session);\n\t\t\tif (departure != null && logout < departure) return false;\n\n\t\t\tconst stored = await this.peekSecret(id, session.id, true, session.domain);\n\t\t\tif (this._disposed || logout !== this.lastCloudLogout || stored === null) return false;\n\t\t\tif (stored === undefined) {\n\t\t\t\treturn (\n\t\t\t\t\tdeparture == null &&\n\t\t\t\t\t!this.getConfigured(id, {\n\t\t\t\t\t\tcloud: true,\n\t\t\t\t\t\tdomain: isSelfManagedHostIntegrationId(id) ? session.domain : undefined,\n\t\t\t\t\t}).some(c => c.id === session.id)\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn (\n\t\t\t\tstored.id === session.id &&\n\t\t\t\tstored.cloud &&\n\t\t\t\tstored.accessToken === session.accessToken &&\n\t\t\t\t(!stored.account.id || stored.account.id === session.account.id)\n\t\t\t);\n\t\t});\n\t}\n\n\tasync acceptCloudSync(\n\t\tmark: number,\n\t\tconnections: ReadonlyMap<IntegrationIds, readonly CloudIntegrationConnection[]>,\n\t): Promise<CloudIntegrationSync | undefined> {\n\t\tif (this._disposed) return undefined;\n\n\t\tconst sync = this.state.cloud.accept(mark, connections);\n\t\tif (sync == null) return undefined;\n\n\t\t// KEEP: A previous sync may already have dispatched a storage operation under another provider lock.\n\t\tawait Promise.all(this.state.locks.values());\n\t\treturn !this._disposed && sync.isCurrent() ? sync : undefined;\n\t}\n\n\tsupersedingPrimary(id: IntegrationIds, session: ProviderAuthenticationSession, mark: number): string | undefined {\n\t\treturn this.state.cloud.supersedingPrimary(id, session.domain, session.id, mark);\n\t}\n\n\thasNewCloudConnection(id: IntegrationIds, domain: string | undefined, mark: number): boolean {\n\t\tconst scopedDomain = isSelfManagedHostIntegrationId(id) ? domain : undefined;\n\t\treturn this.getConfigured(id, { cloud: true, domain: scopedDomain }).some(c =>\n\t\t\tthis.state.cloud.observedSince(`${id}|connection:${c.id}`, mark),\n\t\t);\n\t}\n\n\tasync dispatchHostListRetirement(\n\t\tid: IntegrationIds,\n\t\tdomain: string,\n\t\tsync: CloudIntegrationSync,\n\t\tretire: () => Promise<void>,\n\t): Promise<boolean> {\n\t\tconst dispatched = await this.withLock(id, () => {\n\t\t\tif (this._disposed || !sync.isCurrent() || this.hasNewCloudConnection(id, domain, sync.mark)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// KEEP: The host can re-enter storage after dispatch, so it must settle outside the provider lock.\n\t\t\treturn { settled: retire() };\n\t\t});\n\t\tif (dispatched == null) return false;\n\n\t\tawait dispatched.settled;\n\t\treturn !this._disposed && sync.isCurrent() && !this.hasNewCloudConnection(id, domain, sync.mark);\n\t}\n\n\tgetStoredWriteMark(): number {\n\t\treturn this.state.epoch;\n\t}\n\n\tisStoredWriteRetiredSince(\n\t\tid: IntegrationIds,\n\t\tsession: Pick<ProviderAuthenticationSession, 'id' | 'domain' | 'cloud'>,\n\t\tmark: number,\n\t): boolean {\n\t\treturn (\n\t\t\tthis._disposed ||\n\t\t\t(session.cloud && this.state.cloud.loggedOutSince(mark)) ||\n\t\t\tthis.hasRetirement(this.state.scopes, id, session, mark)\n\t\t);\n\t}\n\n\tasync captureConfiguredConnection(id: IntegrationIds, connectionId: string): Promise<(() => boolean) | undefined> {\n\t\treturn (await this.captureConnectionSelection(id, connectionId))?.isCurrent;\n\t}\n\n\tasync captureConnectionSelection(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string,\n\t): Promise<{ connection: ConfiguredIntegrationDescriptor; isCurrent: () => boolean } | undefined> {\n\t\tconst matches = this.getConfigured(id).filter(connection => connection.id === connectionId);\n\t\tconst selected = matches.find(connection => connection.cloud) ?? matches[0];\n\t\tif (selected == null) return undefined;\n\n\t\tconst mark = this.state.epoch;\n\t\tconst scope = { id: connectionId, domain: selected.domain ?? '', cloud: selected.cloud };\n\t\tconst current = () =>\n\t\t\t!this._disposed &&\n\t\t\t!(selected.cloud && this.state.cloud.loggedOutSince(mark)) &&\n\t\t\t!this.hasRetirement(this.state.removals, id, scope, mark) &&\n\t\t\tthis.configured\n\t\t\t\t.get(id)\n\t\t\t\t?.some(\n\t\t\t\t\tconnection =>\n\t\t\t\t\t\tconnection.id === connectionId &&\n\t\t\t\t\t\tconnection.cloud === selected.cloud &&\n\t\t\t\t\t\tthis.domainsMatch(id, connection.domain, selected.domain) &&\n\t\t\t\t\t\tsameConfiguredBaseUrl(connection.baseUrl, selected.baseUrl),\n\t\t\t\t) === true;\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (\n\t\t\t\tselected.cloud &&\n\t\t\t\tthis.hasCloudLogout &&\n\t\t\t\t(await this.peekSecret(id, connectionId, true, scope.domain)) == null\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn current() ? { connection: selected, isCurrent: current } : undefined;\n\t\t});\n\t}\n\n\tprivate async duringRemoval(scope: string, cloud: boolean | undefined, remove: () => Promise<void>): Promise<void> {\n\t\tconst key = cloud == null ? scope : `${scope}|${cloud}`;\n\t\tthis.retirePendingStores(scope, cloud);\n\t\tthis.state.removals.set(key, Infinity);\n\t\ttry {\n\t\t\tawait remove();\n\t\t} finally {\n\t\t\tconst mark = ++this.state.epoch;\n\t\t\tthis.state.removals.set(key, mark);\n\t\t\tthis.state.signOuts.set(key, mark);\n\t\t}\n\t}\n\n\tcaptureStoredRelationshipCurrency(\n\t\tid: IntegrationIds,\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<(() => boolean) | undefined> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tconst mark = this.getStoredWriteMark();\n\t\t\tconst stored = await this.peekSecret(id, session.id, session.cloud, session.domain);\n\t\t\tif (\n\t\t\t\tthis.isStoredWriteRetiredSince(id, session, mark) ||\n\t\t\t\tstored == null ||\n\t\t\t\t!isSameAuthenticationSession(stored, session)\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst scope = `${id}|connection:${session.id}|${session.cloud}`;\n\t\t\tconst expiries = this.state.expiries;\n\t\t\tif (expiries.get(scope) === null) return undefined;\n\n\t\t\texpiries.set(scope, sessionExpiry(stored.expiresAt));\n\t\t\treturn () => !this.isStoredWriteRetiredSince(id, session, mark) && (expiries.get(scope) ?? 0) > Date.now();\n\t\t});\n\t}\n\n\tprivate retireStoredWrites(scope: string, cloud?: boolean): void {\n\t\tconst retirements = this.state;\n\t\tretirements.scopes.set(cloud == null ? scope : `${scope}|${cloud}`, ++retirements.epoch);\n\t\tfor (const variant of cloud == null ? [true, false] : [cloud]) {\n\t\t\tconst key = `${scope}|${variant}`;\n\t\t\tif (retirements.expiries.get(key) !== null) {\n\t\t\t\tretirements.expiries.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getHostScope(id: IntegrationIds, domain: string): string {\n\t\treturn `${id}|host:${hostFromDomain(domain) ?? domain}`;\n\t}\n\n\tisSessionRetiredSince(\n\t\tid: IntegrationIds,\n\t\tsession: Pick<ProviderAuthenticationSession, 'id' | 'domain'> & { cloud?: boolean },\n\t\tmark: number,\n\t\tacquisitionMark = mark,\n\t): boolean {\n\t\treturn (\n\t\t\t(session.cloud !== false && !this.state.cloud.allows(this.state.cloud.origin(mark))) ||\n\t\t\tthis.hasRetirement(this.state.signOuts, id, session, mark) ||\n\t\t\tthis.hasRetirement(this.state.publications, id, session, acquisitionMark)\n\t\t);\n\t}\n\n\tprivate hasRetirement(\n\t\tscopes: ReadonlyMap<string, number>,\n\t\tid: IntegrationIds,\n\t\tsession: Pick<ProviderAuthenticationSession, 'id' | 'domain'> & { cloud?: boolean },\n\t\tmark: number,\n\t): boolean {\n\t\tconst since = (scope: string) =>\n\t\t\t(scopes.get(scope) ?? 0) > mark ||\n\t\t\t(session.cloud !== false && (scopes.get(`${scope}|true`) ?? 0) > mark) ||\n\t\t\t(session.cloud !== true && (scopes.get(`${scope}|false`) ?? 0) > mark);\n\t\tif (since(id)) return true;\n\t\tif (isSelfManagedHostIntegrationId(id) && session.domain && since(this.getHostScope(id, session.domain))) {\n\t\t\treturn true;\n\t\t}\n\t\treturn since(`${id}|connection:${session.id}`);\n\t}\n\n\t/**\n\t * Stores the session's secret and descriptor together. A pending store can be invalidated by a sign-out or a\n\t * credential recovery. A recovery must still own the stored credential when it publishes its replacement.\n\t */\n\tstoreSession(\n\t\tid: IntegrationIds,\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions?: {\n\t\t\tsignOutMark?: number;\n\t\t\tacquisitionMark?: number;\n\t\t\tresource?: ConnectionResource;\n\t\t\texpectedStoredAccessToken?: string;\n\t\t\tprimaryResponse?: 'named' | 'legacy';\n\t\t\tsync?: CloudIntegrationSync;\n\t\t},\n\t): Promise<boolean> {\n\t\tconst origin = session.cloud\n\t\t\t? this.state.cloud.origin(options?.sync?.mark ?? options?.signOutMark ?? this.getSignOutMark())\n\t\t\t: undefined;\n\t\treturn this.withLock(id, async () => {\n\t\t\tconst canStore = () =>\n\t\t\t\t!this._disposed &&\n\t\t\t\t(origin == null || this.state.cloud.allows(origin)) &&\n\t\t\t\toptions?.sync?.isCurrent() !== false &&\n\t\t\t\t(options?.signOutMark == null ||\n\t\t\t\t\t!this.isSessionRetiredSince(id, session, options.signOutMark, options.acquisitionMark));\n\t\t\tif (!canStore()) return false;\n\n\t\t\tconst scope = `${id}|connection:${session.id}`;\n\t\t\tconst expiryScope = `${scope}|${session.cloud}`;\n\t\t\tconst expiries = this.state.expiries;\n\t\t\tconst previous = await this.peekSecret(id, session.id, session.cloud, session.domain);\n\t\t\tif (\n\t\t\t\t(options?.primaryResponse === 'legacy' &&\n\t\t\t\t\toptions.signOutMark != null &&\n\t\t\t\t\tthis.state.cloud.observedSince(scope, options.signOutMark)) ||\n\t\t\t\t!canStore() ||\n\t\t\t\t(options?.expectedStoredAccessToken != null &&\n\t\t\t\t\tprevious?.accessToken !== options.expectedStoredAccessToken)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst changed = getSessionIdentity(previous) !== getSessionIdentity(session);\n\t\t\tconst replaced = changed || previous?.account?.id !== session.account?.id;\n\t\t\tif (replaced) {\n\t\t\t\tthis.retireStoredWrites(scope, session.cloud);\n\t\t\t}\n\t\t\tif (changed) {\n\t\t\t\tthis._onWillChangeSession.fire({\n\t\t\t\t\tintegrationId: id,\n\t\t\t\t\tsession: session,\n\t\t\t\t\tpreviousDomain: previous?.domain,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!canStore()) return false;\n\n\t\t\tconst trackedExpiry = expiries.get(expiryScope);\n\t\t\tconst nextExpiry = sessionExpiry(session.expiresAt);\n\t\t\tif (typeof trackedExpiry === 'number') {\n\t\t\t\texpiries.set(expiryScope, Math.min(trackedExpiry, nextExpiry));\n\t\t\t}\n\t\t\tconst logoutAtDispatch = this.lastCloudLogout;\n\t\t\ttry {\n\t\t\t\tawait this.writeSecret(id, session, options?.resource, origin);\n\t\t\t} catch (ex) {\n\t\t\t\tif (origin != null && !this.state.cloud.allows(origin)) throw ex;\n\n\t\t\t\tthis.retirePendingStores(scope, session.cloud);\n\t\t\t\tif (session.cloud) {\n\t\t\t\t\tthis.state.cloud.observe(scope, this.state.epoch);\n\t\t\t\t}\n\t\t\t\texpiries.set(expiryScope, null);\n\t\t\t\tthrow ex;\n\t\t\t}\n\t\t\tif (origin != null && !this.state.cloud.allows(origin)) return false;\n\n\t\t\tif (origin != null) {\n\t\t\t\tthis.state.cloud.published(scope, origin.mark);\n\t\t\t}\n\t\t\tif (expiries.has(expiryScope)) {\n\t\t\t\texpiries.set(expiryScope, nextExpiry);\n\t\t\t}\n\t\t\tif (replaced || nextExpiry !== sessionExpiry(previous?.expiresAt)) {\n\t\t\t\t// KEEP: A write already dispatched at logout precedes acquisitions admitted after it.\n\t\t\t\tconst mark =\n\t\t\t\t\tsession.cloud && this.lastCloudLogout !== logoutAtDispatch\n\t\t\t\t\t\t? this.lastCloudLogout\n\t\t\t\t\t\t: ++this.state.epoch;\n\t\t\t\tthis.state.publications.set(expiryScope, mark);\n\t\t\t\tif (\n\t\t\t\t\toptions?.expectedStoredAccessToken != null &&\n\t\t\t\t\tsession.accessToken !== options.expectedStoredAccessToken\n\t\t\t\t) {\n\t\t\t\t\tthis.state.signOuts.set(expiryScope, mark);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (session.cloud && options?.primaryResponse !== 'legacy') {\n\t\t\t\tthis.state.cloud.observe(\n\t\t\t\t\tscope,\n\t\t\t\t\toptions?.sync?.isCurrent() === false ? options.sync.mark : ++this.state.epoch,\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\toptions?.primaryResponse === 'named' &&\n\t\t\t\t\toptions.signOutMark != null &&\n\t\t\t\t\toptions.sync?.isCurrent() !== false &&\n\t\t\t\t\tthis.supersedingPrimary(id, session, options.signOutMark) == null\n\t\t\t\t) {\n\t\t\t\t\tconst primaryMark = ++this.state.epoch;\n\t\t\t\t\tawait this.setPrimaryConnectionCore(id, session.id);\n\t\t\t\t\tthis.state.cloud.observePrimary(id, session.domain, session.id, primaryMark);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\t}\n\n\tpeekStoredSession(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string,\n\t\tcloud: boolean,\n\t\tdomain: string,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (this._disposed) return undefined;\n\n\t\t\tconst session = await this.peekSecret(id, connectionId, cloud, domain);\n\t\t\treturn this._disposed ? undefined : (session ?? undefined);\n\t\t});\n\t}\n\n\tprivate async peekSecret(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string,\n\t\tcloud: boolean,\n\t\tdomain: string,\n\t): Promise<ProviderAuthenticationSession | null | undefined> {\n\t\tconst json = await this.ctx.storage.getSecret(this.getSecretKey(id, connectionId, cloud));\n\t\tif (json == null) return undefined;\n\n\t\ttry {\n\t\t\tconst stored = JSON.parse(json) as StoredSession;\n\t\t\tif (this.isRetiredSecret(stored, cloud)) return null;\n\t\t\treturn convertStoredSessionToSession(\n\t\t\t\tstored,\n\t\t\t\t{ connectionId: connectionId, domain: domain, scopes: [] },\n\t\t\t\tcloud,\n\t\t\t);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tprivate isRetiredSecret(session: StoredSession, cloud: boolean): boolean {\n\t\tif (!cloud && session.cloud !== false && session.expiresAt != null) return this.hasCloudLogout;\n\t\treturn (cloud || session.cloud === true) && !this.state.cloud.allows(session.cloudOrigin);\n\t}\n\n\tgetStoredSession(\n\t\tid: IntegrationIds,\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (this._disposed) return undefined;\n\n\t\t\tconst sessionId = this.resolveConnectionId(id, descriptor);\n\t\t\tlet session = descriptor.cloud === true ? undefined : await this.readSecret(id, sessionId, false);\n\t\t\tif (this._disposed) return undefined;\n\n\t\t\tlet cloudIfMissing = false;\n\t\t\tif (session != null && session.cloud !== false && session.expiresAt != null) {\n\t\t\t\tcloudIfMissing = true;\n\t\t\t\ttry {\n\t\t\t\t\tawait this.deleteSecrets(id, session.id);\n\t\t\t\t\tif (this.hasCloudLogout) return undefined;\n\n\t\t\t\t\tawait this.writeSecret(id, { ...session, cloud: true });\n\t\t\t\t} catch {}\n\t\t\t}\n\n\t\t\tif (session == null && descriptor.cloud !== false) {\n\t\t\t\tcloudIfMissing = true;\n\t\t\t\tsession = await this.readSecret(id, sessionId, true);\n\t\t\t}\n\n\t\t\treturn this._disposed || (session != null && this.isRetiredSecret(session, cloudIfMissing))\n\t\t\t\t? undefined\n\t\t\t\t: convertStoredSessionToSession(session, descriptor, cloudIfMissing);\n\t\t});\n\t}\n\n\t/**\n\t * Deletes one connection's stored session. `signOut` is for a delete that signs the integration out (a forced new\n\t * session): it also refuses the store of any token of the provider, or of the descriptor's self-managed host,\n\t * fetched before it (see {@link getSignOutMark}). A cleanup of a replaced token leaves it unset.\n\t */\n\tdeleteStoredSessions(\n\t\tid: IntegrationIds,\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\tcloud?: boolean,\n\t\toptions?: {\n\t\t\tpreserveConfigured?: boolean;\n\t\t\tsignOut?: boolean;\n\t\t\tsignOutMark?: number;\n\t\t\tunobservedSince?: number;\n\t\t\tsync?: CloudIntegrationSync;\n\t\t},\n\t): Promise<boolean> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (this._disposed || options?.sync?.isCurrent() === false) return false;\n\n\t\t\tconst connectionId = this.resolveConnectionId(id, descriptor);\n\t\t\tif (\n\t\t\t\toptions?.unobservedSince != null &&\n\t\t\t\tthis.state.cloud.observedSince(`${id}|connection:${connectionId}`, options.unobservedSince)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\toptions?.signOutMark != null &&\n\t\t\t\tthis.isSessionRetiredSince(\n\t\t\t\t\tid,\n\t\t\t\t\t{ id: connectionId, domain: descriptor.domain, cloud: cloud },\n\t\t\t\t\toptions.signOutMark,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif (options?.signOut) {\n\t\t\t\tthis.retirePendingStores(\n\t\t\t\t\tisSelfManagedHostIntegrationId(id) && descriptor.domain\n\t\t\t\t\t\t? this.getHostScope(id, descriptor.domain)\n\t\t\t\t\t\t: id,\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait this.deleteSecrets(id, connectionId, cloud, {\n\t\t\t\t...options,\n\t\t\t\tonRemoving: () =>\n\t\t\t\t\tthis._onWillRemoveSessions.fire({\n\t\t\t\t\t\tintegrationId: id,\n\t\t\t\t\t\tconnectionId: connectionId,\n\t\t\t\t\t\tcloud: cloud,\n\t\t\t\t\t\tdomain: descriptor.domain,\n\t\t\t\t\t}),\n\t\t\t});\n\t\t\treturn true;\n\t\t});\n\t}\n\n\t/** Signs out of every stored session of the provider, or of one self-managed host when `domain` is given. */\n\tdeleteAllStoredSessions(\n\t\tid: IntegrationIds,\n\t\tcloud?: boolean,\n\t\tdomain?: string,\n\t\tsync?: CloudIntegrationSync,\n\t): Promise<boolean> {\n\t\tconst scope = isSelfManagedHostIntegrationId(id) && domain != null ? this.getHostScope(id, domain) : id;\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (\n\t\t\t\tthis._disposed ||\n\t\t\t\tsync?.isCurrent() === false ||\n\t\t\t\t(sync && this.hasNewCloudConnection(id, domain, sync.mark))\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tawait this.duringRemoval(scope, cloud, async () => {\n\t\t\t\tthis._onWillRemoveSessions.fire({ integrationId: id, cloud: cloud, domain: domain });\n\t\t\t\tif (this._disposed) return;\n\n\t\t\t\tawait this.deleteAllSecrets(id, cloud, domain);\n\t\t\t});\n\t\t\treturn !this._disposed;\n\t\t});\n\t}\n\n\tasync purgeStoredConfiguration(ids: readonly string[]): Promise<void> {\n\t\tfor (const id of ids as readonly IntegrationIds[]) {\n\t\t\tawait this.withLock(id, async () => {\n\t\t\t\tconst descriptors =\n\t\t\t\t\tthis.ctx.storage.get<StoredIntegrationConfigurations>('integrations:configured')?.[id];\n\t\t\t\tif (descriptors == null) return;\n\n\t\t\t\tawait this.duringRemoval(id, undefined, async () => {\n\t\t\t\t\tfor (const descriptor of descriptors) {\n\t\t\t\t\t\tconst key = descriptor.id || descriptor.domain || providersMetadata[id]?.domain || id;\n\t\t\t\t\t\tawait this.ctx.storage.deleteSecret(this.getLocalSecretKey(id, key));\n\t\t\t\t\t\tawait this.ctx.storage.deleteSecret(this.getCloudSecretKey(id, key));\n\t\t\t\t\t\tif (descriptor.domain) {\n\t\t\t\t\t\t\tawait this.ctx.storage.deleteWorkspace(`connected:${id}:${descriptor.domain}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tawait this.storeConfigured(id);\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async deleteSecrets(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string,\n\t\tcloud?: boolean,\n\t\toptions?: { preserveConfigured?: boolean; onRemoving?: () => void },\n\t): Promise<void> {\n\t\tawait this.duringRemoval(`${id}|connection:${connectionId}`, cloud, async () => {\n\t\t\tif (options?.onRemoving != null) {\n\t\t\t\toptions.onRemoving();\n\t\t\t\tif (this._disposed) return;\n\t\t\t}\n\n\t\t\tif (cloud == null || cloud === false) {\n\t\t\t\tawait this.ctx.storage.deleteSecret(this.getLocalSecretKey(id, connectionId));\n\t\t\t}\n\n\t\t\tif (cloud == null || cloud === true) {\n\t\t\t\tawait this.ctx.storage.deleteSecret(this.getCloudSecretKey(id, connectionId));\n\t\t\t\tthis.state.cloud.remove(`${id}|connection:${connectionId}`);\n\t\t\t}\n\n\t\t\tif (options?.preserveConfigured) return;\n\n\t\t\tawait this.removeConfigured(id, { connectionId: connectionId, cloud: cloud });\n\t\t});\n\t}\n\n\tprivate async deleteAllSecrets(id: IntegrationIds, cloud?: boolean, domain?: string): Promise<void> {\n\t\t// Delete every connection's secret (multi-account): secrets are keyed per connection id, so a\n\t\t// single canonical-domain delete would orphan secondary tokens. When a domain is given (self-managed\n\t\t// disconnect of one host), scope to that host so other hosts under the same provider id survive.\n\t\tconst descriptors = this.configured.get(id);\n\t\tconst connectionIds = [\n\t\t\t...new Set(\n\t\t\t\t(domain != null ? descriptors?.filter(c => this.domainsMatch(id, c.domain, domain)) : descriptors)?.map(\n\t\t\t\t\tc => c.id,\n\t\t\t\t) ?? [],\n\t\t\t),\n\t\t];\n\t\tif (connectionIds.length) {\n\t\t\tfor (const connectionId of connectionIds) {\n\t\t\t\tawait this.deleteSecrets(id, connectionId, cloud);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\t// A domain-scoped clear that matched nothing means this host has no stored connections, so it must be\n\t\t// a no-op. The canonical-domain fallback below would target a bogus key (self-managed canonical domain\n\t\t// is empty), so skip it.\n\t\tif (domain != null) return;\n\n\t\t// No configured connections (e.g. an orphaned secret with no descriptor): fall back to the\n\t\t// provider's canonical domain, which is the legacy session id for cloud providers. Mirror the\n\t\t// hydration backfill's `|| id` guard so a self-managed provider (empty canonical domain) doesn't\n\t\t// target an ambiguous empty connection id.\n\t\tawait this.deleteSecrets(id, providersMetadata[id]?.domain || id, cloud);\n\t}\n\n\tprivate async writeSecret(\n\t\tid: IntegrationIds,\n\t\tsession: ProviderAuthenticationSession | StoredSession,\n\t\tresource?: ConnectionResource,\n\t\tcloudOrigin?: CloudCredentialOrigin,\n\t): Promise<void> {\n\t\tawait this.ctx.storage.storeSecret(\n\t\t\tthis.getSecretKey(id, session.id, session.cloud ?? false),\n\t\t\tJSON.stringify(cloudOrigin == null ? session : { ...session, cloudOrigin: cloudOrigin }),\n\t\t);\n\n\t\tawait this.addOrUpdateConfigured({\n\t\t\tid: session.id,\n\t\t\tintegrationId: id,\n\t\t\tdomain: isSelfManagedHostIntegrationId(id) ? session.domain : undefined,\n\t\t\tbaseUrl: isSelfManagedHostIntegrationId(id) ? session.baseUrl : undefined,\n\t\t\texpiresAt: session.expiresAt,\n\t\t\tscopes: session.scopes.join(','),\n\t\t\tcloud: session.cloud ?? false,\n\t\t\ttype: session.type,\n\t\t\taccountName: session.account?.label || undefined,\n\t\t\tresourceName: resource?.name,\n\t\t\tresourceId: resource?.id,\n\t\t});\n\t}\n\n\tprivate async readSecret(\n\t\tid: IntegrationIds,\n\t\tsessionId: string,\n\t\tcloud: boolean = false,\n\t): Promise<StoredSession | undefined> {\n\t\tlet storedSession: StoredSession | undefined;\n\t\ttry {\n\t\t\tconst sessionJSON = await this.ctx.storage.getSecret(this.getSecretKey(id, sessionId, cloud));\n\t\t\tif (this._disposed) return undefined;\n\n\t\t\tif (sessionJSON) {\n\t\t\t\tstoredSession = JSON.parse(sessionJSON);\n\t\t\t\tif (storedSession != null) {\n\t\t\t\t\tif (this.isRetiredSecret(storedSession, cloud)) return undefined;\n\n\t\t\t\t\tconst configured = this.configured.get(id);\n\t\t\t\t\tconst connectionId = storedSession.id ?? sessionId;\n\t\t\t\t\tconst sessionCloud = storedSession.cloud ?? cloud;\n\t\t\t\t\tconst domain = isSelfManagedHostIntegrationId(id)\n\t\t\t\t\t\t? (storedSession.domain ?? storedSession.id)\n\t\t\t\t\t\t: undefined;\n\t\t\t\t\tif (\n\t\t\t\t\t\tconfigured == null ||\n\t\t\t\t\t\tconfigured.length === 0 ||\n\t\t\t\t\t\t!configured.some(\n\t\t\t\t\t\t\tc => c.id === connectionId && c.integrationId === id && c.cloud === sessionCloud,\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tawait this.addOrUpdateConfigured({\n\t\t\t\t\t\t\tid: connectionId,\n\t\t\t\t\t\t\tintegrationId: id,\n\t\t\t\t\t\t\tdomain: domain,\n\t\t\t\t\t\t\t// Rebuilt from the secret, so it must carry the address the session does; omitting it\n\t\t\t\t\t\t\t// leaves the descriptor claiming no context path and makes reconcile read every\n\t\t\t\t\t\t\t// routine check-in as a re-pointed connection.\n\t\t\t\t\t\t\tbaseUrl: isSelfManagedHostIntegrationId(id) ? storedSession.baseUrl : undefined,\n\t\t\t\t\t\t\texpiresAt: storedSession.expiresAt,\n\t\t\t\t\t\t\tscopes: storedSession.scopes.join(','),\n\t\t\t\t\t\t\tcloud: sessionCloud,\n\t\t\t\t\t\t\ttype: storedSession.type,\n\t\t\t\t\t\t\taccountName: storedSession.account?.label || undefined,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (_ex) {\n\t\t\tif (this._disposed) return undefined;\n\n\t\t\ttry {\n\t\t\t\tawait this.deleteSecrets(id, sessionId, cloud);\n\t\t\t} catch {}\n\t\t}\n\t\treturn storedSession;\n\t}\n\n\tprivate getSecretKey(\n\t\tid: IntegrationIds,\n\t\tsessionId: string,\n\t\tcloud: boolean = false,\n\t): `integration.auth:${IntegrationIds}|${string}` | `integration.auth.cloud:${IntegrationIds}|${string}` {\n\t\treturn cloud ? this.getCloudSecretKey(id, sessionId) : this.getLocalSecretKey(id, sessionId);\n\t}\n\n\tprivate getLocalSecretKey(id: IntegrationIds, sessionId: string): `integration.auth:${IntegrationIds}|${string}` {\n\t\treturn `integration.auth:${id}|${sessionId}`;\n\t}\n\n\tprivate getCloudSecretKey(\n\t\tid: IntegrationIds,\n\t\tsessionId: string,\n\t): `integration.auth.cloud:${IntegrationIds}|${string}` {\n\t\treturn `integration.auth.cloud:${id}|${sessionId}`;\n\t}\n\n\tprivate getPrimaryScope(\n\t\tid: IntegrationIds,\n\t\tdescriptors: ConfiguredIntegrationDescriptor[],\n\t\tdomain: string | undefined,\n\t): ConfiguredIntegrationDescriptor[] {\n\t\treturn isSelfManagedHostIntegrationId(id)\n\t\t\t? descriptors.filter(d => this.isInPrimaryScope(id, d, domain))\n\t\t\t: descriptors;\n\t}\n\n\tprivate isInPrimaryScope(\n\t\tid: IntegrationIds,\n\t\tdescriptor: ConfiguredIntegrationDescriptor,\n\t\tdomain: string | undefined,\n\t): boolean {\n\t\treturn !isSelfManagedHostIntegrationId(id) || this.domainsMatch(id, descriptor.domain, domain);\n\t}\n\n\t/**\n\t * Resolves the connection id used as the secret-key session id for an auth descriptor.\n\t * - If the descriptor targets a specific connection (`connectionId`), that wins.\n\t * - Otherwise returns the primary connection's id for the provider (matching the descriptor's domain\n\t * for self-managed hosts; any connection for cloud hosts, where the stored domain is undefined).\n\t * - Falls back to the descriptor domain when nothing is configured yet, preserving legacy\n\t * (pre-multi-account) reads with zero secret migration.\n\t */\n\tresolveConnectionId(id: IntegrationIds, descriptor: IntegrationAuthenticationSessionDescriptor): string {\n\t\t// An empty connectionId is not a real target — treat it as \"no target\" so it resolves the primary\n\t\t// rather than keying a secret under an empty id.\n\t\tif (descriptor.connectionId) return descriptor.connectionId;\n\n\t\tconst domain = isSelfManagedHostIntegrationId(id) ? descriptor.domain : undefined;\n\t\tconst candidates = this.scopeConnectionCandidates(id, domain, descriptor.cloud);\n\t\treturn (candidates?.find(c => c.primary) ?? candidates?.[0])?.id ?? descriptor.domain;\n\t}\n\n\t/**\n\t * Returns the id of the configured connection an unscoped descriptor resolves to (the primary for the\n\t * descriptor's domain, matching {@link resolveConnectionId}'s selection), or `undefined` when nothing is\n\t * configured for it. Unlike {@link resolveConnectionId} this only returns a genuine per-connection cloud\n\t * token id (never a local/PAT or domain-derived legacy id), so callers can safely use it to scope a cloud\n\t * token fetch to one host of a multi-host self-managed provider, or fall through to the provider-global\n\t * primary endpoint on `undefined`.\n\t */\n\t/**\n\t * The address already stored for a self-managed connection — see {@link ConfiguredIntegrationDescriptor.baseUrl}.\n\t *\n\t * Exists so a session rebuilt from a backend response that omits the domain can keep the address the\n\t * connection was configured with, rather than silently falling back to the bare host and losing a context\n\t * path the user never changed. Looked up by connection id first, then by host for an unscoped fetch.\n\t */\n\t/**\n\t * Whether `connectionId` names a cloud connection configured for `domain`'s host.\n\t *\n\t * The caller-facing question is \"is this id evidence that a token belongs to this host\". A connection id\n\t * can arrive from a caller rather than from our own configuration, so it is only evidence once it matches\n\t * a descriptor we stored for that host — see the host guard in `CloudIntegrationAuthenticationProvider`.\n\t */\n\tisConnectionConfiguredForHost(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string | undefined,\n\t\tdomain: string | undefined,\n\t): boolean {\n\t\tif (connectionId == null) return false;\n\n\t\tconst connection = this.getConfigured(id, { cloud: true }).find(c => c.id === connectionId);\n\t\tif (connection == null) return false;\n\n\t\treturn !isSelfManagedHostIntegrationId(id) || this.domainsMatch(id, connection.domain, domain);\n\t}\n\n\tgetConfiguredBaseUrl(id: IntegrationIds, connectionId: string | undefined, domain?: string): string | undefined {\n\t\tif (!isSelfManagedHostIntegrationId(id)) return undefined;\n\n\t\tconst configured = this.getConfigured(id, { cloud: true });\n\t\tconst byId = connectionId != null ? configured.find(c => c.id === connectionId) : undefined;\n\t\tif (byId != null) return byId.baseUrl;\n\n\t\treturn configured.find(c => this.domainsMatch(id, c.domain, domain))?.baseUrl;\n\t}\n\n\tgetConfiguredConnectionId(id: IntegrationIds, domain: string | undefined, cloud?: boolean): string | undefined {\n\t\tconst scoped = isSelfManagedHostIntegrationId(id) ? domain : undefined;\n\t\tconst candidates = this.scopeConnectionCandidates(id, scoped, cloud);\n\t\tconst connection = candidates?.find(c => c.primary) ?? candidates?.[0];\n\t\tif (connection == null) return undefined;\n\n\t\t// Only return a real per-connection cloud token id. Reject a local (PAT) descriptor (surfaced by\n\t\t// scopeConnectionCandidates' non-cloud fallback) and a domain-derived legacy id (the descriptor's own\n\t\t// domain or the provider's canonical domain — see ConfiguredIntegrationDescriptor.id), either of which\n\t\t// would target `v1/provider-tokens/tokens/{domain}` (rejected as a non-uuid). Callers then fall through\n\t\t// to the provider-scoped primary endpoint.\n\t\tif (!connection.cloud) return undefined;\n\n\t\tconst canonicalDomain = providersMetadata[id]?.domain;\n\t\tif (connection.id === connection.domain || (canonicalDomain && connection.id === canonicalDomain)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn connection.id;\n\t}\n\n\t/**\n\t * Selects configured descriptors for a provider matching `domain`, further narrowed to the `cloud`\n\t * variant when specified. A connection id can have both a local (PAT) and cloud descriptor whose ids\n\t * differ (e.g. a legacy local descriptor keyed by domain alongside a real cloud token id); scoping by\n\t * `cloud` keeps a cloud-scoped read/delete from resolving the local id (and vice versa). Falls back to\n\t * the domain-only set when no variant matches, so legacy single-variant resolution is unchanged.\n\t */\n\tprivate scopeConnectionCandidates(\n\t\tid: IntegrationIds,\n\t\tdomain: string | undefined,\n\t\tcloud: boolean | undefined,\n\t): ConfiguredIntegrationDescriptor[] | undefined {\n\t\tconst candidates = this.configured.get(id)?.filter(c => this.domainsMatch(id, c.domain, domain));\n\t\tif (cloud == null || candidates == null) return candidates;\n\n\t\tconst scoped = candidates.filter(c => c.cloud === cloud);\n\t\treturn scoped.length ? scoped : candidates;\n\t}\n\n\t/**\n\t * Marks the given connection as the primary/default for the provider and clears the flag on its\n\t * siblings. Persists immediately instead of relying on a session re-store to carry the primary flag.\n\t */\n\tsetPrimaryConnection(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string,\n\t\tlist?: { sync: CloudIntegrationSync; domain?: string },\n\t): Promise<void> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (this._disposed) return;\n\n\t\t\tif (\n\t\t\t\tlist != null &&\n\t\t\t\t(!list.sync.isCurrent() ||\n\t\t\t\t\tthis.state.cloud.supersedingPrimary(id, list.domain, connectionId, list.sync.mark) != null)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tawait this.setPrimaryConnectionCore(id, connectionId);\n\t\t\tif (list != null || this._disposed) return;\n\n\t\t\tconst selected = this.getConfigured(id, { cloud: true }).find(c => c.id === connectionId && c.primary);\n\t\t\tif (selected != null) {\n\t\t\t\tconst mark = ++this.state.epoch;\n\t\t\t\tthis.state.cloud.observe(`${id}|connection:${connectionId}`, mark);\n\t\t\t\tthis.state.cloud.observePrimary(id, selected.domain, connectionId, mark);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate async setPrimaryConnectionCore(id: IntegrationIds, connectionId: string): Promise<void> {\n\t\tconst descriptors = this.configured.get(id);\n\t\tif (descriptors == null || descriptors.length === 0) return;\n\t\tif (!descriptors.some(d => d.id === connectionId)) return;\n\n\t\tconst target =\n\t\t\tdescriptors.find(d => d.id === connectionId && d.cloud) ?? descriptors.find(d => d.id === connectionId);\n\t\tif (target == null) return;\n\n\t\tconst domain = isSelfManagedHostIntegrationId(id) ? target.domain : undefined;\n\t\t// A connection id can have both a local (PAT) and cloud descriptor. Mark the primary on a single\n\t\t// canonical variant (prefer cloud, since multi-account primaries are cloud-driven) within the\n\t\t// provider/host scope, so other self-managed hosts keep their own default connection.\n\t\tconst primaryIsCloud = descriptors.some(\n\t\t\td => d.id === connectionId && d.cloud && this.isInPrimaryScope(id, d, domain),\n\t\t);\n\n\t\tlet changed = false;\n\t\tconst updated = descriptors.map(d => {\n\t\t\tif (!this.isInPrimaryScope(id, d, domain)) return d;\n\n\t\t\tconst primary = d.id === connectionId && (d.cloud ?? false) === primaryIsCloud;\n\t\t\tif ((d.primary ?? false) === primary) return d;\n\n\t\t\tchanged = true;\n\t\t\treturn { ...d, primary: primary };\n\t\t});\n\t\tif (!changed) return;\n\n\t\tawait this.storeConfigured(id, updated);\n\t\tthis.fireChange(id);\n\t}\n\n\t/**\n\t * Removes a single connection (its secret + configured descriptor). If it was the primary and other\n\t * connections remain, a secondary is promoted (see {@link removeConfigured}). Unlike\n\t * {@link deleteAllStoredSessions}, this only affects the targeted connection. Pass `cloud` to scope\n\t * the removal to the cloud/local variant when a local PAT and a cloud session share a connection id.\n\t */\n\tdeleteConnection(id: IntegrationIds, connectionId: string, cloud?: boolean): Promise<void> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (this._disposed) return;\n\n\t\t\tawait this.deleteSecrets(id, connectionId, cloud, {\n\t\t\t\tonRemoving: () =>\n\t\t\t\t\tthis._onWillRemoveSessions.fire({ integrationId: id, connectionId: connectionId, cloud: cloud }),\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate _addedIds = new Set<IntegrationIds>();\n\tprivate _removedIds = new Set<IntegrationIds>();\n\tprivate _fireChangeDebounced?: () => void;\n\n\tprivate normalizeConfiguredDomain(id: IntegrationIds, domain: string | undefined): string | undefined {\n\t\tif (!isSelfManagedHostIntegrationId(id)) return domain;\n\n\t\treturn hostFromDomain(domain) ?? domain;\n\t}\n\n\tprivate domainsMatch(id: IntegrationIds, first: string | undefined, second: string | undefined): boolean {\n\t\tif (first === second) return true;\n\t\tif (!isSelfManagedHostIntegrationId(id)) return false;\n\t\tif (first == null || second == null) return false;\n\n\t\treturn areDomainsOnSameHost(first, second);\n\t}\n\n\tprivate fireChange(added?: IntegrationIds, removed?: IntegrationIds) {\n\t\tthis._fireChangeDebounced ??= debounce(() => {\n\t\t\tconst added = [...this._addedIds];\n\t\t\tthis._addedIds.clear();\n\t\t\tconst removed = [...this._removedIds];\n\t\t\tthis._removedIds.clear();\n\n\t\t\tthis._onDidChange.fire({ added: added, removed: removed });\n\t\t}, 250);\n\n\t\tif (added != null) {\n\t\t\tthis._addedIds.add(added);\n\t\t}\n\t\tif (removed != null) {\n\t\t\tthis._removedIds.add(removed);\n\t\t}\n\t\tthis._fireChangeDebounced();\n\t}\n}\n\nfunction isLegacyCloudSecret(raw: string): boolean {\n\ttry {\n\t\tconst session = JSON.parse(raw) as StoredSession;\n\t\treturn session?.cloud === true || (session?.cloud !== false && session?.expiresAt != null);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction convertStoredSessionToSession(\n\tstoredSession: StoredSession | undefined,\n\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\tcloudIfMissing: boolean,\n): ProviderAuthenticationSession | undefined {\n\tif (storedSession == null) return undefined;\n\n\treturn {\n\t\tid: storedSession.id,\n\t\taccessToken: storedSession.accessToken,\n\t\taccount: {\n\t\t\tid: storedSession.account?.id ?? '',\n\t\t\tlabel: storedSession.account?.label ?? '',\n\t\t},\n\t\tscopes: storedSession.scopes,\n\t\tcloud: storedSession.cloud ?? cloudIfMissing,\n\t\texpiresAt: storedSession.expiresAt ? new Date(storedSession.expiresAt) : undefined,\n\t\tdomain: storedSession.domain ?? descriptor.domain,\n\t\tbaseUrl: getStoredBaseUrl(storedSession.baseUrl, storedSession.domain, storedSession.protocol),\n\t\tprotocol: storedSession.protocol,\n\t\ttype: storedSession.type,\n\t\t// Carried for providers whose client needs an app key alongside the token (e.g. Trello); without\n\t\t// this a rehydrated session silently loses the key and every read no-ops.\n\t\tappKey: storedSession.appKey,\n\t};\n}\n\nfunction getStoredBaseUrl(\n\tbaseUrl: string | undefined,\n\tdomain: string | undefined,\n\tprotocol?: string,\n): string | undefined {\n\tif (baseUrl != null) return baseUrl;\n\n\tconst legacyUrl = baseUrlFromDomain(domain, protocol);\n\treturn legacyUrl != null && new URL(legacyUrl).pathname !== '/' ? legacyUrl : undefined;\n}\n"],"mappings":";;;;;;;;;;AAqCA,MAAM,iBAAiB;AAgDvB,MAAM,yCAAyB,IAAI,QAAsE;AAEzG,IAAa,+BAAb,MAAgE;CAyBlC;CAxB7B,eAAgC,IAAI,QAA2C;CAC/E,uBAAwC,IAAI,QAAuC;CACnF,wBAAyC,IAAI,QAK1C;CACH,gCAAiC,IAAI,IAA4C;CACjF;CACA,YAAoB;CACpB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,KAAK,cAAc,SAAS,IAAI,KAAA;EACzE,QAAQ,cAAc,UAAU,WAAW;EAC3C,SAAS,iBAAiB,cAAc,SAAS,cAAc,QAAQ,cAAc,QAAQ;EAC7F,UAAU,cAAc;EACxB,MAAM,cAAc;EAGpB,QAAQ,cAAc;CACvB;AACD;AAEA,SAAS,iBACR,SACA,QACA,UACqB;CACrB,IAAI,WAAW,MAAM,OAAO;CAE5B,MAAM,YAAY,kBAAkB,QAAQ,QAAQ;CACpD,OAAO,aAAa,QAAQ,IAAI,IAAI,SAAS,CAAC,CAAC,aAAa,MAAM,YAAY,KAAA;AAC/E"}
1
+ {"version":3,"file":"configuredIntegrationService.js","names":[],"sources":["../../../../../plus/integrations/src/authentication/configuredIntegrationService.ts"],"sourcesContent":["import { debounce } from '@gitlens/utils/debounce.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 { flatten } from '@gitlens/utils/iterable.js';\nimport type {\n\tIntegrationIds,\n\tStoredConfiguredIntegrationDescriptor,\n\tStoredIntegrationConfigurations,\n} from '../constants.js';\nimport { GitSelfManagedHostIntegrationId } from '../constants.js';\nimport type { IntegrationServiceContext } from '../context.js';\nimport { providersMetadata } from '../providers/metadata.js';\nimport {\n\tareDomainsOnSameHost,\n\tbaseUrlFromDomain,\n\thostFromDomain,\n\tsameConfiguredBaseUrl,\n} from '../utils/domain.utils.js';\nimport { isSelfManagedHostIntegrationId } from '../utils/integration.utils.js';\nimport type { CloudCredentialOrigin, CloudIntegrationSync } from './cloudIntegrationObservations.js';\nimport { CloudIntegrationObservations } from './cloudIntegrationObservations.js';\nimport type { IntegrationAuthenticationSessionDescriptor } from './integrationAuthenticationProvider.js';\nimport type {\n\tCloudIntegrationAuthType,\n\tCloudIntegrationConnection,\n\tConfiguredIntegrationDescriptor,\n\tConnectionResource,\n\tProviderAuthenticationSession,\n} from './models.js';\nimport {\n\tgetSessionIdentity,\n\tgetSupportedCloudIntegrationIds,\n\tisSameAuthenticationSession,\n\tsessionExpiry,\n} from './models.js';\n\nconst cloudLogoutKey = 'integrations:cloudLogout';\n\ninterface StoredSession {\n\tcloudOrigin?: CloudCredentialOrigin;\n\tid: string;\n\taccessToken: string;\n\taccount?: { label?: string; displayName?: string; id: string };\n\tscopes: string[];\n\tcloud?: boolean;\n\ttype: CloudIntegrationAuthType | undefined;\n\texpiresAt?: string;\n\tdomain?: string;\n\t/** See {@link ProviderAuthenticationSession.baseUrl}: the configured address, path included. */\n\tbaseUrl?: string;\n\tprotocol?: string;\n\t/** The provider app key paired with the token for providers whose client needs one (e.g. Trello). */\n\tappKey?: string;\n}\n\nexport interface ConfiguredIntegrationsChangeEvent {\n\treadonly added: readonly IntegrationIds[];\n\treadonly removed: readonly IntegrationIds[];\n}\n\ntype IntegrationSessionChangeEvent = {\n\treadonly integrationId: IntegrationIds;\n\treadonly session: ProviderAuthenticationSession;\n\treadonly previousDomain?: string;\n};\n\ntype CredentialAcquisitions = { unscoped?: Promise<void>; connections: Map<string, Promise<void>> };\n\ntype CloudLogoutConnection = ConfiguredIntegrationDescriptor & { retained: boolean };\n\ntype ConfiguredStorageState = {\n\tconfigured?: Map<IntegrationIds, ConfiguredIntegrationDescriptor[]>;\n\tpersistence: Promise<void>;\n\tlocks: Map<IntegrationIds, Promise<void>>;\n\tepoch: number;\n\tscopes: Map<string, number>;\n\tsignOuts: Map<string, number>;\n\tpublications: Map<string, number>;\n\tremovals: Map<string, number>;\n\tcloud: CloudIntegrationObservations;\n\tonCloudLogout: Emitter<readonly CloudLogoutConnection[]>;\n\t// KEEP: A partial secret/descriptor write blocks this variant until both are stored successfully.\n\texpiries: Map<string, number | null>;\n};\nconst configuredStorageState = new WeakMap<IntegrationServiceContext['storage'], ConfiguredStorageState>();\n\nexport class ConfiguredIntegrationService implements Disposable {\n\tprivate readonly _onDidChange = new Emitter<ConfiguredIntegrationsChangeEvent>();\n\tprivate readonly _onWillChangeSession = new Emitter<IntegrationSessionChangeEvent>();\n\tprivate readonly _onWillRemoveSessions = new Emitter<{\n\t\tintegrationId: IntegrationIds;\n\t\tconnectionId?: string;\n\t\tcloud?: boolean;\n\t\tdomain?: string;\n\t}>();\n\tprivate readonly _acquisitions = new Map<IntegrationIds, CredentialAcquisitions>();\n\tprivate readonly state: ConfiguredStorageState;\n\tprivate _disposed = false;\n\tget onDidChange(): Event<ConfiguredIntegrationsChangeEvent> {\n\t\treturn this._onDidChange.event;\n\t}\n\tget onCloudLogout(): Event<readonly CloudLogoutConnection[]> {\n\t\treturn this.state.onCloudLogout.event;\n\t}\n\tget onWillChangeSession(): Event<IntegrationSessionChangeEvent> {\n\t\treturn this._onWillChangeSession.event;\n\t}\n\tget onWillRemoveSessions(): typeof this._onWillRemoveSessions.event {\n\t\treturn this._onWillRemoveSessions.event;\n\t}\n\n\tconstructor(private readonly ctx: IntegrationServiceContext) {\n\t\tlet state = configuredStorageState.get(ctx.storage);\n\t\tif (state == null) {\n\t\t\tstate = {\n\t\t\t\tpersistence: Promise.resolve(),\n\t\t\t\tlocks: new Map(),\n\t\t\t\tepoch: 0,\n\t\t\t\tscopes: new Map(),\n\t\t\t\tsignOuts: new Map(),\n\t\t\t\tpublications: new Map(),\n\t\t\t\tremovals: new Map(),\n\t\t\t\tcloud: new CloudIntegrationObservations(ctx.storage.get(cloudLogoutKey)),\n\t\t\t\tonCloudLogout: new Emitter<readonly CloudLogoutConnection[]>(),\n\t\t\t\texpiries: new Map(),\n\t\t\t};\n\t\t\tconfiguredStorageState.set(ctx.storage, state);\n\t\t}\n\t\tthis.state = state;\n\t}\n\n\tdispose(): void {\n\t\tthis._disposed = true;\n\t\tthis._onDidChange.dispose();\n\t\tthis._onWillChangeSession.dispose();\n\t\tthis._onWillRemoveSessions.dispose();\n\t}\n\n\tprivate get configured(): Map<IntegrationIds, ConfiguredIntegrationDescriptor[]> {\n\t\tif (this.state.configured == null) {\n\t\t\tthis.state.configured = new Map<IntegrationIds, ConfiguredIntegrationDescriptor[]>();\n\n\t\t\tconst storedConfigured = this.ctx.storage.get('integrations:configured');\n\t\t\tfor (const [id, configured] of Object.entries(storedConfigured ?? {}) as [\n\t\t\t\tIntegrationIds,\n\t\t\t\tStoredConfiguredIntegrationDescriptor[],\n\t\t\t][]) {\n\t\t\t\tif (configured == null) continue;\n\n\t\t\t\tconst descriptors = configured.map(d => ({\n\t\t\t\t\t...d,\n\t\t\t\t\tbaseUrl: isSelfManagedHostIntegrationId(id) ? getStoredBaseUrl(d.baseUrl, d.domain) : d.baseUrl,\n\t\t\t\t\tdomain: this.normalizeConfiguredDomain(id, d.domain),\n\t\t\t\t\tid: d.id || d.domain || providersMetadata[id]?.domain || id,\n\t\t\t\t\texpiresAt: d.expiresAt ? new Date(d.expiresAt) : undefined,\n\t\t\t\t}));\n\t\t\t\tthis.state.configured.set(id, descriptors);\n\t\t\t}\n\t\t}\n\n\t\treturn this.state.configured;\n\t}\n\n\tgetConfigured(\n\t\tid?: IntegrationIds,\n\t\toptions?: { cloud?: boolean; domain?: string },\n\t): ConfiguredIntegrationDescriptor[] {\n\t\tconst descriptors: ConfiguredIntegrationDescriptor[] = [];\n\n\t\tconst configured =\n\t\t\tid != null\n\t\t\t\t? this.configured.get(id)\n\t\t\t\t: [...flatten<ConfiguredIntegrationDescriptor>(this.configured.values())];\n\t\tif (!configured?.length) return descriptors;\n\n\t\tif (options?.domain != null || options?.cloud != null) {\n\t\t\tfor (const descriptor of configured) {\n\t\t\t\tif (\n\t\t\t\t\t(options?.domain != null &&\n\t\t\t\t\t\t!this.domainsMatch(id ?? descriptor.integrationId, descriptor.domain, options.domain)) ||\n\t\t\t\t\t(options?.cloud === true && !descriptor.cloud) ||\n\t\t\t\t\t(options?.cloud === false && descriptor.cloud)\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tdescriptors.push(descriptor);\n\t\t\t}\n\t\t} else {\n\t\t\tdescriptors.push(...configured);\n\t\t}\n\n\t\treturn descriptors;\n\t}\n\n\tprivate storeConfigured(id: IntegrationIds, descriptors?: ConfiguredIntegrationDescriptor[]): Promise<void> {\n\t\tconst pending = this.state.persistence.then(async () => {\n\t\t\tconst updated = new Map(this.configured);\n\t\t\tif (descriptors == null) {\n\t\t\t\tupdated.delete(id);\n\t\t\t} else {\n\t\t\t\tupdated.set(id, descriptors);\n\t\t\t}\n\n\t\t\tconst record: Partial<StoredIntegrationConfigurations> = {};\n\t\t\tfor (const [providerId, connections] of updated) {\n\t\t\t\trecord[providerId] = connections.map(connection => ({\n\t\t\t\t\t...connection,\n\t\t\t\t\texpiresAt:\n\t\t\t\t\t\tconnection.expiresAt instanceof Date\n\t\t\t\t\t\t\t? connection.expiresAt.toISOString()\n\t\t\t\t\t\t\t: connection.expiresAt,\n\t\t\t\t}));\n\t\t\t}\n\t\t\tawait this.ctx.storage.store('integrations:configured', record);\n\t\t\tthis.state.configured = updated;\n\t\t});\n\t\tthis.state.persistence = pending.catch(() => {});\n\t\treturn pending;\n\t}\n\n\tprivate async addOrUpdateConfigured(descriptor: ConfiguredIntegrationDescriptor): Promise<void> {\n\t\tdescriptor = {\n\t\t\t...descriptor,\n\t\t\tbaseUrl: isSelfManagedHostIntegrationId(descriptor.integrationId)\n\t\t\t\t? getStoredBaseUrl(descriptor.baseUrl, descriptor.domain)\n\t\t\t\t: descriptor.baseUrl,\n\t\t\tdomain: this.normalizeConfiguredDomain(descriptor.integrationId, descriptor.domain),\n\t\t};\n\t\tconst descriptors = [...(this.configured.get(descriptor.integrationId) ?? [])];\n\t\tconst existing = descriptors.find(d => d.id === descriptor.id && d.cloud === descriptor.cloud);\n\n\t\t// The first connection for a provider/domain is primary by default; an explicit flag (or the\n\t\t// existing value) always wins. Self-managed providers can span multiple hosts under the same\n\t\t// integration id, so each host needs its own primary.\n\t\tconst primaryScope = this.getPrimaryScope(descriptor.integrationId, descriptors, descriptor.domain);\n\t\tconst primary = descriptor.primary ?? existing?.primary ?? !primaryScope.some(d => d.primary);\n\t\t// Preserve a previously-resolved type/accountName when the incoming write doesn't carry them (e.g.\n\t\t// the model re-stores the primary session with an empty account, after reconcile enriched it).\n\t\tconst type = descriptor.type ?? existing?.type;\n\t\tconst accountName = descriptor.accountName ?? existing?.accountName;\n\t\t// A write without a workspace (a failed lookup, or a session re-store) keeps the stored pair whole.\n\t\tconst resource = descriptor.resourceId != null ? descriptor : existing;\n\t\tconst normalized: ConfiguredIntegrationDescriptor = {\n\t\t\t...descriptor,\n\t\t\tprimary: primary,\n\t\t\ttype: type,\n\t\t\taccountName: accountName,\n\t\t\tresourceName: resource?.resourceName,\n\t\t\tresourceId: resource?.resourceId,\n\t\t};\n\n\t\tlet changed: boolean;\n\t\tif (existing != null) {\n\t\t\t// `baseUrl` is compared alongside `domain`, not folded into it: `domain` is normalized to a bare\n\t\t\t// host, so a connection re-pointed to another context path on the SAME host is identical by domain\n\t\t\t// and would otherwise be treated as unchanged — leaving the stored descriptor, and every warm\n\t\t\t// integration listening for the change, on the old address.\n\t\t\tif (\n\t\t\t\texisting.domain === normalized.domain &&\n\t\t\t\tsameConfiguredBaseUrl(existing.baseUrl, normalized.baseUrl) &&\n\t\t\t\texisting.expiresAt === normalized.expiresAt &&\n\t\t\t\texisting.scopes === normalized.scopes &&\n\t\t\t\t(existing.primary ?? false) === (normalized.primary ?? false) &&\n\t\t\t\texisting.type === normalized.type &&\n\t\t\t\texisting.accountName === normalized.accountName &&\n\t\t\t\texisting.resourceName === normalized.resourceName &&\n\t\t\t\texisting.resourceId === normalized.resourceId\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Only fire the change event on address/scopes/primary/type/accountName changes (ignore expiresAt churn)\n\t\t\tchanged =\n\t\t\t\texisting.domain !== normalized.domain ||\n\t\t\t\t!sameConfiguredBaseUrl(existing.baseUrl, normalized.baseUrl) ||\n\t\t\t\texisting.scopes !== normalized.scopes ||\n\t\t\t\t(existing.primary ?? false) !== (normalized.primary ?? false) ||\n\t\t\t\texisting.type !== normalized.type ||\n\t\t\t\texisting.accountName !== normalized.accountName ||\n\t\t\t\texisting.resourceName !== normalized.resourceName ||\n\t\t\t\texisting.resourceId !== normalized.resourceId;\n\n\t\t\tdescriptors.splice(descriptors.indexOf(existing), 1);\n\t\t} else {\n\t\t\tchanged = true;\n\t\t}\n\n\t\tdescriptors.push(normalized);\n\t\tawait this.storeConfigured(descriptor.integrationId, descriptors);\n\n\t\tif (changed) {\n\t\t\tthis.fireChange(descriptor.integrationId);\n\t\t}\n\t}\n\n\tprivate async removeConfigured(\n\t\tid: IntegrationIds,\n\t\toptions: { connectionId: string; cloud: boolean | undefined },\n\t): Promise<void> {\n\t\tconst existing = this.configured.get(id);\n\t\tif (existing == null || existing.length === 0) return;\n\n\t\tconst removedPrimaryDomains = new Set<string | undefined>();\n\t\tconst descriptors: ConfiguredIntegrationDescriptor[] = [];\n\t\tfor (const d of existing) {\n\t\t\tif (\n\t\t\t\td.id === options.connectionId &&\n\t\t\t\t(options?.cloud == null ||\n\t\t\t\t\t(options?.cloud === true && d.cloud === true) ||\n\t\t\t\t\t(options?.cloud === false && d.cloud === false))\n\t\t\t) {\n\t\t\t\tif (d.primary) {\n\t\t\t\t\tremovedPrimaryDomains.add(d.domain);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tdescriptors.push(d);\n\t\t}\n\n\t\tif (descriptors.length === existing.length) return; // nothing matched\n\n\t\t// Promote a secondary to primary when the removed connection was the primary and others remain\n\t\t// in the same primary scope, so the provider/host stays in a well-defined connected state.\n\t\tfor (const domain of removedPrimaryDomains) {\n\t\t\tif (descriptors.some(d => this.isInPrimaryScope(id, d, domain) && d.primary)) continue;\n\n\t\t\tconst index = descriptors.findIndex(d => this.isInPrimaryScope(id, d, domain));\n\t\t\tif (index !== -1) {\n\t\t\t\tdescriptors[index] = { ...descriptors[index], primary: true };\n\t\t\t}\n\t\t}\n\n\t\tawait this.storeConfigured(id, descriptors);\n\t\tthis.fireChange(undefined, id);\n\t}\n\n\tprivate withLock<T>(id: IntegrationIds, fn: () => Promise<T> | T): Promise<T> {\n\t\tconst locks = this.state.locks;\n\t\tconst run = (locks.get(id) ?? Promise.resolve()).then(fn);\n\t\tconst settled = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\tlocks.set(id, settled);\n\t\tvoid settled.then(() => {\n\t\t\tif (locks.get(id) === settled) {\n\t\t\t\tlocks.delete(id);\n\t\t\t}\n\t\t});\n\t\treturn run;\n\t}\n\n\tserializesCredentialAcquisition(id: IntegrationIds): boolean {\n\t\treturn id === GitSelfManagedHostIntegrationId.AzureDevOpsServer;\n\t}\n\n\t/**\n\t * KEEP: not reentrant. A `connectionId` acquisition waits for that connection's and every earlier unscoped one;\n\t * an unscoped acquisition waits for every earlier acquisition of `id`.\n\t */\n\twithCredentialAcquisition<T>(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string | undefined,\n\t\tfn: () => Promise<T>,\n\t): Promise<T> {\n\t\tif (!this.serializesCredentialAcquisition(id)) return fn();\n\n\t\tlet queue = this._acquisitions.get(id);\n\t\tif (queue == null) {\n\t\t\tqueue = { connections: new Map() };\n\t\t\tthis._acquisitions.set(id, queue);\n\t\t}\n\n\t\tconst predecessors = (\n\t\t\tconnectionId != null\n\t\t\t\t? [queue.unscoped, queue.connections.get(connectionId)]\n\t\t\t\t: [queue.unscoped, ...queue.connections.values()]\n\t\t).filter(p => p != null);\n\t\tconst run = Promise.all(predecessors).then(() => fn());\n\t\tconst settled = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\tif (connectionId != null) {\n\t\t\tqueue.connections.set(connectionId, settled);\n\t\t} else {\n\t\t\tqueue.unscoped = settled;\n\t\t\tqueue.connections.clear();\n\t\t}\n\n\t\tconst current = queue;\n\t\tvoid settled.then(() => {\n\t\t\tif (connectionId != null) {\n\t\t\t\tif (current.connections.get(connectionId) === settled) {\n\t\t\t\t\tcurrent.connections.delete(connectionId);\n\t\t\t\t}\n\t\t\t} else if (current.unscoped === settled) {\n\t\t\t\tcurrent.unscoped = undefined;\n\t\t\t}\n\n\t\t\tif (current.unscoped == null && current.connections.size === 0 && this._acquisitions.get(id) === current) {\n\t\t\t\tthis._acquisitions.delete(id);\n\t\t\t}\n\t\t});\n\t\treturn run;\n\t}\n\n\t/**\n\t * Taken before a token is read or fetched and handed to {@link storeSession}. A later sign-out or a recovery\n\t * that replaces the credential invalidates the pending store.\n\t */\n\tgetSignOutMark(): number {\n\t\treturn ++this.state.epoch;\n\t}\n\n\tprivate retirePendingStores(scope: string, cloud?: boolean): void {\n\t\tthis.retireStoredWrites(scope, cloud);\n\t\tthis.state.signOuts.set(cloud == null ? scope : `${scope}|${cloud}`, this.getStoredWriteMark());\n\t}\n\n\tbeginCloudSync(): number {\n\t\treturn ++this.state.epoch;\n\t}\n\n\tget lastCloudLogout(): number {\n\t\treturn this.state.cloud.lastLogout;\n\t}\n\n\tget hasCloudLogout(): boolean {\n\t\treturn this.state.cloud.hasLogout;\n\t}\n\n\tasync retireCloudAccount(mark: number): Promise<CloudIntegrationSync | undefined> {\n\t\tif (this._disposed) return undefined;\n\n\t\tconst connections = this.getConfigured(undefined, { cloud: true });\n\t\tconst sync = this.state.cloud.acceptLogout(mark, ++this.state.epoch, connections);\n\t\tif (sync == null) return undefined;\n\n\t\tconst persist = this.persistCloudLogout();\n\n\t\tconst departing = connections.map(c => ({\n\t\t\t...c,\n\t\t\tretained: this.state.cloud.acquiredAfter(`${c.integrationId}|connection:${c.id}`, mark),\n\t\t}));\n\t\t// KEEP: Reserve all provider locks before notifying observers that can start publishing the next account.\n\t\tconst cleanup = getSupportedCloudIntegrationIds().map(id =>\n\t\t\tthis.withLock(id, () => this.clearDepartedCloudCredentials(id, mark, sync.mark)),\n\t\t);\n\t\tthis.state.onCloudLogout.fire(departing);\n\t\tconst results = await Promise.allSettled([persist, ...cleanup]);\n\t\tconst failure = results.find(result => result.status === 'rejected');\n\t\tif (failure != null) throw failure.reason;\n\t\treturn this._disposed ? undefined : sync;\n\t}\n\n\tprivate persistCloudLogout(): Promise<void> {\n\t\tconst pending = this.state.persistence.then(() =>\n\t\t\tthis.ctx.storage.store(cloudLogoutKey, this.state.cloud.snapshotLogout()),\n\t\t);\n\t\tthis.state.persistence = pending.catch(() => {});\n\t\treturn pending;\n\t}\n\n\tprivate async clearDepartedCloudCredentials(id: IntegrationIds, cutoff: number, logout: number): Promise<void> {\n\t\tconst connections = this.getConfigured(id);\n\t\tconst ids = new Set(connections.map(c => c.id));\n\t\tids.add(providersMetadata[id]?.domain || id);\n\t\tconst failures: unknown[] = [];\n\t\tfor (const connectionId of ids) {\n\t\t\ttry {\n\t\t\t\tconst localKey = this.getLocalSecretKey(id, connectionId);\n\t\t\t\tconst raw = await this.ctx.storage.getSecret(localKey);\n\t\t\t\tif (raw != null && isLegacyCloudSecret(raw)) {\n\t\t\t\t\tawait this.ctx.storage.deleteSecret(localKey);\n\t\t\t\t\tawait this.removeConfigured(id, { connectionId: connectionId, cloud: false });\n\t\t\t\t}\n\t\t\t\tconst scope = `${id}|connection:${connectionId}`;\n\t\t\t\tif (this.state.cloud.acquiredAfter(scope, cutoff)) continue;\n\n\t\t\t\tconst departed = connections.find(c => c.id === connectionId && c.cloud);\n\t\t\t\tif (departed != null && this.state.cloud.depart(id, departed.domain, connectionId, logout)) {\n\t\t\t\t\tawait this.persistCloudLogout();\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tawait this.ctx.storage.deleteSecret(this.getCloudSecretKey(id, connectionId));\n\t\t\t\t} finally {\n\t\t\t\t\tthis.state.cloud.remove(scope);\n\t\t\t\t\tawait this.removeConfigured(id, { connectionId: connectionId, cloud: true });\n\t\t\t\t}\n\t\t\t} catch (ex) {\n\t\t\t\tfailures.push(ex);\n\t\t\t}\n\t\t}\n\t\tif (failures.length) throw new AggregateError(failures, 'Unable to clear retired cloud credentials.');\n\t}\n\n\tgetCloudDeparture(id: IntegrationIds, session: ProviderAuthenticationSession): number | undefined {\n\t\treturn session.cloud ? this.state.cloud.departedAt(id, session.domain, session.id) : undefined;\n\t}\n\n\tconfirmHostCloudSession(\n\t\tid: IntegrationIds,\n\t\tsession: ProviderAuthenticationSession,\n\t\tlogout: number,\n\t): Promise<boolean> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (this._disposed) return false;\n\n\t\t\tconst departure = this.getCloudDeparture(id, session);\n\t\t\tif (departure != null && logout < departure) return false;\n\n\t\t\tconst stored = await this.peekSecret(id, session.id, true, session.domain);\n\t\t\tif (this._disposed || logout !== this.lastCloudLogout || stored === null) return false;\n\t\t\tif (stored === undefined) {\n\t\t\t\treturn (\n\t\t\t\t\tdeparture == null &&\n\t\t\t\t\t!this.getConfigured(id, {\n\t\t\t\t\t\tcloud: true,\n\t\t\t\t\t\tdomain: isSelfManagedHostIntegrationId(id) ? session.domain : undefined,\n\t\t\t\t\t}).some(c => c.id === session.id)\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn (\n\t\t\t\tstored.id === session.id &&\n\t\t\t\tstored.cloud &&\n\t\t\t\tstored.accessToken === session.accessToken &&\n\t\t\t\t(!stored.account.id || stored.account.id === session.account.id)\n\t\t\t);\n\t\t});\n\t}\n\n\tasync acceptCloudSync(\n\t\tmark: number,\n\t\tconnections: ReadonlyMap<IntegrationIds, readonly CloudIntegrationConnection[]>,\n\t): Promise<CloudIntegrationSync | undefined> {\n\t\tif (this._disposed) return undefined;\n\n\t\tconst sync = this.state.cloud.accept(mark, connections);\n\t\tif (sync == null) return undefined;\n\n\t\t// KEEP: A previous sync may already have dispatched a storage operation under another provider lock.\n\t\tawait Promise.all(this.state.locks.values());\n\t\treturn !this._disposed && sync.isCurrent() ? sync : undefined;\n\t}\n\n\tsupersedingPrimary(id: IntegrationIds, session: ProviderAuthenticationSession, mark: number): string | undefined {\n\t\treturn this.state.cloud.supersedingPrimary(id, session.domain, session.id, mark);\n\t}\n\n\thasNewCloudConnection(id: IntegrationIds, domain: string | undefined, mark: number): boolean {\n\t\tconst scopedDomain = isSelfManagedHostIntegrationId(id) ? domain : undefined;\n\t\treturn this.getConfigured(id, { cloud: true, domain: scopedDomain }).some(c =>\n\t\t\tthis.state.cloud.observedSince(`${id}|connection:${c.id}`, mark),\n\t\t);\n\t}\n\n\tasync dispatchHostListRetirement(\n\t\tid: IntegrationIds,\n\t\tdomain: string,\n\t\tsync: CloudIntegrationSync,\n\t\tretire: () => Promise<void>,\n\t): Promise<boolean> {\n\t\tconst dispatched = await this.withLock(id, () => {\n\t\t\tif (this._disposed || !sync.isCurrent() || this.hasNewCloudConnection(id, domain, sync.mark)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// KEEP: The host can re-enter storage after dispatch, so it must settle outside the provider lock.\n\t\t\treturn { settled: retire() };\n\t\t});\n\t\tif (dispatched == null) return false;\n\n\t\tawait dispatched.settled;\n\t\treturn !this._disposed && sync.isCurrent() && !this.hasNewCloudConnection(id, domain, sync.mark);\n\t}\n\n\tgetStoredWriteMark(): number {\n\t\treturn this.state.epoch;\n\t}\n\n\tisStoredWriteRetiredSince(\n\t\tid: IntegrationIds,\n\t\tsession: Pick<ProviderAuthenticationSession, 'id' | 'domain' | 'cloud'>,\n\t\tmark: number,\n\t): boolean {\n\t\treturn (\n\t\t\tthis._disposed ||\n\t\t\t(session.cloud && this.state.cloud.loggedOutSince(mark)) ||\n\t\t\tthis.hasRetirement(this.state.scopes, id, session, mark)\n\t\t);\n\t}\n\n\tasync captureConfiguredConnection(id: IntegrationIds, connectionId: string): Promise<(() => boolean) | undefined> {\n\t\treturn (await this.captureConnectionSelection(id, connectionId))?.isCurrent;\n\t}\n\n\tasync captureConnectionSelection(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string,\n\t): Promise<{ connection: ConfiguredIntegrationDescriptor; isCurrent: () => boolean } | undefined> {\n\t\tconst matches = this.getConfigured(id).filter(connection => connection.id === connectionId);\n\t\tconst selected = matches.find(connection => connection.cloud) ?? matches[0];\n\t\tif (selected == null) return undefined;\n\n\t\tconst mark = this.state.epoch;\n\t\tconst scope = { id: connectionId, domain: selected.domain ?? '', cloud: selected.cloud };\n\t\tconst current = () =>\n\t\t\t!this._disposed &&\n\t\t\t!(selected.cloud && this.state.cloud.loggedOutSince(mark)) &&\n\t\t\t!this.hasRetirement(this.state.removals, id, scope, mark) &&\n\t\t\tthis.configured\n\t\t\t\t.get(id)\n\t\t\t\t?.some(\n\t\t\t\t\tconnection =>\n\t\t\t\t\t\tconnection.id === connectionId &&\n\t\t\t\t\t\tconnection.cloud === selected.cloud &&\n\t\t\t\t\t\tthis.domainsMatch(id, connection.domain, selected.domain) &&\n\t\t\t\t\t\tsameConfiguredBaseUrl(connection.baseUrl, selected.baseUrl),\n\t\t\t\t) === true;\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (\n\t\t\t\tselected.cloud &&\n\t\t\t\tthis.hasCloudLogout &&\n\t\t\t\t(await this.peekSecret(id, connectionId, true, scope.domain)) == null\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn current() ? { connection: selected, isCurrent: current } : undefined;\n\t\t});\n\t}\n\n\tprivate async duringRemoval(scope: string, cloud: boolean | undefined, remove: () => Promise<void>): Promise<void> {\n\t\tconst key = cloud == null ? scope : `${scope}|${cloud}`;\n\t\tthis.retirePendingStores(scope, cloud);\n\t\tthis.state.removals.set(key, Infinity);\n\t\ttry {\n\t\t\tawait remove();\n\t\t} finally {\n\t\t\tconst mark = ++this.state.epoch;\n\t\t\tthis.state.removals.set(key, mark);\n\t\t\tthis.state.signOuts.set(key, mark);\n\t\t}\n\t}\n\n\tcaptureStoredRelationshipCurrency(\n\t\tid: IntegrationIds,\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<(() => boolean) | undefined> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tconst mark = this.getStoredWriteMark();\n\t\t\tconst stored = await this.peekSecret(id, session.id, session.cloud, session.domain);\n\t\t\tif (\n\t\t\t\tthis.isStoredWriteRetiredSince(id, session, mark) ||\n\t\t\t\tstored == null ||\n\t\t\t\t!isSameAuthenticationSession(stored, session)\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst scope = `${id}|connection:${session.id}|${session.cloud}`;\n\t\t\tconst expiries = this.state.expiries;\n\t\t\tif (expiries.get(scope) === null) return undefined;\n\n\t\t\texpiries.set(scope, sessionExpiry(stored.expiresAt));\n\t\t\treturn () => !this.isStoredWriteRetiredSince(id, session, mark) && (expiries.get(scope) ?? 0) > Date.now();\n\t\t});\n\t}\n\n\tprivate retireStoredWrites(scope: string, cloud?: boolean): void {\n\t\tconst retirements = this.state;\n\t\tretirements.scopes.set(cloud == null ? scope : `${scope}|${cloud}`, ++retirements.epoch);\n\t\tfor (const variant of cloud == null ? [true, false] : [cloud]) {\n\t\t\tconst key = `${scope}|${variant}`;\n\t\t\tif (retirements.expiries.get(key) !== null) {\n\t\t\t\tretirements.expiries.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getHostScope(id: IntegrationIds, domain: string): string {\n\t\treturn `${id}|host:${hostFromDomain(domain) ?? domain}`;\n\t}\n\n\tisSessionRetiredSince(\n\t\tid: IntegrationIds,\n\t\tsession: Pick<ProviderAuthenticationSession, 'id' | 'domain'> & { cloud?: boolean },\n\t\tmark: number,\n\t\tacquisitionMark = mark,\n\t): boolean {\n\t\treturn (\n\t\t\t(session.cloud !== false && !this.state.cloud.allows(this.state.cloud.origin(mark))) ||\n\t\t\tthis.hasRetirement(this.state.signOuts, id, session, mark) ||\n\t\t\tthis.hasRetirement(this.state.publications, id, session, acquisitionMark)\n\t\t);\n\t}\n\n\tprivate hasRetirement(\n\t\tscopes: ReadonlyMap<string, number>,\n\t\tid: IntegrationIds,\n\t\tsession: Pick<ProviderAuthenticationSession, 'id' | 'domain'> & { cloud?: boolean },\n\t\tmark: number,\n\t): boolean {\n\t\tconst since = (scope: string) =>\n\t\t\t(scopes.get(scope) ?? 0) > mark ||\n\t\t\t(session.cloud !== false && (scopes.get(`${scope}|true`) ?? 0) > mark) ||\n\t\t\t(session.cloud !== true && (scopes.get(`${scope}|false`) ?? 0) > mark);\n\t\tif (since(id)) return true;\n\t\tif (isSelfManagedHostIntegrationId(id) && session.domain && since(this.getHostScope(id, session.domain))) {\n\t\t\treturn true;\n\t\t}\n\t\treturn since(`${id}|connection:${session.id}`);\n\t}\n\n\t/**\n\t * Stores the session's secret and descriptor together. A pending store can be invalidated by a sign-out or a\n\t * credential recovery. A recovery must still own the stored credential when it publishes its replacement.\n\t */\n\tstoreSession(\n\t\tid: IntegrationIds,\n\t\tsession: ProviderAuthenticationSession,\n\t\toptions?: {\n\t\t\tsignOutMark?: number;\n\t\t\tacquisitionMark?: number;\n\t\t\tresource?: ConnectionResource;\n\t\t\texpectedStoredAccessToken?: string;\n\t\t\tprimaryResponse?: 'named' | 'legacy';\n\t\t\tsync?: CloudIntegrationSync;\n\t\t},\n\t): Promise<boolean> {\n\t\tconst origin = session.cloud\n\t\t\t? this.state.cloud.origin(options?.sync?.mark ?? options?.signOutMark ?? this.getSignOutMark())\n\t\t\t: undefined;\n\t\treturn this.withLock(id, async () => {\n\t\t\tconst canStore = () =>\n\t\t\t\t!this._disposed &&\n\t\t\t\t(origin == null || this.state.cloud.allows(origin)) &&\n\t\t\t\toptions?.sync?.isCurrent() !== false &&\n\t\t\t\t(options?.signOutMark == null ||\n\t\t\t\t\t!this.isSessionRetiredSince(id, session, options.signOutMark, options.acquisitionMark));\n\t\t\tif (!canStore()) return false;\n\n\t\t\tconst scope = `${id}|connection:${session.id}`;\n\t\t\tconst expiryScope = `${scope}|${session.cloud}`;\n\t\t\tconst expiries = this.state.expiries;\n\t\t\tconst previous = await this.peekSecret(id, session.id, session.cloud, session.domain);\n\t\t\tif (\n\t\t\t\t(options?.primaryResponse === 'legacy' &&\n\t\t\t\t\toptions.signOutMark != null &&\n\t\t\t\t\tthis.state.cloud.observedSince(scope, options.signOutMark)) ||\n\t\t\t\t!canStore() ||\n\t\t\t\t(options?.expectedStoredAccessToken != null &&\n\t\t\t\t\tprevious?.accessToken !== options.expectedStoredAccessToken)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst changed = getSessionIdentity(previous) !== getSessionIdentity(session);\n\t\t\tconst replaced = changed || previous?.account?.id !== session.account?.id;\n\t\t\tif (replaced) {\n\t\t\t\tthis.retireStoredWrites(scope, session.cloud);\n\t\t\t}\n\t\t\tif (changed) {\n\t\t\t\tthis._onWillChangeSession.fire({\n\t\t\t\t\tintegrationId: id,\n\t\t\t\t\tsession: session,\n\t\t\t\t\tpreviousDomain: previous?.domain,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!canStore()) return false;\n\n\t\t\tconst trackedExpiry = expiries.get(expiryScope);\n\t\t\tconst nextExpiry = sessionExpiry(session.expiresAt);\n\t\t\tif (typeof trackedExpiry === 'number') {\n\t\t\t\texpiries.set(expiryScope, Math.min(trackedExpiry, nextExpiry));\n\t\t\t}\n\t\t\tconst logoutAtDispatch = this.lastCloudLogout;\n\t\t\ttry {\n\t\t\t\tawait this.writeSecret(id, session, options?.resource, origin);\n\t\t\t} catch (ex) {\n\t\t\t\tif (origin != null && !this.state.cloud.allows(origin)) throw ex;\n\n\t\t\t\tthis.retirePendingStores(scope, session.cloud);\n\t\t\t\tif (session.cloud) {\n\t\t\t\t\tthis.state.cloud.observe(scope, this.state.epoch);\n\t\t\t\t}\n\t\t\t\texpiries.set(expiryScope, null);\n\t\t\t\tthrow ex;\n\t\t\t}\n\t\t\tif (origin != null && !this.state.cloud.allows(origin)) return false;\n\n\t\t\tif (origin != null) {\n\t\t\t\tthis.state.cloud.published(scope, origin.mark);\n\t\t\t}\n\t\t\tif (expiries.has(expiryScope)) {\n\t\t\t\texpiries.set(expiryScope, nextExpiry);\n\t\t\t}\n\t\t\tif (replaced || nextExpiry !== sessionExpiry(previous?.expiresAt)) {\n\t\t\t\t// KEEP: A write already dispatched at logout precedes acquisitions admitted after it.\n\t\t\t\tconst mark =\n\t\t\t\t\tsession.cloud && this.lastCloudLogout !== logoutAtDispatch\n\t\t\t\t\t\t? this.lastCloudLogout\n\t\t\t\t\t\t: ++this.state.epoch;\n\t\t\t\tthis.state.publications.set(expiryScope, mark);\n\t\t\t\tif (\n\t\t\t\t\toptions?.expectedStoredAccessToken != null &&\n\t\t\t\t\tsession.accessToken !== options.expectedStoredAccessToken\n\t\t\t\t) {\n\t\t\t\t\tthis.state.signOuts.set(expiryScope, mark);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (session.cloud && options?.primaryResponse !== 'legacy') {\n\t\t\t\tthis.state.cloud.observe(\n\t\t\t\t\tscope,\n\t\t\t\t\toptions?.sync?.isCurrent() === false ? options.sync.mark : ++this.state.epoch,\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\toptions?.primaryResponse === 'named' &&\n\t\t\t\t\toptions.signOutMark != null &&\n\t\t\t\t\toptions.sync?.isCurrent() !== false &&\n\t\t\t\t\tthis.supersedingPrimary(id, session, options.signOutMark) == null\n\t\t\t\t) {\n\t\t\t\t\tconst primaryMark = ++this.state.epoch;\n\t\t\t\t\tawait this.setPrimaryConnectionCore(id, session.id);\n\t\t\t\t\tthis.state.cloud.observePrimary(id, session.domain, session.id, primaryMark);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\t}\n\n\tpeekStoredSession(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string,\n\t\tcloud: boolean,\n\t\tdomain: string,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (this._disposed) return undefined;\n\n\t\t\tconst session = await this.peekSecret(id, connectionId, cloud, domain);\n\t\t\treturn this._disposed ? undefined : (session ?? undefined);\n\t\t});\n\t}\n\n\tprivate async peekSecret(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string,\n\t\tcloud: boolean,\n\t\tdomain: string,\n\t): Promise<ProviderAuthenticationSession | null | undefined> {\n\t\tconst json = await this.ctx.storage.getSecret(this.getSecretKey(id, connectionId, cloud));\n\t\tif (json == null) return undefined;\n\n\t\ttry {\n\t\t\tconst stored = JSON.parse(json) as StoredSession;\n\t\t\tif (this.isRetiredSecret(stored, cloud)) return null;\n\t\t\treturn convertStoredSessionToSession(\n\t\t\t\tstored,\n\t\t\t\t{ connectionId: connectionId, domain: domain, scopes: [] },\n\t\t\t\tcloud,\n\t\t\t);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tprivate isRetiredSecret(session: StoredSession, cloud: boolean): boolean {\n\t\tif (!cloud && session.cloud !== false && session.expiresAt != null) return this.hasCloudLogout;\n\t\treturn (cloud || session.cloud === true) && !this.state.cloud.allows(session.cloudOrigin);\n\t}\n\n\tgetStoredSession(\n\t\tid: IntegrationIds,\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (this._disposed) return undefined;\n\n\t\t\tconst sessionId = this.resolveConnectionId(id, descriptor);\n\t\t\tlet session = descriptor.cloud === true ? undefined : await this.readSecret(id, sessionId, false);\n\t\t\tif (this._disposed) return undefined;\n\n\t\t\tlet cloudIfMissing = false;\n\t\t\tif (session != null && session.cloud !== false && session.expiresAt != null) {\n\t\t\t\tcloudIfMissing = true;\n\t\t\t\ttry {\n\t\t\t\t\tawait this.deleteSecrets(id, session.id);\n\t\t\t\t\tif (this.hasCloudLogout) return undefined;\n\n\t\t\t\t\tawait this.writeSecret(id, { ...session, cloud: true });\n\t\t\t\t} catch {}\n\t\t\t}\n\n\t\t\tif (session == null && descriptor.cloud !== false) {\n\t\t\t\tcloudIfMissing = true;\n\t\t\t\tsession = await this.readSecret(id, sessionId, true);\n\t\t\t}\n\n\t\t\treturn this._disposed || (session != null && this.isRetiredSecret(session, cloudIfMissing))\n\t\t\t\t? undefined\n\t\t\t\t: convertStoredSessionToSession(session, descriptor, cloudIfMissing);\n\t\t});\n\t}\n\n\t/**\n\t * Deletes one connection's stored session. `signOut` is for a delete that signs the integration out (a forced new\n\t * session): it also refuses the store of any token of the provider, or of the descriptor's self-managed host,\n\t * fetched before it (see {@link getSignOutMark}). A cleanup of a replaced token leaves it unset.\n\t */\n\tdeleteStoredSessions(\n\t\tid: IntegrationIds,\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\tcloud?: boolean,\n\t\toptions?: {\n\t\t\tpreserveConfigured?: boolean;\n\t\t\tsignOut?: boolean;\n\t\t\tsignOutMark?: number;\n\t\t\tunobservedSince?: number;\n\t\t\tsync?: CloudIntegrationSync;\n\t\t},\n\t): Promise<boolean> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (this._disposed || options?.sync?.isCurrent() === false) return false;\n\n\t\t\tconst connectionId = this.resolveConnectionId(id, descriptor);\n\t\t\tif (\n\t\t\t\toptions?.unobservedSince != null &&\n\t\t\t\tthis.state.cloud.observedSince(`${id}|connection:${connectionId}`, options.unobservedSince)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\toptions?.signOutMark != null &&\n\t\t\t\tthis.isSessionRetiredSince(\n\t\t\t\t\tid,\n\t\t\t\t\t{ id: connectionId, domain: descriptor.domain, cloud: cloud },\n\t\t\t\t\toptions.signOutMark,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif (options?.signOut) {\n\t\t\t\tthis.retirePendingStores(\n\t\t\t\t\tisSelfManagedHostIntegrationId(id) && descriptor.domain\n\t\t\t\t\t\t? this.getHostScope(id, descriptor.domain)\n\t\t\t\t\t\t: id,\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait this.deleteSecrets(id, connectionId, cloud, {\n\t\t\t\t...options,\n\t\t\t\tonRemoving: () =>\n\t\t\t\t\tthis._onWillRemoveSessions.fire({\n\t\t\t\t\t\tintegrationId: id,\n\t\t\t\t\t\tconnectionId: connectionId,\n\t\t\t\t\t\tcloud: cloud,\n\t\t\t\t\t\tdomain: descriptor.domain,\n\t\t\t\t\t}),\n\t\t\t});\n\t\t\treturn true;\n\t\t});\n\t}\n\n\t/** Signs out of every stored session of the provider, or of one self-managed host when `domain` is given. */\n\tdeleteAllStoredSessions(\n\t\tid: IntegrationIds,\n\t\tcloud?: boolean,\n\t\tdomain?: string,\n\t\tsync?: CloudIntegrationSync,\n\t): Promise<boolean> {\n\t\tconst scope = isSelfManagedHostIntegrationId(id) && domain != null ? this.getHostScope(id, domain) : id;\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (\n\t\t\t\tthis._disposed ||\n\t\t\t\tsync?.isCurrent() === false ||\n\t\t\t\t(sync && this.hasNewCloudConnection(id, domain, sync.mark))\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tawait this.duringRemoval(scope, cloud, async () => {\n\t\t\t\tthis._onWillRemoveSessions.fire({ integrationId: id, cloud: cloud, domain: domain });\n\t\t\t\tif (this._disposed) return;\n\n\t\t\t\tawait this.deleteAllSecrets(id, cloud, domain);\n\t\t\t});\n\t\t\treturn !this._disposed;\n\t\t});\n\t}\n\n\tasync purgeStoredConfiguration(ids: readonly string[]): Promise<void> {\n\t\tfor (const id of ids as readonly IntegrationIds[]) {\n\t\t\tawait this.withLock(id, async () => {\n\t\t\t\tconst descriptors =\n\t\t\t\t\tthis.ctx.storage.get<StoredIntegrationConfigurations>('integrations:configured')?.[id];\n\t\t\t\tif (descriptors == null) return;\n\n\t\t\t\tawait this.duringRemoval(id, undefined, async () => {\n\t\t\t\t\tfor (const descriptor of descriptors) {\n\t\t\t\t\t\tconst key = descriptor.id || descriptor.domain || providersMetadata[id]?.domain || id;\n\t\t\t\t\t\tawait this.ctx.storage.deleteSecret(this.getLocalSecretKey(id, key));\n\t\t\t\t\t\tawait this.ctx.storage.deleteSecret(this.getCloudSecretKey(id, key));\n\t\t\t\t\t\tif (descriptor.domain) {\n\t\t\t\t\t\t\tawait this.ctx.storage.deleteWorkspace(`connected:${id}:${descriptor.domain}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tawait this.storeConfigured(id);\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async deleteSecrets(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string,\n\t\tcloud?: boolean,\n\t\toptions?: { preserveConfigured?: boolean; onRemoving?: () => void },\n\t): Promise<void> {\n\t\tawait this.duringRemoval(`${id}|connection:${connectionId}`, cloud, async () => {\n\t\t\tif (options?.onRemoving != null) {\n\t\t\t\toptions.onRemoving();\n\t\t\t\tif (this._disposed) return;\n\t\t\t}\n\n\t\t\tif (cloud == null || cloud === false) {\n\t\t\t\tawait this.ctx.storage.deleteSecret(this.getLocalSecretKey(id, connectionId));\n\t\t\t}\n\n\t\t\tif (cloud == null || cloud === true) {\n\t\t\t\tawait this.ctx.storage.deleteSecret(this.getCloudSecretKey(id, connectionId));\n\t\t\t\tthis.state.cloud.remove(`${id}|connection:${connectionId}`);\n\t\t\t}\n\n\t\t\tif (options?.preserveConfigured) return;\n\n\t\t\tawait this.removeConfigured(id, { connectionId: connectionId, cloud: cloud });\n\t\t});\n\t}\n\n\tprivate async deleteAllSecrets(id: IntegrationIds, cloud?: boolean, domain?: string): Promise<void> {\n\t\t// Delete every connection's secret (multi-account): secrets are keyed per connection id, so a\n\t\t// single canonical-domain delete would orphan secondary tokens. When a domain is given (self-managed\n\t\t// disconnect of one host), scope to that host so other hosts under the same provider id survive.\n\t\tconst descriptors = this.configured.get(id);\n\t\tconst connectionIds = [\n\t\t\t...new Set(\n\t\t\t\t(domain != null ? descriptors?.filter(c => this.domainsMatch(id, c.domain, domain)) : descriptors)?.map(\n\t\t\t\t\tc => c.id,\n\t\t\t\t) ?? [],\n\t\t\t),\n\t\t];\n\t\tif (connectionIds.length) {\n\t\t\tfor (const connectionId of connectionIds) {\n\t\t\t\tawait this.deleteSecrets(id, connectionId, cloud);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\t// A domain-scoped clear that matched nothing means this host has no stored connections, so it must be\n\t\t// a no-op. The canonical-domain fallback below would target a bogus key (self-managed canonical domain\n\t\t// is empty), so skip it.\n\t\tif (domain != null) return;\n\n\t\t// No configured connections (e.g. an orphaned secret with no descriptor): fall back to the\n\t\t// provider's canonical domain, which is the legacy session id for cloud providers. Mirror the\n\t\t// hydration backfill's `|| id` guard so a self-managed provider (empty canonical domain) doesn't\n\t\t// target an ambiguous empty connection id.\n\t\tawait this.deleteSecrets(id, providersMetadata[id]?.domain || id, cloud);\n\t}\n\n\tprivate async writeSecret(\n\t\tid: IntegrationIds,\n\t\tsession: ProviderAuthenticationSession | StoredSession,\n\t\tresource?: ConnectionResource,\n\t\tcloudOrigin?: CloudCredentialOrigin,\n\t): Promise<void> {\n\t\tawait this.ctx.storage.storeSecret(\n\t\t\tthis.getSecretKey(id, session.id, session.cloud ?? false),\n\t\t\tJSON.stringify(cloudOrigin == null ? session : { ...session, cloudOrigin: cloudOrigin }),\n\t\t);\n\n\t\tawait this.addOrUpdateConfigured({\n\t\t\tid: session.id,\n\t\t\tintegrationId: id,\n\t\t\tdomain: isSelfManagedHostIntegrationId(id) ? session.domain : undefined,\n\t\t\tbaseUrl: isSelfManagedHostIntegrationId(id) ? session.baseUrl : undefined,\n\t\t\texpiresAt: session.expiresAt,\n\t\t\tscopes: session.scopes.join(','),\n\t\t\tcloud: session.cloud ?? false,\n\t\t\ttype: session.type,\n\t\t\taccountName: session.account?.label || undefined,\n\t\t\tresourceName: resource?.name,\n\t\t\tresourceId: resource?.id,\n\t\t});\n\t}\n\n\tprivate async readSecret(\n\t\tid: IntegrationIds,\n\t\tsessionId: string,\n\t\tcloud: boolean = false,\n\t): Promise<StoredSession | undefined> {\n\t\tconst sessionJSON = await this.ctx.storage.getSecret(this.getSecretKey(id, sessionId, cloud));\n\t\tif (this._disposed) return undefined;\n\n\t\tlet storedSession: StoredSession | undefined;\n\t\ttry {\n\t\t\tif (sessionJSON) {\n\t\t\t\tstoredSession = JSON.parse(sessionJSON);\n\t\t\t\tif (storedSession != null) {\n\t\t\t\t\tif (this.isRetiredSecret(storedSession, cloud)) return undefined;\n\n\t\t\t\t\tconst configured = this.configured.get(id);\n\t\t\t\t\tconst connectionId = storedSession.id ?? sessionId;\n\t\t\t\t\tconst sessionCloud = storedSession.cloud ?? cloud;\n\t\t\t\t\tconst domain = isSelfManagedHostIntegrationId(id)\n\t\t\t\t\t\t? (storedSession.domain ?? storedSession.id)\n\t\t\t\t\t\t: undefined;\n\t\t\t\t\tif (\n\t\t\t\t\t\tconfigured == null ||\n\t\t\t\t\t\tconfigured.length === 0 ||\n\t\t\t\t\t\t!configured.some(\n\t\t\t\t\t\t\tc => c.id === connectionId && c.integrationId === id && c.cloud === sessionCloud,\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tawait this.addOrUpdateConfigured({\n\t\t\t\t\t\t\tid: connectionId,\n\t\t\t\t\t\t\tintegrationId: id,\n\t\t\t\t\t\t\tdomain: domain,\n\t\t\t\t\t\t\t// Rebuilt from the secret, so it must carry the address the session does; omitting it\n\t\t\t\t\t\t\t// leaves the descriptor claiming no context path and makes reconcile read every\n\t\t\t\t\t\t\t// routine check-in as a re-pointed connection.\n\t\t\t\t\t\t\tbaseUrl: isSelfManagedHostIntegrationId(id) ? storedSession.baseUrl : undefined,\n\t\t\t\t\t\t\texpiresAt: storedSession.expiresAt,\n\t\t\t\t\t\t\tscopes: storedSession.scopes.join(','),\n\t\t\t\t\t\t\tcloud: sessionCloud,\n\t\t\t\t\t\t\ttype: storedSession.type,\n\t\t\t\t\t\t\taccountName: storedSession.account?.label || undefined,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (_ex) {\n\t\t\tif (this._disposed) return undefined;\n\n\t\t\ttry {\n\t\t\t\tawait this.deleteSecrets(id, sessionId, cloud);\n\t\t\t} catch {}\n\t\t}\n\t\treturn storedSession;\n\t}\n\n\tprivate getSecretKey(\n\t\tid: IntegrationIds,\n\t\tsessionId: string,\n\t\tcloud: boolean = false,\n\t): `integration.auth:${IntegrationIds}|${string}` | `integration.auth.cloud:${IntegrationIds}|${string}` {\n\t\treturn cloud ? this.getCloudSecretKey(id, sessionId) : this.getLocalSecretKey(id, sessionId);\n\t}\n\n\tprivate getLocalSecretKey(id: IntegrationIds, sessionId: string): `integration.auth:${IntegrationIds}|${string}` {\n\t\treturn `integration.auth:${id}|${sessionId}`;\n\t}\n\n\tprivate getCloudSecretKey(\n\t\tid: IntegrationIds,\n\t\tsessionId: string,\n\t): `integration.auth.cloud:${IntegrationIds}|${string}` {\n\t\treturn `integration.auth.cloud:${id}|${sessionId}`;\n\t}\n\n\tprivate getPrimaryScope(\n\t\tid: IntegrationIds,\n\t\tdescriptors: ConfiguredIntegrationDescriptor[],\n\t\tdomain: string | undefined,\n\t): ConfiguredIntegrationDescriptor[] {\n\t\treturn isSelfManagedHostIntegrationId(id)\n\t\t\t? descriptors.filter(d => this.isInPrimaryScope(id, d, domain))\n\t\t\t: descriptors;\n\t}\n\n\tprivate isInPrimaryScope(\n\t\tid: IntegrationIds,\n\t\tdescriptor: ConfiguredIntegrationDescriptor,\n\t\tdomain: string | undefined,\n\t): boolean {\n\t\treturn !isSelfManagedHostIntegrationId(id) || this.domainsMatch(id, descriptor.domain, domain);\n\t}\n\n\t/**\n\t * Resolves the connection id used as the secret-key session id for an auth descriptor.\n\t * - If the descriptor targets a specific connection (`connectionId`), that wins.\n\t * - Otherwise returns the primary connection's id for the provider (matching the descriptor's domain\n\t * for self-managed hosts; any connection for cloud hosts, where the stored domain is undefined).\n\t * - Falls back to the descriptor domain when nothing is configured yet, preserving legacy\n\t * (pre-multi-account) reads with zero secret migration.\n\t */\n\tresolveConnectionId(id: IntegrationIds, descriptor: IntegrationAuthenticationSessionDescriptor): string {\n\t\t// An empty connectionId is not a real target — treat it as \"no target\" so it resolves the primary\n\t\t// rather than keying a secret under an empty id.\n\t\tif (descriptor.connectionId) return descriptor.connectionId;\n\n\t\tconst domain = isSelfManagedHostIntegrationId(id) ? descriptor.domain : undefined;\n\t\tconst candidates = this.scopeConnectionCandidates(id, domain, descriptor.cloud);\n\t\treturn (candidates?.find(c => c.primary) ?? candidates?.[0])?.id ?? descriptor.domain;\n\t}\n\n\t/**\n\t * Returns the id of the configured connection an unscoped descriptor resolves to (the primary for the\n\t * descriptor's domain, matching {@link resolveConnectionId}'s selection), or `undefined` when nothing is\n\t * configured for it. Unlike {@link resolveConnectionId} this only returns a genuine per-connection cloud\n\t * token id (never a local/PAT or domain-derived legacy id), so callers can safely use it to scope a cloud\n\t * token fetch to one host of a multi-host self-managed provider, or fall through to the provider-global\n\t * primary endpoint on `undefined`.\n\t */\n\t/**\n\t * The address already stored for a self-managed connection — see {@link ConfiguredIntegrationDescriptor.baseUrl}.\n\t *\n\t * Exists so a session rebuilt from a backend response that omits the domain can keep the address the\n\t * connection was configured with, rather than silently falling back to the bare host and losing a context\n\t * path the user never changed. Looked up by connection id first, then by host for an unscoped fetch.\n\t */\n\t/**\n\t * Whether `connectionId` names a cloud connection configured for `domain`'s host.\n\t *\n\t * The caller-facing question is \"is this id evidence that a token belongs to this host\". A connection id\n\t * can arrive from a caller rather than from our own configuration, so it is only evidence once it matches\n\t * a descriptor we stored for that host — see the host guard in `CloudIntegrationAuthenticationProvider`.\n\t */\n\tisConnectionConfiguredForHost(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string | undefined,\n\t\tdomain: string | undefined,\n\t): boolean {\n\t\tif (connectionId == null) return false;\n\n\t\tconst connection = this.getConfigured(id, { cloud: true }).find(c => c.id === connectionId);\n\t\tif (connection == null) return false;\n\n\t\treturn !isSelfManagedHostIntegrationId(id) || this.domainsMatch(id, connection.domain, domain);\n\t}\n\n\tgetConfiguredBaseUrl(id: IntegrationIds, connectionId: string | undefined, domain?: string): string | undefined {\n\t\tif (!isSelfManagedHostIntegrationId(id)) return undefined;\n\n\t\tconst configured = this.getConfigured(id, { cloud: true });\n\t\tconst byId = connectionId != null ? configured.find(c => c.id === connectionId) : undefined;\n\t\tif (byId != null) return byId.baseUrl;\n\n\t\treturn configured.find(c => this.domainsMatch(id, c.domain, domain))?.baseUrl;\n\t}\n\n\tgetConfiguredConnectionId(id: IntegrationIds, domain: string | undefined, cloud?: boolean): string | undefined {\n\t\tconst scoped = isSelfManagedHostIntegrationId(id) ? domain : undefined;\n\t\tconst candidates = this.scopeConnectionCandidates(id, scoped, cloud);\n\t\tconst connection = candidates?.find(c => c.primary) ?? candidates?.[0];\n\t\tif (connection == null) return undefined;\n\n\t\t// Only return a real per-connection cloud token id. Reject a local (PAT) descriptor (surfaced by\n\t\t// scopeConnectionCandidates' non-cloud fallback) and a domain-derived legacy id (the descriptor's own\n\t\t// domain or the provider's canonical domain — see ConfiguredIntegrationDescriptor.id), either of which\n\t\t// would target `v1/provider-tokens/tokens/{domain}` (rejected as a non-uuid). Callers then fall through\n\t\t// to the provider-scoped primary endpoint.\n\t\tif (!connection.cloud) return undefined;\n\n\t\tconst canonicalDomain = providersMetadata[id]?.domain;\n\t\tif (connection.id === connection.domain || (canonicalDomain && connection.id === canonicalDomain)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn connection.id;\n\t}\n\n\t/**\n\t * Selects configured descriptors for a provider matching `domain`, further narrowed to the `cloud`\n\t * variant when specified. A connection id can have both a local (PAT) and cloud descriptor whose ids\n\t * differ (e.g. a legacy local descriptor keyed by domain alongside a real cloud token id); scoping by\n\t * `cloud` keeps a cloud-scoped read/delete from resolving the local id (and vice versa). Falls back to\n\t * the domain-only set when no variant matches, so legacy single-variant resolution is unchanged.\n\t */\n\tprivate scopeConnectionCandidates(\n\t\tid: IntegrationIds,\n\t\tdomain: string | undefined,\n\t\tcloud: boolean | undefined,\n\t): ConfiguredIntegrationDescriptor[] | undefined {\n\t\tconst candidates = this.configured.get(id)?.filter(c => this.domainsMatch(id, c.domain, domain));\n\t\tif (cloud == null || candidates == null) return candidates;\n\n\t\tconst scoped = candidates.filter(c => c.cloud === cloud);\n\t\treturn scoped.length ? scoped : candidates;\n\t}\n\n\t/**\n\t * Marks the given connection as the primary/default for the provider and clears the flag on its\n\t * siblings. Persists immediately instead of relying on a session re-store to carry the primary flag.\n\t */\n\tsetPrimaryConnection(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string,\n\t\tlist?: { sync: CloudIntegrationSync; domain?: string },\n\t): Promise<void> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (this._disposed) return;\n\n\t\t\tif (\n\t\t\t\tlist != null &&\n\t\t\t\t(!list.sync.isCurrent() ||\n\t\t\t\t\tthis.state.cloud.supersedingPrimary(id, list.domain, connectionId, list.sync.mark) != null)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tawait this.setPrimaryConnectionCore(id, connectionId);\n\t\t\tif (list != null || this._disposed) return;\n\n\t\t\tconst selected = this.getConfigured(id, { cloud: true }).find(c => c.id === connectionId && c.primary);\n\t\t\tif (selected != null) {\n\t\t\t\tconst mark = ++this.state.epoch;\n\t\t\t\tthis.state.cloud.observe(`${id}|connection:${connectionId}`, mark);\n\t\t\t\tthis.state.cloud.observePrimary(id, selected.domain, connectionId, mark);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate async setPrimaryConnectionCore(id: IntegrationIds, connectionId: string): Promise<void> {\n\t\tconst descriptors = this.configured.get(id);\n\t\tif (descriptors == null || descriptors.length === 0) return;\n\t\tif (!descriptors.some(d => d.id === connectionId)) return;\n\n\t\tconst target =\n\t\t\tdescriptors.find(d => d.id === connectionId && d.cloud) ?? descriptors.find(d => d.id === connectionId);\n\t\tif (target == null) return;\n\n\t\tconst domain = isSelfManagedHostIntegrationId(id) ? target.domain : undefined;\n\t\t// A connection id can have both a local (PAT) and cloud descriptor. Mark the primary on a single\n\t\t// canonical variant (prefer cloud, since multi-account primaries are cloud-driven) within the\n\t\t// provider/host scope, so other self-managed hosts keep their own default connection.\n\t\tconst primaryIsCloud = descriptors.some(\n\t\t\td => d.id === connectionId && d.cloud && this.isInPrimaryScope(id, d, domain),\n\t\t);\n\n\t\tlet changed = false;\n\t\tconst updated = descriptors.map(d => {\n\t\t\tif (!this.isInPrimaryScope(id, d, domain)) return d;\n\n\t\t\tconst primary = d.id === connectionId && (d.cloud ?? false) === primaryIsCloud;\n\t\t\tif ((d.primary ?? false) === primary) return d;\n\n\t\t\tchanged = true;\n\t\t\treturn { ...d, primary: primary };\n\t\t});\n\t\tif (!changed) return;\n\n\t\tawait this.storeConfigured(id, updated);\n\t\tthis.fireChange(id);\n\t}\n\n\t/**\n\t * Removes a single connection (its secret + configured descriptor). If it was the primary and other\n\t * connections remain, a secondary is promoted (see {@link removeConfigured}). Unlike\n\t * {@link deleteAllStoredSessions}, this only affects the targeted connection. Pass `cloud` to scope\n\t * the removal to the cloud/local variant when a local PAT and a cloud session share a connection id.\n\t */\n\tdeleteConnection(id: IntegrationIds, connectionId: string, cloud?: boolean): Promise<void> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (this._disposed) return;\n\n\t\t\tawait this.deleteSecrets(id, connectionId, cloud, {\n\t\t\t\tonRemoving: () =>\n\t\t\t\t\tthis._onWillRemoveSessions.fire({ integrationId: id, connectionId: connectionId, cloud: cloud }),\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate _addedIds = new Set<IntegrationIds>();\n\tprivate _removedIds = new Set<IntegrationIds>();\n\tprivate _fireChangeDebounced?: () => void;\n\n\tprivate normalizeConfiguredDomain(id: IntegrationIds, domain: string | undefined): string | undefined {\n\t\tif (!isSelfManagedHostIntegrationId(id)) return domain;\n\n\t\treturn hostFromDomain(domain) ?? domain;\n\t}\n\n\tprivate domainsMatch(id: IntegrationIds, first: string | undefined, second: string | undefined): boolean {\n\t\tif (first === second) return true;\n\t\tif (!isSelfManagedHostIntegrationId(id)) return false;\n\t\tif (first == null || second == null) return false;\n\n\t\treturn areDomainsOnSameHost(first, second);\n\t}\n\n\tprivate fireChange(added?: IntegrationIds, removed?: IntegrationIds) {\n\t\tthis._fireChangeDebounced ??= debounce(() => {\n\t\t\tconst added = [...this._addedIds];\n\t\t\tthis._addedIds.clear();\n\t\t\tconst removed = [...this._removedIds];\n\t\t\tthis._removedIds.clear();\n\n\t\t\tthis._onDidChange.fire({ added: added, removed: removed });\n\t\t}, 250);\n\n\t\tif (added != null) {\n\t\t\tthis._addedIds.add(added);\n\t\t}\n\t\tif (removed != null) {\n\t\t\tthis._removedIds.add(removed);\n\t\t}\n\t\tthis._fireChangeDebounced();\n\t}\n}\n\nfunction isLegacyCloudSecret(raw: string): boolean {\n\ttry {\n\t\tconst session = JSON.parse(raw) as StoredSession;\n\t\treturn session?.cloud === true || (session?.cloud !== false && session?.expiresAt != null);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction convertStoredSessionToSession(\n\tstoredSession: StoredSession | undefined,\n\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\tcloudIfMissing: boolean,\n): ProviderAuthenticationSession | undefined {\n\tif (storedSession == null) return undefined;\n\n\treturn {\n\t\tid: storedSession.id,\n\t\taccessToken: storedSession.accessToken,\n\t\taccount: {\n\t\t\tid: storedSession.account?.id ?? '',\n\t\t\tlabel: storedSession.account?.label ?? '',\n\t\t},\n\t\tscopes: storedSession.scopes,\n\t\tcloud: storedSession.cloud ?? cloudIfMissing,\n\t\texpiresAt: storedSession.expiresAt ? new Date(storedSession.expiresAt) : undefined,\n\t\tdomain: storedSession.domain ?? descriptor.domain,\n\t\tbaseUrl: getStoredBaseUrl(storedSession.baseUrl, storedSession.domain, storedSession.protocol),\n\t\tprotocol: storedSession.protocol,\n\t\ttype: storedSession.type,\n\t\t// Carried for providers whose client needs an app key alongside the token (e.g. Trello); without\n\t\t// this a rehydrated session silently loses the key and every read no-ops.\n\t\tappKey: storedSession.appKey,\n\t};\n}\n\nfunction getStoredBaseUrl(\n\tbaseUrl: string | undefined,\n\tdomain: string | undefined,\n\tprotocol?: string,\n): string | undefined {\n\tif (baseUrl != null) return baseUrl;\n\n\tconst legacyUrl = baseUrlFromDomain(domain, protocol);\n\treturn legacyUrl != null && new URL(legacyUrl).pathname !== '/' ? legacyUrl : undefined;\n}\n"],"mappings":";;;;;;;;;;AAqCA,MAAM,iBAAiB;AAgDvB,MAAM,yCAAyB,IAAI,QAAsE;AAEzG,IAAa,+BAAb,MAAgE;CAyBlC;CAxB7B,eAAgC,IAAI,QAA2C;CAC/E,uBAAwC,IAAI,QAAuC;CACnF,wBAAyC,IAAI,QAK1C;CACH,gCAAiC,IAAI,IAA4C;CACjF;CACA,YAAoB;CACpB,IAAI,cAAwD;EAC3D,OAAO,KAAK,aAAa;CAC1B;CACA,IAAI,gBAAyD;EAC5D,OAAO,KAAK,MAAM,cAAc;CACjC;CACA,IAAI,sBAA4D;EAC/D,OAAO,KAAK,qBAAqB;CAClC;CACA,IAAI,uBAAgE;EACnE,OAAO,KAAK,sBAAsB;CACnC;CAEA,YAAY,KAAiD;EAAhC,KAAA,MAAA;EAC5B,IAAI,QAAQ,uBAAuB,IAAI,IAAI,OAAO;EAClD,IAAI,SAAS,MAAM;GAClB,QAAQ;IACP,aAAa,QAAQ,QAAQ;IAC7B,uBAAO,IAAI,IAAI;IACf,OAAO;IACP,wBAAQ,IAAI,IAAI;IAChB,0BAAU,IAAI,IAAI;IAClB,8BAAc,IAAI,IAAI;IACtB,0BAAU,IAAI,IAAI;IAClB,OAAO,IAAI,6BAA6B,IAAI,QAAQ,IAAI,cAAc,CAAC;IACvE,eAAe,IAAI,QAA0C;IAC7D,0BAAU,IAAI,IAAI;GACnB;GACA,uBAAuB,IAAI,IAAI,SAAS,KAAK;EAC9C;EACA,KAAK,QAAQ;CACd;CAEA,UAAgB;EACf,KAAK,YAAY;EACjB,KAAK,aAAa,QAAQ;EAC1B,KAAK,qBAAqB,QAAQ;EAClC,KAAK,sBAAsB,QAAQ;CACpC;CAEA,IAAY,aAAqE;EAChF,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