From dcd513c1e72556ac077e675538254c1579c71ea7 Mon Sep 17 00:00:00 2001 From: Daniel Rochetti Date: Sun, 8 Oct 2023 03:01:24 -0700 Subject: [PATCH] fix: proxy lib exports (#15) * fix: update proxy package config * fix: proxy lib exports at last --- libs/proxy/README.md | 2 +- libs/proxy/package.json | 14 +++++++++++++- libs/proxy/src/index.ts | 9 ++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libs/proxy/README.md b/libs/proxy/README.md index ce9635d..a8fd5d0 100644 --- a/libs/proxy/README.md +++ b/libs/proxy/README.md @@ -29,7 +29,7 @@ For Express applications: ```ts app.use(express.json()); ``` -2. Add the proxy route and its handler. Note that if your client lives outside of the express app (i.e. the express app is solely used as an external API for other clients), your will need to allow CORS on the proxy route: +2. Add the proxy route and its handler. Note that if your client lives outside of the express app (i.e. the express app is solely used as an external API for other clients), you will need to allow CORS on the proxy route: ```ts import * as falProxy from '@fal-ai/serverless-proxy/express'; diff --git a/libs/proxy/package.json b/libs/proxy/package.json index 5b5719c..121184e 100644 --- a/libs/proxy/package.json +++ b/libs/proxy/package.json @@ -1,6 +1,6 @@ { "name": "@fal-ai/serverless-proxy", - "version": "0.3.0", + "version": "0.3.3", "license": "MIT", "repository": { "type": "git", @@ -21,6 +21,18 @@ "./express": "./src/express.js", "./nextjs": "./src/nextjs.js" }, + "typesVersions": { + "*": { + "express": [ + "src/express.d.ts" + ], + "nextjs": [ + "src/nextjs.d.ts" + ] + } + }, + "main": "./src/index.js", + "types": "./src/index.d.ts", "peerDependencies": { "express": "^4.0.0", "next": "^13.0.0", diff --git a/libs/proxy/src/index.ts b/libs/proxy/src/index.ts index 01a2c42..901f02c 100644 --- a/libs/proxy/src/index.ts +++ b/libs/proxy/src/index.ts @@ -7,6 +7,10 @@ const FAL_KEY_ID = process.env.FAL_KEY_ID || process.env.NEXT_PUBLIC_FAL_KEY_ID; const FAL_KEY_SECRET = process.env.FAL_KEY_SECRET || process.env.NEXT_PUBLIC_FAL_KEY_SECRET; +/** + * The proxy behavior that is passed to the proxy handler. This is a subset of + * request objects that are used by different frameworks, like Express and NextJS. + */ export interface ProxyBehavior { id: string; method: string; @@ -59,13 +63,12 @@ function getFalKey(): string | undefined { } /** - * A Next request handler that proxies the request to the fal-serverless + * A request handler that proxies the request to the fal-serverless * endpoint. This is useful so client-side calls to the fal-serverless endpoint * can be made without CORS issues and the correct credentials can be added * effortlessly. * - * @param request the Next request object. - * @param response the Next response object. + * @param behavior the request proxy behavior. * @returns Promise the promise that will be resolved once the request is done. */ export const handleRequest = async (behavior: ProxyBehavior) => {