larvituser
Advanced tools
Comparing version 0.19.1 to 0.20.1
{ | ||
"name": "larvituser", | ||
"version": "0.19.1", | ||
"version": "0.20.1", | ||
"author": { | ||
@@ -11,18 +11,30 @@ "name": "Mikael 'Lilleman' Göransson", | ||
"dependencies": { | ||
"async": "^2.6.1", | ||
"bcryptjs": "^2.4.3", | ||
"larvitamintercom": "^0.3.0", | ||
"larvitamsync": "^0.7.0", | ||
"larvitdbmigration": "^4.0.1", | ||
"larvitutils": "^2.0.0", | ||
"uuid": "^3.3.2" | ||
"bcryptjs": "2.4.3", | ||
"larvitdbmigration": "6.0.0", | ||
"larvitutils": "5.0.0", | ||
"uuid": "8.3.2" | ||
}, | ||
"description": "User module for node.js", | ||
"devDependencies": { | ||
"@istanbuljs/nyc-config-typescript": "1.0.2", | ||
"@types/bcryptjs": "2.4.2", | ||
"@types/mocha": "9.0.0", | ||
"@types/node": "17.0.8", | ||
"@types/uuid": "8.3.4", | ||
"@typescript-eslint/eslint-plugin": "5.9.1", | ||
"@typescript-eslint/parser": "5.9.1", | ||
"eslint": "8.6.0", | ||
"freeport": "1.0.5", | ||
"mocha": "6.2.2", | ||
"mocha-eslint": "5.0.0" | ||
"larvitdb": "3.2.0", | ||
"mocha": "9.1.3", | ||
"mocha-eslint": "7.0.0", | ||
"nyc": "15.1.0", | ||
"ts-node": "10.4.0", | ||
"typescript": "4.5.4" | ||
}, | ||
"scripts": { | ||
"test": "mocha --exit" | ||
"build": "rm -rf dist/* && tsc", | ||
"lint": "eslint src/*.ts test/*.ts", | ||
"test": "npm run lint && npm run test:unit", | ||
"test:unit": "nyc mocha --exit --bail -r ts-node/register 'test/**/*.ts'" | ||
}, | ||
@@ -33,3 +45,6 @@ "keywords": [ | ||
], | ||
"main": "index.js", | ||
"main": "dist/index.js", | ||
"files": [ | ||
"/dist" | ||
], | ||
"repository": { | ||
@@ -36,0 +51,0 @@ "url": "https://github.com/larvit/larvituser", |
173
README.md
@@ -12,13 +12,11 @@ [](https://travis-ci.org/larvit/larvituser) [](https://david-dm.org/larvit/larvituser.svg) | ||
```javascript | ||
const UserLib = require('larvituser'), | ||
Intercom = require('larvitamintercom'), | ||
winston = require('winston'), | ||
log = winston.createLogger({'transports': [new winston.transports.Console()]}), | ||
const UserLib = require('larvituser'), | ||
Intercom = require('larvitamintercom'), | ||
winston = require('winston'), | ||
log = winston.createLogger({'transports': [new winston.transports.Console()]}), | ||
userLib = new UserLib({ | ||
'db': require('larvitdb'), | ||
'db': require('larvitdb'), | ||
// Optional parameters | ||
'mode': 'noSync', // Other options are "master" or "slave" | ||
'intercom': new Intercom({'conStr': 'loopback interface', 'log': log}), | ||
'log': log | ||
'log': log | ||
}); | ||
@@ -33,4 +31,4 @@ | ||
const userData = { | ||
'firstname': 'Nisse', | ||
'lastname': 'Nilsson', | ||
'firstname': 'Nisse', | ||
'lastname': 'Nilsson', | ||
'role': [ | ||
@@ -42,5 +40,4 @@ 'user', | ||
userLib.create('myUsername', 'myPassword', userData, function (err, user) { | ||
console.log('New user UUID: ' + user.uuid); | ||
}); | ||
const user = await userLib.create('myUsername', 'myPassword', userData); | ||
console.log('New user UUID: ' + user.uuid); | ||
``` | ||
@@ -52,7 +49,7 @@ | ||
const uuidLib = require('uuid'); | ||
const uuidLib = require('uuid'); | ||
const uuid = uuidLib.v1(); | ||
const userData = { | ||
'firstname': 'Nisse', | ||
'lastname': 'Nilsson', | ||
'firstname': 'Nisse', | ||
'lastname': 'Nilsson', | ||
'role': [ | ||
@@ -63,6 +60,4 @@ 'user', | ||
} | ||
userLib.create('myUsername', 'myPassword', userData, uuid, function (err, user) { | ||
console.log('New user UUID: ' + user.uuid); | ||
}); | ||
const user = await userLib.create('myUsername', 'myPassword', userData, uuid); | ||
console.log('New user UUID: ' + user.uuid); | ||
``` | ||
@@ -73,13 +68,8 @@ | ||
```javascript | ||
userLib.fromUserAndPass('myUsername', 'myPassword', function (err, user) { | ||
if (err) { | ||
throw err; | ||
} | ||
if ( ! user) { | ||
// No match found, or other more serious error | ||
} else { | ||
console.log('Fetched user ID: ' + user.id); | ||
} | ||
}); | ||
const user = await userLib.fromUserAndPass('myUsername', 'myPassword'); | ||
if ( ! user) { | ||
// No match found, or other more serious error | ||
} else { | ||
console.log('Fetched user ID: ' + user.id); | ||
} | ||
``` | ||
@@ -90,9 +80,6 @@ | ||
```javascript | ||
const users = new UserLib.Users({'db': db, 'log': log}); | ||
const users = new UserLib.Users({'db': db, 'log': log}); | ||
users.get(function (err, userList) { | ||
if (err) throw err; | ||
console.log(userList); // An array of objects | ||
}); | ||
const result = await users.get(); | ||
console.log(result.users); // An array of objects | ||
``` | ||
@@ -103,9 +90,6 @@ | ||
```javascript | ||
const users = new UserLib.Users({'db': db, 'log': log}); | ||
const users = new UserLib.Users({'db': db, 'log': log}); | ||
users.getFieldData('fieldName', function (err, result) { | ||
if (err) throw err; | ||
console.log(userList); // An array of strings | ||
}); | ||
const result = await users.getFieldData('fieldName'); | ||
console.log(result); // An array of strings | ||
``` | ||
@@ -116,3 +100,3 @@ | ||
```javascript | ||
const users = new UserLib.Users({'db': db, 'log': log}); | ||
const users = new UserLib.Users({'db': db, 'log': log}); | ||
@@ -124,7 +108,4 @@ users.order = { | ||
users.get(function (err, userList) { | ||
if (err) throw err; | ||
console.log(userList); // An array of objects | ||
}); | ||
const result = await users.get(); | ||
console.log(result.users); // An array of objects | ||
``` | ||
@@ -137,5 +118,3 @@ | ||
```javascript | ||
userLib.addUserDataField(userUuid, fieldName, fieldValue, function (err) { | ||
// Field have been added | ||
}); | ||
await userLib.addUserDataField(userUuid, fieldName, fieldValue); | ||
``` | ||
@@ -146,5 +125,3 @@ | ||
```javascript | ||
userLib.checkPassword('passwordToTest', 'theHashToTestAgainst', function (err, result) { | ||
// Result being either true or false | ||
}); | ||
const isValid = await userLib.checkPassword('passwordToTest', 'theHashToTestAgainst'); | ||
``` | ||
@@ -155,5 +132,3 @@ | ||
```javascript | ||
userLib.create('username', 'password', {'firstname': 'John', 'lastname': 'Smith'}, function (err, user) { | ||
console.log(user.uuid); // 91f15599-c1fa-4051-9e0e-906cab9819fe (or rather, a random Uuid) | ||
}); | ||
const user = await userLib.create('username', 'password', {'firstname': 'John', 'lastname': 'Smith'});console.log(user.uuid); // 91f15599-c1fa-4051-9e0e-906cab9819fe (or rather, a random Uuid) | ||
``` | ||
@@ -164,5 +139,4 @@ | ||
```javascript | ||
userLib.create('username', 'password', {'firstname': 'John', 'lastname': 'Smith'}, 'f9684592-b245-42fa-88c6-9f16b9236ac3', function (err, user) { | ||
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3 | ||
}); | ||
const user = await userLib.create('username', 'password', {'firstname': 'John', 'lastname': 'Smith'}, 'f9684592-b245-42fa-88c6-9f16b9236ac3'); | ||
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3 | ||
``` | ||
@@ -175,5 +149,4 @@ | ||
```javascript | ||
userLib.fromField('firstname', 'John', function (err, user) { | ||
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3 | ||
}); | ||
const user = await userLib.fromField('firstname', 'John'); | ||
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3 | ||
``` | ||
@@ -186,5 +159,4 @@ | ||
```javascript | ||
userLib.fromFields({'firstname': 'John', 'lastname': 'Smith'}, function (err, user) { | ||
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3 | ||
}); | ||
const user = await userLib.fromFields({'firstname': 'John', 'lastname': 'Smith'}); | ||
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3 | ||
``` | ||
@@ -195,5 +167,4 @@ | ||
```javascript | ||
userLib.fromUsername('username', function (err, user) { | ||
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3 or user will be false if no user is found | ||
}); | ||
const user = await userLib.fromUsername('username'); | ||
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3 or user will be false if no user is found | ||
``` | ||
@@ -204,5 +175,4 @@ | ||
```javascript | ||
userLib.fromUuid('f9684592-b245-42fa-88c6-9f16b9236ac3', function (err, user) { | ||
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3 | ||
}); | ||
const user = await userLib.fromUuid('f9684592-b245-42fa-88c6-9f16b9236ac3'); | ||
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3 | ||
``` | ||
@@ -213,5 +183,4 @@ | ||
```javascript | ||
userLib.getFieldData('f9684592-b245-42fa-88c6-9f16b9236ac3', 'firstname', function (err, data) { | ||
console.log(data); // ['John'] - Observe this will always be an array with values, since a field can hold several values | ||
}); | ||
const data = await userLib.getFieldData('f9684592-b245-42fa-88c6-9f16b9236ac3', 'firstname'); | ||
console.log(data); // ['John'] - Observe this will always be an array with values, since a field can hold several values | ||
``` | ||
@@ -224,10 +193,8 @@ | ||
```javascript | ||
userLib.replaceUserFields('f9684592-b245-42fa-88c6-9f16b9236ac3', {'lastname': ['Smith', 'Johnsson']}, function (err) { | ||
// The field "lastname" will now be replaced with the two values "Smith" and "Johnsson" | ||
// And all other fields will be removed | ||
await userLib.replaceUserFields('f9684592-b245-42fa-88c6-9f16b9236ac3', {'lastname': ['Smith', 'Johnsson']}); | ||
// The field "lastname" will now be replaced with the two values "Smith" and "Johnsson" | ||
// And all other fields will be removed | ||
userLib.getFieldData('f9684592-b245-42fa-88c6-9f16b9236ac3', 'lastname', function (err, data) { | ||
console.log(data); // ['Smith', 'Johnsson'] | ||
}); | ||
}); | ||
const data = await userLib.getFieldData('f9684592-b245-42fa-88c6-9f16b9236ac3', 'lastname'); | ||
console.log(data); // ['Smith', 'Johnsson'] | ||
``` | ||
@@ -238,7 +205,5 @@ | ||
```javascript | ||
userLib.rmUserField('f9684592-b245-42fa-88c6-9f16b9236ac3', 'lastname', function (err) { | ||
userLib.fromUuid('f9684592-b245-42fa-88c6-9f16b9236ac3', function (err, user) { | ||
console.log(user.fields); // {'firstname': ['John']} | ||
}); | ||
}); | ||
await userLib.rmUserField('f9684592-b245-42fa-88c6-9f16b9236ac3', 'lastname'); | ||
const user = await userLib.fromUuid('f9684592-b245-42fa-88c6-9f16b9236ac3'); | ||
console.log(user.fields); // {'firstname': ['John']} | ||
``` | ||
@@ -249,5 +214,3 @@ | ||
```javascript | ||
userLib.setPassword('f9684592-b245-42fa-88c6-9f16b9236ac3', 'newSuperSecretPwd', function (err) { | ||
// Now the users password is updated to "newSuperSecretPwd" | ||
}); | ||
await userLib.setPassword('f9684592-b245-42fa-88c6-9f16b9236ac3', 'newSuperSecretPwd'); | ||
``` | ||
@@ -258,5 +221,3 @@ | ||
```javascript | ||
userLib.setPassword('f9684592-b245-42fa-88c6-9f16b9236ac3', false, function (err) { | ||
// This user can no longer login | ||
}); | ||
await userLib.setPassword('f9684592-b245-42fa-88c6-9f16b9236ac3', false); | ||
``` | ||
@@ -267,10 +228,24 @@ | ||
```javascript | ||
userLib.setUsername('f9684592-b245-42fa-88c6-9f16b9236ac3', 'theNewUsername', function (err) { | ||
// Now the users username is updated to "theNewUsername" | ||
}); | ||
await userLib.setUsername('f9684592-b245-42fa-88c6-9f16b9236ac3', 'theNewUsername'); | ||
``` | ||
### Errors | ||
All functions in the API will throw an exception upon error. | ||
For instance: | ||
```javascript | ||
const user1 = await userLib.create('nisse', false); | ||
const user2 = await userLib.create('olle', false); | ||
try { | ||
await user2.setUsername('nisse'); // Will throw since username "nisse" is already taken | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
``` | ||
## Tests | ||
Run tests with mocha, make sure to have an empty database configured for tests to pass correctly! | ||
Run tests with ```npm test```, make sure to have an empty database configured for tests to pass correctly! | ||
@@ -282,3 +257,3 @@ The default config file will be _application path_/config/db_test.json | ||
```bash | ||
mocha test/test.js /path/to/config/db_another.json | ||
DBCONFFILE=/path/to/config/db_another.json mocha test/test.js | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
97293
4
23
0
15
1276
235
1
+ Added@sindresorhus/is@4.6.0(transitive)
+ Added@szmarczak/http-timer@4.0.6(transitive)
+ Added@types/cacheable-request@6.0.3(transitive)
+ Added@types/http-cache-semantics@4.0.4(transitive)
+ Added@types/keyv@3.1.4(transitive)
+ Added@types/node@22.13.5(transitive)
+ Added@types/responselike@1.0.3(transitive)
+ Addedcacheable-lookup@5.0.4(transitive)
+ Addedcacheable-request@7.0.4(transitive)
+ Addedclone-response@1.0.3(transitive)
+ Addeddecompress-response@6.0.0(transitive)
+ Addeddefer-to-connect@2.0.1(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedget-stream@5.2.0(transitive)
+ Addedgot@11.8.3(transitive)
+ Addedhttp-cache-semantics@4.1.1(transitive)
+ Addedhttp2-wrapper@1.0.3(transitive)
+ Addedjson-buffer@3.0.1(transitive)
+ Addedkeyv@4.5.4(transitive)
+ Addedlarvitdbmigration@6.0.0(transitive)
+ Addedlarvitutils@5.0.0(transitive)
+ Addedlowercase-keys@2.0.0(transitive)
+ Addedmimic-response@1.0.13.1.0(transitive)
+ Addednormalize-url@6.1.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-cancelable@2.1.1(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedquick-lru@5.1.1(transitive)
+ Addedresolve-alpn@1.2.1(transitive)
+ Addedresponselike@2.0.1(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addeduuid@8.3.2(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedasync@^2.6.1
- Removedlarvitamintercom@^0.3.0
- Removedlarvitamsync@^0.7.0
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasync@2.6.43.1.1(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbramqp@0.6.1(transitive)
- Removedbuffer-more-ints@1.0.0(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddenque@1.5.1(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfind-free-port@2.0.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgenerate-function@2.3.1(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removediconv-lite@0.5.2(transitive)
- Removedis-property@1.0.2(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlarvitamintercom@0.3.7(transitive)
- Removedlarvitamsync@0.7.4(transitive)
- Removedlarvitdb@2.1.2(transitive)
- Removedlarvitdbmigration@4.0.3(transitive)
- Removedlarvitutils@2.3.3(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlong@4.0.0(transitive)
- Removedlru-cache@5.1.17.18.3(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedmysql2@1.7.0(transitive)
- Removednamed-placeholders@1.1.3(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpkginfo@0.4.1(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsax@1.4.1(transitive)
- Removedseq-queue@0.0.5(transitive)
- Removedsqlstring@2.3.3(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
- Removedxml2js@0.4.23(transitive)
- Removedxmlbuilder@11.0.1(transitive)
- Removedyallist@3.1.1(transitive)
Updatedbcryptjs@2.4.3
Updatedlarvitdbmigration@6.0.0
Updatedlarvitutils@5.0.0
Updateduuid@8.3.2