
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@amazon/local-function-proxy
Advanced tools
A TypeScript decorator library that enables seamless method call proxying between local and remote environments
@amazon/local-function-proxyA TypeScript decorator library that enables seamless method call proxying between local and proxy environments. Perfect for developers who want to avoid complex local environment setups by proxying specific method calls to a fully configured environment.
This library solves the common development challenge of needing a fully configured environment to test certain functionality. Instead of setting up complex dependencies locally, you can use this library to proxy specific method calls to a remote environment while keeping your local development simple.
Go to src/examples/express.ts to see ExpressJS based Example.
Or Go to src/examples/http.ts to see HTTP Server based Example.
To run locally follow below commands
# For ExpressJS based example
npm run example:express:start
# For HTTP Server based example
npm run example:http:start
There are multiple ways to configure the proxy behavior:
import { DevelopmentProxyInitializer, SecureConfigAdapter } from '@amazon/local-function-proxy';
const { DevelopmentProxy, callActualMethod, resultKey } = new DevelopmentProxyInitializer({
isProxyEnv: process.env.NODE_ENV === 'proxy',
isTestEnv: process.env.NODE_ENV === 'local',
resultKey: 'result',
targetHeaderKey: 'X-Proxy-Header', // Used for uniquely identifying actual method
useRuntimeProxyUrl: false,
proxyUrl: 'http://your-proxy-server.com/proxy', // Global Static proxy URL
secureConfig: SecureConfigAdapter.getPublicPrivateKeyPairSecureConfig(
privateKeyContent,
publicCertContent,
'X-Custom-Header' // Used for passing secure token
)
});
const { DevelopmentProxy, callActualMethod, resultKey } = new DevelopmentProxyInitializer({
isProxyEnv: process.env.NODE_ENV === 'proxy',
isTestEnv: process.env.NODE_ENV === 'local',
resultKey: 'result',
targetHeaderKey: 'X-Proxy-Header',
useRuntimeProxyUrl: true, // Enable dynamic proxy URL
secureConfig: SecureConfigAdapter.getPublicPrivateKeyPairSecureConfig(
privateKeyContent,
publicCertContent,
'X-Custom-Header'
)
});
import express from 'express';
import { HttpRouterAdapter } from '@amazon/roxy';
const app = express();
// Configure proxy router
app.use('/proxy', HttpRouterAdapter.getExpressJsRouter({
callActualMethod,
resultKey
}));
app.listen(3000, () => {
console.log('Proxy server running on port 3000');
});
The @DevelopmentProxy decorator accepts an optional configuration object:
interface ProxyConfig {
route?: string; // Custom route for method disambiguation, required when multiple non-static methods with same name exist
proxyUrl?: string; // Static proxy URL for this specific method (overrides global configuration)
timeout?: number; // Timeout in milliseconds for this method's proxy calls
}
Static Proxy URL (useRuntimeProxyUrl: false)
// Service class with proxied methods
class UserService {
// Static method with proxy by using proxy Url passed in global config
@DevelopmentProxy()
static async getUserCount(): Promise<number> {
// This will run in proxy environment
return await Database.getUserCount();
}
// Method-specific proxy URL and timeout
@DevelopmentProxy({
proxyUrl: 'http://user-service-proxy:3000/proxy',
timeout: 5000 // 5 seconds timeout
})
async getUserDetails(userId: string): Promise<UserDetails> {
// This will run in proxy environment
return await Database.getUserDetails(userId);
}
// Custom route with specific timeout
@DevelopmentProxy({
route: '/user/preferences',
timeout: 10000 // 10 seconds timeout
})
async getUserPreferences(userId: string): Promise<UserPreferences> {
// This will run in proxy environment
return await Database.getUserPreferences(userId);
}
}
// Usage
const count = await UserService.getUserCount();
const details = await new UserService().getUserDetails('user123');
const preference = await new UserService().getUserPreferences('user123');
Dynamic Proxy URL (useRuntimeProxyUrl: true)
class UserService {
@DevelopmentProxy()
static async getUserCount(proxyUrl: string): Promise<number> {
// This will run in proxy environment
return await Database.getUserCount();
}
@DevelopmentProxy()
async getUserDetails(proxyUrl: string, userId: string): Promise<UserDetails> {
// This will run in proxy environment
return await Database.getUserDetails(userId);
}
}
// Usage
const count = await UserService.getUserCount('http://proxy-server:3000/proxy');
const details = await new UserService().getUserDetails('http://proxy-server:3000/proxy', 'user123');
Custom Route Configuration with Dynamic Proxy URL
class PaymentService {
@DevelopmentProxy({ route: '/payment/process' })
async processPayment(proxyUrl: string, amount: number): Promise<PaymentResult> {
// This will run in proxy environment
return await PaymentGateway.process(amount);
}
}
// Usage
const paymentService = new PaymentService();
const result = await paymentService.processPayment('http://proxy-server:3000/proxy', 100);
The library provides robust security options to ensure your proxy communications are secure:
import fs from 'fs';
import path from 'path';
const secureConfig = SecureConfigAdapter.getPublicPrivateKeyPairSecureConfig(
fs.readFileSync(path.join(__dirname, 'private-key.pem'), 'utf8'),
fs.readFileSync(path.join(__dirname, 'public-cert.pem'), 'utf8'),
'X-Security-Header'
);
NODE_ENV=local
PROXY_URL=http://proxy-server.com/proxy
NODE_ENV=proxy
PORT=3000
| Option | Type | Description |
|---|---|---|
| isProxyEnv | boolean | Indicates if current environment is proxy |
| isTestEnv | boolean | Indicates if current environment is local/test |
| resultKey | string | Key used for method results in response |
| targetHeaderKey | string | Custom header for proxy identification |
| proxyUrl | string | URL of the proxy server |
| useRuntimeProxyUrl | boolean | Enable dynamic proxy URL as first parameter |
| secureConfig | SecurityConfig | SSL/TLS configuration |
The library provides built-in error handling mechanisms:
try {
const result = await userService.getUserDetails('user123');
} catch (error) {
// Error from proxy or actual method execution
console.error('Error occurred:', error);
}
You can configure timeouts globally or per method:
// Global timeout in initializer
const { DevelopmentProxy } = new DevelopmentProxyInitializer({
// ... other options
timeout: 30000, // 30 seconds global timeout
});
// Method-specific timeout
@DevelopmentProxy({ timeout: 5000 }) // 5 seconds timeout for this method
async getUserProfile(userId: string): Promise<UserProfile> {
// Method implementation
}
To run the test suite:
npm test
This will execute all tests and generate coverage reports. The library aims to maintain high test coverage to ensure reliability.
To check for lint issues:
npm run lint:ci
To automatically fix lint issues where possible:
npm run lint
npm install @amazon/local-function-proxy
See CONTRIBUTING for more information.
This project is licensed under the Apache-2.0 License.
FAQs
A TypeScript decorator library that enables seamless method call proxying between local and remote environments
We found that @amazon/local-function-proxy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.