Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Contributing Guide

Thank you for your interest in contributing to the Phase Node.js SDK! We welcome all contributions, whether it's fixing bugs, adding new features, or improving documentation.

## Getting Started

1. **Fork the repository** on GitHub.
2. **Clone your fork** to your local machine:
```sh
git clone https://github.com/your-username/node-sdk.git
cd node-sdk
```
3. **Install dependencies**:
```sh
yarn install
```
4. **Build the package**:
```sh
yarn build
```
5. **Run tests**:
```sh
yarn test
```

## Making Changes

- Follow the existing code style (Prettier and ESLint are configured).
- Write clear commit messages following the [Conventional Commits](https://www.conventionalcommits.org/) format.
- Ensure all tests pass before submitting a pull request.
- If adding a new feature, consider writing tests to cover your changes.
- Consider if your changes require an update to [docs](https://github.com/phasehq/docs).
- Bump the package version in `package.json` and `version.ts`. Use the semver standard to bump the major, minor or patch version depending on the type of change you're making.

## Setting Up a Test Project

To test your local changes in a real project, follow these steps:

1. **Create a new test project:**
```sh
mkdir test-project && cd test-project
yarn init -y
```

2. **Link the local SDK package:**
In the SDK root, run:
```sh
yarn link
```
Then in your test project,
```sh
yarn link '@phase.dev/phase-node'
```


3. **Use the SDK in your test project:**
```js
const Phase = require('@phase.dev/phase-node')
```

## Submitting a Pull Request

1. **Create a new branch:**
```sh
git checkout -b feature/your-feature
```
2. **Make and commit your changes:**
```sh
git commit -m "feat: add new feature"
```
3. **Push to your fork:**
```sh
git push origin feature/your-feature
```
4. **Open a Pull Request** on GitHub against the `main` branch.

## Useful Links

[Phase Quickstart](https://docs.phase.dev/quickstart)

[SDK Docs](https://docs.phase.dev/sdks/node)

[Docs repo](https://github.com/phasehq/docs)

[Community Slack](https://slack.phase.dev)


104 changes: 88 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,108 @@ const Phase = require("@phase.dev/phase-node");

## Initialize

Initialize the SDK with your `APP_ID` and `APP_SECRET`:
Initialize the SDK with your PAT or service account token:

```js
const phase = new Phase(APP_ID, APP_SECRET);
```typescript
const token = 'pss_service...'

const phase = new Phase(token)
```

## Usage

### Encrypt
### Get Secrets

```js
const ciphertext = await phase.encrypt("hello world");
Get all secrets in an environment:

```typescript
const getOptions: GetSecretOptions = {
appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66",
envName: "Development",
};

const secrets = await phase.get(getOptions);
```

### Decrypt
Get a specific key:

```js
const plaintext = await phase.decrypt(ciphertext);
```typescript
const getOptions: GetSecretOptions = {
appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66",
envName: "Development",
key: "foo"
};

const secrets = await phase.get(getOptions);
```

## Development
### Create Secrets

Create one or more secrets in a specified application and environment:

```typescript
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

### Install dependencies
Update existing secrets in a specified application and environment:

`npm install`

### Build

`npm run build`
```typescript
import { UpdateSecretOptions } from "phase";

### Run tests
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:

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

## Development

`npm test`
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for more information on how to contribute.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phase.dev/phase-node",
"version": "2.1.0",
"version": "3.0.0",
"description": "Node.js Server SDK for Phase",
"main": "dist/index.js",
"types": "dist/src/index.d.ts",
Expand Down Expand Up @@ -30,6 +30,7 @@
"@types/libsodium-wrappers": "^0.7.10",
"@types/node": "^18.13.0",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"axios-mock-adapter": "^2.1.0",
"babel-preset-es2015": "^6.24.1",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.6.0",
Expand All @@ -48,7 +49,9 @@
"typescript": "^4.9.5"
},
"dependencies": {
"libsodium-wrappers": "^0.7.11"
"axios": "^1.7.9",
"libsodium-wrappers": "^0.7.11",
"ts-node": "^10.9.2"
},
"publishConfig": {
"ignore": [
Expand Down
Loading