@gitkraken/core-gitlens 0.28.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/dist/git/cache.d.ts +39 -1
  3. package/dist/git/cache.js +108 -7
  4. package/dist/git/cache.js.map +1 -1
  5. package/dist/git/providers/branches.d.ts +17 -12
  6. package/dist/git/providers/revision.d.ts +4 -0
  7. package/dist/git/watching/worktreeSummary.d.ts +16 -7
  8. package/dist/git/watching/worktreeSummary.js +44 -14
  9. package/dist/git/watching/worktreeSummary.js.map +1 -1
  10. package/dist/git-cli/cliGitProvider.js +3 -3
  11. package/dist/git-cli/cliGitProvider.js.map +1 -1
  12. package/dist/git-cli/exec/exec.d.ts +2 -2
  13. package/dist/git-cli/exec/exec.js +2 -2
  14. package/dist/git-cli/exec/gitDirResolver.d.ts +6 -1
  15. package/dist/git-cli/exec/gitDirResolver.js +9 -4
  16. package/dist/git-cli/exec/gitDirResolver.js.map +1 -1
  17. package/dist/git-cli/providers/branches.d.ts +91 -13
  18. package/dist/git-cli/providers/branches.js +673 -176
  19. package/dist/git-cli/providers/branches.js.map +1 -1
  20. package/dist/git-cli/providers/config.js +1 -1
  21. package/dist/git-cli/providers/config.js.map +1 -1
  22. package/dist/git-cli/providers/revision.d.ts +4 -0
  23. package/dist/git-cli/providers/revision.js +64 -3
  24. package/dist/git-cli/providers/revision.js.map +1 -1
  25. package/dist/ipc/ipcServer.d.ts +6 -1
  26. package/dist/ipc/ipcServer.js +15 -6
  27. package/dist/ipc/ipcServer.js.map +1 -1
  28. package/dist/plus/ai/errors.js +4 -4
  29. package/dist/plus/ai/errors.js.map +1 -1
  30. package/dist/plus/ai/models/model.d.ts +1 -1
  31. package/dist/plus/ai/models/model.js.map +1 -1
  32. package/dist/plus/ai/models/promptTemplates.d.ts +45 -2
  33. package/dist/plus/ai/models/results.d.ts +41 -0
  34. package/dist/plus/ai/models/results.js +14 -0
  35. package/dist/plus/ai/models/results.js.map +1 -0
  36. package/dist/plus/ai/prompts.d.ts +6 -0
  37. package/dist/plus/ai/prompts.js +255 -5
  38. package/dist/plus/ai/prompts.js.map +1 -1
  39. package/dist/plus/ai/providers/gitkrakenProvider.js +2 -2
  40. package/dist/plus/ai/providers/gitkrakenProvider.js.map +1 -1
  41. package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -0
  42. package/dist/plus/ai/providers/openAICompatibleProviderBase.js.map +1 -1
  43. package/dist/plus/ai/utils/ai.utils.d.ts +4 -0
  44. package/dist/plus/ai/utils/ai.utils.js +8 -1
  45. package/dist/plus/ai/utils/ai.utils.js.map +1 -1
  46. package/dist/plus/ai/utils/results.utils.d.ts +15 -1
  47. package/dist/plus/ai/utils/results.utils.js +80 -4
  48. package/dist/plus/ai/utils/results.utils.js.map +1 -1
  49. package/dist/plus/integrations/authentication/integrationAuthenticationService.js +2 -0
  50. package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
  51. package/dist/plus/integrations/authentication/models.d.ts +1 -1
  52. package/dist/plus/integrations/authentication/models.js +2 -0
  53. package/dist/plus/integrations/authentication/models.js.map +1 -1
  54. package/dist/plus/integrations/constants.d.ts +2 -1
  55. package/dist/plus/integrations/constants.js +12 -2
  56. package/dist/plus/integrations/constants.js.map +1 -1
  57. package/dist/plus/integrations/fieldPresence.js +17 -1
  58. package/dist/plus/integrations/fieldPresence.js.map +1 -1
  59. package/dist/plus/integrations/integrationService.d.ts +1 -1
  60. package/dist/plus/integrations/integrationService.js +8 -2
  61. package/dist/plus/integrations/integrationService.js.map +1 -1
  62. package/dist/plus/integrations/lite.js +5 -6
  63. package/dist/plus/integrations/lite.js.map +1 -1
  64. package/dist/plus/integrations/models/gitHostIntegration.d.ts +11 -1
  65. package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
  66. package/dist/plus/integrations/providers/asana.d.ts +91 -0
  67. package/dist/plus/integrations/providers/asana.js +344 -0
  68. package/dist/plus/integrations/providers/asana.js.map +1 -0
  69. package/dist/plus/integrations/providers/azure/azure.js +3 -2
  70. package/dist/plus/integrations/providers/azure/azure.js.map +1 -1
  71. package/dist/plus/integrations/providers/azure/models.js +3 -2
  72. package/dist/plus/integrations/providers/azure/models.js.map +1 -1
  73. package/dist/plus/integrations/providers/azureDevOps.d.ts +7 -1
  74. package/dist/plus/integrations/providers/azureDevOps.js +9 -1
  75. package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
  76. package/dist/plus/integrations/providers/bitbucket-server/discovery.js +2 -1
  77. package/dist/plus/integrations/providers/bitbucket-server/discovery.js.map +1 -1
  78. package/dist/plus/integrations/providers/bitbucket-server/models.js.map +1 -1
  79. package/dist/plus/integrations/providers/github.d.ts +2 -2
  80. package/dist/plus/integrations/providers/github.js +2 -2
  81. package/dist/plus/integrations/providers/github.js.map +1 -1
  82. package/dist/plus/integrations/providers/issueSorts.d.ts +5 -0
  83. package/dist/plus/integrations/providers/issueSorts.js +6 -1
  84. package/dist/plus/integrations/providers/issueSorts.js.map +1 -1
  85. package/dist/plus/integrations/providers/jiraIssueByKey.js +2 -1
  86. package/dist/plus/integrations/providers/jiraIssueByKey.js.map +1 -1
  87. package/dist/plus/integrations/providers/models.d.ts +19 -3
  88. package/dist/plus/integrations/providers/models.js +12 -1
  89. package/dist/plus/integrations/providers/models.js.map +1 -1
  90. package/dist/plus/integrations/providers/providerApiClient.d.ts +0 -3
  91. package/dist/plus/integrations/providers/providerApiClient.js +1 -3
  92. package/dist/plus/integrations/providers/providerApiClient.js.map +1 -1
  93. package/dist/plus/integrations/providers/providersApi.d.ts +22 -1
  94. package/dist/plus/integrations/providers/providersApi.js +63 -12
  95. package/dist/plus/integrations/providers/providersApi.js.map +1 -1
  96. package/dist/plus/integrations/providers/utils.d.ts +1 -0
  97. package/dist/plus/integrations/providers/utils.js +8 -2
  98. package/dist/plus/integrations/providers/utils.js.map +1 -1
  99. package/dist/plus/integrations/reads/hierarchy.utils.d.ts +3 -3
  100. package/dist/plus/integrations/reads/hierarchy.utils.js +4 -4
  101. package/dist/plus/integrations/reads/hierarchy.utils.js.map +1 -1
  102. package/dist/plus/integrations/reads/resolveRepository.js +29 -21
  103. package/dist/plus/integrations/reads/resolveRepository.js.map +1 -1
  104. package/dist/plus/integrations/results.d.ts +18 -10
  105. package/dist/plus/integrations/results.js.map +1 -1
  106. package/dist/plus/integrations/utils/domain.utils.js +2 -1
  107. package/dist/plus/integrations/utils/domain.utils.js.map +1 -1
  108. package/dist/plus/integrations/utils/integration.utils.js +5 -13
  109. package/dist/plus/integrations/utils/integration.utils.js.map +1 -1
  110. package/dist/utils/diff.d.ts +19 -0
  111. package/dist/utils/diff.js +121 -3
  112. package/dist/utils/diff.js.map +1 -1
  113. package/dist/utils/env/node/exec.d.ts +0 -1
  114. package/dist/utils/env/node/exec.js +2 -14
  115. package/dist/utils/env/node/exec.js.map +1 -1
  116. package/dist/utils/path.d.ts +2 -0
  117. package/dist/utils/path.js +7 -1
  118. package/dist/utils/path.js.map +1 -1
  119. package/docs/integrations.md +72 -43
  120. package/package.json +2 -2
