SDK to integrate Phase in server-side applications running Node.js
npm i @phase.dev/phase-node
or yarn add @phase.dev/phase-node
const Phase = require("@phase.dev/phase-node");
Initialize the SDK with your PAT or service account token:
const token = 'pss_service...'
const phase = new Phase(token)
Get all secrets in an environment:
const getOptions: GetSecretOptions = {
appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66",
envName: "Development",
};
const secrets = await phase.get(getOptions);
Get a specific key:
const getOptions: GetSecretOptions = {
appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66",
envName: "Development",
key: "foo"
};
const secrets = await phase.get(getOptions);
Create one or more secrets in a specified application and environment:
import { CreateSecretOptions } from "phase";
const createOptions: CreateSecretOptions = {
appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66",
envName: "Development",
secrets: [
{
key: "API_KEY",
value: "your-api-key",
comment: 'test key for dev'
},
{
key: "DB_PASSWORD",
value: "your-db-password",
path: "/database",
}
]
};
await phase.create(createOptions);
Update existing secrets in a specified application and environment:
import { UpdateSecretOptions } from "phase";
const updateOptions: UpdateSecretOptions = {
appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66",
envName: "Development",
secrets: [
{
id: "28f5d66e-b006-4d34-8e32-88e1d3478299",
value: 'newvalue'
},
],
};
await phase.update(updateOptions);
Delete one or more secrets from a specified application and environment:
import { DeleteSecretOptions } from "phase";
const secretsToDelete = secrets.map((secret) => secret.id);
const deleteOptions: DeleteSecretOptions = {
appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66",
envName: "Development",
secretIds: secretsToDelete,
};
await phase.delete(deleteOptions);
Please see CONTRIBUTING.md for more information on how to contribute.