Skip to content

Commit 2d49db5

Browse files
committed
Vision API React client 1.0.0
0 parents  commit 2d49db5

22 files changed

Lines changed: 2593 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
# 18.17 is the floor the package declares; test the ends of the range.
14+
node: ['18', '20', '22', '24']
15+
steps:
16+
- uses: actions/checkout@v7
17+
- uses: actions/setup-node@v7
18+
with:
19+
node-version: ${{ matrix.node }}
20+
- run: npm install
21+
- run: npm run typecheck
22+
# The suite stubs `fetch`, so it needs no API key and makes no network calls.
23+
- run: npm test

.github/workflows/publish.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags: ['v[0-9]+.[0-9]+.[0-9]+']
6+
7+
jobs:
8+
publish:
9+
name: Publish to npm
10+
runs-on: ubuntu-latest
11+
environment: npm
12+
permissions:
13+
contents: read
14+
id-token: write # OIDC — trusted publishing and provenance both need this
15+
env:
16+
# Bootstrap only. npm cannot configure a trusted publisher for a package that does not
17+
# exist yet (npm/cli#8544), so 1.0.0 goes out under a short-lived granular token. Once
18+
# the trusted publisher is configured, delete this secret: with it absent the auth step
19+
# below is skipped and the job authenticates entirely over OIDC.
20+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
21+
steps:
22+
- uses: actions/checkout@v7
23+
with:
24+
persist-credentials: false
25+
26+
- uses: actions/setup-node@v7
27+
with:
28+
node-version: '24'
29+
# Deliberately no `registry-url:`. It writes `_authToken=${NODE_AUTH_TOKEN}` into
30+
# ~/.npmrc; with that variable unset npm sees the unexpanded placeholder, decides
31+
# auth is already configured, never starts the OIDC exchange, and fails ENEEDAUTH.
32+
# See actions/setup-node#1551. registry.npmjs.org is npm's default anyway.
33+
34+
- name: Use an npm that can do trusted publishing
35+
run: npm install -g npm@latest # trusted publishing needs npm >= 11.5.1
36+
37+
- name: Tag must match package.json
38+
run: |
39+
tag="${GITHUB_REF_NAME#v}"
40+
pkg="$(node -p "require('./package.json').version")"
41+
[ "$tag" = "$pkg" ] || { echo "tag $tag != package.json $pkg"; exit 1; }
42+
43+
- run: npm ci
44+
- run: npm run typecheck
45+
# The suite stubs `fetch`, so it needs no API key and makes no network calls.
46+
- run: npm test
47+
48+
- name: Bootstrap auth (skipped once NPM_TOKEN is deleted)
49+
if: env.NPM_TOKEN != ''
50+
run: printf '//registry.npmjs.org/:_authToken=%s\n' "$NPM_TOKEN" >> "$HOME/.npmrc"
51+
52+
- name: Publish
53+
# `prepublishOnly` runs the build, so dist/ is fresh. --provenance is required when
54+
# publishing with a token and redundant but harmless under trusted publishing, which
55+
# emits provenance on its own.
56+
run: npm publish --access public --provenance

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
dist/
3+
*.tsbuildinfo
4+
.env
5+
.env.*
6+
.DS_Store
7+
npm-debug.log*
8+
coverage/

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Changelog
2+
3+
All notable changes to this package are documented here. The format follows
4+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the package follows
5+
[semantic versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [1.0.0] — 2026-08-09
8+
9+
First public release.
10+
11+
- `useAnalyze`, `useAsk`, `useDetect` — one file in, structured JSON out, with upload
12+
progress, cancellation and unmount safety
13+
- `useTask` — polls an async task until it settles, and stops on its own
14+
- `usePresets` — the catalog, for a picker
15+
- `VisionProvider` for the endpoint base path and headers, with per-hook overrides
16+
- `VisionError` with `code`, the convenience flags, and a `userMessage` you can render
17+
- `unwrap` / `value` / `rows` / `belowConfidence` result helpers
18+
- Built for the backend-proxy pattern: the hooks talk to your endpoint, never to the API
19+
directly, because an API key is a live spending credential

CONTRIBUTING.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Contributing
2+
3+
Thanks for taking the time. Issues and pull requests are welcome at
4+
<https://github.com/devrobotlabs/visionapi-react>.
5+
6+
If your question is about the **API itself** — a preset, a credit cost, a limit, an error
7+
code — <https://support.visionapi.io> reaches the team faster than an issue here does. This
8+
repository is the React client; the service it talks to is documented at
9+
<https://docs.visionapi.io>.
10+
11+
## Getting set up
12+
13+
```bash
14+
git clone https://github.com/devrobotlabs/visionapi-react.git
15+
cd visionapi-react
16+
npm install
17+
```
18+
19+
## Before you open a pull request
20+
21+
Run what CI runs:
22+
23+
```bash
24+
npm run typecheck
25+
npm test
26+
```
27+
28+
The test suite stubs the transport, so it needs **no API key and makes no network calls**.
29+
A test that reaches the real API will not be merged — it makes the suite slow, flaky, and
30+
impossible to run on a fork.
31+
32+
This package never talks to the API directly. If a change makes it hold an API key in the browser, it is the wrong change — see the README's proxy examples for the shape that is correct.
33+
34+
## One contract, nine libraries
35+
36+
This is one of nine clients — Node, Python, Go, Ruby, PHP, Java, Swift, React and Vue — that
37+
deliberately expose the same surface, named the way each language names things. A change to
38+
behaviour rather than to style is usually a change all nine need, so say so in the pull
39+
request and we will sort out the rest of the set.
40+
41+
Three rules the libraries exist to get right, and which any change has to preserve:
42+
43+
- **Every scalar is wrapped** in `{value, confidence}`, and a line-item array is a *bare*
44+
array whose cells are wrapped individually — not a wrapped array of plain values.
45+
- **Absent is not missing.** A preset response contains every field of the preset, with the
46+
ones the document did not carry as `value: null`. Do not drop them.
47+
- **Retries cannot double-charge.** Every billable POST carries a generated
48+
`Idempotency-Key`; 429 honours the server's `Retry-After`, and 402 and input errors are
49+
never retried because they cannot succeed.
50+
51+
## Style
52+
53+
Match the surrounding code. The linters listed above are the arbiter for everything they
54+
cover; for everything else, the existing files are.
55+
56+
## Reporting a security issue
57+
58+
Please do not open a public issue — see [SECURITY.md](./SECURITY.md).

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Vision API
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)