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

pinia-offline-queue

v1.0.0

Published

Nuxt module for offline-first Pinia action queuing with auto-sync on reconnect

Readme

pinia-offline-queue

npm version npm downloads License Nuxt

Offline support for Pinia actions in Nuxt. Keep actions in a local queue, survive refreshes, and sync them when the user is back online.

Features

  • offlineAction() wrapper for Pinia actions
  • useOfflineQueue() composable with reactive queue state + controls
  • IndexedDB queue persistence (idb)
  • Auto-sync on reconnect (navigator.onLine + online event)
  • Laravel validation error (422) items moved to a failed/review queue
  • Optional $laravel helper with Sanctum-friendly CSRF header handling

Installation

pnpm add pinia-offline-queue

If you want Background Sync through Workbox:

pnpm add @vite-pwa/nuxt

Nuxt Setup

Add modules and configure piniaOfflineQueue in nuxt.config.ts:

export default defineNuxtConfig({
  modules: [
    // ...
    'pinia-offline-queue',
  ],

  piniaOfflineQueue: {
    dbName: 'offlineQueueDB',
    storeName: 'pendingActions',
    failedStoreName: 'failedActions',
    maxRetries: 3,
    apiBaseURL: '/api',
    backgroundSync: true,
    syncStrategy: 'networkFirst', // 'networkFirst' | 'queueOnly'
    headers: {
      Accept: 'application/json',
      'X-Requested-With': 'XMLHttpRequest',
    },
  },
})

Usage

1) Wrap offline-capable Pinia actions

// stores/posts.ts
import { defineStore } from 'pinia'
import { offlineAction } from '#imports'

export const usePostStore = defineStore('posts', {
  actions: {
    createPost: offlineAction(
      {
        endpoint: '/posts',
        method: 'POST',
      },
      async (payload: { title: string; content: string }) => {
        const { $laravel } = useNuxtApp()
        return await $laravel('/posts', {
          method: 'POST',
          body: payload,
        })
      },
    ),
  },
})

Behavior:

  • Online (networkFirst): action executes normally
  • Offline: action is queued in IndexedDB and resolves:
{ queued: true, id: '...' }

2) Manage queue state in UI

const {
  pendingCount,
  failedCount,
  isSyncing,
  pendingItems,
  failedItems,
  sync,
  retryFailed,
  clearFailed,
  removeItem,
  onSyncSuccess,
  onSyncError,
} = useOfflineQueue()

Laravel-specific Behavior

During sync:

  • 2xx: item removed from pending queue
  • 422: item moved immediately to failed queue with validationErrors
  • 408, 425, 429, 5xx, or missing-status network failures: retryCount increments
    • if retryCount < maxRetries: remains in pending queue
    • otherwise: moved to failed queue
  • Other 4xx: item moves directly to the failed queue with lastError

Laravel validation payloads (example):

{
  "message": "The given data was invalid.",
  "errors": {
    "title": ["The title field is required."]
  }
}

Those errors are saved on the failed item so your UI can display and correct payloads before retry.

If endpoint-based replay is used without a registered action handler, a single action argument is sent as the request body. Multiple arguments are sent as a JSON array so no payload data is dropped during replay.

Background Sync (Workbox)

When all are true:

  • piniaOfflineQueue.backgroundSync = true
  • @vite-pwa/nuxt is installed
  • module is included in modules

The module injects Workbox runtime caching for mutation methods (POST/PUT/DELETE) to your API base path and wires a service worker sync signal (offline-queue-sync) back to the app for queue processing.

TypeScript

The module augments:

  • Nuxt config/runtime types for piniaOfflineQueue
  • NuxtApp / Vue component instance with $laravel
  • Pinia store custom properties with $offline

SSR and Client-only Notes

Queue operations depend on browser APIs (IndexedDB, navigator, window, service worker) and run client-side only. The module plugin is registered in client mode.

Serialization Caveat

Queued payloads are cloned before persistence. If payloads include File objects, the module warns because browser file handles are not reliably serializable for background replay. Prefer converting files to base64/blob upload workflows before queueing.

Development

pnpm install
pnpm dev:prepare
pnpm dev
pnpm lint
pnpm test
pnpm test:types