Overview
Supertab Connect helps you manage how bots and automated systems access your content. It uses license tokens (JWTs) to verify that a caller has a valid license to access a specific resource.Key Features
- Edge-Ready: Optimized for Cloudflare Workers, Fastly Compute, and AWS CloudFront Lambda@Edge.
- Flexible Enforcement: Choose between logging-only, signaling, or strictly blocking unauthorized requests.
- Plugin Bot Detection: Built-in logic to identify common AI crawlers and headless browsers, customizable using signals from your WAF provider.
- Analytics: Automatically records license usage and verification failures.
Installation
Install the SDK using your preferred package manager:Quickstart: Fastly Compute
The fastest way to get started is using one of the built-in CDN handlers. For Fastly Compute, read your API key from the Secret Store and pass your origin backend name.Initializing the Client
If you aren’t using a convenience handler, you can initialize theSupertabConnect client manually. The client follows a singleton pattern.
Configuration Options
| Property | Type | Description |
|---|---|---|
apiKey | string | Required. Your Supertab Merchant API Key. |
enforcement | EnforcementMode | Controls how unauthorized requests are handled. See Enforcement Modes. |
botDetector | BotDetector | A custom function to identify bots. Defaults to defaultBotDetector. |
debug | boolean | Enables verbose logging to the console. |
Common Workflows
Edge Integration (CDN Handlers)
The SDK provides static methods that handle the entire request/response lifecycle for specific platforms. These handlers:- Extract tokens from the
Authorization: License <token>header. - Verify the token against the Supertab JWKS.
- Record an analytics event.
- If no token is present, run bot detection and apply the enforcement mode.
Fastly Compute
Cloudflare Workers
Always passctx — the SDK uses it to record analytics in the background without blocking the response. The API key is read from the env object (MERCHANT_API_KEY secret).
AWS CloudFront (Lambda@Edge)
Note: This handler is designed for Origin Request events.Manual Verification
UseverifyAndRecord when you need granular control or are running in a standard Node.js/Bun/Deno backend.
Obtaining a License Token
If you are building a client that needs to access protected resources, useobtainLicenseToken to get a license token.
The SDK handles retrieval of the licensing details and automatically refreshes the token when needed.
Whenever a usage type is specified and a token is not required
(the matched content rule permits the intended usage without a license), the method returns no token (undefined).
You should call obtainLicenseToken before every request, the SDK will handle caching and expiration.
usage. If there is a matching <content> rule with the license
explicitly permitting that usage without requiring a license token, the SDK returns undefined.
This allows you to treat undefined as “no token needed” rather than an error.
Important Types
EnforcementMode
Enforcement modes determine what happens when a bot is detected without a valid license token.
STRICT: Blocks the request immediately with a401 Unauthorized(missing or invalid token) or403 Forbidden(token valid but wrong audience).SOFT(Default): Allows the request but attaches RSL headers (Link,X-RSL-Status) to signal that a license is required.DISABLED: No enforcement, signaling, or analytics recording. Requests are allowed without licensing intervention.
DISABLED mode.
Handler Result
When callinghandleRequest manually, you receive a HandlerResult:
{ action: "allow", headers?: ... }: The request should proceed.{ action: "block", status: number, body: string, headers: ... }: The request should be rejected with the provided response.
Error Handling
The SDK provides clear error reasons when a license is invalid. Common reasons include:missing_license_token: No license was provided in the headers.license_token_expired: The JWTexpclaim is in the past.invalid_license_audience: The token is valid but not for the requested URL.license_signature_verification_failed: The token was tampered with or signed by an untrusted issuer.
Tips and Pitfalls
- Performance: When using Cloudflare Workers, always pass the
ExecutionContext(ctx) to the handlers. This allows the SDK to record analytics in the background without delaying the response to the user. - Singleton Pattern: The
SupertabConnectconstructor returns the existing instance if one was already created with the same API key. UseSupertabConnect.resetInstance()if you need to change configurations dynamically. - Custom Bot Detection: If you have specific traffic patterns (e.g., a known internal scraper), provide a custom
botDetectorfunction to prevent false positives. - No token required:
obtainLicenseTokenreturningundefinedis valid whenusagematches content without server URL that permits that usage. Treat it as “no token needed”, not as an authentication failure. - Cache behavior:
obtainLicenseTokencacheslicense.xmlby origin for 15 minutes and license tokens by client, token server, and matched URL pattern. Process restarts clear that cache.
API Reference
Static Methods
cloudflareHandleRequests(request, env, ctx, options?): Cloudflare-specific handler.fastlyHandleRequests(request, apiKey, backend, options?): Fastly-specific handler.cloudfrontHandleRequests(event, options): CloudFront-specific handler.verify(options): Pure token verification (no analytics).obtainLicenseToken(options): Client-side token acquisition.
Instance Methods
handleRequest(request, ctx?): The core logic used by CDN handlers.verifyAndRecord(options): Verifies a token and records the result to Supertab analytics.