@qawolf/ci-sdk 3.4.1 → 3.5.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 CHANGED
@@ -20,6 +20,7 @@ to determine the status of your CI/CD step/job/action.
20
20
  - [Advanced: Poll with Custom Control (Iterator)](#ci-greenlight-iterator)
21
21
  - [Promote or Terminate a Preview Environment](#environment-lifecycle)
22
22
  - [Read a Promotion](#promotion-get)
23
+ - [Upload an App Build](#upload-build)
23
24
  - [Notify a Terminated Ephemeral Environment (deprecated)](#notify-terminated-ephemeral-environment)
24
25
  - [Upload Run Input Artifacts](#upload-artifacts)
25
26
  - [Requirements](#requirements)
@@ -737,6 +738,49 @@ switch (result.promotion.status) {
737
738
 
738
739
  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
740
 
741
+ <a id="upload-build"></a>
742
+
743
+ ## Upload an App Build
744
+
745
+ `uploadBuild` uploads an Android `.apk` or `.aab`, or an iOS `.ipa` file, up to 500 MB, and registers it as a QA Wolf build. QA Wolf reads the app ID, version and build number from the file, and runs that launch the app install the build.
746
+
747
+ ```ts
748
+ import { makeQaWolfSdk } from "@qawolf/ci-sdk";
749
+
750
+ const { uploadBuild } = makeQaWolfSdk({ apiKey: "qawolf_xxxxx" });
751
+
752
+ const result = await uploadBuild({
753
+ filePath: "app/build/outputs/apk/release/app-release.apk",
754
+ environment: { name: "staging" },
755
+ branch: "main",
756
+ commitSha: "0123abc",
757
+ workspaceId: "your-workspace-id",
758
+ });
759
+ if (result.outcome !== "uploaded") process.exit(1);
760
+ console.log(result.build.id, result.build.appId, result.build.version);
761
+ ```
762
+
763
+ Only `filePath` is required. The file is streamed from disk, so a large build is not held in memory.
764
+
765
+ - `environment` is the environment whose runs install the build from now on, until a newer build of the same app and platform arrives. Pass `{ id }` for an existing environment, or `{ name, ephemeral?, baseEphemeralEnvironment? }`, the same selector `deployment.reportStatus` takes, which creates the environment when none matches. Omit it for a build that only runs created with it install.
766
+ - `branch` and `commitSha` are shown with the build.
767
+ - `workspaceId` is required with an organization or user API key. See [API Keys and Workspaces](#api-keys).
768
+
769
+ The parameters other than `filePath` are the input of the `build.create` contract, derived from the published `@qawolf/api-contracts` package.
770
+
771
+ ### Result
772
+
773
+ `uploadBuild` answers `{ outcome: "uploaded", build }`, where `build` carries the build's `id`, `appId`, `appName`, `platform`, `version`, `buildNumber`, `fileName`, `sizeBytes` and `url`. It never throws.
774
+
775
+ | `outcome` | Meaning |
776
+ | ----------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
777
+ | `file-unreadable` | `filePath` does not name a readable file. Nothing was sent to QA Wolf. Carries `filePath`. |
778
+ | `upload-rejected` | Storage refused the file's bytes, for example because the upload URL expired. Carries `buildId` and `httpStatus`. |
779
+ | `upload-network-error` | The file's bytes never reached storage, or the connection dropped. Carries `buildId`. |
780
+ | `invalid-request`, `unauthorized`, `not-found`, `conflict`, `server-error`, `unexpected-status`, `network-error`, `invalid-response-body` | QA Wolf refused or failed one of the two calls. `failedStep` says which: `request-upload` (for `invalid-request`, a file that is not an `.apk`, `.aab` or `.ipa`, or is over 500 MB) or `create` (for `invalid-request`, a file that is not an app, which also carries `buildId`). Same meanings as for `deployment.reportStatus`. |
781
+
782
+ A failed call creates no build. To retry, call `uploadBuild` again: each call uploads the file under a new build.
783
+
740
784
  <a id="notify-terminated-ephemeral-environment"></a>
741
785
 
742
786
  ## Notify a Terminated Ephemeral Environment
@@ -913,6 +957,15 @@ This package follows the [SemVer](https://semver.org/) versioning scheme. Additi
913
957
 
914
958
  # Changelog
915
959
 
960
+ ## v3.5.1
961
+
962
+ - Fix `deployment.waitForVerdict`, `promotion.get` and `environment.promote`, which aborted with `Invalid response ... (expected string, received null)` whenever the answer left a field unset, such as `completedAt` on a run that is still running. The SDK now reads the server's superjson responses in full, so unset fields read as absent.
963
+
964
+ ## v3.5.0
965
+
966
+ - New `uploadBuild` function, which uploads an Android `.apk` or `.aab`, or an iOS `.ipa` file of up to 500 MB and registers it as a QA Wolf build through the public `build.requestUpload` and `build.create` APIs. It streams the file from disk, optionally puts the build on an environment, and answers `{ outcome: "uploaded", build }` or one named refusal, with `failedStep` saying whether QA Wolf refused to sign the upload or to create the build. See [Upload an App Build](#upload-build).
967
+ - The `@qawolf/api-contracts` dependency floor is now `0.101.0`, the first version with both the `build` contracts and `builds` on `deployment.reportStatus`.
968
+
916
969
  ## v3.4.1
917
970
 
918
971
  - 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`.
package/dist/index.js CHANGED
@@ -123,7 +123,7 @@ var defaultServiceBase = "https://app.qawolf.com/";
123
123
  // package.json
124
124
  var package_default = {
125
125
  name: "@qawolf/ci-sdk",
126
- version: "3.4.1",
126
+ version: "3.5.1",
127
127
  private: false,
128
128
  description: "A simple SDK for interacting with QAWolf in CI scripts.",
129
129
  keywords: [],
@@ -157,9 +157,10 @@ var package_default = {
157
157
  "tsc:check": "tsc --noEmit"
158
158
  },
159
159
  dependencies: {
160
- "@qawolf/api-contracts": ">=0.89.0",
160
+ "@qawolf/api-contracts": ">=0.101.0",
161
161
  "@qawolf/ci-utils": "^2.0.0",
162
162
  "@sinonjs/fake-timers": "^10.3.0",
163
+ superjson: "^2.2.6",
163
164
  tslib: "^2.6.2",
164
165
  zod: "^4.1.11"
165
166
  },
@@ -508,7 +509,8 @@ __name(handleErrorResponse, "handleErrorResponse");
508
509
  // src/lib/sdk/domain/environment/promote.ts
509
510
  import { publicContractsV1 } from "@qawolf/api-contracts";
510
511
 
511
- // src/lib/sdk/publicApi/callContract.ts
512
+ // src/lib/sdk/publicApi/trpcEnvelope.ts
513
+ import superjson from "superjson";
512
514
  function isRecord2(value) {
513
515
  return typeof value === "object" && value !== null;
514
516
  }
@@ -517,15 +519,22 @@ function isSuperJsonEnvelope(data) {
517
519
  return "json" in data && Object.keys(data).every((key) => key === "json" || key === "meta");
518
520
  }
519
521
  __name(isSuperJsonEnvelope, "isSuperJsonEnvelope");
522
+ function readSuperJson(data) {
523
+ if (!isRecord2(data) || !isSuperJsonEnvelope(data)) return data;
524
+ try {
525
+ return superjson.deserialize({ json: data.json, meta: data.meta });
526
+ } catch {
527
+ return void 0;
528
+ }
529
+ }
530
+ __name(readSuperJson, "readSuperJson");
520
531
  function unwrapTrpcEnvelope(body) {
521
532
  if (!isRecord2(body) || !isRecord2(body.result)) return void 0;
522
- const data = body.result.data;
523
- return isRecord2(data) && isSuperJsonEnvelope(data) ? data.json : data;
533
+ return readSuperJson(body.result.data);
524
534
  }
525
535
  __name(unwrapTrpcEnvelope, "unwrapTrpcEnvelope");
526
536
  function readTrpcError(body) {
527
- const wrapped = isRecord2(body) ? body.error : void 0;
528
- const error = isRecord2(wrapped) && isRecord2(wrapped.json) ? wrapped.json : wrapped;
537
+ const error = readSuperJson(isRecord2(body) ? body.error : void 0);
529
538
  if (!isRecord2(error)) return { eventId: void 0, message: void 0 };
530
539
  const data = isRecord2(error.data) ? error.data : void 0;
531
540
  return {
@@ -543,6 +552,8 @@ function parseJson(text) {
543
552
  }
544
553
  }
545
554
  __name(parseJson, "parseJson");
555
+
556
+ // src/lib/sdk/publicApi/callContract.ts
546
557
  async function readHttpError(response, contractName, log) {
547
558
  const bodyText = await response.text().catch(() => void 0);
548
559
  const { eventId, message } = readTrpcError(parseJson(bodyText));
@@ -1382,8 +1393,96 @@ async function reportDeployment(deps, apiConfig, params) {
1382
1393
  }
1383
1394
  __name(reportDeployment, "reportDeployment");
1384
1395
 
1385
- // src/lib/sdk/domain/waitForVerdict/awaitRuns.ts
1396
+ // src/lib/sdk/domain/uploadBuild/index.ts
1397
+ import { openAsBlob } from "node:fs";
1398
+ import { stat } from "node:fs/promises";
1399
+ import { basename } from "node:path";
1386
1400
  import { publicContractsV1 as publicContractsV15 } from "@qawolf/api-contracts";
1401
+ var uploadTimeoutMs = 30 * 60 * 1e3;
1402
+ async function openBuildFile(filePath) {
1403
+ try {
1404
+ const stats = await stat(filePath);
1405
+ return stats.isFile() ? await openAsBlob(filePath) : void 0;
1406
+ } catch {
1407
+ return void 0;
1408
+ }
1409
+ }
1410
+ __name(openBuildFile, "openBuildFile");
1411
+ async function putFile({ fetch }, {
1412
+ body,
1413
+ uploadHeaders,
1414
+ uploadUrl
1415
+ }) {
1416
+ try {
1417
+ const response = await fetch(uploadUrl, {
1418
+ body,
1419
+ headers: uploadHeaders,
1420
+ method: "PUT",
1421
+ signal: AbortSignal.timeout(uploadTimeoutMs)
1422
+ });
1423
+ return response.ok ? "ok" : { httpStatus: response.status };
1424
+ } catch {
1425
+ return "network-error";
1426
+ }
1427
+ }
1428
+ __name(putFile, "putFile");
1429
+ async function uploadBuild(deps, apiConfig, { branch, commitSha, environment, filePath, workspaceId }) {
1430
+ const file = await openBuildFile(filePath);
1431
+ if (file === void 0) {
1432
+ deps.log.error(`\u{1F6AB} ${filePath} is not a readable file, aborting.`);
1433
+ return { filePath, outcome: "file-unreadable" };
1434
+ }
1435
+ const fileSizeBytes = file.size;
1436
+ const requested = await callPublicContract(deps, apiConfig, {
1437
+ contract: publicContractsV15.build.requestUpload,
1438
+ input: { fileName: basename(filePath), fileSizeBytes, workspaceId }
1439
+ });
1440
+ if (requested.outcome !== "ok")
1441
+ return { ...mapPublicApiFailure(requested), failedStep: "request-upload" };
1442
+ const { buildId, uploadHeaders, uploadUrl } = requested.data;
1443
+ deps.log.info(
1444
+ `Uploading ${basename(filePath)} (${fileSizeBytes} bytes) as build ${buildId}.`
1445
+ );
1446
+ const uploaded = await putFile(deps, {
1447
+ body: file,
1448
+ uploadHeaders,
1449
+ uploadUrl
1450
+ });
1451
+ if (uploaded === "network-error") {
1452
+ deps.log.error(`\u{1F6AB} Network error while uploading build ${buildId}.`);
1453
+ return { buildId, outcome: "upload-network-error" };
1454
+ }
1455
+ if (uploaded !== "ok") {
1456
+ deps.log.error(
1457
+ `\u{1F6AB} Storage refused the upload of build ${buildId} (HTTP status ${uploaded.httpStatus}).`
1458
+ );
1459
+ return {
1460
+ buildId,
1461
+ httpStatus: uploaded.httpStatus,
1462
+ outcome: "upload-rejected"
1463
+ };
1464
+ }
1465
+ const created = await callPublicContract(deps, apiConfig, {
1466
+ contract: publicContractsV15.build.create,
1467
+ input: { branch, buildId, commitSha, environment, workspaceId }
1468
+ });
1469
+ if (created.outcome !== "ok") {
1470
+ return {
1471
+ ...mapPublicApiFailure(created),
1472
+ buildId,
1473
+ failedStep: "create"
1474
+ };
1475
+ }
1476
+ const { build } = created.data;
1477
+ deps.log.info(
1478
+ `\u2705 Build ${build.id} (${build.appId}, ${build.platform}) uploaded: ${build.url}`
1479
+ );
1480
+ return { build, outcome: "uploaded" };
1481
+ }
1482
+ __name(uploadBuild, "uploadBuild");
1483
+
1484
+ // src/lib/sdk/domain/waitForVerdict/awaitRuns.ts
1485
+ import { publicContractsV1 as publicContractsV16 } from "@qawolf/api-contracts";
1387
1486
 
1388
1487
  // src/lib/sdk/domain/waitForVerdict/failures.ts
1389
1488
  function handleCallFailure(failure, deploymentId) {
@@ -1619,7 +1718,7 @@ async function awaitRuns(ctx) {
1619
1718
  };
1620
1719
  },
1621
1720
  request: /* @__PURE__ */ __name(() => callPublicContract(ctx.deps, ctx.apiConfig, {
1622
- contract: publicContractsV15.deployment.listTriggerEvaluations,
1721
+ contract: publicContractsV16.deployment.listTriggerEvaluations,
1623
1722
  input: { deploymentId }
1624
1723
  }), "request")
1625
1724
  });
@@ -1627,7 +1726,7 @@ async function awaitRuns(ctx) {
1627
1726
  __name(awaitRuns, "awaitRuns");
1628
1727
 
1629
1728
  // src/lib/sdk/domain/waitForVerdict/awaitVerdict.ts
1630
- import { publicContractsV1 as publicContractsV16 } from "@qawolf/api-contracts";
1729
+ import { publicContractsV1 as publicContractsV17 } from "@qawolf/api-contracts";
1631
1730
  var settledStatuses = ["passed", "failed", "canceled", "superseded"];
1632
1731
  function isSettled(run) {
1633
1732
  return settledStatuses.includes(run.status);
@@ -1665,7 +1764,7 @@ async function requestRuns(ctx, matched) {
1665
1764
  const answers = await Promise.all(
1666
1765
  matched.map(async (run) => ({
1667
1766
  result: await callPublicContract(ctx.deps, ctx.apiConfig, {
1668
- contract: publicContractsV16.run.get,
1767
+ contract: publicContractsV17.run.get,
1669
1768
  // A suite can hold hundreds of flows and the verdict reads none of
1670
1769
  // them, so ask for the smallest list the contract allows.
1671
1770
  input: { flowStatuses: ["failed"], runId: run.runId }
@@ -1875,7 +1974,8 @@ We recommend 'undici' package for that purpose. See the Requirement section of o
1875
1974
  pollCiGreenlightStatus: pollCiGreenlightStatus.bind(null, deps, apiConfig),
1876
1975
  promotion: {
1877
1976
  get: getPromotion.bind(null, deps, apiConfig)
1878
- }
1977
+ },
1978
+ uploadBuild: uploadBuild.bind(null, deps, apiConfig)
1879
1979
  };
1880
1980
  }
1881
1981
  __name(makeQaWolfSdk, "makeQaWolfSdk");