@smartbear/mcp 0.38.0 → 0.39.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.
@@ -2,10 +2,16 @@ import zod__default from "zod";
2
2
  import { getUserAgent } from "../common/info.js";
3
3
  import { getRequestHeader } from "../common/request-context.js";
4
4
  import { ToolError } from "../common/tools.js";
5
+ import { AdminApi } from "./client/admin-api.js";
6
+ import { AIApi } from "./client/ai-api.js";
7
+ import { ContractApi } from "./client/contract-api.js";
8
+ import { EnvironmentApi } from "./client/environment-api.js";
9
+ import { HttpClient } from "./client/http-client.js";
10
+ import { PacticipantApi } from "./client/pacticipant-api.js";
5
11
  import { withPagination } from "./client/pagination.js";
6
- import { getOADMatcherRecommendations } from "./client/prompt-utils.js";
7
12
  import { PROMPTS } from "./client/prompts.js";
8
13
  import { TOOLS } from "./client/tools.js";
14
+ import { WebhookApi } from "./client/webhook-api.js";
9
15
  const ConfigurationSchema = zod__default.object({
10
16
  base_url: zod__default.url().describe("Pact Broker or PactFlow base URL"),
11
17
  token: zod__default.string().optional().describe(
@@ -22,24 +28,15 @@ class PactflowClient {
22
28
  token;
23
29
  username;
24
30
  password;
25
- aiBaseUrl;
26
- baseUrl;
27
31
  _clientType;
28
32
  _server;
29
33
  cache;
30
- /** Returns the configured MCP server instance. @throws Error if not yet configured. */
34
+ http;
35
+ handlerMap;
31
36
  get server() {
32
37
  if (!this._server) throw new Error("Server not configured");
33
38
  return this._server;
34
39
  }
35
- /**
36
- * Initialises the client with auth credentials and the MCP server reference.
37
- * Accepts either a Bearer token (PactFlow) or username/password (Pact Broker).
38
- * Does nothing if neither is supplied.
39
- *
40
- * @param server - The MCP server instance to bind to.
41
- * @param config - Connection config (base_url + token OR username/password).
42
- */
43
40
  async configure(server, config) {
44
41
  this.token = config.token;
45
42
  this.username = config.username;
@@ -51,92 +48,23 @@ class PactflowClient {
51
48
  } else {
52
49
  this._clientType = "pactflow";
53
50
  }
54
- this.baseUrl = config.base_url;
55
- this.aiBaseUrl = `${this.baseUrl}/api/ai`;
56
51
  this._server = server;
57
52
  this.cache = server.getCache();
53
+ this.http = new HttpClient(config.base_url, () => this.requestHeaders);
54
+ const aiBaseUrl = `${config.base_url}/api/ai`;
55
+ this.handlerMap = {
56
+ ...new PacticipantApi(this.http).handlers,
57
+ ...new EnvironmentApi(this.http).handlers,
58
+ ...new ContractApi(this.http).handlers,
59
+ ...new WebhookApi(this.http).handlers,
60
+ ...new AdminApi(this.http).handlers,
61
+ ...new AIApi(this.http, aiBaseUrl).handlers
62
+ };
63
+ Object.assign(this, this.handlerMap);
58
64
  }
59
- /** Returns true if the client has been configured with a base URL and credentials. */
60
65
  isConfigured() {
61
- return this.baseUrl !== void 0;
62
- }
63
- // PactFlow AI client methods
64
- /**
65
- * Generate new Pact tests based on the provided input.
66
- *
67
- * @param toolInput The input data for the generation process.
68
- * @returns The result of the generation process or a result requiring prompt execution.
69
- * @throws Error if the HTTP request fails or the operation times out.
70
- */
71
- async generate(toolInput, _getInput) {
72
- if (toolInput.openapi?.document && (!toolInput.openapi?.matcher || Object.keys(toolInput.openapi.matcher).length === 0)) {
73
- return getOADMatcherRecommendations(toolInput.openapi.document);
74
- }
75
- const status_response = await this.submitHttpCallback(
76
- "/generate",
77
- toolInput
78
- );
79
- return await this.pollForCompletion(
80
- status_response,
81
- "Generation"
82
- );
83
- }
84
- /**
85
- * Review the provided Pact tests and suggest improvements.
86
- *
87
- * @param toolInput The input data for the review process.
88
- * @returns The result of the review process or a result requiring prompt execution.
89
- * @throws Error if the HTTP request fails or the operation times out.
90
- */
91
- async review(toolInput, _getInput) {
92
- if (toolInput.openapi?.document && (!toolInput.openapi?.matcher || Object.keys(toolInput.openapi.matcher).length === 0)) {
93
- return getOADMatcherRecommendations(toolInput.openapi.document);
94
- }
95
- const status_response = await this.submitHttpCallback("/review", toolInput);
96
- return await this.pollForCompletion(
97
- status_response,
98
- "Review Pacts"
99
- );
100
- }
101
- /**
102
- * Retrieve PactFlow AI entitlement information for the current user
103
- * and organization when encountering 401 unauthorized errors.
104
- * Use this to check AI entitlements and credits when AI operations fail.
105
- *
106
- * @returns Entitlement containing permissions, organization
107
- * entitlements, and user entitlements.
108
- * @throws Error if the request fails or returns a non-OK response.
109
- */
110
- async checkAIEntitlements() {
111
- if (this.aiBaseUrl) {
112
- return await this.fetchJson(
113
- `${this.aiBaseUrl}/entitlement`,
114
- {
115
- method: "GET",
116
- errorContext: "PactFlow AI Entitlements Request"
117
- }
118
- );
119
- } else {
120
- return null;
121
- }
122
- }
123
- /**
124
- * Polls the given status URL with a HEAD request to check operation progress.
125
- *
126
- * @param statusUrl - The URL returned by the async AI operation.
127
- * @returns HTTP status code and whether the operation has completed (status 200).
128
- */
129
- async getStatus(statusUrl) {
130
- const response = await fetch(statusUrl, {
131
- method: "HEAD",
132
- headers: this.requestHeaders
133
- });
134
- return {
135
- status: response.status,
136
- isComplete: response.status === 200
137
- };
66
+ return this.http !== void 0;
138
67
  }
139
- /** Returns the current auth/content-type headers used for all requests. */
140
68
  get requestHeaders() {
141
69
  let contextToken = getRequestHeader("Pact-Token") || getRequestHeader("Authorization");
142
70
  if (Array.isArray(contextToken)) {
@@ -173,1872 +101,11 @@ class PactflowClient {
173
101
  }
174
102
  return void 0;
175
103
  }
176
- /**
177
- * Fetches the final result of a completed async operation.
178
- *
179
- * @param resultUrl - The result URL returned by the async AI operation.
180
- * @returns The parsed JSON result of type T.
181
- * @throws ToolError if the response is not OK.
182
- */
183
- async getResult(resultUrl) {
184
- const response = await fetch(resultUrl, {
185
- method: "GET",
186
- headers: this.requestHeaders
187
- });
188
- if (!response.ok) {
189
- throw new ToolError(`HTTP error! status: ${response.status}`);
190
- }
191
- return response.json();
192
- }
193
- /**
194
- * Polls status_url every second until the operation completes or times out (120s).
195
- *
196
- * @param status_response - URLs returned by the initial async submission.
197
- * @param operationName - Human-readable name used in error messages.
198
- * @returns The parsed result of type T on success.
199
- * @throws ToolError on non-202 status or timeout.
200
- */
201
- async pollForCompletion(status_response, operationName) {
202
- const startTime = Date.now();
203
- const timeout = 12e4;
204
- const pollInterval = 1e3;
205
- while (Date.now() - startTime < timeout) {
206
- const statusCheck = await this.getStatus(status_response.status_url);
207
- if (statusCheck.isComplete) {
208
- return await this.getResult(status_response.result_url);
209
- }
210
- if (statusCheck.status !== 202) {
211
- throw new ToolError(
212
- `${operationName} failed with status: ${statusCheck.status}`
213
- );
214
- }
215
- await new Promise((resolve) => setTimeout(resolve, pollInterval));
216
- }
217
- throw new ToolError(
218
- `${operationName} timed out after ${timeout / 1e3} seconds`
219
- );
220
- }
221
- /**
222
- * Helper method to fetch JSON data from an API endpoint.
223
- *
224
- * @param url The full URL to fetch from.
225
- * @param options Options including method, body, and error context.
226
- * @returns The parsed JSON response.
227
- * @throws ToolError if the request fails.
228
- */
229
- async fetchJson(url, options) {
230
- const { method, body, errorContext = "Request" } = options;
231
- try {
232
- const response = await fetch(url, {
233
- method,
234
- headers: this.requestHeaders,
235
- ...body && { body: JSON.stringify(body) }
236
- });
237
- if (!response.ok) {
238
- const errorText = await response.text().catch(() => "");
239
- throw new ToolError(
240
- `${errorContext} Failed - status: ${response.status} ${response.statusText}${errorText ? ` - ${errorText}` : ""}`,
241
- void 0,
242
- /* @__PURE__ */ new Map([["responseStatus", response.status]])
243
- );
244
- }
245
- if (response.status === 204) {
246
- return void 0;
247
- }
248
- return await response.json();
249
- } catch (error) {
250
- if (error instanceof ToolError) {
251
- throw error;
252
- }
253
- const errorMessage = error instanceof Error ? error.message : String(error);
254
- console.error(`[${errorContext}] Unexpected error: ${error}
255
- `);
256
- throw new ToolError(
257
- `${errorContext} Failed - ${errorMessage}`,
258
- void 0,
259
- /* @__PURE__ */ new Map([["responseStatus", 500]])
260
- );
261
- }
262
- }
263
- /**
264
- * Submits an HTTP callback request to the PactFlow AI API.
265
- * @param endpoint The AI API endpoint (relative to aiBaseUrl), e.g., '/generate' or '/review'.
266
- * @param body The request body specific to the AI operation.
267
- * @returns StatusResponse with status_url for polling and result_url for fetching results.
268
- * @throws ToolError if the request fails.
269
- */
270
- async submitHttpCallback(endpoint, body) {
271
- return await this.fetchJson(
272
- `${this.aiBaseUrl}${endpoint}`,
273
- {
274
- method: "POST",
275
- body,
276
- errorContext: `HTTP callback submission to ${endpoint}`
277
- }
278
- );
279
- }
280
- // PactFlow / Pact_Broker client methods
281
- /**
282
- * Retrieves all provider states declared by a provider's pact tests.
283
- *
284
- * @param params - `provider`: The name of the provider.
285
- * @returns List of provider state strings the provider supports.
286
- * @throws ToolError if the request fails.
287
- */
288
- async getProviderStates({
289
- provider
290
- }) {
291
- const uri_encoded_provider_name = encodeURIComponent(provider);
292
- return await this.fetchJson(
293
- `${this.baseUrl}/pacts/provider/${uri_encoded_provider_name}/provider-states`,
294
- {
295
- method: "GET",
296
- errorContext: "Get Provider States"
297
- }
298
- );
299
- }
300
- /**
301
- * Checks if a given pacticipant version is safe to deploy
302
- * to a specified environment.
303
- *
304
- * @param body - Input containing:
305
- * - `pacticipant`: The name of the service (pacticipant).
306
- * - `version`: The version of the pacticipant being evaluated for deployment.
307
- * - `environment`: The target environment (e.g., staging, production).
308
- * @returns CanIDeployResponse containing deployment decision and verification results.
309
- * @throws Error if the request fails or returns a non-OK response.
310
- */
311
- async canIDeploy(body) {
312
- const { pacticipant, version, environment } = body;
313
- const queryParams = new URLSearchParams({
314
- pacticipant,
315
- version,
316
- environment
317
- });
318
- const url = `${this.baseUrl}/can-i-deploy?${queryParams.toString()}`;
319
- return await this.fetchJson(url, {
320
- method: "GET",
321
- errorContext: "Can-I-Deploy Request"
322
- });
323
- }
324
- /**
325
- * Retrieves the matrix of pact verification results for the specified pacticipants.
326
- * This allows you to see which consumer/provider combinations have been verified
327
- * and make deployment decisions based on contract test results.
328
- *
329
- * @param body - Matrix query parameters including pacticipants, versions, environments, etc.
330
- * @returns MatrixResponse containing the verification matrix, notices, and summary
331
- * @throws Error if the request fails or returns a non-OK response
332
- */
333
- async getMatrix(body) {
334
- const { q, latestby, limit } = body;
335
- const queryParts = [];
336
- if (latestby) {
337
- queryParts.push(`latestby=${encodeURIComponent(latestby)}`);
338
- }
339
- if (limit !== void 0) {
340
- queryParts.push(`limit=${limit}`);
341
- }
342
- q.forEach((selector) => {
343
- queryParts.push(
344
- `q[]pacticipant=${encodeURIComponent(selector.pacticipant)}`
345
- );
346
- if (selector.version) {
347
- queryParts.push(`q[]version=${encodeURIComponent(selector.version)}`);
348
- }
349
- if (selector.branch) {
350
- queryParts.push(`q[]branch=${encodeURIComponent(selector.branch)}`);
351
- }
352
- if (selector.environment) {
353
- queryParts.push(
354
- `q[]environment=${encodeURIComponent(selector.environment)}`
355
- );
356
- }
357
- if (selector.latest !== void 0) {
358
- queryParts.push(`q[]latest=${selector.latest}`);
359
- }
360
- if (selector.tag) {
361
- queryParts.push(`q[]tag=${encodeURIComponent(selector.tag)}`);
362
- }
363
- if (selector.mainBranch !== void 0) {
364
- queryParts.push(`q[]mainBranch=${selector.mainBranch}`);
365
- }
366
- });
367
- const url = `${this.baseUrl}/matrix?${queryParts.join("&")}`;
368
- return await this.fetchJson(url, {
369
- method: "GET",
370
- errorContext: "Matrix Request"
371
- });
372
- }
373
- /**
374
- * Retrieves metrics across the workspace.
375
- *
376
- * @returns MetricsResponse containing workspace-wide metrics
377
- * @throws Error if the request fails or returns a non-OK response
378
- */
379
- async getMetrics() {
380
- const url = `${this.baseUrl}/metrics`;
381
- try {
382
- const response = await fetch(url, {
383
- method: "GET",
384
- headers: this.requestHeaders
385
- });
386
- if (!response.ok) {
387
- const errorText = await response.text().catch(() => "");
388
- throw new ToolError(
389
- `Metrics Request Failed - status: ${response.status} ${response.statusText}${errorText ? ` - ${errorText}` : ""}`
390
- );
391
- }
392
- return await response.json();
393
- } catch (error) {
394
- console.error("[GetMetrics] Unexpected error:", error);
395
- throw error;
396
- }
397
- }
398
- /**
399
- * Retrieves metrics for all teams.
400
- *
401
- * @returns TeamMetricsResponse containing metrics for all teams
402
- * @throws Error if the request fails or returns a non-OK response
403
- */
404
- async getTeamMetrics() {
405
- const url = `${this.baseUrl}/metrics/teams`;
406
- try {
407
- const response = await fetch(url, {
408
- method: "GET",
409
- headers: this.requestHeaders
410
- });
411
- if (!response.ok) {
412
- const errorText = await response.text().catch(() => "");
413
- throw new ToolError(
414
- `Team Metrics Request Failed - status: ${response.status} ${response.statusText}${errorText ? ` - ${errorText}` : ""}`
415
- );
416
- }
417
- return await response.json();
418
- } catch (error) {
419
- console.error("[GetTeamMetrics] Unexpected error:", error);
420
- throw error;
421
- }
422
- }
423
- /**
424
- * Retrieves all pacticipants (applications/services) registered in the workspace,
425
- * with optional pagination.
426
- *
427
- * @param params - Optional pagination parameters (`pageNumber`, `pageSize`).
428
- * @returns List of pacticipants with their metadata.
429
- * @throws ToolError if the request fails.
430
- */
431
- async listPacticipants(params) {
432
- const queryParams = new URLSearchParams();
433
- if (params?.pageNumber) queryParams.set("page", String(params.pageNumber));
434
- if (params?.pageSize) queryParams.set("size", String(params.pageSize));
435
- const qs = queryParams.toString();
436
- return await this.fetchJson(
437
- `${this.baseUrl}/pacticipants${qs ? `?${qs}` : ""}`,
438
- { method: "GET", errorContext: "List Pacticipants" }
439
- );
440
- }
441
- /**
442
- * Retrieves metadata for a specific pacticipant by name.
443
- *
444
- * @param params - `pacticipantName`: The name of the pacticipant to fetch.
445
- * @returns Pacticipant metadata including display name, main branch, and repository URL.
446
- * @throws ToolError if the pacticipant is not found or the request fails.
447
- */
448
- async getPacticipant({ pacticipantName }) {
449
- return await this.fetchJson(
450
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}`,
451
- { method: "GET", errorContext: "Get Pacticipant" }
452
- );
453
- }
454
- /**
455
- * Retrieves all branches for a given pacticipant, with optional name filtering
456
- * and pagination.
457
- *
458
- * @param params - `pacticipantName`, optional `q` (name filter), `pageNumber`, `pageSize`.
459
- * @returns List of branches for the pacticipant.
460
- * @throws ToolError if the request fails.
461
- */
462
- async listBranches({
463
- pacticipantName,
464
- q,
465
- pageNumber,
466
- pageSize
467
- }) {
468
- const queryParams = new URLSearchParams();
469
- if (q) queryParams.set("q", q);
470
- if (pageNumber) queryParams.set("pageNumber", String(pageNumber));
471
- if (pageSize) queryParams.set("pageSize", String(pageSize));
472
- const qs = queryParams.toString();
473
- return await this.fetchJson(
474
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/branches${qs ? `?${qs}` : ""}`,
475
- { method: "GET", errorContext: "List Branches" }
476
- );
477
- }
478
- /**
479
- * Retrieves all published versions for a given pacticipant, with optional pagination.
480
- *
481
- * @param params - `pacticipantName`, optional `pageNumber` and `pageSize`.
482
- * @returns List of versions with their branch and tag associations.
483
- * @throws ToolError if the request fails.
484
- */
485
- async listVersions({
486
- pacticipantName,
487
- pageNumber,
488
- pageSize
489
- }) {
490
- const queryParams = new URLSearchParams();
491
- if (pageNumber) queryParams.set("page", String(pageNumber));
492
- if (pageSize) queryParams.set("size", String(pageSize));
493
- const qs = queryParams.toString();
494
- return await this.fetchJson(
495
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/versions${qs ? `?${qs}` : ""}`,
496
- { method: "GET", errorContext: "List Versions" }
497
- );
498
- }
499
- /**
500
- * Retrieves metadata for a specific version of a pacticipant.
501
- *
502
- * @param params - `pacticipantName` and `versionNumber` to retrieve.
503
- * @returns Version metadata including branches, tags, and build URL.
504
- * @throws ToolError if the version is not found or the request fails.
505
- */
506
- async getVersion({
507
- pacticipantName,
508
- versionNumber
509
- }) {
510
- return await this.fetchJson(
511
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/versions/${encodeURIComponent(versionNumber)}`,
512
- { method: "GET", errorContext: "Get Version" }
513
- );
514
- }
515
- /**
516
- * Retrieves the latest version of a pacticipant, optionally filtered by tag.
517
- *
518
- * @param params - `pacticipantName` and optional `tag` to filter by.
519
- * @returns The latest matching version.
520
- * @throws ToolError if the request fails.
521
- */
522
- async getLatestVersion({
523
- pacticipantName,
524
- tag
525
- }) {
526
- const path = tag ? `/pacticipants/${encodeURIComponent(pacticipantName)}/latest-version/${encodeURIComponent(tag)}` : `/pacticipants/${encodeURIComponent(pacticipantName)}/latest-version`;
527
- return await this.fetchJson(`${this.baseUrl}${path}`, {
528
- method: "GET",
529
- errorContext: "Get Latest Version"
530
- });
531
- }
532
- /**
533
- * Retrieves all environments configured in the workspace.
534
- *
535
- * @returns List of environments with their UUIDs, names, and production flags.
536
- * @throws ToolError if the request fails.
537
- */
538
- async listEnvironments() {
539
- return await this.fetchJson(`${this.baseUrl}/environments`, {
540
- method: "GET",
541
- errorContext: "List Environments"
542
- });
543
- }
544
- /**
545
- * Retrieves metadata for a specific environment by UUID.
546
- *
547
- * @param params - `environmentId`: The UUID of the environment.
548
- * @returns Environment metadata including name, display name, and production flag.
549
- * @throws ToolError if the environment is not found or the request fails.
550
- */
551
- async getEnvironment({ environmentId }) {
552
- return await this.fetchJson(
553
- `${this.baseUrl}/environments/${encodeURIComponent(environmentId)}`,
554
- { method: "GET", errorContext: "Get Environment" }
555
- );
556
- }
557
- /**
558
- * Records that a specific version of a pacticipant has been deployed to an environment.
559
- *
560
- * @param params - `pacticipantName`, `versionNumber`, `environmentId`, and optional
561
- * `applicationInstance` (for blue/green or multi-instance deployments).
562
- * @returns The created deployment record.
563
- * @throws ToolError if the request fails.
564
- */
565
- async recordDeployment({
566
- pacticipantName,
567
- versionNumber,
568
- environmentId,
569
- applicationInstance
570
- }) {
571
- return await this.fetchJson(
572
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/versions/${encodeURIComponent(versionNumber)}/deployed-versions/environment/${encodeURIComponent(environmentId)}`,
573
- {
574
- method: "POST",
575
- body: applicationInstance ? { applicationInstance } : {},
576
- errorContext: "Record Deployment"
577
- }
578
- );
579
- }
580
- /**
581
- * Retrieves all versions currently deployed to a given environment.
582
- *
583
- * @param params - `environmentId`: The UUID of the environment to query.
584
- * @returns List of currently deployed versions across all pacticipants.
585
- * @throws ToolError if the request fails.
586
- */
587
- async getCurrentlyDeployed({
588
- environmentId
589
- }) {
590
- return await this.fetchJson(
591
- `${this.baseUrl}/environments/${encodeURIComponent(environmentId)}/deployed-versions/currently-deployed`,
592
- { method: "GET", errorContext: "Get Currently Deployed" }
593
- );
594
- }
595
- /**
596
- * Records that a version of a pacticipant has been released to an environment.
597
- * Used for mobile/library workflows where multiple versions coexist simultaneously.
598
- *
599
- * @param params - `pacticipantName`, `versionNumber`, and `environmentId`.
600
- * @returns The created release record.
601
- * @throws ToolError if the request fails.
602
- */
603
- async recordRelease({
604
- pacticipantName,
605
- versionNumber,
606
- environmentId
607
- }) {
608
- return await this.fetchJson(
609
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/versions/${encodeURIComponent(versionNumber)}/released-versions/environment/${encodeURIComponent(environmentId)}`,
610
- { method: "POST", body: {}, errorContext: "Record Release" }
611
- );
612
- }
613
- /**
614
- * Retrieves all versions currently released and supported in a given environment.
615
- *
616
- * @param params - `environmentId`: The UUID of the environment to query.
617
- * @returns List of currently supported released versions.
618
- * @throws ToolError if the request fails.
619
- */
620
- async getCurrentlySupported({
621
- environmentId
622
- }) {
623
- return await this.fetchJson(
624
- `${this.baseUrl}/environments/${encodeURIComponent(environmentId)}/released-versions/currently-supported`,
625
- { method: "GET", errorContext: "Get Currently Supported" }
626
- );
627
- }
628
- /**
629
- * Publishes one or more consumer Pact contracts to the Pact Broker or PactFlow.
630
- *
631
- * @param body - Consumer name, version number, contract files (base64-encoded),
632
- * and optional branch/tag metadata.
633
- * @returns Publication result including the pacticipant version number.
634
- * @throws ToolError if the request fails.
635
- */
636
- async publishContracts(body) {
637
- return await this.fetchJson(`${this.baseUrl}/contracts/publish`, {
638
- method: "POST",
639
- body,
640
- errorContext: "Publish Consumer Contracts"
641
- });
642
- }
643
- /**
644
- * Publishes a provider OpenAPI or AsyncAPI contract and its self-verification results
645
- * to PactFlow for use in Bi-Directional Contract Testing.
646
- *
647
- * @param params - `providerName`, version number, base64-encoded OpenAPI/AsyncAPI spec,
648
- * content type, and self-verification results.
649
- * @returns Publication result.
650
- * @throws ToolError if the request fails.
651
- */
652
- async publishProviderContract({
653
- providerName,
654
- ...body
655
- }) {
656
- return await this.fetchJson(
657
- `${this.baseUrl}/provider-contracts/provider/${encodeURIComponent(providerName)}/publish`,
658
- { method: "POST", body, errorContext: "Publish Provider Contract" }
659
- );
660
- }
661
- /**
662
- * Retrieves the set of consumer pacts a provider should verify in its current CI run,
663
- * based on consumer version selectors and WIP/pending pact configuration.
664
- *
665
- * @param params - `providerName`, consumer version selectors, pending/WIP flags,
666
- * and optional provider branch/tag context.
667
- * @returns List of pact URLs and metadata the provider must verify.
668
- * @throws ToolError if the request fails.
669
- */
670
- async getPactsForVerification({
671
- providerName,
672
- ...body
673
- }) {
674
- return await this.fetchJson(
675
- `${this.baseUrl}/pacts/provider/${encodeURIComponent(providerName)}/for-verification`,
676
- { method: "POST", body, errorContext: "Get Pacts for Verification" }
677
- );
678
- }
679
- /**
680
- * Fetches the provider OpenAPI contract for a given provider version in BDCT.
681
- *
682
- * @param params - `providerName` and `providerVersionNumber`.
683
- * @returns The published OpenAPI spec and its verification status.
684
- * @throws ToolError if the request fails.
685
- */
686
- async getBiDirectionalProviderContract({
687
- providerName,
688
- providerVersionNumber
689
- }) {
690
- return await this.fetchJson(
691
- `${this.baseUrl}/contracts/bi-directional/provider/${encodeURIComponent(providerName)}/version/${encodeURIComponent(providerVersionNumber)}/provider-contract`,
692
- { method: "GET", errorContext: "Get BDCT Provider Contract" }
693
- );
694
- }
695
- /**
696
- * Fetches the self-verification results for a provider contract version in BDCT.
697
- *
698
- * @param params - `providerName` and `providerVersionNumber`.
699
- * @returns The results of the tool (e.g. Dredd, Schemathesis) that verified the provider.
700
- * @throws ToolError if the request fails.
701
- */
702
- async getBiDirectionalProviderContractVerificationResults({
703
- providerName,
704
- providerVersionNumber
705
- }) {
706
- return await this.fetchJson(
707
- `${this.baseUrl}/contracts/bi-directional/provider/${encodeURIComponent(providerName)}/version/${encodeURIComponent(providerVersionNumber)}/provider-contract-verification-results`,
708
- {
709
- method: "GET",
710
- errorContext: "Get BDCT Provider Contract Verification Results"
711
- }
712
- );
713
- }
714
- /**
715
- * Fetches all consumer Pact contracts relevant to a given provider version in BDCT.
716
- *
717
- * @param params - `providerName` and `providerVersionNumber`.
718
- * @returns Consumer contracts compared against the provider's OpenAPI spec.
719
- * @throws ToolError if the request fails.
720
- */
721
- async getBiDirectionalConsumerContract({
722
- providerName,
723
- providerVersionNumber
724
- }) {
725
- return await this.fetchJson(
726
- `${this.baseUrl}/contracts/bi-directional/provider/${encodeURIComponent(providerName)}/version/${encodeURIComponent(providerVersionNumber)}/consumer-contract`,
727
- { method: "GET", errorContext: "Get BDCT Consumer Contract" }
728
- );
729
- }
730
- /**
731
- * Fetches the consumer contract verification results for a given provider version in BDCT.
732
- *
733
- * @param params - `providerName` and `providerVersionNumber`.
734
- * @returns Results of comparing all consumer pacts against the provider's OpenAPI spec.
735
- * @throws ToolError if the request fails.
736
- */
737
- async getBiDirectionalConsumerContractVerificationResults({
738
- providerName,
739
- providerVersionNumber
740
- }) {
741
- return await this.fetchJson(
742
- `${this.baseUrl}/contracts/bi-directional/provider/${encodeURIComponent(providerName)}/version/${encodeURIComponent(providerVersionNumber)}/consumer-contract-verification-results`,
743
- {
744
- method: "GET",
745
- errorContext: "Get BDCT Consumer Contract Verification Results"
746
- }
747
- );
748
- }
749
- /**
750
- * Fetches the cross-contract verification results for a given provider version in BDCT.
751
- *
752
- * @param params - `providerName` and `providerVersionNumber`.
753
- * @returns Combined outcome of PactFlow's automated comparison of the provider spec
754
- * against all relevant consumer pacts.
755
- * @throws ToolError if the request fails.
756
- */
757
- async getBiDirectionalCrossContractVerificationResults({
758
- providerName,
759
- providerVersionNumber
760
- }) {
761
- return await this.fetchJson(
762
- `${this.baseUrl}/contracts/bi-directional/provider/${encodeURIComponent(providerName)}/version/${encodeURIComponent(providerVersionNumber)}/cross-contract-verification-results`,
763
- {
764
- method: "GET",
765
- errorContext: "Get BDCT Cross-Contract Verification Results"
766
- }
767
- );
768
- }
769
- /**
770
- * Fetches the consumer Pact contract for a specific consumer-provider version pair in BDCT.
771
- *
772
- * @param params - `providerName`, `providerVersionNumber`, `consumerName`,
773
- * and `consumerVersionNumber`.
774
- * @returns The Pact contract published by the specified consumer version.
775
- * @throws ToolError if the request fails.
776
- */
777
- async getBiDirectionalConsumerContractByConsumer({
778
- providerName,
779
- providerVersionNumber,
780
- consumerName,
781
- consumerVersionNumber
782
- }) {
783
- return await this.fetchJson(
784
- `${this.baseUrl}/contracts/bi-directional/provider/${encodeURIComponent(providerName)}/version/${encodeURIComponent(providerVersionNumber)}/consumer/${encodeURIComponent(consumerName)}/version/${encodeURIComponent(consumerVersionNumber)}/consumer-contract`,
785
- {
786
- method: "GET",
787
- errorContext: "Get BDCT Consumer Contract (by consumer version)"
788
- }
789
- );
790
- }
791
- /**
792
- * Fetches the provider OpenAPI contract for a specific consumer-provider version pair in BDCT.
793
- *
794
- * @param params - `providerName`, `providerVersionNumber`, `consumerName`,
795
- * and `consumerVersionNumber`.
796
- * @returns The provider's OpenAPI spec in the context of the given consumer version.
797
- * @throws ToolError if the request fails.
798
- */
799
- async getBiDirectionalProviderContractByConsumer({
800
- providerName,
801
- providerVersionNumber,
802
- consumerName,
803
- consumerVersionNumber
804
- }) {
805
- return await this.fetchJson(
806
- `${this.baseUrl}/contracts/bi-directional/provider/${encodeURIComponent(providerName)}/version/${encodeURIComponent(providerVersionNumber)}/consumer/${encodeURIComponent(consumerName)}/version/${encodeURIComponent(consumerVersionNumber)}/provider-contract`,
807
- {
808
- method: "GET",
809
- errorContext: "Get BDCT Provider Contract (by consumer version)"
810
- }
811
- );
812
- }
813
- /**
814
- * Fetches the provider contract self-verification results for a specific
815
- * consumer-provider version pair in BDCT.
816
- *
817
- * @param params - `providerName`, `providerVersionNumber`, `consumerName`,
818
- * and `consumerVersionNumber`.
819
- * @returns Provider self-verification results scoped to the given consumer version.
820
- * @throws ToolError if the request fails.
821
- */
822
- async getBiDirectionalProviderContractVerificationResultsByConsumer({
823
- providerName,
824
- providerVersionNumber,
825
- consumerName,
826
- consumerVersionNumber
827
- }) {
828
- return await this.fetchJson(
829
- `${this.baseUrl}/contracts/bi-directional/provider/${encodeURIComponent(providerName)}/version/${encodeURIComponent(providerVersionNumber)}/consumer/${encodeURIComponent(consumerName)}/version/${encodeURIComponent(consumerVersionNumber)}/provider-contract-verification-results`,
830
- {
831
- method: "GET",
832
- errorContext: "Get BDCT Provider Contract Verification Results (by consumer version)"
833
- }
834
- );
835
- }
836
- /**
837
- * Fetches the consumer contract verification results for a specific
838
- * consumer-provider version pair in BDCT.
839
- *
840
- * @param params - `providerName`, `providerVersionNumber`, `consumerName`,
841
- * and `consumerVersionNumber`.
842
- * @returns Results of comparing the specific consumer pact against the provider's OpenAPI spec.
843
- * @throws ToolError if the request fails.
844
- */
845
- async getBiDirectionalConsumerContractVerificationResultsByConsumer({
846
- providerName,
847
- providerVersionNumber,
848
- consumerName,
849
- consumerVersionNumber
850
- }) {
851
- return await this.fetchJson(
852
- `${this.baseUrl}/contracts/bi-directional/provider/${encodeURIComponent(providerName)}/version/${encodeURIComponent(providerVersionNumber)}/consumer/${encodeURIComponent(consumerName)}/version/${encodeURIComponent(consumerVersionNumber)}/consumer-contract-verification-results`,
853
- {
854
- method: "GET",
855
- errorContext: "Get BDCT Consumer Contract Verification Results (by consumer version)"
856
- }
857
- );
858
- }
859
- /**
860
- * Fetches the cross-contract verification results for a specific
861
- * consumer-provider version pair in BDCT.
862
- *
863
- * @param params - `providerName`, `providerVersionNumber`, `consumerName`,
864
- * and `consumerVersionNumber`.
865
- * @returns The precise cross-contract comparison outcome for the given pairing.
866
- * @throws ToolError if the request fails.
867
- */
868
- async getBiDirectionalCrossContractVerificationResultsByConsumer({
869
- providerName,
870
- providerVersionNumber,
871
- consumerName,
872
- consumerVersionNumber
873
- }) {
874
- return await this.fetchJson(
875
- `${this.baseUrl}/contracts/bi-directional/provider/${encodeURIComponent(providerName)}/version/${encodeURIComponent(providerVersionNumber)}/consumer/${encodeURIComponent(consumerName)}/version/${encodeURIComponent(consumerVersionNumber)}/cross-contract-verification-results`,
876
- {
877
- method: "GET",
878
- errorContext: "Get BDCT Cross-Contract Verification Results (by consumer version)"
879
- }
880
- );
881
- }
882
- /**
883
- * Retrieves all consumer-provider integrations registered in the workspace.
884
- *
885
- * @returns List of all consumer-provider pairings that have pacts published.
886
- * @throws ToolError if the request fails.
887
- */
888
- async listIntegrations() {
889
- return await this.fetchJson(`${this.baseUrl}/integrations`, {
890
- method: "GET",
891
- errorContext: "List Integrations"
892
- });
893
- }
894
- /**
895
- * Retrieves the integration network graph for a specific pacticipant,
896
- * showing all services it consumes and all consumers that depend on it.
897
- *
898
- * @param params - `pacticipantName`: The name of the pacticipant.
899
- * @returns Network graph of consumer-provider relationships for the pacticipant.
900
- * @throws ToolError if the request fails.
901
- */
902
- async getPacticipantNetwork({
903
- pacticipantName
904
- }) {
905
- return await this.fetchJson(
906
- `${this.baseUrl}/pacticipant/${encodeURIComponent(pacticipantName)}/network`,
907
- { method: "GET", errorContext: "Get Pacticipant Network" }
908
- );
909
- }
910
- /**
911
- * Retrieves all labels used across the workspace, with optional pagination.
912
- *
913
- * @param params - Optional `pageNumber` and `pageSize`.
914
- * @returns List of every label applied to any pacticipant.
915
- * @throws ToolError if the request fails.
916
- */
917
- async listLabels(params) {
918
- const queryParams = new URLSearchParams();
919
- if (params?.pageNumber) queryParams.set("page", String(params.pageNumber));
920
- if (params?.pageSize) queryParams.set("size", String(params.pageSize));
921
- const qs = queryParams.toString();
922
- return await this.fetchJson(
923
- `${this.baseUrl}/labels${qs ? `?${qs}` : ""}`,
924
- { method: "GET", errorContext: "List Labels" }
925
- );
926
- }
927
- /**
928
- * Checks whether a specific label is applied to a pacticipant.
929
- *
930
- * @param params - `pacticipantName` and `labelName`.
931
- * @returns The label resource if it exists (404 if not applied).
932
- * @throws ToolError if the request fails.
933
- */
934
- async getPacticipantLabel({
935
- pacticipantName,
936
- labelName
937
- }) {
938
- return await this.fetchJson(
939
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/labels/${encodeURIComponent(labelName)}`,
940
- { method: "GET", errorContext: "Get Pacticipant Label" }
941
- );
942
- }
943
- /**
944
- * Retrieves all pacticipants that have a specific label applied.
945
- *
946
- * @param params - `labelName`: The label to filter by.
947
- * @returns List of pacticipants with the given label.
948
- * @throws ToolError if the request fails.
949
- */
950
- async listPacticipantsByLabel({ labelName }) {
951
- return await this.fetchJson(
952
- `${this.baseUrl}/pacticipants/label/${encodeURIComponent(labelName)}`,
953
- { method: "GET", errorContext: "List Pacticipants by Label" }
954
- );
955
- }
956
- /**
957
- * Fully replaces a pacticipant's metadata. All fields not provided are cleared.
958
- *
959
- * @param params - `pacticipantName` plus optional metadata fields
960
- * (displayName, mainBranch, repositoryUrl, etc.).
961
- * @returns The updated pacticipant resource.
962
- * @throws ToolError if the request fails.
963
- */
964
- async updatePacticipant({
965
- pacticipantName,
966
- ...body
967
- }) {
968
- return await this.fetchJson(
969
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}`,
970
- { method: "PUT", body, errorContext: "Update Pacticipant" }
971
- );
972
- }
973
- /**
974
- * Partially updates a pacticipant's metadata — only the fields provided are changed.
975
- *
976
- * @param params - `pacticipantName` plus the specific fields to update.
977
- * @returns The updated pacticipant resource.
978
- * @throws ToolError if the request fails.
979
- */
980
- async patchPacticipant({
981
- pacticipantName,
982
- ...body
983
- }) {
984
- return await this.fetchJson(
985
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}`,
986
- { method: "PATCH", body, errorContext: "Patch Pacticipant" }
987
- );
988
- }
989
- /**
990
- * Updates metadata for a specific pacticipant version (e.g. sets the build URL).
991
- *
992
- * @param params - `pacticipantName`, `versionNumber`, and optional `buildUrl`.
993
- * @returns The updated version resource.
994
- * @throws ToolError if the request fails.
995
- */
996
- async updateVersion({
997
- pacticipantName,
998
- versionNumber,
999
- ...body
1000
- }) {
1001
- return await this.fetchJson(
1002
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/versions/${encodeURIComponent(versionNumber)}`,
1003
- { method: "PUT", body, errorContext: "Update Version" }
1004
- );
1005
- }
1006
- /**
1007
- * Retrieves all versions published from a specific branch of a pacticipant.
1008
- *
1009
- * @param params - `pacticipantName`, `branchName`, optional `pageNumber` and `pageSize`.
1010
- * @returns List of versions created on the given branch.
1011
- * @throws ToolError if the request fails.
1012
- */
1013
- async getBranchVersions({
1014
- pacticipantName,
1015
- branchName,
1016
- pageNumber,
1017
- pageSize
1018
- }) {
1019
- const queryParams = new URLSearchParams();
1020
- if (pageNumber) queryParams.set("page", String(pageNumber));
1021
- if (pageSize) queryParams.set("size", String(pageSize));
1022
- const qs = queryParams.toString();
1023
- return await this.fetchJson(
1024
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/branches/${encodeURIComponent(branchName)}/versions${qs ? `?${qs}` : ""}`,
1025
- { method: "GET", errorContext: "Get Branch Versions" }
1026
- );
1027
- }
1028
- /**
1029
- * Retrieves deployment records for a specific pacticipant version in a given environment.
1030
- *
1031
- * @param params - `pacticipantName`, `versionNumber`, and `environmentId`.
1032
- * @returns All deployment records for the version, including whether each is currently active.
1033
- * @throws ToolError if the request fails.
1034
- */
1035
- async getDeployedVersions({
1036
- pacticipantName,
1037
- versionNumber,
1038
- environmentId
1039
- }) {
1040
- return await this.fetchJson(
1041
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/versions/${encodeURIComponent(versionNumber)}/deployed-versions/environment/${encodeURIComponent(environmentId)}`,
1042
- { method: "GET", errorContext: "Get Deployed Versions" }
1043
- );
1044
- }
1045
- /**
1046
- * Retrieves release records for a specific pacticipant version in a given environment.
1047
- *
1048
- * @param params - `pacticipantName`, `versionNumber`, and `environmentId`.
1049
- * @returns All release records for the version in the environment.
1050
- * @throws ToolError if the request fails.
1051
- */
1052
- async getReleasedVersions({
1053
- pacticipantName,
1054
- versionNumber,
1055
- environmentId
1056
- }) {
1057
- return await this.fetchJson(
1058
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/versions/${encodeURIComponent(versionNumber)}/released-versions/environment/${encodeURIComponent(environmentId)}`,
1059
- { method: "GET", errorContext: "Get Released Versions" }
1060
- );
1061
- }
1062
- /**
1063
- * Creates a new deployment environment in the workspace.
1064
- *
1065
- * @param body - Environment name, display name, and whether it is a production environment.
1066
- * @returns The created environment resource.
1067
- * @throws ToolError if the request fails.
1068
- */
1069
- async createEnvironment({
1070
- ...body
1071
- }) {
1072
- return await this.fetchJson(`${this.baseUrl}/environments`, {
1073
- method: "POST",
1074
- body,
1075
- errorContext: "Create Environment"
1076
- });
1077
- }
1078
- /**
1079
- * Fully replaces an environment's configuration.
1080
- *
1081
- * @param params - `environmentId` (UUID) plus updated name, display name, and production flag.
1082
- * @returns The updated environment resource.
1083
- * @throws ToolError if the environment is not found or the request fails.
1084
- */
1085
- async updateEnvironment({
1086
- environmentId,
1087
- ...body
1088
- }) {
1089
- return await this.fetchJson(
1090
- `${this.baseUrl}/environments/${encodeURIComponent(environmentId)}`,
1091
- {
1092
- method: "PUT",
1093
- body,
1094
- errorContext: "Update Environment"
1095
- }
1096
- );
1097
- }
1098
- /**
1099
- * Deletes a deployment environment from the workspace.
1100
- *
1101
- * @param params - `environmentId`: UUID of the environment to delete.
1102
- * @throws ToolError if the environment is not found or the request fails.
1103
- */
1104
- async deleteEnvironment({
1105
- environmentId
1106
- }) {
1107
- return await this.fetchJson(
1108
- `${this.baseUrl}/environments/${encodeURIComponent(environmentId)}`,
1109
- {
1110
- method: "DELETE",
1111
- errorContext: "Delete Environment"
1112
- }
1113
- );
1114
- }
1115
- /**
1116
- * Registers a new pacticipant (application/service) in the workspace.
1117
- *
1118
- * @param body - Name, optional display name, main branch, and repository URL.
1119
- * @returns The created pacticipant resource.
1120
- * @throws ToolError if the request fails.
1121
- */
1122
- async createPacticipant({
1123
- ...body
1124
- }) {
1125
- return await this.fetchJson(`${this.baseUrl}/pacticipants`, {
1126
- method: "POST",
1127
- body,
1128
- errorContext: "Create Pacticipant"
1129
- });
1130
- }
1131
- /**
1132
- * Permanently removes a pacticipant and all its associated data from the workspace.
1133
- *
1134
- * @param params - `pacticipantName`: The name of the pacticipant to delete.
1135
- * @throws ToolError if the request fails.
1136
- */
1137
- async deletePacticipant({
1138
- pacticipantName
1139
- }) {
1140
- return await this.fetchJson(
1141
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}`,
1142
- {
1143
- method: "DELETE",
1144
- errorContext: "Delete Pacticipant"
1145
- }
1146
- );
1147
- }
1148
- /**
1149
- * Retrieves metadata for a specific branch of a pacticipant.
1150
- *
1151
- * @param params - `pacticipantName` and `branchName`.
1152
- * @returns Branch metadata including its versions.
1153
- * @throws ToolError if the branch is not found or the request fails.
1154
- */
1155
- async getBranch({
1156
- pacticipantName,
1157
- branchName
1158
- }) {
1159
- return await this.fetchJson(
1160
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/branches/${encodeURIComponent(branchName)}`,
1161
- { method: "GET", errorContext: "Get Branch" }
1162
- );
1163
- }
1164
- /**
1165
- * Deletes a branch and its version associations from a pacticipant.
1166
- *
1167
- * @param params - `pacticipantName` and `branchName`.
1168
- * @throws ToolError if the branch is not found or the request fails.
1169
- */
1170
- async deleteBranch({
1171
- pacticipantName,
1172
- branchName
1173
- }) {
1174
- return await this.fetchJson(
1175
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/branches/${encodeURIComponent(branchName)}`,
1176
- { method: "DELETE", errorContext: "Delete Branch" }
1177
- );
1178
- }
1179
- /**
1180
- * Applies a label to a pacticipant.
1181
- *
1182
- * @param params - `pacticipantName` and `labelName` to apply.
1183
- * @returns The created label resource.
1184
- * @throws ToolError if the request fails.
1185
- */
1186
- async addLabel({
1187
- pacticipantName,
1188
- labelName
1189
- }) {
1190
- return await this.fetchJson(
1191
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/labels/${encodeURIComponent(labelName)}`,
1192
- { method: "PUT", body: {}, errorContext: "Add Label" }
1193
- );
1194
- }
1195
- /**
1196
- * Removes a label from a pacticipant.
1197
- *
1198
- * @param params - `pacticipantName` and `labelName` to remove.
1199
- * @throws ToolError if the label or pacticipant is not found, or the request fails.
1200
- */
1201
- async removeLabel({
1202
- pacticipantName,
1203
- labelName
1204
- }) {
1205
- return await this.fetchJson(
1206
- `${this.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/labels/${encodeURIComponent(labelName)}`,
1207
- { method: "DELETE", errorContext: "Remove Label" }
1208
- );
1209
- }
1210
- /**
1211
- * Retrieves all consumer-provider integrations assigned to a specific team.
1212
- *
1213
- * @param params - `teamId`: UUID of the team.
1214
- * @returns List of integrations associated with the team.
1215
- * @throws ToolError if the request fails.
1216
- */
1217
- async getIntegrationsByTeam({
1218
- teamId
1219
- }) {
1220
- return await this.fetchJson(
1221
- `${this.baseUrl}/integrations/team/${encodeURIComponent(teamId)}`,
1222
- {
1223
- method: "GET",
1224
- errorContext: "Get Integrations by Team"
1225
- }
1226
- );
1227
- }
1228
- /**
1229
- * Deletes the integration (pact relationship) between a specific consumer and provider.
1230
- *
1231
- * @param params - `providerName` and `consumerName`.
1232
- * @throws ToolError if the integration is not found or the request fails.
1233
- */
1234
- async deleteIntegration({
1235
- providerName,
1236
- consumerName
1237
- }) {
1238
- return await this.fetchJson(
1239
- `${this.baseUrl}/integrations/provider/${encodeURIComponent(providerName)}/consumer/${encodeURIComponent(consumerName)}`,
1240
- { method: "DELETE", errorContext: "Delete Integration" }
1241
- );
1242
- }
1243
- /**
1244
- * Deletes all consumer-provider integrations in the workspace. Use with caution.
1245
- *
1246
- * @throws ToolError if the request fails.
1247
- */
1248
- async deleteAllIntegrations() {
1249
- return await this.fetchJson(`${this.baseUrl}/integrations`, {
1250
- method: "DELETE",
1251
- errorContext: "Delete All Integrations"
1252
- });
1253
- }
1254
- /**
1255
- * Retrieves all webhooks configured in the workspace.
1256
- *
1257
- * @returns List of webhook definitions and their trigger configurations.
1258
- * @throws ToolError if the request fails.
1259
- */
1260
- async listWebhooks() {
1261
- return await this.fetchJson(`${this.baseUrl}/webhooks`, {
1262
- method: "GET",
1263
- errorContext: "List Webhooks"
1264
- });
1265
- }
1266
- /**
1267
- * Retrieves the configuration for a specific webhook by UUID.
1268
- *
1269
- * @param params - `webhookId`: UUID of the webhook.
1270
- * @returns Webhook definition including its URL, events, and consumer/provider filters.
1271
- * @throws ToolError if the webhook is not found or the request fails.
1272
- */
1273
- async getWebhook({
1274
- webhookId
1275
- }) {
1276
- return await this.fetchJson(
1277
- `${this.baseUrl}/webhooks/${encodeURIComponent(webhookId)}`,
1278
- {
1279
- method: "GET",
1280
- errorContext: "Get Webhook"
1281
- }
1282
- );
1283
- }
1284
- /**
1285
- * Creates a new webhook triggered by pact publication or verification events.
1286
- *
1287
- * @param body - Webhook URL, HTTP method, headers, body, events, and optional
1288
- * consumer/provider filters.
1289
- * @returns The created webhook resource.
1290
- * @throws ToolError if the request fails.
1291
- */
1292
- async createWebhook({
1293
- ...body
1294
- }) {
1295
- return await this.fetchJson(`${this.baseUrl}/webhooks`, {
1296
- method: "POST",
1297
- body,
1298
- errorContext: "Create Webhook"
1299
- });
1300
- }
1301
- /**
1302
- * Replaces the configuration of an existing webhook.
1303
- *
1304
- * @param params - `webhookId` (UUID) plus the full updated webhook definition.
1305
- * @returns The updated webhook resource.
1306
- * @throws ToolError if the webhook is not found or the request fails.
1307
- */
1308
- async updateWebhook({
1309
- webhookId,
1310
- ...body
1311
- }) {
1312
- return await this.fetchJson(
1313
- `${this.baseUrl}/webhooks/${encodeURIComponent(webhookId)}`,
1314
- {
1315
- method: "PUT",
1316
- body,
1317
- errorContext: "Update Webhook"
1318
- }
1319
- );
1320
- }
1321
- /**
1322
- * Deletes a webhook by UUID.
1323
- *
1324
- * @param params - `webhookId`: UUID of the webhook to delete.
1325
- * @throws ToolError if the webhook is not found or the request fails.
1326
- */
1327
- async deleteWebhook({
1328
- webhookId
1329
- }) {
1330
- return await this.fetchJson(
1331
- `${this.baseUrl}/webhooks/${encodeURIComponent(webhookId)}`,
1332
- {
1333
- method: "DELETE",
1334
- errorContext: "Delete Webhook"
1335
- }
1336
- );
1337
- }
1338
- /**
1339
- * Fires all webhooks in the workspace as a test, regardless of their trigger conditions.
1340
- *
1341
- * @throws ToolError if the request fails.
1342
- */
1343
- async executeWebhooks() {
1344
- return await this.fetchJson(`${this.baseUrl}/webhooks/execute`, {
1345
- method: "POST",
1346
- body: {},
1347
- errorContext: "Execute Webhooks"
1348
- });
1349
- }
1350
- /**
1351
- * Fires a specific webhook as a test, regardless of its trigger conditions.
1352
- *
1353
- * @param params - `webhookId`: UUID of the webhook to execute.
1354
- * @throws ToolError if the webhook is not found or the request fails.
1355
- */
1356
- async executeWebhook({
1357
- webhookId
1358
- }) {
1359
- return await this.fetchJson(
1360
- `${this.baseUrl}/webhooks/${encodeURIComponent(webhookId)}/execute`,
1361
- {
1362
- method: "POST",
1363
- body: {},
1364
- errorContext: "Execute Webhook"
1365
- }
1366
- );
1367
- }
1368
- /**
1369
- * Retrieves all secrets stored in the workspace (names only, not values).
1370
- *
1371
- * @returns List of secret metadata.
1372
- * @throws ToolError if the request fails.
1373
- */
1374
- async listSecrets() {
1375
- return await this.fetchJson(`${this.baseUrl}/secrets`, {
1376
- method: "GET",
1377
- errorContext: "List Secrets"
1378
- });
1379
- }
1380
- /**
1381
- * Retrieves metadata for a specific secret by UUID (value is not returned).
1382
- *
1383
- * @param params - `secretId`: UUID of the secret.
1384
- * @throws ToolError if the secret is not found or the request fails.
1385
- */
1386
- async getSecret({
1387
- secretId
1388
- }) {
1389
- return await this.fetchJson(
1390
- `${this.baseUrl}/secrets/${encodeURIComponent(secretId)}`,
1391
- {
1392
- method: "GET",
1393
- errorContext: "Get Secret"
1394
- }
1395
- );
1396
- }
1397
- /**
1398
- * Creates a new secret for use in webhook configurations.
1399
- *
1400
- * @param body - Secret name, description, and value.
1401
- * @returns The created secret resource (value is not echoed back).
1402
- * @throws ToolError if the request fails.
1403
- */
1404
- async createSecret({
1405
- ...body
1406
- }) {
1407
- return await this.fetchJson(`${this.baseUrl}/secrets`, {
1408
- method: "POST",
1409
- body,
1410
- errorContext: "Create Secret"
1411
- });
1412
- }
1413
- /**
1414
- * Replaces the value and/or description of an existing secret.
1415
- *
1416
- * @param params - `secretId` (UUID) plus updated name, description, and/or value.
1417
- * @throws ToolError if the secret is not found or the request fails.
1418
- */
1419
- async updateSecret({
1420
- secretId,
1421
- ...body
1422
- }) {
1423
- return await this.fetchJson(
1424
- `${this.baseUrl}/secrets/${encodeURIComponent(secretId)}`,
1425
- {
1426
- method: "PUT",
1427
- body,
1428
- errorContext: "Update Secret"
1429
- }
1430
- );
1431
- }
1432
- /**
1433
- * Permanently deletes a secret from the workspace.
1434
- *
1435
- * @param params - `secretId`: UUID of the secret to delete.
1436
- * @throws ToolError if the secret is not found or the request fails.
1437
- */
1438
- async deleteSecret({
1439
- secretId
1440
- }) {
1441
- return await this.fetchJson(
1442
- `${this.baseUrl}/secrets/${encodeURIComponent(secretId)}`,
1443
- {
1444
- method: "DELETE",
1445
- errorContext: "Delete Secret"
1446
- }
1447
- );
1448
- }
1449
- /**
1450
- * Retrieves the profile of the currently authenticated user.
1451
- *
1452
- * @returns Current user's name, email, roles, and active status.
1453
- * @throws ToolError if the request fails.
1454
- */
1455
- async getCurrentUser() {
1456
- return await this.fetchJson(`${this.baseUrl}/user`, {
1457
- method: "GET",
1458
- errorContext: "Get Current User"
1459
- });
1460
- }
1461
- /**
1462
- * Lists all API tokens associated with the current user's account.
1463
- *
1464
- * @returns Token metadata (IDs, descriptions) — values are not returned.
1465
- * @throws ToolError if the request fails.
1466
- */
1467
- async listTokens() {
1468
- return await this.fetchJson(`${this.baseUrl}/settings/tokens`, {
1469
- method: "GET",
1470
- errorContext: "List Tokens"
1471
- });
1472
- }
1473
- /**
1474
- * Regenerates (rotates) an API token, invalidating the previous value.
1475
- *
1476
- * @param params - `tokenId`: The identifier of the token to regenerate.
1477
- * @returns The new token value.
1478
- * @throws ToolError if the token is not found or the request fails.
1479
- */
1480
- async regenerateToken({
1481
- tokenId
1482
- }) {
1483
- return await this.fetchJson(
1484
- `${this.baseUrl}/settings/tokens/${encodeURIComponent(tokenId)}/regenerate`,
1485
- {
1486
- method: "POST",
1487
- body: {},
1488
- errorContext: "Regenerate Token"
1489
- }
1490
- );
1491
- }
1492
- /**
1493
- * Retrieves UI and notification preferences for the currently authenticated user.
1494
- *
1495
- * @returns User preference settings.
1496
- * @throws ToolError if the request fails.
1497
- */
1498
- async getUserPreferences() {
1499
- return await this.fetchJson(
1500
- `${this.baseUrl}/preferences/current-user`,
1501
- {
1502
- method: "GET",
1503
- errorContext: "Get User Preferences"
1504
- }
1505
- );
1506
- }
1507
- /**
1508
- * Retrieves workspace-level system preferences and configuration.
1509
- *
1510
- * @returns System preference settings.
1511
- * @throws ToolError if the request fails.
1512
- */
1513
- async getSystemPreferences() {
1514
- return await this.fetchJson(`${this.baseUrl}/preferences/system`, {
1515
- method: "GET",
1516
- errorContext: "Get System Preferences"
1517
- });
1518
- }
1519
- /**
1520
- * Retrieves the workspace audit log with optional filtering and pagination.
1521
- *
1522
- * @param params - Optional filters: `since` (ISO date), `userUuid`, `type`,
1523
- * `sort`, `from` cursor, `pageNumber`, and `pageSize`.
1524
- * @returns Paginated list of audit events.
1525
- * @throws ToolError if the request fails.
1526
- */
1527
- async getAuditLog(params) {
1528
- const queryParams = new URLSearchParams();
1529
- if (params.since) queryParams.set("since", params.since);
1530
- if (params.userUuid) queryParams.set("userUuid", params.userUuid);
1531
- if (params.type) queryParams.set("type", params.type);
1532
- if (params.sort) queryParams.set("sort", params.sort);
1533
- if (params.from) queryParams.set("from", params.from);
1534
- if (params.pageNumber)
1535
- queryParams.set("pageNumber", String(params.pageNumber));
1536
- if (params.pageSize) queryParams.set("pageSize", String(params.pageSize));
1537
- const qs = queryParams.toString();
1538
- return await this.fetchJson(
1539
- `${this.baseUrl}/audit${qs ? `?${qs}` : ""}`,
1540
- {
1541
- method: "GET",
1542
- errorContext: "Get Audit Log"
1543
- }
1544
- );
1545
- }
1546
- /**
1547
- * Lists all users in the workspace with optional filtering and pagination (admin).
1548
- *
1549
- * @param params - Optional `active` flag, `q` (name/email search), `userType`,
1550
- * `page`, and `size`.
1551
- * @returns Paginated list of user accounts.
1552
- * @throws ToolError if the request fails.
1553
- */
1554
- async listAdminUsers(params) {
1555
- const queryParams = new URLSearchParams();
1556
- if (params.active !== void 0)
1557
- queryParams.set("active", String(params.active));
1558
- if (params.q) queryParams.set("q", params.q);
1559
- if (params.userType !== void 0)
1560
- queryParams.set("userType", String(params.userType));
1561
- if (params.page) queryParams.set("page", String(params.page));
1562
- if (params.size) queryParams.set("size", String(params.size));
1563
- const qs = queryParams.toString();
1564
- return await this.fetchJson(
1565
- `${this.baseUrl}/admin/users${qs ? `?${qs}` : ""}`,
1566
- {
1567
- method: "GET",
1568
- errorContext: "List Admin Users"
1569
- }
1570
- );
1571
- }
1572
- /**
1573
- * Retrieves a user's full profile by UUID (admin).
1574
- *
1575
- * @param params - `userId`: UUID of the user.
1576
- * @returns User profile including roles and active status.
1577
- * @throws ToolError if the user is not found or the request fails.
1578
- */
1579
- async getAdminUser({
1580
- userId
1581
- }) {
1582
- return await this.fetchJson(
1583
- `${this.baseUrl}/admin/users/${encodeURIComponent(userId)}`,
1584
- {
1585
- method: "GET",
1586
- errorContext: "Get Admin User"
1587
- }
1588
- );
1589
- }
1590
- /**
1591
- * Creates a new user account in the workspace (admin).
1592
- *
1593
- * @param body - User name, email, and optional SSO identity fields.
1594
- * @returns The created user resource.
1595
- * @throws ToolError if the request fails.
1596
- */
1597
- async createAdminUser({
1598
- ...body
1599
- }) {
1600
- return await this.fetchJson(`${this.baseUrl}/admin/users`, {
1601
- method: "POST",
1602
- body,
1603
- errorContext: "Create Admin User"
1604
- });
1605
- }
1606
- /**
1607
- * Replaces a user's profile (admin). Can also deactivate the user.
1608
- *
1609
- * @param params - `userId` (UUID) plus updated name, email, active flag, and SSO fields.
1610
- * @returns The updated user resource.
1611
- * @throws ToolError if the user is not found or the request fails.
1612
- */
1613
- async updateAdminUser({
1614
- userId,
1615
- ...body
1616
- }) {
1617
- return await this.fetchJson(
1618
- `${this.baseUrl}/admin/users/${encodeURIComponent(userId)}`,
1619
- {
1620
- method: "PUT",
1621
- body,
1622
- errorContext: "Update Admin User"
1623
- }
1624
- );
1625
- }
1626
- /**
1627
- * Permanently deletes a user account from the workspace (admin).
1628
- *
1629
- * @param params - `userId`: UUID of the user to delete.
1630
- * @throws ToolError if the user is not found or the request fails.
1631
- */
1632
- async deleteAdminUser({
1633
- userId
1634
- }) {
1635
- return await this.fetchJson(
1636
- `${this.baseUrl}/admin/users/${encodeURIComponent(userId)}`,
1637
- {
1638
- method: "DELETE",
1639
- errorContext: "Delete Admin User"
1640
- }
1641
- );
1642
- }
1643
- /**
1644
- * Sends invitation emails to one or more new users (admin).
1645
- *
1646
- * @param params - `users`: Array of objects with email and optional name.
1647
- * @throws ToolError if the request fails.
1648
- */
1649
- async inviteUsers({
1650
- users
1651
- }) {
1652
- return await this.fetchJson(
1653
- `${this.baseUrl}/admin/users/invite-users`,
1654
- {
1655
- method: "POST",
1656
- body: { users },
1657
- errorContext: "Invite Users"
1658
- }
1659
- );
1660
- }
1661
- /**
1662
- * Fully replaces the roles assigned to a user (admin).
1663
- * All existing roles are removed; the provided list becomes the new set.
1664
- *
1665
- * @param params - `userId` (UUID) and `roles` array of role UUIDs.
1666
- * @throws ToolError if the user is not found or the request fails.
1667
- */
1668
- async setUserRoles({
1669
- userId,
1670
- roles
1671
- }) {
1672
- return await this.fetchJson(
1673
- `${this.baseUrl}/admin/users/${encodeURIComponent(userId)}/roles`,
1674
- {
1675
- method: "PUT",
1676
- body: { roles },
1677
- errorContext: "Set User Roles"
1678
- }
1679
- );
1680
- }
1681
- /**
1682
- * Grants a single additional role to a user without affecting their existing roles (admin).
1683
- *
1684
- * @param params - `userId` and `roleId` UUIDs.
1685
- * @throws ToolError if the user or role is not found, or the request fails.
1686
- */
1687
- async addRoleToUser({
1688
- userId,
1689
- roleId
1690
- }) {
1691
- return await this.fetchJson(
1692
- `${this.baseUrl}/admin/users/${encodeURIComponent(userId)}/roles/${encodeURIComponent(roleId)}`,
1693
- { method: "PUT", body: {}, errorContext: "Add Role to User" }
1694
- );
1695
- }
1696
- /**
1697
- * Revokes a specific role from a user without affecting their other roles (admin).
1698
- *
1699
- * @param params - `userId` and `roleId` UUIDs.
1700
- * @throws ToolError if the user or role is not found, or the request fails.
1701
- */
1702
- async removeRoleFromUser({
1703
- userId,
1704
- roleId
1705
- }) {
1706
- return await this.fetchJson(
1707
- `${this.baseUrl}/admin/users/${encodeURIComponent(userId)}/roles/${encodeURIComponent(roleId)}`,
1708
- { method: "DELETE", errorContext: "Remove Role from User" }
1709
- );
1710
- }
1711
- /**
1712
- * Lists all teams in the workspace with optional name filtering and pagination (admin).
1713
- *
1714
- * @param params - Optional `q` (name search), `page`, and `size`.
1715
- * @returns Paginated list of teams.
1716
- * @throws ToolError if the request fails.
1717
- */
1718
- async listAdminTeams(params) {
1719
- const queryParams = new URLSearchParams();
1720
- if (params.q) queryParams.set("q", params.q);
1721
- if (params.page) queryParams.set("page", String(params.page));
1722
- if (params.size) queryParams.set("size", String(params.size));
1723
- const qs = queryParams.toString();
1724
- return await this.fetchJson(
1725
- `${this.baseUrl}/admin/teams${qs ? `?${qs}` : ""}`,
1726
- {
1727
- method: "GET",
1728
- errorContext: "List Admin Teams"
1729
- }
1730
- );
1731
- }
1732
- /**
1733
- * Retrieves the full configuration of a team by UUID (admin).
1734
- *
1735
- * @param params - `teamId`: UUID of the team.
1736
- * @returns Team details including name, members, environments, and pacticipants.
1737
- * @throws ToolError if the team is not found or the request fails.
1738
- */
1739
- async getAdminTeam({
1740
- teamId
1741
- }) {
1742
- return await this.fetchJson(
1743
- `${this.baseUrl}/admin/teams/${encodeURIComponent(teamId)}`,
1744
- {
1745
- method: "GET",
1746
- errorContext: "Get Admin Team"
1747
- }
1748
- );
1749
- }
1750
- /**
1751
- * Creates a new team in the workspace (admin).
1752
- *
1753
- * @param body - Team name and optional administrators, environments, and pacticipants.
1754
- * @returns The created team resource.
1755
- * @throws ToolError if the request fails.
1756
- */
1757
- async createAdminTeam({
1758
- ...body
1759
- }) {
1760
- return await this.fetchJson(`${this.baseUrl}/admin/teams`, {
1761
- method: "POST",
1762
- body,
1763
- errorContext: "Create Admin Team"
1764
- });
1765
- }
1766
- /**
1767
- * Fully replaces a team's configuration (admin).
1768
- *
1769
- * @param params - `teamId` (UUID) plus updated name, administrators, environments,
1770
- * and pacticipant assignments.
1771
- * @throws ToolError if the team is not found or the request fails.
1772
- */
1773
- async updateAdminTeam({
1774
- teamId,
1775
- ...body
1776
- }) {
1777
- return await this.fetchJson(
1778
- `${this.baseUrl}/admin/teams/${encodeURIComponent(teamId)}`,
1779
- {
1780
- method: "PUT",
1781
- body,
1782
- errorContext: "Update Admin Team"
1783
- }
1784
- );
1785
- }
1786
- /**
1787
- * Permanently deletes a team from the workspace (admin). Members are not deleted.
1788
- *
1789
- * @param params - `teamId`: UUID of the team to delete.
1790
- * @throws ToolError if the team is not found or the request fails.
1791
- */
1792
- async deleteAdminTeam({
1793
- teamId
1794
- }) {
1795
- return await this.fetchJson(
1796
- `${this.baseUrl}/admin/teams/${encodeURIComponent(teamId)}`,
1797
- {
1798
- method: "DELETE",
1799
- errorContext: "Delete Admin Team"
1800
- }
1801
- );
1802
- }
1803
- /**
1804
- * Lists all user members of a specific team (admin).
1805
- *
1806
- * @param params - `teamId`: UUID of the team.
1807
- * @returns List of users in the team.
1808
- * @throws ToolError if the team is not found or the request fails.
1809
- */
1810
- async listTeamUsers({
1811
- teamId
1812
- }) {
1813
- return await this.fetchJson(
1814
- `${this.baseUrl}/admin/teams/${encodeURIComponent(teamId)}/users`,
1815
- {
1816
- method: "GET",
1817
- errorContext: "List Team Users"
1818
- }
1819
- );
1820
- }
1821
- /**
1822
- * Verifies whether a specific user is a member of a team (admin).
1823
- * Returns 404 if the user is not in the team.
1824
- *
1825
- * @param params - `teamId` and `userId` UUIDs.
1826
- * @throws ToolError if not found or the request fails.
1827
- */
1828
- async getTeamUser({
1829
- teamId,
1830
- userId
1831
- }) {
1832
- return await this.fetchJson(
1833
- `${this.baseUrl}/admin/teams/${encodeURIComponent(teamId)}/users/${encodeURIComponent(userId)}`,
1834
- { method: "GET", errorContext: "Get Team User" }
1835
- );
1836
- }
1837
- /**
1838
- * Fully replaces the members of a team (admin).
1839
- * All existing members are removed; the provided UUID list becomes the new membership.
1840
- *
1841
- * @param params - `teamId` (UUID) and `uuids` array of user UUIDs.
1842
- * @throws ToolError if the team is not found or the request fails.
1843
- */
1844
- async setTeamUsers({
1845
- teamId,
1846
- uuids
1847
- }) {
1848
- return await this.fetchJson(
1849
- `${this.baseUrl}/admin/teams/${encodeURIComponent(teamId)}/users`,
1850
- {
1851
- method: "PUT",
1852
- body: { users: uuids },
1853
- errorContext: "Set Team Users"
1854
- }
1855
- );
1856
- }
1857
- /**
1858
- * Adds or removes individual users from a team using JSON Patch semantics (admin).
1859
- *
1860
- * @param params - `teamId` (UUID) and `operations` array of JSON Patch ops (add/remove).
1861
- * @throws ToolError if the team is not found or the request fails.
1862
- */
1863
- async patchTeamUsers({
1864
- teamId,
1865
- operations
1866
- }) {
1867
- return await this.fetchJson(
1868
- `${this.baseUrl}/admin/teams/${encodeURIComponent(teamId)}/users`,
1869
- {
1870
- method: "PATCH",
1871
- body: operations,
1872
- errorContext: "Patch Team Users"
1873
- }
1874
- );
1875
- }
1876
- /**
1877
- * Removes a specific user from a team (admin).
1878
- *
1879
- * @param params - `teamId` and `userId` UUIDs.
1880
- * @throws ToolError if not found or the request fails.
1881
- */
1882
- async removeUserFromTeam({
1883
- teamId,
1884
- userId
1885
- }) {
1886
- return await this.fetchJson(
1887
- `${this.baseUrl}/admin/teams/${encodeURIComponent(teamId)}/users/${encodeURIComponent(userId)}`,
1888
- { method: "DELETE", errorContext: "Remove User from Team" }
1889
- );
1890
- }
1891
- /**
1892
- * Lists all roles defined in the workspace (admin).
1893
- *
1894
- * @returns All role definitions and their associated permission scopes.
1895
- * @throws ToolError if the request fails.
1896
- */
1897
- async listAdminRoles() {
1898
- return await this.fetchJson(`${this.baseUrl}/admin/roles`, {
1899
- method: "GET",
1900
- errorContext: "List Admin Roles"
1901
- });
1902
- }
1903
- /**
1904
- * Retrieves a role's name, description, and full permission set by UUID (admin).
1905
- *
1906
- * @param params - `roleId`: UUID of the role.
1907
- * @throws ToolError if the role is not found or the request fails.
1908
- */
1909
- async getAdminRole({
1910
- roleId
1911
- }) {
1912
- return await this.fetchJson(
1913
- `${this.baseUrl}/admin/roles/${encodeURIComponent(roleId)}`,
1914
- {
1915
- method: "GET",
1916
- errorContext: "Get Admin Role"
1917
- }
1918
- );
1919
- }
1920
- /**
1921
- * Creates a custom role with a tailored set of permission scopes (admin).
1922
- *
1923
- * @param body - Role name, optional description, and array of permission scope strings.
1924
- * @returns The created role resource.
1925
- * @throws ToolError if the request fails.
1926
- */
1927
- async createAdminRole({
1928
- ...body
1929
- }) {
1930
- return await this.fetchJson(`${this.baseUrl}/admin/roles`, {
1931
- method: "POST",
1932
- body,
1933
- errorContext: "Create Admin Role"
1934
- });
1935
- }
1936
- /**
1937
- * Updates an existing role's name and/or permission set (admin).
1938
- * Changes affect all users currently assigned the role.
1939
- *
1940
- * @param params - `roleId` (UUID) plus updated name, description, and permissions.
1941
- * @throws ToolError if the role is not found or the request fails.
1942
- */
1943
- async updateAdminRole({
1944
- roleId,
1945
- ...body
1946
- }) {
1947
- return await this.fetchJson(
1948
- `${this.baseUrl}/admin/roles/${encodeURIComponent(roleId)}`,
1949
- {
1950
- method: "PUT",
1951
- body,
1952
- errorContext: "Update Admin Role"
1953
- }
1954
- );
1955
- }
1956
- /**
1957
- * Permanently deletes a role (admin). Users assigned this role will lose its permissions.
1958
- *
1959
- * @param params - `roleId`: UUID of the role to delete.
1960
- * @throws ToolError if the role is not found or the request fails.
1961
- */
1962
- async deleteAdminRole({
1963
- roleId
1964
- }) {
1965
- return await this.fetchJson(
1966
- `${this.baseUrl}/admin/roles/${encodeURIComponent(roleId)}`,
1967
- {
1968
- method: "DELETE",
1969
- errorContext: "Delete Admin Role"
1970
- }
1971
- );
1972
- }
1973
- /**
1974
- * Resets all roles to factory defaults (admin).
1975
- * Custom roles are removed; built-in roles are restored to their original permissions.
1976
- *
1977
- * @throws ToolError if the request fails.
1978
- */
1979
- async resetAdminRoles() {
1980
- return await this.fetchJson(`${this.baseUrl}/admin/roles/reset`, {
1981
- method: "POST",
1982
- body: {},
1983
- errorContext: "Reset Admin Roles"
1984
- });
1985
- }
1986
- /**
1987
- * Lists all permission scopes available to assign to roles (admin).
1988
- *
1989
- * @returns All permission scope definitions.
1990
- * @throws ToolError if the request fails.
1991
- */
1992
- async listAdminPermissions() {
1993
- return await this.fetchJson(`${this.baseUrl}/admin/permissions`, {
1994
- method: "GET",
1995
- errorContext: "List Admin Permissions"
1996
- });
1997
- }
1998
- /**
1999
- * Creates a machine/service account that authenticates via API token (admin).
2000
- *
2001
- * @param body - Account name and optional description.
2002
- * @returns The created system account resource.
2003
- * @throws ToolError if the request fails.
2004
- */
2005
- async createSystemAccount({
2006
- ...body
2007
- }) {
2008
- return await this.fetchJson(`${this.baseUrl}/admin/system-accounts`, {
2009
- method: "POST",
2010
- body,
2011
- errorContext: "Create System Account"
2012
- });
2013
- }
2014
- /**
2015
- * Retrieves the API tokens associated with a system account (admin).
2016
- *
2017
- * @param params - `accountId`: UUID of the system account.
2018
- * @returns Token list for use in CI/CD pipelines.
2019
- * @throws ToolError if the account is not found or the request fails.
2020
- */
2021
- async getSystemAccountTokens({
2022
- accountId
2023
- }) {
2024
- return await this.fetchJson(
2025
- `${this.baseUrl}/admin/system-accounts/${encodeURIComponent(accountId)}/tokens`,
2026
- {
2027
- method: "GET",
2028
- errorContext: "Get System Account Tokens"
2029
- }
2030
- );
2031
- }
2032
- /**
2033
- * Registers tools with the provided register function.
2034
- *
2035
- * @param register - The function used to register tools.
2036
- * @param getInput - The function used to get input for tools.
2037
- */
2038
104
  async registerTools(register, getInput) {
2039
105
  let disablePactflowAItools = false;
2040
106
  try {
2041
- const entitlement = await this.checkAIEntitlements();
107
+ const aiApi = new AIApi(this.http, `${this.http.baseUrl}/api/ai`);
108
+ const entitlement = await aiApi.checkAIEntitlements();
2042
109
  if (entitlement && !entitlement.aiEnabled) {
2043
110
  disablePactflowAItools = true;
2044
111
  }
@@ -2055,26 +122,26 @@ class PactflowClient {
2055
122
  }
2056
123
  const { handler, clients: _, formatResponse, ...toolParams } = tool;
2057
124
  register(toolParams, async (args, _ctx) => {
2058
- const handler_fn = this[handler];
125
+ const handler_fn = this.handlerMap[handler];
2059
126
  if (typeof handler_fn !== "function") {
2060
127
  throw new Error(`Handler '${handler}' not found on PactClient`);
2061
128
  }
2062
129
  let result;
2063
130
  if (tool.paginated) {
2064
- if (!this.baseUrl || !this.cache) {
131
+ if (!this.http || !this.cache) {
2065
132
  throw new ToolError(
2066
133
  "PactflowClient must be configured before registering paginated tools"
2067
134
  );
2068
135
  }
2069
- result = await withPagination(handler_fn.bind(this), handler, args, {
2070
- baseUrl: this.baseUrl,
136
+ result = await withPagination(handler_fn, handler, args, {
137
+ baseUrl: this.http.baseUrl,
2071
138
  authToken: this.requestHeaders?.Authorization,
2072
139
  cache: this.cache
2073
140
  });
2074
141
  } else if (tool.enableElicitation) {
2075
- result = await handler_fn.call(this, args, getInput);
142
+ result = await handler_fn(args, getInput);
2076
143
  } else {
2077
- result = await handler_fn.call(this, args);
144
+ result = await handler_fn(args);
2078
145
  }
2079
146
  if (formatResponse) {
2080
147
  return formatResponse(result);
@@ -2085,11 +152,6 @@ class PactflowClient {
2085
152
  });
2086
153
  }
2087
154
  }
2088
- /**
2089
- * Registers prompts with the provided register function.
2090
- *
2091
- * @param register - The function used to register prompts.
2092
- */
2093
155
  async registerPrompts(register) {
2094
156
  for (const prompt of PROMPTS) {
2095
157
  register(