@qawolf/ci-sdk 3.3.0-oidc-check.0 → 3.4.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/README.md CHANGED
@@ -18,7 +18,9 @@ to determine the status of your CI/CD step/job/action.
18
18
  - [Notify Preview Deployment (Pull Request / Merge Request Testing)](#notify-preview)
19
19
  - [Poll for CI Greenlight Status (deprecated)](#ci-greenlight)
20
20
  - [Advanced: Poll with Custom Control (Iterator)](#ci-greenlight-iterator)
21
- - [Notify a Terminated Ephemeral Environment](#notify-terminated-ephemeral-environment)
21
+ - [Promote or Terminate a Preview Environment](#environment-lifecycle)
22
+ - [Read a Promotion](#promotion-get)
23
+ - [Notify a Terminated Ephemeral Environment (deprecated)](#notify-terminated-ephemeral-environment)
22
24
  - [Upload Run Input Artifacts](#upload-artifacts)
23
25
  - [Requirements](#requirements)
24
26
  - [Versioning](#versioning)
@@ -63,7 +65,9 @@ await attemptNotifyDeploy({
63
65
  });
64
66
  ```
65
67
 
66
- `notifyTerminatedEphemeralEnvironment` accepts `workspaceId` the same way.
68
+ `notifyTerminatedEphemeralEnvironment` accepts `workspaceId` the same way. `environment.promote` and
69
+ `environment.terminate` take it only when `environmentId` is an alias rather than an id, since an
70
+ alias is unique within one workspace; `promotion.get` never needs it.
67
71
 
68
72
  ### What happens when it is missing
69
73
 
@@ -76,6 +80,7 @@ call, so it is worth knowing which behavior to expect:
76
80
  | `generateSignedUrlForRunInputsExecutablesStorage` | Same as above — the backend answers HTTP `400`. |
77
81
  | `attemptNotifyDeploy` | Succeeds against your organization's first-created workspace and returns a `warning` naming it. |
78
82
  | `notifyTerminatedEphemeralEnvironment` | Succeeds against your organization's first-created workspace and returns a `warning` naming it. |
83
+ | `environment.promote`, `environment.terminate` | Succeeds when `environmentId` is an id. An alias cannot be resolved without a workspace, so it answers `invalid-request`. |
79
84
 
80
85
  > ⚠️ The signed-URL functions **require** `workspaceId` for organization and user API keys — they do
81
86
  > not fall back to a default workspace. A `400` from either function, especially when the API key and
@@ -471,6 +476,8 @@ await deployment.reportStatus({
471
476
 
472
477
  `metadata.pullRequestNumber` names a GitLab merge request too. For a preview with no code hosting integration, pass `deployTarget` and an ephemeral `environment` and leave the repository fields out. `environment.baseEphemeralEnvironment` names the environment an ephemeral one inherits its configuration from.
473
478
 
479
+ With an integration, QA Wolf ends the preview environment when the code host says the pull request merged or closed. Without one, or when your pipeline owns the preview's lifecycle, end it yourself with [`environment.promote` or `environment.terminate`](#environment-lifecycle).
480
+
474
481
  The [GitHub Action](https://github.com/marketplace/actions/notify-qa-wolf-on-deploy) and `attemptNotifyDeploy`'s `hostingService` / `mergeRequestNumber` / `ephemeralEnvironment` / `deploymentUrl` fields still work, but they report through the legacy `deploy_success` webhook that triggers do not see.
475
482
 
476
483
  <a id="ci-greenlight"></a>
@@ -645,15 +652,102 @@ When `abortReason` is `"run-canceled"`, the iteration also carries:
645
652
 
646
653
  **Important**: Always check `iteration.isAborted` to determine which type of result you received. When `isAborted === true`, you should handle the abort reason and exit appropriately.
647
654
 
655
+ <a id="environment-lifecycle"></a>
656
+
657
+ ## Promote or Terminate a Preview Environment
658
+
659
+ A preview environment created by [`deployment.reportStatus`](#report-deployment) accumulates flow changes while QA Wolf tests it. When the pull request is done, those changes either go into the base environment or they do not, and the environment is torn down. Two calls, and they are not interchangeable:
660
+
661
+ - `environment.promote` — the work was **accepted**, typically on merge. The environment's flow changes are merged into its base environment and the environment is terminated once they land.
662
+ - `environment.terminate` — the work was **abandoned**, typically on a close without merge. The flow changes are discarded and the environment's runs are canceled.
663
+
664
+ Terminating an accepted preview throws away the flow work done for that pull request. Promoting an abandoned one merges flows nobody kept into the base that every later preview copies from.
665
+
666
+ ```ts
667
+ import { makeQaWolfSdk } from "@qawolf/ci-sdk";
668
+
669
+ const { environment } = makeQaWolfSdk({ apiKey: "qawolf_xxxxx" });
670
+
671
+ if (pullRequestWasMerged) {
672
+ const result = await environment.promote({
673
+ environmentId: `pr-${pullRequestNumber}`,
674
+ workspaceId: "your-workspace-id",
675
+ });
676
+ if (result.outcome !== "requested") process.exit(1);
677
+ // The merge runs in the background; see "Read a Promotion" below.
678
+ console.log(result.promotion.id, result.promotion.status); // "pending"
679
+ } else {
680
+ const result = await environment.terminate({
681
+ environmentId: `pr-${pullRequestNumber}`,
682
+ workspaceId: "your-workspace-id",
683
+ });
684
+ if (result.outcome !== "terminated") process.exit(1);
685
+ }
686
+ ```
687
+
688
+ `environmentId` is the environment's id or its alias. An alias is unique within one workspace, so an organization or user API key must also pass `workspaceId` to use one; a workspace API key implies it. The parameters are exactly the input of the `environment.promote` and `environment.terminate` contracts, derived from the published `@qawolf/api-contracts` package.
689
+
690
+ ### Result
691
+
692
+ `environment.promote` answers `{ outcome: "requested", promotion }`, and `environment.terminate` answers `{ outcome: "terminated", environment }` with `terminatedAt` set. Both share the refusals below. Neither throws.
693
+
694
+ | `outcome` | Meaning |
695
+ | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
696
+ | `invalid-request` | The call cannot be carried out as sent: the environment is already terminated, for a promotion it has no base environment to promote into, or an alias was sent without the `workspaceId` an organization or user API key needs to resolve it. Carries `message`. HTTP `400`. |
697
+ | `unauthorized` | The API key is unknown, or may not act on this workspace. Carries `message`. |
698
+ | `not-found` | No environment matches `environmentId`. Carries `message`. |
699
+ | `conflict` | The call clashes with the environment's current state. Carries `message`. |
700
+ | `server-error` | QA Wolf failed to answer; retrying is reasonable. Carries `httpStatus`. |
701
+ | `unexpected-status` | A status this SDK version does not map. Carries `httpStatus` and `message`. |
702
+ | `network-error` | The request never reached QA Wolf, or the connection dropped. |
703
+ | `invalid-response-body` | The server answered 2xx with a body the contract's output rejects. |
704
+
705
+ Calling `environment.promote` again while a promotion is open returns that same promotion rather than opening a second one. An environment whose promotion is still being applied cannot be terminated until it settles; one whose promotion is `conflicted` can.
706
+
707
+ <a id="promotion-get"></a>
708
+
709
+ ## Read a Promotion
710
+
711
+ `environment.promote` returns the promotion in `pending`, because the merge runs in the background. `promotion.get` reads how it settled:
712
+
713
+ ```ts
714
+ const { promotion } = makeQaWolfSdk({ apiKey: "qawolf_xxxxx" });
715
+
716
+ const result = await promotion.get({ promotionId });
717
+ if (result.outcome !== "found") process.exit(1);
718
+
719
+ switch (result.promotion.status) {
720
+ case "pending":
721
+ case "resolving":
722
+ break; // Poll again later.
723
+ case "promoted":
724
+ case "no-changes":
725
+ break; // Settled; the preview environment is terminated.
726
+ case "conflicted":
727
+ // The head's flow changes clash with the base. `result.promotion.conflict.paths`
728
+ // names the files; a person resolves it in QA Wolf, and the environment stays
729
+ // until they do.
730
+ break;
731
+ case "abandoned":
732
+ break; // The environment was terminated before the promotion settled.
733
+ }
734
+ ```
735
+
736
+ `status` reads `pending`, `conflicted`, `resolving`, `promoted`, `no-changes` or `abandoned`. `conflict` is present while it is `conflicted` or `resolving`, `promotedCommitHash` once it is `promoted`, and `settledAt` once it is `promoted`, `no-changes` or `abandoned`. Refusals are the same as for the environment calls above, with `not-found` meaning no promotion matches `promotionId`.
737
+
738
+ A promotion usually settles within a minute or two. The SDK has no wait helper for it yet, so a pipeline that needs the settled status polls `promotion.get` itself, with `pending` and `resolving` as the states to keep polling on.
739
+
648
740
  <a id="notify-terminated-ephemeral-environment"></a>
649
741
 
650
742
  ## Notify a Terminated Ephemeral Environment
651
743
 
744
+ > ⚠️ **Deprecated.** Despite its name, this method performs a **promote**: the legacy `environment_terminated` webhook merges the environment's flow changes into its base and then terminates it. Use [`environment.promote`](#environment-lifecycle) for accepted work, and [`environment.terminate`](#environment-lifecycle) to discard abandoned work, which this method has never done. It keeps working and there is no removal date.
745
+
652
746
  > ℹ️ [See the API documentation page for this endpoint](https://qawolf.notion.site/2c45b2a994fb8096a42af8d41c811ae2).
653
747
 
654
748
  After you terminate an ephemeral environment or release it for something else to be installed in it, you should notify QA Wolf of that fact. When you notify us, we will stop all runs targeting that environment and check whether there are any changes to flows that need to be promoted to the static base environment. This eventually results in the environment showing as "closed" in QA Wolf.
655
749
 
656
- > ⚠️ **Note**: If you have the QA Wolf GitHub integration enabled for your preview testing, GitHub will notify us of PRs being merged or closed, and we use that notification to stop runs and trigger flow promotion. In this case, it is typically redundant and unnecessary to call this..
750
+ > ⚠️ **Note**: If you have the QA Wolf GitHub integration enabled for your preview testing, GitHub will notify us of PRs being merged or closed, and we use that notification to stop runs. A merged pull request promotes the environment's flow changes into its base; a pull request closed without merging terminates the environment and discards those changes. In this case, it is typically redundant and unnecessary to call this.
657
751
 
658
752
  > ⚠️ **Important**: PR/MR testing functionality must be activated by QA Wolf. Please reach out to your QA Wolf representative to enable this feature and help with the setup.
659
753
 
@@ -819,6 +913,13 @@ This package follows the [SemVer](https://semver.org/) versioning scheme. Additi
819
913
 
820
914
  # Changelog
821
915
 
916
+ ## v3.4.0
917
+
918
+ - New `environment.promote` and `environment.terminate` functions, for a pipeline that manages its own preview environments. `environment.promote` declares the work accepted: the environment's flow changes are merged into its base and the environment is terminated once they land. It returns the promotion in `pending`, since the merge runs in the background. `environment.terminate` discards abandoned work: the flow changes are not promoted and the runs are canceled. The two are not interchangeable. Both derive their parameters from `@qawolf/api-contracts` and answer refusals with the same named outcomes as `deployment.reportStatus`. See [Promote or Terminate a Preview Environment](#environment-lifecycle).
919
+ - New `promotion.get` function, which reads a promotion's `status` and, while it is conflicted, the conflicting paths, so a pipeline can learn how the promotion it requested settled. See [Read a Promotion](#promotion-get).
920
+ - `notifyTerminatedEphemeralEnvironment` is deprecated. Despite its name it performs a promote through the legacy `environment_terminated` webhook, merging the environment's flow changes into its base before terminating it. Replace it with `environment.promote`, or with `environment.terminate` where the work is abandoned. It keeps working unchanged, prints no warning, and has no removal date.
921
+ - The `@qawolf/api-contracts` dependency floor is now `0.89.0`, the first version serving the `environment.terminate` contract.
922
+
822
923
  ## v3.3.0
823
924
 
824
925
  - `deployment.waitForVerdict` answers `superseded` when a newer deployment to the same branch and environment replaced the run before it finished. It carries `runs` and `supersededBy` with the replacement's id and URL, is not a pass, and the wait stops there rather than follow the replacement, which may be testing a later commit. A caller switching exhaustively on `outcome` has one more case to handle; the recipe's `["passed", "not-tested"].includes(...)` check needs no change. `runs[].status` now uses the run summary's vocabulary, so it can read `superseded`, and `runs[]` carries `supersededBy` for such a run. See [Wait for a Verdict](#wait-for-verdict).
package/dist/index.js CHANGED
@@ -123,12 +123,17 @@ var defaultServiceBase = "https://app.qawolf.com/";
123
123
  // package.json
124
124
  var package_default = {
125
125
  name: "@qawolf/ci-sdk",
126
- version: "3.3.0",
126
+ version: "3.4.0",
127
127
  private: false,
128
128
  description: "A simple SDK for interacting with QAWolf in CI scripts.",
129
129
  keywords: [],
130
130
  license: "MIT",
131
131
  author: "Jules Sam. Randolph<jules@qawolf.com>",
132
+ repository: {
133
+ type: "git",
134
+ url: "git+https://github.com/qawolf/platform.git",
135
+ directory: "packages-published-public/ci-sdk"
136
+ },
132
137
  files: [
133
138
  "/dist",
134
139
  "/README.md"
@@ -152,7 +157,7 @@ var package_default = {
152
157
  "tsc:check": "tsc --noEmit"
153
158
  },
154
159
  dependencies: {
155
- "@qawolf/api-contracts": ">=0.73.0",
160
+ "@qawolf/api-contracts": ">=0.89.0",
156
161
  "@qawolf/ci-utils": "^2.0.0",
157
162
  "@sinonjs/fake-timers": "^10.3.0",
158
163
  tslib: "^2.6.2",
@@ -500,6 +505,145 @@ async function handleErrorResponse(response, log) {
500
505
  }
501
506
  __name(handleErrorResponse, "handleErrorResponse");
502
507
 
508
+ // src/lib/sdk/domain/environment/promote.ts
509
+ import { publicContractsV1 } from "@qawolf/api-contracts";
510
+
511
+ // src/lib/sdk/publicApi/callContract.ts
512
+ function isRecord2(value) {
513
+ return typeof value === "object" && value !== null;
514
+ }
515
+ __name(isRecord2, "isRecord");
516
+ function isSuperJsonEnvelope(data) {
517
+ return "json" in data && Object.keys(data).every((key) => key === "json" || key === "meta");
518
+ }
519
+ __name(isSuperJsonEnvelope, "isSuperJsonEnvelope");
520
+ function unwrapTrpcEnvelope(body) {
521
+ if (!isRecord2(body) || !isRecord2(body.result)) return void 0;
522
+ const data = body.result.data;
523
+ return isRecord2(data) && isSuperJsonEnvelope(data) ? data.json : data;
524
+ }
525
+ __name(unwrapTrpcEnvelope, "unwrapTrpcEnvelope");
526
+ function readTrpcError(body) {
527
+ const wrapped = isRecord2(body) ? body.error : void 0;
528
+ const error = isRecord2(wrapped) && isRecord2(wrapped.json) ? wrapped.json : wrapped;
529
+ if (!isRecord2(error)) return { eventId: void 0, message: void 0 };
530
+ const data = isRecord2(error.data) ? error.data : void 0;
531
+ return {
532
+ eventId: typeof data?.eventId === "string" ? data.eventId : void 0,
533
+ message: typeof error.message === "string" ? error.message : void 0
534
+ };
535
+ }
536
+ __name(readTrpcError, "readTrpcError");
537
+ function parseJson(text) {
538
+ if (text === void 0) return void 0;
539
+ try {
540
+ return JSON.parse(text);
541
+ } catch {
542
+ return void 0;
543
+ }
544
+ }
545
+ __name(parseJson, "parseJson");
546
+ async function readHttpError(response, contractName, log) {
547
+ const bodyText = await response.text().catch(() => void 0);
548
+ const { eventId, message } = readTrpcError(parseJson(bodyText));
549
+ const statusText = response.status >= 500 ? "Server Error" : response.statusText || "Unknown Error";
550
+ const eventIdSuffix = eventId ? ` (Event ID: ${eventId})` : "";
551
+ const messageSuffix = message ? `: ${message}` : "";
552
+ log.error(
553
+ `\u274C [${contractName}] ${response.status} ${statusText}${eventIdSuffix}${messageSuffix}`
554
+ );
555
+ return {
556
+ eventId,
557
+ httpStatus: response.status,
558
+ message,
559
+ outcome: "http-error"
560
+ };
561
+ }
562
+ __name(readHttpError, "readHttpError");
563
+ async function callPublicContract({ fetch: localFetch, log }, apiConfig, {
564
+ contract,
565
+ input
566
+ }) {
567
+ const procedurePath = `public.${contract.name}`;
568
+ let bodyText;
569
+ try {
570
+ const response = await localFetch(
571
+ new URL(`/api/trpc/${procedurePath}`, apiConfig.serviceBase),
572
+ {
573
+ // The server's superjson transformer reads the input from `json`.
574
+ body: JSON.stringify({ json: input }),
575
+ headers: {
576
+ Authorization: `Bearer ${apiConfig.apiKey}`,
577
+ "Content-Type": "application/json",
578
+ "User-Agent": apiConfig.userAgent
579
+ },
580
+ method: "POST"
581
+ }
582
+ );
583
+ if (!response.ok) return readHttpError(response, contract.name, log);
584
+ bodyText = await response.text();
585
+ } catch {
586
+ log.error(`\u{1F6AB} Network error from ${contract.name}.`);
587
+ return { outcome: "network-error" };
588
+ }
589
+ const parsed = contract.output.safeParse(
590
+ unwrapTrpcEnvelope(parseJson(bodyText))
591
+ );
592
+ if (!parsed.success) {
593
+ log.error(
594
+ `\u{1F6AB} Invalid response from ${contract.name} (${parsed.error.issues[0]?.message ?? "the response body did not match the contract"}), aborting.`
595
+ );
596
+ return { outcome: "invalid-response-body" };
597
+ }
598
+ return { data: parsed.data, outcome: "ok" };
599
+ }
600
+ __name(callPublicContract, "callPublicContract");
601
+
602
+ // src/lib/sdk/publicApi/mapFailure.ts
603
+ function mapPublicApiFailure(result) {
604
+ if (result.outcome !== "http-error") return { outcome: result.outcome };
605
+ const { httpStatus, message } = result;
606
+ if (httpStatus === 400) return { message, outcome: "invalid-request" };
607
+ if (httpStatus === 401 || httpStatus === 403)
608
+ return { message, outcome: "unauthorized" };
609
+ if (httpStatus === 404) return { message, outcome: "not-found" };
610
+ if (httpStatus === 409) return { message, outcome: "conflict" };
611
+ if (httpStatus >= 500) return { httpStatus, outcome: "server-error" };
612
+ return { httpStatus, message, outcome: "unexpected-status" };
613
+ }
614
+ __name(mapPublicApiFailure, "mapPublicApiFailure");
615
+
616
+ // src/lib/sdk/domain/environment/promote.ts
617
+ async function promoteEnvironment(deps, apiConfig, params) {
618
+ const result = await callPublicContract(deps, apiConfig, {
619
+ contract: publicContractsV1.environment.promote,
620
+ input: params
621
+ });
622
+ if (result.outcome !== "ok") return mapPublicApiFailure(result);
623
+ const promotion = result.data;
624
+ deps.log.info(
625
+ `\u2705 Promotion ${promotion.id} of environment ${promotion.headEnvironmentId} is ${promotion.status}: ${promotion.url}`
626
+ );
627
+ return { outcome: "requested", promotion };
628
+ }
629
+ __name(promoteEnvironment, "promoteEnvironment");
630
+
631
+ // src/lib/sdk/domain/environment/terminate.ts
632
+ import { publicContractsV1 as publicContractsV12 } from "@qawolf/api-contracts";
633
+ async function terminateEnvironment(deps, apiConfig, params) {
634
+ const result = await callPublicContract(deps, apiConfig, {
635
+ contract: publicContractsV12.environment.terminate,
636
+ input: params
637
+ });
638
+ if (result.outcome !== "ok") return mapPublicApiFailure(result);
639
+ const environment = result.data;
640
+ deps.log.info(
641
+ `\u2705 Environment ${environment.id} (${environment.name}) terminated: ${environment.url}`
642
+ );
643
+ return { environment, outcome: "terminated" };
644
+ }
645
+ __name(terminateEnvironment, "terminateEnvironment");
646
+
503
647
  // src/lib/api/signed-url.ts
504
648
  var signedUrlPaths = {
505
649
  runInputsExecutables: "/api/v0/run-inputs-executables-signed-urls",
@@ -1198,107 +1342,26 @@ async function pollCiGreenlightStatus(deps, apiConfig, {
1198
1342
  }
1199
1343
  __name(pollCiGreenlightStatus, "pollCiGreenlightStatus");
1200
1344
 
1201
- // src/lib/sdk/domain/reportDeployment/index.ts
1202
- import { publicContractsV1 } from "@qawolf/api-contracts";
1203
-
1204
- // src/lib/sdk/publicApi/callContract.ts
1205
- function isRecord2(value) {
1206
- return typeof value === "object" && value !== null;
1207
- }
1208
- __name(isRecord2, "isRecord");
1209
- function isSuperJsonEnvelope(data) {
1210
- return "json" in data && Object.keys(data).every((key) => key === "json" || key === "meta");
1211
- }
1212
- __name(isSuperJsonEnvelope, "isSuperJsonEnvelope");
1213
- function unwrapTrpcEnvelope(body) {
1214
- if (!isRecord2(body) || !isRecord2(body.result)) return void 0;
1215
- const data = body.result.data;
1216
- return isRecord2(data) && isSuperJsonEnvelope(data) ? data.json : data;
1217
- }
1218
- __name(unwrapTrpcEnvelope, "unwrapTrpcEnvelope");
1219
- function readTrpcError(body) {
1220
- const wrapped = isRecord2(body) ? body.error : void 0;
1221
- const error = isRecord2(wrapped) && isRecord2(wrapped.json) ? wrapped.json : wrapped;
1222
- if (!isRecord2(error)) return { eventId: void 0, message: void 0 };
1223
- const data = isRecord2(error.data) ? error.data : void 0;
1224
- return {
1225
- eventId: typeof data?.eventId === "string" ? data.eventId : void 0,
1226
- message: typeof error.message === "string" ? error.message : void 0
1227
- };
1228
- }
1229
- __name(readTrpcError, "readTrpcError");
1230
- function parseJson(text) {
1231
- if (text === void 0) return void 0;
1232
- try {
1233
- return JSON.parse(text);
1234
- } catch {
1235
- return void 0;
1236
- }
1237
- }
1238
- __name(parseJson, "parseJson");
1239
- async function readHttpError(response, contractName, log) {
1240
- const bodyText = await response.text().catch(() => void 0);
1241
- const { eventId, message } = readTrpcError(parseJson(bodyText));
1242
- const statusText = response.status >= 500 ? "Server Error" : response.statusText || "Unknown Error";
1243
- const eventIdSuffix = eventId ? ` (Event ID: ${eventId})` : "";
1244
- const messageSuffix = message ? `: ${message}` : "";
1245
- log.error(
1246
- `\u274C [${contractName}] ${response.status} ${statusText}${eventIdSuffix}${messageSuffix}`
1247
- );
1248
- return {
1249
- eventId,
1250
- httpStatus: response.status,
1251
- message,
1252
- outcome: "http-error"
1253
- };
1254
- }
1255
- __name(readHttpError, "readHttpError");
1256
- async function callPublicContract({ fetch: localFetch, log }, apiConfig, {
1257
- contract,
1258
- input
1259
- }) {
1260
- const procedurePath = `public.${contract.name}`;
1261
- let bodyText;
1262
- try {
1263
- const response = await localFetch(
1264
- new URL(`/api/trpc/${procedurePath}`, apiConfig.serviceBase),
1265
- {
1266
- // The server's superjson transformer reads the input from `json`.
1267
- body: JSON.stringify({ json: input }),
1268
- headers: {
1269
- Authorization: `Bearer ${apiConfig.apiKey}`,
1270
- "Content-Type": "application/json",
1271
- "User-Agent": apiConfig.userAgent
1272
- },
1273
- method: "POST"
1274
- }
1275
- );
1276
- if (!response.ok) return readHttpError(response, contract.name, log);
1277
- bodyText = await response.text();
1278
- } catch {
1279
- log.error(`\u{1F6AB} Network error from ${contract.name}.`);
1280
- return { outcome: "network-error" };
1281
- }
1282
- const parsed = contract.output.safeParse(
1283
- unwrapTrpcEnvelope(parseJson(bodyText))
1284
- );
1285
- if (!parsed.success) {
1286
- log.error(
1287
- `\u{1F6AB} Invalid response from ${contract.name} (${parsed.error.issues[0]?.message ?? "the response body did not match the contract"}), aborting.`
1288
- );
1289
- return { outcome: "invalid-response-body" };
1290
- }
1291
- return { data: parsed.data, outcome: "ok" };
1345
+ // src/lib/sdk/domain/promotion/get.ts
1346
+ import { publicContractsV1 as publicContractsV13 } from "@qawolf/api-contracts";
1347
+ async function getPromotion(deps, apiConfig, params) {
1348
+ const result = await callPublicContract(deps, apiConfig, {
1349
+ contract: publicContractsV13.promotion.get,
1350
+ input: params
1351
+ });
1352
+ if (result.outcome !== "ok") return mapPublicApiFailure(result);
1353
+ return { outcome: "found", promotion: result.data };
1292
1354
  }
1293
- __name(callPublicContract, "callPublicContract");
1355
+ __name(getPromotion, "getPromotion");
1294
1356
 
1295
1357
  // src/lib/sdk/domain/reportDeployment/index.ts
1358
+ import { publicContractsV1 as publicContractsV14 } from "@qawolf/api-contracts";
1296
1359
  async function reportDeployment(deps, apiConfig, params) {
1297
1360
  const result = await callPublicContract(deps, apiConfig, {
1298
- contract: publicContractsV1.deployment.reportStatus,
1361
+ contract: publicContractsV14.deployment.reportStatus,
1299
1362
  input: params
1300
1363
  });
1301
- if (result.outcome !== "ok") return mapFailure(result);
1364
+ if (result.outcome !== "ok") return mapPublicApiFailure(result);
1302
1365
  const { deployment } = result.data;
1303
1366
  deps.log.info(
1304
1367
  `\u2705 Deployment ${deployment.id} reported as ${deployment.status}: ${deployment.url}`
@@ -1306,21 +1369,9 @@ async function reportDeployment(deps, apiConfig, params) {
1306
1369
  return { deployment, outcome: "reported" };
1307
1370
  }
1308
1371
  __name(reportDeployment, "reportDeployment");
1309
- function mapFailure(result) {
1310
- if (result.outcome !== "http-error") return { outcome: result.outcome };
1311
- const { httpStatus, message } = result;
1312
- if (httpStatus === 400) return { message, outcome: "invalid-request" };
1313
- if (httpStatus === 401 || httpStatus === 403)
1314
- return { message, outcome: "unauthorized" };
1315
- if (httpStatus === 404) return { message, outcome: "not-found" };
1316
- if (httpStatus === 409) return { message, outcome: "conflict" };
1317
- if (httpStatus >= 500) return { httpStatus, outcome: "server-error" };
1318
- return { httpStatus, message, outcome: "unexpected-status" };
1319
- }
1320
- __name(mapFailure, "mapFailure");
1321
1372
 
1322
1373
  // src/lib/sdk/domain/waitForVerdict/awaitRuns.ts
1323
- import { publicContractsV1 as publicContractsV12 } from "@qawolf/api-contracts";
1374
+ import { publicContractsV1 as publicContractsV15 } from "@qawolf/api-contracts";
1324
1375
 
1325
1376
  // src/lib/sdk/domain/waitForVerdict/failures.ts
1326
1377
  function handleCallFailure(failure, deploymentId) {
@@ -1556,7 +1607,7 @@ async function awaitRuns(ctx) {
1556
1607
  };
1557
1608
  },
1558
1609
  request: /* @__PURE__ */ __name(() => callPublicContract(ctx.deps, ctx.apiConfig, {
1559
- contract: publicContractsV12.deployment.listTriggerEvaluations,
1610
+ contract: publicContractsV15.deployment.listTriggerEvaluations,
1560
1611
  input: { deploymentId }
1561
1612
  }), "request")
1562
1613
  });
@@ -1564,7 +1615,7 @@ async function awaitRuns(ctx) {
1564
1615
  __name(awaitRuns, "awaitRuns");
1565
1616
 
1566
1617
  // src/lib/sdk/domain/waitForVerdict/awaitVerdict.ts
1567
- import { publicContractsV1 as publicContractsV13 } from "@qawolf/api-contracts";
1618
+ import { publicContractsV1 as publicContractsV16 } from "@qawolf/api-contracts";
1568
1619
  var settledStatuses = ["passed", "failed", "canceled", "superseded"];
1569
1620
  function isSettled(run) {
1570
1621
  return settledStatuses.includes(run.status);
@@ -1602,7 +1653,7 @@ async function requestRuns(ctx, matched) {
1602
1653
  const answers = await Promise.all(
1603
1654
  matched.map(async (run) => ({
1604
1655
  result: await callPublicContract(ctx.deps, ctx.apiConfig, {
1605
- contract: publicContractsV13.run.get,
1656
+ contract: publicContractsV16.run.get,
1606
1657
  // A suite can hold hundreds of flows and the verdict reads none of
1607
1658
  // them, so ask for the smallest list the contract allows.
1608
1659
  input: { flowStatuses: ["failed"], runId: run.runId }
@@ -1782,6 +1833,10 @@ We recommend 'undici' package for that purpose. See the Requirement section of o
1782
1833
  reportStatus: reportDeployment.bind(null, deps, apiConfig),
1783
1834
  waitForVerdict: waitForVerdict.bind(null, deps, apiConfig)
1784
1835
  },
1836
+ environment: {
1837
+ promote: promoteEnvironment.bind(null, deps, apiConfig),
1838
+ terminate: terminateEnvironment.bind(null, deps, apiConfig)
1839
+ },
1785
1840
  generateSignedUrlForRunInputsExecutablesStorage: generateSignedUrlForRunInputsExecutablesStorage.bind(
1786
1841
  null,
1787
1842
  deps,
@@ -1793,12 +1848,22 @@ We recommend 'undici' package for that purpose. See the Requirement section of o
1793
1848
  deps,
1794
1849
  apiConfig
1795
1850
  ),
1851
+ /**
1852
+ * @deprecated Despite its name this performs a promote: the legacy
1853
+ * `environment_terminated` webhook merges the environment's flow changes
1854
+ * into its base and then terminates it. Use `environment.promote` for
1855
+ * accepted work, and `environment.terminate` to discard abandoned work,
1856
+ * which this method has never done.
1857
+ */
1796
1858
  notifyTerminatedEphemeralEnvironment: notifyTerminatedEphemeralEnvironment.bind(null, deps, apiConfig),
1797
1859
  /**
1798
1860
  * @deprecated Polls a run id that only `attemptNotifyDeploy` returns, so it
1799
1861
  * keeps the pipeline on the legacy `deploy_success` webhook.
1800
1862
  */
1801
- pollCiGreenlightStatus: pollCiGreenlightStatus.bind(null, deps, apiConfig)
1863
+ pollCiGreenlightStatus: pollCiGreenlightStatus.bind(null, deps, apiConfig),
1864
+ promotion: {
1865
+ get: getPromotion.bind(null, deps, apiConfig)
1866
+ }
1802
1867
  };
1803
1868
  }
1804
1869
  __name(makeQaWolfSdk, "makeQaWolfSdk");