Skip to content

Commit

Permalink
add support for node.js <18
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna-devv committed Jun 10, 2022
1 parent 746b1c3 commit 6659f27
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ If you need help with the website or the raw API, join the **[Official Support S
All examples are written for **TypeScript**, if you use **JavaScript** please use the COMMONJS import method.

## Install
Download this [npm package](https://www.npmjs.com/package/dlist.js) to use in your project with
Download this [npm package](https://www.npmjs.com/package/dlist.js) to use in your project with the following commands:

If you run **node.js v18 or higher**, use
```bash
# With NPM
npm install dlist.js
# With yarn
yarn add dlist.js
```

For **node.js v17 or lower**, use
```bash
# With NPM
npm install dlist.js node-fetch
# With yarn
yarn add dlist.js node-fetch
```

## Getting Dlist Token
To be able to interact with the api, you have to create a client, in the client's option you have to provide the [discordlist.gg]()-token. <br />

Expand Down Expand Up @@ -58,7 +67,7 @@ If you use this, you have to add the `'webhook'` part in [#Create Dlist Client](

Next, head over to [`https://discordlist.gg/bot/<BOT_ID>/dashboard/webhooks`](https://discordlist.gg/bot/<BOT_ID>/dashboard/webhooks) again and enter your server's IP and Port in the `Webhook URl` field, for example: `http://123.456.78:3000`.

In the `Webhook Authorization` field, create a strong key and treat it like a password, **the same** value has to be entered in the [`#Create Dlist Client`](#Create-Dlist-Client)`.webhhok.authorization` in order to work!
In the `Webhook Authorization` field, create a strong key and treat it like a password, **the same** value has to be entered in the [`#Create Dlist Client`](#Create-Dlist-Client)`.webhook.authorization` in order to work!
```ts
client.on('vote', data => {
console.log(data);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dlist.js",
"description": "An API wrapper for the discordlist.gg api",
"version": "0.2.2",
"version": "0.3.0",
"main": "dist/index.js",
"types": "dist/index.d.js",
"files": [
Expand Down
10 changes: 6 additions & 4 deletions src/client/RestManager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { restManagerOptions, requestOption, requestPayload } from '../typings/restManager';

/**
* The internal request manager
* @param {restManagerOptions}
* @param {restManagerOptions} options
*/
export class RestManager {
constructor(options: restManagerOptions) {
Expand All @@ -25,14 +24,17 @@ export class RestManager {
});
};

const res = await fetch(`https://api.discordlist.gg/v0${path}${params}`, {
let request;
if (Number(process.versions.node.split('.')[0]) < 18) request = require('node-fetch');
else request = fetch;
const res = await request(`https://api.discordlist.gg/v0${path}${params}`, {
method,
headers: {
'Content-Type': 'application/json',
Authorization: this.token
},
body: JSON.stringify(payload?.body || {})
}).catch(error => {
}).catch((error: any) => {
throw new Error(error);
});
const response = await res.json();
Expand Down

0 comments on commit 6659f27

Please sign in to comment.