Skip to content
EANVI

Docs

SDK usage

Practical examples for secrets, CLI sync helpers, and error handling.

SDK usage

Create a client

import { createClient } from '@eanvi/sdk';

const client = createClient({
  apiKey: process.env.EANVI_API_KEY!,
});

List and reveal secrets

const secrets = await client.secrets.list('my-app', 'production', organizationId, {
  search: 'STRIPE',
  tags: ['payments'],
});

for (const secret of secrets) {
  console.log(secret.key, secret.maskedValue);
}

const full = await client.secrets.reveal(secrets[0]!.id, organizationId);
console.log(full.value);

Create and update

await client.secrets.create(
  'my-app',
  'development',
  {
    key: 'REDIS_URL',
    value: 'redis://localhost:6379',
    tags: ['cache'],
  },
  organizationId
);

await client.secrets.update(secretId, { value: 'redis://cache:6379' }, organizationId);

Pull decrypted map (CLI helper)

const result = await client.cli.pull({
  project: 'my-app',
  environment: 'production',
  organization: 'acme',
});

// result.secrets is a key/value map suitable for writing a .env file

Push / sync / diff

await client.cli.push({
  project: 'my-app',
  environment: 'development',
  secrets: { DATABASE_URL: 'postgres://...' },
  dryRun: true,
});

await client.cli.diff({
  project: 'my-app',
  environment: 'development',
  secrets: { DATABASE_URL: 'postgres://local' },
});

Import and export

await client.secrets.previewImport('my-app', 'development', envFileContents, 'env');
await client.secrets.import(
  'my-app',
  'development',
  { content: envFileContents, format: 'env' },
  organizationId
);

const exported = await client.secrets.export('my-app', 'development', {
  format: 'yaml',
  tags: ['database'],
});

Versions

const versions = await client.secrets.getVersions(secretId);
await client.secrets.restoreVersion(secretId, versions[1]!.version);
const diff = await client.secrets.compareVersions(secretId, 1, 2);

Error handling

import { createClient, EanviError } from '@eanvi/sdk';

try {
  await client.secrets.reveal(id);
} catch (err: unknown) {
  if (err instanceof EanviError) {
    console.error(err.statusCode, err.code, err.message);
  }
  throw err;
}