larvituser 0.19.1 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -99
- package/dist/dataWriter.d.ts +27 -0
- package/dist/dataWriter.d.ts.map +1 -0
- package/dist/dataWriter.js +205 -0
- package/dist/dataWriter.js.map +1 -0
- package/dist/helpers.d.ts +19 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +59 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +156 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +418 -0
- package/dist/index.js.map +1 -0
- package/dist/userBase.d.ts +53 -0
- package/dist/userBase.d.ts.map +1 -0
- package/dist/userBase.js +120 -0
- package/dist/userBase.js.map +1 -0
- package/dist/users.d.ts +43 -0
- package/dist/users.d.ts.map +1 -0
- package/dist/users.js +186 -0
- package/dist/users.js.map +1 -0
- package/package.json +27 -12
- package/.eslintignore +0 -1
- package/.eslintrc +0 -35
- package/.travis.yml +0 -22
- package/config/db_travis.json +0 -9
- package/dataWriter.js +0 -716
- package/dbmigration/1.sql +0 -33
- package/dbmigration/2.js +0 -63
- package/helpers.js +0 -110
- package/index.js +0 -956
- package/renovate.json +0 -9
- package/test/00test.js +0 -872
- package/test/98lint.js +0 -9
- package/users.js +0 -281
package/dbmigration/1.sql
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
CREATE TABLE IF NOT EXISTS `user_data_fields` (
|
|
2
|
-
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
|
3
|
-
`name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
|
|
4
|
-
PRIMARY KEY (`id`),
|
|
5
|
-
UNIQUE KEY `name` (`name`)
|
|
6
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
7
|
-
|
|
8
|
-
CREATE TABLE IF NOT EXISTS `user_roles_rights` (
|
|
9
|
-
`role` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
|
|
10
|
-
`uri` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
|
|
11
|
-
PRIMARY KEY (`role`,`uri`)
|
|
12
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
13
|
-
|
|
14
|
-
CREATE TABLE IF NOT EXISTS `user_users` (
|
|
15
|
-
`uuid` binary(16) NOT NULL,
|
|
16
|
-
`username` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
|
|
17
|
-
`password` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
|
|
18
|
-
PRIMARY KEY (`uuid`),
|
|
19
|
-
UNIQUE KEY `username` (`username`)
|
|
20
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
21
|
-
|
|
22
|
-
CREATE TABLE IF NOT EXISTS `user_users_data` (
|
|
23
|
-
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
|
24
|
-
`userUuid` binary(16) NOT NULL,
|
|
25
|
-
`fieldId` int(11) unsigned NOT NULL,
|
|
26
|
-
`data` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
|
27
|
-
PRIMARY KEY (`id`),
|
|
28
|
-
KEY `userUuid` (`userUuid`),
|
|
29
|
-
KEY `fieldId` (`fieldId`),
|
|
30
|
-
KEY `userUuid_fieldId` (`userUuid`,`fieldId`),
|
|
31
|
-
CONSTRAINT `user_users_data_ibfk_1` FOREIGN KEY (`userUuid`) REFERENCES `user_users` (`uuid`),
|
|
32
|
-
CONSTRAINT `user_users_data_ibfk_2` FOREIGN KEY (`fieldId`) REFERENCES `user_data_fields` (`id`)
|
|
33
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
package/dbmigration/2.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const uuidLib = require('uuid'),
|
|
4
|
-
async = require('async'),
|
|
5
|
-
db = require('larvitdb');
|
|
6
|
-
|
|
7
|
-
exports = module.exports = function (cb) {
|
|
8
|
-
const tasks = [];
|
|
9
|
-
|
|
10
|
-
/* Create example data to test this migration against existing data * /
|
|
11
|
-
let userUuid = uuidLib.v1();
|
|
12
|
-
let username = 'fomme';
|
|
13
|
-
tasks.push(function (cb) {
|
|
14
|
-
db.query('INSERT INTO user_data_fields (name) VALUES(\'foo\'),(\'bar\');', cb);
|
|
15
|
-
});
|
|
16
|
-
tasks.push(function (cb) {
|
|
17
|
-
db.query('INSERT INTO user_users (uuid, username, password) VALUES(UNHEX(?),?,?);', [userUuid.replace(/-/g, ''), username, 'false'], cb);
|
|
18
|
-
});
|
|
19
|
-
tasks.push(function (cb) {
|
|
20
|
-
const sql = 'INSERT INTO user_users_data (userUuid, fieldId, data) SELECT UNHEX(\'' + userUuid.replace(/-/g, '') + '\'), id, \'mepp\' FROM user_data_fields WHERE name = \'foo\';';
|
|
21
|
-
|
|
22
|
-
db.query(sql, cb);
|
|
23
|
-
});
|
|
24
|
-
tasks.push(function (cb) {
|
|
25
|
-
const sql = 'INSERT INTO user_users_data (userUuid, fieldId, data) SELECT UNHEX(\'' + userUuid.replace(/-/g, '') + '\'), id, \'waff\' FROM user_data_fields WHERE name = \'bar\';';
|
|
26
|
-
|
|
27
|
-
db.query(sql, cb);
|
|
28
|
-
});/**/
|
|
29
|
-
|
|
30
|
-
// Migrate stuff
|
|
31
|
-
tasks.push(function (cb) {
|
|
32
|
-
db.query('ALTER TABLE `user_data_fields` ADD `uuid` binary(16) NOT NULL FIRST;', cb);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
tasks.push(function (cb) {
|
|
36
|
-
db.query('SELECT id, name FROM user_data_fields', function (err, rows) {
|
|
37
|
-
const tasks = [];
|
|
38
|
-
|
|
39
|
-
if (err) { cb(err); return; }
|
|
40
|
-
|
|
41
|
-
for (let i = 0; rows[i] !== undefined; i ++) {
|
|
42
|
-
const row = rows[i];
|
|
43
|
-
|
|
44
|
-
tasks.push(function (cb) {
|
|
45
|
-
db.query('UPDATE user_data_fields SET uuid = UNHEX(?) WHERE id = ?;', [uuidLib.v1().replace(/-/g, ''), row.id], cb);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async.parallel(tasks, cb);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
tasks.push(function (cb) { db.query('ALTER TABLE `user_users_data` ADD `fieldUuid` binary(16) NOT NULL AFTER `userUuid`;', cb); });
|
|
54
|
-
tasks.push(function (cb) { db.query('UPDATE user_users_data uud SET fieldUuid = (SELECT uuid FROM user_data_fields WHERE id = uud.fieldId)', cb); });
|
|
55
|
-
tasks.push(function (cb) { db.query('ALTER TABLE `user_users_data` DROP FOREIGN KEY `user_users_data_ibfk_2`;', cb); });
|
|
56
|
-
tasks.push(function (cb) { db.query('ALTER TABLE `user_users_data` DROP `id`, DROP `fieldId`;', cb); });
|
|
57
|
-
tasks.push(function (cb) { db.query('ALTER TABLE `user_data_fields` DROP `id`;', cb); });
|
|
58
|
-
tasks.push(function (cb) { db.query('ALTER TABLE `user_data_fields` ADD PRIMARY KEY `uuid` (`uuid`);', cb); });
|
|
59
|
-
tasks.push(function (cb) { db.query('ALTER TABLE `user_users_data` ADD FOREIGN KEY (`fieldUuid`) REFERENCES `user_data_fields` (`uuid`) ON DELETE NO ACTION ON UPDATE NO ACTION;', cb); });
|
|
60
|
-
tasks.push(function (cb) { db.query('ALTER TABLE `user_users_data` DROP INDEX `userUuid_fieldId`;', cb); });
|
|
61
|
-
|
|
62
|
-
async.series(tasks, cb);
|
|
63
|
-
};
|
package/helpers.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const topLogPrefix = 'larvituser: helpers.js - ',
|
|
4
|
-
LUtils = require('larvitutils');
|
|
5
|
-
|
|
6
|
-
function Helpers(options) {
|
|
7
|
-
const logPrefix = topLogPrefix + 'Helpers() - ',
|
|
8
|
-
that = this;
|
|
9
|
-
|
|
10
|
-
if ( ! options.log) {
|
|
11
|
-
const tmpLUtils = new LUtils();
|
|
12
|
-
options.log = new tmpLUtils.Log();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
that.options = options;
|
|
16
|
-
|
|
17
|
-
for (const key of Object.keys(options)) {
|
|
18
|
-
that[key] = options[key];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
that.lUtils = new LUtils({'log': that.log});
|
|
22
|
-
|
|
23
|
-
if ( ! that.log) {
|
|
24
|
-
const err = new Error('Required option log not set');
|
|
25
|
-
that.log.error(logPrefix + err.message);
|
|
26
|
-
throw err;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if ( ! that.dataWriter) {
|
|
30
|
-
const err = new Error('Required option dataWriter not set');
|
|
31
|
-
that.log.error(logPrefix + err.message);
|
|
32
|
-
throw err;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if ( ! that.db) {
|
|
36
|
-
const err = new Error('Required option db not set');
|
|
37
|
-
that.log.error(logPrefix + err.message);
|
|
38
|
-
throw err;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get field name by uuid
|
|
44
|
-
*
|
|
45
|
-
* @param str uuid
|
|
46
|
-
* @param func cb(err, name) - name is false if no match is found
|
|
47
|
-
*/
|
|
48
|
-
Helpers.prototype.getFieldName = function getFieldName(uuid, cb) {
|
|
49
|
-
const fieldUuidBuffer = this.lUtils.uuidToBuffer(uuid),
|
|
50
|
-
logPrefix = topLogPrefix + 'getFieldName() - ',
|
|
51
|
-
that = this,
|
|
52
|
-
sql = 'SELECT name FROM user_data_fields WHERE uuid = ?';
|
|
53
|
-
|
|
54
|
-
if (fieldUuidBuffer === false) {
|
|
55
|
-
const err = new Error('Invalid field uuid');
|
|
56
|
-
that.log.verbose(logPrefix + err.message);
|
|
57
|
-
return cb(err);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
that.db.query(sql, [fieldUuidBuffer], function (err, rows) {
|
|
61
|
-
if (err) return cb(err);
|
|
62
|
-
|
|
63
|
-
if (rows.length) {
|
|
64
|
-
cb(null, rows[0].name);
|
|
65
|
-
} else {
|
|
66
|
-
cb(null, false);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Get data field uuid by field name
|
|
73
|
-
*
|
|
74
|
-
* @param str fieldName
|
|
75
|
-
* @param func cb(err, uuid)
|
|
76
|
-
*/
|
|
77
|
-
Helpers.prototype.getFieldUuid = function getFieldUuid(fieldName, cb) {
|
|
78
|
-
const dbFields = [],
|
|
79
|
-
that = this,
|
|
80
|
-
sql = 'SELECT uuid FROM user_data_fields WHERE name = ?';
|
|
81
|
-
|
|
82
|
-
fieldName = fieldName.trim();
|
|
83
|
-
dbFields.push(fieldName);
|
|
84
|
-
|
|
85
|
-
that.db.query(sql, dbFields, function (err, rows) {
|
|
86
|
-
if (err) return cb(err);
|
|
87
|
-
|
|
88
|
-
if (rows.length) {
|
|
89
|
-
cb(null, that.lUtils.formatUuid(rows[0].uuid));
|
|
90
|
-
} else {
|
|
91
|
-
const options = {'exchange': that.dataWriter.exchangeName},
|
|
92
|
-
sendObj = {};
|
|
93
|
-
|
|
94
|
-
sendObj.action = 'addUserFieldReq';
|
|
95
|
-
sendObj.params = {};
|
|
96
|
-
sendObj.params.name = fieldName;
|
|
97
|
-
|
|
98
|
-
that.dataWriter.intercom.send(sendObj, options, function (err) {
|
|
99
|
-
if (err) return cb(err);
|
|
100
|
-
|
|
101
|
-
that.dataWriter.emitter.once('addedField_' + fieldName, function (err) {
|
|
102
|
-
if (err) return cb(err);
|
|
103
|
-
that.getFieldUuid(fieldName, cb);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
exports = module.exports = Helpers;
|