@gitkraken/core-gitlens 0.51.1 → 0.53.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 (71) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/_types/provider-apis/types/exportedTypes/github.d.ts +75 -0
  3. package/dist/_types/provider-apis/types/exportedTypes/types.d.ts +7 -0
  4. package/dist/git-cli/providers/config.js +2 -2
  5. package/dist/git-cli/providers/pausedOperations.js +2 -2
  6. package/dist/git-cli/providers/pausedOperations.js.map +1 -1
  7. package/dist/git-cli/providers/staging.js +1 -1
  8. package/dist/ipc/discovery.js +1 -1
  9. package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
  10. package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
  11. package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
  12. package/dist/plus/git-github/api/issueWrites.js +1 -1
  13. package/dist/plus/git-github/api/issueWrites.js.map +1 -1
  14. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.d.ts +10 -1
  15. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +75 -23
  16. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -1
  17. package/dist/plus/integrations/authentication/cloudIntegrationObservations.d.ts +49 -0
  18. package/dist/plus/integrations/authentication/cloudIntegrationObservations.js +118 -0
  19. package/dist/plus/integrations/authentication/cloudIntegrationObservations.js.map +1 -0
  20. package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +45 -25
  21. package/dist/plus/integrations/authentication/configuredIntegrationService.js +409 -141
  22. package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
  23. package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +12 -3
  24. package/dist/plus/integrations/authentication/integrationAuthenticationService.js +39 -7
  25. package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
  26. package/dist/plus/integrations/authentication/models.d.ts +6 -0
  27. package/dist/plus/integrations/authentication/models.js +9 -1
  28. package/dist/plus/integrations/authentication/models.js.map +1 -1
  29. package/dist/plus/integrations/authentication/observedAuthenticationProvider.d.ts +17 -2
  30. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js +84 -16
  31. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js.map +1 -1
  32. package/dist/plus/integrations/index.d.ts +3 -2
  33. package/dist/plus/integrations/index.js.map +1 -1
  34. package/dist/plus/integrations/integrationService.d.ts +9 -0
  35. package/dist/plus/integrations/integrationService.js +182 -39
  36. package/dist/plus/integrations/integrationService.js.map +1 -1
  37. package/dist/plus/integrations/manager.d.ts +3 -0
  38. package/dist/plus/integrations/models/integration.d.ts +4 -0
  39. package/dist/plus/integrations/models/integration.js +61 -16
  40. package/dist/plus/integrations/models/integration.js.map +1 -1
  41. package/dist/plus/integrations/models/issueRelationships.d.ts +31 -0
  42. package/dist/plus/integrations/models/issueRelationships.js +0 -0
  43. package/dist/plus/integrations/models/workItemWrites.d.ts +34 -2
  44. package/dist/plus/integrations/providers/azure/azure.js +1 -1
  45. package/dist/plus/integrations/providers/azureDevOps.d.ts +4 -3
  46. package/dist/plus/integrations/providers/azureDevOps.js +6 -6
  47. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  48. package/dist/plus/integrations/providers/azureDevOpsServer.d.ts +3 -0
  49. package/dist/plus/integrations/providers/azureDevOpsServer.js +14 -0
  50. package/dist/plus/integrations/providers/azureDevOpsServer.js.map +1 -1
  51. package/dist/plus/integrations/providers/azureWorkItemWriteErrors.d.ts +4 -0
  52. package/dist/plus/integrations/providers/azureWorkItemWriteErrors.js +34 -2
  53. package/dist/plus/integrations/providers/azureWorkItemWriteErrors.js.map +1 -1
  54. package/dist/plus/integrations/providers/azureWorkItemWrites.d.ts +5 -2
  55. package/dist/plus/integrations/providers/azureWorkItemWrites.js +57 -14
  56. package/dist/plus/integrations/providers/azureWorkItemWrites.js.map +1 -1
  57. package/dist/plus/integrations/providers/github.d.ts +8 -0
  58. package/dist/plus/integrations/providers/github.js +162 -2
  59. package/dist/plus/integrations/providers/github.js.map +1 -1
  60. package/dist/plus/integrations/providers/providerApiClient.d.ts +1 -1
  61. package/dist/plus/integrations/providers/providerApiClient.js +33 -14
  62. package/dist/plus/integrations/providers/providerApiClient.js.map +1 -1
  63. package/dist/plus/integrations/providers/providerErrors.d.ts +1 -0
  64. package/dist/plus/integrations/providers/providerErrors.js +1 -2
  65. package/dist/plus/integrations/providers/providerErrors.js.map +1 -1
  66. package/dist/plus/integrations/providers/providersApi.d.ts +10 -4
  67. package/dist/plus/integrations/providers/providersApi.js +21 -0
  68. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  69. package/dist/utils/env/node/exec.js +2 -2
  70. package/docs/integrations.md +61 -0
  71. package/package.json +2 -2
