@gitkraken/core-gitlens 0.51.1 → 0.53.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 +15 -1
- package/dist/_types/provider-apis/types/exportedTypes/github.d.ts +75 -0
- package/dist/_types/provider-apis/types/exportedTypes/types.d.ts +7 -0
- package/dist/git-cli/providers/config.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js.map +1 -1
- package/dist/git-cli/providers/staging.js +1 -1
- package/dist/ipc/discovery.js +1 -1
- package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
- package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
- package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
- package/dist/plus/git-github/api/issueWrites.js +1 -1
- package/dist/plus/git-github/api/issueWrites.js.map +1 -1
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.d.ts +10 -1
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +75 -23
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -1
- package/dist/plus/integrations/authentication/cloudIntegrationObservations.d.ts +49 -0
- package/dist/plus/integrations/authentication/cloudIntegrationObservations.js +118 -0
- package/dist/plus/integrations/authentication/cloudIntegrationObservations.js.map +1 -0
- package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +45 -25
- package/dist/plus/integrations/authentication/configuredIntegrationService.js +409 -141
- package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +12 -3
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js +39 -7
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
- package/dist/plus/integrations/authentication/models.d.ts +6 -0
- package/dist/plus/integrations/authentication/models.js +9 -1
- package/dist/plus/integrations/authentication/models.js.map +1 -1
- package/dist/plus/integrations/authentication/observedAuthenticationProvider.d.ts +17 -2
- package/dist/plus/integrations/authentication/observedAuthenticationProvider.js +84 -16
- package/dist/plus/integrations/authentication/observedAuthenticationProvider.js.map +1 -1
- package/dist/plus/integrations/index.d.ts +3 -2
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +9 -0
- package/dist/plus/integrations/integrationService.js +182 -39
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +3 -0
- package/dist/plus/integrations/models/integration.d.ts +4 -0
- package/dist/plus/integrations/models/integration.js +61 -16
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/models/issueRelationships.d.ts +31 -0
- package/dist/plus/integrations/models/issueRelationships.js +0 -0
- package/dist/plus/integrations/models/workItemWrites.d.ts +34 -2
- package/dist/plus/integrations/providers/azure/azure.js +1 -1
- package/dist/plus/integrations/providers/azureDevOps.d.ts +4 -3
- package/dist/plus/integrations/providers/azureDevOps.js +6 -6
- package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
- package/dist/plus/integrations/providers/azureDevOpsServer.d.ts +3 -0
- package/dist/plus/integrations/providers/azureDevOpsServer.js +14 -0
- package/dist/plus/integrations/providers/azureDevOpsServer.js.map +1 -1
- package/dist/plus/integrations/providers/azureWorkItemWriteErrors.d.ts +4 -0
- package/dist/plus/integrations/providers/azureWorkItemWriteErrors.js +34 -2
- package/dist/plus/integrations/providers/azureWorkItemWriteErrors.js.map +1 -1
- package/dist/plus/integrations/providers/azureWorkItemWrites.d.ts +5 -2
- package/dist/plus/integrations/providers/azureWorkItemWrites.js +57 -14
- package/dist/plus/integrations/providers/azureWorkItemWrites.js.map +1 -1
- package/dist/plus/integrations/providers/github.d.ts +8 -0
- package/dist/plus/integrations/providers/github.js +162 -2
- package/dist/plus/integrations/providers/github.js.map +1 -1
- package/dist/plus/integrations/providers/providerApiClient.d.ts +1 -1
- package/dist/plus/integrations/providers/providerApiClient.js +33 -14
- package/dist/plus/integrations/providers/providerApiClient.js.map +1 -1
- package/dist/plus/integrations/providers/providerErrors.d.ts +1 -0
- package/dist/plus/integrations/providers/providerErrors.js +1 -2
- package/dist/plus/integrations/providers/providerErrors.js.map +1 -1
- package/dist/plus/integrations/providers/providersApi.d.ts +10 -4
- package/dist/plus/integrations/providers/providersApi.js +21 -0
- package/dist/plus/integrations/providers/providersApi.js.map +1 -1
- package/dist/utils/env/node/exec.js +2 -2
- package/docs/integrations.md +61 -0
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { encodeAzurePathSegment } from "./azure/models.js";
|
|
2
2
|
import { getAzureWriteOrganizations, getAzureWriteProfile, isAzureGuid, isAzureIdentifier, isAzurePositiveInt, sameAzureIdentifier } from "./azure/writeIdentity.js";
|
|
3
|
-
import { WorkItemWriteError, toWorkItemWriteFailure } from "./azureWorkItemWriteErrors.js";
|
|
3
|
+
import { WorkItemWriteError, WorkItemWriteNotDispatchedError, toWorkItemWriteFailure } from "./azureWorkItemWriteErrors.js";
|
|
4
|
+
import { decodeAzurePathSegment } from "./azure/azure.utils.js";
|
|
4
5
|
import { getAzureWorkItemBodyField, getAzureWorkItemTransitionTargets, isAzureProjectPathField, isAzureTestArtifact, toAzureWorkItemWriteFields } from "./azure/workItemWriteMetadata.js";
|
|
5
6
|
//#region ../plus/integrations/src/providers/azureWorkItemWrites.ts
|
|
6
7
|
const projectSecurityNamespaceId = "52d39943-cb85-4d7f-8fa8-c6baac873819";
|
|
@@ -88,11 +89,25 @@ function getFieldPatches(input, fieldMetadata, projectName, current) {
|
|
|
88
89
|
if (errors.size) throw new WorkItemWriteError("invalid-input", Object.fromEntries(errors));
|
|
89
90
|
return patch;
|
|
90
91
|
}
|
|
92
|
+
async function readProject(request, headers, collectionUrl, projectId, apiVersion) {
|
|
93
|
+
const { body: project } = await request({
|
|
94
|
+
url: `${collectionUrl}/_apis/projects/${projectId}?api-version=${apiVersion}`,
|
|
95
|
+
headers,
|
|
96
|
+
redirect: "error"
|
|
97
|
+
});
|
|
98
|
+
if (!sameAzureIdentifier(project?.id, projectId) || !isAzureIdentifier(project?.name)) throw new WorkItemWriteError("not-found");
|
|
99
|
+
return {
|
|
100
|
+
id: project.id,
|
|
101
|
+
name: project.name
|
|
102
|
+
};
|
|
103
|
+
}
|
|
91
104
|
var AzureWorkItemWriter = class AzureWorkItemWriter {
|
|
92
105
|
request;
|
|
93
106
|
headers;
|
|
94
107
|
context;
|
|
95
108
|
organizationUrl;
|
|
109
|
+
apiVersion;
|
|
110
|
+
getStatesApiVersion;
|
|
96
111
|
isSessionCurrent;
|
|
97
112
|
static async connect(request, credential, options, isSessionCurrent) {
|
|
98
113
|
const { body: profile } = await getAzureWriteProfile(request, credential.accessToken);
|
|
@@ -103,32 +118,58 @@ var AzureWorkItemWriter = class AzureWorkItemWriter {
|
|
|
103
118
|
const organization = readValues(accounts).find((account) => sameAzureIdentifier(account.accountId, options.organizationId) && sameAzureIdentifier(account.accountName, options.organizationName));
|
|
104
119
|
if (organization == null) throw new WorkItemWriteError("not-found");
|
|
105
120
|
const organizationUrl = `https://dev.azure.com/${encodeAzurePathSegment(organization.accountName)}`;
|
|
106
|
-
const
|
|
107
|
-
|
|
121
|
+
const project = await readProject(request, headers, organizationUrl, options.projectId, "7.1");
|
|
122
|
+
return new AzureWorkItemWriter(request, headers, {
|
|
123
|
+
providerId: options.providerId,
|
|
124
|
+
connectionId: options.connectionId,
|
|
125
|
+
accountId,
|
|
126
|
+
organization: {
|
|
127
|
+
id: organization.accountId,
|
|
128
|
+
name: organization.accountName
|
|
129
|
+
},
|
|
130
|
+
project
|
|
131
|
+
}, organizationUrl, "7.1", () => Promise.resolve("7.1"), isSessionCurrent);
|
|
132
|
+
}
|
|
133
|
+
static async connectServer(request, authorization, options, collectionUrl, resolveApiVersion, resolveStatesApiVersion, isSessionCurrent) {
|
|
134
|
+
const headers = { Authorization: authorization };
|
|
135
|
+
const { body: data } = await request({
|
|
136
|
+
url: `${collectionUrl}/_apis/connectionData`,
|
|
108
137
|
headers,
|
|
109
138
|
redirect: "error"
|
|
110
139
|
});
|
|
111
|
-
|
|
140
|
+
const accountId = data?.authenticatedUser?.id;
|
|
141
|
+
const segment = typeof data?.webApplicationRelativeDirectory === "string" ? data.webApplicationRelativeDirectory.split("/").findLast(Boolean) : void 0;
|
|
142
|
+
const collectionName = segment != null ? decodeAzurePathSegment(segment) : void 0;
|
|
143
|
+
if (!isAzureGuid(data?.instanceId) || !sameAzureIdentifier(data.instanceId, options.organizationId) || collectionName == null || !sameAzureIdentifier(collectionName, options.organizationName)) throw new WorkItemWriteError("not-found");
|
|
144
|
+
if (!isAzureIdentifier(accountId) || options.expectedAccountId !== void 0 && !sameAzureIdentifier(accountId, options.expectedAccountId)) throw new WorkItemWriteError("no-connection");
|
|
145
|
+
const apiVersion = await resolveApiVersion();
|
|
146
|
+
if (apiVersion == null) throw new WorkItemWriteError("unsupported");
|
|
147
|
+
const project = await readProject(request, headers, collectionUrl, options.projectId, apiVersion);
|
|
148
|
+
let statesApiVersion;
|
|
112
149
|
return new AzureWorkItemWriter(request, headers, {
|
|
113
150
|
providerId: options.providerId,
|
|
114
151
|
connectionId: options.connectionId,
|
|
152
|
+
baseUrl: options.baseUrl,
|
|
115
153
|
accountId,
|
|
116
154
|
organization: {
|
|
117
|
-
id:
|
|
118
|
-
name:
|
|
155
|
+
id: data.instanceId,
|
|
156
|
+
name: collectionName,
|
|
157
|
+
url: collectionUrl
|
|
119
158
|
},
|
|
120
|
-
project
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
},
|
|
159
|
+
project
|
|
160
|
+
}, collectionUrl, apiVersion, () => statesApiVersion ??= resolveStatesApiVersion().then((version) => {
|
|
161
|
+
if (version == null) throw new WorkItemWriteError("unsupported");
|
|
162
|
+
return version;
|
|
163
|
+
}), isSessionCurrent);
|
|
125
164
|
}
|
|
126
165
|
projectUrl;
|
|
127
|
-
constructor(request, headers, context, organizationUrl, isSessionCurrent) {
|
|
166
|
+
constructor(request, headers, context, organizationUrl, apiVersion, getStatesApiVersion, isSessionCurrent) {
|
|
128
167
|
this.request = request;
|
|
129
168
|
this.headers = headers;
|
|
130
169
|
this.context = context;
|
|
131
170
|
this.organizationUrl = organizationUrl;
|
|
171
|
+
this.apiVersion = apiVersion;
|
|
172
|
+
this.getStatesApiVersion = getStatesApiVersion;
|
|
132
173
|
this.isSessionCurrent = isSessionCurrent;
|
|
133
174
|
this.projectUrl = `${organizationUrl}/${context.project.id}`;
|
|
134
175
|
}
|
|
@@ -241,6 +282,7 @@ var AzureWorkItemWriter = class AzureWorkItemWriter {
|
|
|
241
282
|
};
|
|
242
283
|
return await this.toDeleteOutcome(deleted, issue, options.expectedRevision);
|
|
243
284
|
} catch (ex) {
|
|
285
|
+
if (ex instanceof WorkItemWriteNotDispatchedError) return toWorkItemWriteFailure(ex);
|
|
244
286
|
return toWorkItemWriteFailure(ex, { fields: metadata.fields });
|
|
245
287
|
}
|
|
246
288
|
}
|
|
@@ -328,7 +370,7 @@ var AzureWorkItemWriter = class AzureWorkItemWriter {
|
|
|
328
370
|
]);
|
|
329
371
|
if (!sameAzureIdentifier(type?.name, name) || !isAzureIdentifier(type?.referenceName)) throw new WorkItemWriteError("unknown");
|
|
330
372
|
if (type.transitions == null || typeof type.transitions !== "object" || Array.isArray(type.transitions)) throw new WorkItemWriteError("unknown");
|
|
331
|
-
const states = Array.isArray(type.states) && type.states.length !== 0 ? type.states : readValues(await this.read(`${path}/states
|
|
373
|
+
const states = Array.isArray(type.states) && type.states.length !== 0 ? type.states : readValues(await this.read(`${path}/states`, { "api-version": await this.getStatesApiVersion() }));
|
|
332
374
|
if (states.some((state) => !isAzureIdentifier(state?.name) || !isAzureIdentifier(state.category))) throw new WorkItemWriteError("unknown");
|
|
333
375
|
const catalog = readValues(definitions);
|
|
334
376
|
return {
|
|
@@ -378,7 +420,7 @@ var AzureWorkItemWriter = class AzureWorkItemWriter {
|
|
|
378
420
|
}
|
|
379
421
|
url(path, params, base = `${this.projectUrl}/_apis/wit`) {
|
|
380
422
|
return `${base}${path}?${new URLSearchParams({
|
|
381
|
-
"api-version":
|
|
423
|
+
"api-version": this.apiVersion,
|
|
382
424
|
...params
|
|
383
425
|
}).toString()}`;
|
|
384
426
|
}
|
|
@@ -421,6 +463,7 @@ var AzureWorkItemWriter = class AzureWorkItemWriter {
|
|
|
421
463
|
issue: this.getReceipt(item, metadata)
|
|
422
464
|
};
|
|
423
465
|
} catch (ex) {
|
|
466
|
+
if (ex instanceof WorkItemWriteNotDispatchedError) return toWorkItemWriteFailure(ex);
|
|
424
467
|
return toWorkItemWriteFailure(ex, { fields: metadata.fields });
|
|
425
468
|
}
|
|
426
469
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"azureWorkItemWrites.js","names":[],"sources":["../../../../../plus/integrations/src/providers/azureWorkItemWrites.ts"],"sourcesContent":["import type {\n\tWorkItemAddress,\n\tWorkItemCreateOptions,\n\tWorkItemCreateOptionsResult,\n\tWorkItemDeleteCapability,\n\tWorkItemDeleteOptions,\n\tWorkItemDeleteResult,\n\tWorkItemReceipt,\n\tWorkItemState,\n\tWorkItemWriteContext,\n\tWorkItemWriteField,\n\tWorkItemWriteOptions,\n\tWorkItemWriteOptionsResult,\n\tWorkItemWriteResult,\n\tWorkItemWriteScope,\n\tWorkItemWriteTargetOptions,\n\tWorkItemWriteTargetResult,\n} from '../models/workItemWrites.js';\nimport { encodeAzurePathSegment } from './azure/models.js';\nimport type {\n\tAzureWorkItemFieldDefinition,\n\tAzureWorkItemTypeCategory,\n\tAzureWorkItemTypeField,\n\tAzureWorkItemTypeMetadata,\n} from './azure/workItemWriteMetadata.js';\nimport {\n\tgetAzureWorkItemBodyField,\n\tgetAzureWorkItemTransitionTargets,\n\tisAzureProjectPathField,\n\tisAzureTestArtifact,\n\ttoAzureWorkItemWriteFields,\n} from './azure/workItemWriteMetadata.js';\nimport {\n\tgetAzureWriteOrganizations,\n\tgetAzureWriteProfile,\n\tisAzureGuid,\n\tisAzureIdentifier,\n\tisAzurePositiveInt,\n\tsameAzureIdentifier,\n} from './azure/writeIdentity.js';\nimport { toWorkItemWriteFailure, WorkItemWriteError } from './azureWorkItemWriteErrors.js';\nimport type { ProviderRequestFunction } from './models.js';\n\ntype AzureWorkItem = { id: number; rev: number; fields: Readonly<Record<string, unknown>> };\ntype AzureDeletedWorkItem = {\n\tid?: unknown;\n\tproject?: unknown;\n\tdeletedDate?: unknown;\n\tcode?: unknown;\n\tresource?: { id?: unknown; rev?: unknown };\n};\ntype WorkItemMetadata = {\n\ttype: AzureWorkItemTypeMetadata;\n\tstates: readonly WorkItemState[];\n\tfields: readonly WorkItemWriteField[];\n\tcatalog: readonly AzureWorkItemFieldDefinition[];\n};\ntype Patch = { op: 'add' | 'test'; path: string; value: unknown } | { op: 'remove'; path: string };\n\nconst projectSecurityNamespaceId = '52d39943-cb85-4d7f-8fa8-c6baac873819';\n\nfunction isSameId(actual: unknown, id: number): boolean {\n\treturn actual === id || actual === String(id);\n}\n\nfunction isDeletedItem(\n\titem: AzureDeletedWorkItem | undefined,\n\tid: number,\n): item is AzureDeletedWorkItem & { project: string } {\n\tif (item == null || !isSameId(item.id, id) || !isAzureIdentifier(item.project)) return false;\n\n\treturn (\n\t\titem.code == null || item.code === 0 || (typeof item.code === 'number' && item.code >= 200 && item.code < 300)\n\t);\n}\n\nfunction getDeletedRevision(item: AzureDeletedWorkItem, id: number): number | undefined {\n\tconst resource = item.resource;\n\treturn resource != null && isSameId(resource.id, id) && isAzurePositiveInt(resource.rev) ? resource.rev : undefined;\n}\n\n// SEE: Azure reports `deletedDate` as a zone-less en-US UTC string (\"11/25/2026 6:24:35 PM\"), observed live.\nconst azureDeletedDate = /^(\\d{1,2})\\/(\\d{1,2})\\/([12]\\d{3}) (\\d{1,2}):([0-5]\\d):([0-5]\\d) (AM|PM)$/;\n\nfunction toDeletedAt(value: unknown): string | undefined {\n\tconst match = typeof value === 'string' ? azureDeletedDate.exec(value) : null;\n\tif (match == null) return undefined;\n\n\tconst [month, day, year, hour, minute, second] = match.slice(1, 7).map(Number);\n\tif (hour < 1 || hour > 12) return undefined;\n\n\tconst date = new Date(Date.UTC(year, month - 1, day, (hour % 12) + (match[7] === 'PM' ? 12 : 0), minute, second));\n\tif (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) {\n\t\treturn undefined;\n\t}\n\n\treturn date.toISOString();\n}\n\nfunction readValues<T>(body: { value?: T[] } | undefined): T[] {\n\tif (!Array.isArray(body?.value)) throw new WorkItemWriteError('unknown');\n\n\treturn body.value;\n}\n\nfunction assertExistingAddress(address: WorkItemAddress): void {\n\tif (!isAzurePositiveInt(address.workItemId)) throw new WorkItemWriteError('invalid-input');\n}\n\nfunction assertMutationIdentity(expectedAccountId: string): void {\n\tif (!isAzureIdentifier(expectedAccountId)) throw new WorkItemWriteError('invalid-input');\n}\n\nfunction assertSameRevision(item: AzureWorkItem, expectedRevision: number): void {\n\tif (!isAzurePositiveInt(expectedRevision)) throw new WorkItemWriteError('invalid-input');\n\tif (item.rev !== expectedRevision) throw new WorkItemWriteError('conflict');\n}\n\nfunction isJsonValue(value: unknown, ancestors = new Set<object>()): boolean {\n\tif (value == null) return value === null;\n\tif (typeof value === 'string' || typeof value === 'boolean') return true;\n\tif (typeof value === 'number') return Number.isFinite(value);\n\tif (typeof value !== 'object' || ancestors.has(value)) return false;\n\tif (\n\t\t!Array.isArray(value) &&\n\t\tObject.getPrototypeOf(value) !== Object.prototype &&\n\t\tObject.getPrototypeOf(value) !== null\n\t) {\n\t\treturn false;\n\t}\n\n\tancestors.add(value);\n\tconst valid = Object.values(value).every(entry => isJsonValue(entry, ancestors));\n\tancestors.delete(value);\n\treturn valid;\n}\n\nfunction isInProjectPath(value: unknown, projectName: string): boolean {\n\tif (typeof value !== 'string') return false;\n\n\tconst root = value.split('\\\\', 1)[0];\n\treturn root.toLowerCase() === projectName.toLowerCase();\n}\n\nfunction getFieldPatches(\n\tinput: Readonly<Record<string, unknown>>,\n\tfieldMetadata: readonly WorkItemWriteField[],\n\tprojectName: string,\n\tcurrent?: Readonly<Record<string, unknown>>,\n): Patch[] {\n\tif (input == null || typeof input !== 'object' || Array.isArray(input)) {\n\t\tthrow new WorkItemWriteError('invalid-input');\n\t}\n\n\tconst fields = new Map(fieldMetadata.map(field => [field.referenceName, field]));\n\tconst errors = new Map<string, string>();\n\tconst patch: Patch[] = [];\n\tfor (const [name, value] of Object.entries(input)) {\n\t\tconst field = fields.get(name);\n\t\tif (field == null || !isJsonValue(value)) {\n\t\t\terrors.set(name, field == null ? 'Field is unavailable for writing.' : 'Expected a JSON field value.');\n\t\t\tcontinue;\n\t\t}\n\t\tif (isAzureProjectPathField(name) && !isInProjectPath(value, projectName)) {\n\t\t\terrors.set(name, 'Expected a path in the selected project.');\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst path = `/fields/${name.replaceAll('~', '~0').replaceAll('/', '~1')}`;\n\t\tif (current != null && value === null) {\n\t\t\tif (Object.hasOwn(current, name)) {\n\t\t\t\tpatch.push({ op: 'remove', path: path });\n\t\t\t}\n\t\t} else {\n\t\t\tpatch.push({ op: 'add', path: path, value: value });\n\t\t}\n\t}\n\tif (current == null) {\n\t\tfor (const field of fieldMetadata) {\n\t\t\tconst value = Object.hasOwn(input, field.referenceName) ? input[field.referenceName] : undefined;\n\t\t\tif (\n\t\t\t\tfield.required &&\n\t\t\t\t(value === null || value === '' || (value === undefined && !Object.hasOwn(field, 'defaultValue')))\n\t\t\t) {\n\t\t\t\terrors.set(field.referenceName, 'This field is required.');\n\t\t\t}\n\t\t}\n\t}\n\tif (errors.size) throw new WorkItemWriteError('invalid-input', Object.fromEntries(errors));\n\n\treturn patch;\n}\n\nexport class AzureWorkItemWriter {\n\tstatic async connect(\n\t\trequest: ProviderRequestFunction,\n\t\tcredential: { accessToken: string; authorization: string },\n\t\toptions: WorkItemWriteScope,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t): Promise<AzureWorkItemWriter> {\n\t\tconst { body: profile } = await getAzureWriteProfile(request, credential.accessToken);\n\t\tconst accountId = profile?.id;\n\t\tif (\n\t\t\t!isAzureIdentifier(accountId) ||\n\t\t\t(options.expectedAccountId !== undefined && !sameAzureIdentifier(accountId, options.expectedAccountId))\n\t\t) {\n\t\t\tthrow new WorkItemWriteError('no-connection');\n\t\t}\n\n\t\tconst headers = { Authorization: credential.authorization };\n\t\tconst { body: accounts } = await getAzureWriteOrganizations(request, credential.authorization, accountId);\n\t\tconst organization = readValues(accounts).find(\n\t\t\taccount =>\n\t\t\t\tsameAzureIdentifier(account.accountId, options.organizationId) &&\n\t\t\t\tsameAzureIdentifier(account.accountName, options.organizationName),\n\t\t);\n\t\tif (organization == null) throw new WorkItemWriteError('not-found');\n\n\t\tconst organizationUrl = `https://dev.azure.com/${encodeAzurePathSegment(organization.accountName)}`;\n\t\tconst { body: project } = await request<{ id: string; name: string }>({\n\t\t\turl: `${organizationUrl}/_apis/projects/${options.projectId}?api-version=7.1`,\n\t\t\theaders: headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tif (!sameAzureIdentifier(project?.id, options.projectId) || !isAzureIdentifier(project?.name)) {\n\t\t\tthrow new WorkItemWriteError('not-found');\n\t\t}\n\n\t\treturn new AzureWorkItemWriter(\n\t\t\trequest,\n\t\t\theaders,\n\t\t\t{\n\t\t\t\tproviderId: options.providerId,\n\t\t\t\tconnectionId: options.connectionId,\n\t\t\t\taccountId: accountId,\n\t\t\t\torganization: { id: organization.accountId, name: organization.accountName },\n\t\t\t\tproject: { id: project.id, name: project.name },\n\t\t\t},\n\t\t\torganizationUrl,\n\t\t\tisSessionCurrent,\n\t\t);\n\t}\n\n\tprivate readonly projectUrl: string;\n\n\tprivate constructor(\n\t\tprivate readonly request: ProviderRequestFunction,\n\t\tprivate readonly headers: { Authorization: string },\n\t\tprivate readonly context: WorkItemWriteContext,\n\t\tprivate readonly organizationUrl: string,\n\t\tprivate readonly isSessionCurrent: () => Promise<boolean>,\n\t) {\n\t\tthis.projectUrl = `${organizationUrl}/${context.project.id}`;\n\t}\n\n\tasync getCreateOptions(options: WorkItemCreateOptions): Promise<WorkItemCreateOptionsResult> {\n\t\tif (options.workItemType === undefined) {\n\t\t\tconst types = await this.read<{ value?: AzureWorkItemTypeMetadata[] }>('/workitemtypes');\n\t\t\tconst enabled = readValues(types).filter(type => isAzureIdentifier(type.name) && !type.isDisabled);\n\t\t\treturn { ok: true, ...this.context, workItemTypes: enabled.map(type => ({ name: type.name })) };\n\t\t}\n\n\t\tconst { type, fields, states, catalog } = await this.getMetadata(options.workItemType);\n\t\tif (type.isDisabled) throw new WorkItemWriteError('invalid-input');\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\t...this.context,\n\t\t\tworkItemType: type.name,\n\t\t\tfields: fields,\n\t\t\tstates: states,\n\t\t\tinitialStates: getAzureWorkItemTransitionTargets(type, states, ''),\n\t\t\tbodyField: getAzureWorkItemBodyField(fields, catalog),\n\t\t};\n\t}\n\n\tasync getWriteOptions(options: WorkItemAddress): Promise<WorkItemWriteOptionsResult> {\n\t\tconst item = await this.getItem(options);\n\t\tconst metadata = await this.getMetadata(this.itemType(item));\n\t\tconst issue = this.getReceipt(item, metadata);\n\t\treturn {\n\t\t\tok: true,\n\t\t\t...this.context,\n\t\t\tissue: issue,\n\t\t\tfields: metadata.fields,\n\t\t\tavailableStates: getAzureWorkItemTransitionTargets(metadata.type, metadata.states, issue.state.name),\n\t\t\tdeleteCapability: await this.getDeleteCapability(metadata.type).catch((): WorkItemDeleteCapability => ({\n\t\t\t\tallowed: 'unknown',\n\t\t\t})),\n\t\t\tbodyField: issue.bodyField,\n\t\t};\n\t}\n\n\tasync resolveTarget(options: WorkItemWriteTargetOptions): Promise<WorkItemWriteTargetResult> {\n\t\tif (options.intent !== undefined && options.intent !== 'delete') throw new WorkItemWriteError('invalid-input');\n\n\t\tconst item = await this.getItem(options);\n\t\tconst metadata = await this.getMetadata(this.itemType(item));\n\t\tconst issue = this.getReceipt(item, metadata);\n\t\tconst deleteCapability =\n\t\t\toptions.intent === 'delete' ? await this.getDeleteCapability(metadata.type) : undefined;\n\t\tif (deleteCapability?.allowed === false) throw new WorkItemWriteError(deleteCapability.reason);\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\t...this.context,\n\t\t\tissue: issue,\n\t\t\t...(deleteCapability && { deleteCapability: deleteCapability }),\n\t\t};\n\t}\n\n\tasync write(options: WorkItemWriteOptions): Promise<WorkItemWriteResult> {\n\t\tassertMutationIdentity(options.expectedAccountId);\n\t\tif (options.action === 'create') return this.create(options);\n\n\t\tif (options.action !== 'edit' && options.action !== 'set-state') throw new WorkItemWriteError('invalid-input');\n\n\t\tconst item = await this.getItem(options);\n\t\tassertSameRevision(item, options.expectedRevision);\n\t\tconst metadata = await this.getMetadata(this.itemType(item));\n\t\tconst patch = getFieldPatches(options.fields ?? {}, metadata.fields, this.context.project.name, item.fields);\n\t\tif (options.action === 'set-state') {\n\t\t\tconst state = this.getReceipt(item, metadata).state.name;\n\t\t\tif (\n\t\t\t\t!getAzureWorkItemTransitionTargets(metadata.type, metadata.states, state).some(\n\t\t\t\t\ts => s.name === options.state,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthrow new WorkItemWriteError('transition-unavailable');\n\t\t\t}\n\n\t\t\tpatch.push({ op: 'add', path: '/fields/System.State', value: options.state });\n\t\t}\n\t\tif (!patch.length) throw new WorkItemWriteError('invalid-input');\n\n\t\tpatch.unshift({ op: 'test', path: '/rev', value: options.expectedRevision });\n\t\treturn this.save('PATCH', `/workitems/${item.id}`, patch, metadata, {\n\t\t\tid: item.id,\n\t\t\tstate: options.action === 'set-state' ? options.state : undefined,\n\t\t});\n\t}\n\n\tasync delete(options: WorkItemDeleteOptions): Promise<WorkItemDeleteResult> {\n\t\tassertMutationIdentity(options.expectedAccountId);\n\t\tconst item = await this.getItem(options);\n\t\tassertSameRevision(item, options.expectedRevision);\n\t\tconst metadata = await this.getMetadata(this.itemType(item));\n\t\tconst capability = await this.getDeleteCapability(metadata.type);\n\t\tif (capability.allowed === false) throw new WorkItemWriteError(capability.reason);\n\n\t\tawait this.assertSessionCurrent();\n\t\tconst current = await this.getItem(options);\n\t\tassertSameRevision(current, options.expectedRevision);\n\t\tif (this.itemType(current) !== metadata.type.name) throw new WorkItemWriteError('conflict');\n\n\t\tconst issue = this.getReceipt(current, metadata);\n\t\tawait this.assertSessionCurrent();\n\t\ttry {\n\t\t\tconst { body, status } = await this.request<AzureDeletedWorkItem>({\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\turl: this.url(`/workitems/${issue.id}`),\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t\tlet deleted =\n\t\t\t\tstatus === 200 && isDeletedItem(body, issue.id) && body.deletedDate != null ? body : undefined;\n\t\t\tif (deleted == null || getDeletedRevision(deleted, issue.id) === undefined) {\n\t\t\t\tconst recycled = await this.read<AzureDeletedWorkItem>(`/recyclebin/${issue.id}`).catch(\n\t\t\t\t\t() => undefined,\n\t\t\t\t);\n\t\t\t\tif (isDeletedItem(recycled, issue.id)) {\n\t\t\t\t\tdeleted = recycled;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (deleted == null) return { ok: false, reason: 'unknown', applied: 'maybe' };\n\n\t\t\treturn await this.toDeleteOutcome(deleted, issue, options.expectedRevision);\n\t\t} catch (ex) {\n\t\t\treturn toWorkItemWriteFailure(ex, { fields: metadata.fields });\n\t\t}\n\t}\n\n\tprivate async toDeleteOutcome(\n\t\tdeleted: AzureDeletedWorkItem & { project: string },\n\t\tissue: WorkItemReceipt,\n\t\texpectedRevision: number,\n\t): Promise<WorkItemDeleteResult> {\n\t\tconst revision = getDeletedRevision(deleted, issue.id);\n\t\tconst deletedAt = toDeletedAt(deleted.deletedDate);\n\t\tconst deletion = {\n\t\t\tdisposition: 'recycle-bin',\n\t\t\trestorable: true,\n\t\t\t...(revision !== undefined && { revision: revision }),\n\t\t\t...(deletedAt !== undefined && { deletedAt: deletedAt }),\n\t\t} as const;\n\t\tconst project = sameAzureIdentifier(\n\t\t\tdeleted.project,\n\t\t\tisAzureGuid(deleted.project) ? this.context.project.id : this.context.project.name,\n\t\t)\n\t\t\t? this.context.project\n\t\t\t: await this.findProject(deleted.project);\n\t\tif (sameAzureIdentifier(project.id, this.context.project.id) && revision === expectedRevision + 1) {\n\t\t\treturn { ok: true, ...this.context, issue: issue, deletion: { ...deletion, revision: revision } };\n\t\t}\n\n\t\treturn {\n\t\t\tok: false,\n\t\t\treason: 'target-changed',\n\t\t\tapplied: true,\n\t\t\t...this.context,\n\t\t\tdeleted: { id: issue.id, ...(revision !== undefined && { revision: revision }), project: project },\n\t\t\tdeletion: deletion,\n\t\t};\n\t}\n\n\tprivate async findProject(nameOrId: string): Promise<{ id?: string; name: string }> {\n\t\ttry {\n\t\t\tconst project = await this.readOrganization<{ id?: unknown; name?: unknown }>(\n\t\t\t\t`/projects/${encodeAzurePathSegment(nameOrId)}`,\n\t\t\t);\n\t\t\tif (\n\t\t\t\tisAzureGuid(project?.id) &&\n\t\t\t\tisAzureIdentifier(project.name) &&\n\t\t\t\t(sameAzureIdentifier(project.name, nameOrId) || sameAzureIdentifier(project.id, nameOrId))\n\t\t\t) {\n\t\t\t\treturn { id: project.id, name: project.name };\n\t\t\t}\n\t\t} catch {}\n\n\t\treturn { name: nameOrId };\n\t}\n\n\tprivate async create(options: Extract<WorkItemWriteOptions, { action: 'create' }>): Promise<WorkItemWriteResult> {\n\t\tconst metadata = await this.getMetadata(options.workItemType);\n\t\tif (metadata.type.isDisabled) throw new WorkItemWriteError('invalid-input');\n\n\t\tconst patch = getFieldPatches(options.fields, metadata.fields, this.context.project.name);\n\t\treturn this.save('POST', `/workitems/$${encodeAzurePathSegment(metadata.type.name)}`, patch, metadata);\n\t}\n\n\tprivate async getDeleteCapability(type: AzureWorkItemTypeMetadata): Promise<WorkItemDeleteCapability> {\n\t\tif (isAzureTestArtifact(type)) return { allowed: false, reason: 'unsupported' };\n\n\t\tconst categories = await this.read<{ value?: AzureWorkItemTypeCategory[] }>('/workitemtypecategories');\n\t\tif (isAzureTestArtifact(type, readValues(categories))) return { allowed: false, reason: 'unsupported' };\n\n\t\ttry {\n\t\t\tconst namespaces = await this.readOrganization<{\n\t\t\t\tvalue?: { namespaceId?: unknown; actions?: { bit?: unknown; name?: unknown }[] }[];\n\t\t\t}>(`/securitynamespaces/${projectSecurityNamespaceId}`);\n\t\t\tconst bit = readValues(namespaces)\n\t\t\t\t.find(namespace => sameAzureIdentifier(namespace?.namespaceId, projectSecurityNamespaceId))\n\t\t\t\t?.actions?.find(action => action?.name === 'WORK_ITEM_DELETE')?.bit;\n\t\t\tif (!isAzurePositiveInt(bit)) return { allowed: 'unknown' };\n\n\t\t\tconst permissions = await this.readOrganization<{ value?: unknown[] }>(\n\t\t\t\t`/permissions/${projectSecurityNamespaceId}/${bit}`,\n\t\t\t\t{\n\t\t\t\t\ttokens: `$PROJECT:vstfs:///Classification/TeamProject/${this.context.project.id}`,\n\t\t\t\t\talwaysAllowAdministrators: 'false',\n\t\t\t\t},\n\t\t\t);\n\t\t\tconst [allowed, ...rest] = readValues(permissions);\n\t\t\tif (typeof allowed !== 'boolean' || rest.length) return { allowed: 'unknown' };\n\n\t\t\treturn allowed ? { allowed: true } : { allowed: false, reason: 'forbidden' };\n\t\t} catch {\n\t\t\treturn { allowed: 'unknown' };\n\t\t}\n\t}\n\n\tprivate async getMetadata(name: string): Promise<WorkItemMetadata> {\n\t\tif (!isAzureIdentifier(name) || name === '.' || name === '..' || /[/\\\\]/.test(name)) {\n\t\t\tthrow new WorkItemWriteError('invalid-input');\n\t\t}\n\n\t\tconst path = `/workitemtypes/${encodeAzurePathSegment(name)}`;\n\t\tconst [type, typeFields, definitions] = await Promise.all([\n\t\t\tthis.read<AzureWorkItemTypeMetadata>(path),\n\t\t\tthis.read<{ value?: AzureWorkItemTypeField[] }>(`${path}/fields`, { $expand: 'All' }),\n\t\t\tthis.read<{ value?: AzureWorkItemFieldDefinition[] }>('/fields'),\n\t\t]);\n\t\tif (!sameAzureIdentifier(type?.name, name) || !isAzureIdentifier(type?.referenceName)) {\n\t\t\tthrow new WorkItemWriteError('unknown');\n\t\t}\n\t\tif (type.transitions == null || typeof type.transitions !== 'object' || Array.isArray(type.transitions)) {\n\t\t\tthrow new WorkItemWriteError('unknown');\n\t\t}\n\n\t\tconst states =\n\t\t\tArray.isArray(type.states) && type.states.length !== 0\n\t\t\t\t? type.states\n\t\t\t\t: readValues(await this.read<{ value?: WorkItemState[] }>(`${path}/states`));\n\t\tif (states.some(state => !isAzureIdentifier(state?.name) || !isAzureIdentifier(state.category))) {\n\t\t\tthrow new WorkItemWriteError('unknown');\n\t\t}\n\n\t\tconst catalog = readValues(definitions);\n\t\treturn {\n\t\t\ttype: type,\n\t\t\tstates: states.map(({ name, category, color }) => ({\n\t\t\t\tname: name,\n\t\t\t\tcategory: category,\n\t\t\t\t...(typeof color === 'string' && { color: color }),\n\t\t\t})),\n\t\t\tfields: toAzureWorkItemWriteFields(readValues(typeFields), catalog),\n\t\t\tcatalog: catalog,\n\t\t};\n\t}\n\n\tprivate async getItem(options: WorkItemAddress): Promise<AzureWorkItem> {\n\t\tassertExistingAddress(options);\n\t\tconst data = await this.read<AzureWorkItem>(`/workitems/${options.workItemId}`);\n\t\tif (!this.isInProject(data) || data.id !== options.workItemId) throw new WorkItemWriteError('not-found');\n\n\t\treturn data;\n\t}\n\n\tprivate isInProject(item: AzureWorkItem | undefined): item is AzureWorkItem {\n\t\treturn sameAzureIdentifier(item?.fields?.['System.TeamProject'], this.context.project.name);\n\t}\n\n\tprivate itemType(item: AzureWorkItem): string {\n\t\tconst type = item.fields['System.WorkItemType'];\n\t\tif (!isAzureIdentifier(type)) throw new WorkItemWriteError('unknown');\n\n\t\treturn type;\n\t}\n\n\tprivate getReceipt(item: AzureWorkItem, metadata: WorkItemMetadata): WorkItemReceipt {\n\t\tconst title = item.fields['System.Title'];\n\t\tconst state = metadata.states.find(candidate => candidate.name === item.fields['System.State']);\n\t\tif (\n\t\t\t!isAzurePositiveInt(item.id) ||\n\t\t\t!isAzurePositiveInt(item.rev) ||\n\t\t\ttypeof title !== 'string' ||\n\t\t\tstate == null ||\n\t\t\tthis.itemType(item) !== metadata.type.name\n\t\t) {\n\t\t\tthrow new WorkItemWriteError('unknown');\n\t\t}\n\n\t\treturn {\n\t\t\tid: item.id,\n\t\t\trevision: item.rev,\n\t\t\turl: `${this.projectUrl}/_workitems/edit/${item.id}`,\n\t\t\ttype: metadata.type.name,\n\t\t\ttitle: title,\n\t\t\tstate: { name: state.name, category: state.category },\n\t\t\tbodyField: getAzureWorkItemBodyField(metadata.fields, metadata.catalog, item.fields),\n\t\t};\n\t}\n\n\tprivate async assertSessionCurrent(): Promise<void> {\n\t\tif (!(await this.isSessionCurrent())) throw new WorkItemWriteError('no-connection');\n\t}\n\n\tprivate url(path: string, params?: Record<string, string>, base = `${this.projectUrl}/_apis/wit`): string {\n\t\treturn `${base}${path}?${new URLSearchParams({ 'api-version': '7.1', ...params }).toString()}`;\n\t}\n\n\tprivate read<T>(path: string, params?: Record<string, string>): Promise<T> {\n\t\treturn this.get<T>(this.url(path, params));\n\t}\n\n\tprivate readOrganization<T>(path: string, params?: Record<string, string>): Promise<T> {\n\t\treturn this.get<T>(this.url(path, params, `${this.organizationUrl}/_apis`));\n\t}\n\n\tprivate async get<T>(url: string): Promise<T> {\n\t\tconst { body } = await this.request<T>({ url: url, headers: this.headers, redirect: 'error' });\n\t\treturn body;\n\t}\n\n\tprivate async save(\n\t\tmethod: 'POST' | 'PATCH',\n\t\tpath: string,\n\t\tpatch: Patch[],\n\t\tmetadata: WorkItemMetadata,\n\t\texpected?: { id: number; state?: string },\n\t): Promise<WorkItemWriteResult> {\n\t\tconst body = JSON.stringify(patch);\n\t\tawait this.assertSessionCurrent();\n\t\ttry {\n\t\t\tconst { body: item } = await this.request<AzureWorkItem>({\n\t\t\t\tmethod: method,\n\t\t\t\turl: this.url(path),\n\t\t\t\theaders: { ...this.headers, 'Content-Type': 'application/json-patch+json' },\n\t\t\t\tbody: body,\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t\tif (\n\t\t\t\t!this.isInProject(item) ||\n\t\t\t\t(expected != null && item.id !== expected.id) ||\n\t\t\t\t(expected?.state !== undefined && item.fields['System.State'] !== expected.state)\n\t\t\t) {\n\t\t\t\treturn { ok: false, reason: 'unknown', applied: 'maybe' };\n\t\t\t}\n\n\t\t\treturn { ok: true, ...this.context, issue: this.getReceipt(item, metadata) };\n\t\t} catch (ex) {\n\t\t\treturn toWorkItemWriteFailure(ex, { fields: metadata.fields });\n\t\t}\n\t}\n}\n"],"mappings":";;;;;AA2DA,MAAM,6BAA6B;AAEnC,SAAS,SAAS,QAAiB,IAAqB;CACvD,OAAO,WAAW,MAAM,WAAW,OAAO,EAAE;AAC7C;AAEA,SAAS,cACR,MACA,IACqD;CACrD,IAAI,QAAQ,QAAQ,CAAC,SAAS,KAAK,IAAI,EAAE,KAAK,CAAC,kBAAkB,KAAK,OAAO,GAAG,OAAO;CAEvF,OACC,KAAK,QAAQ,QAAQ,KAAK,SAAS,KAAM,OAAO,KAAK,SAAS,YAAY,KAAK,QAAQ,OAAO,KAAK,OAAO;AAE5G;AAEA,SAAS,mBAAmB,MAA4B,IAAgC;CACvF,MAAM,WAAW,KAAK;CACtB,OAAO,YAAY,QAAQ,SAAS,SAAS,IAAI,EAAE,KAAK,mBAAmB,SAAS,GAAG,IAAI,SAAS,MAAM,KAAA;AAC3G;AAGA,MAAM,mBAAmB;AAEzB,SAAS,YAAY,OAAoC;CACxD,MAAM,QAAQ,OAAO,UAAU,WAAW,iBAAiB,KAAK,KAAK,IAAI;CACzE,IAAI,SAAS,MAAM,OAAO,KAAA;CAE1B,MAAM,CAAC,OAAO,KAAK,MAAM,MAAM,QAAQ,UAAU,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,MAAM;CA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ent":["import type {\n\tAzureServerWorkItemWriteScope,\n\tAzureServicesWorkItemWriteScope,\n\tWorkItemAddress,\n\tWorkItemCreateOptions,\n\tWorkItemCreateOptionsResult,\n\tWorkItemDeleteCapability,\n\tWorkItemDeleteOptions,\n\tWorkItemDeleteResult,\n\tWorkItemReceipt,\n\tWorkItemState,\n\tWorkItemWriteContext,\n\tWorkItemWriteField,\n\tWorkItemWriteOptions,\n\tWorkItemWriteOptionsResult,\n\tWorkItemWriteResult,\n\tWorkItemWriteTargetOptions,\n\tWorkItemWriteTargetResult,\n} from '../models/workItemWrites.js';\nimport { decodeAzurePathSegment } from './azure/azure.utils.js';\nimport { encodeAzurePathSegment } from './azure/models.js';\nimport type {\n\tAzureWorkItemFieldDefinition,\n\tAzureWorkItemTypeCategory,\n\tAzureWorkItemTypeField,\n\tAzureWorkItemTypeMetadata,\n} from './azure/workItemWriteMetadata.js';\nimport {\n\tgetAzureWorkItemBodyField,\n\tgetAzureWorkItemTransitionTargets,\n\tisAzureProjectPathField,\n\tisAzureTestArtifact,\n\ttoAzureWorkItemWriteFields,\n} from './azure/workItemWriteMetadata.js';\nimport {\n\tgetAzureWriteOrganizations,\n\tgetAzureWriteProfile,\n\tisAzureGuid,\n\tisAzureIdentifier,\n\tisAzurePositiveInt,\n\tsameAzureIdentifier,\n} from './azure/writeIdentity.js';\nimport {\n\ttoWorkItemWriteFailure,\n\tWorkItemWriteError,\n\tWorkItemWriteNotDispatchedError,\n} from './azureWorkItemWriteErrors.js';\nimport type { ProviderRequestFunction } from './models.js';\n\ntype AzureWorkItem = { id: number; rev: number; fields: Readonly<Record<string, unknown>> };\ntype AzureDeletedWorkItem = {\n\tid?: unknown;\n\tproject?: unknown;\n\tdeletedDate?: unknown;\n\tcode?: unknown;\n\tresource?: { id?: unknown; rev?: unknown };\n};\ntype WorkItemMetadata = {\n\ttype: AzureWorkItemTypeMetadata;\n\tstates: readonly WorkItemState[];\n\tfields: readonly WorkItemWriteField[];\n\tcatalog: readonly AzureWorkItemFieldDefinition[];\n};\ntype Patch = { op: 'add' | 'test'; path: string; value: unknown } | { op: 'remove'; path: string };\n\ntype AzureServerConnectionData = {\n\tinstanceId?: unknown;\n\twebApplicationRelativeDirectory?: unknown;\n\tauthenticatedUser?: { id?: unknown };\n};\n\nconst projectSecurityNamespaceId = '52d39943-cb85-4d7f-8fa8-c6baac873819';\n\nfunction isSameId(actual: unknown, id: number): boolean {\n\treturn actual === id || actual === String(id);\n}\n\nfunction isDeletedItem(\n\titem: AzureDeletedWorkItem | undefined,\n\tid: number,\n): item is AzureDeletedWorkItem & { project: string } {\n\tif (item == null || !isSameId(item.id, id) || !isAzureIdentifier(item.project)) return false;\n\n\treturn (\n\t\titem.code == null || item.code === 0 || (typeof item.code === 'number' && item.code >= 200 && item.code < 300)\n\t);\n}\n\nfunction getDeletedRevision(item: AzureDeletedWorkItem, id: number): number | undefined {\n\tconst resource = item.resource;\n\treturn resource != null && isSameId(resource.id, id) && isAzurePositiveInt(resource.rev) ? resource.rev : undefined;\n}\n\n// SEE: Azure reports `deletedDate` as a zone-less en-US UTC string (\"11/25/2026 6:24:35 PM\"), observed live.\nconst azureDeletedDate = /^(\\d{1,2})\\/(\\d{1,2})\\/([12]\\d{3}) (\\d{1,2}):([0-5]\\d):([0-5]\\d) (AM|PM)$/;\n\nfunction toDeletedAt(value: unknown): string | undefined {\n\tconst match = typeof value === 'string' ? azureDeletedDate.exec(value) : null;\n\tif (match == null) return undefined;\n\n\tconst [month, day, year, hour, minute, second] = match.slice(1, 7).map(Number);\n\tif (hour < 1 || hour > 12) return undefined;\n\n\tconst date = new Date(Date.UTC(year, month - 1, day, (hour % 12) + (match[7] === 'PM' ? 12 : 0), minute, second));\n\tif (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) {\n\t\treturn undefined;\n\t}\n\n\treturn date.toISOString();\n}\n\nfunction readValues<T>(body: { value?: T[] } | undefined): T[] {\n\tif (!Array.isArray(body?.value)) throw new WorkItemWriteError('unknown');\n\n\treturn body.value;\n}\n\nfunction assertExistingAddress(address: WorkItemAddress): void {\n\tif (!isAzurePositiveInt(address.workItemId)) throw new WorkItemWriteError('invalid-input');\n}\n\nfunction assertMutationIdentity(expectedAccountId: string): void {\n\tif (!isAzureIdentifier(expectedAccountId)) throw new WorkItemWriteError('invalid-input');\n}\n\nfunction assertSameRevision(item: AzureWorkItem, expectedRevision: number): void {\n\tif (!isAzurePositiveInt(expectedRevision)) throw new WorkItemWriteError('invalid-input');\n\tif (item.rev !== expectedRevision) throw new WorkItemWriteError('conflict');\n}\n\nfunction isJsonValue(value: unknown, ancestors = new Set<object>()): boolean {\n\tif (value == null) return value === null;\n\tif (typeof value === 'string' || typeof value === 'boolean') return true;\n\tif (typeof value === 'number') return Number.isFinite(value);\n\tif (typeof value !== 'object' || ancestors.has(value)) return false;\n\tif (\n\t\t!Array.isArray(value) &&\n\t\tObject.getPrototypeOf(value) !== Object.prototype &&\n\t\tObject.getPrototypeOf(value) !== null\n\t) {\n\t\treturn false;\n\t}\n\n\tancestors.add(value);\n\tconst valid = Object.values(value).every(entry => isJsonValue(entry, ancestors));\n\tancestors.delete(value);\n\treturn valid;\n}\n\nfunction isInProjectPath(value: unknown, projectName: string): boolean {\n\tif (typeof value !== 'string') return false;\n\n\tconst root = value.split('\\\\', 1)[0];\n\treturn root.toLowerCase() === projectName.toLowerCase();\n}\n\nfunction getFieldPatches(\n\tinput: Readonly<Record<string, unknown>>,\n\tfieldMetadata: readonly WorkItemWriteField[],\n\tprojectName: string,\n\tcurrent?: Readonly<Record<string, unknown>>,\n): Patch[] {\n\tif (input == null || typeof input !== 'object' || Array.isArray(input)) {\n\t\tthrow new WorkItemWriteError('invalid-input');\n\t}\n\n\tconst fields = new Map(fieldMetadata.map(field => [field.referenceName, field]));\n\tconst errors = new Map<string, string>();\n\tconst patch: Patch[] = [];\n\tfor (const [name, value] of Object.entries(input)) {\n\t\tconst field = fields.get(name);\n\t\tif (field == null || !isJsonValue(value)) {\n\t\t\terrors.set(name, field == null ? 'Field is unavailable for writing.' : 'Expected a JSON field value.');\n\t\t\tcontinue;\n\t\t}\n\t\tif (isAzureProjectPathField(name) && !isInProjectPath(value, projectName)) {\n\t\t\terrors.set(name, 'Expected a path in the selected project.');\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst path = `/fields/${name.replaceAll('~', '~0').replaceAll('/', '~1')}`;\n\t\tif (current != null && value === null) {\n\t\t\tif (Object.hasOwn(current, name)) {\n\t\t\t\tpatch.push({ op: 'remove', path: path });\n\t\t\t}\n\t\t} else {\n\t\t\tpatch.push({ op: 'add', path: path, value: value });\n\t\t}\n\t}\n\tif (current == null) {\n\t\tfor (const field of fieldMetadata) {\n\t\t\tconst value = Object.hasOwn(input, field.referenceName) ? input[field.referenceName] : undefined;\n\t\t\tif (\n\t\t\t\tfield.required &&\n\t\t\t\t(value === null || value === '' || (value === undefined && !Object.hasOwn(field, 'defaultValue')))\n\t\t\t) {\n\t\t\t\terrors.set(field.referenceName, 'This field is required.');\n\t\t\t}\n\t\t}\n\t}\n\tif (errors.size) throw new WorkItemWriteError('invalid-input', Object.fromEntries(errors));\n\n\treturn patch;\n}\n\nasync function readProject(\n\trequest: ProviderRequestFunction,\n\theaders: { Authorization: string },\n\tcollectionUrl: string,\n\tprojectId: string,\n\tapiVersion: string,\n): Promise<{ id: string; name: string }> {\n\tconst { body: project } = await request<{ id?: unknown; name?: unknown }>({\n\t\turl: `${collectionUrl}/_apis/projects/${projectId}?api-version=${apiVersion}`,\n\t\theaders: headers,\n\t\tredirect: 'error',\n\t});\n\tif (!sameAzureIdentifier(project?.id, projectId) || !isAzureIdentifier(project?.name)) {\n\t\tthrow new WorkItemWriteError('not-found');\n\t}\n\n\treturn { id: project.id as string, name: project.name };\n}\n\nexport class AzureWorkItemWriter {\n\tstatic async connect(\n\t\trequest: ProviderRequestFunction,\n\t\tcredential: { accessToken: string; authorization: string },\n\t\toptions: AzureServicesWorkItemWriteScope,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t): Promise<AzureWorkItemWriter> {\n\t\tconst { body: profile } = await getAzureWriteProfile(request, credential.accessToken);\n\t\tconst accountId = profile?.id;\n\t\tif (\n\t\t\t!isAzureIdentifier(accountId) ||\n\t\t\t(options.expectedAccountId !== undefined && !sameAzureIdentifier(accountId, options.expectedAccountId))\n\t\t) {\n\t\t\tthrow new WorkItemWriteError('no-connection');\n\t\t}\n\n\t\tconst headers = { Authorization: credential.authorization };\n\t\tconst { body: accounts } = await getAzureWriteOrganizations(request, credential.authorization, accountId);\n\t\tconst organization = readValues(accounts).find(\n\t\t\taccount =>\n\t\t\t\tsameAzureIdentifier(account.accountId, options.organizationId) &&\n\t\t\t\tsameAzureIdentifier(account.accountName, options.organizationName),\n\t\t);\n\t\tif (organization == null) throw new WorkItemWriteError('not-found');\n\n\t\tconst organizationUrl = `https://dev.azure.com/${encodeAzurePathSegment(organization.accountName)}`;\n\t\tconst project = await readProject(request, headers, organizationUrl, options.projectId, '7.1');\n\t\treturn new AzureWorkItemWriter(\n\t\t\trequest,\n\t\t\theaders,\n\t\t\t{\n\t\t\t\tproviderId: options.providerId,\n\t\t\t\tconnectionId: options.connectionId,\n\t\t\t\taccountId: accountId,\n\t\t\t\torganization: { id: organization.accountId, name: organization.accountName },\n\t\t\t\tproject: project,\n\t\t\t},\n\t\t\torganizationUrl,\n\t\t\t'7.1',\n\t\t\t() => Promise.resolve('7.1'),\n\t\t\tisSessionCurrent,\n\t\t);\n\t}\n\n\tstatic async connectServer(\n\t\trequest: ProviderRequestFunction,\n\t\tauthorization: string,\n\t\toptions: AzureServerWorkItemWriteScope,\n\t\tcollectionUrl: string,\n\t\tresolveApiVersion: () => Promise<string | undefined>,\n\t\tresolveStatesApiVersion: () => Promise<string | undefined>,\n\t\tisSessionCurrent: () => Promise<boolean>,\n\t): Promise<AzureWorkItemWriter> {\n\t\tconst headers = { Authorization: authorization };\n\t\tconst { body: data } = await request<AzureServerConnectionData>({\n\t\t\turl: `${collectionUrl}/_apis/connectionData`,\n\t\t\theaders: headers,\n\t\t\tredirect: 'error',\n\t\t});\n\t\tconst accountId = data?.authenticatedUser?.id;\n\t\tconst segment =\n\t\t\ttypeof data?.webApplicationRelativeDirectory === 'string'\n\t\t\t\t? data.webApplicationRelativeDirectory.split('/').findLast(Boolean)\n\t\t\t\t: undefined;\n\t\tconst collectionName = segment != null ? decodeAzurePathSegment(segment) : undefined;\n\t\tif (\n\t\t\t!isAzureGuid(data?.instanceId) ||\n\t\t\t!sameAzureIdentifier(data.instanceId, options.organizationId) ||\n\t\t\tcollectionName == null ||\n\t\t\t!sameAzureIdentifier(collectionName, options.organizationName)\n\t\t) {\n\t\t\tthrow new WorkItemWriteError('not-found');\n\t\t}\n\t\tif (\n\t\t\t!isAzureIdentifier(accountId) ||\n\t\t\t(options.expectedAccountId !== undefined && !sameAzureIdentifier(accountId, options.expectedAccountId))\n\t\t) {\n\t\t\tthrow new WorkItemWriteError('no-connection');\n\t\t}\n\n\t\tconst apiVersion = await resolveApiVersion();\n\t\tif (apiVersion == null) throw new WorkItemWriteError('unsupported');\n\n\t\tconst project = await readProject(request, headers, collectionUrl, options.projectId, apiVersion);\n\t\tlet statesApiVersion: Promise<string> | undefined;\n\t\treturn new AzureWorkItemWriter(\n\t\t\trequest,\n\t\t\theaders,\n\t\t\t{\n\t\t\t\tproviderId: options.providerId,\n\t\t\t\tconnectionId: options.connectionId,\n\t\t\t\tbaseUrl: options.baseUrl,\n\t\t\t\taccountId: accountId,\n\t\t\t\torganization: { id: data.instanceId, name: collectionName, url: collectionUrl },\n\t\t\t\tproject: project,\n\t\t\t},\n\t\t\tcollectionUrl,\n\t\t\tapiVersion,\n\t\t\t() =>\n\t\t\t\t(statesApiVersion ??= resolveStatesApiVersion().then(version => {\n\t\t\t\t\tif (version == null) throw new WorkItemWriteError('unsupported');\n\n\t\t\t\t\treturn version;\n\t\t\t\t})),\n\t\t\tisSessionCurrent,\n\t\t);\n\t}\n\n\tprivate readonly projectUrl: string;\n\n\tprivate constructor(\n\t\tprivate readonly request: ProviderRequestFunction,\n\t\tprivate readonly headers: { Authorization: string },\n\t\tprivate readonly context: WorkItemWriteContext,\n\t\tprivate readonly organizationUrl: string,\n\t\tprivate readonly apiVersion: string,\n\t\tprivate readonly getStatesApiVersion: () => Promise<string>,\n\t\tprivate readonly isSessionCurrent: () => Promise<boolean>,\n\t) {\n\t\tthis.projectUrl = `${organizationUrl}/${context.project.id}`;\n\t}\n\n\tasync getCreateOptions(options: WorkItemCreateOptions): Promise<WorkItemCreateOptionsResult> {\n\t\tif (options.workItemType === undefined) {\n\t\t\tconst types = await this.read<{ value?: AzureWorkItemTypeMetadata[] }>('/workitemtypes');\n\t\t\tconst enabled = readValues(types).filter(type => isAzureIdentifier(type.name) && !type.isDisabled);\n\t\t\treturn { ok: true, ...this.context, workItemTypes: enabled.map(type => ({ name: type.name })) };\n\t\t}\n\n\t\tconst { type, fields, states, catalog } = await this.getMetadata(options.workItemType);\n\t\tif (type.isDisabled) throw new WorkItemWriteError('invalid-input');\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\t...this.context,\n\t\t\tworkItemType: type.name,\n\t\t\tfields: fields,\n\t\t\tstates: states,\n\t\t\tinitialStates: getAzureWorkItemTransitionTargets(type, states, ''),\n\t\t\tbodyField: getAzureWorkItemBodyField(fields, catalog),\n\t\t};\n\t}\n\n\tasync getWriteOptions(options: WorkItemAddress): Promise<WorkItemWriteOptionsResult> {\n\t\tconst item = await this.getItem(options);\n\t\tconst metadata = await this.getMetadata(this.itemType(item));\n\t\tconst issue = this.getReceipt(item, metadata);\n\t\treturn {\n\t\t\tok: true,\n\t\t\t...this.context,\n\t\t\tissue: issue,\n\t\t\tfields: metadata.fields,\n\t\t\tavailableStates: getAzureWorkItemTransitionTargets(metadata.type, metadata.states, issue.state.name),\n\t\t\tdeleteCapability: await this.getDeleteCapability(metadata.type).catch((): WorkItemDeleteCapability => ({\n\t\t\t\tallowed: 'unknown',\n\t\t\t})),\n\t\t\tbodyField: issue.bodyField,\n\t\t};\n\t}\n\n\tasync resolveTarget(options: WorkItemWriteTargetOptions): Promise<WorkItemWriteTargetResult> {\n\t\tif (options.intent !== undefined && options.intent !== 'delete') throw new WorkItemWriteError('invalid-input');\n\n\t\tconst item = await this.getItem(options);\n\t\tconst metadata = await this.getMetadata(this.itemType(item));\n\t\tconst issue = this.getReceipt(item, metadata);\n\t\tconst deleteCapability =\n\t\t\toptions.intent === 'delete' ? await this.getDeleteCapability(metadata.type) : undefined;\n\t\tif (deleteCapability?.allowed === false) throw new WorkItemWriteError(deleteCapability.reason);\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\t...this.context,\n\t\t\tissue: issue,\n\t\t\t...(deleteCapability && { deleteCapability: deleteCapability }),\n\t\t};\n\t}\n\n\tasync write(options: WorkItemWriteOptions): Promise<WorkItemWriteResult> {\n\t\tassertMutationIdentity(options.expectedAccountId);\n\t\tif (options.action === 'create') return this.create(options);\n\n\t\tif (options.action !== 'edit' && options.action !== 'set-state') throw new WorkItemWriteError('invalid-input');\n\n\t\tconst item = await this.getItem(options);\n\t\tassertSameRevision(item, options.expectedRevision);\n\t\tconst metadata = await this.getMetadata(this.itemType(item));\n\t\tconst patch = getFieldPatches(options.fields ?? {}, metadata.fields, this.context.project.name, item.fields);\n\t\tif (options.action === 'set-state') {\n\t\t\tconst state = this.getReceipt(item, metadata).state.name;\n\t\t\tif (\n\t\t\t\t!getAzureWorkItemTransitionTargets(metadata.type, metadata.states, state).some(\n\t\t\t\t\ts => s.name === options.state,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthrow new WorkItemWriteError('transition-unavailable');\n\t\t\t}\n\n\t\t\tpatch.push({ op: 'add', path: '/fields/System.State', value: options.state });\n\t\t}\n\t\tif (!patch.length) throw new WorkItemWriteError('invalid-input');\n\n\t\tpatch.unshift({ op: 'test', path: '/rev', value: options.expectedRevision });\n\t\treturn this.save('PATCH', `/workitems/${item.id}`, patch, metadata, {\n\t\t\tid: item.id,\n\t\t\tstate: options.action === 'set-state' ? options.state : undefined,\n\t\t});\n\t}\n\n\tasync delete(options: WorkItemDeleteOptions): Promise<WorkItemDeleteResult> {\n\t\tassertMutationIdentity(options.expectedAccountId);\n\t\tconst item = await this.getItem(options);\n\t\tassertSameRevision(item, options.expectedRevision);\n\t\tconst metadata = await this.getMetadata(this.itemType(item));\n\t\tconst capability = await this.getDeleteCapability(metadata.type);\n\t\tif (capability.allowed === false) throw new WorkItemWriteError(capability.reason);\n\n\t\tawait this.assertSessionCurrent();\n\t\tconst current = await this.getItem(options);\n\t\tassertSameRevision(current, options.expectedRevision);\n\t\tif (this.itemType(current) !== metadata.type.name) throw new WorkItemWriteError('conflict');\n\n\t\tconst issue = this.getReceipt(current, metadata);\n\t\tawait this.assertSessionCurrent();\n\t\ttry {\n\t\t\tconst { body, status } = await this.request<AzureDeletedWorkItem>({\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\turl: this.url(`/workitems/${issue.id}`),\n\t\t\t\theaders: this.headers,\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t\tlet deleted =\n\t\t\t\tstatus === 200 && isDeletedItem(body, issue.id) && body.deletedDate != null ? body : undefined;\n\t\t\tif (deleted == null || getDeletedRevision(deleted, issue.id) === undefined) {\n\t\t\t\tconst recycled = await this.read<AzureDeletedWorkItem>(`/recyclebin/${issue.id}`).catch(\n\t\t\t\t\t() => undefined,\n\t\t\t\t);\n\t\t\t\tif (isDeletedItem(recycled, issue.id)) {\n\t\t\t\t\tdeleted = recycled;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (deleted == null) return { ok: false, reason: 'unknown', applied: 'maybe' };\n\n\t\t\treturn await this.toDeleteOutcome(deleted, issue, options.expectedRevision);\n\t\t} catch (ex) {\n\t\t\tif (ex instanceof WorkItemWriteNotDispatchedError) return toWorkItemWriteFailure(ex);\n\n\t\t\treturn toWorkItemWriteFailure(ex, { fields: metadata.fields });\n\t\t}\n\t}\n\n\tprivate async toDeleteOutcome(\n\t\tdeleted: AzureDeletedWorkItem & { project: string },\n\t\tissue: WorkItemReceipt,\n\t\texpectedRevision: number,\n\t): Promise<WorkItemDeleteResult> {\n\t\tconst revision = getDeletedRevision(deleted, issue.id);\n\t\tconst deletedAt = toDeletedAt(deleted.deletedDate);\n\t\tconst deletion = {\n\t\t\tdisposition: 'recycle-bin',\n\t\t\trestorable: true,\n\t\t\t...(revision !== undefined && { revision: revision }),\n\t\t\t...(deletedAt !== undefined && { deletedAt: deletedAt }),\n\t\t} as const;\n\t\tconst project = sameAzureIdentifier(\n\t\t\tdeleted.project,\n\t\t\tisAzureGuid(deleted.project) ? this.context.project.id : this.context.project.name,\n\t\t)\n\t\t\t? this.context.project\n\t\t\t: await this.findProject(deleted.project);\n\t\tif (sameAzureIdentifier(project.id, this.context.project.id) && revision === expectedRevision + 1) {\n\t\t\treturn { ok: true, ...this.context, issue: issue, deletion: { ...deletion, revision: revision } };\n\t\t}\n\n\t\treturn {\n\t\t\tok: false,\n\t\t\treason: 'target-changed',\n\t\t\tapplied: true,\n\t\t\t...this.context,\n\t\t\tdeleted: { id: issue.id, ...(revision !== undefined && { revision: revision }), project: project },\n\t\t\tdeletion: deletion,\n\t\t};\n\t}\n\n\tprivate async findProject(nameOrId: string): Promise<{ id?: string; name: string }> {\n\t\ttry {\n\t\t\tconst project = await this.readOrganization<{ id?: unknown; name?: unknown }>(\n\t\t\t\t`/projects/${encodeAzurePathSegment(nameOrId)}`,\n\t\t\t);\n\t\t\tif (\n\t\t\t\tisAzureGuid(project?.id) &&\n\t\t\t\tisAzureIdentifier(project.name) &&\n\t\t\t\t(sameAzureIdentifier(project.name, nameOrId) || sameAzureIdentifier(project.id, nameOrId))\n\t\t\t) {\n\t\t\t\treturn { id: project.id, name: project.name };\n\t\t\t}\n\t\t} catch {}\n\n\t\treturn { name: nameOrId };\n\t}\n\n\tprivate async create(options: Extract<WorkItemWriteOptions, { action: 'create' }>): Promise<WorkItemWriteResult> {\n\t\tconst metadata = await this.getMetadata(options.workItemType);\n\t\tif (metadata.type.isDisabled) throw new WorkItemWriteError('invalid-input');\n\n\t\tconst patch = getFieldPatches(options.fields, metadata.fields, this.context.project.name);\n\t\treturn this.save('POST', `/workitems/$${encodeAzurePathSegment(metadata.type.name)}`, patch, metadata);\n\t}\n\n\tprivate async getDeleteCapability(type: AzureWorkItemTypeMetadata): Promise<WorkItemDeleteCapability> {\n\t\tif (isAzureTestArtifact(type)) return { allowed: false, reason: 'unsupported' };\n\n\t\tconst categories = await this.read<{ value?: AzureWorkItemTypeCategory[] }>('/workitemtypecategories');\n\t\tif (isAzureTestArtifact(type, readValues(categories))) return { allowed: false, reason: 'unsupported' };\n\n\t\ttry {\n\t\t\tconst namespaces = await this.readOrganization<{\n\t\t\t\tvalue?: { namespaceId?: unknown; actions?: { bit?: unknown; name?: unknown }[] }[];\n\t\t\t}>(`/securitynamespaces/${projectSecurityNamespaceId}`);\n\t\t\tconst bit = readValues(namespaces)\n\t\t\t\t.find(namespace => sameAzureIdentifier(namespace?.namespaceId, projectSecurityNamespaceId))\n\t\t\t\t?.actions?.find(action => action?.name === 'WORK_ITEM_DELETE')?.bit;\n\t\t\tif (!isAzurePositiveInt(bit)) return { allowed: 'unknown' };\n\n\t\t\tconst permissions = await this.readOrganization<{ value?: unknown[] }>(\n\t\t\t\t`/permissions/${projectSecurityNamespaceId}/${bit}`,\n\t\t\t\t{\n\t\t\t\t\ttokens: `$PROJECT:vstfs:///Classification/TeamProject/${this.context.project.id}`,\n\t\t\t\t\talwaysAllowAdministrators: 'false',\n\t\t\t\t},\n\t\t\t);\n\t\t\tconst [allowed, ...rest] = readValues(permissions);\n\t\t\tif (typeof allowed !== 'boolean' || rest.length) return { allowed: 'unknown' };\n\n\t\t\treturn allowed ? { allowed: true } : { allowed: false, reason: 'forbidden' };\n\t\t} catch {\n\t\t\treturn { allowed: 'unknown' };\n\t\t}\n\t}\n\n\tprivate async getMetadata(name: string): Promise<WorkItemMetadata> {\n\t\tif (!isAzureIdentifier(name) || name === '.' || name === '..' || /[/\\\\]/.test(name)) {\n\t\t\tthrow new WorkItemWriteError('invalid-input');\n\t\t}\n\n\t\tconst path = `/workitemtypes/${encodeAzurePathSegment(name)}`;\n\t\tconst [type, typeFields, definitions] = await Promise.all([\n\t\t\tthis.read<AzureWorkItemTypeMetadata>(path),\n\t\t\tthis.read<{ value?: AzureWorkItemTypeField[] }>(`${path}/fields`, { $expand: 'All' }),\n\t\t\tthis.read<{ value?: AzureWorkItemFieldDefinition[] }>('/fields'),\n\t\t]);\n\t\tif (!sameAzureIdentifier(type?.name, name) || !isAzureIdentifier(type?.referenceName)) {\n\t\t\tthrow new WorkItemWriteError('unknown');\n\t\t}\n\t\tif (type.transitions == null || typeof type.transitions !== 'object' || Array.isArray(type.transitions)) {\n\t\t\tthrow new WorkItemWriteError('unknown');\n\t\t}\n\n\t\tconst states =\n\t\t\tArray.isArray(type.states) && type.states.length !== 0\n\t\t\t\t? type.states\n\t\t\t\t: readValues(\n\t\t\t\t\t\tawait this.read<{ value?: WorkItemState[] }>(`${path}/states`, {\n\t\t\t\t\t\t\t'api-version': await this.getStatesApiVersion(),\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\tif (states.some(state => !isAzureIdentifier(state?.name) || !isAzureIdentifier(state.category))) {\n\t\t\tthrow new WorkItemWriteError('unknown');\n\t\t}\n\n\t\tconst catalog = readValues(definitions);\n\t\treturn {\n\t\t\ttype: type,\n\t\t\tstates: states.map(({ name, category, color }) => ({\n\t\t\t\tname: name,\n\t\t\t\tcategory: category,\n\t\t\t\t...(typeof color === 'string' && { color: color }),\n\t\t\t})),\n\t\t\tfields: toAzureWorkItemWriteFields(readValues(typeFields), catalog),\n\t\t\tcatalog: catalog,\n\t\t};\n\t}\n\n\tprivate async getItem(options: WorkItemAddress): Promise<AzureWorkItem> {\n\t\tassertExistingAddress(options);\n\t\tconst data = await this.read<AzureWorkItem>(`/workitems/${options.workItemId}`);\n\t\tif (!this.isInProject(data) || data.id !== options.workItemId) throw new WorkItemWriteError('not-found');\n\n\t\treturn data;\n\t}\n\n\tprivate isInProject(item: AzureWorkItem | undefined): item is AzureWorkItem {\n\t\treturn sameAzureIdentifier(item?.fields?.['System.TeamProject'], this.context.project.name);\n\t}\n\n\tprivate itemType(item: AzureWorkItem): string {\n\t\tconst type = item.fields['System.WorkItemType'];\n\t\tif (!isAzureIdentifier(type)) throw new WorkItemWriteError('unknown');\n\n\t\treturn type;\n\t}\n\n\tprivate getReceipt(item: AzureWorkItem, metadata: WorkItemMetadata): WorkItemReceipt {\n\t\tconst title = item.fields['System.Title'];\n\t\tconst state = metadata.states.find(candidate => candidate.name === item.fields['System.State']);\n\t\tif (\n\t\t\t!isAzurePositiveInt(item.id) ||\n\t\t\t!isAzurePositiveInt(item.rev) ||\n\t\t\ttypeof title !== 'string' ||\n\t\t\tstate == null ||\n\t\t\tthis.itemType(item) !== metadata.type.name\n\t\t) {\n\t\t\tthrow new WorkItemWriteError('unknown');\n\t\t}\n\n\t\treturn {\n\t\t\tid: item.id,\n\t\t\trevision: item.rev,\n\t\t\turl: `${this.projectUrl}/_workitems/edit/${item.id}`,\n\t\t\ttype: metadata.type.name,\n\t\t\ttitle: title,\n\t\t\tstate: { name: state.name, category: state.category },\n\t\t\tbodyField: getAzureWorkItemBodyField(metadata.fields, metadata.catalog, item.fields),\n\t\t};\n\t}\n\n\tprivate async assertSessionCurrent(): Promise<void> {\n\t\tif (!(await this.isSessionCurrent())) throw new WorkItemWriteError('no-connection');\n\t}\n\n\tprivate url(path: string, params?: Record<string, string>, base = `${this.projectUrl}/_apis/wit`): string {\n\t\treturn `${base}${path}?${new URLSearchParams({ 'api-version': this.apiVersion, ...params }).toString()}`;\n\t}\n\n\tprivate read<T>(path: string, params?: Record<string, string>): Promise<T> {\n\t\treturn this.get<T>(this.url(path, params));\n\t}\n\n\tprivate readOrganization<T>(path: string, params?: Record<string, string>): Promise<T> {\n\t\treturn this.get<T>(this.url(path, params, `${this.organizationUrl}/_apis`));\n\t}\n\n\tprivate async get<T>(url: string): Promise<T> {\n\t\tconst { body } = await this.request<T>({ url: url, headers: this.headers, redirect: 'error' });\n\t\treturn body;\n\t}\n\n\tprivate async save(\n\t\tmethod: 'POST' | 'PATCH',\n\t\tpath: string,\n\t\tpatch: Patch[],\n\t\tmetadata: WorkItemMetadata,\n\t\texpected?: { id: number; state?: string },\n\t): Promise<WorkItemWriteResult> {\n\t\tconst body = JSON.stringify(patch);\n\t\tawait this.assertSessionCurrent();\n\t\ttry {\n\t\t\tconst { body: item } = await this.request<AzureWorkItem>({\n\t\t\t\tmethod: method,\n\t\t\t\turl: this.url(path),\n\t\t\t\theaders: { ...this.headers, 'Content-Type': 'application/json-patch+json' },\n\t\t\t\tbody: body,\n\t\t\t\tredirect: 'error',\n\t\t\t});\n\t\t\tif (\n\t\t\t\t!this.isInProject(item) ||\n\t\t\t\t(expected != null && item.id !== expected.id) ||\n\t\t\t\t(expected?.state !== undefined && item.fields['System.State'] !== expected.state)\n\t\t\t) {\n\t\t\t\treturn { ok: false, reason: 'unknown', applied: 'maybe' };\n\t\t\t}\n\n\t\t\treturn { ok: true, ...this.context, issue: this.getReceipt(item, metadata) };\n\t\t} catch (ex) {\n\t\t\tif (ex instanceof WorkItemWriteNotDispatchedError) return toWorkItemWriteFailure(ex);\n\n\t\t\treturn toWorkItemWriteFailure(ex, { fields: metadata.fields });\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;AAuEA,MAAM,6BAA6B;AAEnC,SAAS,SAAS,QAAiB,IAAqB;CACvD,OAAO,WAAW,MAAM,WAAW,OAAO,EAAE;AAC7C;AAEA,SAAS,cACR,MACA,IACqD;CACrD,IAAI,QAAQ,QAAQ,CAAC,SAAS,KAAK,IAAI,EAAE,KAAK,CAAC,kBAAkB,KAAK,OAAO,GAAG,OAAO;CAEvF,OACC,KAAK,QAAQ,QAAQ,KAAK,SAAS,KAAM,OAAO,KAAK,SAAS,YAAY,KAAK,QAAQ,OAAO,KAAK,OAA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,KAAK;EACjC,MAAM,KAAK,qBAAqB;EAChC,IAAI;GACH,MAAM,EAAE,MAAM,SAAS,MAAM,KAAK,QAAuB;IAChD;IACR,KAAK,KAAK,IAAI,IAAI;IAClB,SAAS;KAAE,GAAG,KAAK;KAAS,gBAAgB;IAA8B;IACpE;IACN,UAAU;GACX,CAAC;GACD,IACC,CAAC,KAAK,YAAY,IAAI,KACrB,YAAY,QAAQ,KAAK,OAAO,SAAS,MACzC,UAAU,UAAU,KAAA,KAAa,KAAK,OAAO,oBAAoB,SAAS,OAE3E,OAAO;IAAE,IAAI;IAAO,QAAQ;IAAW,SAAS;GAAQ;GAGzD,OAAO;IAAE,IAAI;IAAM,GAAG,KAAK;IAAS,OAAO,KAAK,WAAW,MAAM,QAAQ;GAAE;EAC5E,SAAS,IAAI;GACZ,IAAI,cAAc,iCAAiC,OAAO,uBAAuB,EAAE;GAEnF,OAAO,uBAAuB,IAAI,EAAE,QAAQ,SAAS,OAAO,CAAC;EAC9D;CACD;AACD"}
|
|
@@ -13,6 +13,7 @@ import { GitHubIssueMutation, IssueWriteResult } from "../../git-github/api/issu
|
|
|
13
13
|
import { ProviderAuthenticationSession } from "../authentication/models.js";
|
|
14
14
|
import { GitCloudHostIntegrationId, GitSelfManagedHostIntegrationId } from "../constants.js";
|
|
15
15
|
import { IntegrationAuthenticationProviderDescriptor } from "../authentication/integrationAuthenticationProvider.js";
|
|
16
|
+
import { CaptureRelationshipCurrency, IssueRelationshipWriteOptions, IssueRelationshipWriteResult, IssueRelationshipsOptions, IssueRelationshipsResult } from "../models/issueRelationships.js";
|
|
16
17
|
import { IssueEtagFields, IssueEtagInclude, PullRequestEtagFields, PullRequestEtagInclude } from "../reads/etag.js";
|
|
17
18
|
import { ProviderOrganization, ProviderWarningCause } from "../results.js";
|
|
18
19
|
import { IntegrationCacheDescriptor, SearchMyPullRequestsOptions, SearchPullRequestsOptions } from "../models/publicIntegration.js";
|
|
@@ -331,6 +332,13 @@ export declare class GitHubIntegration extends GitHubIntegrationBase<GitCloudHos
|
|
|
331
332
|
protected readonly key = GitCloudHostIntegrationId.GitHub;
|
|
332
333
|
readonly name: string;
|
|
333
334
|
get domain(): string;
|
|
335
|
+
private readonly relationshipCredentials;
|
|
336
|
+
dispose(): void;
|
|
337
|
+
getIssueRelationships(options: IssueRelationshipsOptions, isHostSessionCurrent?: () => boolean, captureCurrency?: CaptureRelationshipCurrency): Promise<IssueRelationshipsResult>;
|
|
338
|
+
writeIssueRelationship(options: IssueRelationshipWriteOptions, isHostSessionCurrent?: () => boolean, captureCurrency?: CaptureRelationshipCurrency): Promise<IssueRelationshipWriteResult>;
|
|
339
|
+
private withRelationshipSession;
|
|
340
|
+
private checkRelationshipLogin;
|
|
341
|
+
private getRelationshipCredential;
|
|
334
342
|
protected apiBaseUrlFor(_session: ProviderAuthenticationSession): string | undefined;
|
|
335
343
|
access(): Promise<boolean>;
|
|
336
344
|
refresh(): Promise<void>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { chunk } from "../../../utils/array.js";
|
|
2
|
+
import { isCancellationError } from "../../../utils/cancellation.js";
|
|
2
3
|
import { batch, mapBounded, mapSettledBounded } from "../../../utils/promise.js";
|
|
3
4
|
import { AuthenticationError, RequestNotFoundError } from "../../../git/errors.js";
|
|
4
5
|
import { parseGitRemoteUrl } from "../../../git/utils/remote.utils.js";
|
|
5
6
|
import { getGitHubNoReplyAddressParts } from "../../../git/remotes/github.js";
|
|
7
|
+
import { uuid } from "../../../utils/crypto.js";
|
|
6
8
|
import "../../../git/models/pullRequest.js";
|
|
7
9
|
import { decodeGitHubCheckRunId, fromGitHubCheckContextState, fromGitHubIssueOrPullRequestState, fromGitHubMergeQueueEntryState, fromGitHubMergeQueueRemoval, fromGitHubPullRequestMergeableState, fromGitHubPullRequestReviewDecision, fromGitHubPullRequestStatusCheckRollupState, toGitHubCheckRunId } from "../../git-github/models.js";
|
|
8
10
|
import { IntegrationReadUnavailableError } from "../errors.js";
|
|
@@ -11,9 +13,10 @@ import { toCollectionScopeFailure } from "../collectionMetadata.js";
|
|
|
11
13
|
import "../providerFilters.js";
|
|
12
14
|
import { resolveBranchPullRequests } from "./utils/providerPaging.js";
|
|
13
15
|
import { providersMetadata } from "./metadata.js";
|
|
14
|
-
import { areDomainsOnSameHostname, isWebRemoteScheme } from "../utils/domain.utils.js";
|
|
16
|
+
import { areDomainsOnSameHostname, isWebRemoteScheme, matchesInstallationOrigin } from "../utils/domain.utils.js";
|
|
15
17
|
import { getGitHubEnterprisePullRequestWriteOrigin } from "../utils/integration.utils.js";
|
|
16
|
-
import { getSessionIdentity, toTokenWithInfo } from "../authentication/models.js";
|
|
18
|
+
import { getSessionIdentity, isSameAuthenticationSession, toTokenWithInfo } from "../authentication/models.js";
|
|
19
|
+
import { ObservedAuthenticationProvider } from "../authentication/observedAuthenticationProvider.js";
|
|
17
20
|
import { getProviderPullRequestIdentity, stampNativePullRequest } from "./models.js";
|
|
18
21
|
import { pullRequestCheckRunsEtag } from "../reads/etag.js";
|
|
19
22
|
import "../../git-github/api/aliasedQuery.js";
|
|
@@ -1019,6 +1022,9 @@ var GitHubIntegrationBase = class extends GitHostIntegration {
|
|
|
1019
1022
|
return getGitHubPullRequestIdentityFromMaybeUrl(search, this.id);
|
|
1020
1023
|
}
|
|
1021
1024
|
};
|
|
1025
|
+
function isSelectedRelationshipSession(session, connectionId) {
|
|
1026
|
+
return session?.id === connectionId && Boolean(session.accessToken) && matchesInstallationOrigin(session.domain, "https://github.com") && (session.baseUrl == null || matchesInstallationOrigin(session.baseUrl, "https://github.com"));
|
|
1027
|
+
}
|
|
1022
1028
|
var GitHubIntegration = class extends GitHubIntegrationBase {
|
|
1023
1029
|
authProvider = authProvider;
|
|
1024
1030
|
id = "github";
|
|
@@ -1027,6 +1033,160 @@ var GitHubIntegration = class extends GitHubIntegrationBase {
|
|
|
1027
1033
|
get domain() {
|
|
1028
1034
|
return metadata.domain;
|
|
1029
1035
|
}
|
|
1036
|
+
relationshipCredentials = /* @__PURE__ */ new Map();
|
|
1037
|
+
dispose() {
|
|
1038
|
+
this.relationshipCredentials.clear();
|
|
1039
|
+
super.dispose();
|
|
1040
|
+
}
|
|
1041
|
+
getIssueRelationships(options, isHostSessionCurrent, captureCurrency) {
|
|
1042
|
+
return this.withRelationshipSession(options, false, isHostSessionCurrent, captureCurrency, async (api, credentials, proof) => {
|
|
1043
|
+
const result = await api.getIssueRelationships(options, credentials);
|
|
1044
|
+
return result.ok ? {
|
|
1045
|
+
...result,
|
|
1046
|
+
connectionProof: proof
|
|
1047
|
+
} : result;
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
writeIssueRelationship(options, isHostSessionCurrent, captureCurrency) {
|
|
1051
|
+
return this.withRelationshipSession(options, true, isHostSessionCurrent, captureCurrency, (api, credentials) => api.writeIssueRelationship(options, credentials));
|
|
1052
|
+
}
|
|
1053
|
+
async withRelationshipSession(options, write, isHostSessionCurrent, captureCurrency, run) {
|
|
1054
|
+
const notSent = write ? {
|
|
1055
|
+
mutationDispatched: false,
|
|
1056
|
+
outcome: "not-sent"
|
|
1057
|
+
} : {};
|
|
1058
|
+
const disconnected = {
|
|
1059
|
+
ok: false,
|
|
1060
|
+
reason: "no-connection",
|
|
1061
|
+
...notSent
|
|
1062
|
+
};
|
|
1063
|
+
const { connectionId, expectedLogin } = options;
|
|
1064
|
+
const credential = await this.getRelationshipCredential(options).catch((ex) => isCancellationError(ex) ? void 0 : issueWriteFailure(ex));
|
|
1065
|
+
if (credential == null) return disconnected;
|
|
1066
|
+
if ("reason" in credential) return {
|
|
1067
|
+
...credential,
|
|
1068
|
+
...notSent
|
|
1069
|
+
};
|
|
1070
|
+
const isCurrent = () => credential.guard.isCurrent() && (isHostSessionCurrent == null || isHostSessionCurrent()) && this.isIntegrationAccessEnabled() && this.relationshipCredentials.get(connectionId) === credential;
|
|
1071
|
+
const isSessionCurrent = async () => isCurrent() && await credential.guard.verify() && isCurrent();
|
|
1072
|
+
let unauthorized = false;
|
|
1073
|
+
const onUnauthorized = () => {
|
|
1074
|
+
unauthorized = true;
|
|
1075
|
+
};
|
|
1076
|
+
const token = credential.session.accessToken;
|
|
1077
|
+
let sdkStarted = false;
|
|
1078
|
+
let result;
|
|
1079
|
+
try {
|
|
1080
|
+
const api = (await this.getProvidersApi()).githubRelationships;
|
|
1081
|
+
if (!await isSessionCurrent() || !isCurrent()) return disconnected;
|
|
1082
|
+
captureCurrency?.(isCurrent);
|
|
1083
|
+
const viewerFailure = expectedLogin === void 0 ? void 0 : await this.checkRelationshipLogin(credential.session, expectedLogin, isCurrent, onUnauthorized);
|
|
1084
|
+
if (viewerFailure != null) result = {
|
|
1085
|
+
ok: false,
|
|
1086
|
+
reason: viewerFailure,
|
|
1087
|
+
...notSent
|
|
1088
|
+
};
|
|
1089
|
+
else if ((expectedLogin === void 0 || await isSessionCurrent()) && isCurrent()) {
|
|
1090
|
+
sdkStarted = true;
|
|
1091
|
+
result = await run(api, {
|
|
1092
|
+
token,
|
|
1093
|
+
isSessionCurrent,
|
|
1094
|
+
isSessionCurrentNow: isCurrent,
|
|
1095
|
+
onUnauthorized
|
|
1096
|
+
}, credential.proof);
|
|
1097
|
+
} else result = disconnected;
|
|
1098
|
+
} catch (ex) {
|
|
1099
|
+
result = sdkStarted && write ? {
|
|
1100
|
+
ok: false,
|
|
1101
|
+
reason: "unknown",
|
|
1102
|
+
outcome: "unconfirmed"
|
|
1103
|
+
} : {
|
|
1104
|
+
...issueWriteFailure(ex),
|
|
1105
|
+
...notSent
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
const verified = await isSessionCurrent().catch((ex) => isCancellationError(ex) ? false : issueWriteFailure(ex));
|
|
1109
|
+
const current = isCurrent();
|
|
1110
|
+
if (verified !== true || !current) {
|
|
1111
|
+
const lookupFailure = current && typeof verified === "object" ? verified : void 0;
|
|
1112
|
+
if (lookupFailure != null && !result.ok) return unauthorized && !write ? {
|
|
1113
|
+
...result,
|
|
1114
|
+
reason: "no-connection"
|
|
1115
|
+
} : result;
|
|
1116
|
+
if (!write || !sdkStarted) return lookupFailure != null ? {
|
|
1117
|
+
...lookupFailure,
|
|
1118
|
+
...notSent
|
|
1119
|
+
} : disconnected;
|
|
1120
|
+
if (!result.ok) return result.mutationDispatched === false ? {
|
|
1121
|
+
...result,
|
|
1122
|
+
reason: "no-connection"
|
|
1123
|
+
} : result;
|
|
1124
|
+
return {
|
|
1125
|
+
ok: false,
|
|
1126
|
+
reason: lookupFailure?.reason ?? "unknown",
|
|
1127
|
+
outcome: "unconfirmed",
|
|
1128
|
+
..."previousParent" in result && result.previousParent != null && {
|
|
1129
|
+
phase: "attach",
|
|
1130
|
+
detached: true
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
if (unauthorized) {
|
|
1135
|
+
this.handleConnectionAuthenticationRejection(connectionId, true, token);
|
|
1136
|
+
if (!result.ok) return {
|
|
1137
|
+
...result,
|
|
1138
|
+
reason: "no-connection"
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
return result;
|
|
1142
|
+
}
|
|
1143
|
+
async checkRelationshipLogin(session, expectedLogin, isCurrent, onUnauthorized) {
|
|
1144
|
+
const github = await this.authenticationService.apis.github;
|
|
1145
|
+
if (github == null) return "unsupported";
|
|
1146
|
+
if (!isCurrent()) return "no-connection";
|
|
1147
|
+
const login = await github.getWriteViewer(this, toTokenWithInfo(this.id, session), void 0, onUnauthorized);
|
|
1148
|
+
if (!login) return "unknown";
|
|
1149
|
+
return login.toLowerCase() === expectedLogin.toLowerCase() ? void 0 : "no-connection";
|
|
1150
|
+
}
|
|
1151
|
+
async getRelationshipCredential({ connectionId, expectedConnectionProof }) {
|
|
1152
|
+
const selectionCurrent = await this.authenticationService.captureConfiguredConnection(this.id, connectionId);
|
|
1153
|
+
if (!selectionCurrent?.()) return void 0;
|
|
1154
|
+
const cached = this.relationshipCredentials.get(connectionId);
|
|
1155
|
+
if (expectedConnectionProof != null && cached?.proof !== expectedConnectionProof) return void 0;
|
|
1156
|
+
const provider = await this.authenticationService.get(this.id);
|
|
1157
|
+
const descriptor = {
|
|
1158
|
+
...this.authProviderDescriptor,
|
|
1159
|
+
connectionId,
|
|
1160
|
+
cloud: true
|
|
1161
|
+
};
|
|
1162
|
+
const observe = provider instanceof ObservedAuthenticationProvider ? provider.captureRelationshipSession(descriptor) : void 0;
|
|
1163
|
+
let session = await this.resolveReadSessionOrThrow(connectionId, void 0);
|
|
1164
|
+
if (!isSelectedRelationshipSession(session, connectionId)) return void 0;
|
|
1165
|
+
if (cached?.guard.isCurrent() && isSameAuthenticationSession(cached.session, session) && await cached.guard.verify()) return cached;
|
|
1166
|
+
if (expectedConnectionProof != null) return void 0;
|
|
1167
|
+
let observed = observe?.(session);
|
|
1168
|
+
if (observed?.isRetired() && provider instanceof ObservedAuthenticationProvider) {
|
|
1169
|
+
const accountId = session.account.id;
|
|
1170
|
+
const capture = provider.captureRelationshipSession(descriptor);
|
|
1171
|
+
session = await this.resolveReadSessionOrThrow(connectionId, void 0);
|
|
1172
|
+
if (!isSelectedRelationshipSession(session, connectionId) || session.account.id !== accountId) return;
|
|
1173
|
+
observed = capture(session);
|
|
1174
|
+
}
|
|
1175
|
+
const guard = observed == null ? await this.authenticationService.trackStoredRelationshipSession(this.id, session) : {
|
|
1176
|
+
isCurrent: () => selectionCurrent() && observed.isCurrent(),
|
|
1177
|
+
verify: observed.verify
|
|
1178
|
+
};
|
|
1179
|
+
if (!selectionCurrent() || !guard?.isCurrent()) return void 0;
|
|
1180
|
+
const latest = this.relationshipCredentials.get(connectionId);
|
|
1181
|
+
if (latest !== cached) return latest?.guard.isCurrent() && isSameAuthenticationSession(latest.session, session) ? latest : void 0;
|
|
1182
|
+
const credential = {
|
|
1183
|
+
proof: uuid(),
|
|
1184
|
+
session,
|
|
1185
|
+
guard
|
|
1186
|
+
};
|
|
1187
|
+
this.relationshipCredentials.set(connectionId, credential);
|
|
1188
|
+
return credential;
|
|
1189
|
+
}
|
|
1030
1190
|
apiBaseUrlFor(_session) {}
|
|
1031
1191
|
access() {
|
|
1032
1192
|
return Promise.resolve(true);
|