Feature/update modernization - #1
Open
Trollinou wants to merge 9 commits into
Open
Conversation
- 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>
Feat/conformity and ssr support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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): AddedInMemoryTokenStorage,LocalStorageTokenStorage, andCookieTokenStorage(with HTTP-only cookie support and SSR fallbacks).Silent & Proactive JWT Refresh: Automatic token renewal via
getValidJwt()with concurrent request deduplication andonTokenRefreshedcallback.WordPress Plugin v4 Alignment:
Full TypeScript response interfaces (
AuthenticateResponse,RegisterUserResponse,ValidateTokenResponse, etc.).Typed error handling with
SimpleJwtLoginApiErrorand plugin v4 error codes (ERROR_CODES).Updated
RefreshTokenInterfaceprioritizingrefresh_tokenoverJWT.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.Async & Modern Fetch: Removed legacy
XMLHttpRequestand callbacks in favor of nativefetchand Promise-basedasync/await.Constructor signature: Refactored to accept an options object:
new SimpleJwtLogin(host, { namespace, authCodeKey }).Response payload updates: Aligned
registerUserpayload 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