@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.
- package/CHANGELOG.md +8 -1
- package/dist/_types/provider-apis/types/exportedTypes/github.d.ts +75 -0
- package/dist/_types/provider-apis/types/exportedTypes/types.d.ts +7 -0
- package/dist/plus/git-github/api/issueWrites.js +1 -1
- package/dist/plus/git-github/api/issueWrites.js.map +1 -1
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.d.ts +5 -1
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +44 -20
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -1
- package/dist/plus/integrations/authentication/cloudIntegrationObservations.d.ts +49 -0
- package/dist/plus/integrations/authentication/cloudIntegrationObservations.js +118 -0
- package/dist/plus/integrations/authentication/cloudIntegrationObservations.js.map +1 -0
- package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +38 -25
- package/dist/plus/integrations/authentication/configuredIntegrationService.js +376 -141
- package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +8 -2
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js +34 -4
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
- package/dist/plus/integrations/authentication/models.d.ts +6 -0
- package/dist/plus/integrations/authentication/models.js +9 -1
- package/dist/plus/integrations/authentication/models.js.map +1 -1
- package/dist/plus/integrations/authentication/observedAuthenticationProvider.d.ts +13 -2
- package/dist/plus/integrations/authentication/observedAuthenticationProvider.js +68 -30
- package/dist/plus/integrations/authentication/observedAuthenticationProvider.js.map +1 -1
- package/dist/plus/integrations/index.d.ts +2 -1
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +8 -0
- package/dist/plus/integrations/integrationService.js +148 -36
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +3 -0
- package/dist/plus/integrations/models/integration.d.ts +4 -0
- package/dist/plus/integrations/models/integration.js +61 -16
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/models/issueRelationships.d.ts +31 -0
- package/dist/plus/integrations/models/issueRelationships.js +0 -0
- package/dist/plus/integrations/models/publicIntegration.d.ts +0 -1
- package/dist/plus/integrations/providers/github.d.ts +8 -0
- package/dist/plus/integrations/providers/github.js +162 -2
- package/dist/plus/integrations/providers/github.js.map +1 -1
- package/dist/plus/integrations/providers/issueSorts.d.ts +0 -1
- package/dist/plus/integrations/providers/providerApiClient.d.ts +1 -1
- package/dist/plus/integrations/providers/providerApiClient.js +33 -14
- package/dist/plus/integrations/providers/providerApiClient.js.map +1 -1
- package/dist/plus/integrations/providers/providerErrors.d.ts +1 -0
- package/dist/plus/integrations/providers/providerErrors.js +1 -2
- package/dist/plus/integrations/providers/providerErrors.js.map +1 -1
- package/dist/plus/integrations/providers/providersApi.d.ts +2 -1
- package/dist/plus/integrations/providers/providersApi.js +2 -0
- package/dist/plus/integrations/providers/providersApi.js.map +1 -1
- package/dist/plus/integrations/reads/drains.d.ts +0 -1
- package/docs/integrations.md +36 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.53.0] - 2026-11-27
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Adds GitHub.com parent and sub-issue reads and writes to `IntegrationManager`. Hosts can page through direct children, read progress, and attach, detach or reorder issues using an explicit connection. Replacing a parent requires the approved previous parent and the credential proof from a relationship read (plus/integrations) ([#6294](https://github.com/gitkraken/vscode-gitlens/issues/6294))
|
|
14
|
+
|
|
9
15
|
## [0.52.0] - 2026-11-27
|
|
10
16
|
|
|
11
17
|
### Added
|
|
@@ -1478,7 +1484,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
|
|
|
1478
1484
|
|
|
1479
1485
|
- Initial release. Bundles `@gitlens/utils`, `@gitlens/git`, `@gitlens/git-cli`, `@gitlens/ai`, and `@gitlens/git-github` into a single core npm package with subpath exports.
|
|
1480
1486
|
|
|
1481
|
-
[unreleased]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.
|
|
1487
|
+
[unreleased]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.53.0...HEAD
|
|
1488
|
+
[0.53.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.52.0...gitkraken:releases/core/v0.53.0
|
|
1482
1489
|
[0.52.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.51.1...gitkraken:releases/core/v0.52.0
|
|
1483
1490
|
[0.51.1]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.51.0...gitkraken:releases/core/v0.51.1
|
|
1484
1491
|
[0.51.0]: https://github.com/gitkraken/vscode-gitlens/compare/releases/core/v0.50.0...gitkraken:releases/core/v0.51.0
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { CursorPageInfo } from "./types.js";
|
|
2
|
+
//#region ../../../../../setup-pnpm/store/v11/links/@gitkraken/provider-apis/0.71.0/9522f42a454c76d34136f57b94046d836283e270908b023c73710314fbf7df91/node_modules/@gitkraken/provider-apis/dist/types/exportedTypes/github.d.ts
|
|
3
|
+
export interface GitHubIssueRelationshipPin {
|
|
4
|
+
owner: string;
|
|
5
|
+
repo: string;
|
|
6
|
+
number: number;
|
|
7
|
+
expectedNodeId: string;
|
|
8
|
+
}
|
|
9
|
+
export interface GitHubIssueRelationshipReceipt {
|
|
10
|
+
owner: string;
|
|
11
|
+
repo: string;
|
|
12
|
+
number: number;
|
|
13
|
+
nodeId: string;
|
|
14
|
+
url: string;
|
|
15
|
+
title: string;
|
|
16
|
+
state: 'open' | 'closed';
|
|
17
|
+
}
|
|
18
|
+
export interface GitHubGetIssueRelationshipsInput {
|
|
19
|
+
issue: Omit<GitHubIssueRelationshipPin, 'expectedNodeId'> & {
|
|
20
|
+
expectedNodeId?: string;
|
|
21
|
+
};
|
|
22
|
+
cursor?: string;
|
|
23
|
+
limit?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface GitHubIssueRelationshipProgress {
|
|
26
|
+
total: number;
|
|
27
|
+
completed: number;
|
|
28
|
+
percentCompleted: number;
|
|
29
|
+
}
|
|
30
|
+
export interface GitHubIssueRelationshipFailure {
|
|
31
|
+
ok: false;
|
|
32
|
+
/** GitHub can report inaccessible resources as `not-found`. */
|
|
33
|
+
reason: 'unsupported' | 'no-connection' | 'forbidden' | 'not-found' | 'invalid-input' | 'conflict' | 'rate-limit' | 'unknown';
|
|
34
|
+
/** Present when no relationship mutation was dispatched. See `outcome` for the failed phase. */
|
|
35
|
+
mutationDispatched?: false;
|
|
36
|
+
phase?: 'detach' | 'attach';
|
|
37
|
+
outcome?: 'not-sent' | 'rejected' | 'unconfirmed';
|
|
38
|
+
/** The detach step completed and GitHub returned the child as parentless before an attach failure. */
|
|
39
|
+
detached?: true;
|
|
40
|
+
}
|
|
41
|
+
export type GitHubIssueRelationshipsResult = {
|
|
42
|
+
ok: true;
|
|
43
|
+
issue: GitHubIssueRelationshipReceipt;
|
|
44
|
+
parent: GitHubIssueRelationshipReceipt | null;
|
|
45
|
+
children: GitHubIssueRelationshipReceipt[];
|
|
46
|
+
/** Paginated reads report GitHub's aggregate, which can lag recent changes. */
|
|
47
|
+
progress: GitHubIssueRelationshipProgress;
|
|
48
|
+
pageInfo: CursorPageInfo;
|
|
49
|
+
} | GitHubIssueRelationshipFailure;
|
|
50
|
+
export type GitHubWriteIssueRelationshipInput = {
|
|
51
|
+
parent: GitHubIssueRelationshipPin;
|
|
52
|
+
child: GitHubIssueRelationshipPin;
|
|
53
|
+
} & ({
|
|
54
|
+
action: 'add';
|
|
55
|
+
replaceParent?: GitHubIssueRelationshipPin;
|
|
56
|
+
} | {
|
|
57
|
+
action: 'remove';
|
|
58
|
+
} | {
|
|
59
|
+
action: 'reorder';
|
|
60
|
+
placement: {
|
|
61
|
+
before: GitHubIssueRelationshipPin;
|
|
62
|
+
after?: never;
|
|
63
|
+
} | {
|
|
64
|
+
after: GitHubIssueRelationshipPin;
|
|
65
|
+
before?: never;
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
export type GitHubWriteIssueRelationshipResult = {
|
|
69
|
+
ok: true;
|
|
70
|
+
parent: GitHubIssueRelationshipReceipt;
|
|
71
|
+
child: GitHubIssueRelationshipReceipt;
|
|
72
|
+
previousParent: GitHubIssueRelationshipReceipt | null;
|
|
73
|
+
} | GitHubIssueRelationshipFailure;
|
|
74
|
+
//#endregion
|
|
75
|
+
//# sourceMappingURL=github.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region ../../../../../setup-pnpm/store/v11/links/@gitkraken/provider-apis/0.71.0/9522f42a454c76d34136f57b94046d836283e270908b023c73710314fbf7df91/node_modules/@gitkraken/provider-apis/dist/types/exportedTypes/types.d.ts
|
|
2
|
+
export interface CursorPageInfo {
|
|
3
|
+
hasNextPage: boolean;
|
|
4
|
+
endCursor: string | null;
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -60,7 +60,7 @@ function issueWriteFailure(ex) {
|
|
|
60
60
|
};
|
|
61
61
|
case 403: return {
|
|
62
62
|
ok: false,
|
|
63
|
-
reason: ex.message.toLowerCase().includes("rate limit") ? "rate-limit" : "forbidden"
|
|
63
|
+
reason: ex.response?.headers["retry-after"] != null || ex.message.toLowerCase().includes("rate limit") ? "rate-limit" : "forbidden"
|
|
64
64
|
};
|
|
65
65
|
case 404:
|
|
66
66
|
case 410: return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"issueWrites.js","names":[],"sources":["../../../../../plus/git-github/src/api/issueWrites.ts"],"sourcesContent":["import { GraphqlResponseError } from '@octokit/graphql';\nimport { RequestError } from '@octokit/request-error';\nimport type { RequestParameters } from '@octokit/types';\nimport { RequestRateLimitError } from '@gitlens/git/errors.js';\n\ntype GitHubIssueWriteTarget = { owner: string; repo: string };\n\nexport type GitHubIssueDelete = GitHubIssueWriteTarget & { number: number; expectedNodeId: string };\n\nexport type GitHubIssueWrite =\n\t| (GitHubIssueWriteTarget & { action: 'create'; title: string; body?: string })\n\t| (GitHubIssueDelete &\n\t\t\t(\n\t\t\t\t| { action: 'edit'; title?: string; body?: string }\n\t\t\t\t| { action: 'set-state'; state: 'open' }\n\t\t\t\t| { action: 'set-state'; state: 'closed'; reason: 'completed' | 'not_planned' }\n\t\t\t));\n\nexport type IssueWriteResult =\n\t| {\n\t\t\tok: true;\n\t\t\tissue: {\n\t\t\t\towner: string;\n\t\t\t\trepo: string;\n\t\t\t\tnumber: number;\n\t\t\t\tnodeId: string;\n\t\t\t\turl: string;\n\t\t\t\ttitle: string;\n\t\t\t\tbody: string;\n\t\t\t\tstate: 'open' | 'closed';\n\t\t\t};\n\t\t\tdeletedFromDifferentRepository?: true;\n\t }\n\t| {\n\t\t\tok: false;\n\t\t\treason:\n\t\t\t\t| 'unsupported'\n\t\t\t\t| 'no-connection'\n\t\t\t\t| 'forbidden'\n\t\t\t\t| 'not-found'\n\t\t\t\t| 'invalid-input'\n\t\t\t\t| 'rate-limit'\n\t\t\t\t| 'unknown';\n\t\t\t/** An unconfirmed result that failed before the mutation could be sent. */\n\t\t\tmutationDispatched?: false;\n\t };\n\nexport type GitHubIssueMutation =\n\t| GitHubIssueWrite\n\t| (GitHubIssueDelete & { action: 'delete' })\n\t| (GitHubIssueDelete & { action: 'resolve'; intent?: 'delete' });\ntype GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;\n\nconst issueFields = `\n\tid number url title body state\n\trepository { id owner { login } name }\n`;\n\ntype IssueNode = {\n\tid: string;\n\tnumber: number;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'OPEN' | 'CLOSED';\n\trepository: { id: string; owner: { login: string }; name: string };\n};\n\ntype RepositoryNode = {\n\tid: string;\n\thasIssuesEnabled: boolean;\n\tisArchived: boolean;\n};\n\ntype WriteTarget = {\n\trepository: RepositoryNode | null;\n\tnode?: (IssueNode & { __typename: string; viewerCanDelete?: boolean }) | null;\n};\n\nexport function isValidGitHubIssueMutation(input: GitHubIssueMutation): boolean {\n\tif (\n\t\ttypeof input.owner !== 'string' ||\n\t\t!/^[a-z\\d_-]+$/i.test(input.owner) ||\n\t\ttypeof input.repo !== 'string' ||\n\t\t!/^[a-z\\d._-]+$/i.test(input.repo) ||\n\t\tinput.repo === '.' ||\n\t\tinput.repo === '..'\n\t) {\n\t\treturn false;\n\t}\n\n\tif (\n\t\tinput.action !== 'create' &&\n\t\t(!Number.isInteger(input.number) ||\n\t\t\tinput.number < 1 ||\n\t\t\tinput.number > 2147483647 ||\n\t\t\ttypeof input.expectedNodeId !== 'string' ||\n\t\t\t!input.expectedNodeId.trim())\n\t) {\n\t\treturn false;\n\t}\n\n\tswitch (input.action) {\n\t\tcase 'create':\n\t\t\treturn isIssueTitle(input.title) && (input.body === undefined || typeof input.body === 'string');\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(input.title !== undefined || input.body !== undefined) &&\n\t\t\t\t(input.title === undefined || isIssueTitle(input.title)) &&\n\t\t\t\t(input.body === undefined || typeof input.body === 'string')\n\t\t\t);\n\t\tcase 'set-state':\n\t\t\treturn (\n\t\t\t\tinput.state === 'open' ||\n\t\t\t\t(input.state === 'closed' && (input.reason === 'completed' || input.reason === 'not_planned'))\n\t\t\t);\n\t\tcase 'delete':\n\t\t\treturn true;\n\t\tcase 'resolve':\n\t\t\treturn input.intent === undefined || input.intent === 'delete';\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isIssueTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nexport function issueWriteFailure(ex: unknown): Extract<IssueWriteResult, { ok: false }> {\n\tif (RequestRateLimitError.is(ex)) return { ok: false, reason: 'rate-limit' };\n\n\tif (ex instanceof GraphqlResponseError) {\n\t\tif (ex.errors?.some(error => error.type === 'RATE_LIMIT' || error.type === 'RATE_LIMITED')) {\n\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\n\t\tswitch (ex.errors?.[0]?.type) {\n\t\t\tcase 'NOT_FOUND':\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 'FORBIDDEN':\n\t\t\tcase 'INSUFFICIENT_SCOPES':\n\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\tcase 'BAD_USER_INPUT':\n\t\t\tcase 'UNPROCESSABLE':\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t}\n\t}\n\n\tif (ex instanceof RequestError) {\n\t\tswitch (ex.status) {\n\t\t\tcase 400:\n\t\t\tcase 422:\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t\tcase 401:\n\t\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t\tcase 403:\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\treason: ex.message.toLowerCase().includes('rate limit') ? 'rate-limit' : 'forbidden',\n\t\t\t\t};\n\t\t\tcase 404:\n\t\t\tcase 410:\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 429:\n\t\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\t}\n\n\treturn { ok: false, reason: 'unknown' };\n}\n\nexport async function mutateGitHubIssue(\n\tinput: GitHubIssueMutation,\n\tgraphql: GraphqlRequest,\n\t{ origin, isSessionCurrent }: { origin?: string; isSessionCurrent?: () => Promise<boolean> },\n): Promise<IssueWriteResult> {\n\tlet dispatched = false;\n\tconst mutate: GraphqlRequest = (query, variables) => {\n\t\tdispatched = true;\n\t\treturn graphql(query, variables);\n\t};\n\ttry {\n\t\tconst { owner, repo } = input;\n\t\tconst checkDelete = input.action === 'delete' || (input.action === 'resolve' && input.intent === 'delete');\n\t\tconst target =\n\t\t\tinput.action === 'create'\n\t\t\t\t? await graphql<WriteTarget>(\n\t\t\t\t\t\t`\n\t\t\t\t\t\t\tquery IssueCreateTarget($owner: String!, $repo: String!) {\n\t\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t\thasIssuesEnabled\n\t\t\t\t\t\t\t\t\tisArchived\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t`,\n\t\t\t\t\t\t{ owner: owner, repo: repo },\n\t\t\t\t\t)\n\t\t\t\t: await graphql<WriteTarget>(\n\t\t\t\t\t\t`query IssueWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!) {\n\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\tid hasIssuesEnabled isArchived\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnode(id: $expectedNodeId) {\n\t\t\t\t\t\t\t\t__typename\n\t\t\t\t\t\t\t\t... on Issue {\n\t\t\t\t\t\t\t\t\t${issueFields}\n\t\t\t\t\t\t\t\t\t${checkDelete ? 'viewerCanDelete' : ''}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\towner: owner,\n\t\t\t\t\t\t\trepo: repo,\n\t\t\t\t\t\t\texpectedNodeId: input.expectedNodeId,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\tconst repository = target?.repository;\n\t\tif (repository == null) return { ok: false, reason: 'not-found' };\n\t\tif (repository.isArchived) return { ok: false, reason: 'forbidden' };\n\t\tif (!repository.hasIssuesEnabled) return { ok: false, reason: 'unsupported' };\n\n\t\tif (input.action === 'create') {\n\t\t\tif (isSessionCurrent != null && !(await isSessionCurrent())) {\n\t\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t\t}\n\n\t\t\treturn await writeIssue(\n\t\t\t\tmutate,\n\t\t\t\t'createIssue',\n\t\t\t\t'CreateIssueInput',\n\t\t\t\t{\n\t\t\t\t\trepositoryId: repository.id,\n\t\t\t\t\ttitle: input.title,\n\t\t\t\t\tbody: input.body,\n\t\t\t\t},\n\t\t\t\torigin,\n\t\t\t);\n\t\t}\n\n\t\tconst issue = target?.node;\n\t\tif (\n\t\t\tissue?.__typename !== 'Issue' ||\n\t\t\t!isGitHubWriteUrlOnInstallation(issue.url, origin) ||\n\t\t\tissue.number !== input.number ||\n\t\t\tissue.repository.id !== repository.id ||\n\t\t\tissue.repository.owner.login.toLowerCase() !== owner.toLowerCase() ||\n\t\t\tissue.repository.name.toLowerCase() !== repo.toLowerCase()\n\t\t) {\n\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t}\n\n\t\tif (checkDelete && issue.viewerCanDelete !== true) return { ok: false, reason: 'forbidden' };\n\n\t\tif (input.action === 'resolve') return toIssueWriteResult(issue);\n\n\t\tif (isSessionCurrent != null && !(await isSessionCurrent())) {\n\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t}\n\n\t\tswitch (input.action) {\n\t\t\tcase 'edit':\n\t\t\t\treturn await writeIssue(\n\t\t\t\t\tmutate,\n\t\t\t\t\t'updateIssue',\n\t\t\t\t\t'UpdateIssueInput',\n\t\t\t\t\t{\n\t\t\t\t\t\tid: issue.id,\n\t\t\t\t\t\ttitle: input.title,\n\t\t\t\t\t\tbody: input.body,\n\t\t\t\t\t},\n\t\t\t\t\torigin,\n\t\t\t\t);\n\t\t\tcase 'set-state':\n\t\t\t\treturn input.state === 'open'\n\t\t\t\t\t? await writeIssue(mutate, 'reopenIssue', 'ReopenIssueInput', { issueId: issue.id }, origin)\n\t\t\t\t\t: await writeIssue(\n\t\t\t\t\t\t\tmutate,\n\t\t\t\t\t\t\t'closeIssue',\n\t\t\t\t\t\t\t'CloseIssueInput',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tissueId: issue.id,\n\t\t\t\t\t\t\t\tstateReason: input.reason === 'completed' ? 'COMPLETED' : 'NOT_PLANNED',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\torigin,\n\t\t\t\t\t\t);\n\t\t\tcase 'delete': {\n\t\t\t\tconst result = await mutate<{ deleteIssue: { repository: { id: string } | null } | null }>(\n\t\t\t\t\t`\n\t\t\t\t\t\tmutation DeleteIssue($issueId: ID!) {\n\t\t\t\t\t\t\tdeleteIssue(input: { issueId: $issueId }) {\n\t\t\t\t\t\t\t\trepository {\n\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t`,\n\t\t\t\t\t{ issueId: issue.id },\n\t\t\t\t);\n\t\t\t\tconst deletedRepositoryId = result?.deleteIssue?.repository?.id;\n\t\t\t\treturn typeof deletedRepositoryId === 'string' && deletedRepositoryId.length > 0\n\t\t\t\t\t? toIssueWriteResult(issue, deletedRepositoryId !== repository.id)\n\t\t\t\t\t: { ok: false, reason: 'unknown' };\n\t\t\t}\n\t\t}\n\t} catch (ex) {\n\t\tif (\n\t\t\torigin != null &&\n\t\t\tex instanceof GraphqlResponseError &&\n\t\t\tex.data == null &&\n\t\t\tex.errors?.some(error => {\n\t\t\t\tconst code: unknown = error.extensions?.code;\n\t\t\t\treturn (\n\t\t\t\t\tcode === 'undefinedField' || code === 'argumentNotAccepted' || code === 'variableRequiresValidType'\n\t\t\t\t);\n\t\t\t})\n\t\t) {\n\t\t\treturn { ok: false, reason: 'unsupported' };\n\t\t}\n\n\t\tif (\n\t\t\tdispatched &&\n\t\t\tex instanceof GraphqlResponseError &&\n\t\t\tex.errors?.some(error => error.path != null && error.path.length > 1)\n\t\t) {\n\t\t\treturn { ok: false, reason: 'unknown' };\n\t\t}\n\n\t\tconst failure = issueWriteFailure(ex);\n\t\treturn origin != null && failure.reason === 'unknown' && !dispatched\n\t\t\t? { ...failure, mutationDispatched: false }\n\t\t\t: failure;\n\t}\n}\n\nasync function writeIssue(\n\tgraphql: GraphqlRequest,\n\tmutation: 'createIssue' | 'updateIssue' | 'closeIssue' | 'reopenIssue',\n\tinputType: string,\n\tinput: Record<string, string | undefined>,\n\torigin: string | undefined,\n): Promise<IssueWriteResult> {\n\tconst result = await graphql<{ change: { issue: IssueNode | null } | null }>(\n\t\t`mutation WriteIssue($input: ${inputType}!) {\n\t\t\tchange: ${mutation}(input: $input) { issue { ${issueFields} } }\n\t\t}`,\n\t\t{ input: input },\n\t);\n\tconst issue = result?.change?.issue;\n\treturn issue != null && isGitHubWriteUrlOnInstallation(issue.url, origin)\n\t\t? toIssueWriteResult(issue)\n\t\t: { ok: false, reason: 'unknown' };\n}\n\nexport function isGitHubWriteUrlOnInstallation(value: unknown, origin: string | undefined): boolean {\n\tif (origin == null) return true;\n\n\tconst url = typeof value === 'string' ? URL.parse(value) : null;\n\treturn (\n\t\turl?.origin === origin &&\n\t\t(url.protocol === 'https:' || url.protocol === 'http:') &&\n\t\t!url.username &&\n\t\t!url.password\n\t);\n}\n\nfunction toIssueWriteResult(issue: IssueNode, deletedFromDifferentRepository = false): IssueWriteResult {\n\treturn {\n\t\tok: true,\n\t\t...(deletedFromDifferentRepository && { deletedFromDifferentRepository: true }),\n\t\tissue: {\n\t\t\towner: issue.repository.owner.login,\n\t\t\trepo: issue.repository.name,\n\t\t\tnumber: issue.number,\n\t\t\tnodeId: issue.id,\n\t\t\turl: issue.url,\n\t\t\ttitle: issue.title,\n\t\t\tbody: issue.body,\n\t\t\tstate: issue.state === 'CLOSED' ? 'closed' : 'open',\n\t\t},\n\t};\n}\n"],"mappings":";;;;AAqDA,MAAM,cAAc;;;;AA0BpB,SAAgB,2BAA2B,OAAqC;CAC/E,IACC,OAAO,MAAM,UAAU,YACvB,CAAC,gBAAgB,KAAK,MAAM,KAAK,KACjC,OAAO,MAAM,SAAS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OAAO;GACN,OAAO,MAAM,WAAW,MAAM;GAC9B,MAAM,MAAM,WAAW;GACvB,QAAQ,MAAM;GACd,QAAQ,MAAM;GACd,KAAK,MAAM;GACX,OAAO,MAAM;GACb,MAAM,MAAM;GACZ,OAAO,MAAM,UAAU,WAAW,WAAW;EAC9C;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"issueWrites.js","names":[],"sources":["../../../../../plus/git-github/src/api/issueWrites.ts"],"sourcesContent":["import { GraphqlResponseError } from '@octokit/graphql';\nimport { RequestError } from '@octokit/request-error';\nimport type { RequestParameters } from '@octokit/types';\nimport { RequestRateLimitError } from '@gitlens/git/errors.js';\n\ntype GitHubIssueWriteTarget = { owner: string; repo: string };\n\nexport type GitHubIssueDelete = GitHubIssueWriteTarget & { number: number; expectedNodeId: string };\n\nexport type GitHubIssueWrite =\n\t| (GitHubIssueWriteTarget & { action: 'create'; title: string; body?: string })\n\t| (GitHubIssueDelete &\n\t\t\t(\n\t\t\t\t| { action: 'edit'; title?: string; body?: string }\n\t\t\t\t| { action: 'set-state'; state: 'open' }\n\t\t\t\t| { action: 'set-state'; state: 'closed'; reason: 'completed' | 'not_planned' }\n\t\t\t));\n\nexport type IssueWriteResult =\n\t| {\n\t\t\tok: true;\n\t\t\tissue: {\n\t\t\t\towner: string;\n\t\t\t\trepo: string;\n\t\t\t\tnumber: number;\n\t\t\t\tnodeId: string;\n\t\t\t\turl: string;\n\t\t\t\ttitle: string;\n\t\t\t\tbody: string;\n\t\t\t\tstate: 'open' | 'closed';\n\t\t\t};\n\t\t\tdeletedFromDifferentRepository?: true;\n\t }\n\t| {\n\t\t\tok: false;\n\t\t\treason:\n\t\t\t\t| 'unsupported'\n\t\t\t\t| 'no-connection'\n\t\t\t\t| 'forbidden'\n\t\t\t\t| 'not-found'\n\t\t\t\t| 'invalid-input'\n\t\t\t\t| 'rate-limit'\n\t\t\t\t| 'unknown';\n\t\t\t/** An unconfirmed result that failed before the mutation could be sent. */\n\t\t\tmutationDispatched?: false;\n\t };\n\nexport type GitHubIssueMutation =\n\t| GitHubIssueWrite\n\t| (GitHubIssueDelete & { action: 'delete' })\n\t| (GitHubIssueDelete & { action: 'resolve'; intent?: 'delete' });\ntype GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;\n\nconst issueFields = `\n\tid number url title body state\n\trepository { id owner { login } name }\n`;\n\ntype IssueNode = {\n\tid: string;\n\tnumber: number;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'OPEN' | 'CLOSED';\n\trepository: { id: string; owner: { login: string }; name: string };\n};\n\ntype RepositoryNode = {\n\tid: string;\n\thasIssuesEnabled: boolean;\n\tisArchived: boolean;\n};\n\ntype WriteTarget = {\n\trepository: RepositoryNode | null;\n\tnode?: (IssueNode & { __typename: string; viewerCanDelete?: boolean }) | null;\n};\n\nexport function isValidGitHubIssueMutation(input: GitHubIssueMutation): boolean {\n\tif (\n\t\ttypeof input.owner !== 'string' ||\n\t\t!/^[a-z\\d_-]+$/i.test(input.owner) ||\n\t\ttypeof input.repo !== 'string' ||\n\t\t!/^[a-z\\d._-]+$/i.test(input.repo) ||\n\t\tinput.repo === '.' ||\n\t\tinput.repo === '..'\n\t) {\n\t\treturn false;\n\t}\n\n\tif (\n\t\tinput.action !== 'create' &&\n\t\t(!Number.isInteger(input.number) ||\n\t\t\tinput.number < 1 ||\n\t\t\tinput.number > 2147483647 ||\n\t\t\ttypeof input.expectedNodeId !== 'string' ||\n\t\t\t!input.expectedNodeId.trim())\n\t) {\n\t\treturn false;\n\t}\n\n\tswitch (input.action) {\n\t\tcase 'create':\n\t\t\treturn isIssueTitle(input.title) && (input.body === undefined || typeof input.body === 'string');\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(input.title !== undefined || input.body !== undefined) &&\n\t\t\t\t(input.title === undefined || isIssueTitle(input.title)) &&\n\t\t\t\t(input.body === undefined || typeof input.body === 'string')\n\t\t\t);\n\t\tcase 'set-state':\n\t\t\treturn (\n\t\t\t\tinput.state === 'open' ||\n\t\t\t\t(input.state === 'closed' && (input.reason === 'completed' || input.reason === 'not_planned'))\n\t\t\t);\n\t\tcase 'delete':\n\t\t\treturn true;\n\t\tcase 'resolve':\n\t\t\treturn input.intent === undefined || input.intent === 'delete';\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isIssueTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nexport function issueWriteFailure(ex: unknown): Extract<IssueWriteResult, { ok: false }> {\n\tif (RequestRateLimitError.is(ex)) return { ok: false, reason: 'rate-limit' };\n\n\tif (ex instanceof GraphqlResponseError) {\n\t\tif (ex.errors?.some(error => error.type === 'RATE_LIMIT' || error.type === 'RATE_LIMITED')) {\n\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\n\t\tswitch (ex.errors?.[0]?.type) {\n\t\t\tcase 'NOT_FOUND':\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 'FORBIDDEN':\n\t\t\tcase 'INSUFFICIENT_SCOPES':\n\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\tcase 'BAD_USER_INPUT':\n\t\t\tcase 'UNPROCESSABLE':\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t}\n\t}\n\n\tif (ex instanceof RequestError) {\n\t\tswitch (ex.status) {\n\t\t\tcase 400:\n\t\t\tcase 422:\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t\tcase 401:\n\t\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t\tcase 403:\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\treason:\n\t\t\t\t\t\tex.response?.headers['retry-after'] != null || ex.message.toLowerCase().includes('rate limit')\n\t\t\t\t\t\t\t? 'rate-limit'\n\t\t\t\t\t\t\t: 'forbidden',\n\t\t\t\t};\n\t\t\tcase 404:\n\t\t\tcase 410:\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 429:\n\t\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\t}\n\n\treturn { ok: false, reason: 'unknown' };\n}\n\nexport async function mutateGitHubIssue(\n\tinput: GitHubIssueMutation,\n\tgraphql: GraphqlRequest,\n\t{ origin, isSessionCurrent }: { origin?: string; isSessionCurrent?: () => Promise<boolean> },\n): Promise<IssueWriteResult> {\n\tlet dispatched = false;\n\tconst mutate: GraphqlRequest = (query, variables) => {\n\t\tdispatched = true;\n\t\treturn graphql(query, variables);\n\t};\n\ttry {\n\t\tconst { owner, repo } = input;\n\t\tconst checkDelete = input.action === 'delete' || (input.action === 'resolve' && input.intent === 'delete');\n\t\tconst target =\n\t\t\tinput.action === 'create'\n\t\t\t\t? await graphql<WriteTarget>(\n\t\t\t\t\t\t`\n\t\t\t\t\t\t\tquery IssueCreateTarget($owner: String!, $repo: String!) {\n\t\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t\thasIssuesEnabled\n\t\t\t\t\t\t\t\t\tisArchived\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t`,\n\t\t\t\t\t\t{ owner: owner, repo: repo },\n\t\t\t\t\t)\n\t\t\t\t: await graphql<WriteTarget>(\n\t\t\t\t\t\t`query IssueWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!) {\n\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\tid hasIssuesEnabled isArchived\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnode(id: $expectedNodeId) {\n\t\t\t\t\t\t\t\t__typename\n\t\t\t\t\t\t\t\t... on Issue {\n\t\t\t\t\t\t\t\t\t${issueFields}\n\t\t\t\t\t\t\t\t\t${checkDelete ? 'viewerCanDelete' : ''}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\towner: owner,\n\t\t\t\t\t\t\trepo: repo,\n\t\t\t\t\t\t\texpectedNodeId: input.expectedNodeId,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\tconst repository = target?.repository;\n\t\tif (repository == null) return { ok: false, reason: 'not-found' };\n\t\tif (repository.isArchived) return { ok: false, reason: 'forbidden' };\n\t\tif (!repository.hasIssuesEnabled) return { ok: false, reason: 'unsupported' };\n\n\t\tif (input.action === 'create') {\n\t\t\tif (isSessionCurrent != null && !(await isSessionCurrent())) {\n\t\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t\t}\n\n\t\t\treturn await writeIssue(\n\t\t\t\tmutate,\n\t\t\t\t'createIssue',\n\t\t\t\t'CreateIssueInput',\n\t\t\t\t{\n\t\t\t\t\trepositoryId: repository.id,\n\t\t\t\t\ttitle: input.title,\n\t\t\t\t\tbody: input.body,\n\t\t\t\t},\n\t\t\t\torigin,\n\t\t\t);\n\t\t}\n\n\t\tconst issue = target?.node;\n\t\tif (\n\t\t\tissue?.__typename !== 'Issue' ||\n\t\t\t!isGitHubWriteUrlOnInstallation(issue.url, origin) ||\n\t\t\tissue.number !== input.number ||\n\t\t\tissue.repository.id !== repository.id ||\n\t\t\tissue.repository.owner.login.toLowerCase() !== owner.toLowerCase() ||\n\t\t\tissue.repository.name.toLowerCase() !== repo.toLowerCase()\n\t\t) {\n\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t}\n\n\t\tif (checkDelete && issue.viewerCanDelete !== true) return { ok: false, reason: 'forbidden' };\n\n\t\tif (input.action === 'resolve') return toIssueWriteResult(issue);\n\n\t\tif (isSessionCurrent != null && !(await isSessionCurrent())) {\n\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t}\n\n\t\tswitch (input.action) {\n\t\t\tcase 'edit':\n\t\t\t\treturn await writeIssue(\n\t\t\t\t\tmutate,\n\t\t\t\t\t'updateIssue',\n\t\t\t\t\t'UpdateIssueInput',\n\t\t\t\t\t{\n\t\t\t\t\t\tid: issue.id,\n\t\t\t\t\t\ttitle: input.title,\n\t\t\t\t\t\tbody: input.body,\n\t\t\t\t\t},\n\t\t\t\t\torigin,\n\t\t\t\t);\n\t\t\tcase 'set-state':\n\t\t\t\treturn input.state === 'open'\n\t\t\t\t\t? await writeIssue(mutate, 'reopenIssue', 'ReopenIssueInput', { issueId: issue.id }, origin)\n\t\t\t\t\t: await writeIssue(\n\t\t\t\t\t\t\tmutate,\n\t\t\t\t\t\t\t'closeIssue',\n\t\t\t\t\t\t\t'CloseIssueInput',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tissueId: issue.id,\n\t\t\t\t\t\t\t\tstateReason: input.reason === 'completed' ? 'COMPLETED' : 'NOT_PLANNED',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\torigin,\n\t\t\t\t\t\t);\n\t\t\tcase 'delete': {\n\t\t\t\tconst result = await mutate<{ deleteIssue: { repository: { id: string } | null } | null }>(\n\t\t\t\t\t`\n\t\t\t\t\t\tmutation DeleteIssue($issueId: ID!) {\n\t\t\t\t\t\t\tdeleteIssue(input: { issueId: $issueId }) {\n\t\t\t\t\t\t\t\trepository {\n\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t`,\n\t\t\t\t\t{ issueId: issue.id },\n\t\t\t\t);\n\t\t\t\tconst deletedRepositoryId = result?.deleteIssue?.repository?.id;\n\t\t\t\treturn typeof deletedRepositoryId === 'string' && deletedRepositoryId.length > 0\n\t\t\t\t\t? toIssueWriteResult(issue, deletedRepositoryId !== repository.id)\n\t\t\t\t\t: { ok: false, reason: 'unknown' };\n\t\t\t}\n\t\t}\n\t} catch (ex) {\n\t\tif (\n\t\t\torigin != null &&\n\t\t\tex instanceof GraphqlResponseError &&\n\t\t\tex.data == null &&\n\t\t\tex.errors?.some(error => {\n\t\t\t\tconst code: unknown = error.extensions?.code;\n\t\t\t\treturn (\n\t\t\t\t\tcode === 'undefinedField' || code === 'argumentNotAccepted' || code === 'variableRequiresValidType'\n\t\t\t\t);\n\t\t\t})\n\t\t) {\n\t\t\treturn { ok: false, reason: 'unsupported' };\n\t\t}\n\n\t\tif (\n\t\t\tdispatched &&\n\t\t\tex instanceof GraphqlResponseError &&\n\t\t\tex.errors?.some(error => error.path != null && error.path.length > 1)\n\t\t) {\n\t\t\treturn { ok: false, reason: 'unknown' };\n\t\t}\n\n\t\tconst failure = issueWriteFailure(ex);\n\t\treturn origin != null && failure.reason === 'unknown' && !dispatched\n\t\t\t? { ...failure, mutationDispatched: false }\n\t\t\t: failure;\n\t}\n}\n\nasync function writeIssue(\n\tgraphql: GraphqlRequest,\n\tmutation: 'createIssue' | 'updateIssue' | 'closeIssue' | 'reopenIssue',\n\tinputType: string,\n\tinput: Record<string, string | undefined>,\n\torigin: string | undefined,\n): Promise<IssueWriteResult> {\n\tconst result = await graphql<{ change: { issue: IssueNode | null } | null }>(\n\t\t`mutation WriteIssue($input: ${inputType}!) {\n\t\t\tchange: ${mutation}(input: $input) { issue { ${issueFields} } }\n\t\t}`,\n\t\t{ input: input },\n\t);\n\tconst issue = result?.change?.issue;\n\treturn issue != null && isGitHubWriteUrlOnInstallation(issue.url, origin)\n\t\t? toIssueWriteResult(issue)\n\t\t: { ok: false, reason: 'unknown' };\n}\n\nexport function isGitHubWriteUrlOnInstallation(value: unknown, origin: string | undefined): boolean {\n\tif (origin == null) return true;\n\n\tconst url = typeof value === 'string' ? URL.parse(value) : null;\n\treturn (\n\t\turl?.origin === origin &&\n\t\t(url.protocol === 'https:' || url.protocol === 'http:') &&\n\t\t!url.username &&\n\t\t!url.password\n\t);\n}\n\nfunction toIssueWriteResult(issue: IssueNode, deletedFromDifferentRepository = false): IssueWriteResult {\n\treturn {\n\t\tok: true,\n\t\t...(deletedFromDifferentRepository && { deletedFromDifferentRepository: true }),\n\t\tissue: {\n\t\t\towner: issue.repository.owner.login,\n\t\t\trepo: issue.repository.name,\n\t\t\tnumber: issue.number,\n\t\t\tnodeId: issue.id,\n\t\t\turl: issue.url,\n\t\t\ttitle: issue.title,\n\t\t\tbody: issue.body,\n\t\t\tstate: issue.state === 'CLOSED' ? 'closed' : 'open',\n\t\t},\n\t};\n}\n"],"mappings":";;;;AAqDA,MAAM,cAAc;;;;AA0BpB,SAAgB,2BAA2B,OAAqC;CAC/E,IACC,OAAO,MAAM,UAAU,YACvB,CAAC,gBAAgB,KAAK,MAAM,KAAK,KACjC,OAAO,MAAM,SAAS,YACtB,CAAC,iBAAiB,KAAK,MAAM,IAAI,KACjC,MAAM,SAAS,OACf,MAAM,SAAS,MAEf,OAAO;CAGR,IACC,MAAM,WAAW,aAChB,CAAC,OAAO,UAAU,MAAM,MAAM,KAC9B,MAAM,SAAS,KACf,MAAM,SAAS,cACf,OAAO,MAAM,mBAAmB,YAChC,CAAC,MAAM,eAAe,KAAK,IAE5B,OAAO;CAGR,QAAQ,MAAM,QAAd;EACC,KAAK,UACJ,OAAO,aAAa,MAAM,KAAK,MAAM,MAAM,SAAS,KAAA,KAAa,OAAO,MAAM,SAAS;EACxF,KAAK,QACJ,QACE,MAAM,UAAU,KAAA,KAAa,MAAM,SAAS,KAAA,OAC5C,MAAM,UAAU,KAAA,KAAa,aAAa,MAAM,KAAK,OACrD,MAAM,SAAS,KAAA,KAAa,OAAO,MAAM,SAAS;EAErD,KAAK,aACJ,OACC,MAAM,UAAU,UACf,MAAM,UAAU,aAAa,MAAM,WAAW,eAAe,MAAM,WAAW;EAEjF,KAAK,UACJ,OAAO;EACR,KAAK,WACJ,OAAO,MAAM,WAAW,KAAA,KAAa,MAAM,WAAW;EACvD,SACC,OAAO;CACT;AACD;AAEA,SAAS,aAAa,OAAiC;CACtD,OAAO,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,SAAS;AAC3D;AAEA,SAAgB,kBAAkB,IAAuD;CACxF,IAAI,sBAAsB,GAAG,EAAE,GAAG,O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,IAAI;EAAO,QAAQ;CAAU;AACnC;AAEA,SAAgB,+BAA+B,OAAgB,QAAqC;CACnG,IAAI,UAAU,MAAM,OAAO;CAE3B,MAAM,MAAM,OAAO,UAAU,WAAW,IAAI,MAAM,KAAK,IAAI;CAC3D,OACC,KAAK,WAAW,WACf,IAAI,aAAa,YAAY,IAAI,aAAa,YAC/C,CAAC,IAAI,YACL,CAAC,IAAI;AAEP;AAEA,SAAS,mBAAmB,OAAkB,iCAAiC,OAAyB;CACvG,OAAO;EACN,IAAI;EACJ,GAAI,kCAAkC,EAAE,gCAAgC,KAAK;EAC7E,OAAO;GACN,OAAO,MAAM,WAAW,MAAM;GAC9B,MAAM,MAAM,WAAW;GACvB,QAAQ,MAAM;GACd,QAAQ,MAAM;GACd,KAAK,MAAM;GACX,OAAO,MAAM;GACb,MAAM,MAAM;GACZ,OAAO,MAAM,UAAU,WAAW,WAAW;EAC9C;CACD;AACD"}
|
|
@@ -2,6 +2,7 @@ import { Disposable } from "../../../utils/disposable.js";
|
|
|
2
2
|
import { Event } from "../../../utils/event.js";
|
|
3
3
|
import { ProviderAuthenticationSession } from "./models.js";
|
|
4
4
|
import { IntegrationIds } from "../constants.js";
|
|
5
|
+
import { CloudIntegrationSync } from "./cloudIntegrationObservations.js";
|
|
5
6
|
import { GetSessionOptions, IntegrationAuthenticationProvider, IntegrationAuthenticationSessionDescriptor } from "./integrationAuthenticationProvider.js";
|
|
6
7
|
import { ConfiguredIntegrationService } from "./configuredIntegrationService.js";
|
|
7
8
|
import { IntegrationAuthenticationService } from "./integrationAuthenticationService.js";
|
|
@@ -18,6 +19,7 @@ declare abstract class IntegrationAuthenticationProviderBase<ID extends Integrat
|
|
|
18
19
|
protected readonly authenticationService: IntegrationAuthenticationService;
|
|
19
20
|
protected readonly configuredIntegrationService: ConfiguredIntegrationService;
|
|
20
21
|
protected readonly disposables: Disposable[];
|
|
22
|
+
protected readonly primaryResponses: WeakMap<ProviderAuthenticationSession, "legacy" | "named">;
|
|
21
23
|
constructor(authenticationService: IntegrationAuthenticationService, configuredIntegrationService: ConfiguredIntegrationService);
|
|
22
24
|
dispose(): void;
|
|
23
25
|
private readonly _onDidChange;
|
|
@@ -26,9 +28,11 @@ declare abstract class IntegrationAuthenticationProviderBase<ID extends Integrat
|
|
|
26
28
|
deleteSession(descriptor: IntegrationAuthenticationSessionDescriptor, options?: {
|
|
27
29
|
preserveConfigured?: boolean;
|
|
28
30
|
signOutMark?: number;
|
|
31
|
+
sync?: CloudIntegrationSync;
|
|
29
32
|
}): Promise<void>;
|
|
30
33
|
deleteAllSessions(descriptor?: IntegrationAuthenticationSessionDescriptor): Promise<void>;
|
|
31
|
-
|
|
34
|
+
clearSessions(descriptor?: IntegrationAuthenticationSessionDescriptor, sync?: CloudIntegrationSync): Promise<boolean>;
|
|
35
|
+
getSession(descriptor: IntegrationAuthenticationSessionDescriptor, options?: GetSessionOptions, authority?: CloudIntegrationSync): Promise<ProviderAuthenticationSession | undefined>;
|
|
32
36
|
private getImplicitCloudConnectionId;
|
|
33
37
|
private acquireSession;
|
|
34
38
|
protected connectNewSession(_descriptor: IntegrationAuthenticationSessionDescriptor, _options: GetSessionOptions | undefined): Promise<ProviderAuthenticationSession | undefined>;
|
|
@@ -11,6 +11,7 @@ var IntegrationAuthenticationProviderBase = class {
|
|
|
11
11
|
authenticationService;
|
|
12
12
|
configuredIntegrationService;
|
|
13
13
|
disposables = [];
|
|
14
|
+
primaryResponses = /* @__PURE__ */ new WeakMap();
|
|
14
15
|
constructor(authenticationService, configuredIntegrationService) {
|
|
15
16
|
this.authenticationService = authenticationService;
|
|
16
17
|
this.configuredIntegrationService = configuredIntegrationService;
|
|
@@ -30,18 +31,23 @@ var IntegrationAuthenticationProviderBase = class {
|
|
|
30
31
|
cloud: true
|
|
31
32
|
}, true, {
|
|
32
33
|
preserveConfigured: options?.preserveConfigured ?? true,
|
|
33
|
-
signOutMark: options?.signOutMark
|
|
34
|
+
signOutMark: options?.signOutMark,
|
|
35
|
+
sync: options?.sync
|
|
34
36
|
}) && configured?.length) this.fireChange();
|
|
35
37
|
}
|
|
36
38
|
async deleteAllSessions(descriptor) {
|
|
39
|
+
await this.clearSessions(descriptor);
|
|
40
|
+
}
|
|
41
|
+
async clearSessions(descriptor, sync) {
|
|
37
42
|
const domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : void 0;
|
|
38
43
|
const configured = this.configuredIntegrationService.getConfigured(this.authProviderId, { domain });
|
|
39
|
-
await this.configuredIntegrationService.deleteAllStoredSessions(this.authProviderId, void 0, domain);
|
|
40
|
-
if (configured
|
|
44
|
+
const cleared = await this.configuredIntegrationService.deleteAllStoredSessions(this.authProviderId, void 0, domain, sync);
|
|
45
|
+
if (cleared && configured.length) this.fireChange();
|
|
46
|
+
return cleared;
|
|
41
47
|
}
|
|
42
|
-
async getSession(descriptor, options) {
|
|
48
|
+
async getSession(descriptor, options, authority) {
|
|
43
49
|
const signOutMark = this.configuredIntegrationService.getSignOutMark();
|
|
44
|
-
if (!this.configuredIntegrationService.serializesCredentialAcquisition(this.authProviderId)) return this.acquireSession(descriptor, options, signOutMark);
|
|
50
|
+
if (!this.configuredIntegrationService.serializesCredentialAcquisition(this.authProviderId)) return this.acquireSession(descriptor, options, signOutMark, signOutMark, authority);
|
|
45
51
|
const connectionId = descriptor.connectionId || this.getImplicitCloudConnectionId(descriptor, options);
|
|
46
52
|
const session = await this.configuredIntegrationService.withCredentialAcquisition(this.authProviderId, connectionId, () => this.acquireSession(connectionId != null ? {
|
|
47
53
|
...descriptor,
|
|
@@ -49,11 +55,12 @@ var IntegrationAuthenticationProviderBase = class {
|
|
|
49
55
|
} : descriptor, {
|
|
50
56
|
...options,
|
|
51
57
|
skipConnect: true
|
|
52
|
-
}, signOutMark));
|
|
58
|
+
}, signOutMark, this.configuredIntegrationService.getStoredWriteMark(), authority));
|
|
53
59
|
if (session != null || !options?.createIfNeeded || options.forceNewSession) return session;
|
|
54
60
|
if (this.configuredIntegrationService.isSessionRetiredSince(this.authProviderId, {
|
|
55
61
|
id: connectionId ?? "",
|
|
56
|
-
domain: descriptor.domain
|
|
62
|
+
domain: descriptor.domain,
|
|
63
|
+
cloud: descriptor.cloud
|
|
57
64
|
}, signOutMark)) return;
|
|
58
65
|
return this.connectNewSession(descriptor, options);
|
|
59
66
|
}
|
|
@@ -64,7 +71,7 @@ var IntegrationAuthenticationProviderBase = class {
|
|
|
64
71
|
cloud: true
|
|
65
72
|
} : descriptor) ? connectionId : void 0;
|
|
66
73
|
}
|
|
67
|
-
async acquireSession(descriptor, options, initialSignOutMark) {
|
|
74
|
+
async acquireSession(descriptor, options, initialSignOutMark, acquisitionMark, authority) {
|
|
68
75
|
let signOutMark = initialSignOutMark;
|
|
69
76
|
let session;
|
|
70
77
|
let previousToken;
|
|
@@ -86,6 +93,7 @@ var IntegrationAuthenticationProviderBase = class {
|
|
|
86
93
|
preserveConfigured: isSelfManagedHostIntegrationId(this.authProviderId)
|
|
87
94
|
});
|
|
88
95
|
signOutMark = this.configuredIntegrationService.getSignOutMark();
|
|
96
|
+
acquisitionMark = signOutMark;
|
|
89
97
|
} else {
|
|
90
98
|
const stored = await this.configuredIntegrationService.getStoredSession(this.authProviderId, options?.sync ? {
|
|
91
99
|
...descriptor,
|
|
@@ -105,25 +113,38 @@ var IntegrationAuthenticationProviderBase = class {
|
|
|
105
113
|
refreshRejectedToken,
|
|
106
114
|
isRejectedToken: scopedRecovery ? options?.isRejectedToken : void 0
|
|
107
115
|
});
|
|
108
|
-
if (session == null && options?.refetch && refetched != null && this.configuredIntegrationService.isSessionRetiredSince(this.authProviderId, refetched, signOutMark)) throw new CancellationError();
|
|
116
|
+
if (session == null && options?.refetch && refetched != null && this.configuredIntegrationService.isSessionRetiredSince(this.authProviderId, refetched, signOutMark, acquisitionMark)) throw new CancellationError();
|
|
109
117
|
if (session != null) {
|
|
110
|
-
|
|
118
|
+
const primaryResponse = this.primaryResponses.get(session);
|
|
119
|
+
const stored = await this.configuredIntegrationService.storeSession(this.authProviderId, session, {
|
|
111
120
|
signOutMark,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
121
|
+
acquisitionMark,
|
|
122
|
+
expectedStoredAccessToken: scopedRecovery ? previousToken : void 0,
|
|
123
|
+
primaryResponse,
|
|
124
|
+
sync: authority
|
|
125
|
+
});
|
|
126
|
+
if (authority?.isCurrent() === false) throw new CancellationError();
|
|
127
|
+
const primary = primaryResponse === "named" ? this.configuredIntegrationService.supersedingPrimary(this.authProviderId, session, signOutMark) : void 0;
|
|
128
|
+
if (primary != null) {
|
|
129
|
+
const current = await this.configuredIntegrationService.peekStoredSession(this.authProviderId, primary, true, descriptor.domain);
|
|
130
|
+
if (current == null || this.configuredIntegrationService.supersedingPrimary(this.authProviderId, session, signOutMark) !== primary) throw new CancellationError();
|
|
131
|
+
session = current;
|
|
132
|
+
} else if (!stored) {
|
|
133
|
+
session = await this.configuredIntegrationService.peekStoredSession(this.authProviderId, session.id, session.cloud, descriptor.domain);
|
|
119
134
|
options?.isRejectedToken?.(session?.accessToken);
|
|
120
135
|
} else if (refetched?.id != null && refetched.id !== session.id) await this.configuredIntegrationService.deleteStoredSessions(this.authProviderId, {
|
|
121
136
|
...descriptor,
|
|
122
137
|
connectionId: refetched.id,
|
|
123
138
|
cloud: true
|
|
124
|
-
}, true, {
|
|
139
|
+
}, true, {
|
|
140
|
+
preserveConfigured: true,
|
|
141
|
+
signOutMark,
|
|
142
|
+
unobservedSince: signOutMark,
|
|
143
|
+
sync: authority
|
|
144
|
+
});
|
|
125
145
|
}
|
|
126
146
|
}
|
|
147
|
+
if (session?.cloud && this.configuredIntegrationService.lastCloudLogout > signOutMark) throw new CancellationError();
|
|
127
148
|
if (previousToken !== session?.accessToken) this.fireChange();
|
|
128
149
|
return session;
|
|
129
150
|
}
|
|
@@ -181,6 +202,7 @@ var CloudIntegrationAuthenticationProvider = class extends IntegrationAuthentica
|
|
|
181
202
|
const connectionId = descriptor.connectionId ?? (isSelfManagedHostIntegrationId(this.authProviderId) ? this.configuredIntegrationService.getConfiguredConnectionId(this.authProviderId, descriptor.domain, true) : void 0);
|
|
182
203
|
const scopedToThisHost = this.configuredIntegrationService.isConnectionConfiguredForHost(this.authProviderId, connectionId, descriptor.domain);
|
|
183
204
|
const isForAnotherHost = (session) => session != null && isSelfManagedHostIntegrationId(this.authProviderId) && (!scopedToThisHost || Boolean(session.domain?.trim())) && !areDomainsOnSameHost(session.domain, descriptor.domain);
|
|
205
|
+
const fallbackId = connectionId ?? this.configuredIntegrationService.resolveConnectionId(this.authProviderId, descriptor);
|
|
184
206
|
let session = await cloudIntegrations.getConnectionSession(this.authProviderId, void 0, connectionId);
|
|
185
207
|
if (isForAnotherHost(session)) return void 0;
|
|
186
208
|
if (options?.isRejectedToken != null && session?.id != null && session.id !== connectionId) return void 0;
|
|
@@ -197,8 +219,8 @@ var CloudIntegrationAuthenticationProvider = class extends IntegrationAuthentica
|
|
|
197
219
|
} catch {
|
|
198
220
|
sessionProtocol = void 0;
|
|
199
221
|
}
|
|
200
|
-
|
|
201
|
-
id: session.id ??
|
|
222
|
+
const resolved = {
|
|
223
|
+
id: session.id ?? fallbackId,
|
|
202
224
|
accessToken: session.accessToken,
|
|
203
225
|
scopes: descriptor.scopes,
|
|
204
226
|
account: {
|
|
@@ -213,6 +235,8 @@ var CloudIntegrationAuthenticationProvider = class extends IntegrationAuthentica
|
|
|
213
235
|
protocol: sessionProtocol ?? void 0,
|
|
214
236
|
appKey: session.appKey
|
|
215
237
|
};
|
|
238
|
+
if (connectionId == null) this.primaryResponses.set(resolved, session.id == null ? "legacy" : "named");
|
|
239
|
+
return resolved;
|
|
216
240
|
}
|
|
217
241
|
async disconnectCloudSession(descriptor) {
|
|
218
242
|
if (!(await this.authenticationService.ctx.account.getAccount() != null)) return "skip";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudIntegrationAuthenticationProvider.js","names":[],"sources":["../../../../../plus/integrations/src/authentication/cloudIntegrationAuthenticationProvider.ts"],"sourcesContent":["import { CancellationError } from '@gitlens/utils/cancellation.js';\nimport { trace } from '@gitlens/utils/decorators/log.js';\nimport type { Disposable } from '@gitlens/utils/disposable.js';\nimport type { Event } from '@gitlens/utils/event.js';\nimport { Emitter } from '@gitlens/utils/event.js';\nimport type { IntegrationIds } from '../constants.js';\nimport type { Sources } from '../telemetry.js';\nimport { areDomainsOnSameHost } from '../utils/domain.utils.js';\nimport { isNonExpiringZeroTokenIntegrationId, isSelfManagedHostIntegrationId } from '../utils/integration.utils.js';\nimport type { ConfiguredIntegrationService } from './configuredIntegrationService.js';\nimport type {\n\tGetSessionOptions,\n\tIntegrationAuthenticationProvider,\n\tIntegrationAuthenticationSessionDescriptor,\n\tRejectedTokenRefreshOptions,\n} from './integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from './integrationAuthenticationService.js';\nimport type { ProviderAuthenticationSession } from './models.js';\nimport { isSupportedCloudIntegrationId } from './models.js';\n\n// The package's implementation of the public `IntegrationAuthenticationProvider` contract, kept out of that module so\n// the contract's declarations never reach the internal services these classes are built on.\n\nconst maxSmallIntegerV8 = 2 ** 30 - 1; // Max number that can be stored in V8's smis (small integers)\n\n/**\n * What {@link IntegrationAuthenticationProviderBase.getSession} passes down once it has decided the stored\n * session can't be served as-is. `refreshIfExpired` is its own conclusion, not a caller's option.\n */\ntype GetNewSessionOptions = GetSessionOptions & { refreshIfExpired?: boolean; skipConnect?: boolean };\n\nabstract class IntegrationAuthenticationProviderBase<\n\tID extends IntegrationIds = IntegrationIds,\n> implements IntegrationAuthenticationProvider {\n\tprotected readonly disposables: Disposable[] = [];\n\n\tconstructor(\n\t\tprotected readonly authenticationService: IntegrationAuthenticationService,\n\t\tprotected readonly configuredIntegrationService: ConfiguredIntegrationService,\n\t) {}\n\n\tdispose(): void {\n\t\tthis.disposables.forEach(d => d.dispose());\n\t}\n\n\tprivate readonly _onDidChange = new Emitter<void>();\n\tget onDidChange(): Event<void> {\n\t\treturn this._onDidChange.event;\n\t}\n\n\tprotected abstract get authProviderId(): ID;\n\n\t@trace()\n\tasync deleteSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: { preserveConfigured?: boolean; signOutMark?: number },\n\t): Promise<void> {\n\t\tconst domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : undefined;\n\t\tconst configured = this.configuredIntegrationService.getConfigured(this.authProviderId, {\n\t\t\tdomain: domain,\n\t\t});\n\n\t\t// Scope the descriptor to cloud so resolveConnectionId targets the cloud variant's id: this is a\n\t\t// cloud-only delete, and a mixed local+cloud connection whose local descriptor is primary would\n\t\t// otherwise resolve the local id and leave the cloud secret intact.\n\t\tconst deleted = await this.configuredIntegrationService.deleteStoredSessions(\n\t\t\tthis.authProviderId,\n\t\t\t{ ...descriptor, cloud: true },\n\t\t\ttrue,\n\t\t\t{ preserveConfigured: options?.preserveConfigured ?? true, signOutMark: options?.signOutMark },\n\t\t);\n\n\t\tif (deleted && configured?.length) {\n\t\t\tthis.fireChange();\n\t\t}\n\t}\n\n\t@trace()\n\tasync deleteAllSessions(descriptor?: IntegrationAuthenticationSessionDescriptor): Promise<void> {\n\t\t// Self-managed providers group every host under one provider id, so scope the clear to this\n\t\t// descriptor's host when given; for cloud providers the domain stays undefined here, clearing every account.\n\t\tconst domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : undefined;\n\t\tconst configured = this.configuredIntegrationService.getConfigured(this.authProviderId, {\n\t\t\tdomain: domain,\n\t\t});\n\n\t\tawait this.configuredIntegrationService.deleteAllStoredSessions(this.authProviderId, undefined, domain);\n\n\t\tif (configured?.length) {\n\t\t\tthis.fireChange();\n\t\t}\n\t}\n\n\t@trace()\n\tasync getSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetSessionOptions,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\t// KEEP: taken before queueing, so a sign-out while this waits refuses its store.\n\t\tconst signOutMark = this.configuredIntegrationService.getSignOutMark();\n\t\tif (!this.configuredIntegrationService.serializesCredentialAcquisition(this.authProviderId)) {\n\t\t\treturn this.acquireSession(descriptor, options, signOutMark);\n\t\t}\n\n\t\tconst connectionId = descriptor.connectionId || this.getImplicitCloudConnectionId(descriptor, options);\n\t\t// KEEP: connecting reaches this provider's own getSession again, so it runs after the queued acquisition.\n\t\tconst session = await this.configuredIntegrationService.withCredentialAcquisition(\n\t\t\tthis.authProviderId,\n\t\t\tconnectionId,\n\t\t\t() =>\n\t\t\t\tthis.acquireSession(\n\t\t\t\t\tconnectionId != null ? { ...descriptor, connectionId: connectionId } : descriptor,\n\t\t\t\t\t{ ...options, skipConnect: true },\n\t\t\t\t\tsignOutMark,\n\t\t\t\t),\n\t\t);\n\t\tif (session != null || !options?.createIfNeeded || options.forceNewSession) return session;\n\t\t// KEEP: a sign-out or replacement since the mark refused the fetched credential; it is not a missing one.\n\t\tif (\n\t\t\tthis.configuredIntegrationService.isSessionRetiredSince(\n\t\t\t\tthis.authProviderId,\n\t\t\t\t{ id: connectionId ?? '', domain: descriptor.domain },\n\t\t\t\tsignOutMark,\n\t\t\t)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.connectNewSession(descriptor, options);\n\t}\n\n\tprivate getImplicitCloudConnectionId(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions: GetSessionOptions | undefined,\n\t): string | undefined {\n\t\tconst connectionId = this.configuredIntegrationService.getConfiguredConnectionId(\n\t\t\tthis.authProviderId,\n\t\t\tdescriptor.domain,\n\t\t\ttrue,\n\t\t);\n\t\tconst stored = this.configuredIntegrationService.resolveConnectionId(\n\t\t\tthis.authProviderId,\n\t\t\toptions?.sync ? { ...descriptor, cloud: true } : descriptor,\n\t\t);\n\t\treturn connectionId === stored ? connectionId : undefined;\n\t}\n\n\tprivate async acquireSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions: (GetSessionOptions & { skipConnect?: boolean }) | undefined,\n\t\tinitialSignOutMark: number,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tlet signOutMark = initialSignOutMark;\n\t\tlet session;\n\t\tlet previousToken;\n\t\tlet refetched: ProviderAuthenticationSession | undefined;\n\t\tif (options?.forceNewSession) {\n\t\t\tif (isSelfManagedHostIntegrationId(this.authProviderId)) {\n\t\t\t\tconst connectionId =\n\t\t\t\t\tdescriptor.connectionId ||\n\t\t\t\t\tthis.configuredIntegrationService.getConfiguredConnectionId(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\t!this.configuredIntegrationService.isConnectionConfiguredForHost(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tconnectionId,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tdescriptor = { ...descriptor, connectionId: connectionId };\n\t\t\t}\n\t\t\t// Cloud-only delete (see deleteSession): scope to cloud so the cloud variant's id is cleared even\n\t\t\t// when a mixed local+cloud connection's local descriptor is primary. A sign-out, so a token fetched before\n\t\t\t// it is not stored back; the mark is taken after it, so this session's own fetch is not refused.\n\t\t\tawait this.configuredIntegrationService.deleteStoredSessions(\n\t\t\t\tthis.authProviderId,\n\t\t\t\t{ ...descriptor, cloud: true },\n\t\t\t\ttrue,\n\t\t\t\t{ signOut: true, preserveConfigured: isSelfManagedHostIntegrationId(this.authProviderId) },\n\t\t\t);\n\t\t\tsignOutMark = this.configuredIntegrationService.getSignOutMark();\n\t\t} else {\n\t\t\tconst stored = await this.configuredIntegrationService.getStoredSession(\n\t\t\t\tthis.authProviderId,\n\t\t\t\toptions?.sync ? { ...descriptor, cloud: true } : descriptor,\n\t\t\t);\n\t\t\tpreviousToken = stored?.accessToken;\n\t\t\tif (options?.sync && options.refetch) {\n\t\t\t\trefetched = stored;\n\t\t\t} else {\n\t\t\t\tsession = stored;\n\t\t\t}\n\t\t}\n\n\t\tconst isExpiredSession = session?.expiresAt != null && new Date(session.expiresAt).getTime() < Date.now();\n\t\t// A rejected token has to re-resolve even when the stored session looks perfectly healthy: that is\n\t\t// the whole point — the provider refused it while its expiry still says valid. Without this the\n\t\t// stored session short-circuits here and the refresh below is never reached.\n\t\tconst scopedRecovery = options?.isRejectedToken?.(session?.accessToken) === true;\n\t\tconst refreshRejectedToken = scopedRecovery || (options?.refreshRejectedToken === true && session != null);\n\t\tif (session == null || isExpiredSession || refreshRejectedToken) {\n\t\t\tsession = await this.getNewSession(descriptor, {\n\t\t\t\t...options,\n\t\t\t\trefreshIfExpired: isExpiredSession,\n\t\t\t\trefreshRejectedToken: refreshRejectedToken,\n\t\t\t\tisRejectedToken: scopedRecovery ? options?.isRejectedToken : undefined,\n\t\t\t});\n\t\t\tif (\n\t\t\t\tsession == null &&\n\t\t\t\toptions?.refetch &&\n\t\t\t\trefetched != null &&\n\t\t\t\tthis.configuredIntegrationService.isSessionRetiredSince(this.authProviderId, refetched, signOutMark)\n\t\t\t) {\n\t\t\t\tthrow new CancellationError();\n\t\t\t}\n\n\t\t\tif (session != null) {\n\t\t\t\tconst stored = await this.configuredIntegrationService.storeSession(this.authProviderId, session, {\n\t\t\t\t\tsignOutMark: signOutMark,\n\t\t\t\t\texpectedStoredAccessToken: scopedRecovery ? previousToken : undefined,\n\t\t\t\t});\n\t\t\t\tif (!stored) {\n\t\t\t\t\t// A disconnect leaves no credential here. A recovery can leave a replacement for this same\n\t\t\t\t\t// connection, which a forced sync must not interpret as a disconnect and delete.\n\t\t\t\t\tsession = await this.configuredIntegrationService.getStoredSession(this.authProviderId, {\n\t\t\t\t\t\t...descriptor,\n\t\t\t\t\t\tconnectionId: session.id,\n\t\t\t\t\t\tcloud: session.cloud,\n\t\t\t\t\t});\n\t\t\t\t\toptions?.isRejectedToken?.(session?.accessToken);\n\t\t\t\t} else if (refetched?.id != null && refetched.id !== session.id) {\n\t\t\t\t\t// The replacement belongs to a different connection (the cloud's primary moved to another\n\t\t\t\t\t// account), so it was stored beside the one it replaces rather than over it. Drop the old token\n\t\t\t\t\t// as the up-front delete used to, or an unscoped read would keep resolving it until the next sync.\n\t\t\t\t\tawait this.configuredIntegrationService.deleteStoredSessions(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\t{ ...descriptor, connectionId: refetched.id, cloud: true },\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t{ preserveConfigured: true },\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (previousToken !== session?.accessToken) {\n\t\t\tthis.fireChange();\n\t\t}\n\n\t\treturn session;\n\t}\n\n\tprotected connectNewSession(\n\t\t_descriptor: IntegrationAuthenticationSessionDescriptor,\n\t\t_options: GetSessionOptions | undefined,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected abstract getNewSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetNewSessionOptions,\n\t): Promise<ProviderAuthenticationSession | undefined>;\n\n\tprotected fireChange(): void {\n\t\tqueueMicrotask(() => this._onDidChange.fire());\n\t}\n}\n\nexport class CloudIntegrationAuthenticationProvider<\n\tID extends IntegrationIds = IntegrationIds,\n> extends IntegrationAuthenticationProviderBase<ID> {\n\tconstructor(\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tconfiguredIntegrationService: ConfiguredIntegrationService,\n\t\tprivate readonly _authProviderId: ID,\n\t) {\n\t\tsuper(authenticationService, configuredIntegrationService);\n\t}\n\n\tprotected get authProviderId(): ID {\n\t\treturn this._authProviderId;\n\t}\n\n\tprotected override async getNewSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetNewSessionOptions,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tif (options?.forceNewSession) {\n\t\t\tif ((await this.disconnectCloudSession(descriptor)) === 'failure') {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tvoid this.connectCloudSession(false, options?.source);\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// TODO: This is a stopgap to make sure we're not hammering the api on automatic calls to get the session.\n\t\t// Ultimately we want to timestamp calls to syncCloudIntegrations and use that to determine whether we should\n\t\t// make the call or not.\n\t\t// `refreshRejectedToken` joins the list for the same reason `refreshIfExpired` is on it: both mean the\n\t\t// session in hand is known-unusable, so skipping the cloud round trip would just re-serve it.\n\t\tconst session =\n\t\t\toptions?.refreshIfExpired ||\n\t\t\toptions?.refreshRejectedToken ||\n\t\t\toptions?.createIfNeeded ||\n\t\t\toptions?.forceNewSession ||\n\t\t\toptions?.sync\n\t\t\t\t? await this.getCloudSession(descriptor, options)\n\t\t\t\t: undefined;\n\n\t\tif (options?.createIfNeeded && session == null && !options.skipConnect) {\n\t\t\treturn this.connectNewSession(descriptor, options);\n\t\t}\n\n\t\treturn session;\n\t}\n\n\tprotected override async connectNewSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions: GetSessionOptions | undefined,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tconst connected = await this.connectCloudSession(true, options?.source);\n\t\tif (!connected) return undefined;\n\n\t\treturn this.getSession(descriptor, { source: options?.source });\n\t}\n\n\tprivate connectCloudSession(skipIfConnected: boolean, source: Sources | undefined): Promise<boolean> {\n\t\t// Capture in a const so the type guard narrows it to `SupportedCloudIntegrationIds` (a getter\n\t\t// access wouldn't narrow), letting us call the service directly without a cast.\n\t\tconst id = this.authProviderId;\n\t\tif (isSupportedCloudIntegrationId(id)) {\n\t\t\treturn this.authenticationService.connectCloudIntegrations(\n\t\t\t\t{ integrationIds: [id], skipIfConnected: skipIfConnected, skipPreSync: true },\n\t\t\t\t{\n\t\t\t\t\tsource: source ?? 'integrations',\n\t\t\t\t\tdetail: {\n\t\t\t\t\t\taction: 'connect',\n\t\t\t\t\t\tintegration: id,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\treturn Promise.resolve(false);\n\t}\n\n\tprivate async getCloudSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: RejectedTokenRefreshOptions,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tconst loggedIn = (await this.authenticationService.ctx.account.getAccount()) != null;\n\t\tif (!loggedIn) return undefined;\n\n\t\tconst cloudIntegrations = this.authenticationService.cloudIntegrations;\n\t\t// An unscoped descriptor (no explicit connectionId) would fetch the provider-global primary via\n\t\t// `v1/provider-tokens/<provider>`. For a self-managed provider spanning multiple hosts that primary\n\t\t// can belong to a different host, so a forced sync of host A would hydrate host B's token here (before\n\t\t// reconcile corrects storage). Scope to this host's own configured connection when we have one; fall\n\t\t// through to the provider-scoped path only when nothing is configured yet (legacy/first sync).\n\t\tconst connectionId =\n\t\t\tdescriptor.connectionId ??\n\t\t\t(isSelfManagedHostIntegrationId(this.authProviderId)\n\t\t\t\t? this.configuredIntegrationService.getConfiguredConnectionId(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t)\n\t\t\t\t: undefined);\n\t\t// Refuses a session issued for a DIFFERENT host than the one this connection is keyed by, which would\n\t\t// otherwise let host B's token serve host A.\n\t\t//\n\t\t// A session that names no host is accepted ONLY when it was fetched by a connection id WE have stored\n\t\t// for this host. That descriptor is what ties the token to the host, so an absent domain then means the\n\t\t// backend did not say rather than that the token belongs elsewhere, and refusing it would strand the\n\t\t// refresh.\n\t\t//\n\t\t// A non-null id is not enough on its own: `descriptor.connectionId` can come from the caller, and with\n\t\t// no id at all the fetch goes to the provider-GLOBAL primary endpoint whose token can belong to any\n\t\t// configured host. In both of those cases a domainless response must be refused, or a token would be\n\t\t// bound to — and sent to — a host it was never issued for.\n\t\tconst scopedToThisHost = this.configuredIntegrationService.isConnectionConfiguredForHost(\n\t\t\tthis.authProviderId,\n\t\t\tconnectionId,\n\t\t\tdescriptor.domain,\n\t\t);\n\t\tconst isForAnotherHost = (session: { domain: string } | undefined) =>\n\t\t\tsession != null &&\n\t\t\tisSelfManagedHostIntegrationId(this.authProviderId) &&\n\t\t\t(!scopedToThisHost || Boolean(session.domain?.trim())) &&\n\t\t\t!areDomainsOnSameHost(session.domain, descriptor.domain);\n\n\t\tlet session = await cloudIntegrations.getConnectionSession(this.authProviderId, undefined, connectionId);\n\t\tif (isForAnotherHost(session)) return undefined;\n\t\tif (options?.isRejectedToken != null && session?.id != null && session.id !== connectionId) return undefined;\n\n\t\t// GitHub, the cloud self-managed hosts, and Trello return `expiresIn: 0` for a token that never\n\t\t// expires; left as 0 the session would be built with `expiresAt = now` and rejected as expired on the\n\t\t// next resolution. Map it to the maximum expiry so it isn't refreshed frequently.\n\t\tif (session?.expiresIn === 0 && isNonExpiringZeroTokenIntegrationId(this.authProviderId)) {\n\t\t\tsession.expiresIn = maxSmallIntegerV8; // maximum expiration length\n\t\t}\n\n\t\t// `expiresIn < 60` is a PREDICTION that the token is about to lapse, and it is the only trigger the\n\t\t// refresh used to have. It cannot see a token the provider has already refused while the backend\n\t\t// still believes it is valid — a revoked grant, retired scopes, an app removed from the org — where\n\t\t// `expiresIn` stays high and the doomed token is re-sent on every read. `refreshRejectedToken` is\n\t\t// the observed counterpart: the caller saw the provider reject this exact token, so refresh it\n\t\t// regardless of what its expiry claims.\n\t\tif (\n\t\t\tsession != null &&\n\t\t\t(session.expiresIn < 60 ||\n\t\t\t\t(options?.refreshRejectedToken && (options.isRejectedToken?.(session.accessToken) ?? true)))\n\t\t) {\n\t\t\tsession = await cloudIntegrations.getConnectionSession(\n\t\t\t\tthis.authProviderId,\n\t\t\t\tsession.accessToken,\n\t\t\t\tconnectionId,\n\t\t\t);\n\t\t\tif (isForAnotherHost(session)) return undefined;\n\t\t\tif (options?.isRejectedToken != null && session?.id != null && session.id !== connectionId) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\n\t\tif (!session) return undefined;\n\n\t\tlet sessionProtocol;\n\t\t// Only derive a protocol from a domain carrying an explicit scheme; a bare `host:port` (e.g. a\n\t\t// self-managed `ghe.example.com:8443`) parses the host as the protocol, corrupting the value.\n\t\tif (/^[a-z][a-z\\d+\\-.]*:\\/\\//i.test(session.domain)) {\n\t\t\ttry {\n\t\t\t\tsessionProtocol = new URL(session.domain).protocol;\n\t\t\t} catch {\n\t\t\t\tsessionProtocol = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t// Prefer the backend's per-connection token id (multi-account); fall back to the resolved\n\t\t\t// primary/legacy connection id so existing single-connection storage keys are preserved.\n\t\t\tid: session.id ?? this.configuredIntegrationService.resolveConnectionId(this.authProviderId, descriptor),\n\t\t\taccessToken: session.accessToken,\n\t\t\tscopes: descriptor.scopes,\n\t\t\taccount: {\n\t\t\t\tid: '',\n\t\t\t\tlabel: '',\n\t\t\t},\n\t\t\tcloud: true,\n\t\t\ttype: session.type,\n\t\t\texpiresAt: new Date(session.expiresIn * 1000 + Date.now()),\n\t\t\t// Note: do not use the session's domain, because the format is different than in our model\n\t\t\tdomain: descriptor.domain,\n\t\t\t// That format difference is exactly what `baseUrl` is for: the descriptor's domain is the\n\t\t\t// normalized host this connection is keyed by, so a context path only survives on the wire value.\n\t\t\t// When the backend reports no domain at all, KEEP the address already configured rather than\n\t\t\t// writing `undefined` — `writeSecret` mirrors this onto the descriptor, so falling back to the\n\t\t\t// bare host here would drop a context path the user never changed on the next refresh.\n\t\t\tbaseUrl:\n\t\t\t\tsession.domain ||\n\t\t\t\tthis.configuredIntegrationService.getConfiguredBaseUrl(\n\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\tconnectionId,\n\t\t\t\t\tdescriptor.domain,\n\t\t\t\t),\n\t\t\tprotocol: sessionProtocol ?? undefined,\n\t\t\t// Carried for providers whose client needs an app key alongside the token (e.g. Trello).\n\t\t\tappKey: session.appKey,\n\t\t};\n\t}\n\n\tprivate async disconnectCloudSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t): Promise<'skip' | 'success' | 'failure'> {\n\t\tconst loggedIn = (await this.authenticationService.ctx.account.getAccount()) != null;\n\t\tif (!loggedIn) return 'skip';\n\n\t\tconst cloudIntegrations = this.authenticationService.cloudIntegrations;\n\t\tif (!(await cloudIntegrations.disconnect(this.authProviderId, descriptor.connectionId))) return 'failure';\n\n\t\tif (isSelfManagedHostIntegrationId(this.authProviderId)) {\n\t\t\tawait this.deleteSession(descriptor, { preserveConfigured: false });\n\t\t}\n\n\t\treturn 'success';\n\t}\n}\n"],"mappings":";;;;;;;;AAuBA,MAAM,oBAAoB,KAAK,KAAK;AAQpC,IAAe,wCAAf,MAE+C;CAI1B;CACA;CAJpB,cAA+C,CAAC;CAEhD,YACC,uBACA,8BACC;EAFkB,KAAA,wBAAA;EACA,KAAA,+BAAA;CACjB;CAEH,UAAgB;EACf,KAAK,YAAY,SAAQ,MAAK,EAAE,QAAQ,CAAC;CAC1C;CAEA,eAAgC,IAAI,QAAc;CAClD,IAAI,cAA2B;EAC9B,OAAO,KAAK,aAAa;CAC1B;CAIA,MACM,cACL,YACA,SACgB;EAChB,MAAM,SAAS,+BAA+B,KAAK,cAAc,IAAI,YAAY,SAAS,KAAA;EAC1F,MAAM,aAAa,KAAK,6BAA6B,cAAc,KAAK,gBAAgB,EAC/E,OACT,CAAC;EAYD,IAAI,MAPkB,KAAK,6BAA6B,qBACvD,KAAK,gBACL;GAAE,GAAG;GAAY,OAAO;EAAK,GAC7B,MACA;GAAE,oBAAoB,SAAS,sBAAsB;GAAM,aAAa,SAAS;EAAY,CAC9F,KAEe,YAAY,QAC1B,KAAK,WAAW;CAElB;CAEA,MACM,kBAAkB,YAAwE;EAG/F,MAAM,SAAS,+BAA+B,KAAK,cAAc,IAAI,YAAY,SAAS,KAAA;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":[],"sources":["../../../../../plus/integrations/src/authentication/cloudIntegrationAuthenticationProvider.ts"],"sourcesContent":["import { CancellationError } from '@gitlens/utils/cancellation.js';\nimport { trace } from '@gitlens/utils/decorators/log.js';\nimport type { Disposable } from '@gitlens/utils/disposable.js';\nimport type { Event } from '@gitlens/utils/event.js';\nimport { Emitter } from '@gitlens/utils/event.js';\nimport type { IntegrationIds } from '../constants.js';\nimport type { Sources } from '../telemetry.js';\nimport { areDomainsOnSameHost } from '../utils/domain.utils.js';\nimport { isNonExpiringZeroTokenIntegrationId, isSelfManagedHostIntegrationId } from '../utils/integration.utils.js';\nimport type { CloudIntegrationSync } from './cloudIntegrationObservations.js';\nimport type { ConfiguredIntegrationService } from './configuredIntegrationService.js';\nimport type {\n\tGetSessionOptions,\n\tIntegrationAuthenticationProvider,\n\tIntegrationAuthenticationSessionDescriptor,\n\tRejectedTokenRefreshOptions,\n} from './integrationAuthenticationProvider.js';\nimport type { IntegrationAuthenticationService } from './integrationAuthenticationService.js';\nimport type { ProviderAuthenticationSession } from './models.js';\nimport { isSupportedCloudIntegrationId } from './models.js';\n\n// The package's implementation of the public `IntegrationAuthenticationProvider` contract, kept out of that module so\n// the contract's declarations never reach the internal services these classes are built on.\n\nconst maxSmallIntegerV8 = 2 ** 30 - 1; // Max number that can be stored in V8's smis (small integers)\n\n/**\n * What {@link IntegrationAuthenticationProviderBase.getSession} passes down once it has decided the stored\n * session can't be served as-is. `refreshIfExpired` is its own conclusion, not a caller's option.\n */\ntype GetNewSessionOptions = GetSessionOptions & { refreshIfExpired?: boolean; skipConnect?: boolean };\n\nabstract class IntegrationAuthenticationProviderBase<\n\tID extends IntegrationIds = IntegrationIds,\n> implements IntegrationAuthenticationProvider {\n\tprotected readonly disposables: Disposable[] = [];\n\tprotected readonly primaryResponses = new WeakMap<ProviderAuthenticationSession, 'named' | 'legacy'>();\n\n\tconstructor(\n\t\tprotected readonly authenticationService: IntegrationAuthenticationService,\n\t\tprotected readonly configuredIntegrationService: ConfiguredIntegrationService,\n\t) {}\n\n\tdispose(): void {\n\t\tthis.disposables.forEach(d => d.dispose());\n\t}\n\n\tprivate readonly _onDidChange = new Emitter<void>();\n\tget onDidChange(): Event<void> {\n\t\treturn this._onDidChange.event;\n\t}\n\n\tprotected abstract get authProviderId(): ID;\n\n\t@trace()\n\tasync deleteSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: { preserveConfigured?: boolean; signOutMark?: number; sync?: CloudIntegrationSync },\n\t): Promise<void> {\n\t\tconst domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : undefined;\n\t\tconst configured = this.configuredIntegrationService.getConfigured(this.authProviderId, {\n\t\t\tdomain: domain,\n\t\t});\n\n\t\t// Scope the descriptor to cloud so resolveConnectionId targets the cloud variant's id: this is a\n\t\t// cloud-only delete, and a mixed local+cloud connection whose local descriptor is primary would\n\t\t// otherwise resolve the local id and leave the cloud secret intact.\n\t\tconst deleted = await this.configuredIntegrationService.deleteStoredSessions(\n\t\t\tthis.authProviderId,\n\t\t\t{ ...descriptor, cloud: true },\n\t\t\ttrue,\n\t\t\t{\n\t\t\t\tpreserveConfigured: options?.preserveConfigured ?? true,\n\t\t\t\tsignOutMark: options?.signOutMark,\n\t\t\t\tsync: options?.sync,\n\t\t\t},\n\t\t);\n\n\t\tif (deleted && configured?.length) {\n\t\t\tthis.fireChange();\n\t\t}\n\t}\n\n\t@trace()\n\tasync deleteAllSessions(descriptor?: IntegrationAuthenticationSessionDescriptor): Promise<void> {\n\t\tawait this.clearSessions(descriptor);\n\t}\n\n\tasync clearSessions(\n\t\tdescriptor?: IntegrationAuthenticationSessionDescriptor,\n\t\tsync?: CloudIntegrationSync,\n\t): Promise<boolean> {\n\t\tconst domain = isSelfManagedHostIntegrationId(this.authProviderId) ? descriptor?.domain : undefined;\n\t\tconst configured = this.configuredIntegrationService.getConfigured(this.authProviderId, { domain: domain });\n\t\tconst cleared = await this.configuredIntegrationService.deleteAllStoredSessions(\n\t\t\tthis.authProviderId,\n\t\t\tundefined,\n\t\t\tdomain,\n\t\t\tsync,\n\t\t);\n\t\tif (cleared && configured.length) {\n\t\t\tthis.fireChange();\n\t\t}\n\t\treturn cleared;\n\t}\n\n\t@trace()\n\tasync getSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetSessionOptions,\n\t\tauthority?: CloudIntegrationSync,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\t// KEEP: taken before queueing, so a sign-out while this waits refuses its store.\n\t\tconst signOutMark = this.configuredIntegrationService.getSignOutMark();\n\t\tif (!this.configuredIntegrationService.serializesCredentialAcquisition(this.authProviderId)) {\n\t\t\treturn this.acquireSession(descriptor, options, signOutMark, signOutMark, authority);\n\t\t}\n\n\t\tconst connectionId = descriptor.connectionId || this.getImplicitCloudConnectionId(descriptor, options);\n\t\t// KEEP: connecting reaches this provider's own getSession again, so it runs after the queued acquisition.\n\t\tconst session = await this.configuredIntegrationService.withCredentialAcquisition(\n\t\t\tthis.authProviderId,\n\t\t\tconnectionId,\n\t\t\t() =>\n\t\t\t\tthis.acquireSession(\n\t\t\t\t\tconnectionId != null ? { ...descriptor, connectionId: connectionId } : descriptor,\n\t\t\t\t\t{ ...options, skipConnect: true },\n\t\t\t\t\tsignOutMark,\n\t\t\t\t\tthis.configuredIntegrationService.getStoredWriteMark(),\n\t\t\t\t\tauthority,\n\t\t\t\t),\n\t\t);\n\t\tif (session != null || !options?.createIfNeeded || options.forceNewSession) return session;\n\t\t// KEEP: a sign-out or replacement since the mark refused the fetched credential; it is not a missing one.\n\t\tif (\n\t\t\tthis.configuredIntegrationService.isSessionRetiredSince(\n\t\t\t\tthis.authProviderId,\n\t\t\t\t{ id: connectionId ?? '', domain: descriptor.domain, cloud: descriptor.cloud },\n\t\t\t\tsignOutMark,\n\t\t\t)\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn this.connectNewSession(descriptor, options);\n\t}\n\n\tprivate getImplicitCloudConnectionId(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions: GetSessionOptions | undefined,\n\t): string | undefined {\n\t\tconst connectionId = this.configuredIntegrationService.getConfiguredConnectionId(\n\t\t\tthis.authProviderId,\n\t\t\tdescriptor.domain,\n\t\t\ttrue,\n\t\t);\n\t\tconst stored = this.configuredIntegrationService.resolveConnectionId(\n\t\t\tthis.authProviderId,\n\t\t\toptions?.sync ? { ...descriptor, cloud: true } : descriptor,\n\t\t);\n\t\treturn connectionId === stored ? connectionId : undefined;\n\t}\n\n\tprivate async acquireSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions: (GetSessionOptions & { skipConnect?: boolean }) | undefined,\n\t\tinitialSignOutMark: number,\n\t\tacquisitionMark: number,\n\t\tauthority?: CloudIntegrationSync,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tlet signOutMark = initialSignOutMark;\n\t\tlet session;\n\t\tlet previousToken;\n\t\tlet refetched: ProviderAuthenticationSession | undefined;\n\t\tif (options?.forceNewSession) {\n\t\t\tif (isSelfManagedHostIntegrationId(this.authProviderId)) {\n\t\t\t\tconst connectionId =\n\t\t\t\t\tdescriptor.connectionId ||\n\t\t\t\t\tthis.configuredIntegrationService.getConfiguredConnectionId(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\t!this.configuredIntegrationService.isConnectionConfiguredForHost(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tconnectionId,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\n\t\t\t\tdescriptor = { ...descriptor, connectionId: connectionId };\n\t\t\t}\n\t\t\t// Cloud-only delete (see deleteSession): scope to cloud so the cloud variant's id is cleared even\n\t\t\t// when a mixed local+cloud connection's local descriptor is primary. A sign-out, so a token fetched before\n\t\t\t// it is not stored back; the mark is taken after it, so this session's own fetch is not refused.\n\t\t\tawait this.configuredIntegrationService.deleteStoredSessions(\n\t\t\t\tthis.authProviderId,\n\t\t\t\t{ ...descriptor, cloud: true },\n\t\t\t\ttrue,\n\t\t\t\t{ signOut: true, preserveConfigured: isSelfManagedHostIntegrationId(this.authProviderId) },\n\t\t\t);\n\t\t\tsignOutMark = this.configuredIntegrationService.getSignOutMark();\n\t\t\tacquisitionMark = signOutMark;\n\t\t} else {\n\t\t\tconst stored = await this.configuredIntegrationService.getStoredSession(\n\t\t\t\tthis.authProviderId,\n\t\t\t\toptions?.sync ? { ...descriptor, cloud: true } : descriptor,\n\t\t\t);\n\t\t\tpreviousToken = stored?.accessToken;\n\t\t\tif (options?.sync && options.refetch) {\n\t\t\t\trefetched = stored;\n\t\t\t} else {\n\t\t\t\tsession = stored;\n\t\t\t}\n\t\t}\n\n\t\tconst isExpiredSession = session?.expiresAt != null && new Date(session.expiresAt).getTime() < Date.now();\n\t\t// A rejected token has to re-resolve even when the stored session looks perfectly healthy: that is\n\t\t// the whole point — the provider refused it while its expiry still says valid. Without this the\n\t\t// stored session short-circuits here and the refresh below is never reached.\n\t\tconst scopedRecovery = options?.isRejectedToken?.(session?.accessToken) === true;\n\t\tconst refreshRejectedToken = scopedRecovery || (options?.refreshRejectedToken === true && session != null);\n\t\tif (session == null || isExpiredSession || refreshRejectedToken) {\n\t\t\tsession = await this.getNewSession(descriptor, {\n\t\t\t\t...options,\n\t\t\t\trefreshIfExpired: isExpiredSession,\n\t\t\t\trefreshRejectedToken: refreshRejectedToken,\n\t\t\t\tisRejectedToken: scopedRecovery ? options?.isRejectedToken : undefined,\n\t\t\t});\n\t\t\tif (\n\t\t\t\tsession == null &&\n\t\t\t\toptions?.refetch &&\n\t\t\t\trefetched != null &&\n\t\t\t\tthis.configuredIntegrationService.isSessionRetiredSince(\n\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\trefetched,\n\t\t\t\t\tsignOutMark,\n\t\t\t\t\tacquisitionMark,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthrow new CancellationError();\n\t\t\t}\n\n\t\t\tif (session != null) {\n\t\t\t\tconst primaryResponse = this.primaryResponses.get(session);\n\t\t\t\tconst stored = await this.configuredIntegrationService.storeSession(this.authProviderId, session, {\n\t\t\t\t\tsignOutMark: signOutMark,\n\t\t\t\t\tacquisitionMark: acquisitionMark,\n\t\t\t\t\texpectedStoredAccessToken: scopedRecovery ? previousToken : undefined,\n\t\t\t\t\tprimaryResponse: primaryResponse,\n\t\t\t\t\tsync: authority,\n\t\t\t\t});\n\t\t\t\tif (authority?.isCurrent() === false) throw new CancellationError();\n\n\t\t\t\tconst primary =\n\t\t\t\t\tprimaryResponse === 'named'\n\t\t\t\t\t\t? this.configuredIntegrationService.supersedingPrimary(\n\t\t\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\t\tsignOutMark,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (primary != null) {\n\t\t\t\t\tconst current = await this.configuredIntegrationService.peekStoredSession(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tprimary,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t);\n\t\t\t\t\tif (\n\t\t\t\t\t\tcurrent == null ||\n\t\t\t\t\t\tthis.configuredIntegrationService.supersedingPrimary(\n\t\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\tsignOutMark,\n\t\t\t\t\t\t) !== primary\n\t\t\t\t\t) {\n\t\t\t\t\t\tthrow new CancellationError();\n\t\t\t\t\t}\n\n\t\t\t\t\tsession = current;\n\t\t\t\t} else if (!stored) {\n\t\t\t\t\tsession = await this.configuredIntegrationService.peekStoredSession(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tsession.id,\n\t\t\t\t\t\tsession.cloud,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t);\n\t\t\t\t\toptions?.isRejectedToken?.(session?.accessToken);\n\t\t\t\t} else if (refetched?.id != null && refetched.id !== session.id) {\n\t\t\t\t\t// The replacement belongs to a different connection (the cloud's primary moved to another\n\t\t\t\t\t// account), so it was stored beside the one it replaces rather than over it. Drop the old token\n\t\t\t\t\t// as the up-front delete used to, or an unscoped read would keep resolving it until the next sync.\n\t\t\t\t\tawait this.configuredIntegrationService.deleteStoredSessions(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\t{ ...descriptor, connectionId: refetched.id, cloud: true },\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpreserveConfigured: true,\n\t\t\t\t\t\t\tsignOutMark: signOutMark,\n\t\t\t\t\t\t\tunobservedSince: signOutMark,\n\t\t\t\t\t\t\tsync: authority,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (session?.cloud && this.configuredIntegrationService.lastCloudLogout > signOutMark) {\n\t\t\tthrow new CancellationError();\n\t\t}\n\n\t\tif (previousToken !== session?.accessToken) {\n\t\t\tthis.fireChange();\n\t\t}\n\n\t\treturn session;\n\t}\n\n\tprotected connectNewSession(\n\t\t_descriptor: IntegrationAuthenticationSessionDescriptor,\n\t\t_options: GetSessionOptions | undefined,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\tprotected abstract getNewSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetNewSessionOptions,\n\t): Promise<ProviderAuthenticationSession | undefined>;\n\n\tprotected fireChange(): void {\n\t\tqueueMicrotask(() => this._onDidChange.fire());\n\t}\n}\n\nexport class CloudIntegrationAuthenticationProvider<\n\tID extends IntegrationIds = IntegrationIds,\n> extends IntegrationAuthenticationProviderBase<ID> {\n\tconstructor(\n\t\tauthenticationService: IntegrationAuthenticationService,\n\t\tconfiguredIntegrationService: ConfiguredIntegrationService,\n\t\tprivate readonly _authProviderId: ID,\n\t) {\n\t\tsuper(authenticationService, configuredIntegrationService);\n\t}\n\n\tprotected get authProviderId(): ID {\n\t\treturn this._authProviderId;\n\t}\n\n\tprotected override async getNewSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: GetNewSessionOptions,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tif (options?.forceNewSession) {\n\t\t\tif ((await this.disconnectCloudSession(descriptor)) === 'failure') {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tvoid this.connectCloudSession(false, options?.source);\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// TODO: This is a stopgap to make sure we're not hammering the api on automatic calls to get the session.\n\t\t// Ultimately we want to timestamp calls to syncCloudIntegrations and use that to determine whether we should\n\t\t// make the call or not.\n\t\t// `refreshRejectedToken` joins the list for the same reason `refreshIfExpired` is on it: both mean the\n\t\t// session in hand is known-unusable, so skipping the cloud round trip would just re-serve it.\n\t\tconst session =\n\t\t\toptions?.refreshIfExpired ||\n\t\t\toptions?.refreshRejectedToken ||\n\t\t\toptions?.createIfNeeded ||\n\t\t\toptions?.forceNewSession ||\n\t\t\toptions?.sync\n\t\t\t\t? await this.getCloudSession(descriptor, options)\n\t\t\t\t: undefined;\n\n\t\tif (options?.createIfNeeded && session == null && !options.skipConnect) {\n\t\t\treturn this.connectNewSession(descriptor, options);\n\t\t}\n\n\t\treturn session;\n\t}\n\n\tprotected override async connectNewSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions: GetSessionOptions | undefined,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tconst connected = await this.connectCloudSession(true, options?.source);\n\t\tif (!connected) return undefined;\n\n\t\treturn this.getSession(descriptor, { source: options?.source });\n\t}\n\n\tprivate connectCloudSession(skipIfConnected: boolean, source: Sources | undefined): Promise<boolean> {\n\t\t// Capture in a const so the type guard narrows it to `SupportedCloudIntegrationIds` (a getter\n\t\t// access wouldn't narrow), letting us call the service directly without a cast.\n\t\tconst id = this.authProviderId;\n\t\tif (isSupportedCloudIntegrationId(id)) {\n\t\t\treturn this.authenticationService.connectCloudIntegrations(\n\t\t\t\t{ integrationIds: [id], skipIfConnected: skipIfConnected, skipPreSync: true },\n\t\t\t\t{\n\t\t\t\t\tsource: source ?? 'integrations',\n\t\t\t\t\tdetail: {\n\t\t\t\t\t\taction: 'connect',\n\t\t\t\t\t\tintegration: id,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\treturn Promise.resolve(false);\n\t}\n\n\tprivate async getCloudSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t\toptions?: RejectedTokenRefreshOptions,\n\t): Promise<ProviderAuthenticationSession | undefined> {\n\t\tconst loggedIn = (await this.authenticationService.ctx.account.getAccount()) != null;\n\t\tif (!loggedIn) return undefined;\n\n\t\tconst cloudIntegrations = this.authenticationService.cloudIntegrations;\n\t\t// An unscoped descriptor (no explicit connectionId) would fetch the provider-global primary via\n\t\t// `v1/provider-tokens/<provider>`. For a self-managed provider spanning multiple hosts that primary\n\t\t// can belong to a different host, so a forced sync of host A would hydrate host B's token here (before\n\t\t// reconcile corrects storage). Scope to this host's own configured connection when we have one; fall\n\t\t// through to the provider-scoped path only when nothing is configured yet (legacy/first sync).\n\t\tconst connectionId =\n\t\t\tdescriptor.connectionId ??\n\t\t\t(isSelfManagedHostIntegrationId(this.authProviderId)\n\t\t\t\t? this.configuredIntegrationService.getConfiguredConnectionId(\n\t\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\t\tdescriptor.domain,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t)\n\t\t\t\t: undefined);\n\t\t// Refuses a session issued for a DIFFERENT host than the one this connection is keyed by, which would\n\t\t// otherwise let host B's token serve host A.\n\t\t//\n\t\t// A session that names no host is accepted ONLY when it was fetched by a connection id WE have stored\n\t\t// for this host. That descriptor is what ties the token to the host, so an absent domain then means the\n\t\t// backend did not say rather than that the token belongs elsewhere, and refusing it would strand the\n\t\t// refresh.\n\t\t//\n\t\t// A non-null id is not enough on its own: `descriptor.connectionId` can come from the caller, and with\n\t\t// no id at all the fetch goes to the provider-GLOBAL primary endpoint whose token can belong to any\n\t\t// configured host. In both of those cases a domainless response must be refused, or a token would be\n\t\t// bound to — and sent to — a host it was never issued for.\n\t\tconst scopedToThisHost = this.configuredIntegrationService.isConnectionConfiguredForHost(\n\t\t\tthis.authProviderId,\n\t\t\tconnectionId,\n\t\t\tdescriptor.domain,\n\t\t);\n\t\tconst isForAnotherHost = (session: { domain: string } | undefined) =>\n\t\t\tsession != null &&\n\t\t\tisSelfManagedHostIntegrationId(this.authProviderId) &&\n\t\t\t(!scopedToThisHost || Boolean(session.domain?.trim())) &&\n\t\t\t!areDomainsOnSameHost(session.domain, descriptor.domain);\n\n\t\tconst fallbackId =\n\t\t\tconnectionId ?? this.configuredIntegrationService.resolveConnectionId(this.authProviderId, descriptor);\n\t\tlet session = await cloudIntegrations.getConnectionSession(this.authProviderId, undefined, connectionId);\n\t\tif (isForAnotherHost(session)) return undefined;\n\t\tif (options?.isRejectedToken != null && session?.id != null && session.id !== connectionId) return undefined;\n\n\t\t// GitHub, the cloud self-managed hosts, and Trello return `expiresIn: 0` for a token that never\n\t\t// expires; left as 0 the session would be built with `expiresAt = now` and rejected as expired on the\n\t\t// next resolution. Map it to the maximum expiry so it isn't refreshed frequently.\n\t\tif (session?.expiresIn === 0 && isNonExpiringZeroTokenIntegrationId(this.authProviderId)) {\n\t\t\tsession.expiresIn = maxSmallIntegerV8; // maximum expiration length\n\t\t}\n\n\t\t// `expiresIn < 60` is a PREDICTION that the token is about to lapse, and it is the only trigger the\n\t\t// refresh used to have. It cannot see a token the provider has already refused while the backend\n\t\t// still believes it is valid — a revoked grant, retired scopes, an app removed from the org — where\n\t\t// `expiresIn` stays high and the doomed token is re-sent on every read. `refreshRejectedToken` is\n\t\t// the observed counterpart: the caller saw the provider reject this exact token, so refresh it\n\t\t// regardless of what its expiry claims.\n\t\tif (\n\t\t\tsession != null &&\n\t\t\t(session.expiresIn < 60 ||\n\t\t\t\t(options?.refreshRejectedToken && (options.isRejectedToken?.(session.accessToken) ?? true)))\n\t\t) {\n\t\t\tsession = await cloudIntegrations.getConnectionSession(\n\t\t\t\tthis.authProviderId,\n\t\t\t\tsession.accessToken,\n\t\t\t\tconnectionId,\n\t\t\t);\n\t\t\tif (isForAnotherHost(session)) return undefined;\n\t\t\tif (options?.isRejectedToken != null && session?.id != null && session.id !== connectionId) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\n\t\tif (!session) return undefined;\n\n\t\tlet sessionProtocol;\n\t\t// Only derive a protocol from a domain carrying an explicit scheme; a bare `host:port` (e.g. a\n\t\t// self-managed `ghe.example.com:8443`) parses the host as the protocol, corrupting the value.\n\t\tif (/^[a-z][a-z\\d+\\-.]*:\\/\\//i.test(session.domain)) {\n\t\t\ttry {\n\t\t\t\tsessionProtocol = new URL(session.domain).protocol;\n\t\t\t} catch {\n\t\t\t\tsessionProtocol = undefined;\n\t\t\t}\n\t\t}\n\n\t\tconst resolved: ProviderAuthenticationSession = {\n\t\t\t// Prefer the backend's per-connection token id (multi-account); fall back to the resolved\n\t\t\t// primary/legacy connection id so existing single-connection storage keys are preserved.\n\t\t\tid: session.id ?? fallbackId,\n\t\t\taccessToken: session.accessToken,\n\t\t\tscopes: descriptor.scopes,\n\t\t\taccount: {\n\t\t\t\tid: '',\n\t\t\t\tlabel: '',\n\t\t\t},\n\t\t\tcloud: true,\n\t\t\ttype: session.type,\n\t\t\texpiresAt: new Date(session.expiresIn * 1000 + Date.now()),\n\t\t\t// Note: do not use the session's domain, because the format is different than in our model\n\t\t\tdomain: descriptor.domain,\n\t\t\t// That format difference is exactly what `baseUrl` is for: the descriptor's domain is the\n\t\t\t// normalized host this connection is keyed by, so a context path only survives on the wire value.\n\t\t\t// When the backend reports no domain at all, KEEP the address already configured rather than\n\t\t\t// writing `undefined` — `writeSecret` mirrors this onto the descriptor, so falling back to the\n\t\t\t// bare host here would drop a context path the user never changed on the next refresh.\n\t\t\tbaseUrl:\n\t\t\t\tsession.domain ||\n\t\t\t\tthis.configuredIntegrationService.getConfiguredBaseUrl(\n\t\t\t\t\tthis.authProviderId,\n\t\t\t\t\tconnectionId,\n\t\t\t\t\tdescriptor.domain,\n\t\t\t\t),\n\t\t\tprotocol: sessionProtocol ?? undefined,\n\t\t\t// Carried for providers whose client needs an app key alongside the token (e.g. Trello).\n\t\t\tappKey: session.appKey,\n\t\t};\n\t\tif (connectionId == null) {\n\t\t\tthis.primaryResponses.set(resolved, session.id == null ? 'legacy' : 'named');\n\t\t}\n\t\treturn resolved;\n\t}\n\n\tprivate async disconnectCloudSession(\n\t\tdescriptor: IntegrationAuthenticationSessionDescriptor,\n\t): Promise<'skip' | 'success' | 'failure'> {\n\t\tconst loggedIn = (await this.authenticationService.ctx.account.getAccount()) != null;\n\t\tif (!loggedIn) return 'skip';\n\n\t\tconst cloudIntegrations = this.authenticationService.cloudIntegrations;\n\t\tif (!(await cloudIntegrations.disconnect(this.authProviderId, descriptor.connectionId))) return 'failure';\n\n\t\tif (isSelfManagedHostIntegrationId(this.authProviderId)) {\n\t\t\tawait this.deleteSession(descriptor, { preserveConfigured: false });\n\t\t}\n\n\t\treturn 'success';\n\t}\n}\n"],"mappings":";;;;;;;;AAwBA,MAAM,oBAAoB,KAAK,KAAK;AAQpC,IAAe,wCAAf,MAE+C;CAK1B;CACA;CALpB,cAA+C,CAAC;CAChD,mCAAsC,IAAI,QAA2D;CAErG,YACC,uBACA,8BACC;EAFkB,KAAA,wBAAA;EACA,KAAA,+BAAA;CACjB;CAEH,UAAgB;EACf,KAAK,YAAY,SAAQ,MAAK,EAAE,QAAQ,CAAC;CAC1C;CAEA,eAAgC,IAAI,QAAc;CAClD,IAAI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Y,EAAE,oBAAoB,MAAM,CAAC;EAGnE,OAAO;CACR;AACD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CloudIntegrationConnection, ConfiguredIntegrationDescriptor } from "./models.js";
|
|
2
|
+
import { IntegrationIds } from "../constants.js";
|
|
3
|
+
//#region ../plus/integrations/src/authentication/cloudIntegrationObservations.d.ts
|
|
4
|
+
export interface CloudIntegrationSync {
|
|
5
|
+
readonly mark: number;
|
|
6
|
+
isCurrent(): boolean;
|
|
7
|
+
}
|
|
8
|
+
type CloudOrder = {
|
|
9
|
+
owner: string;
|
|
10
|
+
mark: number;
|
|
11
|
+
};
|
|
12
|
+
type CloudLogout = CloudOrder & {
|
|
13
|
+
departures: readonly string[];
|
|
14
|
+
};
|
|
15
|
+
export type CloudCredentialOrigin = CloudOrder & {
|
|
16
|
+
after?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare class CloudIntegrationObservations {
|
|
19
|
+
private readonly owner;
|
|
20
|
+
private readonly acquisitions;
|
|
21
|
+
private readonly inheritedLogout?;
|
|
22
|
+
private _logout?;
|
|
23
|
+
get hasLogout(): boolean;
|
|
24
|
+
snapshotLogout(): CloudLogout | undefined;
|
|
25
|
+
constructor(previousLogout?: CloudLogout);
|
|
26
|
+
origin(mark: number): CloudCredentialOrigin;
|
|
27
|
+
allows(origin: CloudCredentialOrigin | undefined): boolean;
|
|
28
|
+
published(scope: string, mark: number): void;
|
|
29
|
+
acquiredAfter(scope: string, mark: number): boolean;
|
|
30
|
+
private latestSync;
|
|
31
|
+
private _lastLogout;
|
|
32
|
+
get lastLogout(): number;
|
|
33
|
+
private readonly connections;
|
|
34
|
+
private readonly departures;
|
|
35
|
+
private readonly primaries;
|
|
36
|
+
acceptLogout(request: number, mark: number, connections: readonly ConfiguredIntegrationDescriptor[]): CloudIntegrationSync | undefined;
|
|
37
|
+
accept(mark: number, connections: ReadonlyMap<IntegrationIds, readonly CloudIntegrationConnection[]>): CloudIntegrationSync | undefined;
|
|
38
|
+
loggedOutSince(mark: number): boolean;
|
|
39
|
+
observe(scope: string, mark: number): void;
|
|
40
|
+
observedSince(scope: string, mark: number): boolean;
|
|
41
|
+
remove(scope: string): void;
|
|
42
|
+
depart(id: IntegrationIds, domain: string | undefined, connectionId: string, mark: number): boolean;
|
|
43
|
+
departedAt(id: IntegrationIds, domain: string, connectionId: string): number | undefined;
|
|
44
|
+
observePrimary(id: IntegrationIds, domain: string | undefined, connectionId: string, mark: number): void;
|
|
45
|
+
supersedingPrimary(id: IntegrationIds, domain: string | undefined, connectionId: string, mark: number): string | undefined;
|
|
46
|
+
private primaryScope;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//# sourceMappingURL=cloudIntegrationObservations.d.ts.map
|