@gitkraken/core-gitlens 0.68.0 → 0.69.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 (37) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +1 -1
  3. package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -1
  4. package/dist/plus/integrations/index.d.ts +2 -1
  5. package/dist/plus/integrations/index.js +9 -0
  6. package/dist/plus/integrations/index.js.map +1 -1
  7. package/dist/plus/integrations/integrationService.d.ts +15 -0
  8. package/dist/plus/integrations/integrationService.js +35 -4
  9. package/dist/plus/integrations/integrationService.js.map +1 -1
  10. package/dist/plus/integrations/manager.d.ts +6 -0
  11. package/dist/plus/integrations/models/asanaTaskWrites.d.ts +155 -0
  12. package/dist/plus/integrations/models/asanaTaskWrites.js +0 -0
  13. package/dist/plus/integrations/models/issuesIntegration.d.ts +6 -1
  14. package/dist/plus/integrations/models/issuesIntegration.js +25 -0
  15. package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
  16. package/dist/plus/integrations/models/publicIntegration.d.ts +1 -0
  17. package/dist/plus/integrations/providers/asana.d.ts +3 -1
  18. package/dist/plus/integrations/providers/asana.js +10 -0
  19. package/dist/plus/integrations/providers/asana.js.map +1 -1
  20. package/dist/plus/integrations/providers/asanaTaskWriteTransport.d.ts +40 -0
  21. package/dist/plus/integrations/providers/asanaTaskWriteTransport.js +122 -0
  22. package/dist/plus/integrations/providers/asanaTaskWriteTransport.js.map +1 -0
  23. package/dist/plus/integrations/providers/asanaTaskWrites.d.ts +38 -0
  24. package/dist/plus/integrations/providers/asanaTaskWrites.js +521 -0
  25. package/dist/plus/integrations/providers/asanaTaskWrites.js.map +1 -0
  26. package/dist/plus/integrations/providers/issueSorts.d.ts +1 -0
  27. package/dist/plus/integrations/providers/trello.js +6 -23
  28. package/dist/plus/integrations/providers/trello.js.map +1 -1
  29. package/dist/plus/integrations/providers/trelloCardWriteTransport.d.ts +3 -4
  30. package/dist/plus/integrations/providers/trelloCardWriteTransport.js +19 -40
  31. package/dist/plus/integrations/providers/trelloCardWriteTransport.js.map +1 -1
  32. package/dist/plus/integrations/providers/utils/writeTransport.d.ts +28 -0
  33. package/dist/plus/integrations/providers/utils/writeTransport.js +60 -0
  34. package/dist/plus/integrations/providers/utils/writeTransport.js.map +1 -0
  35. package/dist/plus/integrations/reads/drains.d.ts +1 -0
  36. package/docs/integrations.md +25 -0
  37. package/package.json +1 -1
@@ -4,7 +4,6 @@ import { IntegrationReadUnavailableError } from "../errors.js";
4
4
  import "../constants.js";
5
5
  import { providersMetadata } from "./metadata.js";
6
6
  import { toTokenWithInfo } from "../authentication/models.js";
7
- import { ObservedAuthenticationProvider } from "../authentication/observedAuthenticationProvider.js";
8
7
  import { fromProviderIssue, toIssueShape } from "./models.js";
9
8
  import { IssuesIntegration } from "../models/issuesIntegration.js";
10
9
  //#region ../plus/integrations/src/providers/trello.ts
