npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@formforkio/js

v1.0.0

Published

Official Vanilla JavaScript & TypeScript SDK for FormFork — Universal form submission client, progressive HTML form enhancer, and Store-and-Forward failover.

Readme

@formforkio/js

Zero-dependency Vanilla JavaScript & TypeScript SDK for FormFork.

Designed for static sites (Astro, Eleventy, Hugo, Jekyll, Webflow, Shopify, plain HTML) and custom frontend architectures. Includes Triple-Layer Store-and-Forward Failover, cryptographic fallback tickets (X-FormFork-Ticket), automatic _ff_t bot-timing proof, and localStorage offline queueing.


Features

  • Zero Dependencies & Tiny Footprint: Pure Fetch + FormData + AbortController implementation with full TypeScript definitions.
  • Triple-Layer Store-and-Forward Resilience:
    1. Primary Server: Sends to endpointHost (/f/{formId} or /api/v1/submit) with configurable timeoutMs (6000ms default).
    2. Store-and-Forward Fallback Node: On 502/503/504 or network timeout, seamlessly fails over to your fallbackEndpoint (/storage-node-scripts/fallback-php/index.php).
    3. Browser Offline Outbox: If the user has no internet connection at all, queues the payload in localStorage (formfork_offline_outbox_v1).
  • Offline Site & Form Verification: Supports both embedToken (X-FormFork-Token: ff_pub_...) and stateless HMAC fallbackTicket (X-FormFork-Ticket) so your fallback server can verify request legitimacy even while the primary FormFork server is offline.
  • Flexible Payloads: Pass an HTMLFormElement, a FormData instance (including file uploads), or a plain JSON object.

Installation

# npm
npm install @formforkio/js

# pnpm
pnpm add @formforkio/js

# yarn
yarn add @formforkio/js

# bun
bun add @formforkio/js

Quick Start

1. Submitting a Plain Object or JSON Payload

import { createFormForkClient } from '@formforkio/js';

const formfork = createFormForkClient({
  endpointHost: 'https://forms.yourdomain.com',
  fallbackEndpoint: 'https://fallback.yourdomain.com/index.php',
  embedToken: 'ff_pub_live_98a7bc65d4e3f210',
  fallbackTicket: 'eyJmb3JtSWQiOiJmb3JtLWNvbnRhY3QiLCJkb21haW5zIjpbInlvdXJkb21haW4uY29tIl19.8f3a...',
  timeoutMs: 5000,
});

const result = await formfork.submit('form-contact', {
  name: 'Ada Lovelace',
  email: '[email protected]',
  message: 'Inquiring about enterprise self-hosted licensing.',
});

if (result.success) {
  if (result.queuedViaFallback) {
    console.log('Accepted by Store-and-Forward fallback node:', result.submissionId);
  } else if (result.queuedOffline) {
    console.log('Saved in browser offline outbox; will sync when online.');
  } else {
    console.log('Delivered live to primary server:', result.submissionId);
  }
} else {
  console.error('Submission rejected:', result.code, result.message);
}

2. Binding Directly to an HTML <form> (With File Uploads)

When you pass an HTMLFormElement or FormData object, @formforkio/js automatically preserves multipart/form-data file inputs and appends the _ff_t mount timestamp:

import { FormForkClient } from '@formforkio/js';

const client = new FormForkClient({
  endpointHost: 'https://forms.yourdomain.com',
  fallbackEndpoint: 'https://fallback.yourdomain.com/index.php?formId=form-careers',
});

const formElement = document.querySelector<HTMLFormElement>('#careers-form')!;
const statusBanner = document.querySelector<HTMLElement>('#form-status')!;

formElement.addEventListener('submit', async (event) => {
  event.preventDefault();
  statusBanner.textContent = 'Uploading application...';

  const res = await client.submit('form-careers', formElement);

  if (res.success) {
    statusBanner.textContent = res.message;
    formElement.reset();
  } else {
    statusBanner.textContent = `Error: ${res.message}`;
  }
});

Zero-Setup Form Auto-Provisioning (embedToken)

If you configure an embedToken (ff_pub_live_... or ff_pub_dev_...) tied to your verified domain in FormFork, you can pass a human-readable form name instead of a form-... ID:

const client = createFormForkClient({
  endpointHost: 'https://forms.yourdomain.com',
  embedToken: 'ff_pub_live_98a7bc65d4e3f210',
});

// Automatically creates "Waitlist Signup" in your dashboard on first submission
await client.submit('Waitlist Signup', {
  email: '[email protected]',
  role: 'Engineering Lead',
});

How Offline Fallback Legitimacy Works (fallbackTicket & embedToken)

When your primary FormFork server is down for maintenance or unreachable, the fallback server (fallbackEndpoint) validates incoming browser requests using:

  1. X-FormFork-Ticket (fallbackTicket): A stateless HMAC-SHA256 signed ticket generated by @formforkio/node (createFallbackTicket) that proves the formId, allowed domains (Origin/Referer), and file upload limits without needing database access.
  2. X-FormFork-Token (embedToken): Verified against the SHA-256 token hash list in the fallback server's synced allowlist_manifest.json.

API Reference

new FormForkClient(options?) / createFormForkClient(options?)

FormForkClientOptions

| Option | Type | Default | Description | | :--- | :--- | :--- | :--- | | embedToken | string | undefined | Public embed token (ff_pub_live_... or ff_pub_dev_...). Sent via X-FormFork-Token. | | fallbackTicket | string | undefined | Stateless HMAC ticket generated by @formforkio/node. Sent via X-FormFork-Ticket. | | endpointHost | string | 'https://formfork.io' | Primary FormFork server URL. | | fallbackEndpoint | string | 'https://fallback.formfork.io/index.php' | Secondary Store-and-Forward fallback endpoint URL. | | timeoutMs | number | 6000 | Milliseconds to wait for primary server before failing over to fallbackEndpoint. | | enableOfflineOutbox | boolean | true | Store failed submissions in localStorage when both primary and fallback are unreachable. |

client.submit(formIdOrName, payload)

  • formIdOrName: string — Either an existing FormFork ID (form-...) or a human-readable form name (when embedToken is provided).
  • payload: HTMLFormElement | FormData | Record<string, any> — Form element, FormData, or JSON key-value object.

Returns Promise<FormForkSubmitResponse>

| Property | Type | Description | | :--- | :--- | :--- | | success | boolean | true if accepted by primary, fallback node, or offline outbox. | | submissionId | string \| undefined | Unique submission or spool ID returned by the server. | | queuedViaFallback | boolean \| undefined | true when spooled on the Store-and-Forward fallback server. | | queuedOffline | boolean \| undefined | true when saved to localStorage due to complete network loss. | | message | string | Human-readable status or validation error message. | | redirectUrl | string \| undefined | Optional redirect URL configured on the form. | | code | string \| undefined | Machine-readable error code (e.g. FORBIDDEN_ORIGIN, network_unavailable). |


License

MIT