lp-helper-scripts
v2.1.14
Published
A multi-tenant API library for landing pages, supporting multiple backend systems with a unified frontend interface.
Downloads
573
Readme
LP Helper Scripts
A multi-tenant API library for landing pages, supporting multiple backend systems with a unified frontend interface.
Installation
Authenticate against Gitlab NPM Repo
npm config set -- '//gitlab.com/api/v4/projects/38774892/packages/npm/:_authToken' "#auth-token#"
npm config set lp-helper-scripts:registry https://gitlab.com/api/v4/projects/38774892/packages/npm/Install the package
npm install lp-helper-scripts
# or
yarn add lp-helper-scriptsMulti-Tenant Architecture
This library implements a multi-tenant architecture that allows the same frontend code to work with different backend systems. Currently supported backends:
- backend1: Original implementation (default)
- backend2: Liebeskontakte API implementation
Why Multi-Tenant?
The multi-tenant design allows:
- Single codebase for multiple backend systems
- Easy switching between backends via configuration
- Consistent API interface regardless of backend
- Field mapping and data transformation handled internally
- No frontend code changes required when switching backends
Usage
Configuration
Configure the API once at the start of your application:
import { configureApi } from 'lp-helper-scripts';
// For backend1 (original implementation)
configureApi({
type: 'backend1',
baseUrl: 'https://your-api.example.com' // optional, uses window settings by default
});
// For backend2 (Liebeskontakte)
configureApi({
type: 'backend2',
baseUrl: 'https://dev.user-api.liebeskontakte.de', // optional
apiToken: 'your-x-landing-token-here' // required for authentication
});API Functions
After configuration, use the same API functions regardless of the backend:
import {
registerUser,
validateEmail,
validateUsername,
loginUser,
getNewPassword,
resendActivationEmail,
getLocationAutocompleteData
} from 'lp-helper-scripts';
// Register a new user
const result = await registerUser({
username: 'johndoe',
email: '[email protected]',
password: 'SecurePass123',
gender: 'man',
lookingfor: 'woman',
birthday: { age: 25 },
location: {
country: 'DE',
city: 'Berlin'
}
});
// Validate email availability
const emailValid = await validateEmail('[email protected]');
// Validate username availability
const usernameValid = await validateUsername('johndoe');
// Login user
const loginResult = await loginUser({
email: '[email protected]',
password: 'SecurePass123'
});
// Request password reset
const resetResult = await getNewPassword('[email protected]');
// Resend activation email
const resendResult = await resendActivationEmail('[email protected]');
// Get location autocomplete suggestions
const locations = await getLocationAutocompleteData('Berlin');Backend-Specific Notes
Backend1 (Original)
- Uses URL parameters for GET requests
- Requires PID from window settings
- Returns redirect URLs in response
Backend2 (Liebeskontakte)
- Uses JSON POST requests for all endpoints
- Requires X-Landing-Token header for authentication
- Automatic field mapping:
- Gender:
"woman"/"man"→0/1 - Country codes:
"DE"→"0","AT"→"1", etc.
- Gender:
- Supports both standard and OCR registration flows
- Returns platform URLs for redirects
Getting the X-Landing-Token
For backend2 (Liebeskontakte), you need to obtain an API token:
- Contact Liebeskontakte support for API access
- Request your X-Landing-Token
- Configure the API with your token
Field Mapping
The library automatically handles field mapping between different backend formats:
| Frontend Format | Backend1 | Backend2 (Liebeskontakte) | |----------------|----------|---------------------------| | gender: "woman" | "2" | 0 | | gender: "man" | "1" | 1 | | country: "DE" | "DE" | "0" | | country: "AT" | "AT" | "1" | | country: "CH" | "CH" | "2" |
Error Handling
All API functions return a consistent response format:
interface DefaultReturnType {
message: string; // Success or error message
passed: boolean; // True if successful, false otherwise
}Development
Building
yarn buildTesting
yarn testProject Structure
src/Api/
├── PublicApi.ts # Public API interface
├── config.ts # Configuration management
├── router.ts # Backend routing logic
├── types.ts # TypeScript type definitions
├── backend1/ # Backend1 implementation
│ ├── registerUser.ts
│ ├── validateUserData.ts
│ └── ...
└── backend2/ # Backend2 (Liebeskontakte) implementation
├── registerUser.ts
├── validateUserData.ts
└── ...License
MIT
