Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
chore: merge develop with master

See merge request prey/js/prey-node-client!1114
  • Loading branch information
beregcamlost committed Nov 21, 2024
2 parents c2687d6 + eaea243 commit d06c0b9
Show file tree
Hide file tree
Showing 149 changed files with 6,626 additions and 20,813 deletions.
10 changes: 0 additions & 10 deletions .npmignore

This file was deleted.

1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

7 changes: 0 additions & 7 deletions .vscode/settings.json

This file was deleted.

17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Change Log

## [v1.13.5](https://github.com/prey/prey-node-client/tree/v1.13.5) (2024-11-21)
[Full Changelog](https://github.com/prey/prey-node-client/compare/v1.13.4..v1.13.5)

- Feat: Adds new `skip permissions` command to instalation by command on MacOS. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji)) ([Javo](https://github.com/javo))

- Fix: Fixes MacOS instalation by command which didn't let device get recognized when there are not slot available. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji)) ([Javo](https://github.com/javo))

- Fix: Fixes a known issue on setting device key. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))

- Fix: Fixes on missing automation handling to be able to set device's status. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))

- Fix: Improvements on weboscket comunnication with our servers. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))

- Feat: New wpxsvc version 2.0.20. Adds funcionality to change database's location. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))

- Feat: New prey-user binary version 1.0.6. Fixes wdutil command error on MacOS 15+ with SSID information and map location. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))

