1.0.3 • Published 10 months ago

wg-easy-wrapper v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

wg-easy-wrapper

Convenient Node module for interacting with the wg-easy API

Installation

Install it from npm:

npm install wg-easy-wrapper

Error Handling

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' }

Usage

Create a new instance of the WGEasyWrapper class

const WGEasyWrapper = require('wg-easy-wrapper');

const wgEasy = new WGEasyWrapper('https://website.com', 'password_example');

Getting the release version

await wgEasy.getRelease();
// 7

Getting a session

await wgEasy.getSession();
// { requiresPassword: true, authenticated: true }

Creating a wg-easy client

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
}*/

Deleting a wg-easy client

await wgEasy.delete('721f6ac2-ab4f-2fz2-v1b4-2gtc93462099');
// { message: 'Deleted' }

Getting wg-easy clients

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
  },
  {
     ...
  }
]*/

Getting wg-easy client configuration

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
*/

Getting wg-easy client qr-code

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>
*/

Enable wg-easy client

await wgEasy.enable('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
// { message: 'Enabled' }

Disable wg-easy client

await wgEasy.disable('f2t3bdbh-b340-4e7d-62f7-651a0122bc62');
// // { message: 'Disabled' }

Rename wg-easy client

await wgEasy.rename('f2t3bdbh-b340-4e7d-62f7-651a0122bc62', 'newName');
// { message: 'Renamed' }

Update wg-easy client address

await wgEasy.updateAddress('f2t3bdbh-b340-4e7d-62f7-651a0122bc62', '10.8.0.1');
// { message: 'Address updated' }

Find wg-easy client

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
}*/

License

This project is licensed under the MIT License. You are free to modify and distribute the code as per the terms of the license.

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago