ais-common-lib

A library of common utilities and components for Nuxt 3 applications
2,105
Install
npm install ais-common-lib
Latest Version:1.0.38
Vue:3
License:MIT
Last Updated:Oct 23, 2026
Links: npm
Maintainer: rudolfxjacobs

ais-common-lib

A Nuxt 3 module providing API fetch composables for API interaction.

Features

  • Manage API requests with built-in authentication
  • Create/Update/Delete operations simplified

Composables

  • authFetch: Authenticated API requests
  • basicFetch: Simple non-authenticated API requests
  • authMiddleware: handleAuthFlow, checkAccount, checkBasicAuth, checkSuperAuth, and checkEmailVerification helpers
  • useUser: Reactive auth state including emailVerified and pendingEmail computed values

Session clearing semantics

Auth state (localStorage tokens + runtimeConfig.public.*) is only cleared by removeHeaders(), which runs on:

  • an explicit logout() call (after its confirm() passes, or immediately when confirmLogout=false)
  • a 401/403 from checkAccount (network errors and 5xx keep the session so transient backend failures don't log users out)
  • a 401 that survives the axios interceptor's refresh-and-retry flow (catchError), or a failed token refresh in the interceptor itself

Error-log payload redaction

catchError posts diagnostics to errorLogUrl — everything goes through logRedaction.ts first so passwords, tokens, and personal data never leave the browser:

  • key denylist — any object/FormData/header key containing token|password|secret|authorization|credential|signature, or matching a sensitive segment (otp, cvv, code, pin, key, session, csrf, address, postal, dob, passport, …) collapses to "[REDACTED]". Segment matching means shipping/laptop don't trip pin/otp.
  • string masks — JWTs (eyJ…), sor_ shopper tokens, Bearer/Basic creds, ?token=/&key= query params, emails (***@domain), SA phone numbers, and 13–19-digit runs (SA IDs, card PANs) are masked inside every remaining string.
  • api is masked and capped at 255 chars (server CharField); oversized data/error/headers serialize to a {truncated, preview} marker; FormData files become "[file]"; depth caps at 8.

Quick Setup

  1. Add ais-common-lib dependency to your project
# Using npm
npm install ais-common-lib

# Using yarn
yarn add ais-common-lib

# Using pnpm
pnpm add ais-common-lib
  1. Add ais-common-lib to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    'ais-common-lib'
  ],
  aisCommonLib: {
    // module options
    apiBase: 'https://api.example.com'
    profileUrl: 'https://api.example.com/profile',
    errorLogUrl: 'https://api.example.com/errorlog'
  }
})

Usage

AuthFetch Composable

<script setup>
const response = get("api/endpoint");
</script>

BasicFetch Composable

<script setup>
const response = basicGet("api/endpoint");
</script>

Development

# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the playground
npm run dev

# Build the package
npm run build

License

MIT License

Version History

Version Released Vue License
1.0.38 ^3.0.0 MIT
1.0.37 ^3.0.0 MIT
1.0.36 ^3.0.0 MIT
1.0.35 ^3.0.0 MIT
1.0.34 ^3.0.0 MIT