@gitkraken/core-gitlens 0.37.0 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/CHANGELOG.md +67 -1
  2. package/dist/git/cache.d.ts +128 -8
  3. package/dist/git/cache.js +425 -46
  4. package/dist/git/cache.js.map +1 -1
  5. package/dist/git/features.d.ts +1 -1
  6. package/dist/git/features.js +3 -0
  7. package/dist/git/features.js.map +1 -1
  8. package/dist/git/providers/branches.d.ts +42 -1
  9. package/dist/git/providers/diff.d.ts +17 -0
  10. package/dist/git/providers/provider.d.ts +7 -0
  11. package/dist/git/providers/shared/remotes.js +8 -4
  12. package/dist/git/providers/shared/remotes.js.map +1 -1
  13. package/dist/git/remotes/matcher.js +2 -2
  14. package/dist/git/remotes/matcher.js.map +1 -1
  15. package/dist/git/repositoryService.d.ts +16 -1
  16. package/dist/git/repositoryService.js +51 -3
  17. package/dist/git/repositoryService.js.map +1 -1
  18. package/dist/git/run.types.d.ts +1 -0
  19. package/dist/git/service.js +6 -2
  20. package/dist/git/service.js.map +1 -1
  21. package/dist/git/utils/fileStatus.utils.d.ts +5 -0
  22. package/dist/git/utils/fileStatus.utils.js +18 -1
  23. package/dist/git/utils/fileStatus.utils.js.map +1 -1
  24. package/dist/git/watching/changeEvent.d.ts +13 -3
  25. package/dist/git/watching/changeEvent.js +15 -4
  26. package/dist/git/watching/changeEvent.js.map +1 -1
  27. package/dist/git/watching/changeOrdinal.d.ts +9 -0
  28. package/dist/git/watching/changeOrdinal.js +14 -0
  29. package/dist/git/watching/changeOrdinal.js.map +1 -0
  30. package/dist/git/watching/unwatchedCacheValidator.d.ts +38 -5
  31. package/dist/git/watching/unwatchedCacheValidator.js +180 -36
  32. package/dist/git/watching/unwatchedCacheValidator.js.map +1 -1
  33. package/dist/git/watching/watchGroup.d.ts +63 -14
  34. package/dist/git/watching/watchGroup.js +213 -74
  35. package/dist/git/watching/watchGroup.js.map +1 -1
  36. package/dist/git/watching/watchService.js +4 -3
  37. package/dist/git/watching/watchService.js.map +1 -1
  38. package/dist/git/watching/watchSession.d.ts +10 -2
  39. package/dist/git/watching/watchSession.js +18 -4
  40. package/dist/git/watching/watchSession.js.map +1 -1
  41. package/dist/git/watching/watcherPatterns.d.ts +18 -4
  42. package/dist/git/watching/watcherPatterns.js +39 -8
  43. package/dist/git/watching/watcherPatterns.js.map +1 -1
  44. package/dist/git/watching/worktreeSummary.d.ts +23 -12
  45. package/dist/git/watching/worktreeSummary.js +164 -41
  46. package/dist/git/watching/worktreeSummary.js.map +1 -1
  47. package/dist/git-cli/cliGitProvider.d.ts +1 -0
  48. package/dist/git-cli/cliGitProvider.js +11 -2
  49. package/dist/git-cli/cliGitProvider.js.map +1 -1
  50. package/dist/git-cli/exec/git.d.ts +7 -2
  51. package/dist/git-cli/exec/git.js +46 -10
  52. package/dist/git-cli/exec/git.js.map +1 -1
  53. package/dist/git-cli/exec/headState.d.ts +24 -0
  54. package/dist/git-cli/exec/headState.js +46 -6
  55. package/dist/git-cli/exec/headState.js.map +1 -1
  56. package/dist/git-cli/parsers/logParser.js +6 -3
  57. package/dist/git-cli/parsers/logParser.js.map +1 -1
  58. package/dist/git-cli/providers/branches.d.ts +135 -10
  59. package/dist/git-cli/providers/branches.js +622 -80
  60. package/dist/git-cli/providers/branches.js.map +1 -1
  61. package/dist/git-cli/providers/commits.d.ts +16 -0
  62. package/dist/git-cli/providers/commits.js +80 -28
  63. package/dist/git-cli/providers/commits.js.map +1 -1
  64. package/dist/git-cli/providers/config.d.ts +10 -0
  65. package/dist/git-cli/providers/config.js +50 -12
  66. package/dist/git-cli/providers/config.js.map +1 -1
  67. package/dist/git-cli/providers/contributors.js +11 -7
  68. package/dist/git-cli/providers/contributors.js.map +1 -1
  69. package/dist/git-cli/providers/diff.d.ts +12 -0
  70. package/dist/git-cli/providers/diff.js +107 -15
  71. package/dist/git-cli/providers/diff.js.map +1 -1
  72. package/dist/git-cli/providers/graph.js +32 -25
  73. package/dist/git-cli/providers/graph.js.map +1 -1
  74. package/dist/git-cli/providers/operations.d.ts +37 -3
  75. package/dist/git-cli/providers/operations.js +124 -46
  76. package/dist/git-cli/providers/operations.js.map +1 -1
  77. package/dist/git-cli/providers/patch.js +1 -1
  78. package/dist/git-cli/providers/patch.js.map +1 -1
  79. package/dist/git-cli/providers/refs.d.ts +1 -1
  80. package/dist/git-cli/providers/refs.js +10 -11
  81. package/dist/git-cli/providers/refs.js.map +1 -1
  82. package/dist/git-cli/providers/status.d.ts +4 -5
  83. package/dist/git-cli/providers/status.js +36 -33
  84. package/dist/git-cli/providers/status.js.map +1 -1
  85. package/dist/git-cli/providers/tags.d.ts +8 -0
  86. package/dist/git-cli/providers/tags.js +53 -34
  87. package/dist/git-cli/providers/tags.js.map +1 -1
  88. package/dist/git-cli/service.d.ts +15 -0
  89. package/dist/git-cli/service.js +19 -1
  90. package/dist/git-cli/service.js.map +1 -1
  91. package/dist/plus/git-github/api/github.d.ts +4 -0
  92. package/dist/plus/git-github/api/github.js +11 -1
  93. package/dist/plus/git-github/api/github.js.map +1 -1
  94. package/dist/plus/git-github/providers/github/diff.d.ts +1 -0
  95. package/dist/plus/git-github/providers/github/diff.js +6 -1
  96. package/dist/plus/git-github/providers/github/diff.js.map +1 -1
  97. package/dist/plus/integrations/integrationService.js +9 -0
  98. package/dist/plus/integrations/integrationService.js.map +1 -1
  99. package/dist/plus/integrations/providers/jira-server.js +1 -1
  100. package/dist/plus/integrations/providers/jira-server.js.map +1 -1
  101. package/dist/plus/integrations/providers/jira.d.ts +38 -6
  102. package/dist/plus/integrations/providers/jira.js +111 -69
  103. package/dist/plus/integrations/providers/jira.js.map +1 -1
  104. package/dist/plus/integrations/providers/linear.d.ts +31 -3
  105. package/dist/plus/integrations/providers/linear.js +77 -18
  106. package/dist/plus/integrations/providers/linear.js.map +1 -1
  107. package/dist/plus/integrations/providers/utils/discoveryCache.d.ts +41 -4
  108. package/dist/plus/integrations/providers/utils/discoveryCache.js +50 -11
  109. package/dist/plus/integrations/providers/utils/discoveryCache.js.map +1 -1
  110. package/dist/utils/env/node/exec.d.ts +5 -4
  111. package/dist/utils/env/node/exec.js +52 -9
  112. package/dist/utils/env/node/exec.js.map +1 -1
  113. package/dist/utils/holdOffMap.d.ts +23 -0
  114. package/dist/utils/holdOffMap.js +43 -0
  115. package/dist/utils/holdOffMap.js.map +1 -0
  116. package/dist/utils/promiseCache.d.ts +15 -2
  117. package/dist/utils/promiseCache.js +34 -4
  118. package/dist/utils/promiseCache.js.map +1 -1
  119. package/package.json +1 -1
@@ -164,7 +164,7 @@ var JiraServerIntegration = class extends IssuesIntegration {
164
164
  const generation = this._projects.generation;
165
165
  const descriptors = await this.readProjects(session);
166
166
  if (descriptors == null) return void 0;
167
- if (this._projects.set(cacheKey, descriptors, { generation })) this._autolinks.delete(cacheKey);
167
+ if (this._projects.set(cacheKey, descriptors, { generation }) !== false) this._autolinks.delete(cacheKey);
168
168
  return descriptors;
169
169
  }
