ExtantApe

payload plugin scan

by ExtantApe
Other
v3
^3.80.0
MIT

Overview

Summary generated from the README

Adds scan link handling and a client-side scanner for Payload. Sites register link kinds with a pattern, site scope, staff check and resolver, and the plugin answers each scan based on who is signed in, with rate limits and fail-closed behaviour. React components read codes from a phone camera or USB scanner. Requires Payload 3.80 or newer and a thin Next route per kind.

Features

  • Registers scan link kinds with pattern, scope, staff check and resolver
  • Same answer for unknown, forbidden and malformed codes to prevent probing
  • Per-user rate limit of lookups per minute with hashed keys
  • JSON endpoint returning redirect, sign-in, nothing-here or not-found answers
  • Scanner component with camera, typed and USB entry, repeat suppression and undo
  • Offline queue held in memory and sent in order when the connection returns

Use cases

  • Resolve QR links on shipped kits so staff see the record and buyers see their own page
  • Add camera scanning to a packing or warehouse screen in a custom admin flow
  • Let other plugins register scan kinds without importing each other

From the author

Scan for Payload: read barcodes and QR codes with a phone camera or a USB scanner, and answer scan links by who is signed in, without letting codes be probed.

Installation

npm i @extantape/payload-plugin-scan

0

Stars

0

Forks

0

Open Issues

6 days ago

Last Updated

313

Weekly Downloads

v0.1.1

npm Version

52.7 KB

Unpacked Size

0

Dependencies

GitHub stars

00 since Nov 8

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
Nov 14, 20260
Nov 13, 20260
Nov 12, 20260
Nov 11, 20260
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
npm weekly downloads

302+302 since Nov 14

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 2026302
Dec 4, 2026293
Dec 3, 2026263
Dec 2, 2026242
Dec 1, 202632
Nov 30, 202627
Nov 29, 202630
Nov 28, 202629
Nov 27, 202628
Nov 26, 202623
Nov 25, 202626
Nov 24, 202631
Nov 23, 202642
Nov 22, 2026313
Nov 21, 2026310
Nov 20, 2026308
Nov 19, 2026308
Nov 18, 2026300
Nov 17, 2026290
Nov 16, 2026277
Nov 15, 20260
Nov 14, 20260

Each point is npm's rolling 7-day download count.

Health Score

