@gitkraken/core-gitlens 0.68.0 → 0.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -1
- package/dist/git/providers/diff.d.ts +10 -1
- package/dist/git/providers/status.d.ts +2 -0
- package/dist/git/service.d.ts +5 -1
- package/dist/git/service.js +8 -4
- package/dist/git/service.js.map +1 -1
- package/dist/git/watching/worktreeSummary.d.ts +9 -0
- package/dist/git/watching/worktreeSummary.js +17 -5
- package/dist/git/watching/worktreeSummary.js.map +1 -1
- package/dist/git-cli/cliGitProvider.d.ts +8 -1
- package/dist/git-cli/cliGitProvider.js +14 -3
- package/dist/git-cli/cliGitProvider.js.map +1 -1
- package/dist/git-cli/exec/exec.d.ts +2 -2
- package/dist/git-cli/exec/exec.js +2 -2
- package/dist/git-cli/exec/git.js +4 -3
- package/dist/git-cli/exec/git.js.map +1 -1
- package/dist/git-cli/exec/indexRefresh.d.ts +38 -6
- package/dist/git-cli/exec/indexRefresh.js +84 -3
- package/dist/git-cli/exec/indexRefresh.js.map +1 -1
- package/dist/git-cli/providers/diff.d.ts +4 -1
- package/dist/git-cli/providers/diff.js +17 -1
- package/dist/git-cli/providers/diff.js.map +1 -1
- package/dist/git-cli/providers/status.d.ts +4 -0
- package/dist/git-cli/providers/status.js +113 -16
- package/dist/git-cli/providers/status.js.map +1 -1
- package/dist/git-cli/service.d.ts +13 -1
- package/dist/git-cli/service.js +1 -0
- package/dist/git-cli/service.js.map +1 -1
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +1 -1
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -1
- package/dist/plus/integrations/index.d.ts +2 -1
- package/dist/plus/integrations/index.js +9 -0
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +15 -0
- package/dist/plus/integrations/integrationService.js +35 -4
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +6 -0
- package/dist/plus/integrations/models/asanaTaskWrites.d.ts +155 -0
- package/dist/plus/integrations/models/asanaTaskWrites.js +0 -0
- package/dist/plus/integrations/models/issuesIntegration.d.ts +6 -1
- package/dist/plus/integrations/models/issuesIntegration.js +25 -0
- package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
- package/dist/plus/integrations/providers/asana.d.ts +3 -1
- package/dist/plus/integrations/providers/asana.js +10 -0
- package/dist/plus/integrations/providers/asana.js.map +1 -1
- package/dist/plus/integrations/providers/asanaTaskWriteTransport.d.ts +40 -0
- package/dist/plus/integrations/providers/asanaTaskWriteTransport.js +122 -0
- package/dist/plus/integrations/providers/asanaTaskWriteTransport.js.map +1 -0
- package/dist/plus/integrations/providers/asanaTaskWrites.d.ts +38 -0
- package/dist/plus/integrations/providers/asanaTaskWrites.js +521 -0
- package/dist/plus/integrations/providers/asanaTaskWrites.js.map +1 -0
- package/dist/plus/integrations/providers/trello.js +6 -23
- package/dist/plus/integrations/providers/trello.js.map +1 -1
- package/dist/plus/integrations/providers/trelloCardWriteTransport.d.ts +3 -4
- package/dist/plus/integrations/providers/trelloCardWriteTransport.js +19 -40
- package/dist/plus/integrations/providers/trelloCardWriteTransport.js.map +1 -1
- package/dist/plus/integrations/providers/utils/writeTransport.d.ts +28 -0
- package/dist/plus/integrations/providers/utils/writeTransport.js +60 -0
- package/dist/plus/integrations/providers/utils/writeTransport.js.map +1 -0
- package/dist/utils/env/browser/platform.d.ts +1 -0
- package/dist/utils/env/browser/platform.js +4 -1
- package/dist/utils/env/browser/platform.js.map +1 -1
- package/dist/utils/env/node/exec.d.ts +1 -0
- package/dist/utils/env/node/exec.js +9 -3
- package/dist/utils/env/node/exec.js.map +1 -1
- package/dist/utils/env/node/platform.d.ts +1 -0
- package/dist/utils/env/node/platform.js +4 -1
- package/dist/utils/env/node/platform.js.map +1 -1
- package/dist/utils/platform.d.ts +2 -2
- package/dist/utils/platform.js +2 -2
- package/docs/integrations.md +25 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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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;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,mBAAmB;AAKzB,IAAa,oBAAb,cAAuC,kBAAuD;CAC7F,eAAqE;CAErE,MAAM,uBACL,YACA,oBACiD;EACjD,MAAM,SAAS,MAAM,KAAK,sBAAsB,YAAY,qBAAoB,YAC/E,QAAQ,KAAK,UAAU,OAAO,CAAC,CAChC;EACA,MAAM,SAAS,UAAU,OAAO,KAAK,UAAU,OAAO,OAAO,IAAI,KAAA;EACjE,IAAI,UAAU,QAAQ,CAAC,QAAQ,OAAO,KAAA;EAEtC,OAAO;GACE;GACR,aAA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AAS,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?:
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
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,MAA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
|
+
//#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,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,7 @@
|
|
|
2
2
|
export declare const isWindows: boolean;
|
|
3
3
|
export declare const isLinux: boolean;
|
|
4
4
|
export declare const isMac: boolean;
|
|
5
|
+
export declare function getAltKeySymbol(): string;
|
|
5
6
|
export declare function getShiftKeySymbol(): string;
|
|
6
7
|
//#endregion
|
|
7
8
|
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -4,10 +4,13 @@ const _userAgent = typeof navigator !== "undefined" ? navigator.userAgent : "";
|
|
|
4
4
|
const isWindows = _platform === "Windows" || _userAgent.includes("Windows");
|
|
5
5
|
const isLinux = _platform === "Linux" || _userAgent.includes("Linux");
|
|
6
6
|
const isMac = _platform === "macOS" || _userAgent.includes("Macintosh");
|
|
7
|
+
function getAltKeySymbol() {
|
|
8
|
+
return isMac ? "⌥" : "Alt";
|
|
9
|
+
}
|
|
7
10
|
function getShiftKeySymbol() {
|
|
8
11
|
return isMac ? "⇧" : "Shift";
|
|
9
12
|
}
|
|
10
13
|
//#endregion
|
|
11
|
-
export { getShiftKeySymbol, isLinux, isMac, isWindows };
|
|
14
|
+
export { getAltKeySymbol, getShiftKeySymbol, isLinux, isMac, isWindows };
|
|
12
15
|
|
|
13
16
|
//# sourceMappingURL=platform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","names":[],"sources":["../../../../../utils/src/env/browser/platform.ts"],"sourcesContent":["declare const navigator: { userAgent: string; userAgentData?: { platform?: string } } | undefined;\n\nconst _platform: string | undefined = (\n\tglobalThis as unknown as { navigator?: { userAgentData?: { platform?: string } } }\n).navigator?.userAgentData?.platform;\nconst _userAgent: string = typeof navigator !== 'undefined' ? navigator.userAgent : '';\n\nexport const isWindows: boolean = _platform === 'Windows' || _userAgent.includes('Windows');\nexport const isLinux: boolean = _platform === 'Linux' || _userAgent.includes('Linux');\nexport const isMac: boolean = _platform === 'macOS' || _userAgent.includes('Macintosh');\n\nexport function getShiftKeySymbol(): string {\n\treturn isMac ? '⇧' : 'Shift';\n}\n"],"mappings":";AAEA,MAAM,YACL,WACC,WAAW,eAAe;AAC5B,MAAM,aAAqB,OAAO,cAAc,cAAc,UAAU,YAAY;AAEpF,MAAa,YAAqB,cAAc,aAAa,WAAW,SAAS,SAAS;AAC1F,MAAa,UAAmB,cAAc,WAAW,WAAW,SAAS,OAAO;AACpF,MAAa,QAAiB,cAAc,WAAW,WAAW,SAAS,WAAW;AAEtF,SAAgB,oBAA4B;CAC3C,OAAO,QAAQ,MAAM;AACtB"}
|
|
1
|
+
{"version":3,"file":"platform.js","names":[],"sources":["../../../../../utils/src/env/browser/platform.ts"],"sourcesContent":["declare const navigator: { userAgent: string; userAgentData?: { platform?: string } } | undefined;\n\nconst _platform: string | undefined = (\n\tglobalThis as unknown as { navigator?: { userAgentData?: { platform?: string } } }\n).navigator?.userAgentData?.platform;\nconst _userAgent: string = typeof navigator !== 'undefined' ? navigator.userAgent : '';\n\nexport const isWindows: boolean = _platform === 'Windows' || _userAgent.includes('Windows');\nexport const isLinux: boolean = _platform === 'Linux' || _userAgent.includes('Linux');\nexport const isMac: boolean = _platform === 'macOS' || _userAgent.includes('Macintosh');\n\nexport function getAltKeySymbol(): string {\n\treturn isMac ? '⌥' : 'Alt';\n}\n\nexport function getShiftKeySymbol(): string {\n\treturn isMac ? '⇧' : 'Shift';\n}\n"],"mappings":";AAEA,MAAM,YACL,WACC,WAAW,eAAe;AAC5B,MAAM,aAAqB,OAAO,cAAc,cAAc,UAAU,YAAY;AAEpF,MAAa,YAAqB,cAAc,aAAa,WAAW,SAAS,SAAS;AAC1F,MAAa,UAAmB,cAAc,WAAW,WAAW,SAAS,OAAO;AACpF,MAAa,QAAiB,cAAc,WAAW,WAAW,SAAS,WAAW;AAEtF,SAAgB,kBAA0B;CACzC,OAAO,QAAQ,MAAM;AACtB;AAEA,SAAgB,oBAA4B;CAC3C,OAAO,QAAQ,MAAM;AACtB"}
|
|
@@ -125,6 +125,7 @@ export interface RunOptions<TEncoding = BufferEncoding | 'buffer'> {
|
|
|
125
125
|
/** Launches the process; defaults to {@link spawnProcess}. Only used by `runSpawn` */
|
|
126
126
|
readonly spawn?: ProcessSpawner;
|
|
127
127
|
}
|
|
128
|
+
export declare function withoutTrace2EventLines(text: string): string;
|
|
128
129
|
type ExitCodeOnlyRunOptions<TEncoding = BufferEncoding | 'buffer'> = RunOptions<TEncoding> & {
|
|
129
130
|
exitCodeOnly: true;
|
|
130
131
|
};
|
|
@@ -235,6 +235,10 @@ function killTreeOnKill(child) {
|
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
const bufferExceededRegex = /stdout maxBuffer( length)? exceeded/;
|
|
238
|
+
function withoutTrace2EventLines(text) {
|
|
239
|
+
if (!text.includes("{\"event\":")) return text;
|
|
240
|
+
return text.split("\n").filter((line) => !line.startsWith("{\"event\":")).join("\n");
|
|
241
|
+
}
|
|
238
242
|
function run(command, args, encoding, options) {
|
|
239
243
|
const scope = getScopedLogger() ?? maybeStartScopedLogger("Exec.run");
|
|
240
244
|
const { stdin, stdinEncoding, cancellation, decode, ...opts } = {
|
|
@@ -392,7 +396,8 @@ function runSpawn(command, args, encoding, options) {
|
|
|
392
396
|
if (code !== 0 || signal) {
|
|
393
397
|
const stdio = getStdio(errorEncoding);
|
|
394
398
|
const { stdout, stderr } = stdio instanceof Promise ? await stdio : stdio;
|
|
395
|
-
|
|
399
|
+
const loggedStderr = !options?.quiet && scope?.enabled("debug") ? withoutTrace2EventLines(stderr) : void 0;
|
|
400
|
+
if (loggedStderr) scope?.warn(`[EXEC] '${command} ${args.join(" ")}' \u2022 ${loggedStderr}`);
|
|
396
401
|
if (signal === "SIGTERM") {
|
|
397
402
|
reject(new CancelledRunError(`${command} ${args.join(" ")}`, true, code ?? void 0, signal, proc.killed ? "timeout" : "unknown"));
|
|
398
403
|
return;
|
|
@@ -406,7 +411,8 @@ function runSpawn(command, args, encoding, options) {
|
|
|
406
411
|
}
|
|
407
412
|
const stdio = getStdio(encoding);
|
|
408
413
|
const { stdout, stderr } = stdio instanceof Promise ? await stdio : stdio;
|
|
409
|
-
|
|
414
|
+
const loggedStderr = stderr.length && !options?.quiet && scope?.enabled("debug") ? withoutTrace2EventLines(typeof stderr === "string" ? stderr : stderr.toString()) : void 0;
|
|
415
|
+
if (loggedStderr) scope?.warn(`[EXEC] '${command} ${args.join(" ")}' \u2022 ${loggedStderr}`);
|
|
410
416
|
resolve({
|
|
411
417
|
exitCode: code ?? void 0,
|
|
412
418
|
signal: signal ?? void 0,
|
|
@@ -422,6 +428,6 @@ async function fsExists(path) {
|
|
|
422
428
|
return new Promise((resolve) => access(path, constants.F_OK, (err) => resolve(err == null)));
|
|
423
429
|
}
|
|
424
430
|
//#endregion
|
|
425
|
-
export { CancelledRunError, RunError, endStdin, findExecutable, fsExists, run, runSpawn, spawnProcess };
|
|
431
|
+
export { CancelledRunError, RunError, endStdin, findExecutable, fsExists, run, runSpawn, spawnProcess, withoutTrace2EventLines };
|
|
426
432
|
|
|
427
433
|
//# sourceMappingURL=exec.js.map
|