Skip to content

Commit 6d6ec3b

Browse files
committed
Update README examples
1 parent 9072623 commit 6d6ec3b

11 files changed

Lines changed: 103 additions & 35 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ jobs:
3939
working-directory: ./keeperapi
4040

4141
- name: Examples (node) - Installation
42-
run: npm run link-local
42+
run: npm i
4343
working-directory: ./examples/print-vault-node
4444

4545
- name: Examples (node) - Check Types
4646
run: npm run types:ci
4747
working-directory: ./examples/print-vault-node
4848

4949
- name: Examples (browser) - Installation
50-
run: npm run link-local
50+
run: npm i
5151
working-directory: ./examples/print-vault-browser
5252

5353
- name: Examples (browser) - Check Types

README.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,23 @@ This SDK can be used from Node or from the browser
1111
Usage:
1212

1313
```bash
14-
npm install keeperapi
14+
npm install @keeper-security/keeperapi
1515
```
1616

17-
```typescript
18-
try {
19-
let auth = new Auth({
20-
host: KeeperEnvironment.DEV
21-
});
22-
await auth.login(username, password);
23-
console.log("login successful");
24-
let vault = new Vault(auth);
25-
await vault.syncDown();
26-
vault.records.forEach(x => console.log(JSON.stringify(x)));
27-
} catch (e) {
28-
console.log(e);
29-
}
30-
```
17+
## Examples
18+
19+
Check out the example projects to see the SDK in action:
3120

32-
For local development,
21+
- [Node.js Example](examples/print-vault-node) - Print vault contents using Node.js
22+
- [Browser Example](examples/print-vault-browser) - Print vault contents in a React web app
23+
24+
## Local Development
3325

3426
```bash
3527
npm run build
3628
```
3729
from "keeperapi" folder, then
38-
30+
3931
```bash
4032
npm link ../../keeperapi
4133
```

examples/print-vault-browser/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
- `npm start`
66

77
### NOTES
8-
- By default, the `preinstall` script links the installed version of `keeperapi` to the local version in this repo
8+
- This example automatically uses the local `keeperapi` package from the monorepo via `file:` reference

examples/print-vault-browser/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
"private": true,
55
"scripts": {
66
"start": "react-scripts start",
7-
"link-local": "npm link ../../keeperapi",
87
"types": "tsc --watch",
98
"types:ci": "tsc"
109
},
1110
"dependencies": {
12-
"keeperapi": "0.2.0",
11+
"@keeper-security/keeperapi": "file:../../keeperapi",
1312
"react": "^16.8.6",
1413
"react-dom": "^16.8.6"
1514
},

examples/print-vault-browser/src/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,13 @@ class App extends Component<{}, AppState> implements AuthUI {
5757
newState.status.push('Logged In, querying records...')
5858
newState.loggedIn = true
5959
this.setState(newState)
60-
const records = [] as DRecord[]
6160
const storage = {} as VaultStorage
6261
await syncDown({
6362
auth,
6463
storage,
6564
})
6665
newState = {...this.state}
67-
newState.records = [...records.map(x => JSON.stringify(x))]
66+
newState.records = [...storage.records.map(x => JSON.stringify(x))]
6867
this.setState(newState)
6968
} catch (e) {
7069
console.log(e)

examples/print-vault-node/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
- `npm start`
66

77
### NOTES
8-
- By default, the `preinstall` script links the installed version of `keeperapi` to the local version in this repo
8+
- This example automatically uses the local `keeperapi` package from the monorepo via `file:` reference

examples/print-vault-node/package-lock.json

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/print-vault-node/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
"license": "ISC",
99
"scripts": {
1010
"start": "ts-node src/index.ts",
11-
"link-local": "npm link ../../keeperapi",
1211
"types": "tsc --watch",
1312
"types:ci": "tsc"
1413
},
1514
"dependencies": {
16-
"@keeper-security/keeperapi": "16.0.5",
15+
"@keeper-security/keeperapi": "file:../../keeperapi",
1716
"@types/node": "^17.0.25",
1817
"ts-node": "^10.7.0",
1918
"typescript": "^4.6.3"

examples/print-vault-node/src/index.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,41 @@ import LoginType = Authentication.LoginType;
44

55
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
66

7-
const clientVersion = 'w16.4.0'
7+
const clientVersion = 'w17.5.0'
88

99
async function printVault(username: string, password: string) {
1010
try {
1111
let auth = new Auth({
1212
host: KeeperEnvironment.DEV,
13-
clientVersion: clientVersion
13+
clientVersion: clientVersion,
14+
deviceConfig: { deviceName: "JS SDK Example" },
1415
})
1516
await auth.loginV3({username, password, loginType: LoginType.NORMAL})
16-
console.log('login successful')
1717

18-
const records = [] as DRecord[]
19-
const storage = {} as VaultStorage
18+
const storage: VaultStorage = {
19+
async put(data) {
20+
if (data.kind === 'record') {
21+
console.log(JSON.stringify(data, null, 2))
22+
}
23+
},
24+
// remaing methods are no-ops
25+
async getDependencies(uid) { return undefined },
26+
async addDependencies() { return },
27+
async removeDependencies() { return },
28+
async clear() { return },
29+
async get(kind, uid) { return undefined },
30+
async delete(kind, uid) { return },
31+
async getKeyBytes() { return undefined },
32+
async saveKeyBytes() {}
33+
}
2034
await syncDown({
2135
auth,
2236
storage,
2337
})
24-
records.forEach(x => console.log(JSON.stringify(x)))
38+
process.exit(0)
2539
} catch (e) {
2640
console.log(e)
41+
process.exit(1)
2742
}
2843
}
2944

examples/print-vault-node/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
},
99
"exclude": [
1010
"node_modules"
11-
]
11+
],
12+
"ts-node": {
13+
"emit": false
14+
}
1215
}

0 commit comments

Comments
 (0)