Convenient Node module for interacting with the wg-easy API
Install it from npm:
npm install wg-easy-wrapper
When a request encounters an error, the response will contain an object with the variable "error" This object will provide relevant information about the error
Example: { error: 'The name wg-easy is already taken' }
const WGEasyWrapper = require('wg-easy-wrapper');
const wgEasy = new WGEasyWrapper('https://website.com', 'password_example');
await wgEasy.getRelease();
// 7
await wgEasy.getSession();
// { requiresPassword: true, authenticated: true }
await wgEasy.create('newClient');
/*{
id: '721f6ac2-ab4f-2fz2-v1b4-2gtc93462099',
name: 'newClient',
enabled: true,
address: '10.8.0.1',
publicKey: 'a2DdjFEO6fcs4fBGbyNlcaczF2trFkCpjFELcc71Cz0=',
createdAt: '2023-07-18T00:00:00.000Z',
updatedAt: '2023-07-18T00:00:00.000Z',
persistentKeepalive: 'off',
latestHandshakeAt: null,
transferRx: 0,
transferTx: 0
}*/
await wgEasy.delete('721f6ac2-ab4f-2fz2-v1b4-2gtc93462099');
// { message: 'Deleted' }
await wgEasy.getClients();
/*[
{
id: 'f2t3bdbh-b340-4e7d-62f7-651a0122bc62',
name: 'testName',
enabled: true,
address: '10.8.0.0',
publicKey: 'qd2BCXsnsw/USjV92emeexTL5S87mJwU7J85MyjgqW4=',
createdAt: '2023-07-18T00:00:00.000Z',
updatedAt: '2023-07-18T00:00:00.000Z',
persistentKeepalive: 'off',
latestHandshakeAt: null,
transferRx: 0,
transferTx: 0
},
{
...
}
]*/
await wgEasy.getConfig('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
/*
[Interface]
PrivateKey = ...
Address = 10.8.0.0/24
DNS = 1.1.1.1
[Peer]
PublicKey = ...
PresharedKey = ...
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 0
Endpoint = website.com:51820
*/
await wgEasy.getQRCode('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
/*
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 77 77" shape-rendering="crispEdges">
<path fill="#ffffff" d="M0 0h77v77H0z"/>
<path stroke="#000000" d="M4 ... 0h2m2 0h1"/>
</svg>
*/
await wgEasy.enable('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
// { message: 'Enabled' }
await wgEasy.disable('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
// // { message: 'Disabled' }
await wgEasy.rename('f2t3bdbh-b340-4e7d-62f7-651a0122bc62', 'newName');
// { message: 'Renamed' }
await wgEasy.updateAddress('f2t3bdbh-b340-4e7d-62f7-651a0122bc62', '10.8.0.1');
// { message: 'Address updated' }
await wgEasy.find('newName'); // or id or addres
/*{
id: 'f2t3bdbh-b340-4e7d-62f7-651a0122bc62',
name: 'newName',
enabled: true,
address: '10.8.0.0',
publicKey: 'qd2BCXsnsw/USjV92emeexTL5S87mJwU7J85MyjgqW4=',
createdAt: '2023-07-18T00:00:00.000Z',
updatedAt: '2023-07-18T00:00:00.000Z',
persistentKeepalive: 'off',
latestHandshakeAt: null,
transferRx: 0,
transferTx: 0
}*/
This project is licensed under the MIT License. You are free to modify and distribute the code as per the terms of the license.