@gitkraken/core-gitlens 0.68.0 → 0.70.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 +29 -1
- package/dist/git/providers/diff.d.ts +10 -1
- package/dist/git/providers/status.d.ts +2 -0
- package/dist/git/service.d.ts +5 -1
- package/dist/git/service.js +8 -4
- package/dist/git/service.js.map +1 -1
- package/dist/git/watching/worktreeSummary.d.ts +9 -0
- package/dist/git/watching/worktreeSummary.js +17 -5
- package/dist/git/watching/worktreeSummary.js.map +1 -1
- package/dist/git-cli/cliGitProvider.d.ts +8 -1
- package/dist/git-cli/cliGitProvider.js +14 -3
- package/dist/git-cli/cliGitProvider.js.map +1 -1
- package/dist/git-cli/exec/exec.d.ts +2 -2
- package/dist/git-cli/exec/exec.js +2 -2
- package/dist/git-cli/exec/git.js +4 -3
- package/dist/git-cli/exec/git.js.map +1 -1
- package/dist/git-cli/exec/indexRefresh.d.ts +38 -6
- package/dist/git-cli/exec/indexRefresh.js +84 -3
- package/dist/git-cli/exec/indexRefresh.js.map +1 -1
- package/dist/git-cli/providers/diff.d.ts +4 -1
- package/dist/git-cli/providers/diff.js +17 -1
- package/dist/git-cli/providers/diff.js.map +1 -1
- package/dist/git-cli/providers/status.d.ts +4 -0
- package/dist/git-cli/providers/status.js +113 -16
- package/dist/git-cli/providers/status.js.map +1 -1
- package/dist/git-cli/service.d.ts +13 -1
- package/dist/git-cli/service.js +1 -0
- package/dist/git-cli/service.js.map +1 -1
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +1 -1
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -1
- package/dist/plus/integrations/index.d.ts +2 -1
- package/dist/plus/integrations/index.js +9 -0
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +15 -0
- package/dist/plus/integrations/integrationService.js +35 -4
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +6 -0
- package/dist/plus/integrations/models/asanaTaskWrites.d.ts +155 -0
- package/dist/plus/integrations/models/asanaTaskWrites.js +0 -0
- package/dist/plus/integrations/models/issuesIntegration.d.ts +6 -1
- package/dist/plus/integrations/models/issuesIntegration.js +25 -0
- package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
- package/dist/plus/integrations/providers/asana.d.ts +3 -1
- package/dist/plus/integrations/providers/asana.js +10 -0
- package/dist/plus/integrations/providers/asana.js.map +1 -1
- package/dist/plus/integrations/providers/asanaTaskWriteTransport.d.ts +40 -0
- package/dist/plus/integrations/providers/asanaTaskWriteTransport.js +122 -0
- package/dist/plus/integrations/providers/asanaTaskWriteTransport.js.map +1 -0
- package/dist/plus/integrations/providers/asanaTaskWrites.d.ts +38 -0
- package/dist/plus/integrations/providers/asanaTaskWrites.js +521 -0
- package/dist/plus/integrations/providers/asanaTaskWrites.js.map +1 -0
- package/dist/plus/integrations/providers/trello.js +6 -23
- package/dist/plus/integrations/providers/trello.js.map +1 -1
- package/dist/plus/integrations/providers/trelloCardWriteTransport.d.ts +3 -4
- package/dist/plus/integrations/providers/trelloCardWriteTransport.js +19 -40
- package/dist/plus/integrations/providers/trelloCardWriteTransport.js.map +1 -1
- package/dist/plus/integrations/providers/utils/writeTransport.d.ts +28 -0
- package/dist/plus/integrations/providers/utils/writeTransport.js +60 -0
- package/dist/plus/integrations/providers/utils/writeTransport.js.map +1 -0
- package/dist/utils/env/browser/platform.d.ts +1 -0
- package/dist/utils/env/browser/platform.js +4 -1
- package/dist/utils/env/browser/platform.js.map +1 -1
- package/dist/utils/env/node/exec.d.ts +1 -0
- package/dist/utils/env/node/exec.js +9 -3
- package/dist/utils/env/node/exec.js.map +1 -1
- package/dist/utils/env/node/platform.d.ts +1 -0
- package/dist/utils/env/node/platform.js +4 -1
- package/dist/utils/env/node/platform.js.map +1 -1
- package/dist/utils/platform.d.ts +2 -2
- package/dist/utils/platform.js +2 -2
- package/docs/integrations.md +25 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asana.js","names":[],"sources":["../../../../../plus/integrations/src/providers/asana.ts"],"sourcesContent":["import type { CollectionMetadata, CollectionScopeFailure, IssueProjectMembership } 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 { providersMetadata } from './metadata.js';\nimport type { ProviderApiCollectionResult, ProviderIssue } from './models.js';\nimport { fromProviderIssue, toIssueProviderState, 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 task can be in several projects (a sprint board and each customer's own board, say), and an unscoped task read\n\t * reports only the first one Asana lists as its `project`. So it is filed under every requested project among its\n\t * memberships (`projectMemberships`), with its section in that project as its state, as the per-project fallback\n\t * would list it.\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 task of drain.values) {\n\t\t\tconst shape = toIssueShape(task, this, { projection: 'project' });\n\t\t\tif (shape == null) continue;\n\n\t\t\t// Only the section differs between a task's projects: whether it is closed is the task's own.\n\t\t\tfor (const { index, state } of toRequestedProjectPlacements(task, indexById)) {\n\t\t\t\tsplit[index].push({\n\t\t\t\t\t...shape,\n\t\t\t\t\tproject: toIssueProject(projects[index]),\n\t\t\t\t\tproviderState: toIssueProviderState(state),\n\t\t\t\t});\n\t\t\t}\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\n/**\n * Each requested project a task is in, by its index in the read, with the task's state as that project would list it:\n * its section there, since the unscoped read reports the first membership's.\n */\nfunction toRequestedProjectPlacements(\n\tissue: ProviderIssue,\n\tindexById: ReadonlyMap<string, number>,\n): { index: number; state: ProviderIssue['state'] }[] {\n\tconst memberships = issue.projectMemberships;\n\tif (memberships == null) {\n\t\tconst index = issue.project?.id != null ? indexById.get(issue.project.id) : undefined;\n\t\treturn index != null ? [{ index: index, state: issue.state }] : [];\n\t}\n\n\tconst placements: { index: number; state: ProviderIssue['state'] }[] = [];\n\tfor (const membership of memberships) {\n\t\tconst index = indexById.get(membership.project.id);\n\t\tif (index == null || placements.some(p => p.index === index)) continue;\n\n\t\tplacements.push({ index: index, state: getProjectMembershipState(issue, membership) });\n\t}\n\treturn placements;\n}\n\n/**\n * Mirrors provider-apis' state for a task read scoped to the membership's project; the parity test in `asana.test.ts`\n * runs both through provider-apis' own normalization to keep them agreeing.\n */\nfunction getProjectMembershipState(issue: ProviderIssue, membership: IssueProjectMembership): ProviderIssue['state'] {\n\tif (issue.project?.id === membership.project.id) return issue.state;\n\n\tconst completed = issue.closedDate != null;\n\tif (membership.section != null) {\n\t\treturn {\n\t\t\tid: membership.section.id,\n\t\t\tname: membership.section.name,\n\t\t\tcolor: null,\n\t\t\t...(completed ? { category: 'DONE' as const } : {}),\n\t\t};\n\t}\n\treturn completed ? { name: 'Completed', color: null, category: 'DONE' } : null;\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":";;;;;;;;;;;;AA2BA,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,OAAO,GAAG,EAC9F,YAAW,YAAW,WAAW,KAClC,CAAC;CACF;CAEA,uBAAgD;EAC/C,KAAK,gBAAgB,MAAM;CAC5B;CAEA,kBAAmC,IAAI,aAA0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version":3,"file":"asana.js","names":[],"sources":["../../../../../plus/integrations/src/providers/asana.ts"],"sourcesContent":["import type { CollectionMetadata, CollectionScopeFailure, IssueProjectMembership } 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 { ConfiguredIntegrationDescriptor, 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 { AsanaTaskWriteConnection } from './asanaTaskWriteTransport.js';\nimport { providersMetadata } from './metadata.js';\nimport type { ProviderApiCollectionResult, ProviderIssue } from './models.js';\nimport { fromProviderIssue, toIssueProviderState, 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\tasync getTaskWriteConnection(\n\t\tconnection: ConfiguredIntegrationDescriptor,\n\t\tisSelectionCurrent: () => boolean,\n\t): Promise<AsanaTaskWriteConnection | undefined> {\n\t\tconst pinned = await this.getPinnedWriteSession(connection, isSelectionCurrent);\n\t\tif (pinned == null) return undefined;\n\n\t\treturn {\n\t\t\taccessToken: pinned.session.accessToken,\n\t\t\tscopes: pinned.session.scopes,\n\t\t\tisCurrent: pinned.isCurrent,\n\t\t\tisRetired: pinned.isRetired,\n\t\t};\n\t}\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 task can be in several projects (a sprint board and each customer's own board, say), and an unscoped task read\n\t * reports only the first one Asana lists as its `project`. So it is filed under every requested project among its\n\t * memberships (`projectMemberships`), with its section in that project as its state, as the per-project fallback\n\t * would list it.\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 task of drain.values) {\n\t\t\tconst shape = toIssueShape(task, this, { projection: 'project' });\n\t\t\tif (shape == null) continue;\n\n\t\t\t// Only the section differs between a task's projects: whether it is closed is the task's own.\n\t\t\tfor (const { index, state } of toRequestedProjectPlacements(task, indexById)) {\n\t\t\t\tsplit[index].push({\n\t\t\t\t\t...shape,\n\t\t\t\t\tproject: toIssueProject(projects[index]),\n\t\t\t\t\tproviderState: toIssueProviderState(state),\n\t\t\t\t});\n\t\t\t}\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\n/**\n * Each requested project a task is in, by its index in the read, with the task's state as that project would list it:\n * its section there, since the unscoped read reports the first membership's.\n */\nfunction toRequestedProjectPlacements(\n\tissue: ProviderIssue,\n\tindexById: ReadonlyMap<string, number>,\n): { index: number; state: ProviderIssue['state'] }[] {\n\tconst memberships = issue.projectMemberships;\n\tif (memberships == null) {\n\t\tconst index = issue.project?.id != null ? indexById.get(issue.project.id) : undefined;\n\t\treturn index != null ? [{ index: index, state: issue.state }] : [];\n\t}\n\n\tconst placements: { index: number; state: ProviderIssue['state'] }[] = [];\n\tfor (const membership of memberships) {\n\t\tconst index = indexById.get(membership.project.id);\n\t\tif (index == null || placements.some(p => p.index === index)) continue;\n\n\t\tplacements.push({ index: index, state: getProjectMembershipState(issue, membership) });\n\t}\n\treturn placements;\n}\n\n/**\n * Mirrors provider-apis' state for a task read scoped to the membership's project; the parity test in `asana.test.ts`\n * runs both through provider-apis' own normalization to keep them agreeing.\n */\nfunction getProjectMembershipState(issue: ProviderIssue, membership: IssueProjectMembership): ProviderIssue['state'] {\n\tif (issue.project?.id === membership.project.id) return issue.state;\n\n\tconst completed = issue.closedDate != null;\n\tif (membership.section != null) {\n\t\treturn {\n\t\t\tid: membership.section.id,\n\t\t\tname: membership.section.name,\n\t\t\tcolor: null,\n\t\t\t...(completed ? { category: 'DONE' as const } : {}),\n\t\t};\n\t}\n\treturn completed ? { name: 'Completed', color: null, category: 'DONE' } : null;\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":";;;;;;;;;;;;AA4BA,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,MAAM,uBACL,YACA,oBACgD;EAChD,MAAM,SAAS,MAAM,KAAK,sBAAsB,YAAY,kBAAkB;EAC9E,IAAI,UAAU,MAAM,OAAO,KAAA;EAE3B,OAAO;GACN,aAAa,OAAO,QAAQ;GAC5B,QAAQ,OAAO,QAAQ;GACvB,WAAW,OAAO;GAClB,WAAW,OAAO;EACnB;CACD;CAEA,IAAa,KAAyB;EACrC,OAAO,SAAS;CACjB;CACA,IAAuB,MAAe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,GAAI,YAAY,EAAE,UAAU,OAAgB,IAAI,CAAC;CAClD;CAED,OAAO,YAAY;EAAE,MAAM;EAAa,OAAO;EAAM,UAAU;CAAO,IAAI;AAC3E;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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AsanaTaskWriteFailure } from "../models/asanaTaskWrites.js";
|
|
2
|
+
import { ProviderRequestFunction } from "./models.js";
|
|
3
|
+
import { PinnedWriteConnection, WriteDispatch } from "./utils/writeTransport.js";
|
|
4
|
+
import { Asana } from "@gitkraken/provider-apis";
|
|
5
|
+
//#region ../plus/integrations/src/providers/asanaTaskWriteTransport.d.ts
|
|
6
|
+
type FailureReason = AsanaTaskWriteFailure['reason'];
|
|
7
|
+
export declare class AsanaTaskWriteError extends Error {
|
|
8
|
+
readonly failure: AsanaTaskWriteFailure;
|
|
9
|
+
static is(ex: unknown): ex is AsanaTaskWriteError;
|
|
10
|
+
constructor(reason: FailureReason, dispatch?: WriteDispatch, details?: {
|
|
11
|
+
messages?: readonly string[];
|
|
12
|
+
taskId?: string;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export declare function toAsanaTaskWriteFailure(ex: unknown): AsanaTaskWriteFailure;
|
|
16
|
+
export type AsanaTaskWriteConnection = PinnedWriteConnection & {
|
|
17
|
+
accessToken: string;
|
|
18
|
+
scopes: readonly string[];
|
|
19
|
+
};
|
|
20
|
+
type Envelope<T> = {
|
|
21
|
+
data: T;
|
|
22
|
+
next_page?: {
|
|
23
|
+
offset?: string;
|
|
24
|
+
} | null;
|
|
25
|
+
};
|
|
26
|
+
export declare class AsanaTaskWriteTransport {
|
|
27
|
+
private readonly request;
|
|
28
|
+
private readonly connection;
|
|
29
|
+
private readonly headers;
|
|
30
|
+
private _sdk;
|
|
31
|
+
constructor(request: ProviderRequestFunction, connection: AsanaTaskWriteConnection);
|
|
32
|
+
get scopes(): readonly string[];
|
|
33
|
+
get sdk(): Asana;
|
|
34
|
+
verify(): Promise<void>;
|
|
35
|
+
read<T>(path: string, params?: Record<string, string>): Promise<Envelope<T>>;
|
|
36
|
+
mutate<T>(method: 'POST' | 'PUT' | 'DELETE', path: string, data?: Record<string, unknown>, params?: Record<string, string>): Promise<T | undefined>;
|
|
37
|
+
private send;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//# sourceMappingURL=asanaTaskWriteTransport.d.ts.map
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { isCancellationError } from "../../../utils/cancellation.js";
|
|
2
|
+
import { getProviderGraphQLErrors, getProviderResponseBodyMessage } from "./providerErrors.js";
|
|
3
|
+
import { getWriteErrorStatus, getWriteStatusReason, isPinnedWriteConnectionCurrent, sendPinnedWriteRequest } from "./utils/writeTransport.js";
|
|
4
|
+
import { Asana } from "@gitkraken/provider-apis";
|
|
5
|
+
//#region ../plus/integrations/src/providers/asanaTaskWriteTransport.ts
|
|
6
|
+
const asanaApiUrl = "https://app.asana.com/api/1.0";
|
|
7
|
+
var AsanaTaskWriteError = class AsanaTaskWriteError extends Error {
|
|
8
|
+
failure;
|
|
9
|
+
static is(ex) {
|
|
10
|
+
return ex instanceof AsanaTaskWriteError;
|
|
11
|
+
}
|
|
12
|
+
constructor(reason, dispatch = "none", details) {
|
|
13
|
+
super(reason);
|
|
14
|
+
this.failure = {
|
|
15
|
+
ok: false,
|
|
16
|
+
reason,
|
|
17
|
+
...dispatch === "none" && { mutationDispatched: false },
|
|
18
|
+
...dispatch === "uncertain" && { applied: "maybe" },
|
|
19
|
+
...dispatch === "applied" && { applied: "yes" },
|
|
20
|
+
...details?.messages?.length && { messages: details.messages },
|
|
21
|
+
...dispatch === "applied" && details?.taskId != null && { taskId: details.taskId }
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
function toAsanaTaskWriteFailure(ex) {
|
|
26
|
+
if (AsanaTaskWriteError.is(ex)) return ex.failure;
|
|
27
|
+
return new AsanaTaskWriteError(isCancellationError(ex) ? "no-connection" : getFailureReason(ex)).failure;
|
|
28
|
+
}
|
|
29
|
+
var AsanaTaskWriteTransport = class {
|
|
30
|
+
request;
|
|
31
|
+
connection;
|
|
32
|
+
headers;
|
|
33
|
+
_sdk;
|
|
34
|
+
constructor(request, connection) {
|
|
35
|
+
this.request = request;
|
|
36
|
+
this.connection = connection;
|
|
37
|
+
this.headers = {
|
|
38
|
+
Accept: "application/json",
|
|
39
|
+
Authorization: `Bearer ${connection.accessToken}`
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
get scopes() {
|
|
43
|
+
return this.connection.scopes;
|
|
44
|
+
}
|
|
45
|
+
get sdk() {
|
|
46
|
+
return this._sdk ??= new Asana({
|
|
47
|
+
request: (options) => this.send(options),
|
|
48
|
+
token: this.connection.accessToken
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async verify() {
|
|
52
|
+
if (!await isPinnedWriteConnectionCurrent(this.connection)) throw new AsanaTaskWriteError("no-connection");
|
|
53
|
+
}
|
|
54
|
+
async read(path, params) {
|
|
55
|
+
const response = await this.send({
|
|
56
|
+
url: toUrl(path, params),
|
|
57
|
+
method: "GET"
|
|
58
|
+
});
|
|
59
|
+
if (response.body == null || typeof response.body !== "object") throw new AsanaTaskWriteError("unknown");
|
|
60
|
+
return response.body;
|
|
61
|
+
}
|
|
62
|
+
async mutate(method, path, data, params) {
|
|
63
|
+
return (await this.send({
|
|
64
|
+
url: toUrl(path, params),
|
|
65
|
+
method,
|
|
66
|
+
...data != null && { body: JSON.stringify({ data }) }
|
|
67
|
+
})).body?.data;
|
|
68
|
+
}
|
|
69
|
+
async send(options) {
|
|
70
|
+
if (!options.url.startsWith(`${asanaApiUrl}/`)) throw new AsanaTaskWriteError("invalid-input");
|
|
71
|
+
return sendPinnedWriteRequest(this.request, this.connection, {
|
|
72
|
+
url: options.url,
|
|
73
|
+
method: (options.method ?? "GET").toUpperCase(),
|
|
74
|
+
headers: this.headers,
|
|
75
|
+
body: options.body,
|
|
76
|
+
okStatuses: [200, 201],
|
|
77
|
+
isEvidence: isEnvelope
|
|
78
|
+
}, toDispatchError, (dispatch, response) => new AsanaTaskWriteError("no-connection", dispatch, { taskId: getResponseTaskId(response) }));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
function isEnvelope(body) {
|
|
82
|
+
const data = body?.data;
|
|
83
|
+
return data != null && typeof data === "object" && !Array.isArray(data);
|
|
84
|
+
}
|
|
85
|
+
function getResponseTaskId(response) {
|
|
86
|
+
const gid = (response?.body)?.data?.gid;
|
|
87
|
+
return typeof gid === "string" && /^\d{1,64}$/.test(gid) ? gid : void 0;
|
|
88
|
+
}
|
|
89
|
+
function toDispatchError(ex, dispatch, response) {
|
|
90
|
+
if (dispatch === "applied") return new AsanaTaskWriteError(toAsanaTaskWriteFailure(ex).reason, dispatch, { taskId: getResponseTaskId(response) });
|
|
91
|
+
const reason = ex == null ? "unknown" : getFailureReason(ex);
|
|
92
|
+
return new AsanaTaskWriteError(reason, dispatch === "rejected" && reason === "unknown" ? "uncertain" : dispatch, reason === "invalid-input" ? { messages: getProviderMessages(ex) } : void 0);
|
|
93
|
+
}
|
|
94
|
+
function toUrl(path, params) {
|
|
95
|
+
const url = new URL(`${asanaApiUrl}/${path}`);
|
|
96
|
+
for (const [key, value] of Object.entries(params ?? {})) url.searchParams.set(key, value);
|
|
97
|
+
return url.toString();
|
|
98
|
+
}
|
|
99
|
+
function getProviderMessages(ex) {
|
|
100
|
+
const body = ex?.response?.body;
|
|
101
|
+
return getProviderGraphQLErrors(body).map((error) => error.message).filter((message) => typeof message === "string" && message.length !== 0);
|
|
102
|
+
}
|
|
103
|
+
function getFailureReason(ex) {
|
|
104
|
+
const reason = getWriteStatusReason(ex);
|
|
105
|
+
if (reason != null) return reason;
|
|
106
|
+
switch (getWriteErrorStatus(ex)) {
|
|
107
|
+
case 401: return "no-connection";
|
|
108
|
+
case 402: return "payment-required";
|
|
109
|
+
case 403: {
|
|
110
|
+
const error = ex;
|
|
111
|
+
const challenge = error?.response?.headers?.["www-authenticate"] ?? "";
|
|
112
|
+
const message = getProviderResponseBodyMessage(error?.response?.body) ?? "";
|
|
113
|
+
return /\binsufficient[_ -]scope\b/i.test(challenge) || /\b(?:missing|requires?|required|insufficient)\b[^.]*\bscopes?\b|\bscopes?\b[^.]*\b(?:missing|required|must be present)\b/i.test(message) ? "insufficient-scope" : "forbidden";
|
|
114
|
+
}
|
|
115
|
+
case 451: return "legal-block";
|
|
116
|
+
default: return "unknown";
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
export { AsanaTaskWriteError, AsanaTaskWriteTransport, toAsanaTaskWriteFailure };
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=asanaTaskWriteTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asanaTaskWriteTransport.js","names":[],"sources":["../../../../../plus/integrations/src/providers/asanaTaskWriteTransport.ts"],"sourcesContent":["import { Asana } from '@gitkraken/provider-apis';\nimport { isCancellationError } from '@gitlens/utils/cancellation.js';\nimport type { AsanaTaskWriteFailure } from '../models/asanaTaskWrites.js';\nimport type { ProviderRequestFunction, ProviderRequestOptions, ProviderRequestResponse } from './models.js';\nimport { getProviderGraphQLErrors, getProviderResponseBodyMessage } from './providerErrors.js';\nimport type { PinnedWriteConnection, ProviderErrorLike, WriteDispatch } from './utils/writeTransport.js';\nimport {\n\tgetWriteErrorStatus,\n\tgetWriteStatusReason,\n\tisPinnedWriteConnectionCurrent,\n\tsendPinnedWriteRequest,\n} from './utils/writeTransport.js';\n\nconst asanaApiUrl = 'https://app.asana.com/api/1.0';\n\ntype FailureReason = AsanaTaskWriteFailure['reason'];\n\nexport class AsanaTaskWriteError extends Error {\n\treadonly failure: AsanaTaskWriteFailure;\n\n\tstatic is(ex: unknown): ex is AsanaTaskWriteError {\n\t\treturn ex instanceof AsanaTaskWriteError;\n\t}\n\n\tconstructor(\n\t\treason: FailureReason,\n\t\tdispatch: WriteDispatch = 'none',\n\t\tdetails?: { messages?: readonly string[]; taskId?: string },\n\t) {\n\t\tsuper(reason);\n\t\tthis.failure = {\n\t\t\tok: false,\n\t\t\treason: reason,\n\t\t\t...(dispatch === 'none' && { mutationDispatched: false }),\n\t\t\t...(dispatch === 'uncertain' && { applied: 'maybe' }),\n\t\t\t...(dispatch === 'applied' && { applied: 'yes' }),\n\t\t\t...(details?.messages?.length && { messages: details.messages }),\n\t\t\t...(dispatch === 'applied' && details?.taskId != null && { taskId: details.taskId }),\n\t\t};\n\t}\n}\n\nexport function toAsanaTaskWriteFailure(ex: unknown): AsanaTaskWriteFailure {\n\tif (AsanaTaskWriteError.is(ex)) return ex.failure;\n\n\treturn new AsanaTaskWriteError(isCancellationError(ex) ? 'no-connection' : getFailureReason(ex)).failure;\n}\n\nexport type AsanaTaskWriteConnection = PinnedWriteConnection & {\n\taccessToken: string;\n\tscopes: readonly string[];\n};\n\ntype Envelope<T> = { data: T; next_page?: { offset?: string } | null };\n\nexport class AsanaTaskWriteTransport {\n\tprivate readonly headers: Record<string, string>;\n\tprivate _sdk: Asana | undefined;\n\n\tconstructor(\n\t\tprivate readonly request: ProviderRequestFunction,\n\t\tprivate readonly connection: AsanaTaskWriteConnection,\n\t) {\n\t\tthis.headers = { Accept: 'application/json', Authorization: `Bearer ${connection.accessToken}` };\n\t}\n\n\tget scopes(): readonly string[] {\n\t\treturn this.connection.scopes;\n\t}\n\n\tget sdk(): Asana {\n\t\treturn (this._sdk ??= new Asana({\n\t\t\trequest: <T>(options: ProviderRequestOptions) => this.send<T>(options),\n\t\t\ttoken: this.connection.accessToken,\n\t\t}));\n\t}\n\n\tasync verify(): Promise<void> {\n\t\tif (!(await isPinnedWriteConnectionCurrent(this.connection))) throw new AsanaTaskWriteError('no-connection');\n\t}\n\n\tasync read<T>(path: string, params?: Record<string, string>): Promise<Envelope<T>> {\n\t\tconst response = await this.send<Envelope<T>>({ url: toUrl(path, params), method: 'GET' });\n\t\tif (response.body == null || typeof response.body !== 'object') throw new AsanaTaskWriteError('unknown');\n\n\t\treturn response.body;\n\t}\n\n\tasync mutate<T>(\n\t\tmethod: 'POST' | 'PUT' | 'DELETE',\n\t\tpath: string,\n\t\tdata?: Record<string, unknown>,\n\t\tparams?: Record<string, string>,\n\t): Promise<T | undefined> {\n\t\tconst response = await this.send<Envelope<T>>({\n\t\t\turl: toUrl(path, params),\n\t\t\tmethod: method,\n\t\t\t...(data != null && { body: JSON.stringify({ data: data }) }),\n\t\t});\n\t\treturn response.body?.data;\n\t}\n\n\tprivate async send<T>(options: ProviderRequestOptions): Promise<ProviderRequestResponse<T>> {\n\t\tif (!options.url.startsWith(`${asanaApiUrl}/`)) throw new AsanaTaskWriteError('invalid-input');\n\n\t\treturn sendPinnedWriteRequest<T, AsanaTaskWriteError>(\n\t\t\tthis.request,\n\t\t\tthis.connection,\n\t\t\t{\n\t\t\t\turl: options.url,\n\t\t\t\tmethod: (options.method ?? 'GET').toUpperCase(),\n\t\t\t\theaders: this.headers,\n\t\t\t\tbody: options.body,\n\t\t\t\tokStatuses: [200, 201],\n\t\t\t\tisEvidence: isEnvelope,\n\t\t\t},\n\t\t\ttoDispatchError,\n\t\t\t(dispatch, response) =>\n\t\t\t\tnew AsanaTaskWriteError('no-connection', dispatch, { taskId: getResponseTaskId(response) }),\n\t\t);\n\t}\n}\n\nfunction isEnvelope(body: unknown): boolean {\n\tconst data: unknown = (body as { data?: unknown } | null | undefined)?.data;\n\treturn data != null && typeof data === 'object' && !Array.isArray(data);\n}\n\nfunction getResponseTaskId(response: ProviderRequestResponse<unknown> | undefined): string | undefined {\n\tconst gid = (response?.body as Envelope<{ gid?: unknown }> | null | undefined)?.data?.gid;\n\treturn typeof gid === 'string' && /^\\d{1,64}$/.test(gid) ? gid : undefined;\n}\n\nfunction toDispatchError(\n\tex: unknown,\n\tdispatch: WriteDispatch,\n\tresponse?: ProviderRequestResponse<unknown>,\n): AsanaTaskWriteError {\n\tif (dispatch === 'applied') {\n\t\treturn new AsanaTaskWriteError(toAsanaTaskWriteFailure(ex).reason, dispatch, {\n\t\t\ttaskId: getResponseTaskId(response),\n\t\t});\n\t}\n\n\tconst reason = ex == null ? 'unknown' : getFailureReason(ex);\n\treturn new AsanaTaskWriteError(\n\t\treason,\n\t\tdispatch === 'rejected' && reason === 'unknown' ? 'uncertain' : dispatch,\n\t\treason === 'invalid-input' ? { messages: getProviderMessages(ex) } : undefined,\n\t);\n}\n\nfunction toUrl(path: string, params?: Record<string, string>): string {\n\tconst url = new URL(`${asanaApiUrl}/${path}`);\n\tfor (const [key, value] of Object.entries(params ?? {})) {\n\t\turl.searchParams.set(key, value);\n\t}\n\n\treturn url.toString();\n}\n\nfunction getProviderMessages(ex: unknown): string[] {\n\tconst body = (ex as ProviderErrorLike)?.response?.body;\n\treturn getProviderGraphQLErrors(body)\n\t\t.map(error => error.message)\n\t\t.filter((message): message is string => typeof message === 'string' && message.length !== 0);\n}\n\nfunction getFailureReason(ex: unknown): FailureReason {\n\tconst reason = getWriteStatusReason(ex);\n\tif (reason != null) return reason;\n\n\tswitch (getWriteErrorStatus(ex)) {\n\t\tcase 401:\n\t\t\treturn 'no-connection';\n\t\tcase 402:\n\t\t\treturn 'payment-required';\n\t\tcase 403: {\n\t\t\tconst error = ex as ProviderErrorLike;\n\t\t\tconst challenge = error?.response?.headers?.['www-authenticate'] ?? '';\n\t\t\tconst message = getProviderResponseBodyMessage(error?.response?.body) ?? '';\n\t\t\treturn /\\binsufficient[_ -]scope\\b/i.test(challenge) ||\n\t\t\t\t/\\b(?:missing|requires?|required|insufficient)\\b[^.]*\\bscopes?\\b|\\bscopes?\\b[^.]*\\b(?:missing|required|must be present)\\b/i.test(\n\t\t\t\t\tmessage,\n\t\t\t\t)\n\t\t\t\t? 'insufficient-scope'\n\t\t\t\t: 'forbidden';\n\t\t}\n\t\tcase 451:\n\t\t\treturn 'legal-block';\n\t\tdefault:\n\t\t\treturn 'unknown';\n\t}\n}\n"],"mappings":";;;;;AAaA,MAAM,cAAc;AAIpB,IAAa,sBAAb,MAAa,4BAA4B,MAAM;CAC9C;CAEA,OAAO,GAAG,IAAwC;EACjD,OAAO,cAAc;CACtB;CAEA,YACC,QACA,WAA0B,QAC1B,SACC;EACD,MAAM,MAAM;EACZ,KAAK,UAAU;GACd,IAAI;GACI;GACR,GAAI,aAAa,UAAU,EAAE,oBAAoB,MAAM;GACvD,GAAI,aAAa,eAAe,EAAE,SAAS,QAAQ;GACnD,GAAI,aAAa,aAAa,EAAE,SAAS,MAAM;GAC/C,GAAI,SAAS,UAAU,UAAU,EAAE,UAAU,QAAQ,SAAS;GAC9D,GAAI,aAAa,aAAa,SAAS,UAAU,QAAQ,EAAE,QAAQ,QAAQ,OAAO;EACnF;CACD;AACD;AAEA,SAAgB,wBAAwB,IAAoC;CAC3E,IAAI,oBAAoB,GAAG,EAAE,GAAG,OAAO,GAAG;CAE1C,OAAO,IAAI,oBAAoB,oBAAoB,EAAE,IAAI,kBAAkB,iBAAiB,EAAE,CAAC,CAAC,CAAC;AAClG;AASA,IAAa,0BAAb,MAAqC;CAKlB;CACA;CALlB;CACA;CAEA,YACC,SACA,YACC;EAFgB,KAAA,UAAA;EACA,KAAA,aAAA;EAEjB,KAAK,UAAU;GAAE,QAAQ;GAAoB,eAAe,UAAU,WAAW;EAAc;CAChG;CAEA,IAAI,SAA4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AAK;GACzE,OAAO,8BAA8B,KAAK,SAAS,KAClD,4HAA4H,KAC3H,OACD,IACE,uBACA;EACJ;EACA,KAAK,KACJ,OAAO;EACR,SACC,OAAO;CACT;AACD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AsanaTaskCreateOptions, AsanaTaskCreateOptionsResult, AsanaTaskDeleteOptions, AsanaTaskDeleteResult, AsanaTaskWriteOptions, AsanaTaskWriteOptionsResult, AsanaTaskWriteResult, AsanaTaskWriteScope, AsanaTaskWriteTargetOptions } from "../models/asanaTaskWrites.js";
|
|
2
|
+
import { AsanaTaskWriteTransport } from "./asanaTaskWriteTransport.js";
|
|
3
|
+
//#region ../plus/integrations/src/providers/asanaTaskWrites.d.ts
|
|
4
|
+
type Context = Awaited<ReturnType<AsanaTaskWriter['getContext']>>;
|
|
5
|
+
type ResolvedTarget = Extract<AsanaTaskWriteOptionsResult, {
|
|
6
|
+
ok: true;
|
|
7
|
+
}>;
|
|
8
|
+
type TaskReference = {
|
|
9
|
+
taskId: string;
|
|
10
|
+
workspaceId?: string;
|
|
11
|
+
projectId?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function isAsanaTaskWriteScope(scope: AsanaTaskWriteScope, mutation: boolean): boolean;
|
|
14
|
+
export declare function parseAsanaTaskReference(value: unknown): TaskReference | undefined;
|
|
15
|
+
export declare class AsanaTaskWriter {
|
|
16
|
+
private readonly transport;
|
|
17
|
+
private readonly activeWrites;
|
|
18
|
+
constructor(transport: AsanaTaskWriteTransport, activeWrites: Set<string>);
|
|
19
|
+
verify(): Promise<void>;
|
|
20
|
+
getAccount(options: AsanaTaskWriteScope): Promise<Context>;
|
|
21
|
+
getCreateOptions(options: AsanaTaskCreateOptions): Promise<AsanaTaskCreateOptionsResult>;
|
|
22
|
+
resolveTarget(options: AsanaTaskWriteTargetOptions): Promise<ResolvedTarget>;
|
|
23
|
+
private resolve;
|
|
24
|
+
write(options: AsanaTaskWriteOptions): Promise<AsanaTaskWriteResult>;
|
|
25
|
+
delete(options: AsanaTaskDeleteOptions): Promise<AsanaTaskDeleteResult>;
|
|
26
|
+
private create;
|
|
27
|
+
private resolveMutationTarget;
|
|
28
|
+
private readBack;
|
|
29
|
+
private getContext;
|
|
30
|
+
private getTask;
|
|
31
|
+
private getWorkspace;
|
|
32
|
+
private getProject;
|
|
33
|
+
private getSections;
|
|
34
|
+
private readAll;
|
|
35
|
+
private withTaskMutation;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//# sourceMappingURL=asanaTaskWrites.d.ts.map
|