@qawolf/ci-sdk 3.3.0 → 3.4.1
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 +117 -12
- package/dist/index.js +190 -113
- package/dist/index.js.map +4 -4
- package/dist/lib/sdk/domain/environment/promote.d.ts +9 -0
- package/dist/lib/sdk/domain/environment/terminate.d.ts +8 -0
- package/dist/lib/sdk/domain/environment/types.d.ts +27 -0
- package/dist/lib/sdk/domain/generateSignedUrls/types.d.ts +3 -3
- package/dist/lib/sdk/domain/promotion/get.d.ts +5 -0
- package/dist/lib/sdk/domain/promotion/testSeed.d.ts +14 -0
- package/dist/lib/sdk/domain/promotion/types.d.ts +17 -0
- package/dist/lib/sdk/index.d.ts +30 -6
- package/dist/lib/sdk/publicApi/callContract.d.ts +2 -0
- package/dist/lib/sdk/publicApi/mapFailure.d.ts +47 -0
- package/package.json +7 -2
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
|
-
- [
|
|
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,23 +65,26 @@ 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
|
|
|
70
74
|
Omitting `workspaceId` with an organization or user API key is handled differently depending on the
|
|
71
75
|
call, so it is worth knowing which behavior to expect:
|
|
72
76
|
|
|
73
|
-
| Function | Behavior when `workspaceId` is omitted
|
|
74
|
-
| ------------------------------------------------- |
|
|
75
|
-
| `generateSignedUrlForTempTeamStorage` |
|
|
76
|
-
| `generateSignedUrlForRunInputsExecutablesStorage` | Same as above
|
|
77
|
-
| `attemptNotifyDeploy` | Succeeds against your organization's first-created workspace and returns a `warning` naming it.
|
|
78
|
-
| `notifyTerminatedEphemeralEnvironment` | Succeeds against your organization's first-created workspace and returns a `warning` naming it.
|
|
77
|
+
| Function | Behavior when `workspaceId` is omitted |
|
|
78
|
+
| ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
79
|
+
| `generateSignedUrlForTempTeamStorage` | Succeeds when your organization has exactly one enabled workspace. With several, the backend answers HTTP `400` asking for `workspaceId`; with none, HTTP `400` saying the organization has no active workspace. |
|
|
80
|
+
| `generateSignedUrlForRunInputsExecutablesStorage` | Same as above. |
|
|
81
|
+
| `attemptNotifyDeploy` | Succeeds against your organization's first-created workspace and returns a `warning` naming it. |
|
|
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
|
-
> ⚠️ The signed-URL functions
|
|
81
|
-
>
|
|
82
|
-
> artifact name are otherwise correct, most often means `workspaceId` was not sent.
|
|
85
|
+
> ⚠️ The signed-URL functions never fall back to the first-created workspace. If your organization has
|
|
86
|
+
> several enabled workspaces, they **require** `workspaceId`; a `400` from either function, especially
|
|
87
|
+
> when the API key and artifact name are otherwise correct, most often means `workspaceId` was not sent.
|
|
83
88
|
|
|
84
89
|
When this happens, the SDK logs the real status before it reports the outcome, so the log line is
|
|
85
90
|
the reliable signal:
|
|
@@ -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
|
|
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,17 @@ This package follows the [SemVer](https://semver.org/) versioning scheme. Additi
|
|
|
819
913
|
|
|
820
914
|
# Changelog
|
|
821
915
|
|
|
916
|
+
## v3.4.1
|
|
917
|
+
|
|
918
|
+
- Fix `deployment.waitForVerdict` and `promotion.get`, which failed with HTTP `405 Method Not Allowed` on every call. The SDK sent their read requests as `POST`, and now sends them as `GET`.
|
|
919
|
+
|
|
920
|
+
## v3.4.0
|
|
921
|
+
|
|
922
|
+
- 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).
|
|
923
|
+
- 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).
|
|
924
|
+
- `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.
|
|
925
|
+
- The `@qawolf/api-contracts` dependency floor is now `0.89.0`, the first version serving the `environment.terminate` contract.
|
|
926
|
+
|
|
822
927
|
## v3.3.0
|
|
823
928
|
|
|
824
929
|
- `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.
|
|
126
|
+
version: "3.4.1",
|
|
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.
|
|
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,157 @@ 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
|
+
function buildRequest(apiConfig, contract, input) {
|
|
564
|
+
const url = new URL(
|
|
565
|
+
`/api/trpc/public.${contract.name}`,
|
|
566
|
+
apiConfig.serviceBase
|
|
567
|
+
);
|
|
568
|
+
const serializedInput = JSON.stringify({ json: input });
|
|
569
|
+
const headers = {
|
|
570
|
+
Authorization: `Bearer ${apiConfig.apiKey}`,
|
|
571
|
+
"User-Agent": apiConfig.userAgent
|
|
572
|
+
};
|
|
573
|
+
if (contract.kind === "read") {
|
|
574
|
+
url.searchParams.set("input", serializedInput);
|
|
575
|
+
return { init: { headers, method: "GET" }, url };
|
|
576
|
+
}
|
|
577
|
+
return {
|
|
578
|
+
init: {
|
|
579
|
+
body: serializedInput,
|
|
580
|
+
headers: { ...headers, "Content-Type": "application/json" },
|
|
581
|
+
method: "POST"
|
|
582
|
+
},
|
|
583
|
+
url
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
__name(buildRequest, "buildRequest");
|
|
587
|
+
async function callPublicContract({ fetch: localFetch, log }, apiConfig, {
|
|
588
|
+
contract,
|
|
589
|
+
input
|
|
590
|
+
}) {
|
|
591
|
+
const { init, url } = buildRequest(apiConfig, contract, input);
|
|
592
|
+
let bodyText;
|
|
593
|
+
try {
|
|
594
|
+
const response = await localFetch(url, init);
|
|
595
|
+
if (!response.ok) return readHttpError(response, contract.name, log);
|
|
596
|
+
bodyText = await response.text();
|
|
597
|
+
} catch {
|
|
598
|
+
log.error(`\u{1F6AB} Network error from ${contract.name}.`);
|
|
599
|
+
return { outcome: "network-error" };
|
|
600
|
+
}
|
|
601
|
+
const parsed = contract.output.safeParse(
|
|
602
|
+
unwrapTrpcEnvelope(parseJson(bodyText))
|
|
603
|
+
);
|
|
604
|
+
if (!parsed.success) {
|
|
605
|
+
log.error(
|
|
606
|
+
`\u{1F6AB} Invalid response from ${contract.name} (${parsed.error.issues[0]?.message ?? "the response body did not match the contract"}), aborting.`
|
|
607
|
+
);
|
|
608
|
+
return { outcome: "invalid-response-body" };
|
|
609
|
+
}
|
|
610
|
+
return { data: parsed.data, outcome: "ok" };
|
|
611
|
+
}
|
|
612
|
+
__name(callPublicContract, "callPublicContract");
|
|
613
|
+
|
|
614
|
+
// src/lib/sdk/publicApi/mapFailure.ts
|
|
615
|
+
function mapPublicApiFailure(result) {
|
|
616
|
+
if (result.outcome !== "http-error") return { outcome: result.outcome };
|
|
617
|
+
const { httpStatus, message } = result;
|
|
618
|
+
if (httpStatus === 400) return { message, outcome: "invalid-request" };
|
|
619
|
+
if (httpStatus === 401 || httpStatus === 403)
|
|
620
|
+
return { message, outcome: "unauthorized" };
|
|
621
|
+
if (httpStatus === 404) return { message, outcome: "not-found" };
|
|
622
|
+
if (httpStatus === 409) return { message, outcome: "conflict" };
|
|
623
|
+
if (httpStatus >= 500) return { httpStatus, outcome: "server-error" };
|
|
624
|
+
return { httpStatus, message, outcome: "unexpected-status" };
|
|
625
|
+
}
|
|
626
|
+
__name(mapPublicApiFailure, "mapPublicApiFailure");
|
|
627
|
+
|
|
628
|
+
// src/lib/sdk/domain/environment/promote.ts
|
|
629
|
+
async function promoteEnvironment(deps, apiConfig, params) {
|
|
630
|
+
const result = await callPublicContract(deps, apiConfig, {
|
|
631
|
+
contract: publicContractsV1.environment.promote,
|
|
632
|
+
input: params
|
|
633
|
+
});
|
|
634
|
+
if (result.outcome !== "ok") return mapPublicApiFailure(result);
|
|
635
|
+
const promotion = result.data;
|
|
636
|
+
deps.log.info(
|
|
637
|
+
`\u2705 Promotion ${promotion.id} of environment ${promotion.headEnvironmentId} is ${promotion.status}: ${promotion.url}`
|
|
638
|
+
);
|
|
639
|
+
return { outcome: "requested", promotion };
|
|
640
|
+
}
|
|
641
|
+
__name(promoteEnvironment, "promoteEnvironment");
|
|
642
|
+
|
|
643
|
+
// src/lib/sdk/domain/environment/terminate.ts
|
|
644
|
+
import { publicContractsV1 as publicContractsV12 } from "@qawolf/api-contracts";
|
|
645
|
+
async function terminateEnvironment(deps, apiConfig, params) {
|
|
646
|
+
const result = await callPublicContract(deps, apiConfig, {
|
|
647
|
+
contract: publicContractsV12.environment.terminate,
|
|
648
|
+
input: params
|
|
649
|
+
});
|
|
650
|
+
if (result.outcome !== "ok") return mapPublicApiFailure(result);
|
|
651
|
+
const environment = result.data;
|
|
652
|
+
deps.log.info(
|
|
653
|
+
`\u2705 Environment ${environment.id} (${environment.name}) terminated: ${environment.url}`
|
|
654
|
+
);
|
|
655
|
+
return { environment, outcome: "terminated" };
|
|
656
|
+
}
|
|
657
|
+
__name(terminateEnvironment, "terminateEnvironment");
|
|
658
|
+
|
|
503
659
|
// src/lib/api/signed-url.ts
|
|
504
660
|
var signedUrlPaths = {
|
|
505
661
|
runInputsExecutables: "/api/v0/run-inputs-executables-signed-urls",
|
|
@@ -1198,107 +1354,26 @@ async function pollCiGreenlightStatus(deps, apiConfig, {
|
|
|
1198
1354
|
}
|
|
1199
1355
|
__name(pollCiGreenlightStatus, "pollCiGreenlightStatus");
|
|
1200
1356
|
|
|
1201
|
-
// src/lib/sdk/domain/
|
|
1202
|
-
import { publicContractsV1 } from "@qawolf/api-contracts";
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
|
|
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" };
|
|
1357
|
+
// src/lib/sdk/domain/promotion/get.ts
|
|
1358
|
+
import { publicContractsV1 as publicContractsV13 } from "@qawolf/api-contracts";
|
|
1359
|
+
async function getPromotion(deps, apiConfig, params) {
|
|
1360
|
+
const result = await callPublicContract(deps, apiConfig, {
|
|
1361
|
+
contract: publicContractsV13.promotion.get,
|
|
1362
|
+
input: params
|
|
1363
|
+
});
|
|
1364
|
+
if (result.outcome !== "ok") return mapPublicApiFailure(result);
|
|
1365
|
+
return { outcome: "found", promotion: result.data };
|
|
1292
1366
|
}
|
|
1293
|
-
__name(
|
|
1367
|
+
__name(getPromotion, "getPromotion");
|
|
1294
1368
|
|
|
1295
1369
|
// src/lib/sdk/domain/reportDeployment/index.ts
|
|
1370
|
+
import { publicContractsV1 as publicContractsV14 } from "@qawolf/api-contracts";
|
|
1296
1371
|
async function reportDeployment(deps, apiConfig, params) {
|
|
1297
1372
|
const result = await callPublicContract(deps, apiConfig, {
|
|
1298
|
-
contract:
|
|
1373
|
+
contract: publicContractsV14.deployment.reportStatus,
|
|
1299
1374
|
input: params
|
|
1300
1375
|
});
|
|
1301
|
-
if (result.outcome !== "ok") return
|
|
1376
|
+
if (result.outcome !== "ok") return mapPublicApiFailure(result);
|
|
1302
1377
|
const { deployment } = result.data;
|
|
1303
1378
|
deps.log.info(
|
|
1304
1379
|
`\u2705 Deployment ${deployment.id} reported as ${deployment.status}: ${deployment.url}`
|
|
@@ -1306,21 +1381,9 @@ async function reportDeployment(deps, apiConfig, params) {
|
|
|
1306
1381
|
return { deployment, outcome: "reported" };
|
|
1307
1382
|
}
|
|
1308
1383
|
__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
1384
|
|
|
1322
1385
|
// src/lib/sdk/domain/waitForVerdict/awaitRuns.ts
|
|
1323
|
-
import { publicContractsV1 as
|
|
1386
|
+
import { publicContractsV1 as publicContractsV15 } from "@qawolf/api-contracts";
|
|
1324
1387
|
|
|
1325
1388
|
// src/lib/sdk/domain/waitForVerdict/failures.ts
|
|
1326
1389
|
function handleCallFailure(failure, deploymentId) {
|
|
@@ -1556,7 +1619,7 @@ async function awaitRuns(ctx) {
|
|
|
1556
1619
|
};
|
|
1557
1620
|
},
|
|
1558
1621
|
request: /* @__PURE__ */ __name(() => callPublicContract(ctx.deps, ctx.apiConfig, {
|
|
1559
|
-
contract:
|
|
1622
|
+
contract: publicContractsV15.deployment.listTriggerEvaluations,
|
|
1560
1623
|
input: { deploymentId }
|
|
1561
1624
|
}), "request")
|
|
1562
1625
|
});
|
|
@@ -1564,7 +1627,7 @@ async function awaitRuns(ctx) {
|
|
|
1564
1627
|
__name(awaitRuns, "awaitRuns");
|
|
1565
1628
|
|
|
1566
1629
|
// src/lib/sdk/domain/waitForVerdict/awaitVerdict.ts
|
|
1567
|
-
import { publicContractsV1 as
|
|
1630
|
+
import { publicContractsV1 as publicContractsV16 } from "@qawolf/api-contracts";
|
|
1568
1631
|
var settledStatuses = ["passed", "failed", "canceled", "superseded"];
|
|
1569
1632
|
function isSettled(run) {
|
|
1570
1633
|
return settledStatuses.includes(run.status);
|
|
@@ -1602,7 +1665,7 @@ async function requestRuns(ctx, matched) {
|
|
|
1602
1665
|
const answers = await Promise.all(
|
|
1603
1666
|
matched.map(async (run) => ({
|
|
1604
1667
|
result: await callPublicContract(ctx.deps, ctx.apiConfig, {
|
|
1605
|
-
contract:
|
|
1668
|
+
contract: publicContractsV16.run.get,
|
|
1606
1669
|
// A suite can hold hundreds of flows and the verdict reads none of
|
|
1607
1670
|
// them, so ask for the smallest list the contract allows.
|
|
1608
1671
|
input: { flowStatuses: ["failed"], runId: run.runId }
|
|
@@ -1782,6 +1845,10 @@ We recommend 'undici' package for that purpose. See the Requirement section of o
|
|
|
1782
1845
|
reportStatus: reportDeployment.bind(null, deps, apiConfig),
|
|
1783
1846
|
waitForVerdict: waitForVerdict.bind(null, deps, apiConfig)
|
|
1784
1847
|
},
|
|
1848
|
+
environment: {
|
|
1849
|
+
promote: promoteEnvironment.bind(null, deps, apiConfig),
|
|
1850
|
+
terminate: terminateEnvironment.bind(null, deps, apiConfig)
|
|
1851
|
+
},
|
|
1785
1852
|
generateSignedUrlForRunInputsExecutablesStorage: generateSignedUrlForRunInputsExecutablesStorage.bind(
|
|
1786
1853
|
null,
|
|
1787
1854
|
deps,
|
|
@@ -1793,12 +1860,22 @@ We recommend 'undici' package for that purpose. See the Requirement section of o
|
|
|
1793
1860
|
deps,
|
|
1794
1861
|
apiConfig
|
|
1795
1862
|
),
|
|
1863
|
+
/**
|
|
1864
|
+
* @deprecated Despite its name this performs a promote: the legacy
|
|
1865
|
+
* `environment_terminated` webhook merges the environment's flow changes
|
|
1866
|
+
* into its base and then terminates it. Use `environment.promote` for
|
|
1867
|
+
* accepted work, and `environment.terminate` to discard abandoned work,
|
|
1868
|
+
* which this method has never done.
|
|
1869
|
+
*/
|
|
1796
1870
|
notifyTerminatedEphemeralEnvironment: notifyTerminatedEphemeralEnvironment.bind(null, deps, apiConfig),
|
|
1797
1871
|
/**
|
|
1798
1872
|
* @deprecated Polls a run id that only `attemptNotifyDeploy` returns, so it
|
|
1799
1873
|
* keeps the pipeline on the legacy `deploy_success` webhook.
|
|
1800
1874
|
*/
|
|
1801
|
-
pollCiGreenlightStatus: pollCiGreenlightStatus.bind(null, deps, apiConfig)
|
|
1875
|
+
pollCiGreenlightStatus: pollCiGreenlightStatus.bind(null, deps, apiConfig),
|
|
1876
|
+
promotion: {
|
|
1877
|
+
get: getPromotion.bind(null, deps, apiConfig)
|
|
1878
|
+
}
|
|
1802
1879
|
};
|
|
1803
1880
|
}
|
|
1804
1881
|
__name(makeQaWolfSdk, "makeQaWolfSdk");
|