@gitkraken/core-gitlens 0.52.0 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist/_types/provider-apis/types/exportedTypes/github.d.ts +75 -0
  3. package/dist/_types/provider-apis/types/exportedTypes/types.d.ts +7 -0
  4. package/dist/plus/git-github/api/issueWrites.js +1 -1
  5. package/dist/plus/git-github/api/issueWrites.js.map +1 -1
  6. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.d.ts +5 -1
  7. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +44 -20
  8. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -1
  9. package/dist/plus/integrations/authentication/cloudIntegrationObservations.d.ts +49 -0
  10. package/dist/plus/integrations/authentication/cloudIntegrationObservations.js +118 -0
  11. package/dist/plus/integrations/authentication/cloudIntegrationObservations.js.map +1 -0
  12. package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +38 -25
  13. package/dist/plus/integrations/authentication/configuredIntegrationService.js +376 -141
  14. package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
  15. package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +8 -2
  16. package/dist/plus/integrations/authentication/integrationAuthenticationService.js +34 -4
  17. package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
  18. package/dist/plus/integrations/authentication/models.d.ts +6 -0
  19. package/dist/plus/integrations/authentication/models.js +9 -1
  20. package/dist/plus/integrations/authentication/models.js.map +1 -1
  21. package/dist/plus/integrations/authentication/observedAuthenticationProvider.d.ts +13 -2
  22. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js +68 -30
  23. package/dist/plus/integrations/authentication/observedAuthenticationProvider.js.map +1 -1
  24. package/dist/plus/integrations/index.d.ts +2 -1
  25. package/dist/plus/integrations/index.js.map +1 -1
  26. package/dist/plus/integrations/integrationService.d.ts +8 -0
  27. package/dist/plus/integrations/integrationService.js +148 -36
  28. package/dist/plus/integrations/integrationService.js.map +1 -1
  29. package/dist/plus/integrations/manager.d.ts +3 -0
  30. package/dist/plus/integrations/models/integration.d.ts +4 -0
  31. package/dist/plus/integrations/models/integration.js +61 -16
  32. package/dist/plus/integrations/models/integration.js.map +1 -1
  33. package/dist/plus/integrations/models/issueRelationships.d.ts +31 -0
  34. package/dist/plus/integrations/models/issueRelationships.js +0 -0
  35. package/dist/plus/integrations/models/publicIntegration.d.ts +0 -1
  36. package/dist/plus/integrations/providers/github.d.ts +8 -0
  37. package/dist/plus/integrations/providers/github.js +162 -2
  38. package/dist/plus/integrations/providers/github.js.map +1 -1
  39. package/dist/plus/integrations/providers/issueSorts.d.ts +0 -1
  40. package/dist/plus/integrations/providers/providerApiClient.d.ts +1 -1
  41. package/dist/plus/integrations/providers/providerApiClient.js +33 -14
  42. package/dist/plus/integrations/providers/providerApiClient.js.map +1 -1
  43. package/dist/plus/integrations/providers/providerErrors.d.ts +1 -0
  44. package/dist/plus/integrations/providers/providerErrors.js +1 -2
  45. package/dist/plus/integrations/providers/providerErrors.js.map +1 -1
  46. package/dist/plus/integrations/providers/providersApi.d.ts +2 -1
  47. package/dist/plus/integrations/providers/providersApi.js +2 -0
  48. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  49. package/dist/plus/integrations/reads/drains.d.ts +0 -1
  50. package/docs/integrations.md +36 -0
  51. package/package.json +2 -2
@@ -9,6 +9,7 @@ import { ConfiguredIntegrationDescriptor } from "./authentication/models.js";
9
9
  import { CloudGitSelfManagedHostIntegrationIds, GitCloudHostIntegrationId, GitSelfManagedHostIntegrationId, IntegrationIds, IssuesCloudHostIntegrationId, IssuesSelfManagedHostIntegrationId, SupportedCloudIntegrationIds } from "./constants.js";
