/pa11y-webservice-client-node

A Node.js client library for Pa11y Webservice

Primary LanguageJavaScriptGNU Lesser General Public License v3.0LGPL-3.0

Pa11y Webservice Node.js Client

This is a Node.js client library for Pa11y Webservice.

Latest version published to npm Node.js version support Supports pa11y-webservice@4 API Build status LGPL-3.0 licensed

Installing

Add this client to your project with your preferred package manager. For example, to install it as a development dependency with npm:

npm install --save-dev pa11y-webservice-client-node

Usage

For information about Pa11y Webservice's endpoints and resource types, read the documentation.

const createClient = require('pa11y-webservice-client-node');

// Create client with the base URL of your instance of Pa11y Webservice
const client = createClient('http://localhost:3000/');

// Create a task
client.tasks.create({
    name: 'Nature Home Page',
    url: 'nature.com',
    standard: 'WCAG2AA'
}, function (error, task) {
    // task  =  object representing the new task, or null if an error occurred
});

// Get all tasks
client.tasks.get({}, function (error, tasks) {
    // tasks  =  array of objects representing tasks, or null if an error occurred
});

// Get all tasks with last results included for each
client.tasks.get({
    lastres: true
}, function (error, tasks) {
    // tasks  =  array of objects representing tasks, or null if an error occurred
});

// Get results for all tasks
client.tasks.results({}, function (error, results) {
    // results  =  array of objects representing results, or null if an error occurred
});

// Get results for all tasks within a date range
client.tasks.results({
    from: '2023-01-01',
    to: '2023-01-31'
}, function (error, results) {
    // results  =  array of objects representing results, or null if an error occurred
});

// Get results for all tasks with full details
client.tasks.results({
    full: true
}, function (error, results) {
    // results  =  array of objects representing results, or null if an error occurred
});

// Get a task by ID
client.task('5231c687bbdf0f94fa000007').get({}, function (error, task) {
    // task  =  object representing the requested task, or null if an error occurred
});

// Get a task by ID with last results included
client.task('5231c687bbdf0f94fa000007').get({
    lastres: true
}, function (error, task) {
    // task  =  object representing the requested task, or null if an error occurred
});

// Edit a task by ID
client.task('5231c687bbdf0f94fa000007').edit({
    name: 'New name'
}, function (error, task) {
    // task  =  object representing the newly updated task, or null if an error occurred
});

// Delete a task by ID
client.task('5231c687bbdf0f94fa000007').remove(function (error) {
    // err  =  null if task was deleted, or an Error object if something went wrong
});

// Run a task by ID
client.task('5231c687bbdf0f94fa000007').run(function (error) {
    // err  =  null if task is running, or an Error object if something went wrong
});

// Get results for a task
client.task('5231c687bbdf0f94fa000007').results({}, function (error, results) {
    // results  =  array of objects representing results, or null if an error occurred
});

// Get results for a task within a date range
client.task('5231c687bbdf0f94fa000007').results({
    from: '2023-01-01',
    to: '2023-01-31'
}, function (error, results) {
    // results  =  array of objects representing results, or null if an error occurred
});

// Get results for a task with full details
client.task('5231c687bbdf0f94fa000007').results({
    full: true
}, function (error, results) {
    // results  =  array of objects representing results, or null if an error occurred
});

// Get a result by ID
client.task('5231c687bbdf0f94fa000007').result('523c0ee0ca452f0000000009').get({}, function (error, result) {
    // task  =  object representing the requested result, or null if an error occurred
});

// Get a result by ID with full details
client.task('5231c687bbdf0f94fa000007').result('523c0ee0ca452f0000000009').get({
    full: true
}, function (error, result) {
    // task  =  object representing the requested result, or null if an error occurred
});

Contributing

There are many ways to contribute to Pa11y Webservice Node.js Client; we cover these in this repo's contributing guide.

If you'd like to contribute code, get started by cloning the repo and running npm install. Now you'll be able to run the following commands. Please use these build tools to avoid your contribution being delayed by a lint error or a failing test:

# Lint your contribution
npm run lint
# Test your contribution
npm test

Testing the GitHub Actions workflows

This project's GitHub Actions workflows can be tested locally using nektos/act, which can be installed with Homebrew:

brew install act

To validate the syntax of a workflow:

# Validate the publishing workflow, by triggering a 'release' event
act --dryrun release
# Validate the testing workflow
act --dryrun push

To run the testing workflow locally:

# Run the testing workflow, with Node.js 18 only
act push --matrix node-version:18

Add --verbose for more output.

Support and Migration

Note

We maintain a migration guide to help you migrate between major versions.

When we release a new major version we will continue to support the previous major version for 6 months. This support will be limited to fixes for critical bugs and security issues. If you're opening an issue related to this project, please mention the specific version that the issue affects.

The following table lists the major versions available and, for each previous major version, its end-of-support date, and its final minor version released.

Major version Final minor version Node.js support Support end date
4 18, 20 ✅ Current major version
3 3.0 12, 14, 16 September 2024
2 2.0 8, 10 2022-05-26
1 1.2 0.10, 0.12, 4, 6 2020-01-05

License

Licensed under the Lesser General Public License (LGPL-3.0-only).
Copyright © 2013-2024, Team Pa11y