Skip to content

Commit a559774

Browse files
committed
rewrite in typescript
1 parent 61e610c commit a559774

9 files changed

+2912
-362
lines changed

.eslintrc.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"browser": true,
5+
"es6": true,
6+
"node": true,
7+
"mocha": true
8+
},
9+
"parserOptions": {
10+
"ecmaVersion": 2021,
11+
"sourceType": "module",
12+
"ecmaFeatures": {
13+
"jsx": false
14+
}
15+
},
16+
"rules": {
17+
"comma-spacing": [2, { "before": false, "after": true }],
18+
"eqeqeq": 2,
19+
"handle-callback-err": 2,
20+
"indent": ["error", 2, {
21+
"SwitchCase": 1,
22+
"VariableDeclarator": { "var": 2, "let": 2, "const": 3 },
23+
"FunctionDeclaration": { "parameters": "first" },
24+
"FunctionExpression": { "parameters": "first" },
25+
"CallExpression": { "arguments": 1 }
26+
}],
27+
"keyword-spacing": 2,
28+
"max-len": [2, { "code": 99 }],
29+
"no-eq-null": 2,
30+
"no-eval": 2,
31+
"no-tabs": 2,
32+
"no-var": 2,
33+
"semi": 2,
34+
"space-before-blocks": 2,
35+
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}]
36+
},
37+
"plugins": [
38+
"security-node"
39+
],
40+
"extends": [
41+
// "eslint:recommended",
42+
"plugin:security-node/recommended"
43+
],
44+
"ignorePatterns": ["*.d.ts", "*.test.ts", "*.data.js", "packages/platform-irc/index.js"],
45+
"overrides": [
46+
{
47+
"files": [
48+
"**/*.ts"
49+
],
50+
"parser": "@typescript-eslint/parser",
51+
"parserOptions": {
52+
"project": [
53+
"./tsconfig.json"
54+
]
55+
},
56+
"plugins": [
57+
"@typescript-eslint",
58+
"security-node"
59+
]
60+
// "extends": [
61+
// "plugin:@typescript-eslint/recommended"
62+
// ]
63+
}
64+
]
65+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.tmp
33
.idea
4+
dist

README.md

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,41 @@
11
# secure-store-redis
22

3-
A simple wrapper to encrypt and decrypt data stored in redis. The main point is to ensure that any data you store in redis cannot be accessed by anyone else outside of the process, without the key.
3+
A simple wrapper to encrypt and decrypt data stored in redis.
4+
The main point is to ensure that any data you store in redis cannot be accessed
5+
by anyone else, without the key.
6+
7+
8+
**NOTE** version `2.x` is a rewrite in TypeScript, using async functions, and is
9+
backwards incompatible with `1.x`
410

511

612
```javascript
7-
var SecureStore = require('secure-store-redis');
8-
9-
var store = new SecureStore({
10-
namespace: 'myApp:store',
11-
secret: '823HD8DG26JA0LK1239Hgb651TWfs0j1', // must be 32 char secret
12-
errorOnNotFound: true, //optional; will cb error if data can't be found
13-
redis: {
14-
host: 'localhost', // optional
15-
port: 6379, // optional
16-
// optionally use the 'url' property to specify entire redis connect string
17-
// url: 'redis://localhost:6379',
18-
max_clients: 30, // optional
19-
database: 0, // optional
20-
options: {
21-
auth_pass: 'password'
22-
} //options for createClient of node-redis, optional
23-
}
24-
});
13+
const SecureStore = require('secure-store-redis').default;
2514

26-
store.save('quote', 'i see dead people', function (err, reply) {
27-
//...
28-
store.get('quote', function (err, reply) {
29-
// err: null
30-
// reply: 'i see dead people'
31-
});
32-
store.get('quote', function (err, reply) {
33-
// err: record not found
34-
// reply: undefined
35-
});
15+
const store = new SecureStore('myApp:store', '823HD8DG26JA0LK1239Hgb651TWfs0j1', {
16+
host: 'localhost', // optional
17+
port: 6379, // optional
18+
// optionally use the 'url' property to specify entire redis connect string
19+
// url: 'redis://localhost:6379',
3620
});
21+
await store.init();
3722

38-
store.delete('quote', function (err, reply) {
39-
// err: null
40-
// reply: 1
41-
});
23+
await store.save('quote', 'i see dead people');
24+
let res = await store.get('quote');
25+
// res: 'i see dead people'
26+
let res = await store.get('quote');
27+
// res: null
28+
const num = await store.delete('quote');
29+
// num: 1
4230

31+
await store.save('quote', 'i see dead people again');
4332

44-
var otherStore = new SecureStore({
45-
prefix: 'myApp:store',
46-
secret: 'this is the wrong secret',
47-
redis: { // standard redis config object
48-
host: "127.0.0.1",
49-
port: 6379
50-
}
33+
const otherStore = new SecureStore('myApp:store', 'this is the wrong secret', {
34+
host: "127.0.0.1",
35+
port: 6379
5136
});
37+
await otherStore.init();
5238

53-
otherStore.get('quote', function (err, reply) {
54-
// err: record not found
55-
// reply: undefined
56-
});
39+
let res = await otherStore.get('quote');
40+
// res: undefined
5741
```

index.js

Lines changed: 0 additions & 146 deletions
This file was deleted.

0 commit comments

Comments
 (0)