cf-bindings-proxy
Advanced tools
Comparing version 0.2.8-18a25d1 to 0.2.8-918bb55
@@ -9,6 +9,17 @@ /** | ||
* | ||
* @example | ||
* By default, `process.env` is used in production, however, a custom fallback can be provided. | ||
* ```ts | ||
* const MY_KV = binding<KVNamespace>('MY_KV', { fallback: platform.env }); | ||
* ``` | ||
* | ||
* @param id Binding ID. | ||
* @param opts Binding options, such as a custom fallback. | ||
* @returns Binding value. | ||
*/ | ||
export declare const binding: <T>(id: string) => T; | ||
export declare const binding: <T>(id: string, opts?: BindingOpts) => T; | ||
type BindingOpts = { | ||
fallback: Record<string, unknown>; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
19
index.js
@@ -1,12 +0,15 @@ | ||
import { createBindingProxy as n } from "./proxy.js"; | ||
import { createBindingProxy as _ } from "./proxy.js"; | ||
import "./transform.js"; | ||
const p = (e) => process.env.ENABLE_BINDINGS_PROXY || !process.env.DISABLE_BINDINGS_PROXY && process.env.NODE_ENV === "development" ? new Proxy( | ||
{}, | ||
{ | ||
get: (o, r) => n(e)[r] | ||
} | ||
) : process.env[e]; | ||
const B = (r, e) => { | ||
var n, o, c, N; | ||
return (n = process == null ? void 0 : process.env) != null && n.ENABLE_BINDINGS_PROXY || !((o = process == null ? void 0 : process.env) != null && o.DISABLE_BINDINGS_PROXY) && ((c = process == null ? void 0 : process.env) == null ? void 0 : c.NODE_ENV) === "development" ? new Proxy( | ||
{}, | ||
{ | ||
get: (s, i) => _(r)[i] | ||
} | ||
) : (N = (e == null ? void 0 : e.fallback) ?? (process == null ? void 0 : process.env)) == null ? void 0 : N[r]; | ||
}; | ||
export { | ||
p as binding | ||
B as binding | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "cf-bindings-proxy", | ||
"version": "0.2.8-18a25d1", | ||
"version": "0.2.8-918bb55", | ||
"description": "Experimental proxy for interfacing with bindings in projects targeting Cloudflare Pages", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -48,2 +48,10 @@ <p align="center"> | ||
It is also possible to specify a custom fallback for use in production instead of `process.env`. | ||
```ts | ||
import { binding } from 'cf-bindings-proxy'; | ||
const value = await binding<KVNamespace>('MY_KV', { fallback: platform.env }).get('key'); | ||
``` | ||
## How It Works | ||
@@ -55,3 +63,3 @@ | ||
When building for production, `binding('BINDING_NAME')` simply calls `process.env.BINDING_NAME` to retrieve the binding instead. | ||
When building for production, `binding('BINDING_NAME')` simply calls `process.env.BINDING_NAME` to retrieve the binding instead. If you wish to use a custom fallback like `platform.env` instead of `process.env`, you can pass a custom fallback to the binding call with `binding('BINDING_NAME', { fallback: platform.env })`. | ||
@@ -58,0 +66,0 @@ ### When It's Active |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
58695
278
115
4