pa11y-webservice-client-node
Advanced tools
Comparing version 3.0.0 to 4.0.0
@@ -1,128 +0,102 @@ | ||
// This file is part of Pa11y Webservice Node.js Client. | ||
// | ||
// Pa11y Webservice Node.js Client is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Pa11y Webservice Node.js Client is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Pa11y Webservice Node.js Client. If not, see <http://www.gnu.org/licenses/>. | ||
/* | ||
* Copyright (c) 2024 Pa11y project's team and contributors | ||
* SPDX-License-Identifier: LGPL-3.0-only | ||
*/ | ||
'use strict'; | ||
var request = require('request'); | ||
const request = require('request'); | ||
module.exports = client; | ||
// Create a web-service client | ||
function client (root) { | ||
function client(root) { | ||
return { | ||
tasks: { | ||
// Create a new task | ||
create: function (task, done) { | ||
post(root + 'tasks', task, done); | ||
create(task, done) { | ||
post(`${root}tasks`, task, done); | ||
}, | ||
// Get all tasks | ||
get: function (query, done) { | ||
get(root + 'tasks', query, done); | ||
get(query, done) { | ||
get(`${root}tasks`, query, done); | ||
}, | ||
// Get results for all tasks | ||
results: function (query, done) { | ||
get(root + 'tasks/results', query, done); | ||
results(query, done) { | ||
get(`${root}tasks/results`, query, done); | ||
} | ||
}, | ||
task: function (id) { | ||
task(id) { | ||
return { | ||
// Get a task | ||
get: function (query, done) { | ||
get(root + 'tasks/' + id, query, done); | ||
get(query, done) { | ||
get(`${root}tasks/${id}`, query, done); | ||
}, | ||
// Edit a task | ||
edit: function (edits, done) { | ||
patch(root + 'tasks/' + id, edits, done); | ||
edit(edits, done) { | ||
patch(`${root}tasks/${id}`, edits, done); | ||
}, | ||
// Remove a task | ||
remove: function (done) { | ||
del(root + 'tasks/' + id, null, done); | ||
remove(done) { | ||
del(`${root}tasks/${id}`, null, done); | ||
}, | ||
// Run a task | ||
run: function (done) { | ||
post(root + 'tasks/' + id + '/run', null, done); | ||
run(done) { | ||
post(`${root}tasks/${id}/run`, null, done); | ||
}, | ||
// Get results for a task | ||
results: function (query, done) { | ||
get(root + 'tasks/' + id + '/results', query, done); | ||
results(query, done) { | ||
get(`${root}tasks/${id}/results`, query, done); | ||
}, | ||
result: function (rid) { | ||
result(rid) { | ||
return { | ||
// Get a result | ||
get: function (query, done) { | ||
get(root + 'tasks/' + id + '/results/' + rid, query, done); | ||
get(query, done) { | ||
get(`${root}tasks/${id}/results/${rid}`, query, done); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
// Perform a DELETE request | ||
function del (url, query, done) { | ||
req('DELETE', url, query, null, done); | ||
function del(url, query, done) { | ||
call({ | ||
method: 'DELETE', | ||
url, | ||
query | ||
}, done); | ||
} | ||
// Perform a GET request | ||
function get (url, query, done) { | ||
req('GET', url, query, null, done); | ||
function get(url, query, done) { | ||
call({ | ||
method: 'GET', | ||
url, | ||
query | ||
}, done); | ||
} | ||
// Perform a PATCH request | ||
function patch (url, body, done) { | ||
req('PATCH', url, null, body, done); | ||
function patch(url, body, done) { | ||
call({ | ||
method: 'PATCH', | ||
url, | ||
body | ||
}, done); | ||
} | ||
// Perform a POST request | ||
function post (url, body, done) { | ||
req('POST', url, null, body, done); | ||
function post(url, body, done) { | ||
call({ | ||
method: 'POST', | ||
url, | ||
body | ||
}, done); | ||
} | ||
// Perform a request | ||
function req (method, url, query, body, done) { | ||
function call({method, url, query, body}, done) { | ||
request({ | ||
method: method, | ||
url: url, | ||
method, | ||
url, | ||
qs: query, | ||
body: body, | ||
body, | ||
json: true | ||
}, function (err, res, body) { | ||
if (err) { | ||
return done(err); | ||
}, (error, response, responseBody) => { | ||
if (error) { | ||
return done(error); | ||
} | ||
if (res.statusCode > 299) { | ||
var message = (body && body.message ? body.message : 'Error ' + res.statusCode); | ||
if (response.statusCode >= 300) { | ||
const message = (responseBody?.message || `Error ${response.statusCode}`); | ||
return done(new Error(message)); | ||
} | ||
done(null, body); | ||
done(null, responseBody); | ||
}); | ||
} | ||
module.exports = client; |
{ | ||
"name": "pa11y-webservice-client-node", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=18" | ||
}, | ||
"description": "pa11y-webservice-client-node is a Node.js client library for pa11y-webservice", | ||
"description": "A Node.js client library for Pa11y Webservice", | ||
"keywords": [ | ||
@@ -19,9 +19,6 @@ "accessibility", | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/pa11y/webservice-client-node.git" | ||
}, | ||
"homepage": "https://github.com/pa11y/webservice-client-node", | ||
"bugs": "https://github.com/pa11y/webservice-client-node/issues", | ||
"license": "GPL-3.0", | ||
"repository": "github:pa11y/pa11y-webservice-client-node", | ||
"homepage": "https://github.com/pa11y/pa11y-webservice-client-node", | ||
"bugs": "https://github.com/pa11y/pa11y-webservice-client-node/issues", | ||
"license": "LGPL-3.0-only", | ||
"dependencies": { | ||
@@ -31,13 +28,13 @@ "request": "~2.88.2" | ||
"devDependencies": { | ||
"grunt": "~1.4.1", | ||
"grunt-contrib-jshint": "~3.1.1", | ||
"grunt-mocha-test": "~0.13.3", | ||
"mocha": "~8.4.0", | ||
"mockery": "~1.4.0", | ||
"proclaim": "~3.6.0", | ||
"sinon": "~1.7.0" | ||
"eslint": "^8.53.0", | ||
"mocha": "^10.2.0", | ||
"mockery": "^2.1.0", | ||
"pa11y-lint-config": "^3.0.0", | ||
"proclaim": "^3.6.0", | ||
"sinon": "^17.0.1" | ||
}, | ||
"main": "./lib/client.js", | ||
"scripts": { | ||
"test": "grunt" | ||
"test": "mocha test/unit --recursive", | ||
"lint": "eslint ." | ||
}, | ||
@@ -44,0 +41,0 @@ "files": [ |
129
README.md
@@ -5,4 +5,5 @@ # Pa11y Webservice Node.js Client | ||
[![NPM version][shield-npm]][info-npm] | ||
[![Latest version published to npm][shield-npm]][info-npm] | ||
[![Node.js version support][shield-node]][info-node] | ||
[![Supports pa11y-webservice@4 API][shield-api]][pa11y-webservice] | ||
[![Build status][shield-build]][info-build] | ||
@@ -13,6 +14,6 @@ [![LGPL-3.0 licensed][shield-license]][info-license] | ||
Install Pa11y Webservice Node.js Client with npm: | ||
Add this client to your project with your preferred package manager. For example, to install it as a development dependency with npm: | ||
```sh | ||
$ npm install pa11y-webservice-client-node | ||
npm install --save-dev pa11y-webservice-client-node | ||
``` | ||
@@ -22,9 +23,9 @@ | ||
For more information on the actual webservice endpoints and resource types, [read the documentation][wiki-web-service]. | ||
For information about Pa11y Webservice's endpoints and resource types, [read the documentation][wiki-web-service]. | ||
```js | ||
var createClient = require('pa11y-webservice-client-node'); | ||
const createClient = require('pa11y-webservice-client-node'); | ||
// Create client with the base URL of the web-service | ||
var client = createClient('http://localhost:3000/'); | ||
// Create client with the base URL of your instance of Pa11y Webservice | ||
const client = createClient('http://localhost:3000/'); | ||
@@ -36,3 +37,3 @@ // Create a task | ||
standard: 'WCAG2AA' | ||
}, function (err, task) { | ||
}, function (error, task) { | ||
// task = object representing the new task, or null if an error occurred | ||
@@ -42,3 +43,3 @@ }); | ||
// Get all tasks | ||
client.tasks.get({}, function (err, tasks) { | ||
client.tasks.get({}, function (error, tasks) { | ||
// tasks = array of objects representing tasks, or null if an error occurred | ||
@@ -50,3 +51,3 @@ }); | ||
lastres: true | ||
}, function (err, tasks) { | ||
}, function (error, tasks) { | ||
// tasks = array of objects representing tasks, or null if an error occurred | ||
@@ -56,3 +57,3 @@ }); | ||
// Get results for all tasks | ||
client.tasks.results({}, function (err, results) { | ||
client.tasks.results({}, function (error, results) { | ||
// results = array of objects representing results, or null if an error occurred | ||
@@ -63,5 +64,5 @@ }); | ||
client.tasks.results({ | ||
from: '2013-01-01', | ||
to: '2013-01-31' | ||
}, function (err, results) { | ||
from: '2023-01-01', | ||
to: '2023-01-31' | ||
}, function (error, results) { | ||
// results = array of objects representing results, or null if an error occurred | ||
@@ -73,3 +74,3 @@ }); | ||
full: true | ||
}, function (err, results) { | ||
}, function (error, results) { | ||
// results = array of objects representing results, or null if an error occurred | ||
@@ -79,3 +80,3 @@ }); | ||
// Get a task by ID | ||
client.task('5231c687bbdf0f94fa000007').get({}, function (err, task) { | ||
client.task('5231c687bbdf0f94fa000007').get({}, function (error, task) { | ||
// task = object representing the requested task, or null if an error occurred | ||
@@ -87,3 +88,3 @@ }); | ||
lastres: true | ||
}, function (err, task) { | ||
}, function (error, task) { | ||
// task = object representing the requested task, or null if an error occurred | ||
@@ -95,3 +96,3 @@ }); | ||
name: 'New name' | ||
}, function (err, task) { | ||
}, function (error, task) { | ||
// task = object representing the newly updated task, or null if an error occurred | ||
@@ -101,3 +102,3 @@ }); | ||
// Delete a task by ID | ||
client.task('5231c687bbdf0f94fa000007').remove(function (err) { | ||
client.task('5231c687bbdf0f94fa000007').remove(function (error) { | ||
// err = null if task was deleted, or an Error object if something went wrong | ||
@@ -107,3 +108,3 @@ }); | ||
// Run a task by ID | ||
client.task('5231c687bbdf0f94fa000007').run(function (err) { | ||
client.task('5231c687bbdf0f94fa000007').run(function (error) { | ||
// err = null if task is running, or an Error object if something went wrong | ||
@@ -113,3 +114,3 @@ }); | ||
// Get results for a task | ||
client.task('5231c687bbdf0f94fa000007').results({}, function (err, results) { | ||
client.task('5231c687bbdf0f94fa000007').results({}, function (error, results) { | ||
// results = array of objects representing results, or null if an error occurred | ||
@@ -120,5 +121,5 @@ }); | ||
client.task('5231c687bbdf0f94fa000007').results({ | ||
from: '2013-01-01', | ||
to: '2013-01-31' | ||
}, function (err, results) { | ||
from: '2023-01-01', | ||
to: '2023-01-31' | ||
}, function (error, results) { | ||
// results = array of objects representing results, or null if an error occurred | ||
@@ -130,3 +131,3 @@ }); | ||
full: true | ||
}, function (err, results) { | ||
}, function (error, results) { | ||
// results = array of objects representing results, or null if an error occurred | ||
@@ -136,3 +137,3 @@ }); | ||
// Get a result by ID | ||
client.task('5231c687bbdf0f94fa000007').result('523c0ee0ca452f0000000009').get({}, function (err, result) { | ||
client.task('5231c687bbdf0f94fa000007').result('523c0ee0ca452f0000000009').get({}, function (error, result) { | ||
// task = object representing the requested result, or null if an error occurred | ||
@@ -144,3 +145,3 @@ }); | ||
full: true | ||
}, function (err, result) { | ||
}, function (error, result) { | ||
// task = object representing the requested result, or null if an error occurred | ||
@@ -152,48 +153,78 @@ }); | ||
There are many ways to contribute to Pa11y Webservice Node.js Client, we cover these in the [contributing guide](CONTRIBUTING.md) for this repo. | ||
There are many ways to contribute to Pa11y Webservice Node.js Client; we cover these in this repo's [contributing guide](CONTRIBUTING.md). | ||
If you're ready to contribute some code, you'll need to clone the repo locally and run `npm install`. You'll also need [Grunt][grunt] to be installed globally in order to run tests, you can do this with `npm install -g grunt-cli`. | ||
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: | ||
Now you'll be able to run the following commands: | ||
```sh | ||
# Lint your contribution | ||
npm run lint | ||
``` | ||
```sh | ||
$ grunt # Run the lint and test tasks together | ||
$ grunt lint # Run JSHint with the correct config | ||
$ grunt test # Run unit tests | ||
# Test your contribution | ||
npm test | ||
``` | ||
Code with lint errors or failing tests will not be accepted, please use the build tools outlined above. | ||
### Testing the GitHub Actions workflows | ||
For users with push-access, don't commit to the master branch. Code should be in `develop` until it's ready to be released. | ||
This project's GitHub Actions workflows can be tested locally using [nektos/act](https://github.com/nektos/act), which can be installed with Homebrew: | ||
```sh | ||
brew install act | ||
``` | ||
To validate the syntax of a workflow: | ||
```sh | ||
# Validate the publishing workflow, by triggering a 'release' event | ||
act --dryrun release | ||
``` | ||
```sh | ||
# Validate the testing workflow | ||
act --dryrun push | ||
``` | ||
To run the testing workflow locally: | ||
```sh | ||
# Run the testing workflow, with Node.js 18 only | ||
act push --matrix node-version:18 | ||
``` | ||
Add `--verbose` for more output. | ||
## Support and Migration | ||
Major versions are normally supported for 6 months after their last minor release. This means that patch-level changes will be added and bugs will be fixed. The table below outlines the end-of-support dates for major versions, and the last minor release for that version. | ||
> [!NOTE] | ||
> We maintain a [migration guide](MIGRATION.md) to help you migrate between major versions. | ||
We also maintain a [migration guide](MIGRATION.md) to help you migrate. | ||
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. | ||
| :grey_question: | Major Version | Last Release | Node.js Versions | Support End Date | | ||
| :-------------- | :------------ | :----------- | :--------------- | :--------------- | | ||
| :heart: | 3 | N/A | 12+ | N/A | | ||
| :hourglass: | 2 | 2.0.0 | 8+ | 2022-05-26 | | ||
| :skull: | 1 | 1.2.1 | 0.10+ | 2020-01-05 | | ||
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. | ||
If you're opening issues related to these, please mention the version that the issue relates to. | ||
| 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 [GNU General Public License 3.0](LICENSE.txt).<br/> | ||
Copyright © 2013–2019, Team Pa11y | ||
Licensed under the [Lesser General Public License (LGPL-3.0-only)][info-license]. | ||
Copyright © 2013-2024, Team Pa11y | ||
[gpl]: http://www.gnu.org/licenses/gpl-3.0.html | ||
[grunt]: http://gruntjs.com/ | ||
[pa11y-webservice]: https://github.com/pa11y/pa11y-webservice | ||
[wiki-web-service]: https://github.com/pa11y/pa11y-webservice/wiki/Web-Service-Endpoints | ||
[info-build]: https://github.com/pa11y/pa11y-webservice-client-node/actions/workflows/build-and-test.yml | ||
[info-build]: https://github.com/pa11y/pa11y-webservice-client-node/actions/workflows/tests.yml | ||
[info-license]: LICENSE | ||
[info-node]: package.json | ||
[info-npm]: https://www.npmjs.com/package/pa11y-webservice-client-node | ||
[shield-build]: https://github.com/pa11y/pa11y-webservice-client-node/actions/workflows/build-and-test.yml/badge.svg | ||
[shield-build]: https://github.com/pa11y/pa11y-webservice-client-node/actions/workflows/tests.yml/badge.svg | ||
[shield-license]: https://img.shields.io/badge/license-LGPL%203.0-blue.svg | ||
[shield-node]: https://img.shields.io/node/v/pa11y-webservice-client-node.svg | ||
[shield-npm]: https://img.shields.io/npm/v/pa11y-webservice-client-node.svg | ||
[shield-api]: https://img.shields.io/badge/api-pa11y--webservice@4-blue.svg |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
6
211
17801
94
1