@gitkraken/core-gitlens 0.46.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -1
- package/dist/git-cli/providers/config.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js.map +1 -1
- package/dist/git-cli/providers/staging.js +1 -1
- package/dist/ipc/discovery.js +1 -1
- package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
- package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
- package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
- package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.d.ts +31 -0
- package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.js +166 -0
- package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.js.map +1 -0
- package/dist/plus/git-github/api/github.d.ts +7 -4
- package/dist/plus/git-github/api/github.js +44 -14
- package/dist/plus/git-github/api/github.js.map +1 -1
- package/dist/plus/git-github/api/issueWrites.d.ts +1 -0
- package/dist/plus/git-github/api/issueWrites.js +5 -5
- package/dist/plus/git-github/api/issueWrites.js.map +1 -1
- package/dist/plus/git-github/api/pullRequestWrites.d.ts +7 -3
- package/dist/plus/git-github/api/pullRequestWrites.js +120 -67
- package/dist/plus/git-github/api/pullRequestWrites.js.map +1 -1
- package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +4 -4
- package/dist/plus/integrations/authentication/configuredIntegrationService.js +14 -14
- package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js +3 -3
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
- package/dist/plus/integrations/context.d.ts +4 -4
- package/dist/plus/integrations/index.d.ts +8 -4
- package/dist/plus/integrations/index.js +2 -1
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +9 -2
- package/dist/plus/integrations/integrationService.js +95 -31
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +16 -4
- package/dist/plus/integrations/models/gitHostIntegration.js +7 -4
- package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
- package/dist/plus/integrations/models/integration.d.ts +2 -1
- package/dist/plus/integrations/models/integration.js +11 -4
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/models/issueTrackerWrites.d.ts +128 -0
- package/dist/plus/integrations/models/issueTrackerWrites.js +0 -0
- package/dist/plus/integrations/models/publicIntegration.d.ts +5 -0
- package/dist/plus/integrations/models/publicIntegration.js.map +1 -1
- package/dist/plus/integrations/providers/azure/azure.js +1 -1
- package/dist/plus/integrations/providers/github.d.ts +19 -6
- package/dist/plus/integrations/providers/github.js +126 -53
- package/dist/plus/integrations/providers/github.js.map +1 -1
- package/dist/plus/integrations/providers/issueSorts.d.ts +1 -0
- package/dist/plus/integrations/providers/jira.js +1 -1
- package/dist/plus/integrations/providers/jiraIssueByKey.d.ts +2 -0
- package/dist/plus/integrations/providers/jiraIssueByKey.js +1 -1
- package/dist/plus/integrations/providers/jiraIssueByKey.js.map +1 -1
- package/dist/plus/integrations/providers/jiraIssueWriteErrors.d.ts +10 -0
- package/dist/plus/integrations/providers/jiraIssueWriteErrors.js +68 -0
- package/dist/plus/integrations/providers/jiraIssueWriteErrors.js.map +1 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.d.ts +40 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.js +397 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.js.map +1 -0
- package/dist/plus/integrations/providers/providersApi.d.ts +4 -1
- package/dist/plus/integrations/providers/providersApi.js +21 -10
- package/dist/plus/integrations/providers/providersApi.js.map +1 -1
- package/dist/plus/integrations/reads/drains.d.ts +1 -0
- package/dist/plus/integrations/utils/integration.utils.d.ts +1 -0
- package/dist/plus/integrations/utils/integration.utils.js +7 -1
- package/dist/plus/integrations/utils/integration.utils.js.map +1 -1
- package/dist/utils/env/node/exec.js +2 -2
- package/docs/integrations.md +80 -8
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pullRequestWrites.js","names":[],"sources":["../../../../../plus/git-github/src/api/pullRequestWrites.ts"],"sourcesContent":["import { GraphqlResponseError } from '@octokit/graphql';\nimport type { RequestParameters } from '@octokit/types';\nimport { AuthenticationError, AuthenticationErrorReason, RequestNotFoundError } from '@gitlens/git/errors.js';\nimport type { PullRequestMergeMethod, PullRequestMergeQueueActionResult } from '@gitlens/git/models/pullRequest.js';\nimport { issueWriteFailure } from './issueWrites.js';\n\ntype MergeMethod = `${PullRequestMergeMethod}`;\nexport type GitHubPullRequestCreateTarget = { owner: string; repo: string };\n\nexport type GitHubPullRequestWriteTarget = GitHubPullRequestCreateTarget & { number: number; expectedNodeId: string };\nexport type GitHubPullRequestWrite =\n\t| (GitHubPullRequestCreateTarget & {\n\t\t\taction: 'create';\n\t\t\ttitle: string;\n\t\t\tbody?: string;\n\t\t\theadRef: string;\n\t\t\tbaseRef: string;\n\t\t\texpectedRepositoryId?: string;\n\t })\n\t| (GitHubPullRequestWriteTarget &\n\t\t\t(\n\t\t\t\t| { action: 'edit'; title?: string; body?: string }\n\t\t\t\t| { action: 'set-state'; state: 'open' | 'closed' }\n\t\t\t\t| ({ expectedHeadSha: string; expectedBaseRef: string } & (\n\t\t\t\t\t\t| { action: 'merge'; mergeMethod: MergeMethod }\n\t\t\t\t\t\t| { action: 'enqueue' }\n\t\t\t\t ))\n\t\t\t));\n\nexport type PullRequestWriteFailure = {\n\tok: false;\n\treason:\n\t\t| 'unsupported'\n\t\t| 'no-connection'\n\t\t| 'forbidden'\n\t\t| 'not-found'\n\t\t| 'invalid-input'\n\t\t| 'rate-limit'\n\t\t| 'blocked'\n\t\t| 'head-changed'\n\t\t| 'base-changed'\n\t\t| 'unknown'\n\t\t| 'outcome-unknown';\n};\n\nexport type PullRequestWriteSnapshot = {\n\towner: string;\n\trepo: string;\n\tnumber: number;\n\tnodeId: string;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'open' | 'closed' | 'merged';\n\tclosedAt?: string;\n\tupdatedAt?: string;\n\theadSha: string;\n\tbaseRef: string;\n};\n\nexport type PullRequestCreateCapabilityResult =\n\t| { ok: true; repositoryId: string; canCreate: boolean | undefined }\n\t| PullRequestWriteFailure;\n\ntype MergeCapability =\n\t| { kind: 'direct'; methods: MergeMethod[]; defaultMethod?: MergeMethod }\n\t| { kind: 'queue' }\n\t| { kind: 'unavailable'; reason: PullRequestWriteFailure['reason'] };\n\nexport type PullRequestWriteTargetResult =\n\t| {\n\t\t\tok: true;\n\t\t\tpullRequest: PullRequestWriteSnapshot;\n\t\t\tcapabilities: { edit: boolean; close: boolean; reopen: boolean; merge: MergeCapability };\n\t }\n\t| PullRequestWriteFailure;\n\nexport type PullRequestWriteResult =\n\t| {\n\t\t\tok: true;\n\t\t\tstatus: 'created' | 'updated' | 'closed' | 'reopened' | 'merged' | 'queued';\n\t\t\tpullRequest: PullRequestWriteSnapshot;\n\t }\n\t| PullRequestWriteFailure;\n\ntype RepositoryIdentity = {\n\tid: string;\n\towner: { login: string };\n\tname: string;\n};\n\ntype RepositoryNode = RepositoryIdentity & {\n\tisArchived: boolean;\n\tisDisabled: boolean;\n\tisLocked: boolean;\n\tviewerPermission: 'ADMIN' | 'MAINTAIN' | 'WRITE' | 'MODERATE' | 'TRIAGE' | 'READ' | null;\n};\n\ntype PullRequestNode = {\n\tid: string;\n\tnumber: number;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'OPEN' | 'CLOSED' | 'MERGED';\n\tclosedAt: string | null;\n\tmergedAt: string | null;\n\tupdatedAt: string;\n\theadRefOid: string;\n\tbaseRefName: string;\n\trepository: RepositoryIdentity;\n};\n\ntype WriteNode = PullRequestNode & {\n\t__typename: 'PullRequest';\n\tviewerCanUpdate: boolean;\n\tviewerCanClose: boolean;\n\tviewerCanReopen: boolean;\n\tisDraft: boolean;\n\tisInMergeQueue: boolean;\n\tisMergeQueueEnabled: boolean;\n\tstack: { id: string } | null;\n\tbaseRef: { id: string } | null;\n};\n\ntype MergeRepository = RepositoryNode & {\n\tmergeCommitAllowed: boolean;\n\tsquashMergeAllowed: boolean;\n\trebaseMergeAllowed: boolean;\n\tviewerDefaultMergeMethod: string;\n};\n\ntype ResolvedPullRequest = { ok: true; node: WriteNode; repository: MergeRepository };\ntype GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;\ntype BranchRule = {\n\ttype: string;\n\tparameters: { allowedMergeMethods?: readonly Uppercase<MergeMethod>[] | null } | null;\n};\n\nconst repositoryIdentity = 'id owner { login } name';\nconst repositoryFields = `${repositoryIdentity} isArchived isDisabled isLocked viewerPermission`;\nconst pullRequestFields = `\n\tid number url title body state closedAt mergedAt updatedAt headRefOid baseRefName\n\trepository { ${repositoryIdentity} }\n`;\nconst mergeMethods: readonly MergeMethod[] = ['merge', 'squash', 'rebase'];\n\nfunction isValidRepository({ owner, repo }: GitHubPullRequestCreateTarget): boolean {\n\treturn (\n\t\ttypeof owner === 'string' &&\n\t\t/^[a-z\\d_-]+$/i.test(owner) &&\n\t\ttypeof repo === 'string' &&\n\t\t/^[a-z\\d._-]+$/i.test(repo) &&\n\t\trepo !== '.' &&\n\t\trepo !== '..'\n\t);\n}\n\nfunction isValidTarget(input: GitHubPullRequestWriteTarget): boolean {\n\treturn (\n\t\tisValidRepository(input) &&\n\t\tNumber.isInteger(input.number) &&\n\t\tinput.number >= 1 &&\n\t\tinput.number <= 2147483647 &&\n\t\ttypeof input.expectedNodeId === 'string' &&\n\t\tinput.expectedNodeId.trim().length > 0\n\t);\n}\n\nfunction isBranchName(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === 'string' &&\n\t\tvalue.length > 0 &&\n\t\tvalue.trim() === value &&\n\t\t!value.includes(':') &&\n\t\t!value.startsWith('refs/') &&\n\t\t!value.startsWith('-')\n\t);\n}\n\nfunction isTitle(value: unknown): value is string {\n\treturn typeof value === 'string' && value.trim().length > 0;\n}\n\nfunction isValidWrite(input: GitHubPullRequestWrite): boolean {\n\tif (input.action === 'create') {\n\t\treturn (\n\t\t\tisValidRepository(input) &&\n\t\t\tisTitle(input.title) &&\n\t\t\t(input.body === undefined || typeof input.body === 'string') &&\n\t\t\t(input.expectedRepositoryId === undefined ||\n\t\t\t\t(typeof input.expectedRepositoryId === 'string' && input.expectedRepositoryId.trim().length > 0)) &&\n\t\t\tisBranchName(input.headRef) &&\n\t\t\tisBranchName(input.baseRef) &&\n\t\t\tinput.headRef !== input.baseRef\n\t\t);\n\t}\n\n\tif (!isValidTarget(input)) return false;\n\n\tswitch (input.action) {\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(input.title !== undefined || input.body !== undefined) &&\n\t\t\t\t(input.title === undefined || isTitle(input.title)) &&\n\t\t\t\t(input.body === undefined || typeof input.body === 'string')\n\t\t\t);\n\t\tcase 'set-state':\n\t\t\treturn input.state === 'open' || input.state === 'closed';\n\t\tcase 'merge':\n\t\tcase 'enqueue':\n\t\t\treturn (\n\t\t\t\t(input.action === 'enqueue' || mergeMethods.includes(input.mergeMethod)) &&\n\t\t\t\tisBranchName(input.expectedBaseRef) &&\n\t\t\t\ttypeof input.expectedHeadSha === 'string' &&\n\t\t\t\t/^[a-f\\d]{40}$/i.test(input.expectedHeadSha)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nexport function pullRequestWriteFailure(ex: unknown, phase?: 'write' | 'merge' | 'enqueue'): PullRequestWriteFailure {\n\tif (ex instanceof RequestNotFoundError) return { ok: false, reason: 'not-found' };\n\tif (ex instanceof AuthenticationError) {\n\t\tif (ex.reason === AuthenticationErrorReason.Forbidden) return { ok: false, reason: 'forbidden' };\n\t\treturn { ok: false, reason: 'no-connection' };\n\t}\n\n\tconst failure = issueWriteFailure(ex);\n\tif (failure.reason === 'rate-limit') return failure;\n\n\tif (phase === 'merge' || phase === 'enqueue') {\n\t\tconst error = ex instanceof GraphqlResponseError ? ex.errors?.[0] : undefined;\n\t\tif (error?.type === 'UNPROCESSABLE') {\n\t\t\tif (/\\b(?:expected head oid|head sha) does not match\\b/i.test(error.message)) {\n\t\t\t\treturn { ok: false, reason: 'head-changed' };\n\t\t\t}\n\n\t\t\treturn { ok: false, reason: 'blocked' };\n\t\t}\n\t}\n\n\treturn phase != null && failure.reason === 'unknown' ? { ok: false, reason: 'outcome-unknown' } : failure;\n}\n\nfunction hasWritePermission(repository: RepositoryNode): boolean | undefined {\n\tconst { viewerPermission } = repository;\n\treturn viewerPermission == null\n\t\t? undefined\n\t\t: viewerPermission === 'ADMIN' || viewerPermission === 'MAINTAIN' || viewerPermission === 'WRITE';\n}\n\nfunction isRepositoryWritable(repository: RepositoryNode): boolean {\n\treturn !repository.isArchived && !repository.isDisabled && !repository.isLocked;\n}\n\nfunction sameRepository(a: GitHubPullRequestCreateTarget, b: RepositoryIdentity): boolean {\n\treturn a.owner.toLowerCase() === b.owner.login.toLowerCase() && a.repo.toLowerCase() === b.name.toLowerCase();\n}\n\nfunction toSnapshot(node: PullRequestNode): PullRequestWriteSnapshot {\n\tconst closedAt = node.state === 'MERGED' ? (node.mergedAt ?? node.closedAt) : node.closedAt;\n\treturn {\n\t\towner: node.repository.owner.login,\n\t\trepo: node.repository.name,\n\t\tnumber: node.number,\n\t\tnodeId: node.id,\n\t\turl: node.url,\n\t\ttitle: node.title,\n\t\tbody: node.body,\n\t\tstate: node.state === 'OPEN' ? 'open' : node.state === 'CLOSED' ? 'closed' : 'merged',\n\t\t...(node.state !== 'OPEN' && typeof closedAt === 'string' ? { closedAt: closedAt } : {}),\n\t\t...(typeof node.updatedAt === 'string' ? { updatedAt: node.updatedAt } : {}),\n\t\theadSha: node.headRefOid,\n\t\tbaseRef: node.baseRefName,\n\t};\n}\n\nasync function resolveNode(\n\tinput: GitHubPullRequestWriteTarget,\n\tgraphql: GraphqlRequest,\n): Promise<ResolvedPullRequest | PullRequestWriteFailure> {\n\tconst { owner, repo, expectedNodeId, number } = input;\n\tconst result = await graphql<{ repository: MergeRepository | null; node: WriteNode | null }>(\n\t\t`query PullRequestWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!) {\n\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t${repositoryFields}\n\t\t\t\tmergeCommitAllowed squashMergeAllowed rebaseMergeAllowed viewerDefaultMergeMethod\n\t\t\t}\n\t\t\tnode(id: $expectedNodeId) {\n\t\t\t\t__typename\n\t\t\t\t... on PullRequest {\n\t\t\t\t\t${pullRequestFields}\n\t\t\t\t\tviewerCanUpdate viewerCanClose viewerCanReopen\n\t\t\t\t\tisDraft isInMergeQueue isMergeQueueEnabled\n\t\t\t\t\tstack { id }\n\t\t\t\t\tbaseRef { id }\n\t\t\t\t}\n\t\t\t}\n\t\t}`,\n\t\t{ owner: owner, repo: repo, expectedNodeId: expectedNodeId },\n\t);\n\tconst repository = result?.repository;\n\tconst node = result?.node;\n\tif (\n\t\trepository == null ||\n\t\t!sameRepository(input, repository) ||\n\t\tnode?.__typename !== 'PullRequest' ||\n\t\tnode.number !== number ||\n\t\tnode.repository.id !== repository.id\n\t) {\n\t\treturn { ok: false, reason: 'not-found' };\n\t}\n\n\treturn { ok: true, node: node, repository: repository };\n}\n\nasync function readBranchRules(\n\trefId: string,\n\tgraphql: GraphqlRequest,\n): Promise<{ rules: BranchRule[]; requiresLinearHistory: boolean } | undefined> {\n\ttype Response = {\n\t\tnode: {\n\t\t\tid: string;\n\t\t\trefUpdateRule: { requiresLinearHistory: boolean } | null;\n\t\t\trules: {\n\t\t\t\tnodes: (BranchRule | null)[] | null;\n\t\t\t\tpageInfo: { hasNextPage: boolean; endCursor: string | null };\n\t\t\t};\n\t\t} | null;\n\t};\n\tconst rules: BranchRule[] = [];\n\tconst seen = new Set<string>();\n\tlet requiresLinearHistory = false;\n\tlet cursor: string | undefined;\n\tfor (;;) {\n\t\tconst response = await graphql<Response>(\n\t\t\t`\n\t\t\t\tquery PullRequestBranchRules($id: ID!, $cursor: String) {\n\t\t\t\t\tnode(id: $id) {\n\t\t\t\t\t\t... on Ref {\n\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\trefUpdateRule {\n\t\t\t\t\t\t\t\trequiresLinearHistory\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\trules(first: 100, after: $cursor) {\n\t\t\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\t\t\ttype\n\t\t\t\t\t\t\t\t\tparameters {\n\t\t\t\t\t\t\t\t\t\t... on PullRequestParameters {\n\t\t\t\t\t\t\t\t\t\t\tallowedMergeMethods\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tpageInfo {\n\t\t\t\t\t\t\t\t\thasNextPage\n\t\t\t\t\t\t\t\t\tendCursor\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t`,\n\t\t\t{ id: refId, cursor: cursor },\n\t\t);\n\t\tconst ref = response?.node;\n\t\tconst page = ref?.rules;\n\t\tif (ref?.id !== refId || page?.nodes == null) return undefined;\n\n\t\trequiresLinearHistory ||= ref.refUpdateRule?.requiresLinearHistory === true;\n\n\t\tfor (const rule of page.nodes) {\n\t\t\tif (rule == null) return undefined;\n\n\t\t\trules.push(rule);\n\t\t}\n\n\t\tif (!page.pageInfo.hasNextPage) return { rules: rules, requiresLinearHistory: requiresLinearHistory };\n\n\t\tconst nextCursor = page.pageInfo.endCursor;\n\t\tif (nextCursor == null || seen.has(nextCursor)) return undefined;\n\n\t\tseen.add(nextCursor);\n\t\tcursor = nextCursor;\n\t}\n}\n\nasync function getMergeCapability(\n\t{ node, repository }: ResolvedPullRequest,\n\tgraphql: GraphqlRequest,\n): Promise<MergeCapability> {\n\tif (\n\t\t!isRepositoryWritable(repository) ||\n\t\tnode.state !== 'OPEN' ||\n\t\tnode.isDraft ||\n\t\tnode.isInMergeQueue ||\n\t\tnode.baseRef == null\n\t) {\n\t\treturn { kind: 'unavailable', reason: 'blocked' };\n\t}\n\n\tconst canWrite = hasWritePermission(repository);\n\tif (canWrite !== true) return { kind: 'unavailable', reason: canWrite === false ? 'forbidden' : 'unknown' };\n\tif (node.stack != null) return { kind: 'unavailable', reason: 'unsupported' };\n\tif (node.isMergeQueueEnabled) return { kind: 'queue' };\n\n\ttry {\n\t\tconst branch = await readBranchRules(node.baseRef.id, graphql);\n\t\tif (branch == null) return { kind: 'unavailable', reason: 'unknown' };\n\n\t\tconst { rules, requiresLinearHistory } = branch;\n\t\tif (rules.some(rule => rule.type === 'MERGE_QUEUE')) return { kind: 'queue' };\n\n\t\tconst linearHistory = requiresLinearHistory || rules.some(rule => rule.type === 'REQUIRED_LINEAR_HISTORY');\n\t\tconst methods = mergeMethods.filter(method => {\n\t\t\tconst allowed =\n\t\t\t\tmethod === 'merge'\n\t\t\t\t\t? repository.mergeCommitAllowed && !linearHistory\n\t\t\t\t\t: method === 'squash'\n\t\t\t\t\t\t? repository.squashMergeAllowed\n\t\t\t\t\t\t: repository.rebaseMergeAllowed;\n\t\t\treturn (\n\t\t\t\tallowed &&\n\t\t\t\trules.every(rule => {\n\t\t\t\t\tconst permitted = rule.type === 'PULL_REQUEST' ? rule.parameters?.allowedMergeMethods : undefined;\n\t\t\t\t\treturn permitted == null || permitted.some(allowedMethod => allowedMethod.toLowerCase() === method);\n\t\t\t\t})\n\t\t\t);\n\t\t});\n\t\tif (methods.length === 0) return { kind: 'unavailable', reason: 'blocked' };\n\n\t\tconst preference = repository.viewerDefaultMergeMethod.toLowerCase();\n\t\tconst defaultMethod = methods.find(method => method === preference);\n\t\treturn { kind: 'direct', methods: methods, defaultMethod: defaultMethod };\n\t} catch (ex) {\n\t\treturn { kind: 'unavailable', reason: pullRequestWriteFailure(ex).reason };\n\t}\n}\n\nexport async function resolveGitHubPullRequestWriteTarget(\n\tinput: GitHubPullRequestWriteTarget,\n\tgraphql: GraphqlRequest,\n): Promise<PullRequestWriteTargetResult> {\n\tif (!isValidTarget(input)) return { ok: false, reason: 'invalid-input' };\n\n\ttry {\n\t\tconst resolved = await resolveNode(input, graphql);\n\t\tif (!resolved.ok) return resolved;\n\n\t\tconst { node, repository } = resolved;\n\t\tconst writable = isRepositoryWritable(repository);\n\t\treturn {\n\t\t\tok: true,\n\t\t\tpullRequest: toSnapshot(node),\n\t\t\tcapabilities: {\n\t\t\t\tedit: writable && node.viewerCanUpdate,\n\t\t\t\tclose: writable && node.state === 'OPEN' && node.viewerCanClose,\n\t\t\t\treopen: writable && node.state === 'CLOSED' && node.viewerCanReopen,\n\t\t\t\tmerge: await getMergeCapability(resolved, graphql),\n\t\t\t},\n\t\t};\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex);\n\t}\n}\n\nexport async function getGitHubPullRequestCreateCapability(\n\tinput: GitHubPullRequestCreateTarget,\n\tgraphql: GraphqlRequest,\n): Promise<PullRequestCreateCapabilityResult> {\n\tif (!isValidRepository(input)) return { ok: false, reason: 'invalid-input' };\n\n\ttry {\n\t\tconst result = await graphql<{ repository: RepositoryNode | null }>(\n\t\t\t`query PullRequestCreateCapability($owner: String!, $repo: String!) {\n\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t${repositoryFields}\n\t\t\t\t}\n\t\t\t}`,\n\t\t\t{ owner: input.owner, repo: input.repo },\n\t\t);\n\t\tconst repository = result?.repository;\n\t\tif (repository == null || !sameRepository(input, repository)) return { ok: false, reason: 'not-found' };\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\trepositoryId: repository.id,\n\t\t\t// A repository role only establishes read access. GitHub checks the chosen head branch and organization\n\t\t\t// membership when the pull request is created.\n\t\t\tcanCreate: isRepositoryWritable(repository) && (repository.viewerPermission == null ? undefined : true),\n\t\t};\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex);\n\t}\n}\n\ntype WriteTransport = {\n\tgraphql: GraphqlRequest;\n\tisSessionCurrent: () => Promise<boolean>;\n\tenqueue: (nodeId: string, headSha: string) => Promise<PullRequestMergeQueueActionResult>;\n};\n\nconst mutations = {\n\tcreated: ['createPullRequest', 'CreatePullRequestInput'],\n\tupdated: ['updatePullRequest', 'UpdatePullRequestInput'],\n\tclosed: ['closePullRequest', 'ClosePullRequestInput'],\n\treopened: ['reopenPullRequest', 'ReopenPullRequestInput'],\n\tmerged: ['mergePullRequest', 'MergePullRequestInput'],\n} as const;\n\nasync function sendMutation(\n\ttransport: WriteTransport,\n\tstatus: keyof typeof mutations,\n\trepositoryId: string,\n\tvalues: Record<string, string | undefined>,\n\tprevious?: PullRequestNode,\n): Promise<PullRequestWriteResult> {\n\tif (!(await transport.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\tconst [mutation, inputType] = mutations[status];\n\ttype Payload = { change: { pullRequest: PullRequestNode | null } | null };\n\tlet node: PullRequestNode | null | undefined;\n\ttry {\n\t\tconst response = await transport.graphql<Payload>(\n\t\t\t`mutation WritePullRequest($input: ${inputType}!) {\n\t\t\t\tchange: ${mutation}(input: $input) { pullRequest { ${pullRequestFields} } }\n\t\t\t}`,\n\t\t\t{ input: values },\n\t\t);\n\t\tnode = response?.change?.pullRequest;\n\t} catch (ex) {\n\t\tif (ex instanceof GraphqlResponseError) {\n\t\t\tnode = (ex.data as Payload | undefined)?.change?.pullRequest;\n\t\t\tif (node == null && ex.errors?.some(error => error.path?.[0] === 'change' && error.path.length > 1)) {\n\t\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t\t}\n\t\t}\n\n\t\tif (node == null) return pullRequestWriteFailure(ex, status === 'merged' ? 'merge' : 'write');\n\t}\n\n\tconst expectedState =\n\t\tstatus === 'created' || status === 'reopened'\n\t\t\t? 'OPEN'\n\t\t\t: status === 'closed'\n\t\t\t\t? 'CLOSED'\n\t\t\t\t: status === 'merged'\n\t\t\t\t\t? 'MERGED'\n\t\t\t\t\t: undefined;\n\tif (\n\t\tnode?.repository?.id !== repositoryId ||\n\t\t(previous != null && (node.id !== previous.id || node.number !== previous.number)) ||\n\t\t(expectedState != null && node.state !== expectedState) ||\n\t\ttypeof node.repository.owner?.login !== 'string' ||\n\t\ttypeof node.repository.name !== 'string' ||\n\t\ttypeof node.id !== 'string' ||\n\t\t!Number.isInteger(node.number) ||\n\t\ttypeof node.url !== 'string' ||\n\t\ttypeof node.title !== 'string' ||\n\t\ttypeof node.body !== 'string' ||\n\t\ttypeof node.headRefOid !== 'string' ||\n\t\ttypeof node.baseRefName !== 'string' ||\n\t\t(node.state !== 'OPEN' && node.state !== 'CLOSED' && node.state !== 'MERGED')\n\t) {\n\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t}\n\n\treturn { ok: true, status: status, pullRequest: toSnapshot(node) };\n}\n\nasync function createPullRequest(\n\tinput: Extract<GitHubPullRequestWrite, { action: 'create' }>,\n\ttransport: WriteTransport,\n): Promise<PullRequestWriteResult> {\n\ttype CreateRepository = RepositoryNode & { base: { id: string } | null; head: { id: string } | null };\n\tconst result = await transport.graphql<{ repository: CreateRepository | null }>(\n\t\t`query PullRequestCreateTarget($owner: String!, $repo: String!, $base: String!, $head: String!) {\n\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t${repositoryFields}\n\t\t\t\tbase: ref(qualifiedName: $base) { id }\n\t\t\t\thead: ref(qualifiedName: $head) { id }\n\t\t\t}\n\t\t}`,\n\t\t{\n\t\t\towner: input.owner,\n\t\t\trepo: input.repo,\n\t\t\tbase: `refs/heads/${input.baseRef}`,\n\t\t\thead: `refs/heads/${input.headRef}`,\n\t\t},\n\t);\n\tconst repository = result?.repository;\n\tif (\n\t\trepository == null ||\n\t\t!sameRepository(input, repository) ||\n\t\t(input.expectedRepositoryId != null && input.expectedRepositoryId !== repository.id)\n\t) {\n\t\treturn { ok: false, reason: 'not-found' };\n\t}\n\n\tif (!isRepositoryWritable(repository)) return { ok: false, reason: 'blocked' };\n\tif (repository.base == null || repository.head == null) return { ok: false, reason: 'invalid-input' };\n\n\treturn sendMutation(transport, 'created', repository.id, {\n\t\trepositoryId: repository.id,\n\t\tbaseRefName: input.baseRef,\n\t\theadRefName: input.headRef,\n\t\ttitle: input.title,\n\t\tbody: input.body,\n\t});\n}\n\nasync function mergePullRequest(\n\tinput: Extract<GitHubPullRequestWrite, { action: 'merge' | 'enqueue' }>,\n\tresolved: ResolvedPullRequest,\n\ttransport: WriteTransport,\n): Promise<PullRequestWriteResult> {\n\tconst { node, repository } = resolved;\n\tif (node.headRefOid.toLowerCase() !== input.expectedHeadSha.toLowerCase()) {\n\t\treturn { ok: false, reason: 'head-changed' };\n\t}\n\n\tif (node.baseRefName !== input.expectedBaseRef) return { ok: false, reason: 'base-changed' };\n\n\tconst capability = await getMergeCapability(resolved, transport.graphql);\n\tif (capability.kind === 'unavailable') return { ok: false, reason: capability.reason };\n\n\tif (input.action === 'merge') {\n\t\tif (capability.kind !== 'direct' || !capability.methods.includes(input.mergeMethod)) {\n\t\t\treturn { ok: false, reason: 'blocked' };\n\t\t}\n\n\t\treturn sendMutation(\n\t\t\ttransport,\n\t\t\t'merged',\n\t\t\trepository.id,\n\t\t\t{ pullRequestId: node.id, expectedHeadOid: node.headRefOid, mergeMethod: input.mergeMethod.toUpperCase() },\n\t\t\tnode,\n\t\t);\n\t}\n\n\tif (capability.kind !== 'queue') return { ok: false, reason: 'blocked' };\n\tif (!(await transport.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\ttry {\n\t\tconst result = await transport.enqueue(node.id, node.headRefOid);\n\t\tif (result.status === 'queued' && result.entry != null) {\n\t\t\treturn { ok: true, status: 'queued', pullRequest: toSnapshot(node) };\n\t\t}\n\n\t\tif (result.status !== 'failed') return { ok: false, reason: 'outcome-unknown' };\n\n\t\tswitch (result.reason) {\n\t\t\tcase 'permission':\n\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\tcase 'already-queued':\n\t\t\tcase 'not-allowed':\n\t\t\t\treturn { ok: false, reason: 'blocked' };\n\t\t\tcase 'head-changed':\n\t\t\tcase 'unsupported':\n\t\t\t\treturn { ok: false, reason: result.reason };\n\t\t\tdefault:\n\t\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex, 'enqueue');\n\t}\n}\n\nexport async function writeGitHubPullRequest(\n\tinput: GitHubPullRequestWrite,\n\ttransport: WriteTransport,\n): Promise<PullRequestWriteResult> {\n\tif (!isValidWrite(input)) return { ok: false, reason: 'invalid-input' };\n\n\ttry {\n\t\tif (input.action === 'create') return await createPullRequest(input, transport);\n\n\t\tconst resolved = await resolveNode(input, transport.graphql);\n\t\tif (!resolved.ok) return resolved;\n\n\t\tconst { node, repository } = resolved;\n\t\tif (!isRepositoryWritable(repository)) return { ok: false, reason: 'blocked' };\n\t\tif (input.action === 'merge' || input.action === 'enqueue') {\n\t\t\treturn await mergePullRequest(input, resolved, transport);\n\t\t}\n\n\t\tif (input.action === 'edit') {\n\t\t\tif (!node.viewerCanUpdate) return { ok: false, reason: 'forbidden' };\n\n\t\t\treturn await sendMutation(\n\t\t\t\ttransport,\n\t\t\t\t'updated',\n\t\t\t\trepository.id,\n\t\t\t\t{ pullRequestId: node.id, title: input.title, body: input.body },\n\t\t\t\tnode,\n\t\t\t);\n\t\t}\n\n\t\tconst close = input.state === 'closed';\n\t\tif (node.state !== (close ? 'OPEN' : 'CLOSED')) return { ok: false, reason: 'blocked' };\n\t\tif (close ? !node.viewerCanClose : !node.viewerCanReopen) return { ok: false, reason: 'forbidden' };\n\n\t\treturn await sendMutation(\n\t\t\ttransport,\n\t\t\tclose ? 'closed' : 'reopened',\n\t\t\trepository.id,\n\t\t\t{ pullRequestId: node.id },\n\t\t\tnode,\n\t\t);\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex);\n\t}\n}\n"],"mappings":";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D,SAAS,IAAI;EACZ,OAAO,wBAAwB,EAAE;CAClC;AACD"}
|
|
1
|
+
{"version":3,"file":"pullRequestWrites.js","names":[],"sources":["../../../../../plus/git-github/src/api/pullRequestWrites.ts"],"sourcesContent":["import { GraphqlResponseError } from '@octokit/graphql';\nimport { AuthenticationError, AuthenticationErrorReason, RequestNotFoundError } from '@gitlens/git/errors.js';\nimport type { PullRequestMergeMethod, PullRequestMergeQueueActionResult } from '@gitlens/git/models/pullRequest.js';\nimport type {\n\tBranchPolicy,\n\tBranchRule,\n\tEnterprisePullRequestWriteOptions,\n\tGraphqlRequest,\n} from './enterprisePullRequestMergePolicy.js';\nimport { readEnterprisePullRequestMergePolicy } from './enterprisePullRequestMergePolicy.js';\nimport { isGitHubWriteUrlOnInstallation, issueWriteFailure } from './issueWrites.js';\n\ntype MergeMethod = `${PullRequestMergeMethod}`;\nexport type GitHubPullRequestCreateTarget = { owner: string; repo: string };\n\nexport type GitHubPullRequestWriteTarget = GitHubPullRequestCreateTarget & { number: number; expectedNodeId: string };\nexport type GitHubPullRequestWrite =\n\t| (GitHubPullRequestCreateTarget & {\n\t\t\taction: 'create';\n\t\t\ttitle: string;\n\t\t\tbody?: string;\n\t\t\theadRef: string;\n\t\t\tbaseRef: string;\n\t\t\texpectedRepositoryId?: string;\n\t })\n\t| (GitHubPullRequestWriteTarget &\n\t\t\t(\n\t\t\t\t| { action: 'edit'; title?: string; body?: string }\n\t\t\t\t| { action: 'set-state'; state: 'open' | 'closed' }\n\t\t\t\t| ({ expectedHeadSha: string; expectedBaseRef: string } & (\n\t\t\t\t\t\t| { action: 'merge'; mergeMethod: MergeMethod }\n\t\t\t\t\t\t| { action: 'enqueue' }\n\t\t\t\t ))\n\t\t\t));\n\nexport type PullRequestWriteFailure = {\n\tok: false;\n\treason:\n\t\t| 'unsupported'\n\t\t| 'no-connection'\n\t\t| 'forbidden'\n\t\t| 'not-found'\n\t\t| 'invalid-input'\n\t\t| 'rate-limit'\n\t\t| 'blocked'\n\t\t| 'head-changed'\n\t\t| 'base-changed'\n\t\t| 'unknown'\n\t\t| 'outcome-unknown';\n};\n\nexport type PullRequestWriteSnapshot = {\n\t/** The installation origin for GitHub Enterprise Server pull requests. */\n\tdomain?: string;\n\towner: string;\n\trepo: string;\n\tnumber: number;\n\tnodeId: string;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'open' | 'closed' | 'merged';\n\tclosedAt?: string;\n\tupdatedAt?: string;\n\theadSha: string;\n\tbaseRef: string;\n};\n\nexport type PullRequestCreateCapabilityResult =\n\t| { ok: true; repositoryId: string; canCreate: boolean | undefined }\n\t| PullRequestWriteFailure;\n\ntype MergeCapability =\n\t| { kind: 'direct'; methods: MergeMethod[]; defaultMethod?: MergeMethod }\n\t| { kind: 'queue' }\n\t| { kind: 'unavailable'; reason: PullRequestWriteFailure['reason'] };\n\nexport type PullRequestWriteTargetResult =\n\t| {\n\t\t\tok: true;\n\t\t\tpullRequest: PullRequestWriteSnapshot;\n\t\t\tcapabilities: { edit: boolean; close: boolean; reopen: boolean; merge: MergeCapability };\n\t }\n\t| PullRequestWriteFailure;\n\nexport type PullRequestWriteResult =\n\t| {\n\t\t\tok: true;\n\t\t\tstatus: 'created' | 'updated' | 'closed' | 'reopened' | 'merged' | 'queued';\n\t\t\tpullRequest: PullRequestWriteSnapshot;\n\t\t\t/** The result is confirmed, but its snapshot belongs to a replaced or disconnected credential. */\n\t\t\tcredentialChanged?: true;\n\t }\n\t| PullRequestWriteFailure;\n\ntype RepositoryIdentity = {\n\tid: string;\n\towner: { login: string };\n\tname: string;\n};\n\ntype RepositoryNode = RepositoryIdentity & {\n\tisArchived: boolean;\n\tisDisabled: boolean;\n\tisLocked: boolean;\n\tviewerPermission: 'ADMIN' | 'MAINTAIN' | 'WRITE' | 'MODERATE' | 'TRIAGE' | 'READ' | null;\n};\n\ntype PullRequestNode = {\n\tid: string;\n\tnumber: number;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'OPEN' | 'CLOSED' | 'MERGED';\n\tclosedAt: string | null;\n\tmergedAt: string | null;\n\tupdatedAt: string;\n\theadRefOid: string;\n\theadRefName?: string;\n\tbaseRefName: string;\n\trepository: RepositoryIdentity;\n};\n\ntype WriteNode = PullRequestNode & {\n\t__typename: 'PullRequest';\n\tviewerCanUpdate: boolean;\n\tviewerCanClose: boolean;\n\tviewerCanReopen: boolean;\n\tisDraft: boolean;\n\tisInMergeQueue?: boolean;\n\tisMergeQueueEnabled?: boolean;\n\tstack?: { id: string } | null;\n\tbaseRef: { id: string } | null;\n};\n\ntype MergeRepository = RepositoryNode & {\n\tmergeCommitAllowed: boolean;\n\tsquashMergeAllowed: boolean;\n\trebaseMergeAllowed: boolean;\n\tviewerDefaultMergeMethod?: string;\n};\n\ntype ResolvedPullRequest = { ok: true; node: WriteNode; repository: MergeRepository };\n\nconst repositoryIdentity = 'id owner { login } name';\nconst repositoryFields = `${repositoryIdentity} isArchived isDisabled isLocked viewerPermission`;\nconst pullRequestFields = `\n\tid number url title body state closedAt mergedAt updatedAt headRefOid baseRefName\n\trepository { ${repositoryIdentity} }\n`;\nconst mergeMethods: readonly MergeMethod[] = ['merge', 'squash', 'rebase'];\n\nfunction isValidRepository({ owner, repo }: GitHubPullRequestCreateTarget): boolean {\n\treturn (\n\t\ttypeof owner === 'string' &&\n\t\t/^[a-z\\d_-]+$/i.test(owner) &&\n\t\ttypeof repo === 'string' &&\n\t\t/^[a-z\\d._-]+$/i.test(repo) &&\n\t\trepo !== '.' &&\n\t\trepo !== '..'\n\t);\n}\n\nfunction isValidTarget(input: GitHubPullRequestWriteTarget): boolean {\n\treturn (\n\t\tisValidRepository(input) &&\n\t\tNumber.isInteger(input.number) &&\n\t\tinput.number >= 1 &&\n\t\tinput.number <= 2147483647 &&\n\t\ttypeof input.expectedNodeId === 'string' &&\n\t\tinput.expectedNodeId.trim().length > 0\n\t);\n}\n\nfunction isBranchName(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === 'string' &&\n\t\tvalue.length > 0 &&\n\t\tvalue.trim() === value &&\n\t\t!value.includes(':') &&\n\t\t!value.startsWith('refs/') &&\n\t\t!value.startsWith('-')\n\t);\n}\n\nfunction isTitle(value: unknown): value is string {\n\treturn typeof value === 'string' && value.trim().length > 0;\n}\n\nfunction isValidWrite(input: GitHubPullRequestWrite): boolean {\n\tif (input.action === 'create') {\n\t\treturn (\n\t\t\tisValidRepository(input) &&\n\t\t\tisTitle(input.title) &&\n\t\t\t(input.body === undefined || typeof input.body === 'string') &&\n\t\t\t(input.expectedRepositoryId === undefined ||\n\t\t\t\t(typeof input.expectedRepositoryId === 'string' && input.expectedRepositoryId.trim().length > 0)) &&\n\t\t\tisBranchName(input.headRef) &&\n\t\t\tisBranchName(input.baseRef) &&\n\t\t\tinput.headRef !== input.baseRef\n\t\t);\n\t}\n\n\tif (!isValidTarget(input)) return false;\n\n\tswitch (input.action) {\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(input.title !== undefined || input.body !== undefined) &&\n\t\t\t\t(input.title === undefined || isTitle(input.title)) &&\n\t\t\t\t(input.body === undefined || typeof input.body === 'string')\n\t\t\t);\n\t\tcase 'set-state':\n\t\t\treturn input.state === 'open' || input.state === 'closed';\n\t\tcase 'merge':\n\t\tcase 'enqueue':\n\t\t\treturn (\n\t\t\t\t(input.action === 'enqueue' || mergeMethods.includes(input.mergeMethod)) &&\n\t\t\t\tisBranchName(input.expectedBaseRef) &&\n\t\t\t\ttypeof input.expectedHeadSha === 'string' &&\n\t\t\t\t/^[a-f\\d]{40}$/i.test(input.expectedHeadSha)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nexport function pullRequestWriteFailure(ex: unknown, phase?: 'write' | 'merge' | 'enqueue'): PullRequestWriteFailure {\n\tif (ex instanceof RequestNotFoundError) return { ok: false, reason: 'not-found' };\n\tif (ex instanceof AuthenticationError) {\n\t\tif (ex.reason === AuthenticationErrorReason.Forbidden) return { ok: false, reason: 'forbidden' };\n\t\treturn { ok: false, reason: 'no-connection' };\n\t}\n\n\tconst failure = issueWriteFailure(ex);\n\tif (failure.reason === 'rate-limit') return failure;\n\n\tif (phase === 'merge' || phase === 'enqueue') {\n\t\tconst error = ex instanceof GraphqlResponseError ? ex.errors?.[0] : undefined;\n\t\tif (error?.type === 'UNPROCESSABLE') {\n\t\t\tif (/\\b(?:expected head oid|head sha) does not match\\b/i.test(error.message)) {\n\t\t\t\treturn { ok: false, reason: 'head-changed' };\n\t\t\t}\n\n\t\t\treturn { ok: false, reason: 'blocked' };\n\t\t}\n\t}\n\n\treturn phase != null && failure.reason === 'unknown' ? { ok: false, reason: 'outcome-unknown' } : failure;\n}\n\nfunction hasWritePermission(repository: RepositoryNode): boolean | undefined {\n\tconst { viewerPermission } = repository;\n\treturn viewerPermission == null\n\t\t? undefined\n\t\t: viewerPermission === 'ADMIN' || viewerPermission === 'MAINTAIN' || viewerPermission === 'WRITE';\n}\n\nfunction isRepositoryWritable(repository: RepositoryNode): boolean {\n\treturn !repository.isArchived && !repository.isDisabled && !repository.isLocked;\n}\n\nfunction sameRepository(a: GitHubPullRequestCreateTarget, b: RepositoryIdentity): boolean {\n\treturn a.owner.toLowerCase() === b.owner.login.toLowerCase() && a.repo.toLowerCase() === b.name.toLowerCase();\n}\n\nfunction toSnapshot(node: PullRequestNode, origin?: string): PullRequestWriteSnapshot {\n\tconst closedAt = node.state === 'MERGED' ? (node.mergedAt ?? node.closedAt) : node.closedAt;\n\treturn {\n\t\towner: node.repository.owner.login,\n\t\trepo: node.repository.name,\n\t\tnumber: node.number,\n\t\tnodeId: node.id,\n\t\turl: node.url,\n\t\t...(origin != null && { domain: origin }),\n\t\ttitle: node.title,\n\t\tbody: node.body,\n\t\tstate: node.state === 'OPEN' ? 'open' : node.state === 'CLOSED' ? 'closed' : 'merged',\n\t\t...(node.state !== 'OPEN' && typeof closedAt === 'string' ? { closedAt: closedAt } : {}),\n\t\t...(typeof node.updatedAt === 'string' ? { updatedAt: node.updatedAt } : {}),\n\t\theadSha: node.headRefOid,\n\t\tbaseRef: node.baseRefName,\n\t};\n}\n\nasync function resolveNode(\n\tinput: GitHubPullRequestWriteTarget,\n\tgraphql: GraphqlRequest,\n\torigin?: string,\n): Promise<ResolvedPullRequest | PullRequestWriteFailure> {\n\tconst { owner, repo, expectedNodeId, number } = input;\n\tconst result = await graphql<{ repository: MergeRepository | null; node: WriteNode | null }>(\n\t\t`query PullRequestWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!) {\n\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t${repositoryFields}\n\t\t\t\tmergeCommitAllowed squashMergeAllowed rebaseMergeAllowed ${origin == null ? 'viewerDefaultMergeMethod' : ''}\n\t\t\t}\n\t\t\tnode(id: $expectedNodeId) {\n\t\t\t\t__typename\n\t\t\t\t... on PullRequest {\n\t\t\t\t\t${pullRequestFields}\n\t\t\t\t\tviewerCanUpdate viewerCanClose viewerCanReopen\n\t\t\t\t\tisDraft baseRef { id }\n\t\t\t\t\t${origin == null ? 'isInMergeQueue isMergeQueueEnabled stack { id }' : ''}\n\t\t\t\t}\n\t\t\t}\n\t\t}`,\n\t\t{ owner: owner, repo: repo, expectedNodeId: expectedNodeId },\n\t);\n\tconst repository = result?.repository;\n\tconst node = result?.node;\n\tif (\n\t\trepository == null ||\n\t\t!sameRepository(input, repository) ||\n\t\tnode?.__typename !== 'PullRequest' ||\n\t\tnode.number !== number ||\n\t\tnode.repository.id !== repository.id ||\n\t\t!sameRepository(input, node.repository) ||\n\t\t!isGitHubWriteUrlOnInstallation(node.url, origin)\n\t) {\n\t\treturn { ok: false, reason: 'not-found' };\n\t}\n\n\treturn { ok: true, node: node, repository: repository };\n}\n\nasync function readBranchRules(refId: string, graphql: GraphqlRequest): Promise<BranchPolicy | undefined> {\n\ttype Response = {\n\t\tnode: {\n\t\t\tid: string;\n\t\t\trefUpdateRule: { requiresLinearHistory: boolean } | null;\n\t\t\trules: {\n\t\t\t\tnodes: (BranchRule | null)[] | null;\n\t\t\t\tpageInfo: { hasNextPage: boolean; endCursor: string | null };\n\t\t\t};\n\t\t} | null;\n\t};\n\tconst rules: BranchRule[] = [];\n\tconst seen = new Set<string>();\n\tlet requiresLinearHistory = false;\n\tlet cursor: string | undefined;\n\tfor (;;) {\n\t\tconst response = await graphql<Response>(\n\t\t\t`\n\t\t\t\tquery PullRequestBranchRules($id: ID!, $cursor: String) {\n\t\t\t\t\tnode(id: $id) {\n\t\t\t\t\t\t... on Ref {\n\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\trefUpdateRule {\n\t\t\t\t\t\t\t\trequiresLinearHistory\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\trules(first: 100, after: $cursor) {\n\t\t\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\t\t\ttype\n\t\t\t\t\t\t\t\t\tparameters {\n\t\t\t\t\t\t\t\t\t\t... on PullRequestParameters {\n\t\t\t\t\t\t\t\t\t\t\tallowedMergeMethods\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tpageInfo {\n\t\t\t\t\t\t\t\t\thasNextPage\n\t\t\t\t\t\t\t\t\tendCursor\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t`,\n\t\t\t{ id: refId, cursor: cursor },\n\t\t);\n\t\tconst ref = response?.node;\n\t\tconst page = ref?.rules;\n\t\tif (ref?.id !== refId || page?.nodes == null) return undefined;\n\n\t\trequiresLinearHistory ||= ref.refUpdateRule?.requiresLinearHistory === true;\n\n\t\tfor (const rule of page.nodes) {\n\t\t\tif (rule == null) return undefined;\n\n\t\t\trules.push(rule);\n\t\t}\n\n\t\tif (!page.pageInfo.hasNextPage) return { rules: rules, requiresLinearHistory: requiresLinearHistory };\n\n\t\tconst nextCursor = page.pageInfo.endCursor;\n\t\tif (nextCursor == null || seen.has(nextCursor)) return undefined;\n\n\t\tseen.add(nextCursor);\n\t\tcursor = nextCursor;\n\t}\n}\n\nasync function getMergeCapability(\n\tresolved: ResolvedPullRequest,\n\tgraphql: GraphqlRequest,\n\tenterprise?: EnterprisePullRequestWriteOptions,\n): Promise<MergeCapability> {\n\tconst { node, repository } = resolved;\n\tif (\n\t\t!isRepositoryWritable(repository) ||\n\t\tnode.state !== 'OPEN' ||\n\t\tnode.isDraft ||\n\t\tnode.isInMergeQueue ||\n\t\tnode.baseRef == null\n\t) {\n\t\treturn { kind: 'unavailable', reason: 'blocked' };\n\t}\n\n\tconst canWrite = hasWritePermission(repository);\n\tif (canWrite !== true) return { kind: 'unavailable', reason: canWrite === false ? 'forbidden' : 'unknown' };\n\tif (node.stack != null) return { kind: 'unavailable', reason: 'unsupported' };\n\tif (node.isMergeQueueEnabled) return { kind: 'queue' };\n\n\ttry {\n\t\tif (enterprise != null) {\n\t\t\tconst policy = await readEnterprisePullRequestMergePolicy(\n\t\t\t\t{ id: node.id, baseRef: node.baseRefName, baseRefId: node.baseRef.id },\n\t\t\t\t{ owner: repository.owner.login, repo: repository.name },\n\t\t\t\tgraphql,\n\t\t\t\tenterprise.readBranchRules,\n\t\t\t);\n\t\t\treturn 'kind' in policy ? policy : getDirectMergeCapability(repository, policy);\n\t\t}\n\n\t\tconst policy = await readBranchRules(node.baseRef.id, graphql);\n\t\tif (policy == null) return { kind: 'unavailable', reason: 'unknown' };\n\t\tif (policy.rules.some(rule => rule.type === 'MERGE_QUEUE')) return { kind: 'queue' };\n\n\t\treturn getDirectMergeCapability(repository, policy);\n\t} catch (ex) {\n\t\treturn { kind: 'unavailable', reason: pullRequestWriteFailure(ex).reason };\n\t}\n}\n\nfunction getDirectMergeCapability(\n\trepository: MergeRepository,\n\t{ rules, requiresLinearHistory }: BranchPolicy,\n): MergeCapability {\n\tconst linearHistory = requiresLinearHistory || rules.some(rule => rule.type === 'REQUIRED_LINEAR_HISTORY');\n\tconst methods = mergeMethods.filter(method => {\n\t\tconst allowed =\n\t\t\tmethod === 'merge'\n\t\t\t\t? repository.mergeCommitAllowed && !linearHistory\n\t\t\t\t: method === 'squash'\n\t\t\t\t\t? repository.squashMergeAllowed\n\t\t\t\t\t: repository.rebaseMergeAllowed;\n\t\treturn (\n\t\t\tallowed &&\n\t\t\trules.every(rule => {\n\t\t\t\tconst permitted = rule.type === 'PULL_REQUEST' ? rule.parameters?.allowedMergeMethods : undefined;\n\t\t\t\treturn permitted == null || permitted.some(allowedMethod => allowedMethod.toLowerCase() === method);\n\t\t\t})\n\t\t);\n\t});\n\tif (methods.length === 0) return { kind: 'unavailable', reason: 'blocked' };\n\n\tconst preference = repository.viewerDefaultMergeMethod?.toLowerCase();\n\tconst defaultMethod = methods.find(method => method === preference);\n\treturn { kind: 'direct', methods: methods, defaultMethod: defaultMethod };\n}\n\nexport async function resolveGitHubPullRequestWriteTarget(\n\tinput: GitHubPullRequestWriteTarget,\n\tgraphql: GraphqlRequest,\n\tenterprise?: EnterprisePullRequestWriteOptions,\n): Promise<PullRequestWriteTargetResult> {\n\tif (!isValidTarget(input)) return { ok: false, reason: 'invalid-input' };\n\n\ttry {\n\t\tconst resolved = await resolveNode(input, graphql, enterprise?.origin);\n\t\tif (!resolved.ok) return resolved;\n\n\t\tconst { node, repository } = resolved;\n\t\tconst writable = isRepositoryWritable(repository);\n\t\treturn {\n\t\t\tok: true,\n\t\t\tpullRequest: toSnapshot(node, enterprise?.origin),\n\t\t\tcapabilities: {\n\t\t\t\tedit: writable && node.viewerCanUpdate,\n\t\t\t\tclose: writable && node.state === 'OPEN' && node.viewerCanClose,\n\t\t\t\treopen: writable && node.state === 'CLOSED' && node.viewerCanReopen,\n\t\t\t\tmerge: await getMergeCapability(resolved, graphql, enterprise),\n\t\t\t},\n\t\t};\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex);\n\t}\n}\n\nexport async function getGitHubPullRequestCreateCapability(\n\tinput: GitHubPullRequestCreateTarget,\n\tgraphql: GraphqlRequest,\n): Promise<PullRequestCreateCapabilityResult> {\n\tif (!isValidRepository(input)) return { ok: false, reason: 'invalid-input' };\n\n\ttry {\n\t\tconst result = await graphql<{ repository: RepositoryNode | null }>(\n\t\t\t`query PullRequestCreateCapability($owner: String!, $repo: String!) {\n\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t${repositoryFields}\n\t\t\t\t}\n\t\t\t}`,\n\t\t\t{ owner: input.owner, repo: input.repo },\n\t\t);\n\t\tconst repository = result?.repository;\n\t\tif (repository == null || !sameRepository(input, repository)) return { ok: false, reason: 'not-found' };\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\trepositoryId: repository.id,\n\t\t\tcanCreate: isRepositoryWritable(repository) && (repository.viewerPermission == null ? undefined : true),\n\t\t};\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex);\n\t}\n}\n\ntype WriteTransport = {\n\tgraphql: GraphqlRequest;\n\tenterprise?: EnterprisePullRequestWriteOptions;\n\tisSessionCurrent: () => Promise<boolean>;\n\tenqueue: (nodeId: string, headSha: string) => Promise<PullRequestMergeQueueActionResult>;\n};\n\nconst mutations = {\n\tcreated: ['createPullRequest', 'CreatePullRequestInput'],\n\tupdated: ['updatePullRequest', 'UpdatePullRequestInput'],\n\tclosed: ['closePullRequest', 'ClosePullRequestInput'],\n\treopened: ['reopenPullRequest', 'ReopenPullRequestInput'],\n\tmerged: ['mergePullRequest', 'MergePullRequestInput'],\n\tqueued: ['enqueuePullRequest', 'EnqueuePullRequestInput'],\n} as const;\n\nasync function sendMutation(\n\ttransport: WriteTransport,\n\tstatus: keyof typeof mutations,\n\trepository: RepositoryIdentity,\n\tvalues: Record<string, string | undefined>,\n\tprevious?: PullRequestNode,\n): Promise<PullRequestWriteResult> {\n\tif (!(await transport.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\tconst [mutation, inputType] = mutations[status];\n\tconst fields =\n\t\tstatus === 'created' && transport.enterprise?.origin != null\n\t\t\t? `${pullRequestFields} headRefName`\n\t\t\t: pullRequestFields;\n\tconst pullRequest = `pullRequest { ${fields} }`;\n\tconst selection = status === 'queued' ? `mergeQueueEntry { id ${pullRequest} }` : pullRequest;\n\ttype Payload = {\n\t\tchange: {\n\t\t\tpullRequest?: PullRequestNode | null;\n\t\t\tmergeQueueEntry?: { id: string; pullRequest: PullRequestNode | null } | null;\n\t\t} | null;\n\t};\n\tlet payload: Payload | undefined;\n\tlet error: unknown;\n\ttry {\n\t\tpayload = await transport.graphql<Payload>(\n\t\t\t`mutation WritePullRequest($input: ${inputType}!) {\n\t\t\t\tchange: ${mutation}(input: $input) { ${selection} }\n\t\t\t}`,\n\t\t\t{ input: values },\n\t\t);\n\t} catch (ex) {\n\t\terror = ex;\n\t\tif (ex instanceof GraphqlResponseError) {\n\t\t\tpayload = ex.data as Payload | undefined;\n\t\t}\n\t}\n\n\tconst entry = payload?.change?.mergeQueueEntry;\n\tconst node =\n\t\tstatus === 'queued'\n\t\t\t? typeof entry?.id === 'string' && entry.id\n\t\t\t\t? entry.pullRequest\n\t\t\t\t: undefined\n\t\t\t: payload?.change?.pullRequest;\n\tif (node == null && error != null) {\n\t\tif (\n\t\t\terror instanceof GraphqlResponseError &&\n\t\t\terror.errors?.some(item => item.path?.[0] === 'change' && item.path.length > 1)\n\t\t) {\n\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\n\t\treturn pullRequestWriteFailure(\n\t\t\terror,\n\t\t\tstatus === 'merged' ? 'merge' : status === 'queued' ? 'enqueue' : 'write',\n\t\t);\n\t}\n\n\tconst expectedState =\n\t\tstatus === 'created' || status === 'reopened' || status === 'queued'\n\t\t\t? 'OPEN'\n\t\t\t: status === 'closed'\n\t\t\t\t? 'CLOSED'\n\t\t\t\t: status === 'merged'\n\t\t\t\t\t? 'MERGED'\n\t\t\t\t\t: undefined;\n\tif (\n\t\tnode?.repository?.id !== repository.id ||\n\t\t(previous != null && (node.id !== previous.id || node.number !== previous.number)) ||\n\t\t(expectedState != null && node.state !== expectedState) ||\n\t\ttypeof node.repository.owner?.login !== 'string' ||\n\t\ttypeof node.repository.name !== 'string' ||\n\t\ttypeof node.id !== 'string' ||\n\t\t!Number.isInteger(node.number) ||\n\t\ttypeof node.url !== 'string' ||\n\t\ttypeof node.title !== 'string' ||\n\t\ttypeof node.body !== 'string' ||\n\t\ttypeof node.headRefOid !== 'string' ||\n\t\ttypeof node.baseRefName !== 'string' ||\n\t\t!isGitHubWriteUrlOnInstallation(node.url, transport.enterprise?.origin) ||\n\t\t(node.state !== 'OPEN' && node.state !== 'CLOSED' && node.state !== 'MERGED')\n\t) {\n\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t}\n\n\tif (transport.enterprise?.origin != null) {\n\t\tif (\n\t\t\tstatus === 'created' &&\n\t\t\t(node.baseRefName !== values.baseRefName || node.headRefName !== values.headRefName)\n\t\t) {\n\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\t\tif (\n\t\t\t(status === 'merged' || status === 'queued') &&\n\t\t\t(node.baseRefName !== previous?.baseRefName ||\n\t\t\t\tnode.headRefOid.toLowerCase() !== previous.headRefOid.toLowerCase())\n\t\t) {\n\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\t}\n\n\treturn { ok: true, status: status, pullRequest: toSnapshot(node, transport.enterprise?.origin) };\n}\n\nasync function createPullRequest(\n\tinput: Extract<GitHubPullRequestWrite, { action: 'create' }>,\n\ttransport: WriteTransport,\n): Promise<PullRequestWriteResult> {\n\ttype CreateRepository = RepositoryNode & { base: { id: string } | null; head: { id: string } | null };\n\tconst result = await transport.graphql<{ repository: CreateRepository | null }>(\n\t\t`query PullRequestCreateTarget($owner: String!, $repo: String!, $base: String!, $head: String!) {\n\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t${repositoryFields}\n\t\t\t\tbase: ref(qualifiedName: $base) { id }\n\t\t\t\thead: ref(qualifiedName: $head) { id }\n\t\t\t}\n\t\t}`,\n\t\t{\n\t\t\towner: input.owner,\n\t\t\trepo: input.repo,\n\t\t\tbase: `refs/heads/${input.baseRef}`,\n\t\t\thead: `refs/heads/${input.headRef}`,\n\t\t},\n\t);\n\tconst repository = result?.repository;\n\tif (\n\t\trepository == null ||\n\t\t!sameRepository(input, repository) ||\n\t\t(input.expectedRepositoryId != null && input.expectedRepositoryId !== repository.id)\n\t) {\n\t\treturn { ok: false, reason: 'not-found' };\n\t}\n\n\tif (!isRepositoryWritable(repository)) return { ok: false, reason: 'blocked' };\n\tif (repository.base == null || repository.head == null) return { ok: false, reason: 'invalid-input' };\n\n\treturn sendMutation(transport, 'created', repository, {\n\t\trepositoryId: repository.id,\n\t\tbaseRefName: input.baseRef,\n\t\theadRefName: input.headRef,\n\t\ttitle: input.title,\n\t\tbody: input.body,\n\t});\n}\n\nasync function mergePullRequest(\n\tinput: Extract<GitHubPullRequestWrite, { action: 'merge' | 'enqueue' }>,\n\tresolved: ResolvedPullRequest,\n\ttransport: WriteTransport,\n): Promise<PullRequestWriteResult> {\n\tconst { node, repository } = resolved;\n\tif (node.headRefOid.toLowerCase() !== input.expectedHeadSha.toLowerCase()) {\n\t\treturn { ok: false, reason: 'head-changed' };\n\t}\n\n\tif (node.baseRefName !== input.expectedBaseRef) return { ok: false, reason: 'base-changed' };\n\n\tconst capability = await getMergeCapability(resolved, transport.graphql, transport.enterprise);\n\tif (capability.kind === 'unavailable') return { ok: false, reason: capability.reason };\n\n\tif (\n\t\tinput.action === 'merge'\n\t\t\t? capability.kind !== 'direct' || !capability.methods.includes(input.mergeMethod)\n\t\t\t: capability.kind !== 'queue'\n\t) {\n\t\treturn { ok: false, reason: 'blocked' };\n\t}\n\n\tif (transport.enterprise?.origin != null) {\n\t\tconst current = await resolveNode(\n\t\t\t{ ...input, expectedNodeId: node.id },\n\t\t\ttransport.graphql,\n\t\t\ttransport.enterprise.origin,\n\t\t);\n\t\tif (!current.ok) return current;\n\t\tif (current.node.id !== node.id || current.repository.id !== repository.id) {\n\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t}\n\n\t\tif (current.node.baseRefName !== input.expectedBaseRef || current.node.baseRef?.id !== node.baseRef?.id) {\n\t\t\treturn { ok: false, reason: 'base-changed' };\n\t\t}\n\t\tif (current.node.headRefOid.toLowerCase() !== input.expectedHeadSha.toLowerCase()) {\n\t\t\treturn { ok: false, reason: 'head-changed' };\n\t\t}\n\t\tif (current.node.state !== 'OPEN' || current.node.isDraft || !isRepositoryWritable(current.repository)) {\n\t\t\treturn { ok: false, reason: 'blocked' };\n\t\t}\n\t}\n\n\tconst values = { pullRequestId: node.id, expectedHeadOid: node.headRefOid };\n\tif (input.action === 'merge') {\n\t\treturn sendMutation(\n\t\t\ttransport,\n\t\t\t'merged',\n\t\t\trepository,\n\t\t\t{ ...values, mergeMethod: input.mergeMethod.toUpperCase() },\n\t\t\tnode,\n\t\t);\n\t}\n\n\tif (transport.enterprise?.origin != null) return sendMutation(transport, 'queued', repository, values, node);\n\n\tif (!(await transport.isSessionCurrent())) return { ok: false, reason: 'no-connection' };\n\n\ttry {\n\t\tconst result = await transport.enqueue(node.id, node.headRefOid);\n\t\tif (result.status === 'queued' && result.entry != null) {\n\t\t\treturn { ok: true, status: 'queued', pullRequest: toSnapshot(node) };\n\t\t}\n\n\t\tif (result.status !== 'failed') return { ok: false, reason: 'outcome-unknown' };\n\n\t\tswitch (result.reason) {\n\t\t\tcase 'permission':\n\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\tcase 'already-queued':\n\t\t\tcase 'not-allowed':\n\t\t\t\treturn { ok: false, reason: 'blocked' };\n\t\t\tcase 'head-changed':\n\t\t\tcase 'unsupported':\n\t\t\t\treturn { ok: false, reason: result.reason };\n\t\t\tdefault:\n\t\t\t\treturn { ok: false, reason: 'outcome-unknown' };\n\t\t}\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex, 'enqueue');\n\t}\n}\n\nexport async function writeGitHubPullRequest(\n\tinput: GitHubPullRequestWrite,\n\ttransport: WriteTransport,\n): Promise<PullRequestWriteResult> {\n\tif (\n\t\t!isValidWrite(input) ||\n\t\t(transport.enterprise?.origin != null && input.action === 'create' && input.expectedRepositoryId == null)\n\t) {\n\t\treturn { ok: false, reason: 'invalid-input' };\n\t}\n\n\ttry {\n\t\tif (input.action === 'create') return await createPullRequest(input, transport);\n\n\t\tconst resolved = await resolveNode(input, transport.graphql, transport.enterprise?.origin);\n\t\tif (!resolved.ok) return resolved;\n\n\t\tconst { node, repository } = resolved;\n\t\tif (!isRepositoryWritable(repository)) return { ok: false, reason: 'blocked' };\n\t\tif (input.action === 'merge' || input.action === 'enqueue') {\n\t\t\treturn await mergePullRequest(input, resolved, transport);\n\t\t}\n\n\t\tif (input.action === 'edit') {\n\t\t\tif (!node.viewerCanUpdate) return { ok: false, reason: 'forbidden' };\n\n\t\t\treturn await sendMutation(\n\t\t\t\ttransport,\n\t\t\t\t'updated',\n\t\t\t\trepository,\n\t\t\t\t{ pullRequestId: node.id, title: input.title, body: input.body },\n\t\t\t\tnode,\n\t\t\t);\n\t\t}\n\n\t\tconst close = input.state === 'closed';\n\t\tif (node.state !== (close ? 'OPEN' : 'CLOSED')) return { ok: false, reason: 'blocked' };\n\t\tif (close ? !node.viewerCanClose : !node.viewerCanReopen) return { ok: false, reason: 'forbidden' };\n\n\t\treturn await sendMutation(\n\t\t\ttransport,\n\t\t\tclose ? 'closed' : 'reopened',\n\t\t\trepository,\n\t\t\t{ pullRequestId: node.id },\n\t\t\tnode,\n\t\t);\n\t} catch (ex) {\n\t\treturn pullRequestWriteFailure(ex);\n\t}\n}\n"],"mappings":";;;;;AAiJA,MAAM,qBAAqB;AAC3B,MAAM,mBAAmB,GAAG,mBAAmB;AAC/C,MAAM,oBAAoB;;gBAEV,mBAAmB;;AAEnC,MAAM,eAAuC;CAAC;CAAS;CAAU;AAAQ;AAEzE,SAAS,kBAAkB,EAAE,OAAO,QAAgD;CACnF,OACC,OAAO,UAA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AG,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAU;EAC7E,IAAI,MAAM,WAAW,WAAW,MAAM,WAAW,WAChD,OAAO,MAAM,iBAAiB,OAAO,UAAU,SAAS;EAGzD,IAAI,MAAM,WAAW,QAAQ;GAC5B,IAAI,CAAC,KAAK,iBAAiB,OAAO;IAAE,IAAI;IAAO,QAAQ;GAAY;GAEnE,OAAO,MAAM,aACZ,WACA,WACA,YACA;IAAE,eAAe,KAAK;IAAI,OAAO,MAAM;IAAO,MAAM,MAAM;GAAK,GAC/D,IACD;EACD;EAEA,MAAM,QAAQ,MAAM,UAAU;EAC9B,IAAI,KAAK,WAAW,QAAQ,SAAS,WAAW,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAU;EACtF,IAAI,QAAQ,CAAC,KAAK,iBAAiB,CAAC,KAAK,iBAAiB,OAAO;GAAE,IAAI;GAAO,QAAQ;EAAY;EAElG,OAAO,MAAM,aACZ,WACA,QAAQ,WAAW,YACnB,YACA,EAAE,eAAe,KAAK,GAAG,GACzB,IACD;CACD,SAAS,IAAI;EACZ,OAAO,wBAAwB,EAAE;CAClC;AACD"}
|
|
@@ -30,7 +30,7 @@ export declare class ConfiguredIntegrationService implements Disposable {
|
|
|
30
30
|
private _signOutEpoch;
|
|
31
31
|
/** The latest retirement of pending stores per provider, self-managed host, or connection. */
|
|
32
32
|
private readonly _signOuts;
|
|
33
|
-
private readonly
|
|
33
|
+
private readonly _storedWriteRetirements;
|
|
34
34
|
private _disposed;
|
|
35
35
|
get onDidChange(): Event<ConfiguredIntegrationsChangeEvent>;
|
|
36
36
|
get onWillChangeSession(): Event<IntegrationSessionChangeEvent>;
|
|
@@ -53,9 +53,9 @@ export declare class ConfiguredIntegrationService implements Disposable {
|
|
|
53
53
|
*/
|
|
54
54
|
getSignOutMark(): number;
|
|
55
55
|
private retirePendingStores;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
private
|
|
56
|
+
getStoredWriteMark(): number;
|
|
57
|
+
isStoredWriteRetiredSince(id: IntegrationIds, session: Pick<ProviderAuthenticationSession, 'id' | 'domain'>, mark: number): boolean;
|
|
58
|
+
private retireStoredWrites;
|
|
59
59
|
private getHostScope;
|
|
60
60
|
isSessionRetiredSince(id: IntegrationIds, session: Pick<ProviderAuthenticationSession, 'id' | 'domain'>, mark: number): boolean;
|
|
61
61
|
private hasRetirement;
|
|
@@ -6,7 +6,7 @@ import { areDomainsOnSameHost, baseUrlFromDomain, hostFromDomain, sameConfigured
|
|
|
6
6
|
import { isSelfManagedHostIntegrationId } from "../utils/integration.utils.js";
|
|
7
7
|
import { getSessionIdentity } from "./models.js";
|
|
8
8
|
//#region ../plus/integrations/src/authentication/configuredIntegrationService.ts
|
|
9
|
-
const
|
|
9
|
+
const storedWriteRetirements = /* @__PURE__ */ new WeakMap();
|
|
10
10
|
var ConfiguredIntegrationService = class {
|
|
11
11
|
ctx;
|
|
12
12
|
_onDidChange = new Emitter();
|
|
@@ -23,7 +23,7 @@ var ConfiguredIntegrationService = class {
|
|
|
23
23
|
_signOutEpoch = 0;
|
|
24
24
|
/** The latest retirement of pending stores per provider, self-managed host, or connection. */
|
|
25
25
|
_signOuts = /* @__PURE__ */ new Map();
|
|
26
|
-
|
|
26
|
+
_storedWriteRetirements;
|
|
27
27
|
_disposed = false;
|
|
28
28
|
get onDidChange() {
|
|
29
29
|
return this._onDidChange.event;
|
|
@@ -36,15 +36,15 @@ var ConfiguredIntegrationService = class {
|
|
|
36
36
|
}
|
|
37
37
|
constructor(ctx) {
|
|
38
38
|
this.ctx = ctx;
|
|
39
|
-
let retirements =
|
|
39
|
+
let retirements = storedWriteRetirements.get(ctx.storage);
|
|
40
40
|
if (retirements == null) {
|
|
41
41
|
retirements = {
|
|
42
42
|
epoch: 0,
|
|
43
43
|
scopes: /* @__PURE__ */ new Map()
|
|
44
44
|
};
|
|
45
|
-
|
|
45
|
+
storedWriteRetirements.set(ctx.storage, retirements);
|
|
46
46
|
}
|
|
47
|
-
this.
|
|
47
|
+
this._storedWriteRetirements = retirements;
|
|
48
48
|
}
|
|
49
49
|
dispose() {
|
|
50
50
|
this._disposed = true;
|
|
@@ -167,16 +167,16 @@ var ConfiguredIntegrationService = class {
|
|
|
167
167
|
}
|
|
168
168
|
retirePendingStores(scope) {
|
|
169
169
|
this._signOuts.set(scope, ++this._signOutEpoch);
|
|
170
|
-
this.
|
|
170
|
+
this.retireStoredWrites(scope);
|
|
171
171
|
}
|
|
172
|
-
|
|
173
|
-
return this.
|
|
172
|
+
getStoredWriteMark() {
|
|
173
|
+
return this._storedWriteRetirements.epoch;
|
|
174
174
|
}
|
|
175
|
-
|
|
176
|
-
return this._disposed || this.hasRetirement(this.
|
|
175
|
+
isStoredWriteRetiredSince(id, session, mark) {
|
|
176
|
+
return this._disposed || this.hasRetirement(this._storedWriteRetirements.scopes, id, session, mark);
|
|
177
177
|
}
|
|
178
|
-
|
|
179
|
-
const retirements = this.
|
|
178
|
+
retireStoredWrites(scope) {
|
|
179
|
+
const retirements = this._storedWriteRetirements;
|
|
180
180
|
retirements.scopes.set(scope, ++retirements.epoch);
|
|
181
181
|
}
|
|
182
182
|
getHostScope(id, domain) {
|
|
@@ -201,7 +201,7 @@ var ConfiguredIntegrationService = class {
|
|
|
201
201
|
const previous = await this.readSecret(id, session.id, session.cloud);
|
|
202
202
|
if (options?.expectedStoredAccessToken != null && previous?.accessToken !== options.expectedStoredAccessToken) return false;
|
|
203
203
|
if (getSessionIdentity(previous) !== getSessionIdentity(session)) {
|
|
204
|
-
if (previous != null) this.
|
|
204
|
+
if (previous != null) this.retireStoredWrites(`${id}|connection:${session.id}`);
|
|
205
205
|
this._onWillChangeSession.fire({
|
|
206
206
|
integrationId: id,
|
|
207
207
|
session,
|
|
@@ -310,7 +310,7 @@ var ConfiguredIntegrationService = class {
|
|
|
310
310
|
await this.ctx.storage.store("integrations:configured", remaining);
|
|
311
311
|
}
|
|
312
312
|
async deleteSecrets(id, connectionId, cloud, options) {
|
|
313
|
-
this.
|
|
313
|
+
this.retireStoredWrites(`${id}|connection:${connectionId}`);
|
|
314
314
|
if (cloud == null || cloud === false) await this.ctx.storage.deleteSecret(this.getLocalSecretKey(id, connectionId));
|
|
315
315
|
if (cloud == null || cloud === true) await this.ctx.storage.deleteSecret(this.getCloudSecretKey(id, connectionId));
|
|
316
316
|
if (options?.preserveConfigured) return;
|
|
@@ -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 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 { IntegrationAuthenticationSessionDescriptor } from './integrationAuthenticationProvider.js';\nimport type {\n\tCloudIntegrationAuthType,\n\tConfiguredIntegrationDescriptor,\n\tConnectionResource,\n\tProviderAuthenticationSession,\n} from './models.js';\nimport { getSessionIdentity } from './models.js';\n\ninterface StoredSession {\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 IssueWriteRetirements = { epoch: number; scopes: Map<string, number> };\nconst issueWriteRetirements = new WeakMap<IntegrationServiceContext['storage'], IssueWriteRetirements>();\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 storeConfiguredQueue: Promise<void> = Promise.resolve();\n\t/**\n\t * One provider's secret and descriptor mutations run one at a time, so a sign-out never interleaves with a\n\t * token being stored: storing writes the secret and then registers its descriptor, and a delete in between would\n\t * miss a connection it cannot see yet, or be undone by the pending write (#5948).\n\t */\n\tprivate readonly _locks = new Map<IntegrationIds, Promise<void>>();\n\t/** Monotonic across providers; see {@link getSignOutMark}. */\n\tprivate _signOutEpoch = 0;\n\t/** The latest retirement of pending stores per provider, self-managed host, or connection. */\n\tprivate readonly _signOuts = new Map<string, number>();\n\tprivate readonly _issueWriteRetirements: IssueWriteRetirements;\n\tprivate _disposed = false;\n\tget onDidChange(): Event<ConfiguredIntegrationsChangeEvent> {\n\t\treturn this._onDidChange.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 retirements = issueWriteRetirements.get(ctx.storage);\n\t\tif (retirements == null) {\n\t\t\tretirements = { epoch: 0, scopes: new Map() };\n\t\t\tissueWriteRetirements.set(ctx.storage, retirements);\n\t\t}\n\t\tthis._issueWriteRetirements = retirements;\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 _configured?: Map<IntegrationIds, ConfiguredIntegrationDescriptor[]>;\n\tprivate get configured(): Map<IntegrationIds, ConfiguredIntegrationDescriptor[]> {\n\t\tif (this._configured == null) {\n\t\t\tthis._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\t// Backfill a stable connection id for pre-multi-account stored data: the domain for\n\t\t\t\t\t// self-managed hosts, or the provider's canonical domain for cloud (which is the legacy\n\t\t\t\t\t// secret-key session id), so existing secrets keep resolving with zero migration. Fall back\n\t\t\t\t\t// to the integration id (never empty) when no domain is known — self-managed providers carry\n\t\t\t\t\t// `domain: ''` in metadata, and an empty id would collide across connections and produce\n\t\t\t\t\t// ambiguous secret keys (`...|`).\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._configured.set(id, descriptors);\n\t\t\t}\n\t\t}\n\n\t\treturn this._configured;\n\t}\n\n\t// Synchronous: reads the in-memory configured map (lazily hydrated from storage). No async work —\n\t// the old async variant only existed to weave in the built-in VS Code GitHub session, which is gone.\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 async storeConfigured(): Promise<void> {\n\t\t// We need to convert the map to a record to store\n\t\tconst configured: StoredIntegrationConfigurations = {} as unknown as StoredIntegrationConfigurations;\n\t\tfor (const [id, descriptors] of this.configured) {\n\t\t\tconfigured[id] = descriptors.map(d => ({\n\t\t\t\t...d,\n\t\t\t\texpiresAt: d.expiresAt\n\t\t\t\t\t? d.expiresAt instanceof Date\n\t\t\t\t\t\t? d.expiresAt.toISOString()\n\t\t\t\t\t\t: d.expiresAt\n\t\t\t\t\t: undefined,\n\t\t\t}));\n\t\t}\n\n\t\tconst pending = this.storeConfiguredQueue.then(() =>\n\t\t\tthis.ctx.storage.store('integrations:configured', configured),\n\t\t);\n\t\tthis.storeConfiguredQueue = pending.catch(() => {});\n\t\tawait 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\t// Key connections by their stable id (+ cloud, to preserve legacy local/cloud coexistence) so\n\t\t// multiple accounts on the same provider+domain no longer overwrite each other.\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\t// remove the existing descriptor from the array\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\tthis.configured.set(descriptor.integrationId, descriptors);\n\n\t\tif (changed) {\n\t\t\tthis.fireChange(descriptor.integrationId);\n\t\t}\n\t\tawait this.storeConfigured();\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\tthis.configured.set(id, descriptors);\n\t\tthis.fireChange(undefined, id);\n\t\tawait this.storeConfigured();\n\t}\n\n\tprivate withLock<T>(id: IntegrationIds, fn: () => Promise<T>): Promise<T> {\n\t\tconst run = (this._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\tthis._locks.set(id, settled);\n\t\tvoid settled.then(() => {\n\t\t\tif (this._locks.get(id) === settled) {\n\t\t\t\tthis._locks.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._signOutEpoch;\n\t}\n\n\tprivate retirePendingStores(scope: string): void {\n\t\tthis._signOuts.set(scope, ++this._signOutEpoch);\n\t\tthis.retireIssueWrites(scope);\n\t}\n\n\tgetIssueWriteMark(): number {\n\t\treturn this._issueWriteRetirements.epoch;\n\t}\n\n\tisIssueWriteRetiredSince(\n\t\tid: IntegrationIds,\n\t\tsession: Pick<ProviderAuthenticationSession, 'id' | 'domain'>,\n\t\tmark: number,\n\t): boolean {\n\t\treturn this._disposed || this.hasRetirement(this._issueWriteRetirements.scopes, id, session, mark);\n\t}\n\n\tprivate retireIssueWrites(scope: string): void {\n\t\tconst retirements = this._issueWriteRetirements;\n\t\tretirements.scopes.set(scope, ++retirements.epoch);\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'>,\n\t\tmark: number,\n\t): boolean {\n\t\treturn this.hasRetirement(this._signOuts, id, session, mark);\n\t}\n\n\tprivate hasRetirement(\n\t\tscopes: ReadonlyMap<string, number>,\n\t\tid: IntegrationIds,\n\t\tsession: Pick<ProviderAuthenticationSession, 'id' | 'domain'>,\n\t\tmark: number,\n\t): boolean {\n\t\tconst since = (scope: string) => (scopes.get(scope) ?? 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?: { signOutMark?: number; resource?: ConnectionResource; expectedStoredAccessToken?: string },\n\t): Promise<boolean> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (options?.signOutMark != null && this.isSessionRetiredSince(id, session, options.signOutMark)) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst previous = await this.readSecret(id, session.id, session.cloud);\n\t\t\tif (\n\t\t\t\toptions?.expectedStoredAccessToken != null &&\n\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\tif (getSessionIdentity(previous) !== getSessionIdentity(session)) {\n\t\t\t\tif (previous != null) {\n\t\t\t\t\tthis.retireIssueWrites(`${id}|connection:${session.id}`);\n\t\t\t\t}\n\n\t\t\t\t// Readers share this lock, so none can resolve the retired token after this synchronous fence.\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\tawait this.writeSecret(id, session, options?.resource);\n\t\t\tif (\n\t\t\t\toptions?.expectedStoredAccessToken != null &&\n\t\t\t\tsession.accessToken !== options.expectedStoredAccessToken\n\t\t\t) {\n\t\t\t\tthis.retirePendingStores(`${id}|connection:${session.id}`);\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\t}\n\n\tasync peekStoredSession(\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\tconst json = await this.ctx.storage.getSecret(this.getSecretKey(id, connectionId, cloud));\n\t\t\tif (json == null) return undefined;\n\n\t\t\ttry {\n\t\t\t\treturn convertStoredSessionToSession(\n\t\t\t\t\tJSON.parse(json) as StoredSession,\n\t\t\t\t\t{ connectionId: connectionId, domain: domain, scopes: [] },\n\t\t\t\t\tcloud,\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t});\n\t}\n\n\tgetStoredSession(\n\t\tid: IntegrationIds,\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\t// Under the lock too: reading can repair storage (a legacy local-key cloud session, a missing descriptor).\n\t\treturn this.withLock(id, async () => {\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\n\t\t\tlet cloudIfMissing = false;\n\t\t\tif (session != null) {\n\t\t\t\t// Check the `expiresAt` field\n\t\t\t\t// If it has an expiresAt property and the key is the old type, then it's a cloud session,\n\t\t\t\t// so delete it from the local key and\n\t\t\t\t// store with the \"cloud\" type key, and then use that one.\n\t\t\t\t// Otherwise it's a local session under the local key, so just return it.\n\t\t\t\tif (session.expiresAt != null) {\n\t\t\t\t\tcloudIfMissing = true;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait this.deleteSecrets(id, session.id);\n\t\t\t\t\t\tawait this.writeSecret(id, session);\n\t\t\t\t\t} catch {}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If no local session we try to restore a session with the cloud key\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 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?: { preserveConfigured?: boolean; signOut?: boolean; signOutMark?: number },\n\t): Promise<boolean> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tconst connectionId = this.resolveConnectionId(id, descriptor);\n\t\t\tif (\n\t\t\t\toptions?.signOutMark != null &&\n\t\t\t\tthis.isSessionRetiredSince(id, { id: connectionId, domain: descriptor.domain }, options.signOutMark)\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\tthis._onWillRemoveSessions.fire({\n\t\t\t\tintegrationId: id,\n\t\t\t\tconnectionId: connectionId,\n\t\t\t\tcloud: cloud,\n\t\t\t\tdomain: descriptor.domain,\n\t\t\t});\n\t\t\tawait this.deleteSecrets(id, connectionId, cloud, options);\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(id: IntegrationIds, cloud?: boolean, domain?: string): Promise<void> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tthis.retirePendingStores(\n\t\t\t\tisSelfManagedHostIntegrationId(id) && domain != null ? this.getHostScope(id, domain) : id,\n\t\t\t);\n\t\t\tthis._onWillRemoveSessions.fire({ integrationId: id, cloud: cloud, domain: domain });\n\t\t\tawait this.deleteAllSecrets(id, cloud, domain);\n\t\t});\n\t}\n\n\t/**\n\t * Reclaims all stored configuration + secrets for the given (typically retired) integration ids.\n\t * Used to clean up state left behind when an id is removed from the model — e.g. the local\n\t * self-managed `github-enterprise`/`gitlab-self-hosted` ids dropped when integrations went cloud-only.\n\t * Domains are read from the stored config (secrets are keyed by domain); ids with no stored config\n\t * are a no-op.\n\t */\n\tasync purgeStoredConfiguration(ids: readonly string[]): Promise<void> {\n\t\tconst stored =\n\t\t\tthis.ctx.storage.get<Record<string, StoredConfiguredIntegrationDescriptor[] | undefined>>(\n\t\t\t\t'integrations:configured',\n\t\t\t);\n\t\tif (stored == null) return;\n\n\t\tlet changed = false;\n\t\tfor (const id of ids) {\n\t\t\tif (!(id in stored)) continue;\n\n\t\t\tfor (const descriptor of stored[id] ?? []) {\n\t\t\t\t// Mirror the hydration backfill so the secret keys we delete match what was written: fall back\n\t\t\t\t// through domain, the provider's canonical domain, then the integration id (never empty). A\n\t\t\t\t// legacy cloud descriptor stored neither id nor domain, so an empty connection id here would\n\t\t\t\t// miss the canonical-domain secret (e.g. `integration.auth.cloud:github|github.com`) and orphan it.\n\t\t\t\tconst connectionId =\n\t\t\t\t\tdescriptor.id || descriptor.domain || providersMetadata[id as IntegrationIds]?.domain || id;\n\t\t\t\tawait this.ctx.storage.deleteSecret(this.getLocalSecretKey(id as IntegrationIds, connectionId));\n\t\t\t\tawait this.ctx.storage.deleteSecret(this.getCloudSecretKey(id as IntegrationIds, connectionId));\n\t\t\t\tif (descriptor.domain) {\n\t\t\t\t\tawait this.ctx.storage.deleteWorkspace(`connected:${id}:${descriptor.domain}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tchanged = true;\n\t\t}\n\t\tif (!changed) return;\n\n\t\tconst remaining = Object.fromEntries(Object.entries(stored).filter(([key]) => !ids.includes(key)));\n\t\tawait this.ctx.storage.store('integrations:configured', remaining as StoredIntegrationConfigurations);\n\t}\n\n\tprivate async deleteSecrets(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string,\n\t\tcloud?: boolean,\n\t\toptions?: { preserveConfigured?: boolean },\n\t): Promise<void> {\n\t\tthis.retireIssueWrites(`${id}|connection:${connectionId}`);\n\t\tif (cloud == null || cloud === false) {\n\t\t\tawait this.ctx.storage.deleteSecret(this.getLocalSecretKey(id, connectionId));\n\t\t}\n\n\t\tif (cloud == null || cloud === true) {\n\t\t\tawait this.ctx.storage.deleteSecret(this.getCloudSecretKey(id, connectionId));\n\t\t}\n\n\t\tif (options?.preserveConfigured) return;\n\n\t\tawait this.removeConfigured(id, { connectionId: connectionId, cloud: cloud });\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): 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(session),\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 (sessionJSON) {\n\t\t\t\tstoredSession = JSON.parse(sessionJSON);\n\t\t\t\tif (storedSession != null) {\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\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(id: IntegrationIds, connectionId: string): Promise<void> {\n\t\treturn this.withLock(id, () => this.setPrimaryConnectionCore(id, connectionId));\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\tthis.configured.set(id, updated);\n\t\tthis.fireChange(id);\n\t\tawait this.storeConfigured();\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\t// The connection is gone, so a token of it fetched before must not be stored back.\n\t\t\tthis.retirePendingStores(`${id}|connection:${connectionId}`);\n\t\t\tthis._onWillRemoveSessions.fire({ integrationId: id, connectionId: connectionId, cloud: cloud });\n\t\t\tawait this.deleteSecrets(id, connectionId, cloud);\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 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":";;;;;;;;AAwDA,MAAM,wCAAwB,IAAI,QAAqE;AAEvG,IAAa,+BAAb,MAAgE;CAgClC;CA/B7B,eAAgC,IAAI,QAA2C;CAC/E,uBAAwC,IAAI,QAAuC;CACnF,wBAAyC,IAAI,QAK1C;CACH,uBAA8C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;GAChC,KAAK,UAAU,MAAM;GACrB,MAAM,UAAU,CAAC,GAAG,KAAK,WAAW;GACpC,KAAK,YAAY,MAAM;GAEvB,KAAK,aAAa,KAAK;IAAS;IAAgB;GAAQ,CAAC;EAC1D,GAAG,GAAG;EAEN,IAAI,SAAS,MACZ,KAAK,UAAU,IAAI,KAAK;EAEzB,IAAI,WAAW,MACd,KAAK,YAAY,IAAI,OAAO;EAE7B,KAAK,qBAAqB;CAC3B;AACD;AAEA,SAAS,8BACR,eACA,YACA,gBAC4C;CAC5C,IAAI,iBAAiB,MAAM,OAAO,KAAA;CAElC,OAAO;EACN,IAAI,cAAc;EAClB,aAAa,cAAc;EAC3B,SAAS;GACR,IAAI,cAAc,SAAS,MAAM;GACjC,OAAO,cAAc,SAAS,SAAS;EACxC;EACA,QAAQ,cAAc;EACtB,OAAO,cAAc,SAAS;EAC9B,WAAW,cAAc,YAAY,IAAI,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 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 { IntegrationAuthenticationSessionDescriptor } from './integrationAuthenticationProvider.js';\nimport type {\n\tCloudIntegrationAuthType,\n\tConfiguredIntegrationDescriptor,\n\tConnectionResource,\n\tProviderAuthenticationSession,\n} from './models.js';\nimport { getSessionIdentity } from './models.js';\n\ninterface StoredSession {\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 StoredWriteRetirements = { epoch: number; scopes: Map<string, number> };\nconst storedWriteRetirements = new WeakMap<IntegrationServiceContext['storage'], StoredWriteRetirements>();\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 storeConfiguredQueue: Promise<void> = Promise.resolve();\n\t/**\n\t * One provider's secret and descriptor mutations run one at a time, so a sign-out never interleaves with a\n\t * token being stored: storing writes the secret and then registers its descriptor, and a delete in between would\n\t * miss a connection it cannot see yet, or be undone by the pending write (#5948).\n\t */\n\tprivate readonly _locks = new Map<IntegrationIds, Promise<void>>();\n\t/** Monotonic across providers; see {@link getSignOutMark}. */\n\tprivate _signOutEpoch = 0;\n\t/** The latest retirement of pending stores per provider, self-managed host, or connection. */\n\tprivate readonly _signOuts = new Map<string, number>();\n\tprivate readonly _storedWriteRetirements: StoredWriteRetirements;\n\tprivate _disposed = false;\n\tget onDidChange(): Event<ConfiguredIntegrationsChangeEvent> {\n\t\treturn this._onDidChange.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 retirements = storedWriteRetirements.get(ctx.storage);\n\t\tif (retirements == null) {\n\t\t\tretirements = { epoch: 0, scopes: new Map() };\n\t\t\tstoredWriteRetirements.set(ctx.storage, retirements);\n\t\t}\n\t\tthis._storedWriteRetirements = retirements;\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 _configured?: Map<IntegrationIds, ConfiguredIntegrationDescriptor[]>;\n\tprivate get configured(): Map<IntegrationIds, ConfiguredIntegrationDescriptor[]> {\n\t\tif (this._configured == null) {\n\t\t\tthis._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\t// Backfill a stable connection id for pre-multi-account stored data: the domain for\n\t\t\t\t\t// self-managed hosts, or the provider's canonical domain for cloud (which is the legacy\n\t\t\t\t\t// secret-key session id), so existing secrets keep resolving with zero migration. Fall back\n\t\t\t\t\t// to the integration id (never empty) when no domain is known — self-managed providers carry\n\t\t\t\t\t// `domain: ''` in metadata, and an empty id would collide across connections and produce\n\t\t\t\t\t// ambiguous secret keys (`...|`).\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._configured.set(id, descriptors);\n\t\t\t}\n\t\t}\n\n\t\treturn this._configured;\n\t}\n\n\t// Synchronous: reads the in-memory configured map (lazily hydrated from storage). No async work —\n\t// the old async variant only existed to weave in the built-in VS Code GitHub session, which is gone.\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 async storeConfigured(): Promise<void> {\n\t\t// We need to convert the map to a record to store\n\t\tconst configured: StoredIntegrationConfigurations = {} as unknown as StoredIntegrationConfigurations;\n\t\tfor (const [id, descriptors] of this.configured) {\n\t\t\tconfigured[id] = descriptors.map(d => ({\n\t\t\t\t...d,\n\t\t\t\texpiresAt: d.expiresAt\n\t\t\t\t\t? d.expiresAt instanceof Date\n\t\t\t\t\t\t? d.expiresAt.toISOString()\n\t\t\t\t\t\t: d.expiresAt\n\t\t\t\t\t: undefined,\n\t\t\t}));\n\t\t}\n\n\t\tconst pending = this.storeConfiguredQueue.then(() =>\n\t\t\tthis.ctx.storage.store('integrations:configured', configured),\n\t\t);\n\t\tthis.storeConfiguredQueue = pending.catch(() => {});\n\t\tawait 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\t// Key connections by their stable id (+ cloud, to preserve legacy local/cloud coexistence) so\n\t\t// multiple accounts on the same provider+domain no longer overwrite each other.\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\t// remove the existing descriptor from the array\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\tthis.configured.set(descriptor.integrationId, descriptors);\n\n\t\tif (changed) {\n\t\t\tthis.fireChange(descriptor.integrationId);\n\t\t}\n\t\tawait this.storeConfigured();\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\tthis.configured.set(id, descriptors);\n\t\tthis.fireChange(undefined, id);\n\t\tawait this.storeConfigured();\n\t}\n\n\tprivate withLock<T>(id: IntegrationIds, fn: () => Promise<T>): Promise<T> {\n\t\tconst run = (this._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\tthis._locks.set(id, settled);\n\t\tvoid settled.then(() => {\n\t\t\tif (this._locks.get(id) === settled) {\n\t\t\t\tthis._locks.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._signOutEpoch;\n\t}\n\n\tprivate retirePendingStores(scope: string): void {\n\t\tthis._signOuts.set(scope, ++this._signOutEpoch);\n\t\tthis.retireStoredWrites(scope);\n\t}\n\n\tgetStoredWriteMark(): number {\n\t\treturn this._storedWriteRetirements.epoch;\n\t}\n\n\tisStoredWriteRetiredSince(\n\t\tid: IntegrationIds,\n\t\tsession: Pick<ProviderAuthenticationSession, 'id' | 'domain'>,\n\t\tmark: number,\n\t): boolean {\n\t\treturn this._disposed || this.hasRetirement(this._storedWriteRetirements.scopes, id, session, mark);\n\t}\n\n\tprivate retireStoredWrites(scope: string): void {\n\t\tconst retirements = this._storedWriteRetirements;\n\t\tretirements.scopes.set(scope, ++retirements.epoch);\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'>,\n\t\tmark: number,\n\t): boolean {\n\t\treturn this.hasRetirement(this._signOuts, id, session, mark);\n\t}\n\n\tprivate hasRetirement(\n\t\tscopes: ReadonlyMap<string, number>,\n\t\tid: IntegrationIds,\n\t\tsession: Pick<ProviderAuthenticationSession, 'id' | 'domain'>,\n\t\tmark: number,\n\t): boolean {\n\t\tconst since = (scope: string) => (scopes.get(scope) ?? 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?: { signOutMark?: number; resource?: ConnectionResource; expectedStoredAccessToken?: string },\n\t): Promise<boolean> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tif (options?.signOutMark != null && this.isSessionRetiredSince(id, session, options.signOutMark)) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst previous = await this.readSecret(id, session.id, session.cloud);\n\t\t\tif (\n\t\t\t\toptions?.expectedStoredAccessToken != null &&\n\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\tif (getSessionIdentity(previous) !== getSessionIdentity(session)) {\n\t\t\t\tif (previous != null) {\n\t\t\t\t\tthis.retireStoredWrites(`${id}|connection:${session.id}`);\n\t\t\t\t}\n\n\t\t\t\t// Readers share this lock, so none can resolve the retired token after this synchronous fence.\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\tawait this.writeSecret(id, session, options?.resource);\n\t\t\tif (\n\t\t\t\toptions?.expectedStoredAccessToken != null &&\n\t\t\t\tsession.accessToken !== options.expectedStoredAccessToken\n\t\t\t) {\n\t\t\t\tthis.retirePendingStores(`${id}|connection:${session.id}`);\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\t}\n\n\tasync peekStoredSession(\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\tconst json = await this.ctx.storage.getSecret(this.getSecretKey(id, connectionId, cloud));\n\t\t\tif (json == null) return undefined;\n\n\t\t\ttry {\n\t\t\t\treturn convertStoredSessionToSession(\n\t\t\t\t\tJSON.parse(json) as StoredSession,\n\t\t\t\t\t{ connectionId: connectionId, domain: domain, scopes: [] },\n\t\t\t\t\tcloud,\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t});\n\t}\n\n\tgetStoredSession(\n\t\tid: IntegrationIds,\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\t// Under the lock too: reading can repair storage (a legacy local-key cloud session, a missing descriptor).\n\t\treturn this.withLock(id, async () => {\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\n\t\t\tlet cloudIfMissing = false;\n\t\t\tif (session != null) {\n\t\t\t\t// Check the `expiresAt` field\n\t\t\t\t// If it has an expiresAt property and the key is the old type, then it's a cloud session,\n\t\t\t\t// so delete it from the local key and\n\t\t\t\t// store with the \"cloud\" type key, and then use that one.\n\t\t\t\t// Otherwise it's a local session under the local key, so just return it.\n\t\t\t\tif (session.expiresAt != null) {\n\t\t\t\t\tcloudIfMissing = true;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait this.deleteSecrets(id, session.id);\n\t\t\t\t\t\tawait this.writeSecret(id, session);\n\t\t\t\t\t} catch {}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If no local session we try to restore a session with the cloud key\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 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?: { preserveConfigured?: boolean; signOut?: boolean; signOutMark?: number },\n\t): Promise<boolean> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tconst connectionId = this.resolveConnectionId(id, descriptor);\n\t\t\tif (\n\t\t\t\toptions?.signOutMark != null &&\n\t\t\t\tthis.isSessionRetiredSince(id, { id: connectionId, domain: descriptor.domain }, options.signOutMark)\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\tthis._onWillRemoveSessions.fire({\n\t\t\t\tintegrationId: id,\n\t\t\t\tconnectionId: connectionId,\n\t\t\t\tcloud: cloud,\n\t\t\t\tdomain: descriptor.domain,\n\t\t\t});\n\t\t\tawait this.deleteSecrets(id, connectionId, cloud, options);\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(id: IntegrationIds, cloud?: boolean, domain?: string): Promise<void> {\n\t\treturn this.withLock(id, async () => {\n\t\t\tthis.retirePendingStores(\n\t\t\t\tisSelfManagedHostIntegrationId(id) && domain != null ? this.getHostScope(id, domain) : id,\n\t\t\t);\n\t\t\tthis._onWillRemoveSessions.fire({ integrationId: id, cloud: cloud, domain: domain });\n\t\t\tawait this.deleteAllSecrets(id, cloud, domain);\n\t\t});\n\t}\n\n\t/**\n\t * Reclaims all stored configuration + secrets for the given (typically retired) integration ids.\n\t * Used to clean up state left behind when an id is removed from the model — e.g. the local\n\t * self-managed `github-enterprise`/`gitlab-self-hosted` ids dropped when integrations went cloud-only.\n\t * Domains are read from the stored config (secrets are keyed by domain); ids with no stored config\n\t * are a no-op.\n\t */\n\tasync purgeStoredConfiguration(ids: readonly string[]): Promise<void> {\n\t\tconst stored =\n\t\t\tthis.ctx.storage.get<Record<string, StoredConfiguredIntegrationDescriptor[] | undefined>>(\n\t\t\t\t'integrations:configured',\n\t\t\t);\n\t\tif (stored == null) return;\n\n\t\tlet changed = false;\n\t\tfor (const id of ids) {\n\t\t\tif (!(id in stored)) continue;\n\n\t\t\tfor (const descriptor of stored[id] ?? []) {\n\t\t\t\t// Mirror the hydration backfill so the secret keys we delete match what was written: fall back\n\t\t\t\t// through domain, the provider's canonical domain, then the integration id (never empty). A\n\t\t\t\t// legacy cloud descriptor stored neither id nor domain, so an empty connection id here would\n\t\t\t\t// miss the canonical-domain secret (e.g. `integration.auth.cloud:github|github.com`) and orphan it.\n\t\t\t\tconst connectionId =\n\t\t\t\t\tdescriptor.id || descriptor.domain || providersMetadata[id as IntegrationIds]?.domain || id;\n\t\t\t\tawait this.ctx.storage.deleteSecret(this.getLocalSecretKey(id as IntegrationIds, connectionId));\n\t\t\t\tawait this.ctx.storage.deleteSecret(this.getCloudSecretKey(id as IntegrationIds, connectionId));\n\t\t\t\tif (descriptor.domain) {\n\t\t\t\t\tawait this.ctx.storage.deleteWorkspace(`connected:${id}:${descriptor.domain}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tchanged = true;\n\t\t}\n\t\tif (!changed) return;\n\n\t\tconst remaining = Object.fromEntries(Object.entries(stored).filter(([key]) => !ids.includes(key)));\n\t\tawait this.ctx.storage.store('integrations:configured', remaining as StoredIntegrationConfigurations);\n\t}\n\n\tprivate async deleteSecrets(\n\t\tid: IntegrationIds,\n\t\tconnectionId: string,\n\t\tcloud?: boolean,\n\t\toptions?: { preserveConfigured?: boolean },\n\t): Promise<void> {\n\t\tthis.retireStoredWrites(`${id}|connection:${connectionId}`);\n\t\tif (cloud == null || cloud === false) {\n\t\t\tawait this.ctx.storage.deleteSecret(this.getLocalSecretKey(id, connectionId));\n\t\t}\n\n\t\tif (cloud == null || cloud === true) {\n\t\t\tawait this.ctx.storage.deleteSecret(this.getCloudSecretKey(id, connectionId));\n\t\t}\n\n\t\tif (options?.preserveConfigured) return;\n\n\t\tawait this.removeConfigured(id, { connectionId: connectionId, cloud: cloud });\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): 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(session),\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 (sessionJSON) {\n\t\t\t\tstoredSession = JSON.parse(sessionJSON);\n\t\t\t\tif (storedSession != null) {\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\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(id: IntegrationIds, connectionId: string): Promise<void> {\n\t\treturn this.withLock(id, () => this.setPrimaryConnectionCore(id, connectionId));\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\tthis.configured.set(id, updated);\n\t\tthis.fireChange(id);\n\t\tawait this.storeConfigured();\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\t// The connection is gone, so a token of it fetched before must not be stored back.\n\t\t\tthis.retirePendingStores(`${id}|connection:${connectionId}`);\n\t\t\tthis._onWillRemoveSessions.fire({ integrationId: id, connectionId: connectionId, cloud: cloud });\n\t\t\tawait this.deleteSecrets(id, connectionId, cloud);\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 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":";;;;;;;;AAwDA,MAAM,yCAAyB,IAAI,QAAsE;AAEzG,IAAa,+BAAb,MAAgE;CAgClC;CA/B7B,eAAgC,IAAI,QAA2C;CAC/E,uBAAwC,IAAI,QAAuC;CACnF,wBAAyC,IAAI,QAK1C;CACH,uBAA8C,QAAQ,QAAQ;;;;;;CAM9D,yBAA0B,IAAI,IAAmC;;CAEjE,gBAAwB;;CAExB,4BAA6B,IAAI,IAAoB;CACrD;CACA,YAAoB;CACpB,IAAI,cAAwD;EAC3D,OAAO,KAAK,aAAa;CAC1B;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,cAAc,uBAAuB,IAAI,IAAI,OAAO;EACxD,IAAI,eAAe,MAAM;GACxB,cAAc;IAAE,OAAO;IAAG,wBAAQ,IAAI,IAAI;GAAE;GAC5C,uBAAuB,IAAI,IAAI,SAAS,WAAW;EACpD;EACA,KAAK,0BAA0B;CAChC;CAEA,UAA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,OAAO,cAAc,SAAS;EAC9B,WAAW,cAAc,YAAY,IAAI,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"}
|
|
@@ -55,12 +55,12 @@ var IntegrationAuthenticationService = class {
|
|
|
55
55
|
}
|
|
56
56
|
trackStoredSession(id, session) {
|
|
57
57
|
const store = this.configuredIntegrationService;
|
|
58
|
-
const mark = store.
|
|
58
|
+
const mark = store.getStoredWriteMark();
|
|
59
59
|
const identity = getSessionIdentity(session);
|
|
60
60
|
return async () => {
|
|
61
|
-
if (store.
|
|
61
|
+
if (store.isStoredWriteRetiredSince(id, session, mark)) return false;
|
|
62
62
|
const current = await store.peekStoredSession(id, session.id, session.cloud ?? false, session.domain).catch(() => void 0);
|
|
63
|
-
return current != null && !store.
|
|
63
|
+
return current != null && !store.isStoredWriteRetiredSince(id, session, mark) && getSessionIdentity(current) === identity && current.account?.id === session.account?.id;
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
/** The id of the connection a descriptor naming none reads: the primary configured for its host. */
|