Skip to content

Conversation

@rohan-chaturvedi
Copy link
Member

@rohan-chaturvedi rohan-chaturvedi commented Feb 3, 2025

Overview

Updates the SDK with full secrets management support including getting, creating updating and deleting secrets. The SDK handles end-to-end encryption, personal secret overrides and resolves references across folders and environments.

Example usage

Initialize

Initialize the SDK with your PAT or service account token:

const token = 'pss_service...'

const phase = new Phase(token)

Get Secrets

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 Secrets

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 Secrets

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 Secrets

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);

@nimish-ks nimish-ks self-requested a review February 3, 2025 16:13
@nimish-ks
Copy link
Member

@rohan-chaturvedi please updated the readme with usage and dev instructions.

@rohan-chaturvedi rohan-chaturvedi marked this pull request as ready for review February 6, 2025 08:06
@nimish-ks nimish-ks merged commit ac6b630 into main Feb 7, 2025
1 check passed
@nimish-ks nimish-ks deleted the secrets branch February 7, 2025 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants