Skip to content

Feature/update modernization - #1

Open
Trollinou wants to merge 9 commits into
simple-jwt-login:masterfrom
Trollinou:feature/update-modernization
Open

Feature/update modernization#1
Trollinou wants to merge 9 commits into
simple-jwt-login:masterfrom
Trollinou:feature/update-modernization

Conversation

@Trollinou

Copy link
Copy Markdown

Voici un modèle de description complet en anglais, prêt à copier dans ta Pull Request, structuré à partir de ton changelog :


Subject: Modernize SDK to v1.1.0 (WordPress Plugin v4 compatibility, SSR support, test suite)

Description

Hi @maintainer,

I've been using this SDK and took the initiative to modernize the codebase, bring it up to date with the WordPress Simple-JWT-Login plugin v4 API, and ensure full compatibility with modern TypeScript / SSR environments.

Here is a summary of the major changes included in this PR (detailed in CHANGELOG.md) :

🚀 Key Features & Additions

  • Pluggable Token Storage (TokenStorage): Added InMemoryTokenStorage, LocalStorageTokenStorage, and CookieTokenStorage (with HTTP-only cookie support and SSR fallbacks).

  • Silent & Proactive JWT Refresh: Automatic token renewal via getValidJwt() with concurrent request deduplication and onTokenRefreshed callback.

  • WordPress Plugin v4 Alignment:

  • Full TypeScript response interfaces (AuthenticateResponse, RegisterUserResponse, ValidateTokenResponse, etc.).

  • Typed error handling with SimpleJwtLoginApiError and plugin v4 error codes (ERROR_CODES).

  • Updated RefreshTokenInterface prioritizing refresh_token over JWT.

  • SSR / Node.js Support: Safe polyfills (atob/btoa) and environment guards ensuring zero crashes in headless/SSR environments.

  • Testing Suite: Added a comprehensive unit test suite (Jest / ts-jest) covering core SDK behaviors.

⚠️ Breaking Changes & Modernization

  • Async & Modern Fetch: Removed legacy XMLHttpRequest and callbacks in favor of native fetch and Promise-based async/await.

  • Constructor signature: Refactored to accept an options object: new SimpleJwtLogin(host, { namespace, authCodeKey }).

  • Response payload updates: Aligned registerUser payload with plugin v4 format ({ success: true, data: { id } }).


🤝 Project Maintenance

Since this repository has been quiet for a while, let me know if you are interrest by this code. I'm using your last version of you Wordpress plugin and need an update of you old npm for a PWA, thats why I fork it to update it for my need.

Regards.
Etienne Gagnon

google-labs-jules Bot and others added 9 commits August 11, 2026 13:34
- Refactored `SimpleJwtLogin` to use `fetch` and return Promises instead of synchronous `XMLHttpRequest`.
- Updated `autologin` to return the constructed URL instead of performing a direct browser redirect, making the SDK isomorphic (Node.js compatible).
- Improved TypeScript typings by removing `any` usage in core methods.
- Modernized query string construction using `URLSearchParams`.
- Configured Jest and added a robust test suite covering URL generation and API requests.

Co-authored-by: Trollinou <1736548+Trollinou@users.noreply.github.com>
…0039342

feat: implement modernization recommendations
Breaking changes:
- Constructor now takes an options object instead of positional args
  Before: new SimpleJwtLogin(host, namespace, authCodeKey)
  After:  new SimpleJwtLogin(host, { namespace, authCodeKey, ... })

New features:
- Silent JWT refresh via getValidJwt() — concurrent-safe, auto-deduplication
- Pluggable TokenStorage interface with two built-in implementations:
  InMemoryTokenStorage (default) and LocalStorageTokenStorage (PWA)
- onTokenRefreshed callback fired after every successful silent refresh
- authenticate() and refreshToken() auto-store tokens after success
- setTokens() / getJwt() / clearTokens() for manual token management

Plugin v4.x compatibility:
- AuthenticateResponse: includes refresh_token (v4+)
- RegisterUserResponse: data.id instead of ID (v4 breaking change)
- ValidateTokenResponse: typed user + roles response
- SimpleJwtLoginErrorResponse: error_code instead of errorCode (v4)
- AuthenticateInterface: added login field (v3.6+ email-or-username)
  and payload field (custom JWT claims)

Fixes:
- tsconfig: exclude tests/ removed so ts-jest can compile tests
- tsconfig: added types:[jest], target ES2021, rootDir, exclude dist
- tests: replaced global with globalThis (standard ES2020+)

Tests: 17 passing
Build: tsc compilation clean
…eStorage

## Changements

### Conformité API WordPress Plugin v4
- Corrections RefreshTokenInterface: ajoute refresh_token (conforme API v4)
- SimpleJwtLoginApiError: classe d'erreur typée avec format plugin
- ERROR_CODES: constantes pour tous les codes d'erreur du plugin
- refreshToken() utilise refresh_token en priorité (rétrocompatible)

### Support SSR/Node.js
- LocalStorageTokenStorage: sécurisé pour SSR (vérifie disponibilité)
- atobPolyfill: polyfill pour Node.js < 16
- @types/node ajouté aux types TypeScript

### Nouvelle fonctionnalité
- CookieTokenStorage: stockage par cookies avec options config
- CookieOptions: interface pour configurer les cookies

### Qualité
- 50 tests (vs 34): +16 tests pour CookieStorage et erreurs
- Lint propre
- Build vérifié

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
## Changements de documentation

- README.md:
  - Ajout section CookieTokenStorage
  - Ajout section Error Handling avec exemples
  - Ajout section SSR/Node.js Support
  - Mise à jour Response Types
  - Mise à jour Changelog (v1.1.0)

- CHANGELOG.md:
  - Nouveau fichier au format Keep a Changelog
  - Documentation complète des changements v1.1.0

- RECOMMENDATIONS.md:
  - Supprimé (obsolète, toutes les recommandations implémentées)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant