{"_id":"@amazon/local-function-proxy","_rev":"2-2bab9897be75ea85e6a0d40b9826e66a","name":"@amazon/local-function-proxy","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@amazon/local-function-proxy","version":"0.1.0","keywords":["typescript","decorator","proxy","function-proxy","method-proxy","local-development","remote-execution","development-tools","testing"],"author":{"name":"Harsh Singhal","email":"https://github.com/Harsh0/"},"license":"Apache-2.0","_id":"@amazon/local-function-proxy@0.1.0","maintainers":[{"name":"harsh0","email":"harsh.singhal040@gmail.com"}],"homepage":"https://github.com/local-function-proxy/local-function-proxy#readme","bugs":{"url":"https://github.com/local-function-proxy/local-function-proxy/issues"},"dist":{"shasum":"9c50464a4bc443d0824992e3dbf1e8bc349d53b1","tarball":"https://registry.npmjs.org/@amazon/local-function-proxy/-/local-function-proxy-0.1.0.tgz","fileCount":39,"integrity":"sha512-tpqfA/GwZeGvQymTqSiSZ+hWLT9gnB8Aymvd0w0leZ8ot3GvaJYEQy2mdtFCzbCZmzAWHx5iuqBvxOz9jTq3BA==","signatures":[{"sig":"MEYCIQD7S60HcEO/MVOc8ZQgCDmDZ3DktGFKCp8RaFADWdG5xQIhAJgJe6YdGTTxk/0Tj0R0Jm3LDFVCobz5aEQF6T0oPcjh","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":111437},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"npm":">=8","node":">=18"},"gitHead":"81fd6fc2d90ab34f24cd80e2813ecae3b301e44c","scripts":{"lint":"eslint \"src/**/*.ts\" --fix","test":"jest --collectCoverage --collectCoverageFrom=src/**/*.{ts,js}","build":"tsc -p tsconfig.build.json && npm run test","clean":"rm -rf dist","watch":"tsc -p tsconfig.build.json -w","format":"prettier --write \"src/**/*.{ts,js,json,md}\"","lint:ci":"eslint \"src/**/*.ts\"","prebuild":"npm run clean && npm run lint:ci && npm run format:ci","format:ci":"prettier --check \"src/**/*.{ts,js,json,md}\"","prepublishOnly":"npm run build","example:http:start":"npm run example:generatePrivatePublicKeyPair && npm run example:http:proxy:start & npm run example:http:local:start","example:local:start":"PORT=3000 NODE_ENV=local ts-node --files src/examples/$EXAMPLE_APP.ts","example:proxy:start":"PORT=8080 NODE_ENV=proxy ts-node --files src/examples/$EXAMPLE_APP.ts","example:express:start":"npm run example:generatePrivatePublicKeyPair && npm run example:express:proxy:start & npm run example:express:local:start","example:http:local:start":"EXAMPLE_APP=http npm run example:local:start","example:http:proxy:start":"EXAMPLE_APP=http npm run example:proxy:start","example:express:local:start":"EXAMPLE_APP=express npm run example:local:start","example:express:proxy:start":"EXAMPLE_APP=express npm run example:proxy:start","example:generatePrivatePublicKeyPair":"PORT=8080 NODE_ENV=proxy ts-node --files src/examples/utils/generatePrivatePublicKeyPair.ts"},"_npmUser":{"name":"harsh0","email":"harsh.singhal040@gmail.com"},"repository":{"url":"git+https://github.com/local-function-proxy/local-function-proxy.git","type":"git"},"_npmVersion":"10.7.0","description":"A TypeScript decorator library that enables seamless method call proxying between local and remote environments","directories":{},"_nodeVersion":"20.15.0","dependencies":{"axios":"^1.8.4","http-status-codes":"^2.3.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","eslint":"^9.28.0","ts-jest":"^29.3.4","ts-node":"^10.9.2","supertest":"7.1.1","typescript":"^5.8.3","@types/jest":"^29.5.14","@types/node":"^22.15.29","@types/express":"^4.17.22","@types/supertest":"6.0.3","eslint-config-prettier":"^10.1.2","eslint-plugin-prettier":"^5.4.1","@typescript-eslint/eslint-plugin":"^8.33.1"},"peerDependencies":{"express":"^4.0.0 <5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/local-function-proxy_0.1.0_1749186598970_0.3612439914068817","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@amazon/local-function-proxy","version":"0.1.1","description":"A TypeScript decorator library that enables seamless method call proxying between local and remote environments","main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=18","npm":">=8"},"scripts":{"prebuild":"npm run clean && npm run lint:ci && npm run format:ci","clean":"rm -rf dist","build":"tsc -p tsconfig.build.json && npm run test","watch":"tsc -p tsconfig.build.json -w","prepublishOnly":"npm run build","lint:ci":"eslint \"src/**/*.ts\"","lint":"eslint \"src/**/*.ts\" --fix","format:ci":"prettier --check \"src/**/*.{ts,js,json,md}\"","format":"prettier --write \"src/**/*.{ts,js,json,md}\"","example:express:start":"npm run example:generatePrivatePublicKeyPair && npm run example:express:proxy:start & npm run example:express:local:start","example:http:start":"npm run example:generatePrivatePublicKeyPair && npm run example:http:proxy:start & npm run example:http:local:start","example:generatePrivatePublicKeyPair":"PORT=8080 NODE_ENV=proxy ts-node --files src/examples/utils/generatePrivatePublicKeyPair.ts","example:http:proxy:start":"EXAMPLE_APP=http npm run example:proxy:start","example:http:local:start":"EXAMPLE_APP=http npm run example:local:start","example:express:proxy:start":"EXAMPLE_APP=express npm run example:proxy:start","example:express:local:start":"EXAMPLE_APP=express npm run example:local:start","example:proxy:start":"PORT=8080 NODE_ENV=proxy ts-node --files src/examples/$EXAMPLE_APP.ts","example:local:start":"PORT=3000 NODE_ENV=local ts-node --files src/examples/$EXAMPLE_APP.ts","test":"jest --collectCoverage --collectCoverageFrom=src/**/*.{ts,js}"},"repository":{"type":"git","url":"git+https://github.com/amazonmusic/local-function-proxy.git"},"keywords":["typescript","decorator","proxy","function-proxy","method-proxy","local-development","remote-execution","development-tools","testing"],"author":{"name":"Harsh Singhal","email":"https://github.com/Harsh0/"},"license":"Apache-2.0","bugs":{"url":"https://github.com/amazonmusic/local-function-proxy/issues"},"homepage":"https://github.com/amazonmusic/local-function-proxy#readme","devDependencies":{"@types/express":"^4.17.22","@types/jest":"^29.5.14","@types/node":"^22.15.29","@types/supertest":"6.0.3","@typescript-eslint/eslint-plugin":"^8.33.1","eslint":"^9.28.0","eslint-config-prettier":"^10.1.2","eslint-plugin-prettier":"^5.4.1","jest":"^29.7.0","supertest":"7.1.1","ts-jest":"^29.3.4","ts-node":"^10.9.2","typescript":"^5.8.3"},"dependencies":{"axios":"^1.8.4","http-status-codes":"^2.3.0"},"peerDependencies":{"express":"^4.0.0 <5.0.0"},"_id":"@amazon/local-function-proxy@0.1.1","gitHead":"aa6ace67b20b4467e96ea718de5a6542e6f3b76d","_nodeVersion":"20.15.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-l6mrgB6Kb9llJNO6tE3SWzklNixht6653fIpt1qnVxAtCQh4vLI58TngfMPleAR3nGqoth1XBfmoYPZdB0f+Vg==","shasum":"8fed2666da3acc34d931abff3d18b963d1874e01","tarball":"https://registry.npmjs.org/@amazon/local-function-proxy/-/local-function-proxy-0.1.1.tgz","fileCount":39,"unpackedSize":111408,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIF6/MqH9OPvN15JH2R8plAz3YW6+gaTRaL/AGS7a1ST3AiB4JJe3TFnKxkyIfQt5Emu8mTfDVjwPokTrJhtmn8nIQg=="}]},"_npmUser":{"name":"harsh0","email":"harsh.singhal040@gmail.com"},"directories":{},"maintainers":[{"name":"harsh0","email":"harsh.singhal040@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/local-function-proxy_0.1.1_1749188282004_0.7016477200745601"},"_hasShrinkwrap":false}},"time":{"created":"2025-06-06T05:09:58.509Z","modified":"2025-06-06T05:38:02.361Z","0.1.0":"2025-06-06T05:09:59.188Z","0.1.1":"2025-06-06T05:38:02.191Z"},"bugs":{"url":"https://github.com/amazonmusic/local-function-proxy/issues"},"author":{"name":"Harsh Singhal","email":"https://github.com/Harsh0/"},"license":"Apache-2.0","homepage":"https://github.com/amazonmusic/local-function-proxy#readme","keywords":["typescript","decorator","proxy","function-proxy","method-proxy","local-development","remote-execution","development-tools","testing"],"repository":{"type":"git","url":"git+https://github.com/amazonmusic/local-function-proxy.git"},"description":"A TypeScript decorator library that enables seamless method call proxying between local and remote environments","maintainers":[{"name":"harsh0","email":"harsh.singhal040@gmail.com"}],"readme":"# Local Function Proxy - `@amazon/local-function-proxy`\n\nA 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.\n\n## 📋 Overview\n\nThis 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.\n\n## 🌟 Features\n\n- 🚀 Proxy method calls from local to remote environment\n- 🔒 Secure communication with SSL/TLS\n- 🎯 Support for both static and instance methods\n- 🛠️ Custom route configuration\n- ⚡ Express.js integration\n- 📘 Full TypeScript support\n- 🔄 Automatic request/response handling\n- 🌐 Dynamic and static proxy URL support\n- ⏱️ Configurable timeout per method\n\n## 📘 Quick Example\n\nGo to [`src/examples/express.ts`](src/examples/express.ts) to see ExpressJS based Example.\n\nOr Go to [`src/examples/http.ts`](src/examples/http.ts) to see HTTP Server based Example.\n\nTo run locally follow below commands\n\n```sh\n# For ExpressJS based example\nnpm run example:express:start\n\n# For HTTP Server based example\nnpm run example:http:start\n```\n\n## 🔧 Basic Setup\n\n### 1. Initialize the Proxy Decorator\n\nThere are multiple ways to configure the proxy behavior:\n\n#### Global Configuration with Static Proxy URL Configuration\n```ts\nimport { DevelopmentProxyInitializer, SecureConfigAdapter } from '@amazon/local-function-proxy';\n\nconst { DevelopmentProxy, callActualMethod, resultKey } = new DevelopmentProxyInitializer({\n    isProxyEnv: process.env.NODE_ENV === 'proxy',\n    isTestEnv: process.env.NODE_ENV === 'local',\n    resultKey: 'result',\n    targetHeaderKey: 'X-Proxy-Header', // Used for uniquely identifying actual method\n    useRuntimeProxyUrl: false,\n    proxyUrl: 'http://your-proxy-server.com/proxy', // Global Static proxy URL\n    secureConfig: SecureConfigAdapter.getPublicPrivateKeyPairSecureConfig(\n        privateKeyContent,\n        publicCertContent,\n        'X-Custom-Header' // Used for passing secure token\n    )\n});\n```\n#### Dynamic Proxy URL Configuration\n```ts\nconst { DevelopmentProxy, callActualMethod, resultKey } = new DevelopmentProxyInitializer({\n    isProxyEnv: process.env.NODE_ENV === 'proxy',\n    isTestEnv: process.env.NODE_ENV === 'local',\n    resultKey: 'result',\n    targetHeaderKey: 'X-Proxy-Header',\n    useRuntimeProxyUrl: true,  // Enable dynamic proxy URL\n    secureConfig: SecureConfigAdapter.getPublicPrivateKeyPairSecureConfig(\n        privateKeyContent,\n        publicCertContent,\n        'X-Custom-Header'\n    )\n});\n```\n### 2. Set Up Express Server (Proxy Environment)\n```ts\nimport express from 'express';\nimport { HttpRouterAdapter } from '@amazon/roxy';\n\nconst app = express();\n\n// Configure proxy router\napp.use('/proxy', HttpRouterAdapter.getExpressJsRouter({ \n    callActualMethod, \n    resultKey \n}));\n\napp.listen(3000, () => {\n    console.log('Proxy server running on port 3000');\n});\n```\n\n## 💡 Usage Examples\nThe @DevelopmentProxy decorator accepts an optional configuration object:\n```ts\ninterface ProxyConfig {\n    route?: string;      // Custom route for method disambiguation, required when multiple non-static methods with same name exist\n    proxyUrl?: string;   // Static proxy URL for this specific method (overrides global configuration)\n    timeout?: number;    // Timeout in milliseconds for this method's proxy calls\n}\n```\n\nStatic Proxy URL (useRuntimeProxyUrl: false)\n```ts\n// Service class with proxied methods\nclass UserService {\n    // Static method with proxy by using proxy Url passed in global config\n    @DevelopmentProxy()\n    static async getUserCount(): Promise<number> {\n        // This will run in proxy environment\n        return await Database.getUserCount();\n    }\n\n    // Method-specific proxy URL and timeout\n    @DevelopmentProxy({\n        proxyUrl: 'http://user-service-proxy:3000/proxy',\n        timeout: 5000  // 5 seconds timeout\n    })\n    async getUserDetails(userId: string): Promise<UserDetails> {\n        // This will run in proxy environment\n        return await Database.getUserDetails(userId);\n    }\n\n    // Custom route with specific timeout\n    @DevelopmentProxy({\n        route: '/user/preferences',\n        timeout: 10000  // 10 seconds timeout\n    })\n    async getUserPreferences(userId: string): Promise<UserPreferences> {\n        // This will run in proxy environment\n        return await Database.getUserPreferences(userId);\n    }\n}\n\n// Usage\nconst count = await UserService.getUserCount();\nconst details = await new UserService().getUserDetails('user123');\nconst preference = await new UserService().getUserPreferences('user123');\n```\nDynamic Proxy URL (useRuntimeProxyUrl: true)\n```ts\nclass UserService {\n    @DevelopmentProxy()\n    static async getUserCount(proxyUrl: string): Promise<number> {\n        // This will run in proxy environment\n        return await Database.getUserCount();\n    }\n\n    @DevelopmentProxy()\n    async getUserDetails(proxyUrl: string, userId: string): Promise<UserDetails> {\n        // This will run in proxy environment\n        return await Database.getUserDetails(userId);\n    }\n}\n\n// Usage\nconst count = await UserService.getUserCount('http://proxy-server:3000/proxy');\nconst details = await new UserService().getUserDetails('http://proxy-server:3000/proxy', 'user123');\n\n```\n\nCustom Route Configuration with Dynamic Proxy URL\n```ts\nclass PaymentService {\n    @DevelopmentProxy({ route: '/payment/process' })\n    async processPayment(proxyUrl: string, amount: number): Promise<PaymentResult> {\n        // This will run in proxy environment\n        return await PaymentGateway.process(amount);\n    }\n}\n\n// Usage\nconst paymentService = new PaymentService();\nconst result = await paymentService.processPayment('http://proxy-server:3000/proxy', 100);\n```\n\n## 🔐 Security Configuration\n\nThe library provides robust security options to ensure your proxy communications are secure:\n\n### Setting up SSL/TLS\n```ts\nimport fs from 'fs';\nimport path from 'path';\n\nconst secureConfig = SecureConfigAdapter.getPublicPrivateKeyPairSecureConfig(\n    fs.readFileSync(path.join(__dirname, 'private-key.pem'), 'utf8'),\n    fs.readFileSync(path.join(__dirname, 'public-cert.pem'), 'utf8'),\n    'X-Security-Header'\n);\n```\n\n## 🌍 Environment Configuration\n\n### Local Environment (.env.local)\n```sh\nNODE_ENV=local\nPROXY_URL=http://proxy-server.com/proxy\n```\n\n### Proxy Environment (.env.proxy)\n```sh\nNODE_ENV=proxy\nPORT=3000\n```\n\n## ⚙️ Configuration Options\n\n| Option | Type | Description |\n|--------|------|-------------|\n| isProxyEnv | boolean | Indicates if current environment is proxy |\n| isTestEnv | boolean | Indicates if current environment is local/test |\n| resultKey | string | Key used for method results in response |\n| targetHeaderKey | string | Custom header for proxy identification |\n| proxyUrl | string | URL of the proxy server |\n| useRuntimeProxyUrl | boolean | Enable dynamic proxy URL as first parameter |\n| secureConfig | SecurityConfig | SSL/TLS configuration |\n\n### Error Handling\n\nThe library provides built-in error handling mechanisms:\n\n```ts\ntry {\n  const result = await userService.getUserDetails('user123');\n} catch (error) {\n  // Error from proxy or actual method execution\n  console.error('Error occurred:', error);\n}\n```\n\n### Timeout Configuration\n\nYou can configure timeouts globally or per method:\n\n```ts\n// Global timeout in initializer\nconst { DevelopmentProxy } = new DevelopmentProxyInitializer({\n  // ... other options\n  timeout: 30000, // 30 seconds global timeout\n});\n\n// Method-specific timeout\n@DevelopmentProxy({ timeout: 5000 }) // 5 seconds timeout for this method\nasync getUserProfile(userId: string): Promise<UserProfile> {\n  // Method implementation\n}\n```\n\n## 🧪 Testing\n\nTo run the test suite:\n\n```sh\nnpm test\n```\n\nThis will execute all tests and generate coverage reports. The library aims to maintain high test coverage to ensure reliability.\n\n## 🔍 Linting\n\nTo check for lint issues:\n\n```sh\nnpm run lint:ci\n```\n\nTo automatically fix lint issues where possible:\n\n```sh\nnpm run lint\n```\n\n## 📦 Installation\n\n```sh\nnpm install @amazon/local-function-proxy\n```\n\n## 🛡️ Security\n\nSee [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.\n\n## 🔖 License\n\nThis project is licensed under the Apache-2.0 License.\n\n","readmeFilename":"README.md"}