## [v1.13.4](https://github.com/prey/prey-node-client/tree/v1.13.4) (2024-10-29)
[Full Changelog](https://github.com/prey/prey-node-client/compare/v1.13.3..v1.13.4)

Expand Down
Binary file modified bin/prey-user
Binary file not shown.
1 change: 0 additions & 1 deletion delete

This file was deleted.

Binary file modified lib/agent/actions/lock/windows/new-prey-lock.exe
Binary file not shown.
70 changes: 58 additions & 12 deletions lib/agent/control-panel/api/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,49 @@ const common = require('../../../common');

const lang = common.system.lang || 'en';

const set = (key) => {
/**
* Sets an API key for the user.
*
* @param {string} key - the API key to set.
*
* @throws {Error} if an API key is already set.
*
* @returns {string} the API key set.
*/
exports.set = (key) => {
keys.set({ api: key });
return key;
};

// eslint-disable-next-line func-names, consistent-return
const validate = function (data) {
if (!data.policy_rule_privacy_terms) return 'You need to accept the Terms & Conditions and Privacy Policy to continue';
if (!data.policy_rule_age) return 'You must be older than 16 years old to use Prey';
/**
* Validates user input when creating a new account.
*
* @param {Object} data - User input to validate.
*
* @returns {string} An error message if the input is invalid, or nothing if it's valid.
*/
exports.validate = function (data) {
if (!data.policy_rule_privacy_terms) {
return 'You need to accept the Terms & Conditions and Privacy Policy to continue';
}

if (!data.policy_rule_age) {
return 'You must be older than 16 years old to use Prey';
}
};

/**
* Authorizes user with the given credentials.
*
* @param {Object} opts - Credentials to check.
* @param {string} opts.username - Username.
* @param {string} opts.password - Password.
* @param {Function} cb - Callback function.
*
* @throws {Error} if an API key is already set.
*
* @returns {string} the API key set.
*/
exports.authorize = function (opts, cb) {
if (!opts || !opts.username || !opts.password) { throw (errors.arguments('No credentials passed!')); }

Expand All @@ -31,23 +63,37 @@ exports.authorize = function (opts, cb) {
if (body) return cb(errors.unprocessable(body));
cb(errors.get('INVALID_CREDENTIALS'));
} else if ((body && body.key) || (body && body.user && body.user.key)) {
cb(null, set(body.key || body.user.key));
cb(null, exports.set(body.key || body.user.key));
} else {
cb(errors.unknown(resp));
}
});
};

// eslint-disable-next-line consistent-return
/**
* Signs up a new user with the provided data.
*
* @param {Object} data - User input for signup.
* @param {Function} cb - Callback function.
*
* @throws {Error} if the data is empty or an API key is already set.
*
* @returns {void} - Invokes callback with an error or the set API key.
*/
exports.signup = (data, cb) => {
if (!data || Object.keys(data).length === 0) { throw (errors.arguments('Empty data.')); }
if (!data || Object.keys(data).length === 0) {
throw (errors.arguments('Empty data.'));
}

if (keys.get().api) { throw (errors.get('API_KEY_SET')); }
if (keys.get().api) {
throw (errors.get('API_KEY_SET'));
}

const errs = validate(data);
if (errs) { return cb(errors.validation(errs)); }
const errs = exports.validate(data);
if (errs) {
return cb(errors.validation(errs));
}

// eslint-disable-next-line consistent-return
request.post(`/signup.json?lang=${lang}`, data, {}, (err, resp) => {
if (err) return cb(err);

Expand Down
122 changes: 47 additions & 75 deletions lib/agent/control-panel/api/devices.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,74 @@
"use strict";
const keys = require('./keys');
const errors = require('./errors');
const request = require('./request');

var keys = require('./keys'),
errors = require('./errors'),
request = require('./request');

var set = (key) => {
if (!key) throw(new Error('No key!'));
const set = (key) => {
if (!key) throw (new Error('No key!'));
keys.set({ device: key });
return key;
}
};

exports.link = (data, cb) => {
if (!data || Object.keys(data).length == 0)
return cb(errors.arguments('Empty data.'));
if (!data || Object.keys(data).length == 0) return cb(errors.arguments('Empty data.'));

if (keys.get().device)
return cb(errors.get('DEVICE_KEY_SET'));
else if (!keys.get().api)
return cb(errors.get('NO_API_KEY'));
if (keys.get().device) return cb(errors.get('DEVICE_KEY_SET'));
if (!keys.get().api) return cb(errors.get('NO_API_KEY'));

request.post('/devices.json', data, {}, (err, resp) => {
if (err) return cb(err);

var body = resp.body;
const { body } = resp;

if (body && body.key) {
cb(null, set(body.key))

cb(null, set(body.key));
} else if (resp.statusCode == 401) {
cb(errors.get('INVALID_CREDENTIALS'))

cb(errors.get('INVALID_CREDENTIALS'));
} else if (resp.statusCode == 302 || resp.statusCode == 403) {
cb(errors.get('NO_AVAILABLE_SLOTS'));

} else if (resp.statusCode == 422 || body.errors) {
var obj = body.errors || body;
const obj = body.errors || body;
cb(errors.unprocessable(body));

} else {
cb(errors.unknown(resp))
cb(errors.unknown(resp));
}

});
};

exports.unlink = (cb) => {
if (!keys.get().api || !keys.get().device)
return cb(errors.get('MISSING_KEY'));
if (!keys.get().api || !keys.get().device) return cb(errors.get('MISSING_KEY'));

request.delete('/devices/' + keys.get().device, {}, (err, resp) => {
request.delete(`/devices/${keys.get().device}`, {}, (err, resp) => {
if (err) return cb(err);

if (resp.statusCode === 401)
return cb(errors.get('INVALID_CREDENTIALS'))
else if (resp.statusCode !== 200)
return cb(errors.unknown(resp))
if (resp.statusCode === 401) return cb(errors.get('INVALID_CREDENTIALS'));
if (resp.statusCode !== 200) return cb(errors.unknown(resp));

keys.unset('device');
cb();
});
}
};

exports.post_location = (data, cb) => {
if (!keys.get().api || !keys.get().device)
return cb(errors.get('MISSING_KEY'));
if (!keys.get().api || !keys.get().device) return cb(errors.get('MISSING_KEY'));

if (!data)
return cb(errors.arguments('Empty data.'));
if (!data) return cb(errors.arguments('Empty data.'));

request.post('/devices/' + keys.get().device + '/location.json', data, { json: true }, (err, resp) => {
request.post(`/devices/${keys.get().device}/location.json`, data, { json: true }, (err, resp) => {
if (err) return cb(err);

var state = null;
let state = null;

if (resp.statusCode === 401)
return cb(errors.get('INVALID_CREDENTIALS'))
else if (resp.statusCode == 200)
state = true;
else if (resp.statusCode == 201)
state = false;
else return cb(errors.unknown(resp))
if (resp.statusCode === 401) return cb(errors.get('INVALID_CREDENTIALS'));
if (resp.statusCode == 200) state = true;
else if (resp.statusCode == 201) state = false;
else return cb(errors.unknown(resp));

cb(null, state);
});
}
};

exports.post_sso_status = (data, cb) => {
if (!data)
return cb(errors.arguments('Empty data.'));
if (!data) return cb(errors.arguments('Empty data.'));

request.post('/devices/client_configuration', data, { json: true }, (err, resp) => {
if (err) return cb(err);
Expand All @@ -100,25 +81,20 @@ exports.post_sso_status = (data, cb) => {
};

exports.post_missing = (opt, cb) => {
if (!keys.get().api || !keys.get().device)
return cb(errors.get('MISSING_KEY'));
if (!keys.get().api || !keys.get().device) return cb(errors.get('MISSING_KEY'));

if (opt == null || typeof opt != 'boolean')
return cb(new Error("Invalid option for missing action"));
if (opt == null || typeof opt !== 'boolean') return cb(new Error('Invalid option for missing action'));

request.post('/devices/' + keys.get().device + '/missing/' + opt.toString(), null, (err, resp) => {
request.post(`/devices/${keys.get().device}/missing/${opt.toString()}`, null, null, (err, resp) => {
if (err) return cb(err);

if (resp.statusCode === 401)
return cb(errors.get('INVALID_CREDENTIALS'))
else if (resp.statusCode == 201)
return cb(errors.get('SAME_MISSING_STATE'))
else if (resp.statusCode != 200)
return cb(errors.unknown(resp))
if (resp.statusCode === 401) return cb(errors.get('INVALID_CREDENTIALS'));
if (resp.statusCode == 201) return cb(errors.get('SAME_MISSING_STATE'));
if (resp.statusCode != 200) return cb(errors.unknown(resp));

cb(null);
});
}
};

exports.get = {};

Expand All @@ -129,31 +105,27 @@ exports.get.commands = (cb) => {
throw new Error(err);
}

var req = request.get('/devices/' + keys.get().device + '.json', {}, cb);
const req = request.get(`/devices/${keys.get().device}.json`, {}, cb);

if (!cb)
return req;
if (!cb) return req;
};

exports.get.status = (cb) => {
if (!keys.get().device)
return cb(errors.get('NO_DEVICE_KEY'));
if (!keys.get().device) return cb(errors.get('NO_DEVICE_KEY'));

request.get('/devices/' + keys.get().device + '/status.json', {}, cb);
request.get(`/devices/${keys.get().device}/status.json`, {}, cb);
};

exports.get.geofences = (cb) => {
var device_key = keys.get().device;
if (!device_key)
return cb(errors.get('NO_DEVICE_KEY'));
const device_key = keys.get().device;
if (!device_key) return cb(errors.get('NO_DEVICE_KEY'));

request.get('/devices/' + device_key + '/geofencing.json', {}, cb);
request.get(`/devices/${device_key}/geofencing.json`, {}, cb);
};

exports.get.triggers = (cb) => {
var device_key = keys.get().device;
if (!device_key)
return cb(errors.get('NO_DEVICE_KEY'));
const device_key = keys.get().device;
if (!device_key) return cb(errors.get('NO_DEVICE_KEY'));

request.get('/devices/' + device_key + '/triggers.json', {}, cb);
}
request.get(`/devices/${device_key}/triggers.json`, {}, cb);
};
2 changes: 1 addition & 1 deletion lib/agent/control-panel/api/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var capitalize = function(key) {
}

exports.get = function(code) {
if (!list[code]) return new Error(code);
if (!list[code]) return new Error(code);
var err = new Error(list[code]);
err.code = code;
return err;
Expand Down
10 changes: 9 additions & 1 deletion lib/agent/control-panel/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ exports.accounts = require('./accounts');
exports.devices = require('./devices');
exports.push = require('./push');

exports.use = function(obj) {
/**
* Allows to pass a custom logger and/or request client to be used
* across all control-panel api.
*
* @param {Object} obj
* @param {Object} [obj.logger] - A custom logger to use.
* @param {Object} [obj.request] - A custom request client to use.
*/
exports.use = (obj) => {
if (obj.logger) exports.logger.use(obj.logger);
require('./request').use(obj);
}
Loading

0 comments on commit d06c0b9

Please sign in to comment.