@@ -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 { ConfiguredIntegrationService } from './configuredIntegrationService.js';\nimport type {\n\tGetSessionOptions,\n\tIntegrationAuthenticationProvider,\n\tIntegrationAuthenticationSessionDescriptor,\n\tRejectedTokenRefreshOptions,\n} from './integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from './integrationAuthenticationService.js';\nimport type { ProviderAuthenticationSession } from './models.js';\nimport { isSupportedCloudIntegrationId } from './models.js';\n\n// The package's implementation of the public `IntegrationAuthenticationProvider` contract, kept out of that module so\n// the contract's declarations never reach the internal services these classes are built on.\n\nconst maxSmallIntegerV8 = 2 ** 30 - 1; // Max number that can be stored in V8's smis (small integers)\n\n/**\n * What {@link IntegrationAuthenticationProviderBase.getSession} passes down once it has decided the stored\n * session can't be served as-is. `refreshIfExpired` is its own conclusion, not a caller's option.\n */\ntype GetNewSessionOptions = GetSessionOptions & { refreshIfExpired?: boolean };\n\nabstract class IntegrationAuthenticationProviderBase<\n\tID extends IntegrationIds = IntegrationIds,\n> implements IntegrationAuthenticationProvider {\n\tprotected readonly disposables: Disposable[] = [];\n\n\tconstructor(\n\t\tprotected readonly authenticationService: IntegrationAuthenticationService,\n\t\tprotected readonly configuredIntegrationService: ConfiguredIntegrationService,\n\t) {}\n\n\tdispose(): void {\n\t\tthis.disposables.forEach(d => d.dispose());\n\t}\n\n\tprivate readonly _onDidChange = new Emitter<void>();\n\tget onDidChange(): Event<void> {\n\t\treturn this._onDidChange.event;\n\t}\n\n\tprotected abstract get authProviderId(): ID;\n\n\t@trace()\n\tasync deleteSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: { preserveConfigured?: boolean; signOutMark?: number },\n\t): Promise<void> {\n\t\tconst domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : undefined;\n\t\tconst configured = this.configuredIntegrationService.getConfigured(this.authProviderId, {\n\t\t\tdomain: domain,\n\t\t});\n\n\t\t// Scope the descriptor to cloud so resolveConnectionId targets the cloud variant's id: this is a\n\t\t// cloud-only delete, and a mixed local+cloud connection whose local descriptor is primary would\n\t\t// otherwise resolve the local id and leave the cloud secret intact.\n\t\tconst deleted = await this.configuredIntegrationService.deleteStoredSessions(\n\t\t\tthis.authProviderId,\n\t\t\t{ ...descriptor, cloud: true },\n\t\t\ttrue,\n\t\t\t{ preserveConfigured: options?.preserveConfigured ?? true, signOutMark: options?.signOutMark },\n\t\t);\n\n\t\tif (deleted && configured?.length) {\n\t\t\tthis.fireChange();\n\t\t}\n\t}\n\n\t@trace()\n\tasync deleteAllSessions(descriptor?: IntegrationAuthenticationSessionDescriptor): Promise<void> {\n\t\t// Self-managed providers group every host under one provider id, so scope the clear to this\n\t\t// descriptor's host when given; for cloud providers the domain stays undefined here, clearing every account.\n\t\tconst domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : undefined;\n\t\tconst configured = this.configuredIntegrationService.getConfigured(this.authProviderId, {\n\t\t\tdomain: domain,\n\t\t});\n\n\t\tawait this.configuredIntegrationService.deleteAllStoredSessions(this.authProviderId, undefined, domain);\n\n\t\tif (configured?.length) {\n\t\t\tthis.fireChange();\n\t\t}\n\t}\n\n\t@trace()\n\tasync getSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetSessionOptions,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tlet session;\n\t\tlet previousToken;\n\t\tlet refetched: ProviderAuthenticationSession | undefined;\n\t\tlet signOutMark: number;\n\t\tif (options?.forceNewSession) {\n\t\t\tif (isSelfManagedHostIntegrationId(this.authProviderId)) {\n\t\t\t\tconst connectionId =\n\t\t\t\t\tdescriptor.connectionId ||\n\t\t\t\t\tthis.configuredIntegrationService.getConfiguredConnectionId(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\t!this.configuredIntegrationService.isConnectionConfiguredForHost(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tconnectionId,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tdescriptor = { ...descriptor, connectionId: connectionId };\n\t\t\t}\n\t\t\t// Cloud-only delete (see deleteSession): scope to cloud so the cloud variant's id is cleared even\n\t\t\t// when a mixed local+cloud connection's local descriptor is primary. A sign-out, so a token fetched before\n\t\t\t// it is not stored back; the mark is taken after it, so this session's own fetch is not refused.\n\t\t\tawait this.configuredIntegrationService.deleteStoredSessions(\n\t\t\t\tthis.authProviderId,\n\t\t\t\t{ ...descriptor, cloud: true },\n\t\t\t\ttrue,\n\t\t\t\t{ signOut: true, preserveConfigured: isSelfManagedHostIntegrationId(this.authProviderId) },\n\t\t\t);\n\t\t\tsignOutMark = this.configuredIntegrationService.getSignOutMark();\n\t\t} else {\n\t\t\t// Taken before the stored-token read (a sign-out landing during the read is ordered after it by the storage\n\t\t\t// lock, so it counts either way).\n\t\t\tsignOutMark = this.configuredIntegrationService.getSignOutMark();\n\t\t\tconst stored = await this.configuredIntegrationService.getStoredSession(\n\t\t\t\tthis.authProviderId,\n\t\t\t\toptions?.sync ? { ...descriptor, cloud: true } : descriptor,\n\t\t\t);\n\t\t\tpreviousToken = stored?.accessToken;\n\t\t\tif (options?.sync && options.refetch) {\n\t\t\t\trefetched = stored;\n\t\t\t} else {\n\t\t\t\tsession = stored;\n\t\t\t}\n\t\t}\n\n\t\tconst isExpiredSession = session?.expiresAt != null && new Date(session.expiresAt).getTime() < Date.now();\n\t\t// A rejected token has to re-resolve even when the stored session looks perfectly healthy: that is\n\t\t// the whole point — the provider refused it while its expiry still says valid. Without this the\n\t\t// stored session short-circuits here and the refresh below is never reached.\n\t\tconst scopedRecovery = options?.isRejectedToken?.(session?.accessToken) === true;\n\t\tconst refreshRejectedToken = scopedRecovery || (options?.refreshRejectedToken === true && session != null);\n\t\tif (session == null || isExpiredSession || refreshRejectedToken) {\n\t\t\tsession = await this.getNewSession(descriptor, {\n\t\t\t\t...options,\n\t\t\t\trefreshIfExpired: isExpiredSession,\n\t\t\t\trefreshRejectedToken: refreshRejectedToken,\n\t\t\t\tisRejectedToken: scopedRecovery ? options?.isRejectedToken : undefined,\n\t\t\t});\n\t\t\tif (\n\t\t\t\tsession == null &&\n\t\t\t\toptions?.refetch &&\n\t\t\t\trefetched != null &&\n\t\t\t\tthis.configuredIntegrationService.isSessionRetiredSince(this.authProviderId, refetched, signOutMark)\n\t\t\t) {\n\t\t\t\tthrow new CancellationError();\n\t\t\t}\n\n\t\t\tif (session != null) {\n\t\t\t\tconst stored = await this.configuredIntegrationService.storeSession(this.authProviderId, session, {\n\t\t\t\t\tsignOutMark: signOutMark,\n\t\t\t\t\texpectedStoredAccessToken: scopedRecovery ? previousToken : undefined,\n\t\t\t\t});\n\t\t\t\tif (!stored) {\n\t\t\t\t\t// A disconnect leaves no credential here. A recovery can leave a replacement for this same\n\t\t\t\t\t// connection, which a forced sync must not interpret as a disconnect and delete.\n\t\t\t\t\tsession = await this.configuredIntegrationService.getStoredSession(this.authProviderId, {\n\t\t\t\t\t\t...descriptor,\n\t\t\t\t\t\tconnectionId: session.id,\n\t\t\t\t\t\tcloud: session.cloud,\n\t\t\t\t\t});\n\t\t\t\t\toptions?.isRejectedToken?.(session?.accessToken);\n\t\t\t\t} else if (refetched?.id != null && refetched.id !== session.id) {\n\t\t\t\t\t// The replacement belongs to a different connection (the cloud's primary moved to another\n\t\t\t\t\t// account), so it was stored beside the one it replaces rather than over it. Drop the old token\n\t\t\t\t\t// as the up-front delete used to, or an unscoped read would keep resolving it until the next sync.\n\t\t\t\t\tawait this.configuredIntegrationService.deleteStoredSessions(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\t{ ...descriptor, connectionId: refetched.id, cloud: true },\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t{ preserveConfigured: true },\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (previousToken !== session?.accessToken) {\n\t\t\tthis.fireChange();\n\t\t}\n\n\t\treturn session;\n\t}\n\n\tprotected abstract getNewSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetNewSessionOptions,\n\t): Promise<ProviderAuthenticationSession | undefined>;\n\n\tprotected fireChange(): void {\n\t\tqueueMicrotask(() => this._onDidChange.fire());\n\t}\n}\n\nexport class CloudIntegrationAuthenticationProvider<\n\tID extends IntegrationIds = IntegrationIds,\n> extends IntegrationAuthenticationProviderBase<ID> {\n\tconstructor(\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tconfiguredIntegrationService: ConfiguredIntegrationService,\n\t\tprivate readonly _authProviderId: ID,\n\t) {\n\t\tsuper(authenticationService, configuredIntegrationService);\n\t}\n\n\tprotected get authProviderId(): ID {\n\t\treturn this._authProviderId;\n\t}\n\n\tprotected override async getNewSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetNewSessionOptions,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tif (options?.forceNewSession) {\n\t\t\tif ((await this.disconnectCloudSession(descriptor)) === 'failure') {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tvoid this.connectCloudSession(false, options?.source);\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// TODO: This is a stopgap to make sure we're not hammering the api on automatic calls to get the session.\n\t\t// Ultimately we want to timestamp calls to syncCloudIntegrations and use that to determine whether we should\n\t\t// make the call or not.\n\t\t// `refreshRejectedToken` joins the list for the same reason `refreshIfExpired` is on it: both mean the\n\t\t// session in hand is known-unusable, so skipping the cloud round trip would just re-serve it.\n\t\tlet session =\n\t\t\toptions?.refreshIfExpired ||\n\t\t\toptions?.refreshRejectedToken ||\n\t\t\toptions?.createIfNeeded ||\n\t\t\toptions?.forceNewSession ||\n\t\t\toptions?.sync\n\t\t\t\t? await this.getCloudSession(descriptor, options)\n\t\t\t\t: undefined;\n\n\t\tconst shouldCreateSession = options?.createIfNeeded && session == null;\n\t\tif (shouldCreateSession) {\n\t\t\tconst connected = await this.connectCloudSession(true, options?.source);\n\t\t\tif (!connected) return undefined;\n\n\t\t\t// This should get us the session we just created with connectCloudSession, because a syncCloudIntegrations run from\n\t\t\t// integration service should have resulted in it being created and stored by this provider\n\t\t\tsession = await this.getSession(descriptor, { source: options?.source });\n\t\t}\n\t\treturn session;\n\t}\n\n\tprivate connectCloudSession(skipIfConnected: boolean, source: Sources | undefined): Promise<boolean> {\n\t\t// Capture in a const so the type guard narrows it to `SupportedCloudIntegrationIds` (a getter\n\t\t// access wouldn't narrow), letting us call the service directly without a cast.\n\t\tconst id = this.authProviderId;\n\t\tif (isSupportedCloudIntegrationId(id)) {\n\t\t\treturn this.authenticationService.connectCloudIntegrations(\n\t\t\t\t{ integrationIds: [id], skipIfConnected: skipIfConnected, skipPreSync: true },\n\t\t\t\t{\n\t\t\t\t\tsource: source ?? 'integrations',\n\t\t\t\t\tdetail: {\n\t\t\t\t\t\taction: 'connect',\n\t\t\t\t\t\tintegration: id,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\treturn Promise.resolve(false);\n\t}\n\n\tprivate async getCloudSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: RejectedTokenRefreshOptions,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tconst loggedIn = (await this.authenticationService.ctx.account.getAccount()) != null;\n\t\tif (!loggedIn) return undefined;\n\n\t\tconst cloudIntegrations = this.authenticationService.cloudIntegrations;\n\t\t// An unscoped descriptor (no explicit connectionId) would fetch the provider-global primary via\n\t\t// `v1/provider-tokens/<provider>`. For a self-managed provider spanning multiple hosts that primary\n\t\t// can belong to a different host, so a forced sync of host A would hydrate host B's token here (before\n\t\t// reconcile corrects storage). Scope to this host's own configured connection when we have one; fall\n\t\t// through to the provider-scoped path only when nothing is configured yet (legacy/first sync).\n\t\tconst connectionId =\n\t\t\tdescriptor.connectionId ??\n\t\t\t(isSelfManagedHostIntegrationId(this.authProviderId)\n\t\t\t\t? this.configuredIntegrationService.getConfiguredConnectionId(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t)\n\t\t\t\t: undefined);\n\t\t// Refuses a session issued for a DIFFERENT host than the one this connection is keyed by, which would\n\t\t// otherwise let host B's token serve host A.\n\t\t//\n\t\t// A session that names no host is accepted ONLY when it was fetched by a connection id WE have stored\n\t\t// for this host. That descriptor is what ties the token to the host, so an absent domain then means the\n\t\t// backend did not say rather than that the token belongs elsewhere, and refusing it would strand the\n\t\t// refresh.\n\t\t//\n\t\t// A non-null id is not enough on its own: `descriptor.connectionId` can come from the caller, and with\n\t\t// no id at all the fetch goes to the provider-GLOBAL primary endpoint whose token can belong to any\n\t\t// configured host. In both of those cases a domainless response must be refused, or a token would be\n\t\t// bound to — and sent to — a host it was never issued for.\n\t\tconst scopedToThisHost = this.configuredIntegrationService.isConnectionConfiguredForHost(\n\t\t\tthis.authProviderId,\n\t\t\tconnectionId,\n\t\t\tdescriptor.domain,\n\t\t);\n\t\tconst isForAnotherHost = (session: { domain: string } | undefined) =>\n\t\t\tsession != null &&\n\t\t\tisSelfManagedHostIntegrationId(this.authProviderId) &&\n\t\t\t(!scopedToThisHost || Boolean(session.domain?.trim())) &&\n\t\t\t!areDomainsOnSameHost(session.domain, descriptor.domain);\n\n\t\tlet session = await cloudIntegrations.getConnectionSession(this.authProviderId, undefined, connectionId);\n\t\tif (isForAnotherHost(session)) return undefined;\n\t\tif (options?.isRejectedToken != null && session?.id != null && session.id !== connectionId) return undefined;\n\n\t\t// GitHub, the cloud self-managed hosts, and Trello return `expiresIn: 0` for a token that never\n\t\t// expires; left as 0 the session would be built with `expiresAt = now` and rejected as expired on the\n\t\t// next resolution. Map it to the maximum expiry so it isn't refreshed frequently.\n\t\tif (session?.expiresIn === 0 && isNonExpiringZeroTokenIntegrationId(this.authProviderId)) {\n\t\t\tsession.expiresIn = maxSmallIntegerV8; // maximum expiration length\n\t\t}\n\n\t\t// `expiresIn < 60` is a PREDICTION that the token is about to lapse, and it is the only trigger the\n\t\t// refresh used to have. It cannot see a token the provider has already refused while the backend\n\t\t// still believes it is valid — a revoked grant, retired scopes, an app removed from the org — where\n\t\t// `expiresIn` stays high and the doomed token is re-sent on every read. `refreshRejectedToken` is\n\t\t// the observed counterpart: the caller saw the provider reject this exact token, so refresh it\n\t\t// regardless of what its expiry claims.\n\t\tif (\n\t\t\tsession != null &&\n\t\t\t(session.expiresIn < 60 ||\n\t\t\t\t(options?.refreshRejectedToken && (options.isRejectedToken?.(session.accessToken) ?? true)))\n\t\t) {\n\t\t\tsession = await cloudIntegrations.getConnectionSession(\n\t\t\t\tthis.authProviderId,\n\t\t\t\tsession.accessToken,\n\t\t\t\tconnectionId,\n\t\t\t);\n\t\t\tif (isForAnotherHost(session)) return undefined;\n\t\t\tif (options?.isRejectedToken != null && session?.id != null && session.id !== connectionId) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\n\t\tif (!session) return undefined;\n\n\t\tlet sessionProtocol;\n\t\t// Only derive a protocol from a domain carrying an explicit scheme; a bare `host:port` (e.g. a\n\t\t// self-managed `ghe.example.com:8443`) parses the host as the protocol, corrupting the value.\n\t\tif (/^[a-z][a-z\\d+\\-.]*:\\/\\//i.test(session.domain)) {\n\t\t\ttry {\n\t\t\t\tsessionProtocol = new URL(session.domain).protocol;\n\t\t\t} catch {\n\t\t\t\tsessionProtocol = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t// Prefer the backend's per-connection token id (multi-account); fall back to the resolved\n\t\t\t// primary/legacy connection id so existing single-connection storage keys are preserved.\n\t\t\tid: session.id ?? this.configuredIntegrationService.resolveConnectionId(this.authProviderId, descriptor),\n\t\t\taccessToken: session.accessToken,\n\t\t\tscopes: descriptor.scopes,\n\t\t\taccount: {\n\t\t\t\tid: '',\n\t\t\t\tlabel: '',\n\t\t\t},\n\t\t\tcloud: true,\n\t\t\ttype: session.type,\n\t\t\texpiresAt: new Date(session.expiresIn * 1000 + Date.now()),\n\t\t\t// Note: do not use the session's domain, because the format is different than in our model\n\t\t\tdomain: descriptor.domain,\n\t\t\t// That format difference is exactly what `baseUrl` is for: the descriptor's domain is the\n\t\t\t// normalized host this connection is keyed by, so a context path only survives on the wire value.\n\t\t\t// When the backend reports no domain at all, KEEP the address already configured rather than\n\t\t\t// writing `undefined` — `writeSecret` mirrors this onto the descriptor, so falling back to the\n\t\t\t// bare host here would drop a context path the user never changed on the next refresh.\n\t\t\tbaseUrl:\n\t\t\t\tsession.domain ||\n\t\t\t\tthis.configuredIntegrationService.getConfiguredBaseUrl(\n\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\tconnectionId,\n\t\t\t\t\tdescriptor.domain,\n\t\t\t\t),\n\t\t\tprotocol: sessionProtocol ?? undefined,\n\t\t\t// Carried for providers whose client needs an app key alongside the token (e.g. Trello).\n\t\t\tappKey: session.appKey,\n\t\t};\n\t}\n\n\tprivate async disconnectCloudSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t): Promise<'skip' | 'success' | 'failure'> {\n\t\tconst loggedIn = (await this.authenticationService.ctx.account.getAccount()) != null;\n\t\tif (!loggedIn) return 'skip';\n\n\t\tconst cloudIntegrations = this.authenticationService.cloudIntegrations;\n\t\tif (!(await cloudIntegrations.disconnect(this.authProviderId, descriptor.connectionId))) return 'failure';\n\n\t\tif (isSelfManagedHostIntegrationId(this.authProviderId)) {\n\t\t\tawait this.deleteSession(descriptor, { preserveConfigured: false });\n\t\t}\n\n\t\treturn 'success';\n\t}\n}\n"],"mappings":";;;;;;;;AAuBA,MAAM,oBAAoB,KAAK,KAAK;AAQpC,IAAe,wCAAf,MAE+C;CAI1B;CACA;CAJpB,cAA+C,CAAC;CAEhD,YACC,uBACA,8BACC;EAFkB,KAAA,wBAAA;EACA,KAAA,+BAAA;CACjB;CAEH,UAAgB;EACf,KAAK,YAAY,SAAQ,MAAK,EAAE,QAAQ,CAAC;CAC1C;CAEA,eAAgC,IAAI,QAAc;CAClD,IAAI,cAA2B;EAC9B,OAAO,KAAK,aAAa;CAC1B;CAIA,MACM,cACL,YACA,SACgB;EAChB,MAAM,SAAS,+BAA+B,KAAK,cAAc,IAAI,YAAY,SAAS,KAAA;EAC1F,MAAM,aAAa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;GACR;GACA,OAAO;GACP,MAAM,QAAQ;GACd,WAAW,IAAI,KAAK,QAAQ,YAAY,MAAO,KAAK,IAAI,CAAC;GAEzD,QAAQ,WAAW;GAMnB,SACC,QAAQ,UACR,KAAK,6BAA6B,qBACjC,KAAK,gBACL,cACA,WAAW,MACZ;GACD,UAAU,mBAAmB,KAAA;GAE7B,QAAQ,QAAQ;EACjB;CACD;CAEA,MAAc,uBACb,YAC0C;EAE1C,IAAI,EADc,MAAM,KAAK,sBAAsB,IAAI,QAAQ,WAAW,KAAM,OACjE,OAAO;EAGtB,IAAI,CAAE,MADoB,KAAK,sBAAsB,kBACvB,WAAW,KAAK,gBAAgB,WAAW,YAAY,GAAI,OAAO;EAEhG,IAAI,+BAA+B,KAAK,cAAc,GACrD,MAAM,KAAK,cAAc,YAAY,EAAE,oBAAoB,MAAM,CAAC;EAGnE,OAAO;CACR;AACD"}
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,cAAc,KAAK,gBAAgB,EAAU,OAAO,CAA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;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"}
@@ -0,0 +1,49 @@
1
+ import { CloudIntegrationConnection, ConfiguredIntegrationDescriptor } from "./models.js";
2
+ import { IntegrationIds } from "../constants.js";
3
+ //#region ../plus/integrations/src/authentication/cloudIntegrationObservations.d.ts
4
+ export interface CloudIntegrationSync {
5
+ readonly mark: number;
6
+ isCurrent(): boolean;
7
+ }
8
+ type CloudOrder = {
9
+ owner: string;
10
+ mark: number;
11
+ };
12
+ type CloudLogout = CloudOrder & {
13
+ departures: readonly string[];
14
+ };
15
+ export type CloudCredentialOrigin = CloudOrder & {
16
+ after?: string;
17
+ };
18
+ export declare class CloudIntegrationObservations {
19
+ private readonly owner;
20
+ private readonly acquisitions;
21
+ private readonly inheritedLogout?;
22
+ private _logout?;
23
+ get hasLogout(): boolean;
24
+ snapshotLogout(): CloudLogout | undefined;
25
+ constructor(previousLogout?: CloudLogout);
26
+ origin(mark: number): CloudCredentialOrigin;
27
+ allows(origin: CloudCredentialOrigin | undefined): boolean;
28
+ published(scope: string, mark: number): void;
29
+ acquiredAfter(scope: string, mark: number): boolean;
30
+ private latestSync;
31
+ private _lastLogout;
32
+ get lastLogout(): number;
33
+ private readonly connections;
34
+ private readonly departures;
35
+ private readonly primaries;
36
+ acceptLogout(request: number, mark: number, connections: readonly ConfiguredIntegrationDescriptor[]): CloudIntegrationSync | undefined;
37
+ accept(mark: number, connections: ReadonlyMap<IntegrationIds, readonly CloudIntegrationConnection[]>): CloudIntegrationSync | undefined;
38
+ loggedOutSince(mark: number): boolean;
39
+ observe(scope: string, mark: number): void;
40
+ observedSince(scope: string, mark: number): boolean;
41
+ remove(scope: string): void;
42
+ depart(id: IntegrationIds, domain: string | undefined, connectionId: string, mark: number): boolean;
43
+ departedAt(id: IntegrationIds, domain: string, connectionId: string): number | undefined;
44
+ observePrimary(id: IntegrationIds, domain: string | undefined, connectionId: string, mark: number): void;
45
+ supersedingPrimary(id: IntegrationIds, domain: string | undefined, connectionId: string, mark: number): string | undefined;
46
+ private primaryScope;
47
+ }
48
+ //#endregion
49
+ //# sourceMappingURL=cloudIntegrationObservations.d.ts.map
@@ -0,0 +1,118 @@
1
+ import { uuid } from "../../../utils/crypto.js";
2
+ import { hostFromDomain } from "../utils/domain.utils.js";
3
+ import { isSelfManagedHostIntegrationId } from "../utils/integration.utils.js";
4
+ //#region ../plus/integrations/src/authentication/cloudIntegrationObservations.ts
5
+ var CloudIntegrationObservations = class {
6
+ owner = uuid();
7
+ acquisitions = /* @__PURE__ */ new Map();
8
+ inheritedLogout;
9
+ _logout;
10
+ get hasLogout() {
11
+ return this._logout != null;
12
+ }
13
+ snapshotLogout() {
14
+ return this._logout && {
15
+ ...this._logout,
16
+ departures: [...this.departures.keys()]
17
+ };
18
+ }
19
+ constructor(previousLogout) {
20
+ this._logout = previousLogout;
21
+ if (previousLogout != null) {
22
+ this.inheritedLogout = `${previousLogout.owner}:${previousLogout.mark}`;
23
+ for (const scope of previousLogout.departures) this.departures.set(scope, 0);
24
+ }
25
+ }
26
+ origin(mark) {
27
+ return {
28
+ owner: this.owner,
29
+ mark,
30
+ after: this.inheritedLogout
31
+ };
32
+ }
33
+ allows(origin) {
34
+ const logout = this._logout;
35
+ return logout == null || origin != null && (origin.owner === logout.owner ? origin.mark > logout.mark : origin.after === `${logout.owner}:${logout.mark}`);
36
+ }
37
+ published(scope, mark) {
38
+ this.acquisitions.set(scope, mark);
39
+ }
40
+ acquiredAfter(scope, mark) {
41
+ return (this.acquisitions.get(scope) ?? 0) > mark;
42
+ }
43
+ latestSync = 0;
44
+ _lastLogout = 0;
45
+ get lastLogout() {
46
+ return this._lastLogout;
47
+ }
48
+ connections = /* @__PURE__ */ new Map();
49
+ departures = /* @__PURE__ */ new Map();
50
+ primaries = /* @__PURE__ */ new Map();
51
+ acceptLogout(request, mark, connections) {
52
+ if (this._logout?.owner === this.owner && request <= this._logout.mark) return void 0;
53
+ for (const connection of connections) this.depart(connection.integrationId, connection.domain, connection.id, mark);
54
+ this._logout = {
55
+ owner: this.owner,
56
+ mark: request
57
+ };
58
+ this._lastLogout = mark;
59
+ this.latestSync = Math.max(this.latestSync, request);
60
+ return {
61
+ mark,
62
+ isCurrent: () => this.latestSync === request
63
+ };
64
+ }
65
+ accept(mark, connections) {
66
+ if (mark <= this.latestSync) return void 0;
67
+ this.latestSync = mark;
68
+ for (const [id, entries] of connections) for (const connection of entries) {
69
+ if (connection.id == null) continue;
70
+ this.observe(`${id}|connection:${connection.id}`, mark);
71
+ if (connection.primary) this.observePrimary(id, connection.domain, connection.id, mark);
72
+ }
73
+ return {
74
+ mark,
75
+ isCurrent: () => this.latestSync === mark
76
+ };
77
+ }
78
+ loggedOutSince(mark) {
79
+ return this.lastLogout > mark;
80
+ }
81
+ observe(scope, mark) {
82
+ this.connections.set(scope, Math.max(mark, this.connections.get(scope) ?? 0));
83
+ }
84
+ observedSince(scope, mark) {
85
+ return (this.connections.get(scope) ?? 0) > mark;
86
+ }
87
+ remove(scope) {
88
+ this.connections.delete(scope);
89
+ this.acquisitions.delete(scope);
90
+ }
91
+ depart(id, domain, connectionId, mark) {
92
+ const scope = JSON.stringify([this.primaryScope(id, domain), connectionId]);
93
+ const previous = this.departures.get(scope);
94
+ this.departures.set(scope, Math.max(mark, previous ?? 0));
95
+ return previous == null;
96
+ }
97
+ departedAt(id, domain, connectionId) {
98
+ return this.departures.get(JSON.stringify([this.primaryScope(id, domain), connectionId]));
99
+ }
100
+ observePrimary(id, domain, connectionId, mark) {
101
+ const scope = this.primaryScope(id, domain);
102
+ if ((this.primaries.get(scope)?.mark ?? 0) <= mark) this.primaries.set(scope, {
103
+ connectionId,
104
+ mark
105
+ });
106
+ }
107
+ supersedingPrimary(id, domain, connectionId, mark) {
108
+ const primary = this.primaries.get(this.primaryScope(id, domain));
109
+ return primary != null && primary.mark > mark && primary.connectionId !== connectionId ? primary.connectionId : void 0;
110
+ }
111
+ primaryScope(id, domain) {
112
+ return isSelfManagedHostIntegrationId(id) && domain ? `${id}|host:${hostFromDomain(domain) ?? domain}` : id;
113
+ }
114
+ };
115
+ //#endregion
116
+ export { CloudIntegrationObservations };
117
+
118
+ //# sourceMappingURL=cloudIntegrationObservations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudIntegrationObservations.js","names":[],"sources":["../../../../../plus/integrations/src/authentication/cloudIntegrationObservations.ts"],"sourcesContent":["import { uuid } from '@gitlens/utils/crypto.js';\nimport type { IntegrationIds } from '../constants.js';\nimport { hostFromDomain } from '../utils/domain.utils.js';\nimport { isSelfManagedHostIntegrationId } from '../utils/integration.utils.js';\nimport type { CloudIntegrationConnection, ConfiguredIntegrationDescriptor } from './models.js';\n\nexport interface CloudIntegrationSync {\n\treadonly mark: number;\n\tisCurrent(): boolean;\n}\n\ntype CloudOrder = { owner: string; mark: number };\ntype CloudLogout = CloudOrder & { departures: readonly string[] };\nexport type CloudCredentialOrigin = CloudOrder & { after?: string };\n\nexport class CloudIntegrationObservations {\n\tprivate readonly owner = uuid();\n\tprivate readonly acquisitions = new Map<string, number>();\n\t// KEEP: Request ordinals belong to one storage owner; a reopened owner records which durable logout it followed.\n\tprivate readonly inheritedLogout?: string;\n\tprivate _logout?: CloudOrder;\n\tget hasLogout(): boolean {\n\t\treturn this._logout != null;\n\t}\n\n\tsnapshotLogout(): CloudLogout | undefined {\n\t\treturn this._logout && { ...this._logout, departures: [...this.departures.keys()] };\n\t}\n\n\tconstructor(previousLogout?: CloudLogout) {\n\t\tthis._logout = previousLogout;\n\t\tif (previousLogout != null) {\n\t\t\tthis.inheritedLogout = `${previousLogout.owner}:${previousLogout.mark}`;\n\t\t\tfor (const scope of previousLogout.departures) {\n\t\t\t\tthis.departures.set(scope, 0);\n\t\t\t}\n\t\t}\n\t}\n\n\torigin(mark: number): CloudCredentialOrigin {\n\t\treturn { owner: this.owner, mark: mark, after: this.inheritedLogout };\n\t}\n\n\tallows(origin: CloudCredentialOrigin | undefined): boolean {\n\t\tconst logout = this._logout;\n\t\treturn (\n\t\t\tlogout == null ||\n\t\t\t(origin != null &&\n\t\t\t\t(origin.owner === logout.owner\n\t\t\t\t\t? origin.mark > logout.mark\n\t\t\t\t\t: origin.after === `${logout.owner}:${logout.mark}`))\n\t\t);\n\t}\n\n\tpublished(scope: string, mark: number): void {\n\t\tthis.acquisitions.set(scope, mark);\n\t}\n\n\tacquiredAfter(scope: string, mark: number): boolean {\n\t\treturn (this.acquisitions.get(scope) ?? 0) > mark;\n\t}\n\n\tprivate latestSync = 0;\n\tprivate _lastLogout = 0;\n\tget lastLogout(): number {\n\t\treturn this._lastLogout;\n\t}\n\tprivate readonly connections = new Map<string, number>();\n\tprivate readonly departures = new Map<string, number>();\n\tprivate readonly primaries = new Map<string, { connectionId: string; mark: number }>();\n\n\tacceptLogout(\n\t\trequest: number,\n\t\tmark: number,\n\t\tconnections: readonly ConfiguredIntegrationDescriptor[],\n\t): CloudIntegrationSync | undefined {\n\t\tif (this._logout?.owner === this.owner && request <= this._logout.mark) return undefined;\n\n\t\tfor (const connection of connections) {\n\t\t\tthis.depart(connection.integrationId, connection.domain, connection.id, mark);\n\t\t}\n\t\tthis._logout = { owner: this.owner, mark: request };\n\t\tthis._lastLogout = mark;\n\t\tthis.latestSync = Math.max(this.latestSync, request);\n\t\treturn { mark: mark, isCurrent: () => this.latestSync === request };\n\t}\n\n\taccept(\n\t\tmark: number,\n\t\tconnections: ReadonlyMap<IntegrationIds, readonly CloudIntegrationConnection[]>,\n\t): CloudIntegrationSync | undefined {\n\t\tif (mark <= this.latestSync) return undefined;\n\n\t\tthis.latestSync = mark;\n\t\tfor (const [id, entries] of connections) {\n\t\t\tfor (const connection of entries) {\n\t\t\t\tif (connection.id == null) continue;\n\n\t\t\t\tthis.observe(`${id}|connection:${connection.id}`, mark);\n\t\t\t\tif (connection.primary) {\n\t\t\t\t\tthis.observePrimary(id, connection.domain, connection.id, mark);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn { mark: mark, isCurrent: () => this.latestSync === mark };\n\t}\n\n\tloggedOutSince(mark: number): boolean {\n\t\treturn this.lastLogout > mark;\n\t}\n\n\tobserve(scope: string, mark: number): void {\n\t\tthis.connections.set(scope, Math.max(mark, this.connections.get(scope) ?? 0));\n\t}\n\n\tobservedSince(scope: string, mark: number): boolean {\n\t\treturn (this.connections.get(scope) ?? 0) > mark;\n\t}\n\n\tremove(scope: string): void {\n\t\tthis.connections.delete(scope);\n\t\tthis.acquisitions.delete(scope);\n\t}\n\n\tdepart(id: IntegrationIds, domain: string | undefined, connectionId: string, mark: number): boolean {\n\t\tconst scope = JSON.stringify([this.primaryScope(id, domain), connectionId]);\n\t\tconst previous = this.departures.get(scope);\n\t\tthis.departures.set(scope, Math.max(mark, previous ?? 0));\n\t\treturn previous == null;\n\t}\n\n\tdepartedAt(id: IntegrationIds, domain: string, connectionId: string): number | undefined {\n\t\treturn this.departures.get(JSON.stringify([this.primaryScope(id, domain), connectionId]));\n\t}\n\n\tobservePrimary(id: IntegrationIds, domain: string | undefined, connectionId: string, mark: number): void {\n\t\tconst scope = this.primaryScope(id, domain);\n\t\tif ((this.primaries.get(scope)?.mark ?? 0) <= mark) {\n\t\t\tthis.primaries.set(scope, { connectionId: connectionId, mark: mark });\n\t\t}\n\t}\n\n\tsupersedingPrimary(\n\t\tid: IntegrationIds,\n\t\tdomain: string | undefined,\n\t\tconnectionId: string,\n\t\tmark: number,\n\t): string | undefined {\n\t\tconst primary = this.primaries.get(this.primaryScope(id, domain));\n\t\treturn primary != null && primary.mark > mark && primary.connectionId !== connectionId\n\t\t\t? primary.connectionId\n\t\t\t: undefined;\n\t}\n\n\tprivate primaryScope(id: IntegrationIds, domain?: string): string {\n\t\treturn isSelfManagedHostIntegrationId(id) && domain ? `${id}|host:${hostFromDomain(domain) ?? domain}` : id;\n\t}\n}\n"],"mappings":";;;;AAeA,IAAa,+BAAb,MAA0C;CACzC,QAAyB,KAAK;CAC9B,+BAAgC,IAAI,IAAoB;CAExD;CACA;CACA,IAAI,YAAqB;EACxB,OAAO,KAAK,WAAW;CACxB;CAEA,iBAA0C;EACzC,OAAO,KAAK,WAAW;GAAE,GAAG,KAAK;GAAS,YAAY,CAAC,GAAG,KAAK,WAAW,KAAK,CAAC;EAAE;CACnF;CAEA,YAAY,gBAA8B;EACzC,KAAK,UAAU;EACf,IAAI,kBAAkB,MAAM;GAC3B,KAAK,kBAAkB,GAAG,eAAe,MAAM,GAAG,eAAe;GACjE,KAAK,MAAM,SAAS,eAAe,YAClC,KAAK,WAAW,IAAI,OAAO,CAAC;EAE9B;CACD;CAEA,OAAO,MAAqC;EAC3C,OAAO;GAAE,OAAO,KAAK;GAAa;GAAM,OAAO,KAAK;EAAgB;CACrE;CAEA,OAAO,QAAoD;EAC1D,MAAM,SAAS,KAAK;EACpB,OACC,UAAU,QACT,UAAU,SACT,OAAO,UAAU,OAAO,QACtB,OAAO,OAAO,OAAO,OACrB,OAAO,UAAU,GAAG,OAAO,MAAM,GAAG,OAAO;CAEjD;CAEA,UAAU,OAAe,MAAo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,QAAQ,KAAK,YAAY,IAAI,KAAK,KAAK,KAAK;CAC7C;CAEA,OAAO,OAAqB;EAC3B,KAAK,YAAY,OAAO,KAAK;EAC7B,KAAK,aAAa,OAAO,KAAK;CAC/B;CAEA,OAAO,IAAoB,QAA4B,cAAsB,MAAuB;EACnG,MAAM,QAAQ,KAAK,UAAU,CAAC,KAAK,aAAa,IAAI,MAAM,GAAG,YAAY,CAAC;EAC1E,MAAM,WAAW,KAAK,WAAW,IAAI,KAAK;EAC1C,KAAK,WAAW,IAAI,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC,CAAC;EACxD,OAAO,YAAY;CACpB;CAEA,WAAW,IAAoB,QAAgB,cAA0C;EACxF,OAAO,KAAK,WAAW,IAAI,KAAK,UAAU,CAAC,KAAK,aAAa,IAAI,MAAM,GAAG,YAAY,CAAC,CAAC;CACzF;CAEA,eAAe,IAAoB,QAA4B,cAAsB,MAAoB;EACxG,MAAM,QAAQ,KAAK,aAAa,IAAI,MAAM;EAC1C,KAAK,KAAK,UAAU,IAAI,KAAK,CAAC,EAAE,QAAQ,MAAM,MAC7C,KAAK,UAAU,IAAI,OAAO;GAAgB;GAAoB;EAAK,CAAC;CAEtE;CAEA,mBACC,IACA,QACA,cACA,MACqB;EACrB,MAAM,UAAU,KAAK,UAAU,IAAI,KAAK,aAAa,IAAI,MAAM,CAAC;EAChE,OAAO,WAAW,QAAQ,QAAQ,OAAO,QAAQ,QAAQ,iBAAiB,eACvE,QAAQ,eACR,KAAA;CACJ;CAEA,aAAqB,IAAoB,QAAyB;EACjE,OAAO,+BAA+B,EAAE,KAAK,SAAS,GAAG,GAAG,QAAQ,eAAe,MAAM,KAAK,WAAW;CAC1G;AACD"}
@@ -1,7 +1,8 @@
1
1
  import { Disposable } from "../../../utils/disposable.js";
