SavyScan SDK 0.5.0-beta.7

API reference

The approved commercial beta contract, documented with explicit evidence and support boundaries.

01 / Module surface

Exports

0.5.0-beta.7 approved beta. The live demo and release build include SavyScanError and early validation.

// These imports compile against the approved 0.5.0 beta release.
import SavyScan, { create, version } from "@savyscan/web-sdk";
import "@savyscan/web-sdk/styles.css";

// 0.5.0-beta.7 source also provides a named SavyScanError export.
const ErrorType = SavyScan.SavyScanError;
ExportTypeContract
defaultSavyScanSDKObject containing version, create, and SavyScanError.
versionstring"0.5.0-beta.7" in the approved beta release.
create(options) => instanceCreates and mounts one hidden scanner interface.
SavyScanErrorError subclass0.5.0-beta.7 structured configuration and runtime error.
window.SavyScanSavyScanSDKPreferred global exposed by the direct browser bundle.
window.DocumentScannerSDKSavyScanSDKDeprecated migration alias retained through 0.5.x.

The runtime contains internal test helpers, but they are not part of the supported customer API and may change without a semver guarantee.

02 / Configuration

create(options)

Creates an SDK-owned root under document.body by default. Call it after the body exists, or provide a valid mount target. The option set below is shared by 0.4.0 and 0.5.0-beta.7; validation descriptions refer to the beta.

OptionDefaultSupported behavior
openCvUrlRequiredNon-empty HTTP(S) URL, including a relative URL, to pinned OpenCV.js. Prefer same-origin OpenCV 4.13.0.
mountTargetdocument.bodyElement, non-empty selector resolving to an element, or null. A supplied legacy root retains precedence.
maxPages40Positive safe integer.
maxPdfBytes12 MiBPositive safe integer; maximum completed PDF size.
maxPageBytes8 MiBPositive safe integer; maximum corrected JPEG page size.
maxSourceDimension3000Positive safe integer; maximum decoded or captured source edge.
maxOutputDimension2600Positive safe integer; maximum corrected page edge.
maxOutputPixels5,400,000Positive safe integer; maximum corrected page area.
jpegQuality0.9Finite number from 0 through 1.
defaultEnhancement"grayscale"Exactly grayscale, enhanced_color, black_white, or original.
automaticCapturetrueBoolean; false starts in manual mode.
labels{}Known keys with non-empty string values.
theme{}Known keys with non-empty CSS-value strings.
onCompleteNo-opFunction receiving the completed result. A returned promise is awaited.
onCloseNo-opFunction receiving { completed: boolean }.
onCancelNo-opFunction receiving { completed: false }.
onErrorNo-opFunction receiving SavyScanError in 0.5.0-beta.7 source.
onStateChangeNo-opFunction receiving announced state messages and tones.
onDiagnosticNo-opOpt-in callback receiving frozen privacy-safe lifecycle events. SavyScan never transmits them.

Privacy-safe diagnostics

onDiagnostic(event) {
  // Closed schema: no pixels, text, references, filenames, URLs,
  // device identifiers, wall-clock timestamps, or host metadata.
  telemetry.record(event);
}

Every event includes schemaVersion, sdkVersion, name, session-relative elapsedMs rounded to 100 ms, and pageCount. Applicable events may add only captureMode, automaticCapture, cameraAvailable, completed, errorCode, or recoverable. Callback failures are ignored and cannot interrupt scanning.

Advanced automatic-capture controls

OptionDefaultMeaning and beta range
autoCaptureAnalysisDimension720Positive safe integer; analysis-frame maximum edge.
autoCaptureIntervalMs350Positive finite target delay; scheduling is clamped internally to 300–1200 ms.
autoCaptureWarmupMs1500Non-negative finite delay before analysis.
autoCaptureStableMs900Non-negative finite required stable duration.
autoCaptureStableFrames4Positive safe integer; required stable-frame count.
autoCaptureMaxDriftRatio0.045Finite ratio from 0 through 1 between adjacent frames.
autoCaptureMaxAnchorDriftRatio0.08Finite ratio from 0 through 1 from the stability anchor.
autoCaptureMaxContentDifference14Finite adjacent-frame difference from 0 through 255.
autoCaptureMaxAnchorContentDifference22Finite anchor difference from 0 through 255.
autoCaptureMinimumSharpness110Non-negative finite automatic-detection threshold.
captureMinimumSharpness125Non-negative finite final quality gate.
autoCaptureSharpnessDropRatio0.88Finite ratio greater than 0 and no greater than 1.
autoCaptureSharpnessGainRatio1.15Finite ratio of at least 1.
autoCaptureMissToleranceMs700Non-negative finite ready-state tolerance.
autoCaptureMissToleranceFrames2Non-negative safe integer; brief missed detections allowed without restarting the hold.
autoCaptureAnnouncementIntervalMs1600Non-negative finite guidance interval.