10
10
  import { Source } from "./telemetry.js";
11
11
  import { AzurePullRequestCreateCapabilityOptions, AzurePullRequestCreateCapabilityResult, AzurePullRequestWriteOptions, AzurePullRequestWriteResult, AzurePullRequestWriteTargetOptions, AzurePullRequestWriteTargetResult } from "./models/azurePullRequestWrites.js";
12
+ import { CaptureRelationshipCurrency, IssueRelationshipWriteOptions, IssueRelationshipWriteResult, IssueRelationshipsOptions, IssueRelationshipsResult } from "./models/issueRelationships.js";
12
13
  import { IssueTrackerCreateOptions, IssueTrackerCreateOptionsResult, IssueTrackerDeleteOptions, IssueTrackerIssueWriteOptions, IssueTrackerIssueWriteOptionsResult, IssueTrackerWriteOptions, IssueTrackerWriteResult, IssueTrackerWriteTargetOptions, IssueTrackerWriteTargetResult } from "./models/issueTrackerWrites.js";
13
14
  import { WorkItemAddress, WorkItemCreateOptions, WorkItemCreateOptionsResult, WorkItemDeleteOptions, WorkItemDeleteResult, WorkItemWriteOptions, WorkItemWriteOptionsResult, WorkItemWriteResult, WorkItemWriteTargetOptions, WorkItemWriteTargetResult } from "./models/workItemWrites.js";
14
15
  import { IssueFilter, SupportedFilters } from "./providerFilters.js";
@@ -1190,6 +1191,8 @@ export interface IntegrationManager {
1190
1191
  cursor?: string;
1191
1192
  forceSync?: boolean;
1192
1193
  }): Promise<ProviderBroadenResult<IssueShape>>;
1194
+ getIssueRelationships(options: IssueRelationshipsOptions, isHostSessionCurrent?: () => boolean, captureCurrency?: CaptureRelationshipCurrency): Promise<IssueRelationshipsResult>;
1195
+ writeIssueRelationship(options: IssueRelationshipWriteOptions, isHostSessionCurrent?: () => boolean, captureCurrency?: CaptureRelationshipCurrency): Promise<IssueRelationshipWriteResult>;
1193
1196
  writeIssue(options: IssueWriteOptions): Promise<IssueWriteResult>;
1194
1197
  deleteIssue(options: IssueDeleteOptions): Promise<IssueWriteResult>;
1195
1198
  resolveIssueWriteTarget(options: IssueWriteTargetOptions): Promise<IssueWriteTargetResult>;
@@ -9,6 +9,7 @@ import { ScopedLogger } from "../../../utils/logger.scoped.js";
9
9
  import { Account as Account$1 } from "../../../git/models/author.js";
10
10
  import { ConnectionResource, ProviderAuthenticationSession, SessionPublication } from "../authentication/models.js";
11
11
  import { IntegrationIds, IssuesHostIntegrationIds } from "../constants.js";
12
+ import { CloudIntegrationSync } from "../authentication/cloudIntegrationObservations.js";
12
13
  import { Sources } from "../telemetry.js";
13
14
  import { IntegrationAuthenticationProviderDescriptor, IntegrationAuthenticationSessionDescriptor } from "../authentication/integrationAuthenticationProvider.js";
14
15
  import { ProviderWarningCause, ProviderWarningScope } from "../results.js";
@@ -103,6 +104,7 @@ export declare abstract class IntegrationBase<ID extends IntegrationIds = Integr
103
104
  /** {@link getSession}'s token, for a consumer of the public view, which never sees the session itself. */
104
105
  getCredential(source: Sources): Promise<IntegrationCredential | undefined>;
105
106
  private getRefreshedSession;
107
+ protected isIntegrationAccessEnabled(): boolean;
106
108
  private isSessionForIntegrationHost;
