New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@infisical/sdk

Package Overview
Dependencies
Maintainers
3
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@infisical/sdk

README.md

  • 1.0.24
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.6K
decreased by-21.93%
Maintainers
3
Weekly downloads
 
Created
Source

infisical

Open-source, end-to-end encrypted tool to manage secrets and configs across your team and infrastructure.

Table of Contents

Basic Usage

import express from "express";

import { InfisicalClient, LogLevel } from "@infisical/sdk";

const app = express();

const PORT = 3000;

const client = new InfisicalClient({
    clientId: "YOUR_CLIENT_ID",
    clientSecret: "YOUR_CLIENT_SECRET",
    logLevel: LogLevel.Error
});

app.get("/", async (req, res) => {
    // access value

    const name = await client.getSecret({
        environment: "dev",
        projectId: "656dba7f979ebd6652586669",
        path: "/",
        type: "shared",
        secretName: "NAME"
    });

    res.send(`Hello! My name is: ${name.secretValue}`);
});

app.listen(PORT, async () => {
    // initialize client

    console.log(`App listening on port ${port}`);
});

Installation

$ npm install @infisical/sdk

Configuration

Import the SDK and create a client instance with your Machine Identity.

const { InfisicalClient, LogLevel } = require("@infisical/sdk");

const client = new InfisicalClient({
    clientId: "YOUR_CLIENT_ID",
    clientSecret: "YOUR_CLIENT_SECRET",
    logLevel: LogLevel.Error
});

Using ES6:

import { InfisicalClient } from "@infisical/sdk";

const client = new InfisicalClient({
    clientId: "YOUR_CLIENT_ID",
    clientSecret: "YOUR_CLIENT_SECRET",
    logLevel: LogLevel.Error
});

// your app logic

Options

We currently provide two ways to authenticate using Machine Identities. Either provide a direct access token that you can obtain from the authentication API, or provide your Machine Identity Client ID and client secret.

ParameterTypeDescription
clientIdstringYour machine identity client ID.
clientSecretstringYour machine identity client secret.
accessTokenstring (optional)An access token obtained from the machine identity login endpoint.
siteUrlstring (optional)Your self-hosted Infisical site URL. Default: https://app.infisical.com.
logLevelenum (optional)The level of logs you wish to log The logs are derived from Rust, as we have written our base SDK in Rust. Default: Error.

Secrets

Get Secrets

const secrets = await client.listSecrets({
    environment: "dev",
    projectId: "656dba7f979ebd6652586669",
    path: "/foo/bar/",
    includeImports: false
});

Retrieve all secrets within a given environment and folder path. The service token used must have access to the given path and environment.

Options

ParameterTypeDescription
environmentstringThe slug name (dev, prod, etc) of the environment from where secrets should be fetched from.
projectIdstringThe project ID where the secret lives in.
secretNamestringThe name of the secret you want to get.
pathstring (optional)The path from where secrets should be fetched from.
includeImportsboolean, (optional)Whether or not to include imported secrets from the current path. Read about secret import.

Get Secret

Retrieve a secret from Infisical:

const secret = await client.getSecret({
    environment: "dev",
    projectId: "656dba7f979ebd6652586669",
    secretName: "API_KEY",
    path: "/",
    type: "shared"
});

const value = secret.secretValue; // get its value

By default, getSecret() fetches and returns a shared secret.

To explicitly retrieve a personal secret:

const secret = await client.getSecret({
    environment: "dev",
    projectId: "656dba7f979ebd6652586669",
    secretName: "API_KEY",
    path: "/",
    type: "personal"
});

const value = secret.secretValue; // get its value

Options

ParameterTypeDescription
secretNamestringThe key of the secret to retrieve.
projectIdstringThe project ID where the secret lives in.
environmentstringThe slug name (dev, prod, etc) of the environment from where secrets should be fetched from.
pathstring (optional)The path from where secrets should be fetched from.
typestring (optional)The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared".

Create Secret

Create a new secret in Infisical:

const newApiKey = await client.createSecret({
    projectId: "656dba7f979ebd6652586669",
    environment: "dev",
    secretName: "API_KEY",
    secretValue: "SECRET VALUE",
    path: "/",
    type: "shared"
});

Options

ParameterTypeDescription
secretNamestringThe key of the secret to create.
secretValuestringThe value of the secret.
projectIdstringThe project ID where the secret lives in.
environmentstringThe slug name (dev, prod, etc) of the environment where secret should be created
pathstring (optional)The path from where secret should be created.
typestring, (optional)The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". A personal secret can only be created if a shared secret with the same name exists.

Update Secret

Update an existing secret in Infisical:

const updatedApiKey = await client.updateSecret({
    secretName: "API_KEY",
    secretValue: "NEW SECRET VALUE",
    projectId: "656dba7f979ebd6652586669",
    environment: "dev",
    path: "/",
    type: "shared"
});

Options

ParameterTypeDescription
secretNamestringThe key of the secret to update.
secretValuestringThe new value of the secret.
environmentstringThe slug name (dev, prod, etc) of the environment where secret should be updated.
projectIdstringThe project ID where the secret lives in.
pathstring (optional)The path from where secret should be updated.
typestring (optional)The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared".

Delete Secret

Delete a secret in Infisical:

const deletedSecret = await client.deleteSecret({
    secretName: "API_KEY",

    environment: "dev",
    projectId: "656dba7f979ebd6652586669",
    path: "/",

    type: "shared"
});

Options

ParameterTypeDescription
secretNamestringThe key of the secret to delete.
projectIdstringThe project ID where the secret lives in.
environmentstringThe slug name (dev, prod, etc) of the environment where secret should be deleted.
pathstring (optional)The path from where secret should be deleted.
typestring, (optional)The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". Note that deleting a shared secret also deletes all associated personal secrets.

License

Infisical Node.js SDK is distributed under the terms of the MIT license.

FAQs

Package last updated on 21 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc