From 175b4a3fb6597d56317fc8982d1edc6b3d4e9c02 Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Sun, 12 Mar 2023 23:03:25 +0700 Subject: [PATCH] Add docs for Node SDK --- docs/mint.json | 17 +++--- docs/sdk/overview/usage.mdx | 104 ++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 docs/sdk/overview/usage.mdx diff --git a/docs/mint.json b/docs/mint.json index 7903524f6..697a7bfeb 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -49,6 +49,11 @@ "icon": "server", "url": "self-hosting" }, + { + "name": "SDK", + "icon": "puzzle-piece", + "url": "sdk" + }, { "name": "API Reference", "icon": "cloud", @@ -128,10 +133,8 @@ "integrations/platforms/docker-compose" ] }, - "integrations/platforms/kubernetes", "integrations/frameworks/terraform", - { "group": "AWS", "pages": [ @@ -139,20 +142,16 @@ "integrations/cloud/aws-secret-manager" ] }, - "integrations/cloud/heroku", "integrations/cloud/vercel", "integrations/cloud/netlify", "integrations/cloud/render", "integrations/cloud/flyio", - "integrations/cloud/azure-key-vault", - "integrations/cicd/githubactions", "integrations/cicd/gitlab", "integrations/cicd/circleci", "integrations/cicd/travisci", - "integrations/frameworks/react", "integrations/frameworks/vue", "integrations/frameworks/express", @@ -192,6 +191,12 @@ "self-hosting/configuration/email" ] }, + { + "group": "SDK", + "pages": [ + "sdk/overview/usage" + ] + }, { "group": "Overview", "pages": [ diff --git a/docs/sdk/overview/usage.mdx b/docs/sdk/overview/usage.mdx new file mode 100644 index 000000000..2708f9a2b --- /dev/null +++ b/docs/sdk/overview/usage.mdx @@ -0,0 +1,104 @@ +--- +title: "Usage" +--- + + + We're currently expanding the functionality of the Javascript SDK and working + on mirror SDKs for other languages like Python as well. Follow this GitHub + [issue](https://github.com/Infisical/infisical/issues/320) to stay updated. + + +Infisical provides a [Node SDK](https://github.com/Infisical/infisical-node) that users can easily install into their applications and use to fetch their secrets. + +With the SDK, users can currently fetch back secrets and define default values. + + + + +## Installation + +```bash +$ npm install infisical-node +``` + +## Import + +```js +// ES6 syntax +import infisical from "infisical-node"; + +// ES5 syntax +const infisical = require("infisical-node"); +``` + +## Initialization + +If your app only needs to connect to one Infisical project, you should use `infisical.connect`. If you need to connect to multiple Infisical projects, use `infisical.createConnection`. + +Both `connect` and `createConnection` take a parameter `token` and pull in the secrets accessible by that Infisical token. + +```js +// using async-await (recommended) +await infisical.connect({ + token: "your_infisical_token", +}); +``` + +```js +// using promise chaining +infisical.connect({ + token: "your_infisical_token" +}) +.then(() => { + console.log('Success!) +}) +.catch(err => { + console.error('Error: ', err); +}) +``` + +Options: + +| Option | Description | Default Value | +| -------------------- | ----------------------------------------------------------- | --------------------------- | +| `token` | ❗️ An Infisical Token to be used to fetch secrets | `None` | +| `siteURL` | Site URL of Infisical to connect to | `https://app.infisical.com` | +| `attachToProcessEnv` | Whether or not to attach fetched secrets to `process.env` | `False` | +| `defaultValues` | Default values for secrets if they aren't fetched/passed in | `{}` | + +## Access a Secret Value + +```js +const dbURL = infisical.getSecretValue("DB_URL"); +``` + +## Example with Express + +```js +const express = require("express"); +const port = 3000; +const infisical = require("infisical-node"); + +app.get("/", (req, res) => { + // access value + const name = infisical.getSecret("NAME"); + + res.send(`Hello! My name is: ${name}`); +}); + +app.listen(port, async () => { + // initialize client + await infisical.connect({ + token: "YOUR_INFISICAL_TOKEN", + }); + + console.log(`App listening on port ${port}`); +}); +``` + + + + Coming soon. + + +