107
109
  /**
108
110
  * Resolves the session to read as, for a per-connection (multi-account) read. When `connectionId` is
@@ -197,6 +199,7 @@ export declare abstract class IntegrationBase<ID extends IntegrationIds = Integr
197
199
  protected isResolvedSessionCurrent(_session: ProviderAuthenticationSession | undefined, _generation: number): boolean;
198
200
  onSessionPublishing(publication: SessionPublication): void;
199
201
  protected invalidatePublishedSession(_publication: SessionPublication, _affectsPrimary: boolean): void;
202
+ onCloudConnectionRetired(connectionId: string, retained?: boolean): void;
200
203
  onSessionsRemoving(connectionId?: string, cloud?: boolean): void;
201
204
  private static readonly requestExceptionLimit;
202
205
  /** The primary connection's strikes (see {@link trackRequestException}). */
@@ -232,6 +235,7 @@ export declare abstract class IntegrationBase<ID extends IntegrationIds = Integr
232
235
  * Never rejects: the cloud sync fans this out over every integration and must not fail on one.
233
236
  */
234
237
  syncCloudConnection(state: 'connected' | 'disconnected', forceSync: boolean): Promise<Error | undefined>;
238
+ syncListedCloudConnection(state: 'connected' | 'disconnected', forceSync: boolean, authority: CloudIntegrationSync): Promise<Error | undefined>;
235
239
  private syncCloudConnectionLocked;
236
240
  /**
237
241
  * Proves the credential with an uncached check, rejecting with the provider's `AuthenticationError` when it is
@@ -17,6 +17,7 @@ import { providersMetadata } from "../providers/metadata.js";
17
17
  import { areDomainsOnSameHost } from "../utils/domain.utils.js";
18
18
  import { isSelfManagedHostIntegrationId } from "../utils/integration.utils.js";
19
19
  import { getSessionIdentity } from "../authentication/models.js";
20
+ import { CloudIntegrationAuthenticationProvider } from "../authentication/cloudIntegrationAuthenticationProvider.js";
20
21
  import { RejectedTokenTracker } from "../authentication/rejectedTokenTracker.js";
21
22
  import { FailureBackoff } from "../utils/failureBackoff.js";
22
23
  import { getCachedIssue } from "./issueCache.js";
@@ -176,6 +177,9 @@ var IntegrationBase = class IntegrationBase {
176
177
  if (await this.refreshSessionIfExpired() != null) return void 0;
177
178
  return this._session != null && this.connectionExpired !== true && this.isSessionForIntegrationHost(this._session) ? this._session : void 0;
178
179
  }
180
+ isIntegrationAccessEnabled() {
181
+ return this.ctx.config.isIntegrationsEnabled?.() !== false && this.ctx.storage.getWorkspace(this.connectedKey) !== false;
182
+ }
179
183
  isSessionForIntegrationHost(session) {
180
184
  if (!isSelfManagedHostIntegrationId(this.id)) return true;
181
185
  return areDomainsOnSameHost(this.domain, session.domain);
@@ -196,7 +200,7 @@ var IntegrationBase = class IntegrationBase {
196
200
  * limit as `rate-limit`, anything else as `other`.
197
201
  */