03 / Instance

Methods

open(options?)

Shows the scanner, locks body scrolling, makes background siblings inert, and begins asynchronous OpenCV and camera setup. It returns void, throws after destruction, and is a no-op for valid options if already open.

scanner.open({
  referenceLabel: "Purchase Order",
  referenceNumber: "5C.143430",
  returnFocusElement: launchButton,
});

The 0.5.0-beta.7 source validates open(options) before it mutates session state. References may be strings or finite numbers, returnFocusElement is an element or null, and a session-only maxPages must be a positive safe integer. The deprecated purchaseOrderNumber input remains accepted for backward compatibility.

close({ completed = false }?)

Stops the camera, clears pages and canvases, revokes SDK-owned object URLs, hides the interface, and restores page state. Consumers normally call close(); completed close is primarily the SDK’s internal success path.

destroy()

Idempotently closes if necessary, removes listeners, clears resources, and removes an SDK-owned root. The instance cannot reopen.

04 / Completion value

Result

type SavyScanResult = {
  pdfBlob: Blob;       // application/pdf
  previewBlob: Blob;   // image/jpeg — first corrected page
  pageCount: number;
};

previewBlob is not a PDF preview. It is the first corrected page as JPEG, useful when a mobile browser cannot render the PDF Blob inline.

05 / Event order

Callbacks

CallbackPayloadBehavior
onCompleteSavyScanResultRuns first on success. Its returned promise is awaited before the completed close.
onClose{ completed }Runs after every completed or cancelled close.
onCancel{ completed: false }Runs before onClose when the scan is not completed.
onStateChange{ message, tone }Tones: info, success, warning, error, or working.
onErrorSavyScanErrorIn 0.5.0-beta.7, receives reported operational failures, including recoverable camera warnings and host callback failures. Setup errors may arrive before open() returns.

Success order: onComplete → await returned value → onClose({ completed: true }). A rejected completion promise leaves the scanner open and reports HOST_CALLBACK_FAILED.

06 / Appearance

Labels and theme

Theme keySDK default
primaryColor#3b82f6
primaryTextColor#ffffff
surfaceColor#090d14
reviewSurfaceColor#151a22
textColor#f8fafc
borderRadius0.875rem
fontFamilyInter/system sans stack

Supported labels are title (default “SavyScan”) and cameraPlaceholder (default “Camera preview will appear here.”).

07 / 0.5.0-beta.7 contract

Structured validation and errors

The 0.5.0 beta source validates create(options) and open(options) synchronously, before UI, camera, or session side effects. It rejects unknown top-level and nested keys instead of coercing or silently ignoring them. Reported operational failures use the same error type through onError; camera capability errors may be delivered before open() returns.

{
  name: "SavyScanError",
  code: "CONFIG_INVALID_VALUE",
  message: "maxPages must be at least 1.",
  field: "maxPages",
  recoverable: false
}

Use code and field for program flow; messages may improve between releases. recoverable means the same instance can continue or retry. The optional underlying cause is deliberately omitted by toJSON(), and configured values or URLs are not copied into error messages.

CodeWhen it is used
CONFIG_REQUIREDA required options object or openCvUrl is missing.
CONFIG_UNKNOWN_KEYAn unsupported create, open, label, or theme key was supplied.
CONFIG_INVALID_TYPEA value has the wrong JavaScript type or a numeric value is not finite.
CONFIG_INVALID_VALUEA numeric range, enum, URL protocol, or selector is invalid.
ENVIRONMENT_UNSUPPORTEDA required DOM, Canvas, Blob, URL, text-encoding, or WebAssembly capability is missing.
MOUNT_TARGET_NOT_FOUNDThe configured selector does not resolve to an element.
SCANNER_ROOT_INVALIDA legacy supplied root does not contain the complete scanner structure.
OPENCV_LOAD_FAILEDThe pinned processor asset fails to load or times out.
OPENCV_INITIALIZATION_FAILEDThe processor loads but cannot become ready.
CAMERA_PERMISSION_DENIEDThe user or browser denies live-camera access; Photos remains available.
CAMERA_UNAVAILABLENo compatible live camera API or device is available; Photos remains available.
CAMERA_START_FAILEDThe live camera cannot start; Photos remains available.
INSTANCE_DESTROYEDopen() is called after permanent destruction.
PROCESSING_FAILEDCapture, correction, output, or another scanning operation fails.
HOST_CALLBACK_FAILEDA notification callback other than onError throws synchronously, or onComplete throws or rejects; rejected completion remains retryable.

Release boundary. Structured validation is part of the exact 0.5.0-beta.7 contract. Do not assume it exists in earlier package versions.

Review compatibility