@nexuss0781/envx-sdk
v0.1.0
Published
Typed TypeScript client for the ENVX project, environment, and API-key REST API.
Maintainers
Readme
@nexuss0781/envx-sdk
@nexuss0781/envx-sdk is a typed ESM client for the ENVX authenticated REST API. It is a separate library from the envx command-line package; it does not wrap or launch CLI commands.
Install
Install the SDK with:
npm install @nexuss0781/envx-sdkThe package can be built locally from this directory with npm test (TypeScript build, consumer type-check, and HTTP-mocked tests).
Create a client
The ENVX API authenticates requests with a Supabase user access token. Supply the token from your own Supabase Auth session; the SDK does not sign users in, persist tokens, refresh them, or include credentials in a URL. In the example, supabase is your application's configured Supabase client.
import { EnvxClient } from '@nexuss0781/envx-sdk';
const client = new EnvxClient({
apiUrl: process.env.ENVX_API_URL!,
// Read the current session token when each request is made.
accessToken: async () => {
const { data, error } = await supabase.auth.getSession();
if (error || !data.session) throw new Error('Sign in to ENVX first.');
return data.session.access_token;
},
});
const projects = await client.listProjects();
const project = await client.createProject({ name: 'storefront', description: 'Commerce API' });
const environments = await client.listEnvironments(project.id);
const matches = await client.searchApiKeys('PAYMENT', { environmentId: environments[0]?.id });Avoid hardcoding an access token in source code. Use a session/token provider appropriate to your runtime, and pass the server's public ENVX origin as apiUrl (for example https://envx-lemon.vercel.app). The deployment must have Supabase and the server-only encryption key configured before authenticated operations or secret writes can succeed.
Supported methods
- Projects:
listProjects,getProject,createProject,updateProject,deleteProject. - Environments:
listEnvironments,createEnvironment,updateEnvironment,deleteEnvironment. - API keys:
searchApiKeys,createApiKey,updateApiKey,deleteApiKey,revealApiKey.
Deletes require an explicit { confirm: true } argument in the SDK. Project deletion cascades to its environments and keys; environment deletion cascades to its keys. Label search returns metadata only (up to the API's 500-result limit); it never returns secret values. revealApiKey fetches one value on demand with cache: 'no-store' and returns it to the caller. The SDK does not cache or log that value, so handle it carefully in your application.
Errors are exposed as EnvxError, which includes an HTTP status and a safe message from the API response. Provide an updated token through the access-token callback after a 401; the SDK intentionally leaves authentication/session lifecycle to your app.