75/100Excellent

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1456393482-root.svg)](https://payloaddirectory.dev/plugins/1456393482-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1456393482-root"><img src="https://payloaddirectory.dev/badge/1456393482-root.svg" alt="Payload Directory"></a>
Updated Nov 29, 2026Created Nov 13, 2026Published Nov 29, 2026

README

payload-plugin-scan

Scan for Payload: read barcodes and QR codes with a phone camera or a USB scanner, and answer scan links by who is signed in, without letting codes be probed.

Status: 0.1.1. 71 tests pass. 41 are server tests, on Payload 3.92 with an in-memory MongoDB replica set: the answer table, no probing, rate limits, refusals, odd input, the checks that fail closed, and the JSON endpoint with real sign-in. 30 are component and page tests in jsdom, with a fake camera and a fake detector. Nothing has run on a real camera or in a real browser yet, and no site uses it.

What it does

A kind is a short name a provider registers, for links like …/k/<code>. Each kind gives:

  • a pattern (a plain RegExp, not a subclass), checked before anything is looked up;
  • scopeOf(code), its site (leave it out on a single-site install);
  • isStaff(user, scope);
  • resolve(code, user): where this person may go, or null.

resolveScan(payload, { kind, code, req }) answers from who is signed in, never from the link:

WhoA code they may seeAny other code, or not a code
Signed out"Sign in""Sign in"
Signed inwhere resolve sends themone shared "Nothing here for this account"
Staff of that kind, in the code's sitethe record"Not found"
Staff of another site"Not found", the same as a code that doesn't exist

Over the rate limit, everyone signed in gets the quiet "Nothing here" page, staff included.

  • No probing. For anyone but staff in that site, unknown, forbidden and malformed codes get the same answer. Signed-out scans never look anything up. A malformed code never reaches the provider. A real code and a missing one make the same calls, so timing says little (not measured, so not promised).
  • Rate limits: 30 lookups a minute per signed-in person (perMinute). Over the limit, the answer is the same quiet page and no row is added, so a steady flood can't grow the table. Requests that arrive together can let some past perMinute, and store some rows more than the limit.
  • Fails closed: a provider that fails, or a lookup that can't be checked, answers as if the code didn't exist for that person.
  • Never sends anyone off the site: an answer is resolved the way a browser would, and refused unless it stays on your site (//x, /\x and paths with tabs or newlines are refused).
  • On a multi-site install, give every kind scopeOf. Without it, staff of any site count as staff for every code. Only a string with at least one non-space character, or a whole number of 1 or more, counts as a site. Return the site's id, not the site document: read with depth: 0, or return site.id. Return the id itself, never String() of a document or any other value. Any other answer ('', 0, false, a list) means the code has no site, so nobody is staff for it. A scopeOf set to anything but a function or false stops start-up.
  • Nothing is logged with the code next to a person. onRefusal gets the kind and the outcome only, for abuse alerts.
  • For apps, GET /api/scan/:kind/:code gives the same answers as JSON, never cached: { to }, { signIn: true }, { nothingHere: true } or { notFound: true }.
  • Other plugins register kinds at config.custom.scanKinds ([{ owner, kinds }]), with no import, in any plugin order. A kind registered twice stops the site at start-up.

A plugin can't add Next routes, so your site keeps thin routes (/k/[code]) that call resolveScan and redirect, or show one of the pages from @extantape/payload-plugin-scan/pages:

  • ScanSignIn keeps the link's fragment (where an activation secret travels) as the sign-in link's own fragment, so no server ever sees it: never in a query, a cookie or storage. Your sign-in page puts location.hash back on the return URL in the browser when it redirects: never in a form post or a query. Keep third-party scripts off that page, since any script there can read the fragment.
  • ScanNothingHere has a "Use another account" link.
  • ScanNotFound.

Reading codes (@extantape/payload-plugin-scan/client)

  • <Scanner onScan={…} />:
    • Camera: reads continuously once the person presses "Use camera". It uses the browser's BarcodeDetector, or a reader your site provides (detector), for example a ZXing WebAssembly build served from your own domain. Nothing loads from a CDN, and without a reader the camera isn't asked for.
    • Typed and USB entry always work: a USB scanner is a keyboard. Enter or Tab submits, and Tab only when the field has text.
    • Repeats: the same code held in view counts once within repeatMs (2.5 seconds). Typed entries always count.
    • Announcing: results are announced in a polite live region, in words, and a refusal is shown as text, not color alone.
    • Count and Undo: a running count, and Undo when you give onUndo.
    • Offline:
      • scans wait in memory only (never web storage, so codes don't linger on a shared device);
      • they're sent in order when the connection is back;
      • the screen says "N scans waiting to send. Keep this page open", with a "Try sending now" button.
    • Feedback and targets: sound and vibration can each be switched off, and every control has a keyboard path and a 44px target.
  • <CameraScanButton onResult={…} />: opens the camera in a dialog, reads one code and closes. Escape closes it, and focus goes back to the button. Kitting's packing station, once it's built, is designed to take it by import-map path.
  • useScanner({ … }): the same, without the UI.

On its own, and with others

On its own: Scan needs only Payload. Your site passes its own link kinds in kinds and keeps a thin Next route for each, and the client scanner (./client) needs no server part.

Needs: Payload ^3.80.0 as a peer dependency, with React ^19.0.0 optional. No other EXTANT APE plugin is required.

Works with:

  • Sample Kits: with adapters.scan on, Sample Kits registers the k (kit) and b (shipping box) kinds at config.custom.scanKinds.
  • Wizards: a flow's code step can show <CameraScanButton>, for example to find a kit. Wizards doesn't import Scan; your site renders the step.
  • Kitting (designed, not built): Kitting's packing station plans to take <CameraScanButton> as an optional camera adapter, by import-map path.

Color Theory: no direct link. The camera scanner and its pages bring no colors of their own and take your site's CSS, so a site styled with Color Theory's --palette-* tokens styles them too.

Family: Scan sits in the Fulfillment family, with Kitting, Restock, Sample Kits, Shipping, Labels, Wizards, Custody and Sequences, though the families are a working draft and Fulfillment is due to be split into different groups.

Install

npm install @extantape/payload-plugin-scan
import { scanPlugin } from '@extantape/payload-plugin-scan'

scanPlugin({
  kinds: {
    k: {
      pattern: /^\d{12}$/,
      scopeOf: async ({ code }) => siteOfKit(code),
      isStaff: async ({ user, scope }) => isKitStaff(user, scope),
      resolve: async ({ code, user, staff }) => (staff ? { to: `/kits/${code}` } : buyerLink(code, user)),
    },
  },
})

Build the collections' indexes before first use.

Limits

  • The rate limit stores hashed keys only, with each lookup recorded and then counted, so a burst at the same moment can be refused a little early, or let some past the limit.
  • The fragment survives sign-in only if your sign-in page carries location.hash onto the return URL when it redirects.
  • Not tried on a real camera yet.

Commands

npm test          # server and component tests
npm run typecheck
npm run build

License

MIT. See LICENSE.

Similar plugins