Skip to content

Version 2 #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Jul 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
50c66e3
Rewritten the code for more features and to extract validation, v2.0.…
m-mohr Aug 10, 2023
a74e9fe
Implement custom validation + doc improvements
m-mohr Sep 7, 2023
043bbcb
2.0.0-beta.2
m-mohr Sep 7, 2023
0f04671
fix various issues, v2.0.0-beta.3
m-mohr Sep 7, 2023
2491e0d
fix CLI output issues, v2.0.0-beta.4
m-mohr Oct 6, 2023
ef062ff
fix CLI output issues, v2.0.0-beta.5
m-mohr Oct 6, 2023
2d9f06f
Add funding info
m-mohr Feb 14, 2024
798731f
Restructure
m-mohr Mar 15, 2024
776de0b
Implement temporary workaround for https://github.com/OSGeo/PROJ/issu…
m-mohr Mar 15, 2024
bf48fe0
v2.0.0-beta.6
m-mohr Mar 15, 2024
d2d441b
clean-up
m-mohr Mar 15, 2024
8b364b4
Fix validation of iri without a host (i.e. localhost)
m-mohr Mar 20, 2024
48faec6
v2.0.0-beta.7
m-mohr Mar 20, 2024
f848077
Revert "Implement temporary workaround for https://github.com/OSGeo/P…
m-mohr Mar 26, 2024
98ede5f
Handle schemas that have no $id defined
m-mohr Jul 19, 2024
0f80500
Import doesn't work
m-mohr Jul 19, 2024
445af98
v2.0.0-beta.8
m-mohr Jul 19, 2024
fd598cf
Report data loading issues
m-mohr Aug 5, 2024
57c0922
Add missing uri-js dependency, v2.0.0-beta.9
m-mohr Aug 5, 2024
35a29de
Fix missing import, v2.0.0-beta.10
m-mohr Aug 5, 2024
c3cffc3
Fix linting report, v2.0.0-beta.11
m-mohr Aug 5, 2024
a9a99a3
Allow to customize Ajv via custom validator, v2.0.0-beta.12
m-mohr Aug 7, 2024
1894549
Don't run MacOS 11 CI anylonger
m-mohr Oct 31, 2024
9af3ed4
Merge branch 'master' into v2
m-mohr Oct 31, 2024
7a84f42
Check against more current node versions
m-mohr Oct 31, 2024
80fef01
Add possibility to bypass validator
m-mohr Oct 31, 2024
c5e8dd8
v2.0.0-beta.13
m-mohr Oct 31, 2024
d88b9ed
Support for partial URLs in schema maps
m-mohr Jan 30, 2025
3628d0a
Support for JS config files
m-mohr Jan 30, 2025
1f44231
Handle invalid input paths better
m-mohr Jan 30, 2025
7202d53
Better URL parsing and handling of unsupported protocols
m-mohr Jan 30, 2025
7e39c5e
v2.0.0-beta.14
m-mohr Jan 30, 2025
8611efb
Fix reference error
m-mohr Jan 30, 2025
f128999
Fix various issues of the last release
m-mohr Jan 30, 2025
f6d7cdb
v2.0.0-beta.15
m-mohr Jan 30, 2025
75b6529
Update stac-js
m-mohr Jan 30, 2025
9553f84
Update README.md
m-mohr Jan 30, 2025
486a2d8
Update src/cli.js
m-mohr Feb 4, 2025
fee4463
Properly handle invalid JSON files, other fixes for custom validators
m-mohr Feb 20, 2025
0b43b1a
v2.0.0-beta.16
m-mohr Feb 20, 2025
e3ef9e5
Don't print if no category is given
m-mohr Feb 20, 2025
aa5bc1e
Support for file URIs
m-mohr Mar 14, 2025
b52a3e6
Fix: Single file validation reports missing STAC version #86
m-mohr Mar 14, 2025
58d49a4
v2.0.0-beta.17
m-mohr Mar 14, 2025
60ea35b
Merge branch 'master' into v2
m-mohr Mar 14, 2025
ab2e747
Fix readme
m-mohr Mar 14, 2025
39d4bc1
Fix assigning errors to reports in custom validators, v2.0.0-beta.18
m-mohr Jun 11, 2025
d10e80d
Fix URLs
m-mohr Jul 5, 2025
35bb9c5
Remove unused import
m-mohr Jul 5, 2025
5e50d69
Remove comparison
m-mohr Jul 5, 2025
e78cb33
Browser bundle
m-mohr Jul 5, 2025
a266be8
Add website
m-mohr Jul 5, 2025
476f908
Update tests and fix found issues
m-mohr Jul 5, 2025
a98633c
Update README, v2.0.0-rc.1
m-mohr Jul 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Deploy to GitHub Pages

