We provide the [@qawolf/ci-sdk](<https://www.npmjs.com/package/@qawolf/ci-sdk>) NPM package to handle most of the integration work for you. This script integrates with the two endpoints currently available, and provides one async function for each:

The package features TypeScript definitions, ESM and CJS module interoperability. See the NPM package page for more information.

<aside> ℹ️ We recommend using the ^ npm range operator to get on-the-fly fixes. The SDK package follows SemVer. Learn more about stability guarantees in the official NPM package page.

</aside>

attemptNotifyDeploy

<aside> ⚠️ Please refer to Choosing Fields Based on Your Setup to properly set up the DeployConfig object.

</aside>

import { type DeployConfig, makeQaWolfSdk } from "@qawolf/ci-sdk";

// Edit this to your needs.
const deployConfig: DeployConfig = {
  branch: undefined,
  commitUrl: undefined,
  deduplicationKey: undefined,
  deploymentType: undefined,
  deploymentUrl: undefined,
  hostingService: undefined,
  sha: undefined,
  variables: undefined,
};

const { attemptNotifyDeploy } = makeQaWolfSdk({
  apiKey: "qawolf_xxxxx"
});

(async () => {
  const result = await attemptNotifyDeploy(deployConfig);
  if (result.outcome !== "success") {
    // Fail the job.
    process.exit(1);
  }
  const runId = result.runId;
  // Store the runId as an output of the job to be used in a CI-greenlight job.
  // This will depend on the CI platform you are using.
})();

pollCiGreenlightStatus

import { makeQaWolfSdk } from "@qawolf/ci-sdk";

const { pollCiGreenlightStatus } = makeQaWolfSdk({
  apiKey: "qawolf_xxxxx",
});

(async () => {
  // Retrieve runId from the previous job.
  const { outcome } = await pollCiGreenlightStatus({
    runId,
    // Optional: Callback to be called when the run stage changes.
    onRunStageChanged: (current, previous) => {
      console.log(current, previous);
    },
  });
  if (outcome !== "success") {
    // Fail the job.
    // This will depend on the CI platform you are using.
    // You can also distinguish between "failed" and "aborted" outcomes.
    // Only "failed" outcome indicates bugs were found.
    process.exit(1);
  }
  // Continue CI.
})();

<aside> ℹ️ You can inspect the outcome.ciGreenlightStatus object when the outcome is "success". It will provide ample details on the results of the run. See 200 Response (CI Greenlight status).

</aside>