Skip to content

Conversation

@SpiGAndromeda
Copy link
Contributor

Summary

This PR makes the API key optional in the Endereco JavaScript SDK, allowing systems to proxy requests through their own servers and add the API key server-side for enhanced security.

Changes Made

  • Modified API request headers to conditionally include the X-Auth-Key only when apiKey is configured
  • Updated the following extensions:
    • AddressExtension.js - Modified getAddressMeta function
    • EmailCheckExtension.js - Modified checkEmail function
    • PhoneCheckExtension.js - Modified checkPhone function
    • NameCheckExtension.js - Modified checkPerson function
  • No breaking changes - maintains full backward compatibility

Testing

  • Manual testing in demo environment
  • Integration testing completed
  • No breaking changes to existing APIs

Related Issues

This change enables server-side proxy patterns for systems that need to keep API keys secret and add them via backend proxy services.

This enhancement complements the server-side proxy implementation in the Shopware 6 plugin (PR #76), where API keys are stored securely in the backend and requests are proxied through the shop's server. With this SDK change, the Shopware plugin and similar implementations can now operate without exposing API keys in the frontend.

Implementation Details

When config.apiKey is not provided or is empty, the SDK will make requests without the X-Auth-Key header. This allows backend systems to:

  1. Intercept the requests via a proxy
  2. Add the API key server-side
  3. Forward the request to Endereco's API

Existing implementations with client-side API keys will continue to work exactly as before.

Enable SDK to work without client-side API key by conditionally
adding X-Auth-Key header only when apiKey is configured. This allows
systems to proxy requests through their own servers and add the API
key server-side for enhanced security.

Modified header construction in AddressExtension, EmailCheckExtension,
PhoneCheckExtension, and NameCheckExtension to check for apiKey
existence before including it in request headers. Maintains full
backward compatibility for existing implementations.
@iljamobilemojo iljamobilemojo force-pushed the master branch 3 times, most recently from 1bd2fd8 to 9396787 Compare December 1, 2025 12:57
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