2
2
  import { Event } from "../../../utils/event.js";
3
- import { ConfiguredIntegrationDescriptor, ConnectionResource, ProviderAuthenticationSession } from "./models.js";
3
+ import { CloudIntegrationConnection, ConfiguredIntegrationDescriptor, ConnectionResource, ProviderAuthenticationSession } from "./models.js";
4
4
  import { IntegrationIds } from "../constants.js";
5
+ import { CloudIntegrationSync } from "./cloudIntegrationObservations.js";
5
6
  import { IntegrationAuthenticationSessionDescriptor } from "./integrationAuthenticationProvider.js";
6
7
  import { IntegrationServiceContext } from "../context.js";
7
8
  //#region ../plus/integrations/src/authentication/configuredIntegrationService.d.ts
@@ -14,30 +15,23 @@ type IntegrationSessionChangeEvent = {
14
15
  readonly session: ProviderAuthenticationSession;
15
16
  readonly previousDomain?: string;
16
17
  };
18
+ type CloudLogoutConnection = ConfiguredIntegrationDescriptor & {
19
+ retained: boolean;
20
+ };
17
21
  export declare class ConfiguredIntegrationService implements Disposable {
18
22
  private readonly ctx;
19
23
  private readonly _onDidChange;
20
24
  private readonly _onWillChangeSession;
21
25
  private readonly _onWillRemoveSessions;
22
- private storeConfiguredQueue;
23
- /**
24
- * One provider's secret and descriptor mutations run one at a time, so a sign-out never interleaves with a
25
- * token being stored: storing writes the secret and then registers its descriptor, and a delete in between would
26
- * miss a connection it cannot see yet, or be undone by the pending write (#5948).
27
- */
28
- private readonly _locks;
29
- /** Monotonic across providers; see {@link getSignOutMark}. */
30
- private _signOutEpoch;
31
- /** The latest retirement of pending stores per provider, self-managed host, or connection. */
32
- private readonly _signOuts;
33
- private readonly _storedWriteRetirements;
26
+ private readonly _acquisitions;
27
+ private readonly state;
34
28
  private _disposed;
35
29
  get onDidChange(): Event<ConfiguredIntegrationsChangeEvent>;
30
+ get onCloudLogout(): Event<readonly CloudLogoutConnection[]>;
36
31
  get onWillChangeSession(): Event<IntegrationSessionChangeEvent>;
37
32
  get onWillRemoveSessions(): typeof this._onWillRemoveSessions.event;
38
33
  constructor(ctx: IntegrationServiceContext);
39
34
  dispose(): void;
40
- private _configured?;
41
35
  private get configured();
42
36
  getConfigured(id?: IntegrationIds, options?: {
43
37
  cloud?: boolean;
@@ -47,17 +41,40 @@ export declare class ConfiguredIntegrationService implements Disposable {
47
41
  private addOrUpdateConfigured;
48
42
  private removeConfigured;
49
43
  private withLock;
44
+ serializesCredentialAcquisition(id: IntegrationIds): boolean;
45
+ /**
46
+ * KEEP: not reentrant. A `connectionId` acquisition waits for that connection's and every earlier unscoped one;
47
+ * an unscoped acquisition waits for every earlier acquisition of `id`.
48
+ */
49
+ withCredentialAcquisition<T>(id: IntegrationIds, connectionId: string | undefined, fn: () => Promise<T>): Promise<T>;
50
50
  /**
51
51
  * Taken before a token is read or fetched and handed to {@link storeSession}. A later sign-out or a recovery
52
52
  * that replaces the credential invalidates the pending store.
53
53
  */
54
54
  getSignOutMark(): number;
55
55
  private retirePendingStores;
56
+ beginCloudSync(): number;
57
+ get lastCloudLogout(): number;
58
+ get hasCloudLogout(): boolean;
59
+ retireCloudAccount(mark: number): Promise<CloudIntegrationSync | undefined>;
60
+ private persistCloudLogout;
61
+ private clearDepartedCloudCredentials;
62
+ getCloudDeparture(id: IntegrationIds, session: ProviderAuthenticationSession): number | undefined;
63
+ confirmHostCloudSession(id: IntegrationIds, session: ProviderAuthenticationSession, logout: number): Promise<boolean>;
64
+ acceptCloudSync(mark: number, connections: ReadonlyMap<IntegrationIds, readonly CloudIntegrationConnection[]>): Promise<CloudIntegrationSync | undefined>;
65
+ supersedingPrimary(id: IntegrationIds, session: ProviderAuthenticationSession, mark: number): string | undefined;
66
+ hasNewCloudConnection(id: IntegrationIds, domain: string | undefined, mark: number): boolean;
67
+ dispatchHostListRetirement(id: IntegrationIds, domain: string, sync: CloudIntegrationSync, retire: () => Promise<void>): Promise<boolean>;
56
68
  getStoredWriteMark(): number;
57
- isStoredWriteRetiredSince(id: IntegrationIds, session: Pick<ProviderAuthenticationSession, 'id' | 'domain'>, mark: number): boolean;
69
+ isStoredWriteRetiredSince(id: IntegrationIds, session: Pick<ProviderAuthenticationSession, 'id' | 'domain' | 'cloud'>, mark: number): boolean;
70
+ captureConfiguredConnection(id: IntegrationIds, connectionId: string): Promise<(() => boolean) | undefined>;
71
+ private duringRemoval;
72
+ captureStoredRelationshipCurrency(id: IntegrationIds, session: ProviderAuthenticationSession): Promise<(() => boolean) | undefined>;
58
73
  private retireStoredWrites;
59
74
  private getHostScope;
60
- isSessionRetiredSince(id: IntegrationIds, session: Pick<ProviderAuthenticationSession, 'id' | 'domain'>, mark: number): boolean;
75
+ isSessionRetiredSince(id: IntegrationIds, session: Pick<ProviderAuthenticationSession, 'id' | 'domain'> & {
76
+ cloud?: boolean;
77
+ }, mark: number, acquisitionMark?: number): boolean;
61
78
  private hasRetirement;
62
79
  /**
63
80
  * Stores the session's secret and descriptor together. A pending store can be invalidated by a sign-out or a
@@ -65,10 +82,15 @@ export declare class ConfiguredIntegrationService implements Disposable {
65
82
  */
66
83
  storeSession(id: IntegrationIds, session: ProviderAuthenticationSession, options?: {
67
84
  signOutMark?: number;
85
+ acquisitionMark?: number;
68
86
  resource?: ConnectionResource;
69
87
  expectedStoredAccessToken?: string;
88
+ primaryResponse?: 'named' | 'legacy';
89
+ sync?: CloudIntegrationSync;
70
90
  }): Promise<boolean>;
71
91
  peekStoredSession(id: IntegrationIds, connectionId: string, cloud: boolean, domain: string): Promise<ProviderAuthenticationSession | undefined>;
92
+ private peekSecret;
93
+ private isRetiredSecret;
72
94
  getStoredSession(id: IntegrationIds, descriptor: IntegrationAuthenticationSessionDescriptor): Promise<ProviderAuthenticationSession | undefined>;
73
95
  /**
74
96
  * Deletes one connection's stored session. `signOut` is for a delete that signs the integration out (a forced new
@@ -79,16 +101,11 @@ export declare class ConfiguredIntegrationService implements Disposable {
79
101
  preserveConfigured?: boolean;
80
102
  signOut?: boolean;
81
103
  signOutMark?: number;
104
+ unobservedSince?: number;
105
+ sync?: CloudIntegrationSync;
82
106
  }): Promise<boolean>;
83
107
  /** Signs out of every stored session of the provider, or of one self-managed host when `domain` is given. */
84
- deleteAllStoredSessions(id: IntegrationIds, cloud?: boolean, domain?: string): Promise<void>;
85
- /**
86
- * Reclaims all stored configuration + secrets for the given (typically retired) integration ids.
87
- * Used to clean up state left behind when an id is removed from the model — e.g. the local
88
- * self-managed `github-enterprise`/`gitlab-self-hosted` ids dropped when integrations went cloud-only.
89
- * Domains are read from the stored config (secrets are keyed by domain); ids with no stored config
90
- * are a no-op.
91
- */
108
+ deleteAllStoredSessions(id: IntegrationIds, cloud?: boolean, domain?: string, sync?: CloudIntegrationSync): Promise<boolean>;
92
109
  purgeStoredConfiguration(ids: readonly string[]): Promise<void>;
93
110
  private deleteSecrets;
94
111
  private deleteAllSecrets;
@@ -145,7 +162,10 @@ export declare class ConfiguredIntegrationService implements Disposable {
145
162
  * Marks the given connection as the primary/default for the provider and clears the flag on its
146
163
  * siblings. Persists immediately instead of relying on a session re-store to carry the primary flag.
147
164
  */
148
- setPrimaryConnection(id: IntegrationIds, connectionId: string): Promise<void>;
165
+ setPrimaryConnection(id: IntegrationIds, connectionId: string, list?: {
166
+ sync: CloudIntegrationSync;
167
+ domain?: string;
168
+ }): Promise<void>;
149
169
  private setPrimaryConnectionCore;
150
170
  /**
151
171
  * Removes a single connection (its secret + configured descriptor). If it was the primary and other