Skip to content

Commit ac6b630

Browse files
authored
Merge pull request #10 from phasehq/secrets
refactor: secrets
2 parents 0052b70 + 547fb47 commit ac6b630

21 files changed

+2130
-467
lines changed

CONTRIBUTING.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Contributing Guide
2+
3+
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.
4+
5+
## Getting Started
6+
7+
1. **Fork the repository** on GitHub.
8+
2. **Clone your fork** to your local machine:
9+
```sh
10+
git clone https://github.com/your-username/node-sdk.git
11+
cd node-sdk
12+
```
13+
3. **Install dependencies**:
14+
```sh
15+
yarn install
16+
```
17+
4. **Build the package**:
18+
```sh
19+
yarn build
20+
```
21+
5. **Run tests**:
22+
```sh
23+
yarn test
24+
```
25+
26+
## Making Changes
27+
28+
- Follow the existing code style (Prettier and ESLint are configured).
29+
- Write clear commit messages following the [Conventional Commits](https://www.conventionalcommits.org/) format.
30+
- Ensure all tests pass before submitting a pull request.
31+
- If adding a new feature, consider writing tests to cover your changes.
32+
- Consider if your changes require an update to [docs](https://github.com/phasehq/docs).
33+
- 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.
34+
35+
## Setting Up a Test Project
36+
37+
To test your local changes in a real project, follow these steps:
38+
39+
1. **Create a new test project:**
40+
```sh
41+
mkdir test-project && cd test-project
42+
yarn init -y
43+
```
44+
45+
2. **Link the local SDK package:**
46+
In the SDK root, run:
47+
```sh
48+
yarn link
49+
```
50+
Then in your test project,
51+
```sh
52+
yarn link '@phase.dev/phase-node'
53+
```
54+
55+
56+
3. **Use the SDK in your test project:**
57+
```js
58+
const Phase = require('@phase.dev/phase-node')
59+
```
60+
61+
## Submitting a Pull Request
62+
63+
1. **Create a new branch:**
64+
```sh
65+
git checkout -b feature/your-feature
66+
```
67+
2. **Make and commit your changes:**
68+
```sh
69+
git commit -m "feat: add new feature"
70+
```
71+
3. **Push to your fork:**
72+
```sh
73+
git push origin feature/your-feature
74+
```
75+
4. **Open a Pull Request** on GitHub against the `main` branch.
76+
77+
## Useful Links
78+
79+
[Phase Quickstart](https://docs.phase.dev/quickstart)
80+
81+
[SDK Docs](https://docs.phase.dev/sdks/node)
82+
83+
[Docs repo](https://github.com/phasehq/docs)
84+
85+
[Community Slack](https://slack.phase.dev)
86+
87+

README.md

+88-16
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,108 @@ const Phase = require("@phase.dev/phase-node");
1414

1515
## Initialize
1616

17-
Initialize the SDK with your `APP_ID` and `APP_SECRET`:
17+
Initialize the SDK with your PAT or service account token:
1818

19-
```js
20-
const phase = new Phase(APP_ID, APP_SECRET);
19+
```typescript
20+
const token = 'pss_service...'
21+
22+
const phase = new Phase(token)
2123
```
2224

2325
## Usage
2426

25-
### Encrypt
27+
### Get Secrets
2628

27-
```js
28-
const ciphertext = await phase.encrypt("hello world");
29+
Get all secrets in an environment:
30+
31+
```typescript
32+
const getOptions: GetSecretOptions = {
33+
appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66",
34+
envName: "Development",
35+
};
36+
37+
const secrets = await phase.get(getOptions);
2938
```
3039

31-
### Decrypt
40+
Get a specific key:
3241

33-
```js
34-
const plaintext = await phase.decrypt(ciphertext);
42+
```typescript
43+
const getOptions: GetSecretOptions = {
44+
appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66",
45+
envName: "Development",
46+
key: "foo"
47+
};
48+
49+
const secrets = await phase.get(getOptions);
3550
```
3651

37-
## Development
52+
### Create Secrets
53+
54+
Create one or more secrets in a specified application and environment:
55+
56+
```typescript
57+
import { CreateSecretOptions } from "phase";
58+
59+
const createOptions: CreateSecretOptions = {
60+
appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66",
61+
envName: "Development",
62+
secrets: [
63+
{
64+
key: "API_KEY",
65+
value: "your-api-key",
66+
comment: 'test key for dev'
67+
},
68+
{
69+
key: "DB_PASSWORD",
70+
value: "your-db-password",
71+
path: "/database",
72+
}
73+
]
74+
};
75+
76+
await phase.create(createOptions);
77+
```
78+
79+
### Update Secrets
3880

39-
### Install dependencies
81+
Update existing secrets in a specified application and environment:
4082

41-
`npm install`
4283

43-
### Build
4484

45-
`npm run build`
85+
```typescript
86+
import { UpdateSecretOptions } from "phase";
4687

47-
### Run tests
88+
const updateOptions: UpdateSecretOptions = {
89+
appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66",
90+
envName: "Development",
91+
secrets: [
92+
{
93+
id: "28f5d66e-b006-4d34-8e32-88e1d3478299",
94+
value: 'newvalue'
95+
},
96+
],
97+
};
98+
99+
await phase.update(updateOptions);
100+
```
101+
### Delete Secrets
102+
103+
Delete one or more secrets from a specified application and environment:
104+
105+
```typescript
106+
import { DeleteSecretOptions } from "phase";
107+
108+
const secretsToDelete = secrets.map((secret) => secret.id);
109+
110+
const deleteOptions: DeleteSecretOptions = {
111+
appId: "3b7443aa-3a7c-4791-849a-42aafc9cbe66",
112+
envName: "Development",
113+
secretIds: secretsToDelete,
114+
};
115+
116+
await phase.delete(deleteOptions);
117+
```
118+
119+
## Development
48120

49-
`npm test`
121+
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for more information on how to contribute.

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@phase.dev/phase-node",
3-
"version": "2.1.0",
3+
"version": "3.0.0",
44
"description": "Node.js Server SDK for Phase",
55
"main": "dist/index.js",
66
"types": "dist/src/index.d.ts",
@@ -30,6 +30,7 @@
3030
"@types/libsodium-wrappers": "^0.7.10",
3131
"@types/node": "^18.13.0",
3232
"@typescript-eslint/eslint-plugin": "^5.0.0",
33+
"axios-mock-adapter": "^2.1.0",
3334
"babel-preset-es2015": "^6.24.1",
3435
"eslint": "^8.0.1",
3536
"eslint-config-prettier": "^8.6.0",
@@ -48,7 +49,9 @@
4849
"typescript": "^4.9.5"
4950
},
5051
"dependencies": {
51-
"libsodium-wrappers": "^0.7.11"
52+
"axios": "^1.7.9",
53+
"libsodium-wrappers": "^0.7.11",
54+
"ts-node": "^10.9.2"
5255
},
5356
"publishConfig": {
5457
"ignore": [

0 commit comments

Comments
 (0)