A comprehensive JavaScript SDK for integrating Endereco address validation workflows into web applications.
The Endereco JavaScript SDK provides seamless integration of address validation, email verification, phone validation, and person data services into web applications. Unlike standalone applications, this SDK is designed to be bundled into existing systems, making address validation workflows accessible through simple JavaScript APIs.
- Address Validation (AMS) - Real-time address verification and correction with autocomplete
- Email Services - Email address validation and deliverability checking
- Phone Services - Phone number format validation and type verification
- Person Services - Name validation and formatting for form data
npm install @endereco/js-sdkFor direct browser integration, use the pre-built distribution files:
<script
defer
async
src="dist/endereco.min.js"
></script>The defer and async attributes ensure optimal loading performance.
The SDK supports modern browsers based on the following configuration:
- Coverage: >1% market share, last 2 versions
- Exclusions: Internet Explorer 9 and below
- Polyfills: Automatic polyfill injection for legacy browser compatibility
- Initialize the SDK:
// Ensure EnderecoIntegrator is available
if (undefined === window.EnderecoIntegrator) {
window.EnderecoIntegrator = {};
}
if (!window.EnderecoIntegrator.onLoad) {
window.EnderecoIntegrator.onLoad = [];
}
// Helper function for SDK initialization
async function enderecoInitAMS(selectors, config) {
if (window.EnderecoIntegrator.ready) {
window.EnderecoIntegrator.initAMS(selectors, config);
} else {
window.EnderecoIntegrator.onLoad.push(async () => {
window.EnderecoIntegrator.initAMS(selectors, config);
});
}
}- Configure the SDK:
function enderecoLoadAMSConfig() {
window.EnderecoIntegrator.defaultCountry = 'DE';
window.EnderecoIntegrator.config.apiKey = 'your-api-key';
window.EnderecoIntegrator.config.apiUrl = 'your-proxy-endpoint';
window.EnderecoIntegrator.config.remoteApiUrl = 'https://endereco-service.de/rpc/v1';
// Enable services
window.EnderecoIntegrator.activeServices = {
ams: true,
emailService: true,
personService: true,
phs: true
};
}The function enderecoLoadAMSConfig is usually called at the end of bundle file ensuring both the bundle file was properly loaded and the Integrator exists. e.g.
const waitForConfig = setInterval(() => {
if (typeof enderecoLoadAMSConfig === 'function') {
enderecoLoadAMSConfig();
clearInterval(waitForConfig);
}
}, 10);- Bind to Form Fields:
enderecoInitAMS({
countryCode: '#country',
postalCode: '#zip',
locality: '#city',
streetName: '#street',
buildingNumber: '#house-number',
additionalInfo: '#apartment',
addressStatus: '[name=\"endereco-status\"]',
addressTimestamp: '[name=\"endereco-timestamp\"]',
addressPredictions: '[name=\"endereco-predictions\"]'
}, {
name: 'billing_address',
addressType: 'billing_address'
});npm run build- Complete production build including styles and assetsnpm run build-styles- Compile SCSS themes and copy to distributionnpm run demo- Start development servernpm run copy- Internal untility script to copy built JavaScript assets to demo foldernpm run copy-styles- Internal untility script to copy built CSS assets to demo folder
The demo environment provides real-time development with automatic browser refresh:
npm run demoThis command:
- Starts Express server on
localhost:8888 - Launches BrowserSync proxy on
localhost:3000 - Watches for changes in demo files
- Automatically reloads browser on file changes
The shopware 6 plugin repository contains a complete Shopware 6 plugin implementation demonstrating:
- Frontend integration with Twig templates
- Backend PHP service integration
- Webpack build configuration for e-commerce environments
- Multi-language support and customization
The demo/use-cases/ directory provides working examples:
example/- Comprehensive demonstration of all SDK featuresminiconfig/- Minimal configuration setuptest/- Testing scenarios and edge cases
Access examples via the demo server:
- Main demo:
http://localhost:8888/ - Example case:
http://localhost:8888/use-cases/example/
modules/integrator.js- Main integration interfacemodules/ams.js- Address validation servicemodules/emailservices.js- Email validation servicemodules/phoneservices.js- Phone validation servicemodules/personservices.js- Person data validationmodules/subscriber.js- Event handling system, used primarily for DOMElement to JavaScript object value synchronisation
Located in modules/extensions/fields/:
CountryCodeExtension.js- Country field handlingPostalCodeExtension.js- Postal code validationStreetNameExtension.js- Street name processingEmailExtension.js- Email field integration- And more for comprehensive form field support
SessionExtension.js- Session tracking for accounting
The SDK includes a flexible template system:
templates/- UI component templatesthemes/- SCSS styling themes
window.EnderecoIntegrator.config = {
apiKey: 'your-api-key',
apiUrl: 'your-proxy-endpoint',
remoteApiUrl: 'https://endereco-service.de/rpc/v1',
trigger: {
onblur: true, // Validate on field blur
onsubmit: true // Validate on form submit
},
ux: {
smartFill: true, // Auto-complete obvious matches
resumeSubmit: true, // Continue form submission after validation
useStandardCss: true, // Include default styling
allowCloseModal: true, // Allow modal dismissal
confirmWithCheckbox: true, // Require confirmation for corrections
changeFieldsOrder: true // Optimize field order for validation
}
};...and more. See the integration examples.
window.EnderecoIntegrator.activeServices = {
ams: true, // Address validation
emailService: true, // Email validation
personService: true, // Person data validation
phs: true // Phone validation
};- Button styling - Custom CSS classes for modal buttons to recreate the systems look-n-feel
- Text localization - Override all user-facing text with text coming from the host system
- Country/subdivision mapping - Custom country code handling with mapping tables from the host system
- Validation triggers - Configure when validation occurs
Initialize address validation for form fields.
Parameters:
selectors(Object) - CSS selectors for form fieldsconfig(Object) - Instance-specific configuration
Enable email validation for specified fields.
Activate phone number validation and formatting.
Enable person data validation (names, titles, salutations).
The SDK provides event hooks for custom integration:
- Form validation events
- Modal display events
- API response events
- User interaction events
Custom field value processing:
EnderecoIntegrator.resolvers.countryCodeRead = function(value) {
return Promise.resolve(countryMapping[value]);
};
EnderecoIntegrator.resolvers.countryCodeWrite = function(value) {
return Promise.resolve(reverseCountryMapping[value]);
};Those are needed to properly translate some host system values, like specific ID's of countries from a <select> element
to universally used country codes.
- Babel - ES6+ transpilation with preset-env
- Webpack - Module bundling and asset management
- SASS - CSS preprocessing with theme support
- Polyfills - Browser compatibility (classlist, custom-event, promise)
The build process:
- Transpiles modern JavaScript to browser-compatible code
- Bundles modules into single distribution file
- Processes SCSS themes to CSS
- Includes necessary polyfills
- Minifies output for production
- JavaScript bundles to
dist/endereco.min.js - CSS themes to
dist/endereco.min.css - Demo assets automatically updated via copy scripts
- Host integrations usually have its own webpack configurations, where paths are configured system specific
Access the demo environment to test integration scenarios:
- Start demo server:
npm run demo - Navigate to
localhost:3000 - Select use case to test
- Enter API key in provided field
- Test validation scenarios
The demo includes various test scenarios:
- Multiple address forms on single page
- Different validation triggers
- Custom styling applications
- Service combinations
We also sometimes symlink or just hard copy the file to one of the plugin, build it there and test manually in the context of a system integration, which helps find issues not visible in the demo integration (like problems with AJAX formulars in Shopware 6)
- GitHub Repository: https://github.com/Endereco/js-sdk
- Issue Tracking: https://github.com/Endereco/js-sdk/issues
- API Documentation: Available at endereco.de
- Technical Support: [email protected]
See CONTRIBUTING.md for development guidelines, coding standards, and pull request processes.