170
170
  async getProviderUncachedProjectsForResourcesWithMetadata(session, resources) {
@@ -1 +1 @@
1
- {"version":3,"file":"jira-server.js","names":[],"sources":["../../../../../plus/integrations/src/providers/jira-server.ts"],"sourcesContent":["import type { CollectionMetadata } from '@gitkraken/provider-apis';\nimport { JIRA_MAX_PROJECT_KEYS_PER_REQUEST } from '@gitkraken/provider-apis';\nimport type { Account } from '@gitlens/git/models/author.js';\nimport type { AutolinkReference } from '@gitlens/git/models/autolink.js';\nimport type { Issue, IssueProjection, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type { IssueResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport type { Emitter } from '@gitlens/utils/event.js';\nimport { Logger } from '@gitlens/utils/logger.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService.js';\nimport type { ProviderAuthenticationSession } from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { isIncompleteCollection, toCollectionScopeFailure } from '../collectionMetadata.js';\nimport { IssuesSelfManagedHostIntegrationId } from '../constants.js';\nimport type { IntegrationServiceContext } from '../context.js';\nimport type { IntegrationConnectionChangeEvent } from '../integrationService.js';\nimport type { IntegrationKey } from '../models/integration.js';\nimport type {\n\tAccountWideIssuesResult,\n\tIssuesForProjectOptions,\n\tProjectIssuesDrain,\n\tProjectIssuesRequest,\n\tSearchMyIssuesOptions,\n} from '../models/issueReads.js';\nimport { groupProjectIssuesSearches, IssuesIntegration, toProjectsCollection } from '../models/issuesIntegration.js';\nimport { areDomainsOnSameHost, baseUrlFromDomain } from '../utils/domain.utils.js';\nimport type { ProviderApiCollectionResult } from './models.js';\nimport { providersMetadata, toAccount, toIssueShape, toProviderIssueStates } from './models.js';\nimport { isJiraServerMissingProjectError } from './providerErrors.js';\nimport type { ProvidersApi } from './providersApi.js';\nimport { DiscoveryCache, discoveryCacheTtl } from './utils/discoveryCache.js';\nimport { createIssueAutolinkReferences } from './utils/issueAutolinks.js';\nimport type { JiraDrainOptions, JiraIssuePageFetcher } from './utils/jiraIssueDrains.js';\nimport {\n\tdrainJiraIssues,\n\treadUserScopedJiraIssues,\n\tsearchJiraProjectIssues,\n\tsummarizePageMetadata,\n\ttoUniqueJiraIssueShapes,\n\twithFailureScope,\n} from './utils/jiraIssueDrains.js';\nimport { mergeCollectionMetadata } from './utils/providerPaging.js';\n\nconst metadata = providersMetadata[IssuesSelfManagedHostIntegrationId.JiraServer];\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\nconst maxPagesPerRequest = 10;\n\n/**\n * Every clause is scoped by the HANDLE, and `options.userId` is deliberately ignored here — the one\n * place this provider diverges from Jira Cloud's, which applies it to `assignee`/`creator` (#5857).\n *\n * The two are not interchangeable because `Account.id` means something different per deployment. On\n * Cloud it is the `accountId`, which JQL resolves, so scoping by it fixes the deactivated-account case\n * where the display name no longer resolves. On Server it is the user KEY (`JIRAUSER10224`), which JQL\n * does not resolve at all: measured against a live Jira Server 8.20.13 site, `assignee in\n * (\"JIRAUSER10224\")` returns 0 with `\"The value 'JIRAUSER10224' does not exist for the field\n * 'assignee'\"` — the identical warning a genuinely nonexistent user produces — while the username and\n * the display name both return the real 4.\n *\n * So applying `userId` here would silently empty the read rather than harden it. Do not \"fix\" this\n * asymmetry to match Cloud without re-measuring against a Server instance.\n *\n * The handle itself is already the right one: `provider-apis` 0.60.0 maps `Account.username` from the\n * Server payload's `name` (falling back to `displayName` when absent), so these clauses are scoped by the\n * real username rather than a display name (GKDEV-3629). That is what makes the `mention` clause work at\n * all — it is a free-text `comment ~ \"...\"` over comment bodies, and a Jira mention is stored as\n * `[~username]`, which a display name never matches.\n */\nfunction toUserIdentities(user: string): { userField: string; mention: string } {\n\treturn { userField: user, mention: user };\n}\n\n/**\n * The single resource a Jira Server connection has: the instance itself.\n *\n * Jira Cloud's account spans many sites, so its resources come from an API call that lists them. A\n * self-hosted instance IS the one site the connection addresses, so there is nothing to enumerate — this\n * descriptor is synthesized from the configured host. Modelling it as a resource anyway keeps the\n * resource → project contract of {@link IssuesIntegration} intact, so every tracker read (`listOrgs`,\n * `listProjects`, `listIssueTrackerIssuesPage`) works unchanged.\n */\nexport interface JiraServerResourceDescriptor extends IssueResourceDescriptor {\n\turl: string;\n}\n\nexport interface JiraServerProjectDescriptor extends IssueResourceDescriptor {\n\tresourceId: string;\n}\n\nexport class JiraServerIntegration extends IssuesIntegration<IssuesSelfManagedHostIntegrationId.JiraServer> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\treadonly id = IssuesSelfManagedHostIntegrationId.JiraServer;\n\tprotected readonly key: IntegrationKey<IssuesSelfManagedHostIntegrationId.JiraServer>;\n\treadonly name: string = 'Jira Data Center';\n\n\tconstructor(\n\t\tctx: IntegrationServiceContext,\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tgetProvidersApi: () => Promise<ProvidersApi>,\n\t\tdidChangeConnection: Emitter<IntegrationConnectionChangeEvent>,\n\t\tprivate readonly _domain: string,\n\t) {\n\t\tsuper(ctx, authenticationService, getProvidersApi, didChangeConnection);\n\t\tthis.key = `${this.id}:${this._domain}`;\n\t}\n\n\tget domain(): string {\n\t\treturn this._domain;\n\t}\n\n\t/**\n\t * The URL every request for this connection is addressed to, built from the SESSION's domain rather than\n\t * the integration's.\n\t *\n\t * `this.domain` is the host-keyed identity — `IntegrationService.get()` runs it through `hostFromDomain`\n\t * so one host can't build two instances — which means it has had any context path stripped, and so has\n\t * `session.domain`, which is stored as that same normalized host. Jira Data Center officially supports\n\t * being mounted below a context path (`https://jira.example.com/jira`), so the address comes from\n\t * {@link ProviderAuthenticationSession.baseUrl}, which carries the configured value verbatim; it falls\n\t * back to the host when the backend reported nothing more, which is the common case.\n\t *\n\t * Takes the session rather than reading `_session` so a per-connection (multi-account) read is addressed\n\t * to the host of the connection it resolved, not to whichever one happens to be current.\n\t */\n\tprotected apiBaseUrlFor(session: ProviderAuthenticationSession | undefined): string {\n\t\tconst configured = baseUrlFromDomain(session?.baseUrl, session?.protocol);\n\t\t// A `baseUrl` from another host is not this connection's address — refuse it rather than routing this\n\t\t// integration's reads somewhere its key never named.\n\t\tif (configured != null && areDomainsOnSameHost(session?.baseUrl, this.domain)) return configured;\n\n\t\treturn (\n\t\t\tbaseUrlFromDomain(session?.domain, session?.protocol) ??\n\t\t\tbaseUrlFromDomain(this.domain, session?.protocol) ??\n\t\t\t`${session?.protocol ?? 'https:'}//${this.domain}`\n\t\t);\n\t}\n\n\t/** The one resource this connection has — see {@link JiraServerResourceDescriptor}. */\n\tprivate resourceFor(session: ProviderAuthenticationSession | undefined): JiraServerResourceDescriptor {\n\t\treturn { id: this.domain, key: this.domain, name: this.domain, url: this.apiBaseUrlFor(session) };\n\t}\n\n\tprivate readonly _autolinks = new Map<string, { autolinks: AutolinkReference[]; builtAt: number }>();\n\tprivate readonly _autolinksBuilds = new Map<string, Promise<AutolinkReference[]>>();\n\n\toverride async autolinks(): Promise<AutolinkReference[]> {\n\t\tconst generation = this.discoveryGeneration;\n\t\tconst connected = this.maybeConnected ?? (await this.isConnected());\n\t\tif (!connected || this._session == null) return [];\n\t\tif (!this.isResolvedSessionCurrent(this._session, generation)) return [];\n\n\t\tconst session = this._session;\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tconst cached = this._autolinks.get(cacheKey);\n\t\tif (this.connectionExpired === true) return cached?.autolinks ?? [];\n\t\tif (cached == null) return this.buildAutolinks(session);\n\n\t\tif (Date.now() - cached.builtAt >= discoveryCacheTtl) {\n\t\t\tvoid this.buildAutolinks(session);\n\t\t}\n\t\treturn cached.autolinks;\n\t}\n\n\tprivate buildAutolinks(session: ProviderAuthenticationSession): Promise<AutolinkReference[]> {\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tlet build = this._autolinksBuilds.get(cacheKey);\n\t\tif (build == null) {\n\t\t\tbuild = this.buildAutolinksCore(session).finally(() => {\n\t\t\t\tif (this._autolinksBuilds.get(cacheKey) === build) {\n\t\t\t\t\tthis._autolinksBuilds.delete(cacheKey);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._autolinksBuilds.set(cacheKey, build);\n\t\t}\n\t\treturn build;\n\t}\n\n\tprivate async buildAutolinksCore(session: ProviderAuthenticationSession): Promise<AutolinkReference[]> {\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tconst generation = this._projects.generation;\n\t\ttry {\n\t\t\tconst resource = this.resourceFor(session);\n\t\t\tconst result = await this.getProjectsForResourcesWithMetadataResult([resource]);\n\t\t\tif (this._projects.generation !== generation) return [];\n\t\t\tif (result?.value == null || result.error != null || isIncompleteCollection(result.value.metadata)) {\n\t\t\t\treturn this._autolinks.get(cacheKey)?.autolinks ?? [];\n\t\t\t}\n\n\t\t\tconst autolinks: AutolinkReference[] = [];\n\t\t\tfor (const project of result.value.values) {\n\t\t\t\tif (project.key === project.id) continue;\n\n\t\t\t\tautolinks.push(\n\t\t\t\t\t...createIssueAutolinkReferences(\n\t\t\t\t\t\tproject.key,\n\t\t\t\t\t\t`${resource.url}/browse/${project.key}-<num>`,\n\t\t\t\t\t\tresource,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis._autolinks.set(cacheKey, { autolinks: autolinks, builtAt: Date.now() });\n\t\t\treturn autolinks;\n\t\t} catch (ex) {\n\t\t\tLogger.error(ex, 'JiraServerIntegration.autolinks');\n\t\t\treturn this._autolinks.get(cacheKey)?.autolinks ?? [];\n\t\t}\n\t}\n\n\tprotected override async getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: JiraServerResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api.getJiraServerCurrentUser(toTokenWithInfo(this.id, session), this.apiBaseUrlFor(session));\n\n\t\tif (user == null) return undefined;\n\t\treturn toAccount(user, this);\n\t}\n\n\tprotected override getProviderResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_force?: boolean,\n\t): Promise<JiraServerResourceDescriptor[] | undefined> {\n\t\t// Synthesized from the configured host rather than fetched, so there is nothing to cache or force.\n\t\treturn Promise.resolve([this.resourceFor(session)]);\n\t}\n\n\t/** Expires, and is dropped on a re-sync, so a project created or deleted mid-session is picked up (#5907). */\n\tprivate readonly _projects = new DiscoveryCache<JiraServerProjectDescriptor[]>();\n\tprivate readonly _projectReads = new Map<string, Promise<JiraServerProjectDescriptor[] | undefined>>();\n\tprotected override getProviderProjectsForResources(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: JiraServerResourceDescriptor[],\n\t): Promise<JiraServerProjectDescriptor[] | undefined> {\n\t\t// Every resource here is this instance (see `getProviderResourcesForUser`), so one read serves them\n\t\t// all; a caller that passes none is asking for nothing.\n\t\tif (resources.length === 0) return Promise.resolve([]);\n\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tconst cached = this._projects.get(cacheKey);\n\t\tif (cached != null) return Promise.resolve(cached);\n\n\t\tlet read = this._projectReads.get(cacheKey);\n\t\tif (read == null) {\n\t\t\tread = this.readProjectsCached(session, cacheKey).finally(() => {\n\t\t\t\tif (this._projectReads.get(cacheKey) === read) {\n\t\t\t\t\tthis._projectReads.delete(cacheKey);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._projectReads.set(cacheKey, read);\n\t\t}\n\t\treturn read;\n\t}\n\n\tprivate async readProjectsCached(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcacheKey: string,\n\t): Promise<JiraServerProjectDescriptor[] | undefined> {\n\t\tconst generation = this._projects.generation;\n\t\tconst descriptors = await this.readProjects(session);\n\t\tif (descriptors == null) return undefined;\n\n\t\tif (this._projects.set(cacheKey, descriptors, { generation: generation })) {\n\t\t\tthis._autolinks.delete(cacheKey);\n\t\t}\n\n\t\treturn descriptors;\n\t}\n\n\tprotected override async getProviderUncachedProjectsForResourcesWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: JiraServerResourceDescriptor[],\n\t): Promise<ProviderApiCollectionResult<JiraServerProjectDescriptor>> {\n\t\tif (resources.length === 0) return { values: [] };\n\n\t\treturn toProjectsCollection(await this.readProjects(session));\n\t}\n\n\tprivate async readProjects(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<JiraServerProjectDescriptor[] | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst projects = await api.getJiraServerProjects(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t\tif (projects == null) return undefined;\n\t\tif (projects.length === 0) {\n\t\t\t// Jira can serve anonymous empty projects after rejection without an identifying response header.\n\t\t\tconst account = await this.getProviderAccountForResource(session, this.resourceFor(session));\n\t\t\tif ((account?.username ?? account?.name) == null) return undefined;\n\t\t}\n\n\t\tconst resourceId = this.resourceFor(session).id;\n\t\treturn projects.map<JiraServerProjectDescriptor>(p => ({\n\t\t\tid: p.id,\n\t\t\t// The project key, which selects the project (`listProjects`' `name`) and is what an issue key starts\n\t\t\t// with. The SDK does not validate it, so a missing or blank one falls back to the numeric id, never to the\n\t\t\t// display name, which can equal another project's key. The reads below still address the project by\n\t\t\t// `id`, which no other project can share.\n\t\t\tkey: p.key?.trim() || p.id,\n\t\t\tname: p.name,\n\t\t\tresourceId: resourceId,\n\t\t}));\n\t}\n\n\tprotected override async getProviderIssuesForProject(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: JiraServerProjectDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.getProviderIssuesForProjectWithTruncation(session, project, options))?.values;\n\t}\n\n\tprotected override async getProviderIssuesForProjectWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: JiraServerProjectDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<ProjectIssuesDrain | undefined> {\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst api = await this.getProvidersApi();\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\n\t\t// The same drain as Jira Cloud's (`jiraIssueDrains.ts`): page to a defensive backstop, and report `truncated`\n\t\t// plus a structured failure rather than discarding an already-fetched prefix.\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\t// The numeric project id, not the name: JQL resolves `project = \"<value>\"` against key first, so a display\n\t\t// name that matches another project's key reads that project's issues instead. A Jira project key must begin\n\t\t// with a letter, so a purely numeric value can only be an id.\n\t\tconst fetchPage: JiraIssuePageFetcher = (scope, cursor) =>\n\t\t\tapi.getJiraServerIssuesForProjectPaged(tokenWithInfo, baseUrl, project.id, {\n\t\t\t\t...scope,\n\t\t\t\tcursor: cursor,\n\t\t\t\tstates: states,\n\t\t\t\tsort: options?.sort,\n\t\t\t});\n\t\tconst drainOptions: JiraDrainOptions = {\n\t\t\tmaxPages: maxPagesPerRequest,\n\t\t\t// Scoped by key, as on Jira Cloud: the id addresses the read, the key is how a consumer names the project.\n\t\t\tfailureScope: { providerId: this.id, resourceId: project.resourceId, projectId: project.key },\n\t\t\tproviderName: 'Jira Server',\n\t\t\t// A project this connection can no longer see (deleted, or its browse permission removed) holds\n\t\t\t// no issues for it, and the project list that named it is stale: drop that list so the next read\n\t\t\t// re-reads it, instead of failing the whole provider on every read until a restart (#5907).\n\t\t\tisEmptyFailure: ex => {\n\t\t\t\tif (!isJiraServerMissingProjectError(ex)) return false;\n\n\t\t\t\tLogger.warn(`Jira Server project '${project.name}' (${project.id}) no longer exists or is not visible`);\n\t\t\t\tthis.invalidateDiscoveryCaches();\n\t\t\t\treturn true;\n\t\t\t},\n\t\t};\n\n\t\tif (options?.user != null) {\n\t\t\tconst read = await readUserScopedJiraIssues(\n\t\t\t\tfetchPage,\n\t\t\t\toptions.filters,\n\t\t\t\ttoUserIdentities(options.user),\n\t\t\t\tdrainOptions,\n\t\t\t);\n\t\t\tconst values = toUniqueJiraIssueShapes(read.issues, this);\n\t\t\tconst drain = { values: values, metadata: read.metadata, scope: drainOptions.failureScope };\n\t\t\t// `recovery: 'none'` for the whole set: the filter branches merge here, so even a pure backstop in one\n\t\t\t// branch is not fixable by narrowing this read's scope.\n\t\t\treturn read.truncated ? { ...drain, truncated: true, recovery: 'none' } : { ...drain, truncated: false };\n\t\t}\n\n\t\tconst unscoped = await drainJiraIssues(fetchPage, {}, drainOptions);\n\t\tconst values = unscoped.issues\n\t\t\t.map(issue => toIssueShape(issue, this, { projection: 'project' }))\n\t\t\t.filter((result): result is IssueShape => result !== undefined);\n\t\tconst drain = { values: values, metadata: unscoped.metadata, scope: drainOptions.failureScope };\n\t\treturn unscoped.status !== 'complete'\n\t\t\t? { ...drain, truncated: true, recovery: unscoped.status === 'backstop' ? 'narrow-scope' : 'none' }\n\t\t\t: { ...drain, truncated: false };\n\t}\n\n\t/**\n\t * Searches the instance's projects together for a user-scoped read, as Jira Cloud does per site: one JQL names\n\t * up to {@link JIRA_MAX_PROJECT_KEYS_PER_REQUEST} projects of one user scope. An unscoped read stays per project,\n\t * since its backstop is reported as `narrow-scope` per project.\n\t */\n\tprotected override getProjectIssuesSearches(\n\t\trequests: readonly ProjectIssuesRequest<JiraServerProjectDescriptor>[],\n\t): number[][] | undefined {\n\t\treturn groupProjectIssuesSearches(\n\t\t\trequests,\n\t\t\t({ options }) =>\n\t\t\t\toptions.user != null\n\t\t\t\t\t? [options.user, options.sort ?? '', options.state ?? '', options.filters?.join(',') ?? ''].join(\n\t\t\t\t\t\t\t'\\0',\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined,\n\t\t\tJIRA_MAX_PROJECT_KEYS_PER_REQUEST,\n\t\t);\n\t}\n\n\tprotected override async searchProviderProjectIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\trequests: readonly ProjectIssuesRequest<JiraServerProjectDescriptor>[],\n\t): Promise<IssueShape[][] | undefined> {\n\t\t// Every request of a search shares its user scope (see `getProjectIssuesSearches`).\n\t\tconst { options } = requests[0];\n\t\tif (options.user == null) return undefined;\n\t\t// One project's search is its own read, by the same numeric id, so it costs no more to read it as one. And it\n\t\t// reports what the search can't: a dropped issue's failure, which a search can only answer by being read again.\n\t\tif (requests.length === 1) return undefined;\n\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst api = await this.getProvidersApi();\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\t\t// By numeric id, as the per-project read names them (see there).\n\t\tconst projectIds = requests.map(request => request.project.id);\n\t\tconst states = toProviderIssueStates(options.state);\n\n\t\treturn searchJiraProjectIssues(\n\t\t\t(userScope, cursor) =>\n\t\t\t\tapi.getJiraServerIssuesForProjectsPaged(tokenWithInfo, baseUrl, projectIds, {\n\t\t\t\t\t...userScope,\n\t\t\t\t\tcursor: cursor,\n\t\t\t\t\tstates: states,\n\t\t\t\t\tsort: options.sort,\n\t\t\t\t}),\n\t\t\tprojectIds,\n\t\t\toptions.filters,\n\t\t\ttoUserIdentities(options.user),\n\t\t\t{ maxPages: maxPagesPerRequest, failureScope: { providerId: this.id }, providerName: 'Jira Server' },\n\t\t\tthis,\n\t\t);\n\t}\n\n\tprotected override async searchProviderMyIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: JiraServerResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.searchProviderMyIssuesWithTruncation(session, resources, cancellation))?.values;\n\t}\n\n\t/**\n\t * Account-wide \"my issues\" for this instance, drained to the backstop and reporting whether it got there.\n\t *\n\t * The override exists for the same reason the project drain reports `status`: the default\n\t * implementation wraps whatever the normalized read returned as `truncated: false`, so a run that stopped\n\t * at `maxPagesPerRequest` with pages left, or on a continuation the server never advanced, would be\n\t * published as a complete account. Cancellation is NOT truncation — the caller asked for the stop and\n\t * already knows the prefix is partial — so it breaks without setting the flag.\n\t */\n\tprotected override async searchProviderMyIssuesWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resources?: JiraServerResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchMyIssuesOptions,\n\t): Promise<AccountWideIssuesResult | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\n\t\t// Errors propagate, unlike Jira Cloud's sibling. Cloud swallows per resource because it loops over the\n\t\t// account's many sites and one bad site must not discard the others; this connection addresses exactly\n\t\t// one instance, so there is no sibling to protect and swallowing would turn every failure — an expired\n\t\t// token, an unreachable host — into an empty success. `searchMyIssuesWithTruncationResult` recovers the\n\t\t// throw into `{ error }`, which is what lets the caller warn instead of reporting \"no issues\".\n\t\t// Only the provider: the instance is this connection's single resource, so naming it would publish a\n\t\t// failure of the whole connection as one confined to a sub-scope (see `ProviderWarning.scope`).\n\t\tconst accountScope = { providerId: this.id };\n\t\tconst results: IssueShape[] = [];\n\t\tlet cursor: string | undefined;\n\t\tlet truncated = false;\n\t\tlet metadata: CollectionMetadata | undefined;\n\t\tconst pages: CollectionMetadata[] = [];\n\n\t\tconst stopIncomplete = (reason: string) => {\n\t\t\ttruncated = true;\n\t\t\tmetadata = mergeCollectionMetadata(metadata, {\n\t\t\t\tcompleteness: 'partial',\n\t\t\t\tfailures: [toCollectionScopeFailure(accountScope, new Error(reason))],\n\t\t\t});\n\t\t};\n\n\t\tfor (let i = 0; i < maxPagesPerRequest; i++) {\n\t\t\tif (cancellation?.aborted) break;\n\n\t\t\tconst page = await api.getJiraServerIssuesForCurrentUser(tokenWithInfo, baseUrl, {\n\t\t\t\tcursor: cursor,\n\t\t\t\tstates: states,\n\t\t\t});\n\t\t\tif (page == null) {\n\t\t\t\t// Nothing fetched yet and no page is an empty account, not a failure; after a continuation it\n\t\t\t\t// means the server dropped the drain mid-way.\n\t\t\t\tif (cursor != null) {\n\t\t\t\t\tstopIncomplete('Jira Server returned no page after advertising a continuation');\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tresults.push(\n\t\t\t\t...page.data\n\t\t\t\t\t.map(issue => toIssueShape(issue, this, { projection: 'account' }))\n\t\t\t\t\t.filter((r): r is IssueShape => r != null),\n\t\t\t);\n\t\t\t// An issue the page dropped because it could not be read arrives here, not as a missing row; recorded under\n\t\t\t// the same scope as this read's other failures.\n\t\t\tif (page.metadata != null) {\n\t\t\t\t// Truncated too, as Jira Cloud's read is through `getPagedResult`: the account is missing that issue.\n\t\t\t\ttruncated ||= isIncompleteCollection(page.metadata);\n\t\t\t\tpages.push(withFailureScope(page.metadata, accountScope));\n\t\t\t}\n\n\t\t\tif (!page.hasMore) break;\n\n\t\t\t// More pages are claimed but no advancing cursor came back: the drain can't continue, so flag it\n\t\t\t// rather than stopping silently.\n\t\t\tif (page.nextCursor == null || page.nextCursor === cursor) {\n\t\t\t\tstopIncomplete('Jira Server returned no advancing issue continuation');\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcursor = page.nextCursor;\n\t\t\t// Pages remain but this was the last allowed iteration: the backstop stopped the drain.\n\t\t\tif (i === maxPagesPerRequest - 1) {\n\t\t\t\tstopIncomplete(\n\t\t\t\t\t`Jira Server account-wide issue drain stopped at the ${maxPagesPerRequest}-page backstop`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tvalues: results,\n\t\t\ttruncated: truncated,\n\t\t\tmetadata: mergeCollectionMetadata(summarizePageMetadata(pages), metadata),\n\t\t};\n\t}\n\n\tprotected override async getProviderLinkedIssueOrPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: JiraServerResourceDescriptor,\n\t\t{ key }: { id: string; key: string },\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst issue = await api.getJiraServerIssue(toTokenWithInfo(this.id, session), this.apiBaseUrlFor(session), key);\n\t\treturn issue != null ? toIssueShape(issue, this, { projection: 'point' }) : undefined;\n\t}\n\n\tprotected override async getProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: JiraServerResourceDescriptor,\n\t\tid: string,\n\t): Promise<Issue | undefined> {\n\t\treturn this.readIssue(session, id, 'point');\n\t}\n\n\tprivate async readIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tid: string,\n\t\tprojection: IssueProjection,\n\t): Promise<Issue | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst apiResult = await api.getJiraServerIssue(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tid,\n\t\t);\n\t\tconst issue = apiResult != null ? toIssueShape(apiResult, this, { projection: projection }) : undefined;\n\t\treturn issue != null ? { ...issue, type: 'issue' } : undefined;\n\t}\n\n\t/**\n\t * The point read behind `getIssuesBatch`'s tracker targets (#5872). `resourceId` is this connection's single\n\t * synthetic resource — the host itself, see {@link JiraServerResourceDescriptor} — so it selects nothing further\n\t * here: the host was chosen upstream by `domain` (or the connection's configured domain) and the request is\n\t * addressed to the SESSION's base URL like every other read. No `resourceUrl` is needed either, unlike Jira\n\t * Cloud: its REST `self` link is an API endpoint, whereas `getJiraServerIssue` builds the browser link from\n\t * the base URL it was addressed to. A key that names no issue resolves to `undefined`, a proven absence.\n\t */\n\tprotected override getProviderIssueByResourceId(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resourceId: string,\n\t\tid: string,\n\t\t_resourceUrl: string | undefined,\n\t): Promise<Issue | undefined> {\n\t\treturn this.readIssue(session, id, 'batch');\n\t}\n\n\t/**\n\t * Caches are keyed by the ADDRESS the read was made against as well as the token: one integration instance\n\t * exists per configured host and two hosts can hold the same token, so a token-only key would serve one\n\t * host's projects for the other — and the host alone is not enough either, because a connection re-pointed\n\t * to another context path on the same host keeps its token and would otherwise be served the old path's\n\t * projects.\n\t */\n\tprivate projectsCacheKey(session: ProviderAuthenticationSession): string {\n\t\treturn `${this.apiBaseUrlFor(session)}:${session.accessToken}`;\n\t}\n\n\tprotected override clearDiscoveryCaches(): void {\n\t\tthis._projects.clear();\n\t\tthis._projectReads.clear();\n\t\tthis._autolinks.clear();\n\t\tthis._autolinksBuilds.clear();\n\t}\n\n\tprotected override providerOnDisconnect(): void {\n\t\tthis.invalidateDiscoveryCaches();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AA4CA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;AAC/E,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;AAuB3B,SAAS,iBAAiB,MAAsD;CAC/E,OAAO;EAAE,WAAW;EAAM,SAAS;CAAK;AACzC;AAmBA,IAAa,wBAAb,cAA2C,kBAAiE;CAWzF;CAVlB,eAAqE;CACrE,KAAS;CACT;CACA,OAAwB;CAExB,YACC,KACA,uBACA,iBACA,qBACA,SACC;EACD,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AAU,MAAM;EACrB,KAAK,cAAc,MAAM;EACzB,KAAK,WAAW,MAAM;EACtB,KAAK,iBAAiB,MAAM;CAC7B;CAEA,uBAAgD;EAC/C,KAAK,0BAA0B;CAChC;AACD"}
1
+ {"version":3,"file":"jira-server.js","names":[],"sources":["../../../../../plus/integrations/src/providers/jira-server.ts"],"sourcesContent":["import type { CollectionMetadata } from '@gitkraken/provider-apis';\nimport { JIRA_MAX_PROJECT_KEYS_PER_REQUEST } from '@gitkraken/provider-apis';\nimport type { Account } from '@gitlens/git/models/author.js';\nimport type { AutolinkReference } from '@gitlens/git/models/autolink.js';\nimport type { Issue, IssueProjection, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type { IssueResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport type { Emitter } from '@gitlens/utils/event.js';\nimport { Logger } from '@gitlens/utils/logger.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from '../authentication/integrationAuthenticationService.js';\nimport type { ProviderAuthenticationSession } from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { isIncompleteCollection, toCollectionScopeFailure } from '../collectionMetadata.js';\nimport { IssuesSelfManagedHostIntegrationId } from '../constants.js';\nimport type { IntegrationServiceContext } from '../context.js';\nimport type { IntegrationConnectionChangeEvent } from '../integrationService.js';\nimport type { IntegrationKey } from '../models/integration.js';\nimport type {\n\tAccountWideIssuesResult,\n\tIssuesForProjectOptions,\n\tProjectIssuesDrain,\n\tProjectIssuesRequest,\n\tSearchMyIssuesOptions,\n} from '../models/issueReads.js';\nimport { groupProjectIssuesSearches, IssuesIntegration, toProjectsCollection } from '../models/issuesIntegration.js';\nimport { areDomainsOnSameHost, baseUrlFromDomain } from '../utils/domain.utils.js';\nimport type { ProviderApiCollectionResult } from './models.js';\nimport { providersMetadata, toAccount, toIssueShape, toProviderIssueStates } from './models.js';\nimport { isJiraServerMissingProjectError } from './providerErrors.js';\nimport type { ProvidersApi } from './providersApi.js';\nimport { DiscoveryCache, discoveryCacheTtl } from './utils/discoveryCache.js';\nimport { createIssueAutolinkReferences } from './utils/issueAutolinks.js';\nimport type { JiraDrainOptions, JiraIssuePageFetcher } from './utils/jiraIssueDrains.js';\nimport {\n\tdrainJiraIssues,\n\treadUserScopedJiraIssues,\n\tsearchJiraProjectIssues,\n\tsummarizePageMetadata,\n\ttoUniqueJiraIssueShapes,\n\twithFailureScope,\n} from './utils/jiraIssueDrains.js';\nimport { mergeCollectionMetadata } from './utils/providerPaging.js';\n\nconst metadata = providersMetadata[IssuesSelfManagedHostIntegrationId.JiraServer];\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\nconst maxPagesPerRequest = 10;\n\n/**\n * Every clause is scoped by the HANDLE, and `options.userId` is deliberately ignored here — the one\n * place this provider diverges from Jira Cloud's, which applies it to `assignee`/`creator` (#5857).\n *\n * The two are not interchangeable because `Account.id` means something different per deployment. On\n * Cloud it is the `accountId`, which JQL resolves, so scoping by it fixes the deactivated-account case\n * where the display name no longer resolves. On Server it is the user KEY (`JIRAUSER10224`), which JQL\n * does not resolve at all: measured against a live Jira Server 8.20.13 site, `assignee in\n * (\"JIRAUSER10224\")` returns 0 with `\"The value 'JIRAUSER10224' does not exist for the field\n * 'assignee'\"` — the identical warning a genuinely nonexistent user produces — while the username and\n * the display name both return the real 4.\n *\n * So applying `userId` here would silently empty the read rather than harden it. Do not \"fix\" this\n * asymmetry to match Cloud without re-measuring against a Server instance.\n *\n * The handle itself is already the right one: `provider-apis` 0.60.0 maps `Account.username` from the\n * Server payload's `name` (falling back to `displayName` when absent), so these clauses are scoped by the\n * real username rather than a display name (GKDEV-3629). That is what makes the `mention` clause work at\n * all — it is a free-text `comment ~ \"...\"` over comment bodies, and a Jira mention is stored as\n * `[~username]`, which a display name never matches.\n */\nfunction toUserIdentities(user: string): { userField: string; mention: string } {\n\treturn { userField: user, mention: user };\n}\n\n/**\n * The single resource a Jira Server connection has: the instance itself.\n *\n * Jira Cloud's account spans many sites, so its resources come from an API call that lists them. A\n * self-hosted instance IS the one site the connection addresses, so there is nothing to enumerate — this\n * descriptor is synthesized from the configured host. Modelling it as a resource anyway keeps the\n * resource → project contract of {@link IssuesIntegration} intact, so every tracker read (`listOrgs`,\n * `listProjects`, `listIssueTrackerIssuesPage`) works unchanged.\n */\nexport interface JiraServerResourceDescriptor extends IssueResourceDescriptor {\n\turl: string;\n}\n\nexport interface JiraServerProjectDescriptor extends IssueResourceDescriptor {\n\tresourceId: string;\n}\n\nexport class JiraServerIntegration extends IssuesIntegration<IssuesSelfManagedHostIntegrationId.JiraServer> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\treadonly id = IssuesSelfManagedHostIntegrationId.JiraServer;\n\tprotected readonly key: IntegrationKey<IssuesSelfManagedHostIntegrationId.JiraServer>;\n\treadonly name: string = 'Jira Data Center';\n\n\tconstructor(\n\t\tctx: IntegrationServiceContext,\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tgetProvidersApi: () => Promise<ProvidersApi>,\n\t\tdidChangeConnection: Emitter<IntegrationConnectionChangeEvent>,\n\t\tprivate readonly _domain: string,\n\t) {\n\t\tsuper(ctx, authenticationService, getProvidersApi, didChangeConnection);\n\t\tthis.key = `${this.id}:${this._domain}`;\n\t}\n\n\tget domain(): string {\n\t\treturn this._domain;\n\t}\n\n\t/**\n\t * The URL every request for this connection is addressed to, built from the SESSION's domain rather than\n\t * the integration's.\n\t *\n\t * `this.domain` is the host-keyed identity — `IntegrationService.get()` runs it through `hostFromDomain`\n\t * so one host can't build two instances — which means it has had any context path stripped, and so has\n\t * `session.domain`, which is stored as that same normalized host. Jira Data Center officially supports\n\t * being mounted below a context path (`https://jira.example.com/jira`), so the address comes from\n\t * {@link ProviderAuthenticationSession.baseUrl}, which carries the configured value verbatim; it falls\n\t * back to the host when the backend reported nothing more, which is the common case.\n\t *\n\t * Takes the session rather than reading `_session` so a per-connection (multi-account) read is addressed\n\t * to the host of the connection it resolved, not to whichever one happens to be current.\n\t */\n\tprotected apiBaseUrlFor(session: ProviderAuthenticationSession | undefined): string {\n\t\tconst configured = baseUrlFromDomain(session?.baseUrl, session?.protocol);\n\t\t// A `baseUrl` from another host is not this connection's address — refuse it rather than routing this\n\t\t// integration's reads somewhere its key never named.\n\t\tif (configured != null && areDomainsOnSameHost(session?.baseUrl, this.domain)) return configured;\n\n\t\treturn (\n\t\t\tbaseUrlFromDomain(session?.domain, session?.protocol) ??\n\t\t\tbaseUrlFromDomain(this.domain, session?.protocol) ??\n\t\t\t`${session?.protocol ?? 'https:'}//${this.domain}`\n\t\t);\n\t}\n\n\t/** The one resource this connection has — see {@link JiraServerResourceDescriptor}. */\n\tprivate resourceFor(session: ProviderAuthenticationSession | undefined): JiraServerResourceDescriptor {\n\t\treturn { id: this.domain, key: this.domain, name: this.domain, url: this.apiBaseUrlFor(session) };\n\t}\n\n\tprivate readonly _autolinks = new Map<string, { autolinks: AutolinkReference[]; builtAt: number }>();\n\tprivate readonly _autolinksBuilds = new Map<string, Promise<AutolinkReference[]>>();\n\n\toverride async autolinks(): Promise<AutolinkReference[]> {\n\t\tconst generation = this.discoveryGeneration;\n\t\tconst connected = this.maybeConnected ?? (await this.isConnected());\n\t\tif (!connected || this._session == null) return [];\n\t\tif (!this.isResolvedSessionCurrent(this._session, generation)) return [];\n\n\t\tconst session = this._session;\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tconst cached = this._autolinks.get(cacheKey);\n\t\tif (this.connectionExpired === true) return cached?.autolinks ?? [];\n\t\tif (cached == null) return this.buildAutolinks(session);\n\n\t\tif (Date.now() - cached.builtAt >= discoveryCacheTtl) {\n\t\t\tvoid this.buildAutolinks(session);\n\t\t}\n\t\treturn cached.autolinks;\n\t}\n\n\tprivate buildAutolinks(session: ProviderAuthenticationSession): Promise<AutolinkReference[]> {\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tlet build = this._autolinksBuilds.get(cacheKey);\n\t\tif (build == null) {\n\t\t\tbuild = this.buildAutolinksCore(session).finally(() => {\n\t\t\t\tif (this._autolinksBuilds.get(cacheKey) === build) {\n\t\t\t\t\tthis._autolinksBuilds.delete(cacheKey);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._autolinksBuilds.set(cacheKey, build);\n\t\t}\n\t\treturn build;\n\t}\n\n\tprivate async buildAutolinksCore(session: ProviderAuthenticationSession): Promise<AutolinkReference[]> {\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tconst generation = this._projects.generation;\n\t\ttry {\n\t\t\tconst resource = this.resourceFor(session);\n\t\t\tconst result = await this.getProjectsForResourcesWithMetadataResult([resource]);\n\t\t\tif (this._projects.generation !== generation) return [];\n\t\t\tif (result?.value == null || result.error != null || isIncompleteCollection(result.value.metadata)) {\n\t\t\t\treturn this._autolinks.get(cacheKey)?.autolinks ?? [];\n\t\t\t}\n\n\t\t\tconst autolinks: AutolinkReference[] = [];\n\t\t\tfor (const project of result.value.values) {\n\t\t\t\tif (project.key === project.id) continue;\n\n\t\t\t\tautolinks.push(\n\t\t\t\t\t...createIssueAutolinkReferences(\n\t\t\t\t\t\tproject.key,\n\t\t\t\t\t\t`${resource.url}/browse/${project.key}-<num>`,\n\t\t\t\t\t\tresource,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis._autolinks.set(cacheKey, { autolinks: autolinks, builtAt: Date.now() });\n\t\t\treturn autolinks;\n\t\t} catch (ex) {\n\t\t\tLogger.error(ex, 'JiraServerIntegration.autolinks');\n\t\t\treturn this._autolinks.get(cacheKey)?.autolinks ?? [];\n\t\t}\n\t}\n\n\tprotected override async getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: JiraServerResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api.getJiraServerCurrentUser(toTokenWithInfo(this.id, session), this.apiBaseUrlFor(session));\n\n\t\tif (user == null) return undefined;\n\t\treturn toAccount(user, this);\n\t}\n\n\tprotected override getProviderResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_force?: boolean,\n\t): Promise<JiraServerResourceDescriptor[] | undefined> {\n\t\t// Synthesized from the configured host rather than fetched, so there is nothing to cache or force.\n\t\treturn Promise.resolve([this.resourceFor(session)]);\n\t}\n\n\t/** Expires, and is dropped on a re-sync, so a project created or deleted mid-session is picked up (#5907). */\n\tprivate readonly _projects = new DiscoveryCache<JiraServerProjectDescriptor[]>();\n\tprivate readonly _projectReads = new Map<string, Promise<JiraServerProjectDescriptor[] | undefined>>();\n\tprotected override getProviderProjectsForResources(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: JiraServerResourceDescriptor[],\n\t): Promise<JiraServerProjectDescriptor[] | undefined> {\n\t\t// Every resource here is this instance (see `getProviderResourcesForUser`), so one read serves them\n\t\t// all; a caller that passes none is asking for nothing.\n\t\tif (resources.length === 0) return Promise.resolve([]);\n\n\t\tconst cacheKey = this.projectsCacheKey(session);\n\t\tconst cached = this._projects.get(cacheKey);\n\t\tif (cached != null) return Promise.resolve(cached);\n\n\t\tlet read = this._projectReads.get(cacheKey);\n\t\tif (read == null) {\n\t\t\tread = this.readProjectsCached(session, cacheKey).finally(() => {\n\t\t\t\tif (this._projectReads.get(cacheKey) === read) {\n\t\t\t\t\tthis._projectReads.delete(cacheKey);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._projectReads.set(cacheKey, read);\n\t\t}\n\t\treturn read;\n\t}\n\n\tprivate async readProjectsCached(\n\t\tsession: ProviderAuthenticationSession,\n\t\tcacheKey: string,\n\t): Promise<JiraServerProjectDescriptor[] | undefined> {\n\t\tconst generation = this._projects.generation;\n\t\tconst descriptors = await this.readProjects(session);\n\t\tif (descriptors == null) return undefined;\n\n\t\tif (this._projects.set(cacheKey, descriptors, { generation: generation }) !== false) {\n\t\t\tthis._autolinks.delete(cacheKey);\n\t\t}\n\n\t\treturn descriptors;\n\t}\n\n\tprotected override async getProviderUncachedProjectsForResourcesWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: JiraServerResourceDescriptor[],\n\t): Promise<ProviderApiCollectionResult<JiraServerProjectDescriptor>> {\n\t\tif (resources.length === 0) return { values: [] };\n\n\t\treturn toProjectsCollection(await this.readProjects(session));\n\t}\n\n\tprivate async readProjects(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<JiraServerProjectDescriptor[] | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst projects = await api.getJiraServerProjects(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t);\n\t\tif (projects == null) return undefined;\n\t\tif (projects.length === 0) {\n\t\t\t// Jira can serve anonymous empty projects after rejection without an identifying response header.\n\t\t\tconst account = await this.getProviderAccountForResource(session, this.resourceFor(session));\n\t\t\tif ((account?.username ?? account?.name) == null) return undefined;\n\t\t}\n\n\t\tconst resourceId = this.resourceFor(session).id;\n\t\treturn projects.map<JiraServerProjectDescriptor>(p => ({\n\t\t\tid: p.id,\n\t\t\t// The project key, which selects the project (`listProjects`' `name`) and is what an issue key starts\n\t\t\t// with. The SDK does not validate it, so a missing or blank one falls back to the numeric id, never to the\n\t\t\t// display name, which can equal another project's key. The reads below still address the project by\n\t\t\t// `id`, which no other project can share.\n\t\t\tkey: p.key?.trim() || p.id,\n\t\t\tname: p.name,\n\t\t\tresourceId: resourceId,\n\t\t}));\n\t}\n\n\tprotected override async getProviderIssuesForProject(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: JiraServerProjectDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.getProviderIssuesForProjectWithTruncation(session, project, options))?.values;\n\t}\n\n\tprotected override async getProviderIssuesForProjectWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: JiraServerProjectDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<ProjectIssuesDrain | undefined> {\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst api = await this.getProvidersApi();\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\n\t\t// The same drain as Jira Cloud's (`jiraIssueDrains.ts`): page to a defensive backstop, and report `truncated`\n\t\t// plus a structured failure rather than discarding an already-fetched prefix.\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\t// The numeric project id, not the name: JQL resolves `project = \"<value>\"` against key first, so a display\n\t\t// name that matches another project's key reads that project's issues instead. A Jira project key must begin\n\t\t// with a letter, so a purely numeric value can only be an id.\n\t\tconst fetchPage: JiraIssuePageFetcher = (scope, cursor) =>\n\t\t\tapi.getJiraServerIssuesForProjectPaged(tokenWithInfo, baseUrl, project.id, {\n\t\t\t\t...scope,\n\t\t\t\tcursor: cursor,\n\t\t\t\tstates: states,\n\t\t\t\tsort: options?.sort,\n\t\t\t});\n\t\tconst drainOptions: JiraDrainOptions = {\n\t\t\tmaxPages: maxPagesPerRequest,\n\t\t\t// Scoped by key, as on Jira Cloud: the id addresses the read, the key is how a consumer names the project.\n\t\t\tfailureScope: { providerId: this.id, resourceId: project.resourceId, projectId: project.key },\n\t\t\tproviderName: 'Jira Server',\n\t\t\t// A project this connection can no longer see (deleted, or its browse permission removed) holds\n\t\t\t// no issues for it, and the project list that named it is stale: drop that list so the next read\n\t\t\t// re-reads it, instead of failing the whole provider on every read until a restart (#5907).\n\t\t\tisEmptyFailure: ex => {\n\t\t\t\tif (!isJiraServerMissingProjectError(ex)) return false;\n\n\t\t\t\tLogger.warn(`Jira Server project '${project.name}' (${project.id}) no longer exists or is not visible`);\n\t\t\t\tthis.invalidateDiscoveryCaches();\n\t\t\t\treturn true;\n\t\t\t},\n\t\t};\n\n\t\tif (options?.user != null) {\n\t\t\tconst read = await readUserScopedJiraIssues(\n\t\t\t\tfetchPage,\n\t\t\t\toptions.filters,\n\t\t\t\ttoUserIdentities(options.user),\n\t\t\t\tdrainOptions,\n\t\t\t);\n\t\t\tconst values = toUniqueJiraIssueShapes(read.issues, this);\n\t\t\tconst drain = { values: values, metadata: read.metadata, scope: drainOptions.failureScope };\n\t\t\t// `recovery: 'none'` for the whole set: the filter branches merge here, so even a pure backstop in one\n\t\t\t// branch is not fixable by narrowing this read's scope.\n\t\t\treturn read.truncated ? { ...drain, truncated: true, recovery: 'none' } : { ...drain, truncated: false };\n\t\t}\n\n\t\tconst unscoped = await drainJiraIssues(fetchPage, {}, drainOptions);\n\t\tconst values = unscoped.issues\n\t\t\t.map(issue => toIssueShape(issue, this, { projection: 'project' }))\n\t\t\t.filter((result): result is IssueShape => result !== undefined);\n\t\tconst drain = { values: values, metadata: unscoped.metadata, scope: drainOptions.failureScope };\n\t\treturn unscoped.status !== 'complete'\n\t\t\t? { ...drain, truncated: true, recovery: unscoped.status === 'backstop' ? 'narrow-scope' : 'none' }\n\t\t\t: { ...drain, truncated: false };\n\t}\n\n\t/**\n\t * Searches the instance's projects together for a user-scoped read, as Jira Cloud does per site: one JQL names\n\t * up to {@link JIRA_MAX_PROJECT_KEYS_PER_REQUEST} projects of one user scope. An unscoped read stays per project,\n\t * since its backstop is reported as `narrow-scope` per project.\n\t */\n\tprotected override getProjectIssuesSearches(\n\t\trequests: readonly ProjectIssuesRequest<JiraServerProjectDescriptor>[],\n\t): number[][] | undefined {\n\t\treturn groupProjectIssuesSearches(\n\t\t\trequests,\n\t\t\t({ options }) =>\n\t\t\t\toptions.user != null\n\t\t\t\t\t? [options.user, options.sort ?? '', options.state ?? '', options.filters?.join(',') ?? ''].join(\n\t\t\t\t\t\t\t'\\0',\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined,\n\t\t\tJIRA_MAX_PROJECT_KEYS_PER_REQUEST,\n\t\t);\n\t}\n\n\tprotected override async searchProviderProjectIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\trequests: readonly ProjectIssuesRequest<JiraServerProjectDescriptor>[],\n\t): Promise<IssueShape[][] | undefined> {\n\t\t// Every request of a search shares its user scope (see `getProjectIssuesSearches`).\n\t\tconst { options } = requests[0];\n\t\tif (options.user == null) return undefined;\n\t\t// One project's search is its own read, by the same numeric id, so it costs no more to read it as one. And it\n\t\t// reports what the search can't: a dropped issue's failure, which a search can only answer by being read again.\n\t\tif (requests.length === 1) return undefined;\n\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst api = await this.getProvidersApi();\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\t\t// By numeric id, as the per-project read names them (see there).\n\t\tconst projectIds = requests.map(request => request.project.id);\n\t\tconst states = toProviderIssueStates(options.state);\n\n\t\treturn searchJiraProjectIssues(\n\t\t\t(userScope, cursor) =>\n\t\t\t\tapi.getJiraServerIssuesForProjectsPaged(tokenWithInfo, baseUrl, projectIds, {\n\t\t\t\t\t...userScope,\n\t\t\t\t\tcursor: cursor,\n\t\t\t\t\tstates: states,\n\t\t\t\t\tsort: options.sort,\n\t\t\t\t}),\n\t\t\tprojectIds,\n\t\t\toptions.filters,\n\t\t\ttoUserIdentities(options.user),\n\t\t\t{ maxPages: maxPagesPerRequest, failureScope: { providerId: this.id }, providerName: 'Jira Server' },\n\t\t\tthis,\n\t\t);\n\t}\n\n\tprotected override async searchProviderMyIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: JiraServerResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.searchProviderMyIssuesWithTruncation(session, resources, cancellation))?.values;\n\t}\n\n\t/**\n\t * Account-wide \"my issues\" for this instance, drained to the backstop and reporting whether it got there.\n\t *\n\t * The override exists for the same reason the project drain reports `status`: the default\n\t * implementation wraps whatever the normalized read returned as `truncated: false`, so a run that stopped\n\t * at `maxPagesPerRequest` with pages left, or on a continuation the server never advanced, would be\n\t * published as a complete account. Cancellation is NOT truncation — the caller asked for the stop and\n\t * already knows the prefix is partial — so it breaks without setting the flag.\n\t */\n\tprotected override async searchProviderMyIssuesWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resources?: JiraServerResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchMyIssuesOptions,\n\t): Promise<AccountWideIssuesResult | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst baseUrl = this.apiBaseUrlFor(session);\n\n\t\t// Errors propagate, unlike Jira Cloud's sibling. Cloud swallows per resource because it loops over the\n\t\t// account's many sites and one bad site must not discard the others; this connection addresses exactly\n\t\t// one instance, so there is no sibling to protect and swallowing would turn every failure — an expired\n\t\t// token, an unreachable host — into an empty success. `searchMyIssuesWithTruncationResult` recovers the\n\t\t// throw into `{ error }`, which is what lets the caller warn instead of reporting \"no issues\".\n\t\t// Only the provider: the instance is this connection's single resource, so naming it would publish a\n\t\t// failure of the whole connection as one confined to a sub-scope (see `ProviderWarning.scope`).\n\t\tconst accountScope = { providerId: this.id };\n\t\tconst results: IssueShape[] = [];\n\t\tlet cursor: string | undefined;\n\t\tlet truncated = false;\n\t\tlet metadata: CollectionMetadata | undefined;\n\t\tconst pages: CollectionMetadata[] = [];\n\n\t\tconst stopIncomplete = (reason: string) => {\n\t\t\ttruncated = true;\n\t\t\tmetadata = mergeCollectionMetadata(metadata, {\n\t\t\t\tcompleteness: 'partial',\n\t\t\t\tfailures: [toCollectionScopeFailure(accountScope, new Error(reason))],\n\t\t\t});\n\t\t};\n\n\t\tfor (let i = 0; i < maxPagesPerRequest; i++) {\n\t\t\tif (cancellation?.aborted) break;\n\n\t\t\tconst page = await api.getJiraServerIssuesForCurrentUser(tokenWithInfo, baseUrl, {\n\t\t\t\tcursor: cursor,\n\t\t\t\tstates: states,\n\t\t\t});\n\t\t\tif (page == null) {\n\t\t\t\t// Nothing fetched yet and no page is an empty account, not a failure; after a continuation it\n\t\t\t\t// means the server dropped the drain mid-way.\n\t\t\t\tif (cursor != null) {\n\t\t\t\t\tstopIncomplete('Jira Server returned no page after advertising a continuation');\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tresults.push(\n\t\t\t\t...page.data\n\t\t\t\t\t.map(issue => toIssueShape(issue, this, { projection: 'account' }))\n\t\t\t\t\t.filter((r): r is IssueShape => r != null),\n\t\t\t);\n\t\t\t// An issue the page dropped because it could not be read arrives here, not as a missing row; recorded under\n\t\t\t// the same scope as this read's other failures.\n\t\t\tif (page.metadata != null) {\n\t\t\t\t// Truncated too, as Jira Cloud's read is through `getPagedResult`: the account is missing that issue.\n\t\t\t\ttruncated ||= isIncompleteCollection(page.metadata);\n\t\t\t\tpages.push(withFailureScope(page.metadata, accountScope));\n\t\t\t}\n\n\t\t\tif (!page.hasMore) break;\n\n\t\t\t// More pages are claimed but no advancing cursor came back: the drain can't continue, so flag it\n\t\t\t// rather than stopping silently.\n\t\t\tif (page.nextCursor == null || page.nextCursor === cursor) {\n\t\t\t\tstopIncomplete('Jira Server returned no advancing issue continuation');\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcursor = page.nextCursor;\n\t\t\t// Pages remain but this was the last allowed iteration: the backstop stopped the drain.\n\t\t\tif (i === maxPagesPerRequest - 1) {\n\t\t\t\tstopIncomplete(\n\t\t\t\t\t`Jira Server account-wide issue drain stopped at the ${maxPagesPerRequest}-page backstop`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tvalues: results,\n\t\t\ttruncated: truncated,\n\t\t\tmetadata: mergeCollectionMetadata(summarizePageMetadata(pages), metadata),\n\t\t};\n\t}\n\n\tprotected override async getProviderLinkedIssueOrPullRequest(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: JiraServerResourceDescriptor,\n\t\t{ key }: { id: string; key: string },\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst issue = await api.getJiraServerIssue(toTokenWithInfo(this.id, session), this.apiBaseUrlFor(session), key);\n\t\treturn issue != null ? toIssueShape(issue, this, { projection: 'point' }) : undefined;\n\t}\n\n\tprotected override async getProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: JiraServerResourceDescriptor,\n\t\tid: string,\n\t): Promise<Issue | undefined> {\n\t\treturn this.readIssue(session, id, 'point');\n\t}\n\n\tprivate async readIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tid: string,\n\t\tprojection: IssueProjection,\n\t): Promise<Issue | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst apiResult = await api.getJiraServerIssue(\n\t\t\ttoTokenWithInfo(this.id, session),\n\t\t\tthis.apiBaseUrlFor(session),\n\t\t\tid,\n\t\t);\n\t\tconst issue = apiResult != null ? toIssueShape(apiResult, this, { projection: projection }) : undefined;\n\t\treturn issue != null ? { ...issue, type: 'issue' } : undefined;\n\t}\n\n\t/**\n\t * The point read behind `getIssuesBatch`'s tracker targets (#5872). `resourceId` is this connection's single\n\t * synthetic resource — the host itself, see {@link JiraServerResourceDescriptor} — so it selects nothing further\n\t * here: the host was chosen upstream by `domain` (or the connection's configured domain) and the request is\n\t * addressed to the SESSION's base URL like every other read. No `resourceUrl` is needed either, unlike Jira\n\t * Cloud: its REST `self` link is an API endpoint, whereas `getJiraServerIssue` builds the browser link from\n\t * the base URL it was addressed to. A key that names no issue resolves to `undefined`, a proven absence.\n\t */\n\tprotected override getProviderIssueByResourceId(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resourceId: string,\n\t\tid: string,\n\t\t_resourceUrl: string | undefined,\n\t): Promise<Issue | undefined> {\n\t\treturn this.readIssue(session, id, 'batch');\n\t}\n\n\t/**\n\t * Caches are keyed by the ADDRESS the read was made against as well as the token: one integration instance\n\t * exists per configured host and two hosts can hold the same token, so a token-only key would serve one\n\t * host's projects for the other — and the host alone is not enough either, because a connection re-pointed\n\t * to another context path on the same host keeps its token and would otherwise be served the old path's\n\t * projects.\n\t */\n\tprivate projectsCacheKey(session: ProviderAuthenticationSession): string {\n\t\treturn `${this.apiBaseUrlFor(session)}:${session.accessToken}`;\n\t}\n\n\tprotected override clearDiscoveryCaches(): void {\n\t\tthis._projects.clear();\n\t\tthis._projectReads.clear();\n\t\tthis._autolinks.clear();\n\t\tthis._autolinksBuilds.clear();\n\t}\n\n\tprotected override providerOnDisconnect(): void {\n\t\tthis.invalidateDiscoveryCaches();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AA4CA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;AAC/E,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;AAuB3B,SAAS,iBAAiB,MAAsD;CAC/E,OAAO;EAAE,WAAW;EAAM,SAAS;CAAK;AACzC;AAmBA,IAAa,wBAAb,cAA2C,kBAAiE;CAWzF;CAVlB,eAAqE;CACrE,KAAS;CACT;CACA,OAAwB;CAExB,YACC,KACA,uBACA,iBACA,qBACA,SACC;EACD,MAAM,KAAK,uBAAuB,iBAAiB,mBAAmB;EAFrD,KAAA,UAAA;EAGjB,KAAK,MAAM,GAAG,KAAK,GAAG,GAAG,KAAK;CAC/B;CAEA,IAAI,SAAiB;EACpB,OAAO,KAAK;CACb;;;;;;;;;;;;;;;CAgBA,cAAwB,SAA4D;EACnF,MAAM,aAAa,kBAAkB,SAAS,SAAS,SAAS,QAAQ;EAGxE,IAAI,cAAc,QAAQ,qBAAqB,SAAS,SAAS,KAAK,MAAM,GAAG,OAAO;EAEtF,OACC,kBAAkB,SAAS,QAAQ,SAAS,QAAQ,KACpD,kBAAkB,KAAK,QAAQ,SAAS,QAAQ,KAChD,GAAG,SAAS,YAAY,SAAS,IAAI,KAAK;CAE5C;;CAGA,YAAoB,SAAkF;EACrG,OAAO;GAAE,IAAI,KAAK;GAAQ,KAAK,KAAK;GAAQ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,GAAG;EAC9G,OAAO,SAAS,OAAO,aAAa,OAAO,MAAM,EAAE,YAAY,QAAQ,CAAC,IAAI,KAAA;CAC7E;CAEA,MAAyB,iBACxB,SACA,WACA,IAC6B;EAC7B,OAAO,KAAK,UAAU,SAAS,IAAI,OAAO;CAC3C;CAEA,MAAc,UACb,SACA,IACA,YAC6B;EAE7B,MAAM,YAAY,OAAM,MADN,KAAK,gBAAgB,EAAA,CACX,mBAC3B,gBAAgB,KAAK,IAAI,OAAO,GAChC,KAAK,cAAc,OAAO,GAC1B,EACD;EACA,MAAM,QAAQ,aAAa,OAAO,aAAa,WAAW,MAAM,EAAc,WAAW,CAAC,IAAI,KAAA;EAC9F,OAAO,SAAS,OAAO;GAAE,GAAG;GAAO,MAAM;EAAQ,IAAI,KAAA;CACtD;;;;;;;;;CAUA,6BACC,SACA,aACA,IACA,cAC6B;EAC7B,OAAO,KAAK,UAAU,SAAS,IAAI,OAAO;CAC3C;;;;;;;;CASA,iBAAyB,SAAgD;EACxE,OAAO,GAAG,KAAK,cAAc,OAAO,EAAE,GAAG,QAAQ;CAClD;CAEA,uBAAgD;EAC/C,KAAK,UAAU,MAAM;EACrB,KAAK,cAAc,MAAM;EACzB,KAAK,WAAW,MAAM;EACtB,KAAK,iBAAiB,MAAM;CAC7B;CAEA,uBAAgD;EAC/C,KAAK,0BAA0B;CAChC;AACD"}
@@ -29,16 +29,50 @@ export declare class JiraIntegration extends IssuesIntegration<IssuesCloudHostIn
29
29
  protected get apiBaseUrl(): string;
30
30
  /**
31
31
  * Built from the sites and their projects, so it follows them: rebuilt when a site's project list changes or the
32
- * caches are dropped, and once older than {@link discoveryCacheTtl}. An expired set is still served while it is
33
- * rebuilt in the background, because autolinks are read on every render of a commit message and must not wait
34
- * on the network, nor go empty just because nothing read the projects for a while (#5907).
32
+ * caches are dropped, and once {@link isAutolinkSetExpired}: older than the TTL, or than a shorter retry delay when
33
+ * the sites or a site's projects couldn't be read whole. An expired set is still served while it is rebuilt in the
34
+ * background, because autolinks are read on every render of a commit message and must not wait on the network,
35
+ * nor go empty just because nothing read the projects for a while (#5907, #6183).
35
36
  */
36
37
  private readonly _autolinks;
37
38
  private readonly _autolinksBuilds;
39
+ /**
40
+ * Moves, by token, on every missing-project eviction, which drops one site's list without clearing the caches: a
41
+ * build or project read that started before it puts neither the list it read back in `_projects` nor what it built
42
+ * from it in `_autolinks` (#6176). Cleared with `_projects`, whose generation then refuses those same writes.
43
+ */
44
+ private readonly _projectEvictions;
45
+ /**
46
+ * Moves whenever `_autolinks` is dropped for a list a build reads, so a build that then fails keeps no fallback
47
+ * over lists it didn't read; the next render builds from them instead (#6183). Rule: every writer that stores a
48
+ * different project list for a site must bump it and retire the token's build, through {@link onProjectListStored};
49
+ * the same list stored again does neither while a complete set is kept (#6184). The connect's clear bumps it too.
50
+ * Site-list stores deliberately don't: a build's own site store would then refuse its own fallback. Drops and
51
+ * evictions need no bump: they fail a build's `isCurrent`.
52
+ */
53
+ private _autolinksResets;
38
54
  autolinks(): Promise<(AutolinkReference | DynamicAutolinkReference)[]>;
39
- /** One build per token at a time: concurrent renders share it rather than each re-reading sites and projects. */
55
+ /**
56
+ * One build per token at a time: concurrent renders share it rather than each re-reading sites and projects. A
57
+ * drop, a missing-project eviction or a change to a site's project list retires it, so a render after one doesn't
58
+ * join a build reading the lists as they were before (#6170, #6176, #6184).
59
+ */
40
60
  private buildAutolinks;
41
61
  private buildAutolinksCore;
62
+ /**
63
+ * A site's project list was stored. A different one drops the autolinks built from the lists, so a build that then
64
+ * fails keeps no fallback, and retires the build in flight, which may hold the list as it was. The same one again
65
+ * keeps a complete set and the build in flight; otherwise it drops the incomplete set kept, if any, so the next
66
+ * render builds from the lists again, and still fences a failing build's fallback (#6183, #6184). Other tokens' sets
67
+ * and builds stay; only `_autolinksResets`, shared by all tokens, also stops their failing builds' fallback.
68
+ *
69
+ * A known limit: a build whose own read stores a different list, or a site's first one (with nothing seeded since a
70
+ * start, a clear or an eviction, every first store reads as different), retires itself too. A render in the
71
+ * microtasks before that build resumes then starts a second one rather than joining it; that one builds from the
72
+ * cache, reading again only the sites the first couldn't read whole. A loss of the sharing core had, with no effect
73
+ * on what is kept, and none on an identical list, which retires nothing.
74
+ */
75
+ private onProjectListStored;
42
76
  protected getProviderAccountForResource(session: ProviderAuthenticationSession, resource: JiraOrganizationDescriptor): Promise<Account | undefined>;
43
77
  /** Atlassian's account id is the same on every site, so the first site answers for all of them. */
44
78
  protected getProviderCurrentAccount(session: ProviderAuthenticationSession): Promise<Account | undefined>;
@@ -56,8 +90,6 @@ export declare class JiraIntegration extends IssuesIntegration<IssuesCloudHostIn
56
90
  */
57
91
  private readonly _organizations;
58
92
  private readonly _projects;
59
- /** When the caches were last dropped; a persisted discovery read before then is as stale as they were. */
60
- private _discoveryInvalidatedAt;
61
93
  protected getProviderResourcesForUser(session: ProviderAuthenticationSession, force?: boolean): Promise<JiraOrganizationDescriptor[] | undefined>;
62
94
  protected getProviderUncachedResourcesForUser(session: ProviderAuthenticationSession): Promise<JiraOrganizationDescriptor[] | undefined>;
63
95
  private readOrganizations;
@@ -1,6 +1,7 @@
1
1
  import { chunk } from "../../../utils/array.js";
2
2
  import { Logger as _logger } from "../../../utils/logger.js";
3
3
  import { mapSettledBounded } from "../../../utils/promise.js";
4
+ import { areEqual } from "../../../utils/object.js";
4
5
  import "../constants.js";
5
6
  import { isJiraMissingProjectError } from "./providerErrors.js";
6
7
  import { toCollectionScopeFailure } from "../collectionMetadata.js";
@@ -9,7 +10,7 @@ import { providersMetadata, toAccount, toIssueShape, toProviderIssueStates } fro
9
10
  import { toTokenWithInfo } from "../authentication/models.js";
10
11
  import { IssuesIntegration, groupProjectIssuesSearches } from "../models/issuesIntegration.js";
11
12
  import { createIssueAutolinkReferences } from "./utils/issueAutolinks.js";
12
- import { DiscoveryCache } from "./utils/discoveryCache.js";
13
+ import { DiscoveryCache, isAutolinkSetExpired, isEmptyAutolinkFallback } from "./utils/discoveryCache.js";
13
14
  import { drainJiraIssues, readUserScopedJiraIssues, searchJiraProjectIssues, summarizePageMetadata, toUniqueJiraIssueShapes } from "./utils/jiraIssueDrains.js";
14
15
  import { toJiraIssueEtagFields } from "./jiraIssueByKey.js";
15
16
  import { JIRA_MAX_PROJECT_KEYS_PER_REQUEST } from "@gitkraken/provider-apis";
@@ -52,27 +53,49 @@ var JiraIntegration = class extends IssuesIntegration {
52
53
  }
53
54
  /**
54
55
  * Built from the sites and their projects, so it follows them: rebuilt when a site's project list changes or the
55
- * caches are dropped, and once older than {@link discoveryCacheTtl}. An expired set is still served while it is
56
- * rebuilt in the background, because autolinks are read on every render of a commit message and must not wait
57
- * on the network, nor go empty just because nothing read the projects for a while (#5907).
56
+ * caches are dropped, and once {@link isAutolinkSetExpired}: older than the TTL, or than a shorter retry delay when
57
+ * the sites or a site's projects couldn't be read whole. An expired set is still served while it is rebuilt in the
58
+ * background, because autolinks are read on every render of a commit message and must not wait on the network,
59
+ * nor go empty just because nothing read the projects for a while (#5907, #6183).
58
60
  */
59
61
  _autolinks = /* @__PURE__ */ new Map();
60
62
  _autolinksBuilds = /* @__PURE__ */ new Map();
63
+ /**
64
+ * Moves, by token, on every missing-project eviction, which drops one site's list without clearing the caches: a
65
+ * build or project read that started before it puts neither the list it read back in `_projects` nor what it built
66
+ * from it in `_autolinks` (#6176). Cleared with `_projects`, whose generation then refuses those same writes.
67
+ */
68
+ _projectEvictions = /* @__PURE__ */ new Map();
69
+ /**
70
+ * Moves whenever `_autolinks` is dropped for a list a build reads, so a build that then fails keeps no fallback
71
+ * over lists it didn't read; the next render builds from them instead (#6183). Rule: every writer that stores a
72
+ * different project list for a site must bump it and retire the token's build, through {@link onProjectListStored};
73
+ * the same list stored again does neither while a complete set is kept (#6184). The connect's clear bumps it too.
74
+ * Site-list stores deliberately don't: a build's own site store would then refuse its own fallback. Drops and
75
+ * evictions need no bump: they fail a build's `isCurrent`.
76
+ */
77
+ _autolinksResets = 0;
61
78
  async autolinks() {
62
79
  if (!(this.maybeConnected ?? await this.isConnected()) || this._session == null) return [];
63
80
  const session = this._session;
64
81
  const cached = this._autolinks.get(session.accessToken);
65
82
  if (this.connectionExpired === true) return cached?.autolinks ?? [];
66
83
  if (cached == null) return this.buildAutolinks(session);
67
- if (Date.now() - cached.builtAt >= 3e5) this.buildAutolinks(session);
84
+ if (isAutolinkSetExpired(cached)) this.buildAutolinks(session);
68
85
  return cached.autolinks;
69
86
  }
70
- /** One build per token at a time: concurrent renders share it rather than each re-reading sites and projects. */
87
+ /**
88
+ * One build per token at a time: concurrent renders share it rather than each re-reading sites and projects. A
89
+ * drop, a missing-project eviction or a change to a site's project list retires it, so a render after one doesn't
90
+ * join a build reading the lists as they were before (#6170, #6176, #6184).
91
+ */
71
92
  buildAutolinks(session) {
72
93
  const { accessToken } = session;
73
94
  let build = this._autolinksBuilds.get(accessToken);
74
95
  if (build == null) {
75
- build = this.buildAutolinksCore(session).finally(() => this._autolinksBuilds.delete(accessToken));
96
+ build = this.buildAutolinksCore(session).finally(() => {
97
+ if (this._autolinksBuilds.get(accessToken) === build) this._autolinksBuilds.delete(accessToken);
98
+ });
76
99
  this._autolinksBuilds.set(accessToken, build);
77
100
  }
78
101
  return build;
@@ -80,26 +103,71 @@ var JiraIntegration = class extends IssuesIntegration {
80
103
  async buildAutolinksCore(session) {
81
104
  const { accessToken } = session;
82
105
  const generation = this._projects.generation;
106
+ const evictions = this._projectEvictions.get(accessToken);
107
+ const resets = this._autolinksResets;
108
+ const held = this._autolinks.get(accessToken);
109
+ const isCurrent = () => this._projects.generation === generation && this._projectEvictions.get(accessToken) === evictions;
110
+ const keep = (autolinks, complete) => {
111
+ const kept = this._autolinks.get(accessToken);
112
+ if (isCurrent() && (complete || kept == null || kept === held || isEmptyAutolinkFallback(kept))) this._autolinks.set(accessToken, {
113
+ autolinks,
114
+ builtAt: Date.now(),
115
+ complete
116
+ });
117
+ return autolinks;
118
+ };
119
+ const keepHeld = () => this._autolinksResets === resets ? keep(held?.autolinks ?? [], false) : held?.autolinks ?? [];
83
120
  try {
84
121
  const organizations = await this.getProviderResourcesForUser(session);
85
- if (!organizations?.length) return [];
122
+ if (organizations == null) return keepHeld();
123
+ const sitesCached = () => areEqual(this._organizations.peek(accessToken), organizations);
124
+ if (!organizations.length) return keep([], sitesCached());
86
125
  const { values: projects, metadata } = await this.getProviderProjectsForResourcesWithMetadata(session, organizations);
126
+ const current = isCurrent();
127
+ const heldNone = held == null || isEmptyAutolinkFallback(held);
128
+ const failedSites = new Set(metadata?.failures?.map((f) => f.scope?.resourceId));
129
+ const refsOf = (organization, siteProjects) => siteProjects.flatMap((project) => createIssueAutolinkReferences(project.key, `${organization.url}/browse/${project.key}-<num>`, organization));
87
130
  const autolinks = [];
88
- for (const project of projects) {
89
- const organization = organizations.find((o) => o.id === project.resourceId);
90
- if (organization == null) continue;
91
- autolinks.push(...createIssueAutolinkReferences(project.key, `${organization.url}/browse/${project.key}-<num>`, organization));
131
+ let complete = true;
132
+ for (const organization of organizations) {
133
+ const key = `${accessToken}:${organization.id}`;
134
+ const cachedProjects = current ? this._projects.get(key) : void 0;
135
+ const siteProjects = cachedProjects ?? projects.filter((p) => p.resourceId === organization.id);
136
+ const refs = refsOf(organization, siteProjects);
137
+ autolinks.push(...refs);
138
+ if (cachedProjects != null) continue;
139
+ complete = false;
140
+ if (!(failedSites.has(organization.id) || !siteProjects.length)) continue;
141
+ const stored = heldNone && current ? this._projects.peek(key) : void 0;
142
+ const had = stored != null ? refsOf(organization, stored) : held?.autolinks.filter((ref) => "prefix" in ref && ref.descriptor?.key === organization.id) ?? [];
143
+ const prefixes = new Set(refs.map((r) => r.prefix));
144
+ for (const ref of had) if (!prefixes.has(ref.prefix)) autolinks.push(ref);
92
145
  }
93
- if ((metadata == null || metadata.completeness === "complete") && this._projects.generation === generation) this._autolinks.set(accessToken, {
94
- autolinks,
95
- builtAt: Date.now()
96
- });
97
- return autolinks;
146
+ return keep(autolinks, complete && sitesCached());
98
147
  } catch (ex) {
99
148
  _logger.error(ex, "JiraIntegration.autolinks");
100
- return this._autolinks.get(accessToken)?.autolinks ?? [];
149
+ return keepHeld();
101
150
  }
102
151
  }
152
+ /**
153
+ * A site's project list was stored. A different one drops the autolinks built from the lists, so a build that then
154
+ * fails keeps no fallback, and retires the build in flight, which may hold the list as it was. The same one again
155
+ * keeps a complete set and the build in flight; otherwise it drops the incomplete set kept, if any, so the next
156
+ * render builds from the lists again, and still fences a failing build's fallback (#6183, #6184). Other tokens' sets
157
+ * and builds stay; only `_autolinksResets`, shared by all tokens, also stops their failing builds' fallback.
158
+ *
159
+ * A known limit: a build whose own read stores a different list, or a site's first one (with nothing seeded since a
160
+ * start, a clear or an eviction, every first store reads as different), retires itself too. A render in the
161
+ * microtasks before that build resumes then starts a second one rather than joining it; that one builds from the
162
+ * cache, reading again only the sites the first couldn't read whole. A loss of the sharing core had, with no effect
163
+ * on what is kept, and none on an identical list, which retires nothing.
164
+ */
165
+ onProjectListStored(accessToken, stored) {
166
+ if (stored === "changed") this._autolinksBuilds.delete(accessToken);
167
+ else if (this._autolinks.get(accessToken)?.complete === true) return;
168
+ this._autolinks.delete(accessToken);
169
+ this._autolinksResets++;
170
+ }
103
171
  async getProviderAccountForResource(session, resource) {
104
172
  const user = await (await this.getProvidersApi()).getCurrentUserForResource(toTokenWithInfo(this.id, session), resource.id);
105
173
  if (user == null) return void 0;
@@ -128,8 +196,6 @@ var JiraIntegration = class extends IssuesIntegration {
128
196
  */
129
197
  _organizations = new DiscoveryCache();
130
198
  _projects = new DiscoveryCache();
131
- /** When the caches were last dropped; a persisted discovery read before then is as stale as they were. */
132
- _discoveryInvalidatedAt = 0;
133
199
  async getProviderResourcesForUser(session, force = false) {
134
200
  const { accessToken } = session;
135
201
  const cachedResources = this._organizations.get(accessToken);
@@ -159,6 +225,8 @@ var JiraIntegration = class extends IssuesIntegration {
159
225
  const { accessToken } = session;
160
226
  const projectsCache = this._projects;
161
227
  const generation = projectsCache.generation;
228
+ const evictions = this._projectEvictions.get(accessToken);
229
+ const started = projectsCache.startRead();
162
230
  const cachedProjects = /* @__PURE__ */ new Map();
163
231
  for (const resource of resources) {
164
232
  const projects = projectsCache.get(`${accessToken}:${resource.id}`);
@@ -167,10 +235,20 @@ var JiraIntegration = class extends IssuesIntegration {
167
235
  const resourcesWithoutProjects = force ? resources : resources.filter((resource) => !cachedProjects.has(resource.id));
168
236
  const read = await this.readProjects(session, resourcesWithoutProjects);
169
237
  const values = [...read.partial];
170
- for (const [resourceId, projects] of read.complete) if (projectsCache.set(`${accessToken}:${resourceId}`, projects, { generation })) this._autolinks.delete(accessToken);
238
+ for (const [resourceId, projects] of read.complete) {
239
+ if (this._projectEvictions.get(accessToken) !== evictions) continue;
240
+ const stored = projectsCache.set(`${accessToken}:${resourceId}`, projects, {
241
+ generation,
242
+ read: started
243
+ });
244
+ if (stored !== false) this.onProjectListStored(accessToken, stored);
245
+ }
246
+ const current = projectsCache.generation === generation && this._projectEvictions.get(accessToken) === evictions;
171
247
  for (const resource of resources) {
172
248
  const resourceProjects = read.complete.get(resource.id) ?? cachedProjects.get(resource.id);
173
- if (resourceProjects != null) values.push(...resourceProjects);
249
+ if (resourceProjects == null) continue;
250
+ const stored = current ? projectsCache.peek(`${accessToken}:${resource.id}`) : void 0;
251
+ values.push(...stored ?? resourceProjects);
174
252
  }
175
253
  return {
176
254
  values: uniqueProjects(values),
@@ -258,8 +336,11 @@ var JiraIntegration = class extends IssuesIntegration {
258
336
  isEmptyFailure: (ex) => {
259
337
  if (!isJiraMissingProjectError(ex)) return false;
260
338
  _logger.warn(`Jira project '${project.key}' no longer exists or is not visible`);
261
- this._projects.delete(`${session.accessToken}:${project.resourceId}`);
262
- this._autolinks.delete(session.accessToken);
339
+ const { accessToken } = session;
340
+ this._projects.delete(`${accessToken}:${project.resourceId}`);
341
+ this._projectEvictions.set(accessToken, (this._projectEvictions.get(accessToken) ?? 0) + 1);
342
+ this._autolinks.delete(accessToken);
343
+ this._autolinksBuilds.delete(accessToken);
263
344
  return true;
264
345
  }
265
346
  };
@@ -507,62 +588,23 @@ var JiraIntegration = class extends IssuesIntegration {
507
588
  }
508
589
  async providerOnConnect() {
509
590
  this._autolinks.clear();
591
+ this._autolinksResets++;
510
592
  if (this._session == null) return;
511
593
  const session = this._session;
512
- const { accessToken } = session;
513
- const organizationsGeneration = this._organizations.generation;
514
- const projectsGeneration = this._projects.generation;
515
- const isFresh = (timestamp) => typeof timestamp === "number" && timestamp > this._discoveryInvalidatedAt && Date.now() - timestamp < 3e5;
516
- const storedOrganizations = this.ctx.storage.get(`jira:${accessToken}:organizations`);
517
- const storedProjects = storedOrganizations != null ? this.ctx.storage.get(`jira:${accessToken}:projects`) : void 0;
518
- let organizations;
519
- if (storedOrganizations?.data != null && isFresh(storedOrganizations.timestamp)) {
520
- const seeded = storedOrganizations.data.map((o) => ({ ...o }));
521
- organizations = seeded;
522
- this._organizations.set(accessToken, seeded, {
523
- generation: organizationsGeneration,
524
- storedAt: storedOrganizations.timestamp
525
- });
526
- } else {
527
- const readAt = Date.now();
528
- organizations = await this.getProviderResourcesForUser(session, true);
529
- if (storedOrganizations == null) await this.ctx.storage.deleteWithPrefix("jira");
530
- if (this._organizations.generation === organizationsGeneration) await this.ctx.storage.store(`jira:${accessToken}:organizations`, {
531
- v: 1,
532
- timestamp: readAt,
533
- data: organizations
534
- });
535
- }
536
- if (storedProjects?.data != null && isFresh(storedProjects.timestamp)) {
537
- const projectsByResource = /* @__PURE__ */ new Map();
538
- for (const project of storedProjects.data) {
539
- const projects = projectsByResource.get(project.resourceId);
540
- if (projects == null) projectsByResource.set(project.resourceId, [{ ...project }]);
541
- else if (!projects.some((p) => p.id === project.id)) projects.push({ ...project });
542
- }
543
- for (const [resourceId, projects] of projectsByResource) this._projects.set(`${accessToken}:${resourceId}`, projects, {
544
- generation: projectsGeneration,
545
- storedAt: storedProjects.timestamp
546
- });
547
- } else if (organizations?.length) {
548
- const readAt = Date.now();
549
- const projects = await this.getProviderProjectsForResources(session, organizations, true);
550
- if (this._projects.generation === projectsGeneration) await this.ctx.storage.store(`jira:${accessToken}:projects`, {
551
- v: 1,
552
- timestamp: readAt,
553
- data: projects
554
- });
555
- }
594
+ const organizations = await this.getProviderResourcesForUser(session, true);
595
+ if (organizations?.length) await this.getProviderProjectsForResources(session, organizations, true);
556
596
  }
557
597
  clearDiscoveryCaches() {
558
- this._discoveryInvalidatedAt = Date.now();
559
598
  this._organizations.clear();
560
599
  this._projects.clear();
600
+ this._projectEvictions.clear();
561
601
  this._autolinks.clear();
602
+ this._autolinksBuilds.clear();
562
603
  }
563
604
  providerOnDisconnect() {
564
605
  this._organizations.clear();
565
606
  this._projects.clear();
607
+ this._projectEvictions.clear();
566
608
  this._autolinks.clear();
567
609
  }
568
610
  };