198
202
  async resolveReadSession(connectionId, scope, source) {
199
- if (this.ctx.config.isIntegrationsEnabled?.() === false || this.ctx.storage.getWorkspace(this.connectedKey) === false) return;
203
+ if (!this.isIntegrationAccessEnabled()) return void 0;
200
204
  if (connectionId) {
201
205
  const rejectedToken = this._rejectedTokens.claimRefresh(connectionId);
202
206
  try {
@@ -265,10 +269,16 @@ var IntegrationBase = class IntegrationBase {
265
269
  }
266
270
  await this.runSessionTransition(() => this.disconnectLocked(options, signOut));
267
271
  }
268
- async disconnectLocked(options, signOut) {
269
- if (options?.currentSessionOnly && this._session === null) return;
272
+ async disconnectLocked(options, signOut, authority) {
273
+ if (options?.currentSessionOnly && this._session === null) return false;
270
274
  const connected = this._session != null;
271
- if (signOut) await (await this.authenticationService.get(this.authProvider.id)).deleteAllSessions(this.authProviderDescriptor);
275
+ if (authority != null) {
276
+ if (!await this.authenticationService.clearAbsentCloudScope(this.authProvider.id, this.authProviderDescriptor, authority) || !this.authenticationService.isCloudListCurrent(this.authProvider.id, this.domain, authority)) {
277
+ this._session = void 0;
278
+ this.invalidateDiscoveryCaches();
279
+ return false;
280
+ }
281
+ } else if (signOut) await (await this.authenticationService.get(this.authProvider.id)).deleteAllSessions(this.authProviderDescriptor);
272
282
  this.resetRequestExceptionCount("all");
273
283
  this._session = null;
274
284
  if (connected) {
@@ -281,6 +291,7 @@ var IntegrationBase = class IntegrationBase {
281
291
  });
282
292
  }
283
293
  await this.providerOnDisconnect?.();
294
+ return true;
284
295
  }
285
296
  async reauthenticate() {
286
297
  this.onStoredTokensReplaced();
@@ -386,6 +397,22 @@ var IntegrationBase = class IntegrationBase {
386
397
  invalidatePublishedSession(_publication, _affectsPrimary) {
387
398
  this.invalidateDiscoveryCaches();
388
399
  }
400
+ onCloudConnectionRetired(connectionId, retained = false) {
401
+ const wasConnected = this._session?.cloud === true && this._session.id === connectionId;
402
+ this.onSessionPublishing({
403
+ previousSessionId: connectionId,
404
+ connectionId,
405
+ cloud: true
406
+ });
407
+ if (!wasConnected || retained) return;
408
+ this._onDidChange.fire();
409
+ this.didChangeConnection.fire({
410
+ integration: this,
411
+ key: this.key,
412
+ reason: "disconnected"
413
+ });
414
+ this.providerOnDisconnect?.();
415
+ }
389
416
  onSessionsRemoving(connectionId, cloud) {
390
417
  this.invalidatePublishedSession({
391
418
  previousSessionId: connectionId,
@@ -478,8 +505,12 @@ var IntegrationBase = class IntegrationBase {
478
505
  syncCloudConnection(state, forceSync) {
479
506
  return this.runSessionTransition(() => this.syncCloudConnectionLocked(state, forceSync));
480
507
  }
481
- async syncCloudConnectionLocked(state, forceSync, reason = "explicit") {
508
+ syncListedCloudConnection(state, forceSync, authority) {
509
+ return this.runSessionTransition(() => this.syncCloudConnectionLocked(state, forceSync, "explicit", authority));
510
+ }
511
+ async syncCloudConnectionLocked(state, forceSync, reason = "explicit", authority) {
482
512
  const scope = getScopedLogger();
513
+ if (authority?.isCurrent() === false) return void 0;
483
514
  if (this._session?.cloud === false && state !== "connected") {
484
515
  if (this.id !== "github" && !this.skippedNonCloudReported) {
485
516
  this.ctx.hooks?.session?.onRefreshSkipped?.({
@@ -514,7 +545,8 @@ var IntegrationBase = class IntegrationBase {
514
545
  try {
515
546
  newSession = await this.resolveSessionLocked({
516
547
  sync: forceSync,
517
- refetch: resyncing
548
+ refetch: resyncing,
549
+ authority
518
550
  });
519
551
  } catch (ex) {
520
552
  refetchFailed = true;
@@ -522,13 +554,22 @@ var IntegrationBase = class IntegrationBase {
522
554
  failure = toError(ex);
523
555
  }
524
556
  if (oldSession && newSession && newSession === this._session && newSession.accessToken !== oldSession.accessToken) this.resetRecoveryAccounting();
525
- if (resyncing && newSession == null && !refetchFailed) await (await this.authenticationService.get(this.authProvider.id)).deleteSession(this.authProviderDescriptor, {
526
- preserveConfigured: false,
527
- signOutMark
528
- });
557
+ if (resyncing && newSession == null && !refetchFailed) {
558
+ const authProvider = await this.authenticationService.get(this.authProvider.id);
559
+ if (authority?.isCurrent() === false) return void 0;
560
+ const options = {
561
+ preserveConfigured: false,
562
+ signOutMark
563
+ };
564
+ if (authProvider instanceof CloudIntegrationAuthenticationProvider) await authProvider.deleteSession(this.authProviderDescriptor, {
565
+ ...options,
566
+ sync: authority
567
+ });
568
+ else await authProvider.deleteSession(this.authProviderDescriptor, options);
569
+ }
529
570
  break;
530
571
  }
531
- case "disconnected": await this.disconnectLocked({ silent: true }, true);
572
+ case "disconnected": if (!await this.disconnectLocked({ silent: true }, true, authority)) return void 0;
532
573
  }
533
574
  this._resyncs++;
534
575
  this._lastResyncFailure = failure;
@@ -838,14 +879,18 @@ var IntegrationBase = class IntegrationBase {
838
879
  } else if (this.ctx.storage.getWorkspace(this.connectedKey) === false) return;
839
880
  let session;
840
881
  try {
841
- session = await (await this.authenticationService.get(this.authProvider.id)).getSession(this.authProviderDescriptor, sync ? {
882
+ const authProvider = await this.authenticationService.get(this.authProvider.id);
883
+ if (options.authority?.isCurrent() === false) throw new CancellationError();
884
+ const request = sync ? {
842
885
  sync,
843
886
  refetch,
844
887
  source
845
888
  } : {
846
889
  createIfNeeded,
847
890
  source
848
- });
891
+ };
892
+ session = authProvider instanceof CloudIntegrationAuthenticationProvider ? await authProvider.getSession(this.authProviderDescriptor, request, options.authority) : await authProvider.getSession(this.authProviderDescriptor, request);
893
+ if (options.authority?.isCurrent() === false) throw new CancellationError();
849
894
  if (session?.expiresAt != null && session.expiresAt < /* @__PURE__ */ new Date()) session = null;
850
895
  if (session != null && !this.isSessionForIntegrationHost(session)) session = void 0;
851
896
  } catch (ex) {
@@ -886,19 +931,19 @@ var IntegrationBase = class IntegrationBase {
886
931
  if (session != null) {
887
932
  const publishedGeneration = this.getSessionDiscoveryGeneration(session.id, void 0, session.cloud);
888
933
  await this.ctx.storage.storeWorkspace(this.connectedKey, true);
889
- if (this._session !== session || publishedGeneration !== this.getSessionDiscoveryGeneration(session.id, void 0, session.cloud)) {
934
+ if (options.authority?.isCurrent() === false || this._session !== session || publishedGeneration !== this.getSessionDiscoveryGeneration(session.id, void 0, session.cloud)) {
890
935
  if (sync) throw new CancellationError();
891
936
  return;
892
937
  }
893
938
  queueMicrotask(() => {
894
- if (this._session !== session || publishedGeneration !== this.getSessionDiscoveryGeneration(session.id, void 0, session.cloud)) return;
939
+ if (options.authority?.isCurrent() === false || this._session !== session || publishedGeneration !== this.getSessionDiscoveryGeneration(session.id, void 0, session.cloud)) return;
895
940
  this._onDidChange.fire();
896
941
  this.didChangeConnection?.fire({
897
942
  integration: this,
898
943
  key: this.key,
899
944
  reason: "connected"
900
945
  });
901
- if (this._session !== session || publishedGeneration !== this.getSessionDiscoveryGeneration(session.id, void 0, session.cloud)) return;
946
+ if (options.authority?.isCurrent() === false || this._session !== session || publishedGeneration !== this.getSessionDiscoveryGeneration(session.id, void 0, session.cloud)) return;
902
947
  (async () => {
903
948
  try {
904
949
  await this.providerOnConnect?.();