@gitkraken/core-gitlens 0.67.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.
- package/CHANGELOG.md +20 -0
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +1 -1
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -1
- package/dist/plus/integrations/authentication/configuredIntegrationService.js +2 -2
- package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +4 -2
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js +5 -4
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
- package/dist/plus/integrations/index.d.ts +3 -1
- package/dist/plus/integrations/index.js +18 -0
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +29 -0
- package/dist/plus/integrations/integrationService.js +84 -0
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +12 -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/models/trelloCardWrites.d.ts +117 -0
- package/dist/plus/integrations/models/trelloCardWrites.js +0 -0
- 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/providersApi.js +1 -4
- package/dist/plus/integrations/providers/providersApi.js.map +1 -1
- package/dist/plus/integrations/providers/trello.d.ts +3 -1
- package/dist/plus/integrations/providers/trello.js +11 -0
- package/dist/plus/integrations/providers/trello.js.map +1 -1
- package/dist/plus/integrations/providers/trelloApi.d.ts +5 -0
- package/dist/plus/integrations/providers/trelloApi.js +9 -0
- package/dist/plus/integrations/providers/trelloApi.js.map +1 -0
- package/dist/plus/integrations/providers/trelloCardWriteTransport.d.ts +27 -0
- package/dist/plus/integrations/providers/trelloCardWriteTransport.js +73 -0
- package/dist/plus/integrations/providers/trelloCardWriteTransport.js.map +1 -0
- package/dist/plus/integrations/providers/trelloCardWrites.d.ts +26 -0
- package/dist/plus/integrations/providers/trelloCardWrites.js +342 -0
- package/dist/plus/integrations/providers/trelloCardWrites.js.map +1 -0
- 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/docs/integrations.md +51 -0
- package/package.json +1 -1
|
@@ -2,16 +2,18 @@ import { IssueResourceDescriptor, ResourceDescriptor } from "../../../git/models
|
|
|
2
2
|
import { IssueOrPullRequest, IssueOrPullRequestType } from "../../../git/models/issueOrPullRequest.js";
|
|
3
3
|
import { Issue, IssueShape } from "../../../git/models/issue.js";
|
|
4
4
|
import { Account } from "../../../git/models/author.js";
|
|
5
|
-
import { ProviderAuthenticationSession } from "../authentication/models.js";
|
|
5
|
+
import { ConfiguredIntegrationDescriptor, ProviderAuthenticationSession } from "../authentication/models.js";
|
|
6
6
|
import { IssuesCloudHostIntegrationId } from "../constants.js";
|
|
7
7
|
import { IntegrationAuthenticationProviderDescriptor } from "../authentication/integrationAuthenticationProvider.js";
|
|
8
8
|
import { IssuesForProjectOptions, ProjectIssuesDrain } from "../models/issueReads.js";
|
|
9
9
|
import { IssuesIntegration } from "../models/issuesIntegration.js";
|
|
10
|
+
import { TrelloCardWriteConnection } from "./trelloCardWriteTransport.js";
|
|
10
11
|
//#region ../plus/integrations/src/providers/trello.d.ts
|
|
11
12
|
/** A Trello board, surfaced as both a "resource" (org analogue) and a "project" for issue reads. */
|
|
12
13
|
export interface TrelloBoardDescriptor extends IssueResourceDescriptor {}
|
|
13
14
|
export declare class TrelloIntegration extends IssuesIntegration<IssuesCloudHostIntegrationId.Trello> {
|
|
14
15
|
readonly authProvider: IntegrationAuthenticationProviderDescriptor;
|
|
16
|
+
getCardWriteConnection(connection: ConfiguredIntegrationDescriptor, isSelectionCurrent: () => boolean): Promise<TrelloCardWriteConnection | undefined>;
|
|
15
17
|
get id(): IssuesCloudHostIntegrationId.Trello;
|
|
16
18
|
protected get key(): 'trello';
|
|
17
19
|
get name(): string;
|
|
@@ -16,6 +16,17 @@ const authProvider = Object.freeze({
|
|
|
16
16
|
const recentAccountTTL = 6e4;
|
|
17
17
|
var TrelloIntegration = class extends IssuesIntegration {
|
|
18
18
|
authProvider = authProvider;
|
|
19
|
+
async getCardWriteConnection(connection, isSelectionCurrent) {
|
|
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;
|
|
23
|
+
return {
|
|
24
|
+
appKey,
|
|
25
|
+
accessToken: pinned.session.accessToken,
|
|
26
|
+
isCurrent: pinned.isCurrent,
|
|
27
|
+
isRetired: pinned.isRetired
|
|
28
|
+
};
|
|
29
|
+
}
|
|
19
30
|
get id() {
|
|
20
31
|
return "trello";
|
|
21
32
|
}
|
|
@@ -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 { 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';\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\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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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
|
+
{"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,M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c,OAAO;EACzC,MAAM,MAAM,MAAM,KAAK,gBAAgB;EACvC,MAAM,gBAAgB,gBAAgB,KAAK,IAAI,OAAO;EAEtD,MAAM,wBAAuB,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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
//#region ../plus/integrations/src/providers/trelloApi.d.ts
|
|
2
|
+
export declare const trelloBaseUrl = "https://api.trello.com";
|
|
3
|
+
export declare function getTrelloAuthHeaders(appKey: string, token: string): Record<string, string>;
|
|
4
|
+
//#endregion
|
|
5
|
+
//# sourceMappingURL=trelloApi.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region ../plus/integrations/src/providers/trelloApi.ts
|
|
2
|
+
const trelloBaseUrl = "https://api.trello.com";
|
|
3
|
+
function getTrelloAuthHeaders(appKey, token) {
|
|
4
|
+
return { Authorization: `OAuth oauth_consumer_key="${appKey}", oauth_token="${token}"` };
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { getTrelloAuthHeaders, trelloBaseUrl };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=trelloApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trelloApi.js","names":[],"sources":["../../../../../plus/integrations/src/providers/trelloApi.ts"],"sourcesContent":["export const trelloBaseUrl = 'https://api.trello.com';\n\nexport function getTrelloAuthHeaders(appKey: string, token: string): Record<string, string> {\n\treturn {\n\t\tAuthorization: `OAuth oauth_consumer_key=\"${appKey}\", oauth_token=\"${token}\"`,\n\t};\n}\n"],"mappings":";AAAA,MAAa,gBAAgB;AAE7B,SAAgB,qBAAqB,QAAgB,OAAuC;CAC3F,OAAO,EACN,eAAe,6BAA6B,OAAO,kBAAkB,MAAM,GAC5E;AACD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TrelloCardWriteFailure } from "../models/trelloCardWrites.js";
|
|
2
|
+
import { ProviderRequestFunction } from "./models.js";
|
|
3
|
+
import { PinnedWriteConnection, WriteDispatch } from "./utils/writeTransport.js";
|
|
4
|
+
//#region ../plus/integrations/src/providers/trelloCardWriteTransport.d.ts
|
|
5
|
+
type FailureReason = TrelloCardWriteFailure['reason'];
|
|
6
|
+
export declare class TrelloCardWriteError extends Error {
|
|
7
|
+
readonly failure: TrelloCardWriteFailure;
|
|
8
|
+
static is(ex: unknown): ex is TrelloCardWriteError;
|
|
9
|
+
constructor(reason: FailureReason, dispatch?: Exclude<WriteDispatch, 'applied'>);
|
|
10
|
+
}
|
|
11
|
+
export declare function toTrelloCardWriteFailure(ex: unknown): TrelloCardWriteFailure;
|
|
12
|
+
export type TrelloCardWriteConnection = PinnedWriteConnection & {
|
|
13
|
+
appKey: string;
|
|
14
|
+
accessToken: string;
|
|
15
|
+
};
|
|
16
|
+
export declare class TrelloCardWriteTransport {
|
|
17
|
+
private readonly request;
|
|
18
|
+
private readonly connection;
|
|
19
|
+
private readonly headers;
|
|
20
|
+
constructor(request: ProviderRequestFunction, connection: TrelloCardWriteConnection);
|
|
21
|
+
verify(): Promise<void>;
|
|
22
|
+
read<T>(path: string): Promise<T>;
|
|
23
|
+
mutate<T>(method: 'POST' | 'PUT' | 'DELETE', path: string, data?: Record<string, string | boolean | undefined>): Promise<T>;
|
|
24
|
+
private send;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//# sourceMappingURL=trelloCardWriteTransport.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isCancellationError } from "../../../utils/cancellation.js";
|
|
2
|
+
import { getProviderResponseBodyMessage } from "./providerErrors.js";
|
|
3
|
+
import { getWriteErrorStatus, getWriteStatusReason, isPinnedWriteConnectionCurrent, sendPinnedWriteRequest } from "./utils/writeTransport.js";
|
|
4
|
+
import { getTrelloAuthHeaders, trelloBaseUrl } from "./trelloApi.js";
|
|
5
|
+
//#region ../plus/integrations/src/providers/trelloCardWriteTransport.ts
|
|
6
|
+
var TrelloCardWriteError = class TrelloCardWriteError extends Error {
|
|
7
|
+
failure;
|
|
8
|
+
static is(ex) {
|
|
9
|
+
return ex instanceof TrelloCardWriteError;
|
|
10
|
+
}
|
|
11
|
+
constructor(reason, dispatch = "none") {
|
|
12
|
+
super(reason);
|
|
13
|
+
this.failure = {
|
|
14
|
+
ok: false,
|
|
15
|
+
reason,
|
|
16
|
+
...dispatch === "none" && { mutationDispatched: false },
|
|
17
|
+
...dispatch === "uncertain" && { applied: "maybe" }
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
function toTrelloCardWriteFailure(ex) {
|
|
22
|
+
if (TrelloCardWriteError.is(ex)) return ex.failure;
|
|
23
|
+
return new TrelloCardWriteError(isCancellationError(ex) ? "no-connection" : getFailureReason(ex)).failure;
|
|
24
|
+
}
|
|
25
|
+
var TrelloCardWriteTransport = class {
|
|
26
|
+
request;
|
|
27
|
+
connection;
|
|
28
|
+
headers;
|
|
29
|
+
constructor(request, connection) {
|
|
30
|
+
this.request = request;
|
|
31
|
+
this.connection = connection;
|
|
32
|
+
this.headers = getTrelloAuthHeaders(connection.appKey, connection.accessToken);
|
|
33
|
+
}
|
|
34
|
+
async verify() {
|
|
35
|
+
if (!await isPinnedWriteConnectionCurrent(this.connection)) throw new TrelloCardWriteError("no-connection");
|
|
36
|
+
}
|
|
37
|
+
async read(path) {
|
|
38
|
+
return (await this.send("GET", path)).body;
|
|
39
|
+
}
|
|
40
|
+
async mutate(method, path, data) {
|
|
41
|
+
return (await this.send(method, path, data == null ? void 0 : JSON.stringify(data))).body;
|
|
42
|
+
}
|
|
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));
|
|
51
|
+
}
|
|
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
|
+
}
|
|
58
|
+
function getFailureReason(ex) {
|
|
59
|
+
const status = getWriteErrorStatus(ex);
|
|
60
|
+
if (status === 401 || status === 403) {
|
|
61
|
+
const error = ex;
|
|
62
|
+
const reason = getProviderResponseBodyMessage(error?.response?.body) ?? "";
|
|
63
|
+
const challenge = error?.response?.headers?.["www-authenticate"] ?? "";
|
|
64
|
+
if (/\binsufficient[_ -]scope\b/i.test(challenge)) return "insufficient-scope";
|
|
65
|
+
if (status === 403 || /\bunauthorized (?:board |card |list )?permission requested\b/i.test(reason)) return "forbidden";
|
|
66
|
+
return "no-connection";
|
|
67
|
+
}
|
|
68
|
+
return getWriteStatusReason(ex) ?? "unknown";
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { TrelloCardWriteError, TrelloCardWriteTransport, toTrelloCardWriteFailure };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=trelloCardWriteTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,KAAA,aAAA;EAEjB,KAAK,UAAU,qBAAqB,WAAW,QAAQ,WAAW,WAAW;CAC9E;CAEA,MAAM,SAAwB;EAC7B,IAAI,CAAE,MAAM,+BAA+B,KAAK,UAAU,GAAI,MAAM,IAAI,qBAAqB,eAAe;CAC7G;CAEA,MAAM,KAAQ,MAA0B;EACvC,QAAQ,MAAM,KAAK,KAAQ,OAAO,IAAI,EAAA,CAAG;CAC1C;CAEA,MAAM,OACL,QACA,MACA,MACa;EAEb,QAAO,MADgB,KAAK,KAAQ,QAAQ,MAAM,QAAQ,OAAO,KAAA,IAAY,KAAK,UAAU,IAAI,CAAC,EAAA,CACjF;CACjB;CAEA,KACC,QACA,MACA,MACsC;EACtC,OAAO,uBACN,KAAK,SACL,KAAK,YACL;GACC,KAAK,GAAG,cAAc,KAAK;GACnB;GACR,SAAS,KAAK;GACR;GACN,YAAY,WAAW,WAAW,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG;EACpD,GACA,kBACA,aAAY,IAAI,qBAAqB,iBAAiB,aAAa,YAAY,cAAc,QAAQ,CACtG;CACD;AACD;AAEA,SAAS,gBAAgB,IAAa,UAA+C;CACpF,IAAI,aAAa,WAAW,OAAO,IAAI,qBAAqB,yBAAyB,EAAE,CAAC,CAAC,QAAQ,WAAW;CAE5G,MAAM,SAAS,MAAM,OAAO,YAAY,iBAAiB,EAAE;CAC3D,OAAO,IAAI,qBAAqB,QAAQ,aAAa,cAAc,WAAW,YAAY,cAAc,QAAQ;AACjH;AAEA,SAAS,iBAAiB,IAA4B;CACrD,MAAM,SAAS,oBAAoB,EAAE;CACrC,IAAI,WAAW,OAAO,WAAW,KAAK;EACrC,MAAM,QAAQ;EACd,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;CAEA,OAAO,qBAAqB,EAAE,KAAK;AACpC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TrelloCardCreateOptions, TrelloCardCreateOptionsResult, TrelloCardDeleteOptions, TrelloCardDeleteResult, TrelloCardWriteOptions, TrelloCardWriteOptionsResult, TrelloCardWriteResult, TrelloCardWriteScope, TrelloCardWriteTargetOptions } from "../models/trelloCardWrites.js";
|
|
2
|
+
import { TrelloCardWriteTransport } from "./trelloCardWriteTransport.js";
|
|
3
|
+
//#region ../plus/integrations/src/providers/trelloCardWrites.d.ts
|
|
4
|
+
type ResolvedTarget = Extract<TrelloCardWriteOptionsResult, {
|
|
5
|
+
ok: true;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function isTrelloCardWriteScope(scope: TrelloCardWriteScope, mutation: boolean): boolean;
|
|
8
|
+
export declare class TrelloCardWriter {
|
|
9
|
+
private readonly transport;
|
|
10
|
+
private readonly activeWrites;
|
|
11
|
+
constructor(transport: TrelloCardWriteTransport, activeWrites: Set<string>);
|
|
12
|
+
verify(): Promise<void>;
|
|
13
|
+
getCreateOptions(options: TrelloCardCreateOptions): Promise<TrelloCardCreateOptionsResult>;
|
|
14
|
+
resolveTarget(options: TrelloCardWriteTargetOptions): Promise<ResolvedTarget>;
|
|
15
|
+
write(options: TrelloCardWriteOptions): Promise<TrelloCardWriteResult>;
|
|
16
|
+
delete(options: TrelloCardDeleteOptions): Promise<TrelloCardDeleteResult>;
|
|
17
|
+
private create;
|
|
18
|
+
private getContext;
|
|
19
|
+
private getCard;
|
|
20
|
+
private getList;
|
|
21
|
+
private getBoard;
|
|
22
|
+
private getBoardOptions;
|
|
23
|
+
private withCardMutation;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//# sourceMappingURL=trelloCardWrites.d.ts.map
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { TrelloCardWriteError } from "./trelloCardWriteTransport.js";
|
|
2
|
+
//#region ../plus/integrations/src/providers/trelloCardWrites.ts
|
|
3
|
+
const boardFields = "id,name,closed,url,memberships";
|
|
4
|
+
const cardFields = "id,idShort,shortLink,url,name,idBoard,idList,closed,desc,dateLastActivity";
|
|
5
|
+
const listFields = "id,name,idBoard,closed";
|
|
6
|
+
function isTrelloId(value) {
|
|
7
|
+
return typeof value === "string" && /^[a-f0-9]{24}$/.test(value);
|
|
8
|
+
}
|
|
9
|
+
function isTrelloShortLink(value) {
|
|
10
|
+
return typeof value === "string" && /^[a-zA-Z0-9]{8}$/.test(value);
|
|
11
|
+
}
|
|
12
|
+
function isTrelloCardWriteScope(scope, mutation) {
|
|
13
|
+
return typeof scope.connectionId === "string" && scope.connectionId.trim() !== "" && (!mutation && scope.expectedAccountId === void 0 || isTrelloId(scope.expectedAccountId));
|
|
14
|
+
}
|
|
15
|
+
function isBoard(board) {
|
|
16
|
+
return isTrelloId(board?.id) && typeof board.name === "string" && typeof board.closed === "boolean" && typeof board.url === "string" && board.url.length !== 0;
|
|
17
|
+
}
|
|
18
|
+
function isList(list, boardId) {
|
|
19
|
+
return isTrelloId(list?.id) && typeof list.name === "string" && list.idBoard === boardId && typeof list.closed === "boolean";
|
|
20
|
+
}
|
|
21
|
+
function isCard(card) {
|
|
22
|
+
return isTrelloId(card?.id) && Number.isSafeInteger(card.idShort) && card.idShort > 0 && isTrelloShortLink(card.shortLink) && typeof card.url === "string" && card.url.length !== 0 && typeof card.name === "string" && typeof card.desc === "string" && typeof card.dateLastActivity === "string" && Number.isFinite(Date.parse(card.dateLastActivity)) && isTrelloId(card.idBoard) && isTrelloId(card.idList) && typeof card.closed === "boolean";
|
|
23
|
+
}
|
|
24
|
+
function toReceipt(card) {
|
|
25
|
+
return {
|
|
26
|
+
id: card.id,
|
|
27
|
+
idShort: card.idShort,
|
|
28
|
+
shortLink: card.shortLink,
|
|
29
|
+
url: card.url,
|
|
30
|
+
name: card.name,
|
|
31
|
+
desc: card.desc,
|
|
32
|
+
dateLastActivity: card.dateLastActivity,
|
|
33
|
+
boardId: card.idBoard,
|
|
34
|
+
listId: card.idList,
|
|
35
|
+
closed: card.closed
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function toList(list) {
|
|
39
|
+
return {
|
|
40
|
+
id: list.id,
|
|
41
|
+
name: list.name,
|
|
42
|
+
closed: list.closed
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function getOpenLists(entries, boardId) {
|
|
46
|
+
if (!Array.isArray(entries) || !entries.every((list) => isList(list, boardId))) return void 0;
|
|
47
|
+
return entries.filter((list) => !list.closed).map(toList);
|
|
48
|
+
}
|
|
49
|
+
function toBoardOptions(board, permission, lists) {
|
|
50
|
+
return {
|
|
51
|
+
id: board.id,
|
|
52
|
+
name: board.name,
|
|
53
|
+
closed: board.closed,
|
|
54
|
+
url: board.url,
|
|
55
|
+
permission,
|
|
56
|
+
lists
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function boardPermission(board, accountId) {
|
|
60
|
+
if (!Array.isArray(board.memberships)) return "unknown";
|
|
61
|
+
const membership = board.memberships.find((member) => member?.idMember === accountId);
|
|
62
|
+
if (membership == null) return "unknown";
|
|
63
|
+
if (membership.deactivated || membership.unconfirmed || membership.memberType === "observer") return "forbidden";
|
|
64
|
+
return membership.memberType === "admin" || membership.memberType === "normal" ? "allowed" : "unknown";
|
|
65
|
+
}
|
|
66
|
+
function boardCapability(board, permission) {
|
|
67
|
+
if (board.closed) return {
|
|
68
|
+
status: "unavailable",
|
|
69
|
+
reason: "board-closed"
|
|
70
|
+
};
|
|
71
|
+
if (permission === "forbidden") return {
|
|
72
|
+
status: "unavailable",
|
|
73
|
+
reason: "forbidden"
|
|
74
|
+
};
|
|
75
|
+
return { status: permission };
|
|
76
|
+
}
|
|
77
|
+
function ensureAvailable(capability) {
|
|
78
|
+
if (capability.status === "unavailable") throw new TrelloCardWriteError(capability.reason);
|
|
79
|
+
}
|
|
80
|
+
function validateMutationTarget(options) {
|
|
81
|
+
if (!isTrelloId(options.boardId) || !isTrelloId(options.listId) || !isTrelloId(options.cardId)) throw new TrelloCardWriteError("invalid-input");
|
|
82
|
+
}
|
|
83
|
+
function validateFields(name, description) {
|
|
84
|
+
if (name === void 0 && description === void 0 || name !== void 0 && (typeof name !== "string" || name.trim() === "") || description !== void 0 && typeof description !== "string") throw new TrelloCardWriteError("invalid-input");
|
|
85
|
+
}
|
|
86
|
+
function validateUpdate(options) {
|
|
87
|
+
validateMutationTarget(options);
|
|
88
|
+
switch (options.action) {
|
|
89
|
+
case "edit":
|
|
90
|
+
validateFields(options.name, options.description);
|
|
91
|
+
break;
|
|
92
|
+
case "move":
|
|
93
|
+
if (!isTrelloId(options.destinationBoardId) || !isTrelloId(options.destinationListId)) throw new TrelloCardWriteError("invalid-input");
|
|
94
|
+
if (options.destinationBoardId !== options.boardId) throw new TrelloCardWriteError("cross-board-move");
|
|
95
|
+
if (options.destinationListId === options.listId) throw new TrelloCardWriteError("invalid-input");
|
|
96
|
+
break;
|
|
97
|
+
case "archive":
|
|
98
|
+
case "restore": break;
|
|
99
|
+
default: throw new TrelloCardWriteError("invalid-input");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function validateResult(card, boardId, listId, closed, previous) {
|
|
103
|
+
if (!isCard(card) || card.idBoard !== boardId || card.idList !== listId || card.closed !== closed || previous != null && (card.id !== previous.id || card.idShort !== previous.idShort || card.shortLink !== previous.shortLink)) throw new TrelloCardWriteError("unknown", "uncertain");
|
|
104
|
+
return toReceipt(card);
|
|
105
|
+
}
|
|
106
|
+
var TrelloCardWriter = class {
|
|
107
|
+
transport;
|
|
108
|
+
activeWrites;
|
|
109
|
+
constructor(transport, activeWrites) {
|
|
110
|
+
this.transport = transport;
|
|
111
|
+
this.activeWrites = activeWrites;
|
|
112
|
+
}
|
|
113
|
+
verify() {
|
|
114
|
+
return this.transport.verify();
|
|
115
|
+
}
|
|
116
|
+
async getCreateOptions(options) {
|
|
117
|
+
if (options.boardId !== void 0 && !isTrelloId(options.boardId)) throw new TrelloCardWriteError("invalid-input");
|
|
118
|
+
const context = await this.getContext(options);
|
|
119
|
+
if (options.boardId !== void 0) {
|
|
120
|
+
const board = await this.getBoard(options.boardId);
|
|
121
|
+
const permission = boardPermission(board, context.accountId);
|
|
122
|
+
ensureAvailable(boardCapability(board, permission));
|
|
123
|
+
return {
|
|
124
|
+
...context,
|
|
125
|
+
boards: [await this.getBoardOptions(board, permission)]
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const candidates = await this.transport.read(`members/me/boards?filter=open&fields=${boardFields}&lists=open`);
|
|
129
|
+
if (!Array.isArray(candidates) || !candidates.every(isBoard)) throw new TrelloCardWriteError("unknown");
|
|
130
|
+
const boards = [];
|
|
131
|
+
const failures = [];
|
|
132
|
+
for (const board of candidates) {
|
|
133
|
+
const permission = boardPermission(board, context.accountId);
|
|
134
|
+
if (board.closed || permission === "forbidden") continue;
|
|
135
|
+
const lists = getOpenLists(board.lists, board.id);
|
|
136
|
+
if (lists == null) {
|
|
137
|
+
failures.push({
|
|
138
|
+
boardId: board.id,
|
|
139
|
+
reason: "unknown"
|
|
140
|
+
});
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
boards.push(toBoardOptions(board, permission, lists));
|
|
144
|
+
}
|
|
145
|
+
if (boards.length === 0 && failures.length !== 0) return {
|
|
146
|
+
ok: false,
|
|
147
|
+
reason: "unknown",
|
|
148
|
+
mutationDispatched: false,
|
|
149
|
+
boardFailures: failures
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
...context,
|
|
153
|
+
boards,
|
|
154
|
+
...failures.length !== 0 && { boardFailures: failures }
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
async resolveTarget(options) {
|
|
158
|
+
const { boardId, listId, cardId } = options;
|
|
159
|
+
if (!isTrelloId(cardId) && !isTrelloShortLink(cardId) || boardId !== void 0 && !isTrelloId(boardId) || listId !== void 0 && !isTrelloId(listId)) throw new TrelloCardWriteError("invalid-input");
|
|
160
|
+
const context = await this.getContext(options);
|
|
161
|
+
let resolved;
|
|
162
|
+
let pinnedBoardId = boardId;
|
|
163
|
+
if (pinnedBoardId === void 0) {
|
|
164
|
+
resolved = await this.getCard(options);
|
|
165
|
+
pinnedBoardId = resolved.idBoard;
|
|
166
|
+
}
|
|
167
|
+
const board = await this.getBoard(pinnedBoardId);
|
|
168
|
+
const permission = boardPermission(board, context.accountId);
|
|
169
|
+
const boardOptions = await this.getBoardOptions(board, permission);
|
|
170
|
+
const card = resolved ?? await this.getCard(options);
|
|
171
|
+
const source = boardOptions.lists.find((list) => list.id === card.idList);
|
|
172
|
+
const list = source ?? await this.getList(card.idList, card.idBoard);
|
|
173
|
+
const destination = boardOptions.lists.some((list) => list.id !== card.idList);
|
|
174
|
+
let base = boardCapability(board, permission);
|
|
175
|
+
if (base.status !== "unavailable" && !source) base = {
|
|
176
|
+
status: "unavailable",
|
|
177
|
+
reason: "list-unavailable"
|
|
178
|
+
};
|
|
179
|
+
const active = base.status !== "unavailable" && card.closed ? {
|
|
180
|
+
status: "unavailable",
|
|
181
|
+
reason: "card-archived"
|
|
182
|
+
} : base;
|
|
183
|
+
return {
|
|
184
|
+
...context,
|
|
185
|
+
board: boardOptions,
|
|
186
|
+
list,
|
|
187
|
+
card: toReceipt(card),
|
|
188
|
+
capabilities: {
|
|
189
|
+
edit: active,
|
|
190
|
+
move: active.status !== "unavailable" && !destination ? {
|
|
191
|
+
status: "unavailable",
|
|
192
|
+
reason: "list-unavailable"
|
|
193
|
+
} : active,
|
|
194
|
+
archive: active,
|
|
195
|
+
restore: base.status !== "unavailable" && !card.closed ? {
|
|
196
|
+
status: "unavailable",
|
|
197
|
+
reason: "card-open"
|
|
198
|
+
} : base,
|
|
199
|
+
delete: base
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
async write(options) {
|
|
204
|
+
if (options.action === "create") return this.create(options);
|
|
205
|
+
validateUpdate(options);
|
|
206
|
+
return this.withCardMutation(options.cardId, async () => {
|
|
207
|
+
const { card, board, list, capabilities, connectionId, accountId, account } = await this.resolveTarget(options);
|
|
208
|
+
const { action } = options;
|
|
209
|
+
ensureAvailable(capabilities[action]);
|
|
210
|
+
let destination = list;
|
|
211
|
+
let closed = card.closed;
|
|
212
|
+
let fields;
|
|
213
|
+
switch (action) {
|
|
214
|
+
case "edit":
|
|
215
|
+
fields = {
|
|
216
|
+
name: options.name,
|
|
217
|
+
desc: options.description
|
|
218
|
+
};
|
|
219
|
+
break;
|
|
220
|
+
case "move": {
|
|
221
|
+
const selected = board.lists.find((list) => list.id === options.destinationListId);
|
|
222
|
+
if (selected == null) throw new TrelloCardWriteError("list-unavailable");
|
|
223
|
+
destination = selected;
|
|
224
|
+
fields = { idList: destination.id };
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
case "archive":
|
|
228
|
+
case "restore":
|
|
229
|
+
closed = action === "archive";
|
|
230
|
+
fields = { closed };
|
|
231
|
+
}
|
|
232
|
+
const receipt = {
|
|
233
|
+
ok: true,
|
|
234
|
+
connectionId,
|
|
235
|
+
accountId,
|
|
236
|
+
account,
|
|
237
|
+
card: validateResult(await this.transport.mutate("PUT", `cards/${card.id}`, fields), card.boardId, destination.id, closed, card),
|
|
238
|
+
board,
|
|
239
|
+
list: destination
|
|
240
|
+
};
|
|
241
|
+
return action === "move" ? {
|
|
242
|
+
...receipt,
|
|
243
|
+
action,
|
|
244
|
+
sourceList: list,
|
|
245
|
+
destinationList: destination
|
|
246
|
+
} : {
|
|
247
|
+
...receipt,
|
|
248
|
+
action
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
async delete(options) {
|
|
253
|
+
if (options.confirmed !== true) throw new TrelloCardWriteError("confirmation-required");
|
|
254
|
+
if (!isTrelloShortLink(options.shortLink) || typeof options.closed !== "boolean") throw new TrelloCardWriteError("invalid-input");
|
|
255
|
+
validateMutationTarget(options);
|
|
256
|
+
return this.withCardMutation(options.cardId, async () => {
|
|
257
|
+
const { capabilities, ...target } = await this.resolveTarget(options);
|
|
258
|
+
if (target.card.shortLink !== options.shortLink || target.card.closed !== options.closed) throw new TrelloCardWriteError("conflict");
|
|
259
|
+
ensureAvailable(capabilities.delete);
|
|
260
|
+
await this.transport.mutate("DELETE", `cards/${target.card.id}`);
|
|
261
|
+
return {
|
|
262
|
+
...target,
|
|
263
|
+
deletion: { permanent: true }
|
|
264
|
+
};
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
async create(options) {
|
|
268
|
+
const { boardId, listId, name, description } = options;
|
|
269
|
+
if (!isTrelloId(boardId) || !isTrelloId(listId) || typeof name !== "string") throw new TrelloCardWriteError("invalid-input");
|
|
270
|
+
validateFields(name, description);
|
|
271
|
+
const context = await this.getContext(options);
|
|
272
|
+
const board = await this.getBoard(boardId);
|
|
273
|
+
const permission = boardPermission(board, context.accountId);
|
|
274
|
+
ensureAvailable(boardCapability(board, permission));
|
|
275
|
+
const boardOptions = await this.getBoardOptions(board, permission);
|
|
276
|
+
const list = boardOptions.lists.find((list) => list.id === listId);
|
|
277
|
+
if (list == null) throw new TrelloCardWriteError("list-unavailable");
|
|
278
|
+
const result = await this.transport.mutate("POST", "cards", {
|
|
279
|
+
idList: listId,
|
|
280
|
+
name,
|
|
281
|
+
desc: description
|
|
282
|
+
});
|
|
283
|
+
return {
|
|
284
|
+
...context,
|
|
285
|
+
action: "create",
|
|
286
|
+
card: validateResult(result, boardId, listId, false),
|
|
287
|
+
board: boardOptions,
|
|
288
|
+
list
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
async getContext(options) {
|
|
292
|
+
const member = await this.transport.read("members/me?fields=id,username,fullName");
|
|
293
|
+
if (!isTrelloId(member?.id) || typeof member.username !== "string" || typeof member.fullName !== "string") throw new TrelloCardWriteError("unknown");
|
|
294
|
+
if (options.expectedAccountId !== void 0 && member.id !== options.expectedAccountId) throw new TrelloCardWriteError("forbidden");
|
|
295
|
+
return {
|
|
296
|
+
ok: true,
|
|
297
|
+
connectionId: options.connectionId,
|
|
298
|
+
accountId: member.id,
|
|
299
|
+
account: {
|
|
300
|
+
id: member.id,
|
|
301
|
+
username: member.username,
|
|
302
|
+
name: member.fullName
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
async getCard({ cardId, boardId, listId }) {
|
|
307
|
+
const card = await this.transport.read(`cards/${cardId}?fields=${cardFields}`);
|
|
308
|
+
if (!isCard(card)) throw new TrelloCardWriteError("unknown");
|
|
309
|
+
if ((isTrelloId(cardId) ? card.id : card.shortLink) !== cardId || boardId !== void 0 && card.idBoard !== boardId || listId !== void 0 && card.idList !== listId) throw new TrelloCardWriteError("conflict");
|
|
310
|
+
return card;
|
|
311
|
+
}
|
|
312
|
+
async getList(listId, boardId) {
|
|
313
|
+
const list = await this.transport.read(`lists/${listId}?fields=id,name,idBoard,closed`);
|
|
314
|
+
if (!isList(list, boardId) || list.id !== listId) throw new TrelloCardWriteError("conflict");
|
|
315
|
+
return toList(list);
|
|
316
|
+
}
|
|
317
|
+
async getBoard(boardId) {
|
|
318
|
+
const board = await this.transport.read(`boards/${boardId}?fields=${boardFields}`);
|
|
319
|
+
if (!isBoard(board)) throw new TrelloCardWriteError("unknown");
|
|
320
|
+
if (board.id !== boardId) throw new TrelloCardWriteError("conflict");
|
|
321
|
+
return board;
|
|
322
|
+
}
|
|
323
|
+
async getBoardOptions(board, permission) {
|
|
324
|
+
if (board.closed) return toBoardOptions(board, permission, []);
|
|
325
|
+
const lists = getOpenLists(await this.transport.read(`boards/${board.id}/lists?filter=open&fields=${listFields}`), board.id);
|
|
326
|
+
if (lists == null) throw new TrelloCardWriteError("unknown");
|
|
327
|
+
return toBoardOptions(board, permission, lists);
|
|
328
|
+
}
|
|
329
|
+
async withCardMutation(cardId, run) {
|
|
330
|
+
if (this.activeWrites.has(cardId)) throw new TrelloCardWriteError("conflict");
|
|
331
|
+
this.activeWrites.add(cardId);
|
|
332
|
+
try {
|
|
333
|
+
return await run();
|
|
334
|
+
} finally {
|
|
335
|
+
this.activeWrites.delete(cardId);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
//#endregion
|
|
340
|
+
export { TrelloCardWriter, isTrelloCardWriteScope };
|
|
341
|
+
|
|
342
|
+
//# sourceMappingURL=trelloCardWrites.js.map
|