### Install Phase Node.js SDK Source: https://github.com/phasehq/node-sdk/blob/main/README.md Install the Phase Node.js SDK using npm or yarn package managers. This is the first step to integrate Phase into your project. ```bash npm i @phase.dev/phase-node yarn add @phase.dev/phase-node ``` -------------------------------- ### Clone and Install Dependencies (Shell) Source: https://github.com/phasehq/node-sdk/blob/main/CONTRIBUTING.md Steps to clone the repository and install project dependencies using Yarn. This is a prerequisite for development. ```shell git clone https://github.com/your-username/node-sdk.git cd node-sdk yarn install ``` -------------------------------- ### Import SDK in Test Project (JavaScript) Source: https://github.com/phasehq/node-sdk/blob/main/CONTRIBUTING.md Example of how to import the Phase Node.js SDK into a JavaScript project after linking. ```javascript const Phase = require('@phase.dev/phase-node') ``` -------------------------------- ### Create and Reference Secrets with Phase Node SDK Source: https://context7.com/phasehq/node-sdk/llms.txt This TypeScript code snippet illustrates how to use the Phase Node.js SDK to create secrets and then create new secrets that reference existing ones. It shows examples of creating base secrets (DB_HOST, DB_PORT, DB_NAME), composing a DATABASE_URL using these references, and then retrieving the composed secret with its references automatically resolved. It also demonstrates cross-environment, folder path, cross-app, and complex nested referencing. ```typescript import Phase from "@phase.dev/phase-node"; const phase = new Phase('pss_service:v2:...'); // First, create secrets that will be referenced await phase.create({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secrets: [ { key: "DB_HOST", value: "localhost", comment: "Database host" }, { key: "DB_PORT", value: "5432", comment: "Database port" }, { key: "DB_NAME", value: "myapp_dev", comment: "Database name" } ] }); // Create a secret that references other secrets await phase.create({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secrets: [ { key: "DATABASE_URL", value: "postgresql://user:pass@${DB_HOST}:${DB_PORT}/${DB_NAME}", comment: "Composed database URL from references" } ] }); // Retrieve and automatically resolve references const secrets = await phase.get({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", key: "DATABASE_URL" }); console.log(secrets[0].value); // Output: "postgresql://user:pass@localhost:5432/myapp_dev" // Cross-environment reference await phase.create({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secrets: [ { key: "PROD_API_KEY", value: "${Production.API_KEY}", comment: "Reference to production API key" } ] }); // Folder path reference await phase.create({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secrets: [ { key: "DB_CONNECTION", value: "${/database/DB_PASSWORD}", comment: "Reference to password in /database path" } ] }); // Cross-app reference await phase.create({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secrets: [ { key: "SHARED_SECRET", value: "${other-app::SECRET_KEY}", comment: "Reference to secret in another app" } ] }); // Complex nested references with multiple variables await phase.create({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secrets: [ { key: "FULL_CONFIG", value: "api=${API_KEY},db=${Production./database/DB_PASSWORD},cache=${other-app::Staging.REDIS_URL}", comment: "Multiple references across apps and environments" } ] }); const resolved = await phase.get({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", key: "FULL_CONFIG" }); // All references are automatically resolved ``` -------------------------------- ### Get Secrets with Phase Node.js SDK Source: https://github.com/phasehq/node-sdk/blob/main/README.md Retrieve secrets from a specified application and environment. You can fetch all secrets or a specific secret by its key. Requires `appId` and `envName`. ```typescript import { GetSecretOptions } from "@phase.dev/phase-node"; const getOptions: GetSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", }; const secrets = await phase.get(getOptions); ``` ```typescript import { GetSecretOptions } from "@phase.dev/phase-node"; const getOptions: GetSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", key: "foo" }; const secrets = await phase.get(getOptions); ``` -------------------------------- ### Create and Link Test Project (Shell) Source: https://github.com/phasehq/node-sdk/blob/main/CONTRIBUTING.md Instructions for setting up a separate test project and linking the local SDK development version to it using Yarn. ```shell mkdir test-project && cd test-project yarn init -y # In SDK root: yarn link # In test project: yarn link '@phase.dev/phase-node' ``` -------------------------------- ### Initialize Phase Node.js SDK Source: https://context7.com/phasehq/node-sdk/llms.txt Initializes the Phase SDK using a Personal Access Token (PAT) or service account token. Optionally, a custom host can be specified. The session initialization is typically called automatically on the first operation. ```typescript import Phase from "@phase.dev/phase-node"; // Initialize with service token const token = 'pss_service:v2:048c9daa773b2d9bb21a1dda69a56f2b895401fded26889c7063c72224a61f65:fc065f7e5e1093292b20d0c917968cbe3badfb2e82bf1caa70649b72d0017905:1bb35376aacb277fd2792d781dbff5d0e9f7547da3544f4d394ff027d91436d5:4a04b7a5100c67cbf6376f8dae1ca936ca17bcbc119a4a84f8e3727696460925'; const phase = new Phase(token); // Optionally specify custom host const phaseCustomHost = new Phase(token, 'https://custom.phase.dev'); // Initialize session (automatically called on first operation) await phase.init(); ``` -------------------------------- ### Initialize Phase Node.js SDK Source: https://github.com/phasehq/node-sdk/blob/main/README.md Initialize the Phase SDK with your authentication token (PAT or service account token). This sets up the client for making API requests. ```typescript const token = 'pss_service...'; const phase = new Phase(token) ``` -------------------------------- ### Build and Test Package (Shell) Source: https://github.com/phasehq/node-sdk/blob/main/CONTRIBUTING.md Commands to build the Node.js SDK package and run its test suite. Essential for verifying code changes. ```shell yarn build yarn test ``` -------------------------------- ### Secret Referencing with Phase Node.js SDK Source: https://context7.com/phasehq/node-sdk/llms.txt Demonstrates how to create and reference secrets using dynamic composition. This includes referencing secrets within the same environment, across different environments, within folders, and across different applications. It also shows how the SDK automatically resolves these references when secrets are retrieved. ```APIDOC ## Secret Referencing Reference secrets from other environments or applications using the `${...}` syntax for dynamic secret composition. ### Method `POST` (Implicitly used by `phase.create` and `phase.get`) ### Endpoint `/secrets` (Conceptual endpoint for create/get operations) ### Parameters #### Request Body (for `phase.create`) - **appId** (string) - Required - The ID of the application. - **envName** (string) - Required - The name of the environment. - **secrets** (array) - Required - An array of secret objects to create or update. - **key** (string) - Required - The key of the secret. - **value** (string) - Required - The value of the secret, which can include references. - **comment** (string) - Optional - A description for the secret. #### Request Body (for `phase.get`) - **appId** (string) - Required - The ID of the application. - **envName** (string) - Required - The name of the environment. - **key** (string) - Required - The key of the secret to retrieve. ### Reference Syntax - **Same Environment**: `${SECRET_KEY}` - **Cross-Environment**: `${EnvironmentName.SECRET_KEY}` - **Folder Path**: `${/folder/path/SECRET_KEY}` - **Cross-App**: `${other-app::SECRET_KEY}` - **Cross-App and Environment**: `${other-app::EnvironmentName.SECRET_KEY}` - **Complex Nested**: `${appId::EnvironmentName/folder/SECRET_KEY}` ### Request Example (Creating secrets) ```typescript const phase = new Phase('pss_service:v2:...'); await phase.create({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secrets: [ { key: "DB_HOST", value: "localhost", comment: "Database host" }, { key: "DB_PORT", value: "5432", comment: "Database port" }, { key: "DB_NAME", value: "myapp_dev", comment: "Database name" } ] }); await phase.create({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secrets: [ { key: "DATABASE_URL", value: "postgresql://user:pass@${DB_HOST}:${DB_PORT}/${DB_NAME}", comment: "Composed database URL from references" } ] }); ``` ### Response Example (Retrieving a resolved secret) ```typescript const secrets = await phase.get({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", key: "DATABASE_URL" }); console.log(secrets[0].value); // Output: "postgresql://user:pass@localhost:5432/myapp_dev" ``` ### Error Handling - Specific error codes and messages will be returned for invalid references, missing secrets, or insufficient permissions. ``` -------------------------------- ### Create Branch and Commit Changes (Shell) Source: https://github.com/phasehq/node-sdk/blob/main/CONTRIBUTING.md Standard Git commands for creating a new feature branch, making commits with conventional commit messages, and pushing changes. ```shell git checkout -b feature/your-feature git commit -m "feat: add new feature" git push origin feature/your-feature ``` -------------------------------- ### Create Secrets with Phase Node.js SDK Source: https://context7.com/phasehq/node-sdk/llms.txt Creates one or more encrypted secrets within a specified application and environment. Supports setting keys, values, comments, paths, and tags for each secret. Includes error handling for creation failures and demonstrates creating secrets with empty tags. ```typescript import Phase, { CreateSecretOptions } from "@phase.dev/phase-node"; const phase = new Phase('pss_service:v2:...'); // Create multiple secrets with different configurations const createOptions: CreateSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secrets: [ { key: "API_KEY", value: "sk_test_abc123", comment: "Development API key for testing", tags: ["development", "api"] }, { key: "DB_PASSWORD", value: "super_secret_password", comment: "PostgreSQL database password", path: "/database", tags: ["database", "critical"] }, { key: "REDIS_URL", value: "redis://localhost:6379", comment: "Redis connection string", path: "/cache" } ] }; try { await phase.create(createOptions); console.log("Secrets created successfully"); } catch (error) { console.error("Failed to create secrets:", error); } // Create secret with empty tags (defaults to empty array) const simpleCreate: CreateSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Staging", secrets: [ { key: "SIMPLE_SECRET", value: "simple_value", comment: "" } ] }; await phase.create(simpleCreate); ``` -------------------------------- ### Import Phase Node.js SDK Source: https://github.com/phasehq/node-sdk/blob/main/README.md Import the Phase SDK into your Node.js project. This allows you to access the SDK's functionalities. ```javascript const Phase = require("@phase.dev/phase-node"); ``` -------------------------------- ### Handle Network Errors During Phase Node.js SDK Initialization Source: https://context7.com/phasehq/node-sdk/llms.txt Illustrates catching network-related errors that may occur during the initialization of the Phase SDK. This is crucial for applications relying on network connectivity for service initialization. It requires the '@phase.dev/phase-node' package. ```typescript // Handle network errors during initialization const phase = new Phase('pss_service:v2:...'); try { await phase.init(); } catch (error) { console.error(error); // "Failed to initialize session. Please check your token and network connection." ``` -------------------------------- ### Node SDK: Asymmetric and Symmetric Encryption & Hashing Source: https://context7.com/phasehq/node-sdk/llms.txt Provides utilities for asymmetric encryption/decryption, key pair generation, and message digests. It requires the '@phase.dev/phase-node' package and optionally 'libsodium-wrappers' for environment secret encryption. Inputs include plaintexts, keys, and salts; outputs are ciphertexts or digests. ```typescript import { encryptAsymmetric, decryptAsymmetric, randomKeyPair, digest, encryptEnvSecrets, decryptEnvSecrets } from "@phase.dev/phase-node"; // Generate a random key exchange keypair const keyPair = await randomKeyPair(); console.log(keyPair); // { // publicKey: Uint8Array[32], // privateKey: Uint8Array[32] // } // Encrypt data asymmetrically const plaintext = "sensitive data"; const publicKeyHex = "a3f2b1c4d5e6f7..."; // Hex-encoded public key const ciphertext = await encryptAsymmetric(plaintext, publicKeyHex); console.log(ciphertext); // "ph:v1:7a5e6c91afc57338...:SKD/QatCqjcx..." // Decrypt data asymmetrically const privateKeyHex = "9c8e7a6b5d4c3b2a..."; // Hex-encoded private key const decrypted = await decryptAsymmetric( ciphertext, privateKeyHex, publicKeyHex ); console.log(decrypted); // "sensitive data" // Create a digest (hash) of a secret key const secretKey = "API_KEY"; const salt = "random_salt_value"; const keyDigest = await digest(secretKey, salt); console.log(keyDigest); // "e3b0c44298fc1c14..." // Encrypt multiple secrets for an environment import _sodium from "libsodium-wrappers"; await _sodium.ready; const sodium = _sodium; const envKeyPair = await randomKeyPair(); const envKeys = { publicKey: sodium.to_hex(envKeyPair.publicKey), privateKey: sodium.to_hex(envKeyPair.privateKey) }; const envSalt = "environment_specific_salt"; const secrets = [ { key: "SECRET_1", value: "value1", comment: "First secret" }, { key: "SECRET_2", value: "value2", comment: "Second secret" } ]; const encryptedSecrets = await encryptEnvSecrets(secrets, envKeys, envSalt); console.log(encryptedSecrets); // [ // { // key: "ph:v1:..", // Encrypted // value: "ph:v1:..", // Encrypted // comment: "ph:v1:..", // Encrypted // keyDigest: "a3f2..." // }, // ... // ] // Decrypt environment secrets const decryptedSecrets = await decryptEnvSecrets(encryptedSecrets, envKeys); console.log(decryptedSecrets); // [ // { key: "SECRET_1", value: "value1", comment: "First secret" }, // { key: "SECRET_2", value: "value2", comment: "Second secret" } // ] // Handle encryption errors gracefully try { const wrongKeyPair = await randomKeyPair(); await decryptEnvSecrets(encryptedSecrets, { publicKey: envKeys.publicKey, privateKey: sodium.to_hex(wrongKeyPair.privateKey) }); } catch (error) { console.error("Decryption failed:", error.message); // "Decryption failed: Something went wrong: ..." } ``` -------------------------------- ### Handle Secret Creation Errors in Phase Node.js SDK Source: https://context7.com/phasehq/node-sdk/llms.txt Illustrates how to handle errors that occur during secret creation, such as providing blank keys. This ensures data integrity and adherence to secret naming conventions. It requires the '@phase.dev/phase-node' package. ```typescript // Handle secret creation errors try { await phase.create({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secrets: [ { key: "", value: "value", comment: "" } // Empty key ] }); } catch (error) { console.error(error); // "Secret keys cannot be blank" ``` -------------------------------- ### Create Secrets with Phase Node.js SDK Source: https://github.com/phasehq/node-sdk/blob/main/README.md Create one or more secrets in a specified application and environment. Each secret can have a key, value, and an optional path. Requires `appId`, `envName`, and a list of secrets. ```typescript import { CreateSecretOptions } from "@phase.dev/phase-node"; 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); ``` -------------------------------- ### Handle Invalid Token Format in Phase Node.js SDK Source: https://context7.com/phasehq/node-sdk/llms.txt Demonstrates how to catch and log errors when an invalid token format is provided during Phase SDK initialization. This ensures graceful failure and provides informative error messages to the developer. It requires the '@phase.dev/phase-node' package. ```typescript import Phase from "@phase.dev/phase-node"; // Handle invalid token format try { const phase = new Phase("invalid-token"); } catch (error) { console.error(error.message); // "Invalid token format. Token does not match the expected pattern." } ``` -------------------------------- ### Node SDK: Secret Reference Parsing and Resolution Source: https://context7.com/phasehq/node-sdk/llms.txt Provides functions to parse various secret reference formats, normalize keys for consistent lookups, and resolve these references using a custom fetcher. It depends on '@phase.dev/phase-node'. Inputs include strings with references and a custom fetcher function; outputs are resolved strings or Secret objects. ```typescript import { parseSecretReference, normalizeKey, resolveSecretReferences, SecretFetcher, Secret } from "@phase.dev/phase-node"; // Parse different reference formats const localRef = parseSecretReference('${SECRET_KEY}'); console.log(localRef); // { app: null, env: null, path: '/', key: 'SECRET_KEY' } const pathRef = parseSecretReference('${/path/to/SECRET_KEY}'); console.log(pathRef); // { app: null, env: null, path: '/path/to', key: 'SECRET_KEY' } const crossEnvRef = parseSecretReference('${Production.SECRET_KEY}'); console.log(crossEnvRef); // { app: null, env: 'Production', path: '/', key: 'SECRET_KEY' } const crossAppRef = parseSecretReference('${my-app::Staging./api/API_KEY}'); console.log(crossAppRef); // { app: 'my-app', env: 'Staging', path: '/api', key: 'API_KEY' } // Normalize keys for caching and lookups const normalizedKey = normalizeKey('Production', '/database', 'DB_PASSWORD', 'my-app'); console.log(normalizedKey); // "my-app:production:/database:DB_PASSWORD" // Custom secret fetcher for reference resolution const customFetcher: SecretFetcher = async (env, path, key, app) => { console.log(`Fetching: ${key} from ${env}${path} in app ${app || 'current'}`); // Custom logic to fetch secret return { id: "abc-123", key: key, value: "fetched_value", comment: "", environment: env, path: path, tags: [], keyDigest: "", version: 1 } as Secret; }; // Resolve references with custom fetcher const valueWithRefs = "Database: ${DB_HOST}:${DB_PORT}"; const cache = new Map(); const resolved = await resolveSecretReferences( valueWithRefs, "Development", "/", customFetcher, null, cache ); console.log(resolved); // "Database: localhost:5432" // Handle circular references (automatically detected) const circularValue = "${CIRCULAR_KEY}"; // Assumes CIRCULAR_KEY references back const safeResolved = await resolveSecretReferences( circularValue, "Development", "/", customFetcher, null, new Map() ); // Circular references are detected and logged, original reference returned ``` -------------------------------- ### Handle API Errors with Status Codes in Phase Node.js SDK Source: https://context7.com/phasehq/node-sdk/llms.txt Shows how to handle API errors, specifically those that return status codes, when interacting with the Phase SDK. This helps in debugging and managing failed API requests. It requires the '@phase.dev/phase-node' package. ```typescript // Handle API errors with status codes try { await phase.get({ appId: "invalid-app-id", envName: "Development" }); } catch (error) { console.error(error); // "Invalid app id" ``` -------------------------------- ### Handle Invalid Environment Name in Phase Node.js SDK Source: https://context7.com/phasehq/node-sdk/llms.txt Demonstrates catching errors when an invalid or non-existent environment name is used in Phase SDK operations. This validation is important for ensuring correct data retrieval. It requires the '@phase.dev/phase-node' package. ```typescript // Handle invalid environment name try { await phase.get({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "NonExistentEnv" }); } catch (error) { console.error(error); // "Invalid environment name: 'NonExistentEnv'" ``` -------------------------------- ### Handle Reference Resolution Errors in Phase Node.js SDK Source: https://context7.com/phasehq/node-sdk/llms.txt Shows how to manage errors related to resolving secret references, such as when a referenced secret or key is not found. This is vital for managing complex secret dependencies. It requires the '@phase.dev/phase-node' package. ```typescript // Handle reference resolution errors try { const secrets = await phase.get({ appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", key: "SECRET_WITH_BAD_REF" // Value: "${NonExistent.KEY}" }); } catch (error) { console.error(error); // "Failed to resolve reference: Secret not found: KEY in NonExistent" ``` -------------------------------- ### Retrieve Secrets with Phase Node.js SDK Source: https://context7.com/phasehq/node-sdk/llms.txt Retrieves secrets from a specific environment, with options to filter by key, path, or tags. The SDK handles automatic decryption and reference resolution. Supports retrieving all secrets, a single secret by key, secrets within a path, or secrets matching specific tags. ```typescript import Phase, { GetSecretOptions } from "@phase.dev/phase-node"; const phase = new Phase('pss_service:v2:...'); // Get all secrets in an environment const allSecretsOptions: GetSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development" }; const allSecrets = await phase.get(allSecretsOptions); console.log(allSecrets); // [ // { // id: "28f5d66e-b006-4d34-8e32-88e1d3478299", // key: "API_KEY", // value: "sk_live_12345", // comment: "Production API key", // environment: "Development", // path: "/", // tags: ["production", "api"], // keyDigest: "a3f2...", // version: 1 // } // ] // Get a specific secret by key const specificKeyOptions: GetSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", key: "API_KEY" }; const specificSecret = await phase.get(specificKeyOptions); // Get secrets from a specific path const pathOptions: GetSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", path: "/database" }; const dbSecrets = await phase.get(pathOptions); // Get secrets filtered by tags const tagOptions: GetSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Production", tags: ["critical", "api"] }; const taggedSecrets = await phase.get(tagOptions); ``` -------------------------------- ### Graceful Secret Fetching with Retry in Phase Node.js SDK Source: https://context7.com/phasehq/node-sdk/llms.txt Implements a robust function to fetch secrets using the Phase SDK with a built-in retry mechanism for handling transient network or API issues. This enhances application resilience. It requires the '@phase.dev/phase-node' package. ```typescript // Graceful handling with logging import Phase, { GetSecretOptions } from "@phase.dev/phase-node"; async function getSecretsWithRetry( phase: Phase, options: GetSecretOptions, retries = 3 ) { for (let i = 0; i < retries; i++) { try { return await phase.get(options); } catch (error) { console.warn(`Attempt ${i + 1} failed:`, error); if (i === retries - 1) throw error; await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1))); } } } const secrets = await getSecretsWithRetry(phase, { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development" }); ``` -------------------------------- ### Update Secrets with Phase Node.js SDK Source: https://github.com/phasehq/node-sdk/blob/main/README.md Update existing secrets in a specified application and environment by their IDs. Requires `appId`, `envName`, and a list of secrets with their IDs and new values. ```typescript import { UpdateSecretOptions } from "@phase.dev/phase-node"; const updateOptions: UpdateSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secrets: [ { id: "28f5d66e-b006-4d34-8e32-88e1d3478299", value: 'newvalue' }, ], }; await phase.update(updateOptions); ``` -------------------------------- ### Update Secrets in Phase Node SDK Source: https://context7.com/phasehq/node-sdk/llms.txt Updates existing secrets within a specified application and environment. Supports partial updates to values, comments, tags, and overrides. Requires the Phase SDK and specific update options including app ID, environment name, and a list of secrets to update. ```typescript import Phase, { UpdateSecretOptions } from "@phase.dev/phase-node"; const phase = new Phase('pss_service:v2:...'); // Update secret values const updateOptions: UpdateSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secrets: [ { id: "28f5d66e-b006-4d34-8e32-88e1d3478299", value: "sk_test_new_key_789" }, { id: "91a8c32b-7f15-4e21-9d45-a2b6f8c93d12", value: "updated_password", comment: "Updated password after rotation" } ] }; try { await phase.update(updateOptions); console.log("Secrets updated successfully"); } catch (error) { console.error("Failed to update secrets:", error); } // Update with secret override (temporary value override) const overrideUpdate: UpdateSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Production", secrets: [ { id: "28f5d66e-b006-4d34-8e32-88e1d3478299", override: { value: "temporary_override_value", isActive: true } } ] }; await phase.update(overrideUpdate); // Partial update - only update specific fields const partialUpdate: UpdateSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Staging", secrets: [ { id: "abc-123", key: "UPDATED_KEY_NAME" } ] }; await phase.update(partialUpdate); ``` -------------------------------- ### Delete Secrets with Phase Node.js SDK Source: https://github.com/phasehq/node-sdk/blob/main/README.md Delete one or more secrets from a specified application and environment using their IDs. Requires `appId`, `envName`, and a list of `secretIds`. ```typescript import { DeleteSecretOptions } from "@phase.dev/phase-node"; const secretsToDelete = secrets.map((secret) => secret.id); const deleteOptions: DeleteSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secretIds: secretsToDelete, }; await phase.delete(deleteOptions); ``` -------------------------------- ### Delete Secrets in Phase Node SDK Source: https://context7.com/phasehq/node-sdk/llms.txt Deletes one or more secrets from a specified application and environment using their unique IDs. The function accepts options including app ID, environment name, and an array of secret IDs to remove. It's recommended to first retrieve secret IDs if not already known. ```typescript import Phase, { DeleteSecretOptions } from "@phase.dev/phase-node"; const phase = new Phase('pss_service:v2:...'); // First, get secrets to obtain their IDs const getOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", tags: ["deprecated"] }; const secretsToRemove = await phase.get(getOptions); const secretIds = secretsToRemove.map((secret) => secret.id); // Delete the secrets const deleteOptions: DeleteSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secretIds: secretIds }; try { await phase.delete(deleteOptions); console.log(`Successfully deleted ${secretIds.length} secrets`); } catch (error) { console.error("Failed to delete secrets:", error); } // Delete specific secrets by ID const deleteSpecific: DeleteSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secretIds: [ "28f5d66e-b006-4d34-8e32-88e1d3478299", "91a8c32b-7f15-4e21-9d45-a2b6f8c93d12" ] }; await phase.delete(deleteSpecific); // Safe delete with empty array (no-op) const safeDelete: DeleteSecretOptions = { appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66", envName: "Development", secretIds: [] }; await phase.delete(safeDelete); // Does nothing ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.