@@ -0,0 +1,91 @@
1
+ import { IssueResourceDescriptor, ResourceDescriptor } from "../../../git/models/resourceDescriptor.js";
2
+ import { IssueOrPullRequest, IssueOrPullRequestType } from "../../../git/models/issueOrPullRequest.js";
3
+ import { Issue, IssueShape } from "../../../git/models/issue.js";
4
+ import { Account } from "../../../git/models/author.js";
5
+ import { ProviderAuthenticationSession } from "../authentication/models.js";
6
+ import { IssuesCloudHostIntegrationId } from "../constants.js";
7
+ import { ProviderApiCollectionResult, ProviderMetadata } from "./models.js";
8
+ import { AccountWideIssuesResult, IssuesForProjectOptions, ProjectIssuesDrain, ProjectIssuesRequest, SearchMyIssuesOptions } from "../models/issueReads.js";
9
+ import { IssuesIntegration } from "../models/issuesIntegration.js";
10
+ import { IntegrationAuthenticationProviderDescriptor } from "../authentication/integrationAuthenticationProvider.js";
11
+ //#region ../plus/integrations/src/providers/asana.d.ts
12
+ declare const metadata: ProviderMetadata & {
13
+ id: IssuesCloudHostIntegrationId.Asana;
14
+ };
15
+ type AsanaIntegrationId = typeof metadata.id;
16
+ /** An Asana project, naming the workspace it belongs to so its tasks can be encoded and its account resolved. */
17
+ export interface AsanaProjectDescriptor extends IssueResourceDescriptor {
18
+ resourceId: string;
19
+ resourceName: string;
20
+ }
21
+ export declare class AsanaIntegration extends IssuesIntegration<AsanaIntegrationId> {
22
+ readonly authProvider: IntegrationAuthenticationProviderDescriptor;
23
+ get id(): AsanaIntegrationId;
24
+ protected get key(): 'asana';
25
+ get name(): string;
26
+ get domain(): string;
27
+ /**
28
+ * Always asks Asana: the host's current-account cache decides when this runs. An Asana user is the same in every
29
+ * workspace, so the answer is lent briefly to the per-workspace lookup a tracker read makes right after it.
30
+ */
31
+ protected getProviderCurrentAccount(session: ProviderAuthenticationSession): Promise<Account | undefined>;
32
+ protected getProviderUncachedAccountForResource(session: ProviderAuthenticationSession, _resource: ResourceDescriptor): Promise<Account | undefined>;
33
+ protected getProviderAccountForResource(session: ProviderAuthenticationSession, _resource: ResourceDescriptor): Promise<Account | undefined>;
34
+ protected clearDiscoveryCaches(): void;
35
+ private readonly _recentAccounts;
36
+ private fetchAccount;
37
+ protected getProviderResourcesForUser(session: ProviderAuthenticationSession): Promise<IssueResourceDescriptor[] | undefined>;
38
+ protected getProviderProjectsForResources(session: ProviderAuthenticationSession, resources: ResourceDescriptor[]): Promise<AsanaProjectDescriptor[] | undefined>;
39
+ /**
40
+ * Each workspace's unarchived projects, drained per workspace. A workspace whose drain failed or ran out of pages
41
+ * keeps what it read and is recorded in the metadata, so one large or unreadable workspace doesn't hide the rest.
42
+ */
43
+ protected getProviderProjectsForResourcesWithMetadata(session: ProviderAuthenticationSession, resources: ResourceDescriptor[]): Promise<ProviderApiCollectionResult<AsanaProjectDescriptor>>;
44
+ protected getProviderIssuesForProject(session: ProviderAuthenticationSession, project: ResourceDescriptor, options?: IssuesForProjectOptions): Promise<IssueShape[] | undefined>;
45
+ /**
46
+ * A project's tasks, narrowed to the viewer's by assignee after the drain: Asana's task list takes a project or
47
+ * an assignee, never both. So a user-scoped read of a busy project spends its page budget on other people's
48
+ * tasks, and a truncated one can't be recovered by a narrower scope.
49
+ */
50
+ protected getProviderIssuesForProjectWithTruncation(session: ProviderAuthenticationSession, project: ResourceDescriptor, options?: IssuesForProjectOptions): Promise<ProjectIssuesDrain | undefined>;
51
+ /**
52
+ * Searches every project of one workspace together when the read is scoped to the viewer: Asana's "my tasks" read
53
+ * takes the workspace and the assignee, so one drain answers all of them, where reading project by project would
54
+ * drain every task of every project only to keep the viewer's.
55
+ */
56
+ protected getProjectIssuesSearches(requests: readonly ProjectIssuesRequest<ResourceDescriptor>[]): number[][] | undefined;
57
+ /**
58
+ * The viewer's tasks in one workspace, split into the requested projects. A task outside them (in another project,
59
+ * or in none, only in the user's My Tasks) belongs to no project of this read and is left out.
60
+ *
61
+ * A known limitation: an unscoped task read reports only the first project Asana lists for a task, so a task in
62
+ * several projects is attributed to that one alone, and is left out when that project isn't requested even if
63
+ * another of its projects is. The per-project fallback lists it under every requested project instead. Falling
64
+ * back whenever a task's project is outside the search would avoid this, but most searches hold such a task, so
65
+ * nearly every search would drain each project in full.
66
+ */
67
+ protected searchProviderProjectIssues(session: ProviderAuthenticationSession, requests: readonly ProjectIssuesRequest<ResourceDescriptor>[]): Promise<IssueShape[][] | undefined>;
68
+ protected searchProviderMyIssues(session: ProviderAuthenticationSession, resources?: ResourceDescriptor[], cancellation?: AbortSignal): Promise<IssueShape[] | undefined>;
69
+ /**
70
+ * The tasks assigned to the viewer, one drain per workspace (Asana requires the workspace alongside the
71
+ * assignee). Reads every workspace the user belongs to unless `resources` names some. A workspace that can't be
72
+ * read is recorded in the metadata and the others are still returned; only when none could be read does the read
73
+ * throw. Cancellation stops between workspaces and is not reported as truncation: the caller asked for the read to
74
+ * stop.
75
+ */
76
+ protected searchProviderMyIssuesWithTruncation(session: ProviderAuthenticationSession, resources?: ResourceDescriptor[], cancellation?: AbortSignal, options?: SearchMyIssuesOptions): Promise<AccountWideIssuesResult | undefined>;
77
+ /**
78
+ * Follows a task read's cursor up to {@link maxTaskPages}. `truncated` is set when the backstop stopped it with
79
+ * pages left, or when a page after the first failed (recorded under `scope`, keeping the prefix). A failure on the
80
+ * first page throws, so the caller sees an error rather than an empty success.
81
+ */
82
+ private drainTasks;
83
+ protected getProviderLinkedIssueOrPullRequest(_session: ProviderAuthenticationSession, _resource: ResourceDescriptor, _id: {
84
+ id: string;
85
+ key: string;
86
+ }, _type: undefined | IssueOrPullRequestType): Promise<IssueOrPullRequest | undefined>;
87
+ /** `resource` is the task's workspace; `id` is the task gid, which is also what an Asana issue reports as its id. */
88
+ protected getProviderIssue(session: ProviderAuthenticationSession, resource: ResourceDescriptor, id: string): Promise<Issue | undefined>;
89
+ }
90
+ //#endregion
91
+ //# sourceMappingURL=asana.d.ts.map
@@ -0,0 +1,344 @@
1
+ import { isCancellationError } from "../../../utils/cancellation.js";
2
+ import { Logger as _logger } from "../../../utils/logger.js";
3
+ import { PromiseCache } from "../../../utils/promiseCache.js";
4
+ import { isIssueResourceDescriptor } from "../../../git/utils/resourceDescriptor.utils.js";
5
+ import { IntegrationReadUnavailableError, toError } from "../errors.js";
6
+ import { throwIfCallerContractError, toCollectionScopeFailure } from "../collectionMetadata.js";
7
+ import { collectProviderPagedResult, mergeCollectionMetadata } from "./utils/providerPaging.js";
8
+ import { fromProviderIssue, providersMetadata, toIssueShape, toProviderIssueStates } from "./models.js";
9
+ import { toTokenWithInfo } from "../authentication/models.js";
10
+ import { IssuesIntegration, groupProjectIssuesSearches } from "../models/issuesIntegration.js";
11
+ //#region ../plus/integrations/src/providers/asana.ts
12
+ const metadata = providersMetadata.asana;
13
+ const authProvider = Object.freeze({
14
+ id: metadata.id,
15
+ scopes: metadata.scopes
16
+ });
17
+ /** Long enough to span one tracker read, short enough that a profile change shows on the next. */
18
+ const recentAccountTTL = 6e4;
19
+ /** The workspace and project discovery backstop: provider-apis pages them 100 at a time, so 2,000 of each. */
20
+ const maxDiscoveryPages = 20;
21
+ /** The task drain's backstop, per project or per workspace: 1,000 tasks at the SDK's 100-per-page. */
22
+ const maxTaskPages = 10;
23
+ var AsanaIntegration = class extends IssuesIntegration {
24
+ authProvider = authProvider;
25
+ get id() {
26
+ return metadata.id;
27
+ }
28
+ get key() {
29
+ return "asana";
30
+ }
31
+ get name() {
32
+ return metadata.name;
33
+ }
34
+ get domain() {
35
+ return metadata.domain;
36
+ }
37
+ /**
38
+ * Always asks Asana: the host's current-account cache decides when this runs. An Asana user is the same in every
39
+ * workspace, so the answer is lent briefly to the per-workspace lookup a tracker read makes right after it.
40
+ */
41
+ async getProviderCurrentAccount(session) {
42
+ const account = await this.fetchAccount(session);
43
+ if (account != null) this._recentAccounts.set(session.accessToken, Promise.resolve(account));
44
+ return account;
45
+ }
46
+ getProviderUncachedAccountForResource(session, _resource) {
47
+ return this.fetchAccount(session);
48
+ }
49
+ getProviderAccountForResource(session, _resource) {
50
+ return this._recentAccounts.getOrCreate(session.accessToken, () => this.fetchAccount(session), { evictWhen: (account) => account == null });
51
+ }
52
+ clearDiscoveryCaches() {
53
+ this._recentAccounts.clear();
54
+ }
55
+ _recentAccounts = new PromiseCache({
56
+ capacity: 10,
57
+ createTTL: recentAccountTTL
58
+ });
59
+ async fetchAccount(session) {
60
+ const user = await (await this.getProvidersApi()).getAsanaCurrentUser(toTokenWithInfo(this.id, session));
61
+ if (user == null) return void 0;
62
+ return {
63
+ provider: this,
64
+ id: user.id,
65
+ name: user.name ?? void 0,
66
+ username: user.username ?? void 0,
67
+ email: user.email ?? void 0,
68
+ avatarUrl: user.avatarUrl ?? void 0
69
+ };
70
+ }
71
+ async getProviderResourcesForUser(session) {
72
+ const api = await this.getProvidersApi();
73
+ const tokenWithInfo = toTokenWithInfo(this.id, session);
74
+ const workspaces = await collectProviderPagedResult((cursor) => api.getAsanaWorkspacesForCurrentUser(tokenWithInfo, { cursor }), maxDiscoveryPages);
75
+ if (workspaces.truncated) _logger.warn(`Asana workspace discovery stopped after ${workspaces.values.length} workspaces`);
76
+ return workspaces.values.map((w) => ({
77
+ key: w.id,
78
+ id: w.id,
79
+ name: w.name
80
+ }));
81
+ }
82
+ async getProviderProjectsForResources(session, resources) {
83
+ return (await this.getProviderProjectsForResourcesWithMetadata(session, resources)).values;
84
+ }
85
+ /**
86
+ * Each workspace's unarchived projects, drained per workspace. A workspace whose drain failed or ran out of pages
87
+ * keeps what it read and is recorded in the metadata, so one large or unreadable workspace doesn't hide the rest.
88
+ */
89
+ async getProviderProjectsForResourcesWithMetadata(session, resources) {
90
+ const api = await this.getProvidersApi();
91
+ const tokenWithInfo = toTokenWithInfo(this.id, session);
92
+ const values = [];
93
+ let collectionMetadata;
94
+ for (const workspace of resources.filter(isIssueResourceDescriptor)) {
95
+ const scope = {
96
+ providerId: this.id,
97
+ resourceId: workspace.id
98
+ };
99
+ const projects = await collectProviderPagedResult((cursor) => api.getAsanaProjectsForWorkspace(tokenWithInfo, workspace.id, { cursor }), maxDiscoveryPages, scope);
100
+ values.push(...projects.values.map((p) => ({
101
+ key: p.id,
102
+ id: p.id,
103
+ name: p.name,
104
+ resourceId: workspace.id,
105
+ resourceName: workspace.name
106
+ })));
107
+ collectionMetadata = mergeCollectionMetadata(collectionMetadata, projects.truncated && !projects.metadata?.failures?.length ? mergeCollectionMetadata(projects.metadata, {
108
+ completeness: "partial",
109
+ omissions: [{
110
+ kind: "pagination-incomplete",
111
+ scope
112
+ }]
113
+ }) : projects.metadata);
114
+ }
115
+ return collectionMetadata != null ? {
116
+ values,
117
+ metadata: collectionMetadata
118
+ } : { values };
119
+ }
120
+ async getProviderIssuesForProject(session, project, options) {
121
+ return (await this.getProviderIssuesForProjectWithTruncation(session, project, options))?.values;
122
+ }
123
+ /**
124
+ * A project's tasks, narrowed to the viewer's by assignee after the drain: Asana's task list takes a project or
125
+ * an assignee, never both. So a user-scoped read of a busy project spends its page budget on other people's
126
+ * tasks, and a truncated one can't be recovered by a narrower scope.
127
+ */
128
+ async getProviderIssuesForProjectWithTruncation(session, project, options) {
129
+ if (!isAsanaProjectDescriptor(project)) return void 0;
130
+ let viewerId;
131
+ if (options?.user != null) {
132
+ viewerId = options.userId ?? (await this.getProviderAccountForResource(session, project))?.id;
133
+ if (viewerId == null) throw new IntegrationReadUnavailableError(metadata.name, "could not resolve the current user to scope issues to");
134
+ }
135
+ const drain = await this.drainTasks(session, { projectId: project.id }, options, {
136
+ providerId: this.id,
137
+ resourceId: project.resourceId,
138
+ projectId: project.id
139
+ });
140
+ const issueProject = toIssueProject(project);
141
+ const values = drain.values.flatMap((issue) => {
142
+ if (viewerId != null && !issue.assignees.some((a) => a.id === viewerId)) return [];
143
+ const shape = toIssueShape(issue, this, { projection: "project" });
144
+ return shape == null ? [] : [{
145
+ ...shape,
146
+ project: issueProject
147
+ }];
148
+ });
149
+ return drain.truncated ? {
150
+ values,
151
+ truncated: true,
152
+ recovery: "none",
153
+ metadata: drain.metadata
154
+ } : {
155
+ values,
156
+ truncated: false,
157
+ metadata: drain.metadata
158
+ };
159
+ }
160
+ /**
161
+ * Searches every project of one workspace together when the read is scoped to the viewer: Asana's "my tasks" read
162
+ * takes the workspace and the assignee, so one drain answers all of them, where reading project by project would
163
+ * drain every task of every project only to keep the viewer's.
164
+ */
165
+ getProjectIssuesSearches(requests) {
166
+ return groupProjectIssuesSearches(requests, ({ project, options }) => options.user != null && isAsanaProjectDescriptor(project) ? [
167
+ project.resourceId,
168
+ options.user,
169
+ options.userId ?? "",
170
+ options.sort ?? "",
171
+ options.state ?? "",
172
+ options.filters?.join(",") ?? ""
173
+ ].join("\0") : void 0);
174
+ }
175
+ /**
176
+ * The viewer's tasks in one workspace, split into the requested projects. A task outside them (in another project,
177
+ * or in none, only in the user's My Tasks) belongs to no project of this read and is left out.
178
+ *
179
+ * A known limitation: an unscoped task read reports only the first project Asana lists for a task, so a task in
180
+ * several projects is attributed to that one alone, and is left out when that project isn't requested even if
181
+ * another of its projects is. The per-project fallback lists it under every requested project instead. Falling
182
+ * back whenever a task's project is outside the search would avoid this, but most searches hold such a task, so
183
+ * nearly every search would drain each project in full.
184
+ */
185
+ async searchProviderProjectIssues(session, requests) {
186
+ const projects = requests.map((request) => request.project).filter(isAsanaProjectDescriptor);
187
+ if (projects.length !== requests.length) return void 0;
188
+ const { options } = requests[0];
189
+ const drain = await this.drainTasks(session, { workspaceId: projects[0].resourceId }, options, {
190
+ providerId: this.id,
191
+ resourceId: projects[0].resourceId
192
+ });
193
+ if (drain.truncated || drain.metadata != null && drain.metadata.completeness !== "complete") return;
194
+ const indexById = new Map(projects.map((project, index) => [project.id, index]));
195
+ const split = projects.map(() => []);
196
+ for (const issue of drain.values) {
197
+ const index = issue.project?.id != null ? indexById.get(issue.project.id) : void 0;
198
+ if (index == null) continue;
199
+ const shape = toIssueShape(issue, this, { projection: "project" });
200
+ if (shape == null) continue;
201
+ split[index].push({
202
+ ...shape,
203
+ project: toIssueProject(projects[index])
204
+ });
205
+ }
206
+ return split;
207
+ }
208
+ async searchProviderMyIssues(session, resources, cancellation) {
209
+ return (await this.searchProviderMyIssuesWithTruncation(session, resources, cancellation))?.values;
210
+ }
211
+ /**
212
+ * The tasks assigned to the viewer, one drain per workspace (Asana requires the workspace alongside the
213
+ * assignee). Reads every workspace the user belongs to unless `resources` names some. A workspace that can't be
214
+ * read is recorded in the metadata and the others are still returned; only when none could be read does the read
215
+ * throw. Cancellation stops between workspaces and is not reported as truncation: the caller asked for the read to
216
+ * stop.
217
+ */
218
+ async searchProviderMyIssuesWithTruncation(session, resources, cancellation, options) {
219
+ const workspaces = (resources ?? await this.getProviderResourcesForUser(session) ?? []).filter(isIssueResourceDescriptor);
220
+ const values = [];
221
+ let truncated = false;
222
+ let collectionMetadata;
223
+ let firstError;
224
+ let workspacesRead = 0;
225
+ for (const workspace of workspaces) {
226
+ if (cancellation?.aborted) break;
227
+ const scope = {
228
+ providerId: this.id,
229
+ resourceId: workspace.id
230
+ };
231
+ let drain;
232
+ try {
233
+ drain = await this.drainTasks(session, { workspaceId: workspace.id }, options, scope);
234
+ } catch (ex) {
235
+ if (isCancellationError(ex)) throw ex;
236
+ throwIfCallerContractError(ex);
237
+ firstError ??= toError(ex);
238
+ truncated = true;
239
+ collectionMetadata = mergeCollectionMetadata(collectionMetadata, {
240
+ completeness: "partial",
241
+ failures: [toCollectionScopeFailure(scope, ex)]
242
+ });
243
+ continue;
244
+ }
245
+ workspacesRead++;
246
+ truncated ||= drain.truncated;
247
+ collectionMetadata = mergeCollectionMetadata(collectionMetadata, drain.metadata);
248
+ for (const issue of drain.values) {
249
+ const shape = toIssueShape(issue, this, { projection: "account" });
250
+ if (shape != null) values.push({
251
+ ...shape,
252
+ project: toAsanaIssueProject(issue, workspace)
253
+ });
254
+ }
255
+ }
256
+ if (workspacesRead === 0 && firstError != null) throw firstError;
257
+ return {
258
+ values,
259
+ truncated,
260
+ metadata: collectionMetadata
261
+ };
262
+ }
263
+ /**
264
+ * Follows a task read's cursor up to {@link maxTaskPages}. `truncated` is set when the backstop stopped it with
265
+ * pages left, or when a page after the first failed (recorded under `scope`, keeping the prefix). A failure on the
266
+ * first page throws, so the caller sees an error rather than an empty success.
267
+ */
268
+ async drainTasks(session, read, options, scope) {
269
+ const api = await this.getProvidersApi();
270
+ const tokenWithInfo = toTokenWithInfo(this.id, session);
271
+ const states = toProviderIssueStates(options?.state);
272
+ let pagesRead = 0;
273
+ let firstPageError;
274
+ const drain = await collectProviderPagedResult(async (cursor) => {
275
+ const pageOptions = {
276
+ cursor,
277
+ states,
278
+ sort: options?.sort
279
+ };
280
+ try {
281
+ const page = await ("projectId" in read ? api.getAsanaIssuesForProject(tokenWithInfo, read.projectId, pageOptions) : api.getAsanaIssuesForCurrentUser(tokenWithInfo, read.workspaceId, pageOptions));
282
+ pagesRead++;
283
+ return page;
284
+ } catch (ex) {
285
+ if (pagesRead === 0) firstPageError = toError(ex);
286
+ throw ex;
287
+ }
288
+ }, maxTaskPages, scope);
289
+ if (firstPageError != null) throw firstPageError;
290
+ return {
291
+ values: drain.values,
292
+ truncated: drain.truncated === true,
293
+ metadata: drain.metadata
294
+ };
295
+ }
296
+ getProviderLinkedIssueOrPullRequest(_session, _resource, _id, _type) {
297
+ return Promise.resolve(void 0);
298
+ }
299
+ /** `resource` is the task's workspace; `id` is the task gid, which is also what an Asana issue reports as its id. */
300
+ async getProviderIssue(session, resource, id) {
301
+ if (!isIssueResourceDescriptor(resource)) return void 0;
302
+ const issue = await (await this.getProvidersApi()).getAsanaIssue(toTokenWithInfo(this.id, session), id);
303
+ return issue != null ? fromProviderIssue(issue, this, {
304
+ projection: "point",
305
+ project: toAsanaIssueProject(issue, resource)
306
+ }) : void 0;
307
+ }
308
+ };
309
+ function isAsanaProjectDescriptor(project) {
310
+ return isIssueResourceDescriptor(project) && typeof project.resourceId === "string";
311
+ }
312
+ function toIssueProject(project) {
313
+ return {
314
+ id: project.id,
315
+ name: project.name,
316
+ resourceId: project.resourceId,
317
+ resourceName: project.resourceName
318
+ };
319
+ }
320
+ /**
321
+ * The project an issue read outside a project reports. An Asana issue entity identifier is keyed by the task's
322
+ * workspace, which the SDK reports beside the project rather than in it, so this always names the workspace as the
323
+ * resource. A task in no project (only in someone's My Tasks) reports the workspace as its project too, so its
324
+ * branch associations stay round-trippable.
325
+ */
326
+ function toAsanaIssueProject(issue, workspace) {
327
+ const resourceId = issue.workspaceId ?? workspace.id;
328
+ const resourceName = resourceId === workspace.id ? workspace.name : "";
329
+ return issue.project?.id != null ? {
330
+ id: issue.project.id,
331
+ name: issue.project.name,
332
+ resourceId,
333
+ resourceName
334
+ } : {
335
+ id: resourceId,
336
+ name: resourceName,
337
+ resourceId,
338
+ resourceName
339
+ };
340
+ }
341
+ //#endregion
342
+ export { AsanaIntegration };
343
+
344
+ //# sourceMappingURL=asana.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asana.js","names":[],"sources":["../../../../../plus/integrations/src/providers/asana.ts"],"sourcesContent":["import type { CollectionMetadata, CollectionScopeFailure } from '@gitkraken/provider-apis';\nimport type { Account } from '@gitlens/git/models/author.js';\nimport type { Issue, IssueProject, IssueShape } from '@gitlens/git/models/issue.js';\nimport type { IssueOrPullRequest, IssueOrPullRequestType } from '@gitlens/git/models/issueOrPullRequest.js';\nimport type { IssueResourceDescriptor, ResourceDescriptor } from '@gitlens/git/models/resourceDescriptor.js';\nimport { isIssueResourceDescriptor } from '@gitlens/git/utils/resourceDescriptor.utils.js';\nimport { isCancellationError } from '@gitlens/utils/cancellation.js';\nimport { Logger } from '@gitlens/utils/logger.js';\nimport { PromiseCache } from '@gitlens/utils/promiseCache.js';\nimport type { IntegrationAuthenticationProviderDescriptor } from '../authentication/integrationAuthenticationProvider.js';\nimport type { ProviderAuthenticationSession } from '../authentication/models.js';\nimport { toTokenWithInfo } from '../authentication/models.js';\nimport { throwIfCallerContractError, toCollectionScopeFailure } from '../collectionMetadata.js';\nimport { IntegrationReadUnavailableError, toError } from '../errors.js';\nimport type {\n\tAccountWideIssuesResult,\n\tIssuesForProjectOptions,\n\tProjectIssuesDrain,\n\tProjectIssuesRequest,\n\tSearchMyIssuesOptions,\n} from '../models/issueReads.js';\nimport { groupProjectIssuesSearches, IssuesIntegration } from '../models/issuesIntegration.js';\nimport type { ProviderApiCollectionResult, ProviderIssue } from './models.js';\nimport { fromProviderIssue, providersMetadata, toIssueShape, toProviderIssueStates } from './models.js';\nimport { collectProviderPagedResult, mergeCollectionMetadata } from './utils/providerPaging.js';\n\nconst metadata = providersMetadata.asana;\ntype AsanaIntegrationId = typeof metadata.id;\nconst authProvider = Object.freeze({ id: metadata.id, scopes: metadata.scopes });\n/** Long enough to span one tracker read, short enough that a profile change shows on the next. */\nconst recentAccountTTL = 60 * 1000;\n/** The workspace and project discovery backstop: provider-apis pages them 100 at a time, so 2,000 of each. */\nconst maxDiscoveryPages = 20;\n/** The task drain's backstop, per project or per workspace: 1,000 tasks at the SDK's 100-per-page. */\nconst maxTaskPages = 10;\n\n/** An Asana project, naming the workspace it belongs to so its tasks can be encoded and its account resolved. */\nexport interface AsanaProjectDescriptor extends IssueResourceDescriptor {\n\tresourceId: string;\n\tresourceName: string;\n}\n\nexport class AsanaIntegration extends IssuesIntegration<AsanaIntegrationId> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\n\toverride get id(): AsanaIntegrationId {\n\t\treturn metadata.id;\n\t}\n\tprotected override get key(): 'asana' {\n\t\treturn 'asana';\n\t}\n\toverride get name(): string {\n\t\treturn metadata.name;\n\t}\n\toverride get domain(): string {\n\t\treturn metadata.domain;\n\t}\n\n\t/**\n\t * Always asks Asana: the host's current-account cache decides when this runs. An Asana user is the same in every\n\t * workspace, so the answer is lent briefly to the per-workspace lookup a tracker read makes right after it.\n\t */\n\tprotected override async getProviderCurrentAccount(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<Account | undefined> {\n\t\tconst account = await this.fetchAccount(session);\n\t\tif (account != null) {\n\t\t\tthis._recentAccounts.set(session.accessToken, Promise.resolve(account));\n\t\t}\n\t\treturn account;\n\t}\n\n\tprotected override getProviderUncachedAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\treturn this.fetchAccount(session);\n\t}\n\n\tprotected override getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\treturn this._recentAccounts.getOrCreate(session.accessToken, () => this.fetchAccount(session), {\n\t\t\tevictWhen: account => account == null,\n\t\t});\n\t}\n\n\tprotected override clearDiscoveryCaches(): void {\n\t\tthis._recentAccounts.clear();\n\t}\n\n\tprivate readonly _recentAccounts = new PromiseCache<string, Account | undefined>({\n\t\tcapacity: 10,\n\t\tcreateTTL: recentAccountTTL,\n\t});\n\n\tprivate async fetchAccount(session: ProviderAuthenticationSession): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api.getAsanaCurrentUser(toTokenWithInfo(this.id, session));\n\t\tif (user == null) return undefined;\n\n\t\treturn {\n\t\t\tprovider: this,\n\t\t\tid: user.id,\n\t\t\tname: user.name ?? undefined,\n\t\t\t// Asana has no usernames; the SDK reports the display name as the handle.\n\t\t\tusername: user.username ?? undefined,\n\t\t\temail: user.email ?? undefined,\n\t\t\tavatarUrl: user.avatarUrl ?? undefined,\n\t\t};\n\t}\n\n\tprotected override async getProviderResourcesForUser(\n\t\tsession: ProviderAuthenticationSession,\n\t): Promise<IssueResourceDescriptor[] | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst workspaces = await collectProviderPagedResult(\n\t\t\tcursor => api.getAsanaWorkspacesForCurrentUser(tokenWithInfo, { cursor: cursor }),\n\t\t\tmaxDiscoveryPages,\n\t\t);\n\t\t// Resource discovery has no completeness to report, so a user past the backstop is logged rather than refused:\n\t\t// the workspaces read still hold their projects.\n\t\tif (workspaces.truncated) {\n\t\t\tLogger.warn(`Asana workspace discovery stopped after ${workspaces.values.length} workspaces`);\n\t\t}\n\t\treturn workspaces.values.map(w => ({ key: w.id, id: w.id, name: w.name }));\n\t}\n\n\tprotected override async getProviderProjectsForResources(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: ResourceDescriptor[],\n\t): Promise<AsanaProjectDescriptor[] | undefined> {\n\t\treturn (await this.getProviderProjectsForResourcesWithMetadata(session, resources)).values;\n\t}\n\n\t/**\n\t * Each workspace's unarchived projects, drained per workspace. A workspace whose drain failed or ran out of pages\n\t * keeps what it read and is recorded in the metadata, so one large or unreadable workspace doesn't hide the rest.\n\t */\n\tprotected override async getProviderProjectsForResourcesWithMetadata(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources: ResourceDescriptor[],\n\t): Promise<ProviderApiCollectionResult<AsanaProjectDescriptor>> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\n\t\tconst values: AsanaProjectDescriptor[] = [];\n\t\tlet collectionMetadata: CollectionMetadata | undefined;\n\t\tfor (const workspace of resources.filter(isIssueResourceDescriptor)) {\n\t\t\tconst scope: CollectionScopeFailure['scope'] = { providerId: this.id, resourceId: workspace.id };\n\t\t\tconst projects = await collectProviderPagedResult(\n\t\t\t\tcursor => api.getAsanaProjectsForWorkspace(tokenWithInfo, workspace.id, { cursor: cursor }),\n\t\t\t\tmaxDiscoveryPages,\n\t\t\t\tscope,\n\t\t\t);\n\t\t\tvalues.push(\n\t\t\t\t...projects.values.map(p => ({\n\t\t\t\t\tkey: p.id,\n\t\t\t\t\tid: p.id,\n\t\t\t\t\tname: p.name,\n\t\t\t\t\tresourceId: workspace.id,\n\t\t\t\t\tresourceName: workspace.name,\n\t\t\t\t})),\n\t\t\t);\n\t\t\tcollectionMetadata = mergeCollectionMetadata(\n\t\t\t\tcollectionMetadata,\n\t\t\t\tprojects.truncated && !projects.metadata?.failures?.length\n\t\t\t\t\t? mergeCollectionMetadata(projects.metadata, {\n\t\t\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\t\t\tomissions: [{ kind: 'pagination-incomplete', scope: scope }],\n\t\t\t\t\t\t})\n\t\t\t\t\t: projects.metadata,\n\t\t\t);\n\t\t}\n\n\t\treturn collectionMetadata != null ? { values: values, metadata: collectionMetadata } : { values: values };\n\t}\n\n\tprotected override async getProviderIssuesForProject(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: ResourceDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.getProviderIssuesForProjectWithTruncation(session, project, options))?.values;\n\t}\n\n\t/**\n\t * A project's tasks, narrowed to the viewer's by assignee after the drain: Asana's task list takes a project or\n\t * an assignee, never both. So a user-scoped read of a busy project spends its page budget on other people's\n\t * tasks, and a truncated one can't be recovered by a narrower scope.\n\t */\n\tprotected override async getProviderIssuesForProjectWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: ResourceDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<ProjectIssuesDrain | undefined> {\n\t\tif (!isAsanaProjectDescriptor(project)) return undefined;\n\n\t\tlet viewerId: string | undefined;\n\t\tif (options?.user != null) {\n\t\t\tviewerId = options.userId ?? (await this.getProviderAccountForResource(session, project))?.id;\n\t\t\t// Without the viewer the read can't be scoped to \"my issues\": the unfiltered project would leak everyone\n\t\t\t// else's tasks, and an empty list would read as \"nothing assigned to me\".\n\t\t\tif (viewerId == null) {\n\t\t\t\tthrow new IntegrationReadUnavailableError(\n\t\t\t\t\tmetadata.name,\n\t\t\t\t\t'could not resolve the current user to scope issues to',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst drain = await this.drainTasks(session, { projectId: project.id }, options, {\n\t\t\tproviderId: this.id,\n\t\t\tresourceId: project.resourceId,\n\t\t\tprojectId: project.id,\n\t\t});\n\n\t\tconst issueProject = toIssueProject(project);\n\t\tconst values = drain.values.flatMap(issue => {\n\t\t\tif (viewerId != null && !issue.assignees.some(a => a.id === viewerId)) return [];\n\n\t\t\tconst shape = toIssueShape(issue, this, { projection: 'project' });\n\t\t\treturn shape == null ? [] : [{ ...shape, project: issueProject } satisfies IssueShape];\n\t\t});\n\n\t\treturn drain.truncated\n\t\t\t? { values: values, truncated: true, recovery: 'none', metadata: drain.metadata }\n\t\t\t: { values: values, truncated: false, metadata: drain.metadata };\n\t}\n\n\t/**\n\t * Searches every project of one workspace together when the read is scoped to the viewer: Asana's \"my tasks\" read\n\t * takes the workspace and the assignee, so one drain answers all of them, where reading project by project would\n\t * drain every task of every project only to keep the viewer's.\n\t */\n\tprotected override getProjectIssuesSearches(\n\t\trequests: readonly ProjectIssuesRequest<ResourceDescriptor>[],\n\t): number[][] | undefined {\n\t\treturn groupProjectIssuesSearches(requests, ({ project, options }) =>\n\t\t\toptions.user != null && isAsanaProjectDescriptor(project)\n\t\t\t\t? [\n\t\t\t\t\t\tproject.resourceId,\n\t\t\t\t\t\toptions.user,\n\t\t\t\t\t\toptions.userId ?? '',\n\t\t\t\t\t\toptions.sort ?? '',\n\t\t\t\t\t\toptions.state ?? '',\n\t\t\t\t\t\toptions.filters?.join(',') ?? '',\n\t\t\t\t\t].join('\\0')\n\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\t/**\n\t * The viewer's tasks in one workspace, split into the requested projects. A task outside them (in another project,\n\t * or in none, only in the user's My Tasks) belongs to no project of this read and is left out.\n\t *\n\t * A known limitation: an unscoped task read reports only the first project Asana lists for a task, so a task in\n\t * several projects is attributed to that one alone, and is left out when that project isn't requested even if\n\t * another of its projects is. The per-project fallback lists it under every requested project instead. Falling\n\t * back whenever a task's project is outside the search would avoid this, but most searches hold such a task, so\n\t * nearly every search would drain each project in full.\n\t */\n\tprotected override async searchProviderProjectIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\trequests: readonly ProjectIssuesRequest<ResourceDescriptor>[],\n\t): Promise<IssueShape[][] | undefined> {\n\t\tconst projects = requests.map(request => request.project).filter(isAsanaProjectDescriptor);\n\t\tif (projects.length !== requests.length) return undefined;\n\n\t\t// Every request of a search shares the workspace and every option read here (see `getProjectIssuesSearches`).\n\t\tconst { options } = requests[0];\n\t\tconst drain = await this.drainTasks(\n\t\t\tsession,\n\t\t\t{ workspaceId: projects[0].resourceId },\n\t\t\toptions,\n\t\t\t// Never published: an incomplete search is read again project by project, which records its own failures.\n\t\t\t{ providerId: this.id, resourceId: projects[0].resourceId },\n\t\t);\n\t\t// An incomplete search says nothing about which of its projects it covered, so only the per-project reads can\n\t\t// report each one's completeness.\n\t\tif (drain.truncated || (drain.metadata != null && drain.metadata.completeness !== 'complete')) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst indexById = new Map(projects.map((project, index) => [project.id, index]));\n\t\tconst split = projects.map((): IssueShape[] => []);\n\t\tfor (const issue of drain.values) {\n\t\t\tconst index = issue.project?.id != null ? indexById.get(issue.project.id) : undefined;\n\t\t\tif (index == null) continue;\n\n\t\t\tconst shape = toIssueShape(issue, this, { projection: 'project' });\n\t\t\tif (shape == null) continue;\n\n\t\t\tsplit[index].push({ ...shape, project: toIssueProject(projects[index]) });\n\t\t}\n\t\treturn split;\n\t}\n\n\tprotected override async searchProviderMyIssues(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: ResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\treturn (await this.searchProviderMyIssuesWithTruncation(session, resources, cancellation))?.values;\n\t}\n\n\t/**\n\t * The tasks assigned to the viewer, one drain per workspace (Asana requires the workspace alongside the\n\t * assignee). Reads every workspace the user belongs to unless `resources` names some. A workspace that can't be\n\t * read is recorded in the metadata and the others are still returned; only when none could be read does the read\n\t * throw. Cancellation stops between workspaces and is not reported as truncation: the caller asked for the read to\n\t * stop.\n\t */\n\tprotected override async searchProviderMyIssuesWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresources?: ResourceDescriptor[],\n\t\tcancellation?: AbortSignal,\n\t\toptions?: SearchMyIssuesOptions,\n\t): Promise<AccountWideIssuesResult | undefined> {\n\t\tconst workspaces = (resources ?? (await this.getProviderResourcesForUser(session)) ?? []).filter(\n\t\t\tisIssueResourceDescriptor,\n\t\t);\n\n\t\tconst values: IssueShape[] = [];\n\t\tlet truncated = false;\n\t\tlet collectionMetadata: CollectionMetadata | undefined;\n\t\tlet firstError: Error | undefined;\n\t\tlet workspacesRead = 0;\n\t\tfor (const workspace of workspaces) {\n\t\t\tif (cancellation?.aborted) break;\n\n\t\t\tconst scope: CollectionScopeFailure['scope'] = { providerId: this.id, resourceId: workspace.id };\n\t\t\tlet drain: Awaited<ReturnType<AsanaIntegration['drainTasks']>>;\n\t\t\ttry {\n\t\t\t\tdrain = await this.drainTasks(session, { workspaceId: workspace.id }, options, scope);\n\t\t\t} catch (ex) {\n\t\t\t\tif (isCancellationError(ex)) throw ex;\n\n\t\t\t\tthrowIfCallerContractError(ex);\n\n\t\t\t\tfirstError ??= toError(ex);\n\t\t\t\ttruncated = true;\n\t\t\t\tcollectionMetadata = mergeCollectionMetadata(collectionMetadata, {\n\t\t\t\t\tcompleteness: 'partial',\n\t\t\t\t\tfailures: [toCollectionScopeFailure(scope, ex)],\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tworkspacesRead++;\n\t\t\ttruncated ||= drain.truncated;\n\t\t\tcollectionMetadata = mergeCollectionMetadata(collectionMetadata, drain.metadata);\n\t\t\tfor (const issue of drain.values) {\n\t\t\t\tconst shape = toIssueShape(issue, this, { projection: 'account' });\n\t\t\t\tif (shape != null) {\n\t\t\t\t\tvalues.push({ ...shape, project: toAsanaIssueProject(issue, workspace) });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Every workspace failed: an empty \"my issues\" would read as \"nothing assigned to me\".\n\t\tif (workspacesRead === 0 && firstError != null) throw firstError;\n\n\t\treturn { values: values, truncated: truncated, metadata: collectionMetadata };\n\t}\n\n\t/**\n\t * Follows a task read's cursor up to {@link maxTaskPages}. `truncated` is set when the backstop stopped it with\n\t * pages left, or when a page after the first failed (recorded under `scope`, keeping the prefix). A failure on the\n\t * first page throws, so the caller sees an error rather than an empty success.\n\t */\n\tprivate async drainTasks(\n\t\tsession: ProviderAuthenticationSession,\n\t\tread: { projectId: string } | { workspaceId: string },\n\t\toptions: Pick<IssuesForProjectOptions, 'state' | 'sort'> | undefined,\n\t\tscope: CollectionScopeFailure['scope'],\n\t): Promise<{ values: ProviderIssue[]; truncated: boolean; metadata?: CollectionMetadata }> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst states = toProviderIssueStates(options?.state);\n\t\tlet pagesRead = 0;\n\t\tlet firstPageError: Error | undefined;\n\t\tconst drain = await collectProviderPagedResult(\n\t\t\tasync cursor => {\n\t\t\t\tconst pageOptions = { cursor: cursor, states: states, sort: options?.sort };\n\t\t\t\ttry {\n\t\t\t\t\tconst page = await ('projectId' in read\n\t\t\t\t\t\t? api.getAsanaIssuesForProject(tokenWithInfo, read.projectId, pageOptions)\n\t\t\t\t\t\t: api.getAsanaIssuesForCurrentUser(tokenWithInfo, read.workspaceId, pageOptions));\n\t\t\t\t\tpagesRead++;\n\t\t\t\t\treturn page;\n\t\t\t\t} catch (ex) {\n\t\t\t\t\tif (pagesRead === 0) {\n\t\t\t\t\t\tfirstPageError = toError(ex);\n\t\t\t\t\t}\n\t\t\t\t\tthrow ex;\n\t\t\t\t}\n\t\t\t},\n\t\t\tmaxTaskPages,\n\t\t\tscope,\n\t\t);\n\t\tif (firstPageError != null) throw firstPageError;\n\n\t\treturn { values: drain.values, truncated: drain.truncated === true, metadata: drain.metadata };\n\t}\n\n\tprotected override getProviderLinkedIssueOrPullRequest(\n\t\t_session: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t\t_id: { id: string; key: string },\n\t\t_type: undefined | IssueOrPullRequestType,\n\t): Promise<IssueOrPullRequest | undefined> {\n\t\t// Asana task references are gids in a permalink URL, never a short key a commit message would carry.\n\t\treturn Promise.resolve(undefined);\n\t}\n\n\t/** `resource` is the task's workspace; `id` is the task gid, which is also what an Asana issue reports as its id. */\n\tprotected override async getProviderIssue(\n\t\tsession: ProviderAuthenticationSession,\n\t\tresource: ResourceDescriptor,\n\t\tid: string,\n\t): Promise<Issue | undefined> {\n\t\tif (!isIssueResourceDescriptor(resource)) return undefined;\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst issue = await api.getAsanaIssue(toTokenWithInfo(this.id, session), id);\n\t\treturn issue != null\n\t\t\t? fromProviderIssue(issue, this, { projection: 'point', project: toAsanaIssueProject(issue, resource) })\n\t\t\t: undefined;\n\t}\n}\n\nfunction isAsanaProjectDescriptor(project: ResourceDescriptor): project is AsanaProjectDescriptor {\n\treturn isIssueResourceDescriptor(project) && typeof project.resourceId === 'string';\n}\n\nfunction toIssueProject(project: AsanaProjectDescriptor): IssueProject {\n\treturn { id: project.id, name: project.name, resourceId: project.resourceId, resourceName: project.resourceName };\n}\n\n/**\n * The project an issue read outside a project reports. An Asana issue entity identifier is keyed by the task's\n * workspace, which the SDK reports beside the project rather than in it, so this always names the workspace as the\n * resource. A task in no project (only in someone's My Tasks) reports the workspace as its project too, so its\n * branch associations stay round-trippable.\n */\nfunction toAsanaIssueProject(issue: ProviderIssue, workspace: IssueResourceDescriptor): IssueProject {\n\tconst resourceId = issue.workspaceId ?? workspace.id;\n\tconst resourceName = resourceId === workspace.id ? workspace.name : '';\n\treturn issue.project?.id != null\n\t\t? { id: issue.project.id, name: issue.project.name, resourceId: resourceId, resourceName: resourceName }\n\t\t: { id: resourceId, name: resourceName, resourceId: resourceId, resourceName: resourceName };\n}\n"],"mappings":";;;;;;;;;;;AA0BA,MAAM,WAAW,kBAAkB;AAEnC,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;;AAE/E,MAAM,mBAAmB;;AAEzB,MAAM,oBAAoB;;AAE1B,MAAM,eAAe;AAQrB,IAAa,mBAAb,cAAsC,kBAAsC;CAC3E,eAAqE;CAErE,IAAa,KAAyB;EACrC,OAAO,SAAS;CACjB;CACA,IAAuB,MAAe;EACrC,OAAO;CACR;CACA,IAAa,OAAe;EAC3B,OAAO,SAAS;CACjB;CACA,IAAa,SAAiB;EAC7B,OAAO,SAAS;CACjB;;;;;CAMA,MAAyB,0BACxB,SAC+B;EAC/B,MAAM,UAAU,MAAM,KAAK,aAAa,OAAO;EAC/C,IAAI,WAAW,MACd,KAAK,gBAAgB,IAAI,QAAQ,aAAa,QAAQ,QAAQ,OAAO,CAAC;EAEvE,OAAO;CACR;CAEA,sCACC,SACA,WAC+B;EAC/B,OAAO,KAAK,aAAa,OAAO;CACjC;CAEA,8BACC,SACA,WAC+B;EAC/B,OAAO,KAAK,gBAAgB,YAAY,QAAQ,mBAAmB,KAAK,aAAa,OA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S,yBAAyB,SAAgE;CACjG,OAAO,0BAA0B,OAAO,KAAK,OAAO,QAAQ,eAAe;AAC5E;AAEA,SAAS,eAAe,SAA+C;CACtE,OAAO;EAAE,IAAI,QAAQ;EAAI,MAAM,QAAQ;EAAM,YAAY,QAAQ;EAAY,cAAc,QAAQ;CAAa;AACjH;;;;;;;AAQA,SAAS,oBAAoB,OAAsB,WAAkD;CACpG,MAAM,aAAa,MAAM,eAAe,UAAU;CAClD,MAAM,eAAe,eAAe,UAAU,KAAK,UAAU,OAAO;CACpE,OAAO,MAAM,SAAS,MAAM,OACzB;EAAE,IAAI,MAAM,QAAQ;EAAI,MAAM,MAAM,QAAQ;EAAkB;EAA0B;CAAa,IACrG;EAAE,IAAI;EAAY,MAAM;EAA0B;EAA0B;CAAa;AAC7F"}
@@ -18,9 +18,10 @@ import { azurePullRequestStatusToState, azureWorkItemsStateCategoryToState, enco
18
18
  import { AzureWorkItemDescriptionsCache } from "./workItemDescriptions.js";
19
19
  import { AzureWorkItemStatesCache, getAzureWorkItemTypeStatesPath, getAzureWorkItemTypesUrl, requireAzureWorkItemStateCategories, resolveAzureWorkItemStateCategory } from "./workItemStateCategories.js";
20
20
  import { baseProviderApiConfig } from "../apiConfig.js";
21
- import { createProviderApiRequest, createProviderApis } from "../providerApiClient.js";
21
+ import { createProviderApiRequest } from "../providerApiClient.js";
22
22
  import { queryAzureWorkItemSearch } from "./workItemSearch.js";
23
23
  import * as l10n from "@vscode/l10n";
24
+ import { AzureDevOps } from "@gitkraken/provider-apis";
24
25
  //#region ../plus/integrations/src/providers/azure/azure.ts
25
26
  const forkRepositoryUrlCacheTtl = 3e5;
26
27
  const workItemMetadataConcurrency = 6;
@@ -64,7 +65,7 @@ var AzureDevOpsApi = class {
64
65
  });
65
66
  constructor(config, workItemStates, workItemDescriptions) {
66
67
  this.config = config;
67
- this.restApi = createProviderApis({ request: createProviderApiRequest((input, init) => config.fetch(input, init)) }).azureDevOps;
68
+ this.restApi = new AzureDevOps({ request: createProviderApiRequest((input, init) => config.fetch(input, init)) });
68
69
  this._workItemStates = workItemStates ?? new AzureWorkItemStatesCache();
69
70
  this.ownsWorkItemStates = workItemStates == null;
70
71
  this._workItemDescriptions = workItemDescriptions ?? new AzureWorkItemDescriptionsCache();