on:
push:
branches:
- master

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Install dependencies
run: npm install
- name: Build browser bundle
run: npm run build
- name: Prepare deployment directory
run: |
mkdir -p deploy/dist
cp website/* deploy/
cp dist/* deploy/dist/
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: deploy
user_name: 'moreGeo CI'
user_email: [email protected]
cname: check-stac.moregeo.it

26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release

on:
release:
types: [published]

jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Build browser bundle
run: npm run build
- name: Publish to npm
run: npm publish --provenance --tag latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
44 changes: 26 additions & 18 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
name: Tests

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize]
types:
- opened
- synchronize

jobs:
test:
strategy:
fail-fast: false
matrix:
runner: [
'macos-11',
'macos-12',
'macos-13',
'macos-latest',
'ubuntu-20.04',
'ubuntu-22.04',
'ubuntu-latest',
'windows-2019',
'windows-2022',
'windows-latest',
]
node: [ '16', '18', '20', '22', 'lts/*' ]
runner:
- macos-latest
- ubuntu-latest
- windows-latest
node:
- '20'
- '22'
- '23'
- '24'
- 'lts/*'
runs-on: ${{ matrix.runner }}
name: ${{ matrix.runner }} runner with Node.js ${{ matrix.node }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm test
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Build browser bundle
run: npm run build

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ Thumbs.db
.npm
/node_modules/
/package-lock.json

# Build artifacts
/dist/
46 changes: 0 additions & 46 deletions COMPARISON.md

This file was deleted.

162 changes: 131 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,33 @@ See the [STAC Validator Comparison](COMPARISON.md) for the features supported by

## Versions

**Current version:** 1.3.2
**Current version:** 2.0.0-rc.1

| STAC Node Validator Version | Supported STAC Versions |
| --------------------------- | ----------------------- |
| 1.1.0 / 1.2.x | >= 1.0.0-rc.1 |
| 1.1.0 / 1.2.x / 2.x.x | >= 1.0.0-rc.1 |
| 0.4.x / 1.0.x | >= 1.0.0-beta.2 and < 1.0.0-rc.3 |
| 0.3.0 | 1.0.0-beta.2 |
| 0.2.1 | 1.0.0-beta.1 |

## Quick Start

1. Install a recent version of [node and npm](https://nodejs.org)
Two options:

1. Go to [check-stac.moregeo.it](https://check-stac.moregeo.it) for an online validator.
2. `npx stac-node-validator /path/to/your/file-or-folder` to temporarily install the library and validate the provided file for folder. See the chapters below for advanced usage options.

## Setup
## Usage

1. Install [node and npm](https://nodejs.org) - should run with any version >= 16. Older versions may still work, but no guarantee.
2. `npm install -g stac-node-validator` to install the library permanently
### CLI

## Usage
Install a recent version of [node](https://nodejs.org) (>= 22.1.0) and npm.

Then install the CLI on your computer:

```bash
npm install -g stac-node-validator
```

- Validate a single file: `stac-node-validator /path/to/your/file.json`
- Validate multiple files: `stac-node-validator /path/to/your/catalog.json /path/to/your/item.json`
Expand All @@ -44,51 +51,144 @@ Further options to add to the commands above:
- Add `--strict` to enable strict mode in validation for schemas and numbers (as defined by [ajv](https://ajv.js.org/strict-mode.html) for options `strictSchema`, `strictNumbers` and `strictTuples`)
- To lint local JSON files: `--lint` (add `--verbose` to get a diff with the changes required)
- To format / pretty-print local JSON files: `--format` (Attention: this will override the source files without warning!)
- To run custom validation code: `--custom ./path/to/validation.js` - The validation.js needs to contain a class that implements the `BaseValidator` interface. See [custom.example.js](./custom.example.js) for an example.

**Note on API support:** Validating lists of STAC items/collections (i.e. `GET /collections` and `GET /collections/:id/items`) is partially supported.
It only checks the contained items/collections, but not the other parts of the response (e.g. `links`).

### Config file

You can also pass a config file via the `--config` option. Simply pass a file path as value.
Parameters set via CLI will override the corresponding setting in the config file.
Make sure to use the value `false` to override boolean flags that are set to `true` in the config file.
Parameters set via CLI will not override the corresponding setting in the config file.

The config file uses the same option names as above.
To specify the files to be validated, add an array with paths.
The schema map is an object instead of string separated with a `=` character.

**Example:**
```json
### Programmatic

You can also use the validator programmatically in your JavaScript/NodeJS applications.

Install it into an existing project:

```bash
npm install stac-node-validator
```

#### For browsers

Then in your code, you can for example do the following:

```javascript
const validate = require('stac-node-validator');

// Add any options, e.g. strict mode
const config = {
strict: true
};

// Validate a STAC file from a URL
const result = await validate('https://example.com/catalog.json', config);

// Check if validation passed
if (result.valid) {
console.log('STAC file is valid!');
} else {
console.log('STAC file has errors:');
}
```

#### For NodeJS

```javascript
const validate = require('stac-node-validator');
const nodeLoader = require('stac-node-validator/src/loader/node');

// Add any options
const config = {
loader: nodeLoader
};

// Validate a STAC file from a URL
const result = await validate('https://example.com/catalog.json', config);

// Check if validation passed
if (result.valid) {
console.log('STAC file is valid!');
} else {
console.log('STAC file has errors:');
}
```

#### Validation Results

The `validate` function returns a `Report` object with the following structure:

```javascript
{
"files": [
"/path/to/your/catalog.json",
"/path/to/your/item.json"
],
"schemas": "/path/to/stac/folder",
"schemaMap": {
"https://stac-extensions.github.io/foobar/v1.0.0/schema.json": "./json-schema/schema.json"
id: "catalog.json", // File path or STAC ID
type: "Catalog", // STAC type (Catalog, Collection, Feature)
version: "1.0.0", // STAC version
valid: true, // Overall validation result
skipped: false, // Whether validation was skipped
messages: [], // Info/warning messages
children: [], // Child reports for collections/API responses
results: {
core: [], // Core schema validation errors
extensions: {}, // Extension validation errors (by schema URL)
custom: [] // Custom validation errors
},
"ignoreCerts": false,
"verbose": false,
"lint": true,
"format": false,
"strict": true,
"all": false
apiList: false // Whether this is an API collection response
}
```

You could now override some options as follows in CLI: `stac-node-validator example.json --config /path/to/config.json --lint false`
### Browser

The validator is also available as a browser bundle for client-side validation.

#### CDN Usage

```html
<!-- Include axios for HTTP requests -->
<script src="https://cdn.jsdelivr.net/npm/axios@1/dist/axios.min.js"></script>
<!-- Include the STAC validator bundle -->
<script src="https://cdn.jsdelivr.net/npm/stac-node-validator@2/dist/index.js"></script>

<script>
// The validator is available as a global 'validate' function
async function validateSTAC() {
const stacData = {
"stac_version": "1.0.0",
"type": "Catalog",
"id": "my-catalog",
"description": "A sample catalog",
"links": []
};

const result = await validate(stacData);

if (result.valid) {
console.log('STAC is valid!');
} else {
console.log('Validation errors:', result.results.core);
}
}

validateSTAC();
</script>
```

### Development
## Development

1. `git clone https://github.com/stac-utils/stac-node-validator` to clone the repo
1. `git clone https://github.com/moregeo-it/stac-node-validator` to clone the repo
2. `cd stac-node-validator` to switch into the new folder created by git
3. `npm install` to install dependencies
4. Run the commands as above, but replace `stac-node-validator` with `node bin/cli.js`, for example `node bin/cli.js /path/to/your/file.json`

### Test
### Tests

Simply run `npm test` in a working [development environment](#development).

If you want to disable tests for your fork of the repository, simply delete `.github/workflows/test.yaml`.
### Browser Bundle

To work on the browser bundle build it: `npm run build`

Then you can import it from the `dist` folder.
3 changes: 2 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/bin/env node
require('../index.js')()
const runCLI = require('../src/cli.js');
runCLI();
Loading
Loading