@@ -18,30 +17,14 @@ const recentAccountTTL = 6e4;
18
17
  var TrelloIntegration = class extends IssuesIntegration {
19
18
  authProvider = authProvider;
20
19
  async getCardWriteConnection(connection, isSelectionCurrent) {
21
- if (!isSelectionCurrent()) return void 0;
22
- const { id, cloud } = connection;
23
- const provider = await this.authenticationService.get(this.id);
24
- const capture = provider instanceof ObservedAuthenticationProvider ? provider.captureRelationshipSession({
25
- ...this.authProviderDescriptor,
26
- connectionId: id,
27
- cloud
28
- }) : void 0;
29
- const session = await this.resolveReadSessionOrThrow(id, void 0, cloud);
30
- if (session?.id !== id || session.cloud !== cloud || !session.accessToken) return void 0;
31
- const appKey = this.appKeyFor(session);
32
- if (!appKey) return void 0;
33
- const tracked = this.trackWriteSession(session, {
34
- cloud,
35
- observeHostChanges: true
36
- });
37
- const currency = capture?.(session) ?? await this.authenticationService.trackStoredRelationshipSession(this.id, session, { throwOnLookupError: true });
38
- if (currency == null) return void 0;
39
- const isRetired = () => !isSelectionCurrent() || !this.isIntegrationAccessEnabled() || tracked.isRetired() || !currency.isCurrent();
20
+ const pinned = await this.getPinnedWriteSession(connection, isSelectionCurrent, (session) => Boolean(this.appKeyFor(session)));
21
+ const appKey = pinned != null ? this.appKeyFor(pinned.session) : void 0;
22
+ if (pinned == null || !appKey) return void 0;
40
23
  return {
41
24
  appKey,
42
- accessToken: session.accessToken,
43
- isCurrent: currency.verify,
44
- isRetired
25
+ accessToken: pinned.session.accessToken,
26
+ isCurrent: pinned.isCurrent,
27
+ isRetired: pinned.isRetired
45
28
  };
46
29
  }
47
30
  get id() {
@@ -1 +1 @@
1
- {"version":3,"file":"trello.js","names":[],"sources":["../../../../../plus/integrations/src/providers/trello.ts"],"sourcesContent":["import type { Account } from '@gitlens/git/models/author.js';\nimport type { Issue, 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 { 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 { ObservedAuthenticationProvider } from '../authentication/observedAuthenticationProvider.js';\nimport { IssuesCloudHostIntegrationId } from '../constants.js';\nimport { IntegrationReadUnavailableError } from '../errors.js';\nimport type { IssuesForProjectOptions, ProjectIssuesDrain } from '../models/issueReads.js';\nimport { IssuesIntegration } from '../models/issuesIntegration.js';\nimport { providersMetadata } from './metadata.js';\nimport { fromProviderIssue, toIssueShape } from './models.js';\nimport type { TrelloCardWriteConnection } from './trelloCardWriteTransport.js';\n\nconst metadata = providersMetadata[IssuesCloudHostIntegrationId.Trello];\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\n/** A Trello board, surfaced as both a \"resource\" (org analogue) and a \"project\" for issue reads. */\nexport interface TrelloBoardDescriptor extends IssueResourceDescriptor {}\n\nexport class TrelloIntegration extends IssuesIntegration<IssuesCloudHostIntegrationId.Trello> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\n\tasync getCardWriteConnection(\n\t\tconnection: ConfiguredIntegrationDescriptor,\n\t\tisSelectionCurrent: () => boolean,\n\t): Promise<TrelloCardWriteConnection | undefined> {\n\t\tif (!isSelectionCurrent()) return undefined;\n\n\t\tconst { id, cloud } = connection;\n\t\tconst provider = await this.authenticationService.get(this.id);\n\t\tconst capture =\n\t\t\tprovider instanceof ObservedAuthenticationProvider\n\t\t\t\t? provider.captureRelationshipSession({\n\t\t\t\t\t\t...this.authProviderDescriptor,\n\t\t\t\t\t\tconnectionId: id,\n\t\t\t\t\t\tcloud: cloud,\n\t\t\t\t\t})\n\t\t\t\t: undefined;\n\t\tconst session = await this.resolveReadSessionOrThrow(id, undefined, cloud);\n\t\tif (session?.id !== id || session.cloud !== cloud || !session.accessToken) return undefined;\n\n\t\tconst appKey = this.appKeyFor(session);\n\t\tif (!appKey) return undefined;\n\n\t\tconst tracked = this.trackWriteSession(session, { cloud: cloud, observeHostChanges: true });\n\t\tconst currency =\n\t\t\tcapture?.(session) ??\n\t\t\t(await this.authenticationService.trackStoredRelationshipSession(this.id, session, {\n\t\t\t\tthrowOnLookupError: true,\n\t\t\t}));\n\t\tif (currency == null) return undefined;\n\n\t\tconst isRetired = () =>\n\t\t\t!isSelectionCurrent() || !this.isIntegrationAccessEnabled() || tracked.isRetired() || !currency.isCurrent();\n\t\treturn { appKey: appKey, accessToken: session.accessToken, isCurrent: currency.verify, isRetired: isRetired };\n\t}\n\n\toverride get id(): IssuesCloudHostIntegrationId.Trello {\n\t\treturn IssuesCloudHostIntegrationId.Trello;\n\t}\n\tprotected override get key(): 'trello' {\n\t\treturn 'trello';\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/** The Trello client requires the app key paired with the token; a session without one can't read. */\n\tprivate appKeyFor(session: ProviderAuthenticationSession): string | undefined {\n\t\treturn session.appKey;\n\t}\n\n\t/**\n\t * Resolves the app key or throws — a session that authenticated but carries no app key can't read Trello,\n\t * and must be surfaced as a broken read (warning + fetchFailed) rather than an empty account.\n\t */\n\tprivate requireAppKey(session: ProviderAuthenticationSession): string {\n\t\tconst appKey = this.appKeyFor(session);\n\t\tif (appKey == null) {\n\t\t\tthrow new IntegrationReadUnavailableError(metadata.name, 'missing app key (session has no appKey)');\n\t\t}\n\t\treturn appKey;\n\t}\n\n\t/**\n\t * Always asks Trello: the host's current-account cache decides when this runs. The member lookup is\n\t * account-wide, so the answer is lent briefly to the per-board 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, this.requireAppKey(session));\n\t}\n\n\tprotected override async getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\tconst appKey = this.requireAppKey(session);\n\t\treturn this._recentAccounts.getOrCreate(session.accessToken, () => this.fetchAccount(session, appKey), {\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(\n\t\tsession: ProviderAuthenticationSession,\n\t\tappKey: string = this.requireAppKey(session),\n\t): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api.getTrelloCurrentUser(toTokenWithInfo(this.id, session), appKey);\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,\n\t\t\tusername: user.username,\n\t\t\temail: user.email,\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<TrelloBoardDescriptor[] | undefined> {\n\t\tconst appKey = this.requireAppKey(session);\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst boards = await api.getTrelloBoardsForCurrentUser(toTokenWithInfo(this.id, session), appKey);\n\t\treturn boards?.map(b => ({ key: b.id, id: b.id, name: b.name }));\n\t}\n\n\tprotected override getProviderProjectsForResources(\n\t\t_session: ProviderAuthenticationSession,\n\t\tresources: ResourceDescriptor[],\n\t): Promise<TrelloBoardDescriptor[] | undefined> {\n\t\t// Trello boards are both the resource and the project scope, so projects are the boards themselves.\n\t\treturn Promise.resolve(\n\t\t\tresources.filter(isIssueResourceDescriptor).map(r => ({ key: r.key, id: r.id, name: r.name })),\n\t\t);\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\tprotected override async getProviderIssuesForProjectWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: ResourceDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<ProjectIssuesDrain | undefined> {\n\t\t// A non-issue descriptor genuinely has nothing to read (empty), but a missing app key is a broken read.\n\t\tif (!isIssueResourceDescriptor(project)) return undefined;\n\n\t\t// The board read always excludes archived cards, and a card has no other state, so only open cards can be\n\t\t// read. Refused rather than ignored: answering `closed` with the open cards would publish them as closed.\n\t\tif (options?.state != null && options.state !== 'open') {\n\t\t\tthrow new IntegrationReadUnavailableError(metadata.name, `issue state '${options.state}' is not supported`);\n\t\t}\n\n\t\tconst appKey = this.requireAppKey(session);\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\n\t\t// Enrich issues with their board list names (card status), mirroring gitkraken.dev's Trello reads.\n\t\tconst lists = await api.getTrelloListsForBoard(tokenWithInfo, appKey, project.id);\n\t\tconst trelloBoardListsById = lists?.reduce<Record<string, { name: string }>>((acc, list) => {\n\t\t\tacc[list.id] = { name: list.name };\n\t\t\treturn acc;\n\t\t}, {});\n\t\tconst boardProject = {\n\t\t\tid: project.id,\n\t\t\tname: project.name,\n\t\t\tresourceId: project.id,\n\t\t\tresourceName: project.name,\n\t\t};\n\n\t\tconst result = await api.getTrelloIssuesForBoard(tokenWithInfo, appKey, project.id, {\n\t\t\tassigneeLogins: options?.user != null ? [options.user] : undefined,\n\t\t\ttrelloBoardListsById: trelloBoardListsById,\n\t\t\tsort: options?.sort,\n\t\t});\n\n\t\tconst values = result.values.flatMap(issue => {\n\t\t\tconst mapped = toIssueShape(issue, this, { projection: 'project' });\n\t\t\treturn mapped == null ? [] : [{ ...mapped, project: boardProject } satisfies IssueShape];\n\t\t});\n\n\t\t// Trello's search caps results and reports the cap through `metadata.completeness` (partial/unknown),\n\t\t// never a cursor. Surface that as terminal truncation; there is no next page to fetch, so retrying the\n\t\t// same read cannot recover the omitted cards (D11).\n\t\tconst truncated = result.metadata != null && result.metadata.completeness !== 'complete';\n\t\treturn truncated\n\t\t\t? { values: values, truncated: true, recovery: 'none', metadata: result.metadata }\n\t\t\t: { values: values, truncated: false, metadata: result.metadata };\n\t}\n\n\tprotected override searchProviderMyIssues(\n\t\t_session: ProviderAuthenticationSession,\n\t\t_resources?: ResourceDescriptor[],\n\t\t_cancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\t// Trello has no cross-board \"issues assigned to me\" endpoint; issues are read per board via\n\t\t// getIssuesForProject. Callers that need them enumerate boards first.\n\t\treturn Promise.resolve(undefined);\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\treturn Promise.resolve(undefined);\n\t}\n\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 appKey = this.requireAppKey(session);\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst lists = await api.getTrelloListsForBoard(tokenWithInfo, appKey, resource.id);\n\t\tconst trelloBoardListsById = lists?.reduce<Record<string, { name: string }>>((acc, list) => {\n\t\t\tacc[list.id] = { name: list.name };\n\t\t\treturn acc;\n\t\t}, {});\n\n\t\t// Branch-association round-trips use the encoded entity identifier's stable Trello card id. Resolve that\n\t\t// directly so large boards don't require a capped whole-board scan; keep a numeric idShort fallback so\n\t\t// legacy/manual callers that still pass the board-local display number continue to resolve.\n\t\tlet issue = await api.getTrelloCard(tokenWithInfo, appKey, id, {\n\t\t\ttrelloBoardListsById: trelloBoardListsById,\n\t\t});\n\t\tif (issue == null && /^[0-9]+$/.test(id)) {\n\t\t\tissue = (\n\t\t\t\tawait api.getTrelloIssuesForBoard(tokenWithInfo, appKey, resource.id, {\n\t\t\t\t\ttrelloBoardListsById: trelloBoardListsById,\n\t\t\t\t})\n\t\t\t).values.find(issue => issue.number === id);\n\t\t}\n\n\t\treturn issue != null\n\t\t\t? fromProviderIssue(issue, this, {\n\t\t\t\t\tprojection: 'point',\n\t\t\t\t\tproject: {\n\t\t\t\t\t\tid: resource.id,\n\t\t\t\t\t\tname: resource.name,\n\t\t\t\t\t\tresourceId: resource.id,\n\t\t\t\t\t\tresourceName: resource.name,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t: undefined;\n\t}\n}\n"],"mappings":";;;;;;;;;;AAkBA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;;AAE/E,MAAM,mBAAmB;AAKzB,IAAa,oBAAb,cAAuC,kBAAuD;CAC7F,eAAqE;CAErE,MAAM,uBACL,YACA,oBACiD;EACjD,IAAI,CAAC,mBAAmB,GAAG,OAAO,KAAA;EAElC,MAAM,EAAE,IAAI,UAAU;EACtB,MAAM,WAAW,MAAM,KAAK,sBAAsB,IAAI,KAAK,EAAE;EAC7D,MAAM,UACL,oBAAoB,iCACjB,SAAS,2BAA2B;GACpC,GAAG,KAAK;GACR,cAAc;GACP;EACR,CAAC,IACA,KAAA;EACJ,MAAM,UAAU,MAAM,KAAK,0BAA0B,IAAI,KAAA,GAAW,KAAK;EACzE,IAAI,SAAS,OAAO,MAAM,QAAQ,UAAU,SAAS,CAAC,QAAQ,aAAa,OAAO,KAAA;EAElF,MAAM,SAAS,KAAK,UAAU,OAAO;EACrC,IAAI,CAAC,QAAQ,OAAO,KAAA;EAEpB,MAAM,UAAU,KAAK,kBAAkB,SAAS;GAAS;GAAO,oBAAoB;EAAK,CAAC;EAC1F,MAAM,WACL,UAAU,OAAO,KAChB,MAAM,KAAK,sBAAsB,+BAA+B,KAAK,IAAI,SAAS,EAClF,oBAAoB,KACrB,CAAC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I,QAAQ,MAAM,IAAI,cAAc,eAAe,QAAQ,IAAI,EACxC,qBACvB,CAAC;EACD,IAAI,SAAS,QAAQ,WAAW,KAAK,EAAE,GACtC,SACC,MAAM,IAAI,wBAAwB,eAAe,QAAQ,SAAS,IAAI,EAC/C,qBACvB,CAAC,EAAA,CACA,OAAO,MAAK,UAAS,MAAM,WAAW,EAAE;EAG3C,OAAO,SAAS,OACb,kBAAkB,OAAO,MAAM;GAC/B,YAAY;GACZ,SAAS;IACR,IAAI,SAAS;IACb,MAAM,SAAS;IACf,YAAY,SAAS;IACrB,cAAc,SAAS;GACxB;EACD,CAAC,IACA,KAAA;CACJ;AACD"}
1
+ {"version":3,"file":"trello.js","names":[],"sources":["../../../../../plus/integrations/src/providers/trello.ts"],"sourcesContent":["import type { Account } from '@gitlens/git/models/author.js';\nimport type { Issue, 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 { 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 { IssuesCloudHostIntegrationId } from '../constants.js';\nimport { IntegrationReadUnavailableError } from '../errors.js';\nimport type { IssuesForProjectOptions, ProjectIssuesDrain } from '../models/issueReads.js';\nimport { IssuesIntegration } from '../models/issuesIntegration.js';\nimport { providersMetadata } from './metadata.js';\nimport { fromProviderIssue, toIssueShape } from './models.js';\nimport type { TrelloCardWriteConnection } from './trelloCardWriteTransport.js';\n\nconst metadata = providersMetadata[IssuesCloudHostIntegrationId.Trello];\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\n/** A Trello board, surfaced as both a \"resource\" (org analogue) and a \"project\" for issue reads. */\nexport interface TrelloBoardDescriptor extends IssueResourceDescriptor {}\n\nexport class TrelloIntegration extends IssuesIntegration<IssuesCloudHostIntegrationId.Trello> {\n\treadonly authProvider: IntegrationAuthenticationProviderDescriptor = authProvider;\n\n\tasync getCardWriteConnection(\n\t\tconnection: ConfiguredIntegrationDescriptor,\n\t\tisSelectionCurrent: () => boolean,\n\t): Promise<TrelloCardWriteConnection | undefined> {\n\t\tconst pinned = await this.getPinnedWriteSession(connection, isSelectionCurrent, session =>\n\t\t\tBoolean(this.appKeyFor(session)),\n\t\t);\n\t\tconst appKey = pinned != null ? this.appKeyFor(pinned.session) : undefined;\n\t\tif (pinned == null || !appKey) return undefined;\n\n\t\treturn {\n\t\t\tappKey: appKey,\n\t\t\taccessToken: pinned.session.accessToken,\n\t\t\tisCurrent: pinned.isCurrent,\n\t\t\tisRetired: pinned.isRetired,\n\t\t};\n\t}\n\n\toverride get id(): IssuesCloudHostIntegrationId.Trello {\n\t\treturn IssuesCloudHostIntegrationId.Trello;\n\t}\n\tprotected override get key(): 'trello' {\n\t\treturn 'trello';\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/** The Trello client requires the app key paired with the token; a session without one can't read. */\n\tprivate appKeyFor(session: ProviderAuthenticationSession): string | undefined {\n\t\treturn session.appKey;\n\t}\n\n\t/**\n\t * Resolves the app key or throws — a session that authenticated but carries no app key can't read Trello,\n\t * and must be surfaced as a broken read (warning + fetchFailed) rather than an empty account.\n\t */\n\tprivate requireAppKey(session: ProviderAuthenticationSession): string {\n\t\tconst appKey = this.appKeyFor(session);\n\t\tif (appKey == null) {\n\t\t\tthrow new IntegrationReadUnavailableError(metadata.name, 'missing app key (session has no appKey)');\n\t\t}\n\t\treturn appKey;\n\t}\n\n\t/**\n\t * Always asks Trello: the host's current-account cache decides when this runs. The member lookup is\n\t * account-wide, so the answer is lent briefly to the per-board 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, this.requireAppKey(session));\n\t}\n\n\tprotected override async getProviderAccountForResource(\n\t\tsession: ProviderAuthenticationSession,\n\t\t_resource: ResourceDescriptor,\n\t): Promise<Account | undefined> {\n\t\tconst appKey = this.requireAppKey(session);\n\t\treturn this._recentAccounts.getOrCreate(session.accessToken, () => this.fetchAccount(session, appKey), {\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(\n\t\tsession: ProviderAuthenticationSession,\n\t\tappKey: string = this.requireAppKey(session),\n\t): Promise<Account | undefined> {\n\t\tconst api = await this.getProvidersApi();\n\t\tconst user = await api.getTrelloCurrentUser(toTokenWithInfo(this.id, session), appKey);\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,\n\t\t\tusername: user.username,\n\t\t\temail: user.email,\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<TrelloBoardDescriptor[] | undefined> {\n\t\tconst appKey = this.requireAppKey(session);\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst boards = await api.getTrelloBoardsForCurrentUser(toTokenWithInfo(this.id, session), appKey);\n\t\treturn boards?.map(b => ({ key: b.id, id: b.id, name: b.name }));\n\t}\n\n\tprotected override getProviderProjectsForResources(\n\t\t_session: ProviderAuthenticationSession,\n\t\tresources: ResourceDescriptor[],\n\t): Promise<TrelloBoardDescriptor[] | undefined> {\n\t\t// Trello boards are both the resource and the project scope, so projects are the boards themselves.\n\t\treturn Promise.resolve(\n\t\t\tresources.filter(isIssueResourceDescriptor).map(r => ({ key: r.key, id: r.id, name: r.name })),\n\t\t);\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\tprotected override async getProviderIssuesForProjectWithTruncation(\n\t\tsession: ProviderAuthenticationSession,\n\t\tproject: ResourceDescriptor,\n\t\toptions?: IssuesForProjectOptions,\n\t): Promise<ProjectIssuesDrain | undefined> {\n\t\t// A non-issue descriptor genuinely has nothing to read (empty), but a missing app key is a broken read.\n\t\tif (!isIssueResourceDescriptor(project)) return undefined;\n\n\t\t// The board read always excludes archived cards, and a card has no other state, so only open cards can be\n\t\t// read. Refused rather than ignored: answering `closed` with the open cards would publish them as closed.\n\t\tif (options?.state != null && options.state !== 'open') {\n\t\t\tthrow new IntegrationReadUnavailableError(metadata.name, `issue state '${options.state}' is not supported`);\n\t\t}\n\n\t\tconst appKey = this.requireAppKey(session);\n\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\n\t\t// Enrich issues with their board list names (card status), mirroring gitkraken.dev's Trello reads.\n\t\tconst lists = await api.getTrelloListsForBoard(tokenWithInfo, appKey, project.id);\n\t\tconst trelloBoardListsById = lists?.reduce<Record<string, { name: string }>>((acc, list) => {\n\t\t\tacc[list.id] = { name: list.name };\n\t\t\treturn acc;\n\t\t}, {});\n\t\tconst boardProject = {\n\t\t\tid: project.id,\n\t\t\tname: project.name,\n\t\t\tresourceId: project.id,\n\t\t\tresourceName: project.name,\n\t\t};\n\n\t\tconst result = await api.getTrelloIssuesForBoard(tokenWithInfo, appKey, project.id, {\n\t\t\tassigneeLogins: options?.user != null ? [options.user] : undefined,\n\t\t\ttrelloBoardListsById: trelloBoardListsById,\n\t\t\tsort: options?.sort,\n\t\t});\n\n\t\tconst values = result.values.flatMap(issue => {\n\t\t\tconst mapped = toIssueShape(issue, this, { projection: 'project' });\n\t\t\treturn mapped == null ? [] : [{ ...mapped, project: boardProject } satisfies IssueShape];\n\t\t});\n\n\t\t// Trello's search caps results and reports the cap through `metadata.completeness` (partial/unknown),\n\t\t// never a cursor. Surface that as terminal truncation; there is no next page to fetch, so retrying the\n\t\t// same read cannot recover the omitted cards (D11).\n\t\tconst truncated = result.metadata != null && result.metadata.completeness !== 'complete';\n\t\treturn truncated\n\t\t\t? { values: values, truncated: true, recovery: 'none', metadata: result.metadata }\n\t\t\t: { values: values, truncated: false, metadata: result.metadata };\n\t}\n\n\tprotected override searchProviderMyIssues(\n\t\t_session: ProviderAuthenticationSession,\n\t\t_resources?: ResourceDescriptor[],\n\t\t_cancellation?: AbortSignal,\n\t): Promise<IssueShape[] | undefined> {\n\t\t// Trello has no cross-board \"issues assigned to me\" endpoint; issues are read per board via\n\t\t// getIssuesForProject. Callers that need them enumerate boards first.\n\t\treturn Promise.resolve(undefined);\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\treturn Promise.resolve(undefined);\n\t}\n\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 appKey = this.requireAppKey(session);\n\t\tconst api = await this.getProvidersApi();\n\t\tconst tokenWithInfo = toTokenWithInfo(this.id, session);\n\t\tconst lists = await api.getTrelloListsForBoard(tokenWithInfo, appKey, resource.id);\n\t\tconst trelloBoardListsById = lists?.reduce<Record<string, { name: string }>>((acc, list) => {\n\t\t\tacc[list.id] = { name: list.name };\n\t\t\treturn acc;\n\t\t}, {});\n\n\t\t// Branch-association round-trips use the encoded entity identifier's stable Trello card id. Resolve that\n\t\t// directly so large boards don't require a capped whole-board scan; keep a numeric idShort fallback so\n\t\t// legacy/manual callers that still pass the board-local display number continue to resolve.\n\t\tlet issue = await api.getTrelloCard(tokenWithInfo, appKey, id, {\n\t\t\ttrelloBoardListsById: trelloBoardListsById,\n\t\t});\n\t\tif (issue == null && /^[0-9]+$/.test(id)) {\n\t\t\tissue = (\n\t\t\t\tawait api.getTrelloIssuesForBoard(tokenWithInfo, appKey, resource.id, {\n\t\t\t\t\ttrelloBoardListsById: trelloBoardListsById,\n\t\t\t\t})\n\t\t\t).values.find(issue => issue.number === id);\n\t\t}\n\n\t\treturn issue != null\n\t\t\t? fromProviderIssue(issue, this, {\n\t\t\t\t\tprojection: 'point',\n\t\t\t\t\tproject: {\n\t\t\t\t\t\tid: resource.id,\n\t\t\t\t\t\tname: resource.name,\n\t\t\t\t\t\tresourceId: resource.id,\n\t\t\t\t\t\tresourceName: resource.name,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t: undefined;\n\t}\n}\n"],"mappings":";;;;;;;;;AAiBA,MAAM,WAAW,kBAAA;AACjB,MAAM,eAAe,OAAO,OAAO;CAAE,IAAI,SAAS;CAAI,QAAQ,SAAS;AAAO,CAAC;;AAE/E,MAAM,m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B,MADT,IAAI,uBAAuB,eAAe,QAAQ,SAAS,EAAE,EAAA,EAC7C,QAA0C,KAAK,SAAS;GAC3F,IAAI,KAAK,MAAM,EAAE,MAAM,KAAK,KAAK;GACjC,OAAO;EACR,GAAG,CAAC,CAAC;EAKL,IAAI,QAAQ,MAAM,IAAI,cAAc,eAAe,QAAQ,IAAI,EACxC,qBACvB,CAAC;EACD,IAAI,SAAS,QAAQ,WAAW,KAAK,EAAE,GACtC,SACC,MAAM,IAAI,wBAAwB,eAAe,QAAQ,SAAS,IAAI,EAC/C,qBACvB,CAAC,EAAA,CACA,OAAO,MAAK,UAAS,MAAM,WAAW,EAAE;EAG3C,OAAO,SAAS,OACb,kBAAkB,OAAO,MAAM;GAC/B,YAAY;GACZ,SAAS;IACR,IAAI,SAAS;IACb,MAAM,SAAS;IACf,YAAY,SAAS;IACrB,cAAc,SAAS;GACxB;EACD,CAAC,IACA,KAAA;CACJ;AACD"}
@@ -1,18 +1,17 @@
1
1
  import { TrelloCardWriteFailure } from "../models/trelloCardWrites.js";
2
2
  import { ProviderRequestFunction } from "./models.js";
3
+ import { PinnedWriteConnection, WriteDispatch } from "./utils/writeTransport.js";
3
4
  //#region ../plus/integrations/src/providers/trelloCardWriteTransport.d.ts
4
5
  type FailureReason = TrelloCardWriteFailure['reason'];
5
6
  export declare class TrelloCardWriteError extends Error {
6
7
  readonly failure: TrelloCardWriteFailure;
7
8
  static is(ex: unknown): ex is TrelloCardWriteError;
8
- constructor(reason: FailureReason, dispatch?: 'none' | 'rejected' | 'uncertain');
9
+ constructor(reason: FailureReason, dispatch?: Exclude<WriteDispatch, 'applied'>);
9
10
  }
10
11
  export declare function toTrelloCardWriteFailure(ex: unknown): TrelloCardWriteFailure;
11
- export type TrelloCardWriteConnection = {
12
+ export type TrelloCardWriteConnection = PinnedWriteConnection & {
12
13
  appKey: string;
13
14
  accessToken: string;
14
- isCurrent: () => Promise<boolean>;
15
- isRetired: () => boolean;
16
15
  };
17
16
  export declare class TrelloCardWriteTransport {
18
17
  private readonly request;
@@ -1,6 +1,6 @@
1
1
  import { isCancellationError } from "../../../utils/cancellation.js";
2
- import { RequestRateLimitError } from "../../../git/errors.js";
3
2
  import { getProviderResponseBodyMessage } from "./providerErrors.js";
3
+ import { getWriteErrorStatus, getWriteStatusReason, isPinnedWriteConnectionCurrent, sendPinnedWriteRequest } from "./utils/writeTransport.js";
4
4
  import { getTrelloAuthHeaders, trelloBaseUrl } from "./trelloApi.js";
5
5
  //#region ../plus/integrations/src/providers/trelloCardWriteTransport.ts
6
6
  var TrelloCardWriteError = class TrelloCardWriteError extends Error {
@@ -32,61 +32,40 @@ var TrelloCardWriteTransport = class {
32
32
  this.headers = getTrelloAuthHeaders(connection.appKey, connection.accessToken);
33
33
  }
34
34
  async verify() {
35
- if (this.connection.isRetired() || !await this.connection.isCurrent() || this.connection.isRetired()) throw new TrelloCardWriteError("no-connection");
35
+ if (!await isPinnedWriteConnectionCurrent(this.connection)) throw new TrelloCardWriteError("no-connection");
36
36
  }
37
37
  async read(path) {
38
38
  return (await this.send("GET", path)).body;
39
39
  }
40
40
  async mutate(method, path, data) {
41
- const response = await this.send(method, path, data == null ? void 0 : JSON.stringify(data));
42
- if (response.status !== 200 && (method !== "DELETE" || response.status !== 204)) throw new TrelloCardWriteError("unknown", "uncertain");
43
- try {
44
- await this.verify();
45
- } catch (ex) {
46
- throw new TrelloCardWriteError(toTrelloCardWriteFailure(ex).reason, "uncertain");
47
- }
48
- return response.body;
41
+ return (await this.send(method, path, data == null ? void 0 : JSON.stringify(data))).body;
49
42
  }
50
- async send(method, path, body) {
51
- await this.verify();
52
- if (this.connection.isRetired()) throw new TrelloCardWriteError("no-connection");
53
- const mutation = method !== "GET";
54
- try {
55
- return await this.request({
56
- url: `${trelloBaseUrl}/1/${path}`,
57
- method,
58
- redirect: "error",
59
- credentials: "omit",
60
- signal: AbortSignal.timeout(3e4),
61
- headers: body == null ? this.headers : {
62
- ...this.headers,
63
- "Content-Type": "application/json"
64
- },
65
- body
66
- });
67
- } catch (ex) {
68
- const reason = getFailureReason(ex);
69
- throw new TrelloCardWriteError(reason, mutation ? reason === "unknown" ? "uncertain" : "rejected" : "none");
70
- }
43
+ send(method, path, body) {
44
+ return sendPinnedWriteRequest(this.request, this.connection, {
45
+ url: `${trelloBaseUrl}/1/${path}`,
46
+ method,
47
+ headers: this.headers,
48
+ body,
49
+ okStatuses: method === "DELETE" ? [200, 204] : [200]
50
+ }, toDispatchError, (dispatch) => new TrelloCardWriteError("no-connection", dispatch === "applied" ? "uncertain" : dispatch));
71
51
  }
72
52
  };
53
+ function toDispatchError(ex, dispatch) {
54
+ if (dispatch === "applied") return new TrelloCardWriteError(toTrelloCardWriteFailure(ex).reason, "uncertain");
55
+ const reason = ex == null ? "unknown" : getFailureReason(ex);
56
+ return new TrelloCardWriteError(reason, dispatch === "rejected" && reason === "unknown" ? "uncertain" : dispatch);
57
+ }
73
58
  function getFailureReason(ex) {
74
- if (RequestRateLimitError.is(ex)) return "rate-limit";
75
- const error = ex;
76
- const status = error?.response?.status ?? error?.statusCode;
59
+ const status = getWriteErrorStatus(ex);
77
60
  if (status === 401 || status === 403) {
61
+ const error = ex;
78
62
  const reason = getProviderResponseBodyMessage(error?.response?.body) ?? "";
79
63
  const challenge = error?.response?.headers?.["www-authenticate"] ?? "";
80
64
  if (/\binsufficient[_ -]scope\b/i.test(challenge)) return "insufficient-scope";
81
65
  if (status === 403 || /\bunauthorized (?:board |card |list )?permission requested\b/i.test(reason)) return "forbidden";
82
66
  return "no-connection";
83
67
  }
84
- if (status === 404) return "not-found";
85
- if (status === 400 || status === 413 || status === 414 || status === 415 || status === 422) return "invalid-input";
86
- if (status === 405) return "unsupported";
87
- if (status === 409) return "conflict";
88
- if (status === 429) return "rate-limit";
89
- return "unknown";
68
+ return getWriteStatusReason(ex) ?? "unknown";
90
69
  }
91
70
  //#endregion
92
71
  export { TrelloCardWriteError, TrelloCardWriteTransport, toTrelloCardWriteFailure };
@@ -1 +1 @@
1
- {"version":3,"file":"trelloCardWriteTransport.js","names":[],"sources":["../../../../../plus/integrations/src/providers/trelloCardWriteTransport.ts"],"sourcesContent":["import { RequestRateLimitError } from '@gitlens/git/errors.js';\nimport { isCancellationError } from '@gitlens/utils/cancellation.js';\nimport type { TrelloCardWriteFailure } from '../models/trelloCardWrites.js';\nimport type { ProviderRequestFunction, ProviderRequestResponse } from './models.js';\nimport { getProviderResponseBodyMessage } from './providerErrors.js';\nimport { getTrelloAuthHeaders, trelloBaseUrl } from './trelloApi.js';\n\ntype FailureReason = TrelloCardWriteFailure['reason'];\n\nexport class TrelloCardWriteError extends Error {\n\treadonly failure: TrelloCardWriteFailure;\n\n\tstatic is(ex: unknown): ex is TrelloCardWriteError {\n\t\treturn ex instanceof TrelloCardWriteError;\n\t}\n\n\tconstructor(reason: FailureReason, dispatch: 'none' | 'rejected' | 'uncertain' = 'none') {\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};\n\t}\n}\n\nexport function toTrelloCardWriteFailure(ex: unknown): TrelloCardWriteFailure {\n\tif (TrelloCardWriteError.is(ex)) return ex.failure;\n\n\treturn new TrelloCardWriteError(isCancellationError(ex) ? 'no-connection' : getFailureReason(ex)).failure;\n}\n\nexport type TrelloCardWriteConnection = {\n\tappKey: string;\n\taccessToken: string;\n\tisCurrent: () => Promise<boolean>;\n\tisRetired: () => boolean;\n};\n\nexport class TrelloCardWriteTransport {\n\tprivate readonly headers: Record<string, string>;\n\n\tconstructor(\n\t\tprivate readonly request: ProviderRequestFunction,\n\t\tprivate readonly connection: TrelloCardWriteConnection,\n\t) {\n\t\tthis.headers = getTrelloAuthHeaders(connection.appKey, connection.accessToken);\n\t}\n\n\tasync verify(): Promise<void> {\n\t\tif (this.connection.isRetired() || !(await this.connection.isCurrent()) || this.connection.isRetired()) {\n\t\t\tthrow new TrelloCardWriteError('no-connection');\n\t\t}\n\t}\n\n\tasync read<T>(path: string): Promise<T> {\n\t\treturn (await this.send<T>('GET', path)).body;\n\t}\n\n\tasync mutate<T>(\n\t\tmethod: 'POST' | 'PUT' | 'DELETE',\n\t\tpath: string,\n\t\tdata?: Record<string, string | boolean | undefined>,\n\t): Promise<T> {\n\t\tconst response = await this.send<T>(method, path, data == null ? undefined : JSON.stringify(data));\n\t\tif (response.status !== 200 && (method !== 'DELETE' || response.status !== 204)) {\n\t\t\tthrow new TrelloCardWriteError('unknown', 'uncertain');\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.verify();\n\t\t} catch (ex) {\n\t\t\tthrow new TrelloCardWriteError(toTrelloCardWriteFailure(ex).reason, 'uncertain');\n\t\t}\n\n\t\treturn response.body;\n\t}\n\n\tprivate async send<T>(\n\t\tmethod: 'GET' | 'POST' | 'PUT' | 'DELETE',\n\t\tpath: string,\n\t\tbody?: string,\n\t): Promise<ProviderRequestResponse<T>> {\n\t\tawait this.verify();\n\t\tif (this.connection.isRetired()) throw new TrelloCardWriteError('no-connection');\n\n\t\tconst mutation = method !== 'GET';\n\t\ttry {\n\t\t\treturn await this.request<T>({\n\t\t\t\turl: `${trelloBaseUrl}/1/${path}`,\n\t\t\t\tmethod: method,\n\t\t\t\tredirect: 'error',\n\t\t\t\tcredentials: 'omit',\n\t\t\t\tsignal: AbortSignal.timeout(30_000),\n\t\t\t\theaders: body == null ? this.headers : { ...this.headers, 'Content-Type': 'application/json' },\n\t\t\t\tbody: body,\n\t\t\t});\n\t\t} catch (ex) {\n\t\t\tconst reason = getFailureReason(ex);\n\t\t\tthrow new TrelloCardWriteError(\n\t\t\t\treason,\n\t\t\t\tmutation ? (reason === 'unknown' ? 'uncertain' : 'rejected') : 'none',\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction getFailureReason(ex: unknown): FailureReason {\n\tif (RequestRateLimitError.is(ex)) return 'rate-limit';\n\n\tconst error = ex as {\n\t\tstatusCode?: number;\n\t\tresponse?: { status?: number; body?: unknown; headers?: Record<string, string> };\n\t} | null;\n\tconst status = error?.response?.status ?? error?.statusCode;\n\tif (status === 401 || status === 403) {\n\t\tconst reason = getProviderResponseBodyMessage(error?.response?.body) ?? '';\n\t\tconst challenge = error?.response?.headers?.['www-authenticate'] ?? '';\n\t\tif (/\\binsufficient[_ -]scope\\b/i.test(challenge)) return 'insufficient-scope';\n\t\tif (status === 403 || /\\bunauthorized (?:board |card |list )?permission requested\\b/i.test(reason)) {\n\t\t\treturn 'forbidden';\n\t\t}\n\n\t\treturn 'no-connection';\n\t}\n\tif (status === 404) return 'not-found';\n\tif (status === 400 || status === 413 || status === 414 || status === 415 || status === 422) return 'invalid-input';\n\tif (status === 405) return 'unsupported';\n\tif (status === 409) return 'conflict';\n\tif (status === 429) return 'rate-limit';\n\n\treturn 'unknown';\n}\n"],"mappings":";;;;;AASA,IAAa,uBAAb,MAAa,6BAA6B,MAAM;CAC/C;CAEA,OAAO,GAAG,IAAyC;EAClD,OAAO,cAAc;CACtB;CAEA,YAAY,QAAuB,WAA8C,QAAQ;EACxF,MAAM,MAAM;EACZ,KAAK,UAAU;GACd,IAAI;GACI;GACR,GAAI,aAAa,UAAU,EAAE,oBAAoB,MAAM;GACvD,GAAI,aAAa,eAAe,EAAE,SAAS,QAAQ;EACpD;CACD;AACD;AAEA,SAAgB,yBAAyB,IAAqC;CAC7E,IAAI,qBAAqB,GAAG,EAAE,GAAG,OAAO,GAAG;CAE3C,OAAO,IAAI,qBAAqB,oBAAoB,EAAE,IAAI,kBAAkB,iBAAiB,EAAE,CAAC,CAAC,CAAC;AACnG;AASA,IAAa,2BAAb,MAAsC;CAInB;CACA;CAJlB;CAEA,YACC,SACA,YACC;EAFgB,KAAA,UAAA;EACA,KAAA,aAAA;EAEjB,KAAK,UAAU,qBAAqB,WAAW,QAAQ,WAAW,WAAW;CAC9E;CAEA,MAAM,SAAwB;EAC7B,IAAI,KAAK,WAAW,UAAU,KAA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ACrC,MAAM,SAAS,+BAA+B,OAAO,UAAU,IAAI,KAAK;EACxE,MAAM,YAAY,OAAO,UAAU,UAAU,uBAAuB;EACpE,IAAI,8BAA8B,KAAK,SAAS,GAAG,OAAO;EAC1D,IAAI,WAAW,OAAO,gEAAgE,KAAK,MAAM,GAChG,OAAO;EAGR,OAAO;CACR;CACA,IAAI,WAAW,KAAK,OAAO;CAC3B,IAAI,WAAW,OAAO,WAAW,OAAO,WAAW,OAAO,WAAW,OAAO,WAAW,KAAK,OAAO;CACnG,IAAI,WAAW,KAAK,OAAO;CAC3B,IAAI,WAAW,KAAK,OAAO;CAC3B,IAAI,WAAW,KAAK,OAAO;CAE3B,OAAO;AACR"}
1
+ {"version":3,"file":"trelloCardWriteTransport.js","names":[],"sources":["../../../../../plus/integrations/src/providers/trelloCardWriteTransport.ts"],"sourcesContent":["import { isCancellationError } from '@gitlens/utils/cancellation.js';\nimport type { TrelloCardWriteFailure } from '../models/trelloCardWrites.js';\nimport type { ProviderRequestFunction, ProviderRequestResponse } from './models.js';\nimport { getProviderResponseBodyMessage } from './providerErrors.js';\nimport { getTrelloAuthHeaders, trelloBaseUrl } from './trelloApi.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\ntype FailureReason = TrelloCardWriteFailure['reason'];\n\nexport class TrelloCardWriteError extends Error {\n\treadonly failure: TrelloCardWriteFailure;\n\n\tstatic is(ex: unknown): ex is TrelloCardWriteError {\n\t\treturn ex instanceof TrelloCardWriteError;\n\t}\n\n\tconstructor(reason: FailureReason, dispatch: Exclude<WriteDispatch, 'applied'> = 'none') {\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};\n\t}\n}\n\nexport function toTrelloCardWriteFailure(ex: unknown): TrelloCardWriteFailure {\n\tif (TrelloCardWriteError.is(ex)) return ex.failure;\n\n\treturn new TrelloCardWriteError(isCancellationError(ex) ? 'no-connection' : getFailureReason(ex)).failure;\n}\n\nexport type TrelloCardWriteConnection = PinnedWriteConnection & {\n\tappKey: string;\n\taccessToken: string;\n};\n\nexport class TrelloCardWriteTransport {\n\tprivate readonly headers: Record<string, string>;\n\n\tconstructor(\n\t\tprivate readonly request: ProviderRequestFunction,\n\t\tprivate readonly connection: TrelloCardWriteConnection,\n\t) {\n\t\tthis.headers = getTrelloAuthHeaders(connection.appKey, connection.accessToken);\n\t}\n\n\tasync verify(): Promise<void> {\n\t\tif (!(await isPinnedWriteConnectionCurrent(this.connection))) throw new TrelloCardWriteError('no-connection');\n\t}\n\n\tasync read<T>(path: string): Promise<T> {\n\t\treturn (await this.send<T>('GET', path)).body;\n\t}\n\n\tasync mutate<T>(\n\t\tmethod: 'POST' | 'PUT' | 'DELETE',\n\t\tpath: string,\n\t\tdata?: Record<string, string | boolean | undefined>,\n\t): Promise<T> {\n\t\tconst response = await this.send<T>(method, path, data == null ? undefined : JSON.stringify(data));\n\t\treturn response.body;\n\t}\n\n\tprivate send<T>(\n\t\tmethod: 'GET' | 'POST' | 'PUT' | 'DELETE',\n\t\tpath: string,\n\t\tbody?: string,\n\t): Promise<ProviderRequestResponse<T>> {\n\t\treturn sendPinnedWriteRequest<T, TrelloCardWriteError>(\n\t\t\tthis.request,\n\t\t\tthis.connection,\n\t\t\t{\n\t\t\t\turl: `${trelloBaseUrl}/1/${path}`,\n\t\t\t\tmethod: method,\n\t\t\t\theaders: this.headers,\n\t\t\t\tbody: body,\n\t\t\t\tokStatuses: method === 'DELETE' ? [200, 204] : [200],\n\t\t\t},\n\t\t\ttoDispatchError,\n\t\t\tdispatch => new TrelloCardWriteError('no-connection', dispatch === 'applied' ? 'uncertain' : dispatch),\n\t\t);\n\t}\n}\n\nfunction toDispatchError(ex: unknown, dispatch: WriteDispatch): TrelloCardWriteError {\n\tif (dispatch === 'applied') return new TrelloCardWriteError(toTrelloCardWriteFailure(ex).reason, 'uncertain');\n\n\tconst reason = ex == null ? 'unknown' : getFailureReason(ex);\n\treturn new TrelloCardWriteError(reason, dispatch === 'rejected' && reason === 'unknown' ? 'uncertain' : dispatch);\n}\n\nfunction getFailureReason(ex: unknown): FailureReason {\n\tconst status = getWriteErrorStatus(ex);\n\tif (status === 401 || status === 403) {\n\t\tconst error = ex as ProviderErrorLike;\n\t\tconst reason = getProviderResponseBodyMessage(error?.response?.body) ?? '';\n\t\tconst challenge = error?.response?.headers?.['www-authenticate'] ?? '';\n\t\tif (/\\binsufficient[_ -]scope\\b/i.test(challenge)) return 'insufficient-scope';\n\t\tif (status === 403 || /\\bunauthorized (?:board |card |list )?permission requested\\b/i.test(reason)) {\n\t\t\treturn 'forbidden';\n\t\t}\n\n\t\treturn 'no-connection';\n\t}\n\n\treturn getWriteStatusReason(ex) ?? 'unknown';\n}\n"],"mappings":";;;;;AAeA,IAAa,uBAAb,MAAa,6BAA6B,MAAM;CAC/C;CAEA,OAAO,GAAG,IAAyC;EAClD,OAAO,cAAc;CACtB;CAEA,YAAY,QAAuB,WAA8C,QAAQ;EACxF,MAAM,MAAM;EACZ,KAAK,UAAU;GACd,IAAI;GACI;GACR,GAAI,aAAa,UAAU,EAAE,oBAAoB,MAAM;GACvD,GAAI,aAAa,eAAe,EAAE,SAAS,QAAQ;EACpD;CACD;AACD;AAEA,SAAgB,yBAAyB,IAAqC;CAC7E,IAAI,qBAAqB,GAAG,EAAE,GAAG,OAAO,GAAG;CAE3C,OAAO,IAAI,qBAAqB,oBAAoB,EAAE,IAAI,kBAAkB,iBAAiB,EAAE,CAAC,CAAC,CAAC;AACnG;AAOA,IAAa,2BAAb,MAAsC;CAInB;CACA;CAJlB;CAEA,YACC,SACA,YACC;EAFgB,KAAA,UAAA;EACA,KAA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O;EAGR,OAAO;CACR;CAEA,OAAO,qBAAqB,EAAE,KAAK;AACpC"}
@@ -0,0 +1,28 @@
1
+ import { ProviderRequestFunction, ProviderRequestResponse } from "../models.js";
2
+ //#region ../plus/integrations/src/providers/utils/writeTransport.d.ts
3
+ export type WriteDispatch = 'none' | 'rejected' | 'uncertain' | 'applied';
4
+ export type PinnedWriteConnection = {
5
+ isCurrent: () => Promise<boolean>;
6
+ isRetired: () => boolean;
7
+ };
8
+ export type ProviderErrorLike = {
9
+ statusCode?: number;
10
+ response?: {
11
+ status?: number;
12
+ body?: unknown;
13
+ headers?: Record<string, string>;
14
+ };
15
+ } | null;
16
+ export declare function getWriteErrorStatus(ex: unknown): number | undefined;
17
+ export declare function getWriteStatusReason(ex: unknown): 'invalid-input' | 'not-found' | 'unsupported' | 'conflict' | 'rate-limit' | 'unknown' | undefined;
18
+ export declare function isPinnedWriteConnectionCurrent(connection: PinnedWriteConnection): Promise<boolean>;
19
+ export declare function sendPinnedWriteRequest<T, E extends Error>(request: ProviderRequestFunction, connection: PinnedWriteConnection, options: {
20
+ url: string;
21
+ method: string;
22
+ headers: Record<string, string>;
23
+ body?: string;
24
+ okStatuses: readonly number[];
25
+ isEvidence?: (body: T) => boolean;
26
+ }, toError: (ex: unknown, dispatch: WriteDispatch, response?: ProviderRequestResponse<T>) => E, noConnection: (dispatch: WriteDispatch, response?: ProviderRequestResponse<T>) => E): Promise<ProviderRequestResponse<T>>;
27
+ //#endregion
28
+ //# sourceMappingURL=writeTransport.d.ts.map
@@ -0,0 +1,60 @@
1
+ import { RequestRateLimitError } from "../../../../git/errors.js";
2
+ //#region ../plus/integrations/src/providers/utils/writeTransport.ts
3
+ function getWriteErrorStatus(ex) {
4
+ const error = ex;
5
+ return error?.response?.status ?? error?.statusCode;
6
+ }
7
+ function getWriteStatusReason(ex) {
8
+ if (RequestRateLimitError.is(ex)) return "rate-limit";
9
+ switch (getWriteErrorStatus(ex)) {
10
+ case 400:
11
+ case 413:
12
+ case 414:
13
+ case 415:
14
+ case 422: return "invalid-input";
15
+ case 404: return "not-found";
16
+ case 405: return "unsupported";
17
+ case 409: return "conflict";
18
+ case 429: return "rate-limit";
19
+ default: return;
20
+ }
21
+ }
22
+ async function isPinnedWriteConnectionCurrent(connection) {
23
+ return !connection.isRetired() && await connection.isCurrent() && !connection.isRetired();
24
+ }
25
+ async function sendPinnedWriteRequest(request, connection, options, toError, noConnection) {
26
+ if (!await isPinnedWriteConnectionCurrent(connection)) throw noConnection("none");
27
+ if (connection.isRetired()) throw noConnection("none");
28
+ const mutation = options.method !== "GET";
29
+ let response;
30
+ try {
31
+ response = await request({
32
+ url: options.url,
33
+ method: options.method,
34
+ redirect: "error",
35
+ credentials: "omit",
36
+ signal: AbortSignal.timeout(3e4),
37
+ headers: options.body == null ? options.headers : {
38
+ ...options.headers,
39
+ "Content-Type": "application/json"
40
+ },
41
+ body: options.body
42
+ });
43
+ } catch (ex) {
44
+ throw toError(ex, mutation ? "rejected" : "none");
45
+ }
46
+ if (!mutation) return response;
47
+ if (!options.okStatuses.includes(response.status) || options.isEvidence?.(response.body) === false) throw toError(void 0, "uncertain");
48
+ let current;
49
+ try {
50
+ current = await isPinnedWriteConnectionCurrent(connection);
51
+ } catch (ex) {
52
+ throw toError(ex, "applied", response);
53
+ }
54
+ if (!current) throw noConnection("applied", response);
55
+ return response;
56
+ }
57
+ //#endregion
58
+ export { getWriteErrorStatus, getWriteStatusReason, isPinnedWriteConnectionCurrent, sendPinnedWriteRequest };
59
+
60
+ //# sourceMappingURL=writeTransport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeTransport.js","names":[],"sources":["../../../../../../plus/integrations/src/providers/utils/writeTransport.ts"],"sourcesContent":["import { RequestRateLimitError } from '@gitlens/git/errors.js';\nimport type { ProviderRequestFunction, ProviderRequestResponse } from '../models.js';\n\nexport type WriteDispatch = 'none' | 'rejected' | 'uncertain' | 'applied';\n\nexport type PinnedWriteConnection = {\n\tisCurrent: () => Promise<boolean>;\n\tisRetired: () => boolean;\n};\n\nexport type ProviderErrorLike = {\n\tstatusCode?: number;\n\tresponse?: { status?: number; body?: unknown; headers?: Record<string, string> };\n} | null;\n\nexport function getWriteErrorStatus(ex: unknown): number | undefined {\n\tconst error = ex as ProviderErrorLike;\n\treturn error?.response?.status ?? error?.statusCode;\n}\n\nexport function getWriteStatusReason(\n\tex: unknown,\n): 'invalid-input' | 'not-found' | 'unsupported' | 'conflict' | 'rate-limit' | 'unknown' | undefined {\n\tif (RequestRateLimitError.is(ex)) return 'rate-limit';\n\n\tswitch (getWriteErrorStatus(ex)) {\n\t\tcase 400:\n\t\tcase 413:\n\t\tcase 414:\n\t\tcase 415:\n\t\tcase 422:\n\t\t\treturn 'invalid-input';\n\t\tcase 404:\n\t\t\treturn 'not-found';\n\t\tcase 405:\n\t\t\treturn 'unsupported';\n\t\tcase 409:\n\t\t\treturn 'conflict';\n\t\tcase 429:\n\t\t\treturn 'rate-limit';\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nexport async function isPinnedWriteConnectionCurrent(connection: PinnedWriteConnection): Promise<boolean> {\n\treturn !connection.isRetired() && (await connection.isCurrent()) && !connection.isRetired();\n}\n\nexport async function sendPinnedWriteRequest<T, E extends Error>(\n\trequest: ProviderRequestFunction,\n\tconnection: PinnedWriteConnection,\n\toptions: {\n\t\turl: string;\n\t\tmethod: string;\n\t\theaders: Record<string, string>;\n\t\tbody?: string;\n\t\tokStatuses: readonly number[];\n\t\tisEvidence?: (body: T) => boolean;\n\t},\n\ttoError: (ex: unknown, dispatch: WriteDispatch, response?: ProviderRequestResponse<T>) => E,\n\tnoConnection: (dispatch: WriteDispatch, response?: ProviderRequestResponse<T>) => E,\n): Promise<ProviderRequestResponse<T>> {\n\tif (!(await isPinnedWriteConnectionCurrent(connection))) throw noConnection('none');\n\t// KEEP: re-check synchronously; the awaited check above resumes a microtask after its last isRetired()\n\tif (connection.isRetired()) throw noConnection('none');\n\n\tconst mutation = options.method !== 'GET';\n\tlet response: ProviderRequestResponse<T>;\n\ttry {\n\t\tresponse = await request<T>({\n\t\t\turl: options.url,\n\t\t\tmethod: options.method,\n\t\t\tredirect: 'error',\n\t\t\tcredentials: 'omit',\n\t\t\tsignal: AbortSignal.timeout(30_000),\n\t\t\theaders:\n\t\t\t\toptions.body == null ? options.headers : { ...options.headers, 'Content-Type': 'application/json' },\n\t\t\tbody: options.body,\n\t\t});\n\t} catch (ex) {\n\t\tthrow toError(ex, mutation ? 'rejected' : 'none');\n\t}\n\tif (!mutation) return response;\n\n\tif (!options.okStatuses.includes(response.status) || options.isEvidence?.(response.body) === false) {\n\t\tthrow toError(undefined, 'uncertain');\n\t}\n\n\tlet current: boolean;\n\ttry {\n\t\tcurrent = await isPinnedWriteConnectionCurrent(connection);\n\t} catch (ex) {\n\t\tthrow toError(ex, 'applied', response);\n\t}\n\tif (!current) throw noConnection('applied', response);\n\n\treturn response;\n}\n"],"mappings":";;AAeA,SAAgB,oBAAoB,IAAiC;CACpE,MAAM,QAAQ;CACd,OAAO,OAAO,UAAU,UAAU,OAAO;AAC1C;AAEA,SAAgB,qBACf,IACoG;CACpG,IAAI,sBAAsB,GAAG,EAAE,GAAG,OAAO;CAEzC,QAAQ,oBAAoB,EAAE,GAA9B;EACC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,KACJ,OAAO;EACR,KAAK,KACJ,OAAO;EACR,KAAK,KACJ,OAAO;EACR,KAAK,KACJ,OAAO;EACR,KAAK,KACJ,OAAO;EACR,SACC;CACF;AACD;AAEA,eAAsB,+BAA+B,YAAqD;CACzG,OAAO,CAAC,WAAW,UAAU,KAAM,MAAM,WAAW,UAAU,KAAM,CAAC,WAAW,UAAU;AAC3F;AAEA,eAAsB,uBACrB,SACA,YACA,SAQA,SACA,cACsC;CACtC,IAAI,CAAE,MAAM,+BAA+B,UAAU,GAAI,MAAM,aAAa,MAAM;CAElF,IAAI,WAAW,UAAU,GAAG,MAAM,aAAa,MAAM;CAErD,MAAM,WAAW,QAAQ,WAAW;CACpC,IAAI;CACJ,IAAI;EACH,WAAW,MAAM,QAAW;GAC3B,KAAK,QAAQ;GACb,QAAQ,QAAQ;GAChB,UAAU;GACV,aAAa;GACb,QAAQ,YAAY,QAAQ,GAAM;GAClC,SACC,QAAQ,QAAQ,OAAO,QAAQ,UAAU;IAAE,GAAG,QAAQ;IAAS,gBAAgB;GAAmB;GACnG,MAAM,QAAQ;EACf,CAAC;CACF,SAAS,IAAI;EACZ,MAAM,QAAQ,IAAI,WAAW,aAAa,MAAM;CACjD;CACA,IAAI,CAAC,UAAU,OAAO;CAEtB,IAAI,CAAC,QAAQ,WAAW,SAAS,SAAS,MAAM,KAAK,QAAQ,aAAa,SAAS,IAAI,MAAM,OAC5F,MAAM,QAAQ,KAAA,GAAW,WAAW;CAGrC,IAAI;CACJ,IAAI;EACH,UAAU,MAAM,+BAA+B,UAAU;CAC1D,SAAS,IAAI;EACZ,MAAM,QAAQ,IAAI,WAAW,QAAQ;CACtC;CACA,IAAI,CAAC,SAAS,MAAM,aAAa,WAAW,QAAQ;CAEpD,OAAO;AACR"}
@@ -1,6 +1,7 @@
1
1
  import { ResourceDescriptor } from "../../../git/models/resourceDescriptor.js";
2
2
  import { PullRequest, PullRequestFilter, PullRequestStateFilter } from "../../../git/models/pullRequest.js";
3
3
  import { IntegrationIds } from "../constants.js";
4
+ import "../providerFilters.js";
4
5
  import { ProviderWarning } from "../results.js";
5
6
  import { ProviderSweepTarget, PullRequestSweepOptions } from "../manager.js";
6
7
  import { IntegrationResult } from "../models/publicIntegration.js";
@@ -1247,6 +1247,31 @@ Core sends each mutation once. See [Linear's GraphQL API](https://linear.app/dev
1247
1247
  [GraphQL schema](https://studio.apollographql.com/public/Linear-API/variant/current/schema/reference/objects/Mutation)
1248
1248
  and [delete and archive guidance](https://linear.app/docs/delete-archive-issues).
1249
1249
 
1250
+ ### Asana task writes
1251
+
1252
+ Import the Asana methods and types from `@gitkraken/core-gitlens/plus/integrations/index.js`. All calls use the explicitly selected `connectionId` and its OAuth token. Reads accept an optional `expectedAccountId`. Every mutation requires the viewer GID from `getAsanaTaskWriteAccount` or a previous read. Successful calls return the authenticated `account` with its `id`, `name`, and `email`. Every Asana identifier is a GID string.
1253
+
1254
+ | Method | Input beyond the connection and account | Success |
1255
+ | -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
1256
+ | `getAsanaTaskWriteAccount` | None | The current Asana user. |
1257
+ | `getAsanaTaskCreateOptions` | Optional `workspaceId`, and optional `projectIds` within that workspace | Workspaces with their unarchived projects, or the pinned projects with their sections. |
1258
+ | `resolveAsanaTaskWriteTarget` | `task` as a GID or an `app.asana.com` task URL, and optional `workspaceId` and `projectId` | Current task, workspace, every membership, the pinned project's membership, and individual capabilities. |
1259
+ | `writeAsanaTask` with `action: 'create'` | `workspaceId`, `projectId`, nonblank `name`, optional `notes`, and optional `sectionId` of that project | Created task and its membership in the project. |
1260
+ | `writeAsanaTask` with `action: 'edit'` | `workspaceId`, `projectId`, `taskId`, optional current `sectionId`, and at least one of `name` or `notes` | Updated task. An omitted value is preserved. An empty `notes` clears the notes. |
1261
+ | `writeAsanaTask` with `action: 'complete'` or `'reopen'` | `workspaceId`, `projectId`, `taskId`, and optional current `sectionId` | Updated task with `completed: true` or `false`, respectively. |
1262
+ | `writeAsanaTask` with `action: 'move'` | `workspaceId`, `projectId`, `taskId`, current `sectionId` (or `null`), and `destinationSectionId` of the same project | Updated task with both `sourceSection` and `destinationSection`. |
1263
+ | `deleteAsanaTask` | `workspaceId`, `projectId`, `taskId`, resolved `sectionId`, `completed`, `modifiedAt`, and `membershipProjectIds` values, and `confirmed: true` | Pre-delete task, workspace, project, and membership with `deletion.trashed: true`. |
1264
+
1265
+ Task receipts include the GID `id`, `name`, `notes`, permalink `url`, `completed`, `modifiedAt`, `workspaceId`, every direct project membership in Asana's order with its nullable section, `inheritedProjects` with the projects a subtask belongs to only through an ancestor (absent when Asana's response omits `effective_memberships`), and the `assignee` with its `id`, nullable `name`, and nullable 60×60 `avatarUrl`. `assignee` is `null` for an unassigned task and absent when Asana's response omits it. Point reads accept task URLs in the `/0/<context>/<task>`, `/1/<workspace>/task/<task>`, and `/1/<workspace>/project/<project>/task/<task>` forms. The task GID is the identity; a URL's workspace or project must agree with explicit pins. The `/0/<context>/` segment can name a project, a tag, My Tasks, or a search, so Core ignores it and mutations rely on the explicit `projectId`. A read without a project works for a generic link and reports `project-required` for every action. [Asana task API](https://developers.asana.com/reference/tasks), [URL formats](https://forum.asana.com/t/upcoming-new-v1-asana-url-format-in-the-browser/1011489)
1266
+
1267
+ A task can belong to several projects. Every mutation requires exactly one direct membership in the pinned project, or returns `not-in-project`. A project the task only inherits from an ancestor has no section placement and cannot be pinned for any action, including editing and completion, so pin one of the task's direct projects. Editing and completion change the task in every project. A move changes only the section of the pinned project's membership. The destination section must belong to the pinned project, because adding a task to a section of another project would add the task to that project. Core never requests a membership change, but Asana has no conditional move: if the task is removed from the pinned project between Core's final read and the move, the move adds it back, and the receipt cannot tell that apart from a plain move. [Add task to section](https://developers.asana.com/reference/addtaskforsection), [create a task](https://developers.asana.com/reference/createtask)
1268
+
1269
+ Asana has no per-task permission read, so allowed actions are reported as `status: 'unknown'` and Asana decides on dispatch. The GitKraken Asana authorization requests `tasks:write` but not `tasks:delete`, which `DELETE /tasks/{gid}` requires. When the scopes the GitKraken backend reports for the connection omit `tasks:delete`, the delete capability is `insufficient-scope` and `deleteAsanaTask` refuses before dispatch. A 403 is reported as `insufficient-scope` only when Asana names the missing scope; otherwise it is `forbidden`. A 402 returns `payment-required` for premium-only features, and a 451 returns `legal-block`. [OAuth scopes](https://developers.asana.com/docs/oauth-scopes), [errors](https://developers.asana.com/docs/errors)
1270
+
1271
+ For deletion, resolve the exact target before presenting it for confirmation. Call `deleteAsanaTask` only after approval and carry the resolved viewer, workspace, project, task, and current section, plus the confirmed `completed` and `modifiedAt` values and the project GIDs of every confirmed membership, both direct and in `inheritedProjects`, because a deleted subtask also disappears from the projects it inherits. Asana does not update `modified_at` when a task joins or leaves a project, so Core refuses with `conflict` when the final read shows a different set of projects, and with `unknown` when a membership in it has no readable project or the read omits `effective_memberships`. Deletion moves the task to the deleting user's trash for 30 days and removes it from every project. [Delete a task](https://developers.asana.com/reference/deletetask)
1272
+
1273
+ Core revalidates the session, viewer, project, sections when needed, and finally the task and its membership before dispatch. Asana's write endpoints have no atomic precondition, so an external change can race the final read. A preflight refusal returns `mutationDispatched: false`. A definitive provider rejection returns a typed reason such as `forbidden`, `not-found`, `invalid-input` (with Asana's `messages`), or `rate-limit`. A lost or ambiguous mutation response returns `applied: 'maybe'`. A confirmed mutation whose session check or read-back fails returns `applied: 'yes'` with the `taskId` when known and no receipt; a read-back that does not show the requested change returns `conflict`. A success status with an empty, malformed, HTML, or other non-JSON body, or JSON whose `data` is not an object, proves nothing about Asana and returns `applied: 'maybe'`. Reconcile both outcomes using a read before attempting another write. Completion and moves reuse provider-apis' Asana client over Core's single-attempt request. The integration runtime's `http.fetch` must send `POST /tasks`, `PUT` and `DELETE /tasks/{gid}`, and `POST /sections/{gid}/addTask` in a single attempt.
1274
+
1250
1275
  ### Trello card writes
1251
1276
 
1252
1277
  Import the Trello methods and types from `@gitkraken/core-gitlens/plus/integrations/index.js`. All calls use the explicitly selected `connectionId` and its paired Trello app key and token. Discovery and point reads accept an optional `expectedAccountId`. Every mutation requires the Trello member ID from discovery or the read path. Successful calls return the authenticated `account` with its `id`, `username`, and `name`.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gitkraken/core-gitlens",
3
3
  "description": "GitLens core — shared Git / AI / GitHub primitives for internal GitKraken consumption",
4
- "version": "0.68.0",
4
+ "version": "0.69.0",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": {
7
7
  "name": "GitKraken",