Skip to content

Commit 158866d

Browse files
rob9315rob9315extremeheat
authored
add async and typings with typescript (#54)
* add async and typings with typescript * .gitignore * node 12 * node 12 * redo * fix small mistakes * fix async and history new version * ts-standard (with es6.d.ts TS-STANDARD error) * lint fixes * promise tests * remove the big blob of deprecated code * lint instead of fix Co-authored-by: rob9315 <9315.rob@gmail.com> Co-authored-by: extremeheat <extreme@protonmail.ch>
1 parent 9fda7ea commit 158866d

File tree

20 files changed

+562
-408
lines changed

20 files changed

+562
-408
lines changed

.editorconfig

Lines changed: 0 additions & 12 deletions
This file was deleted.

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.d.ts

.github/workflows/ci.yml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
name: CI
2-
3-
on:
4-
push:
5-
branches: [ master ]
6-
pull_request:
7-
branches: [ master ]
8-
9-
jobs:
10-
build:
11-
12-
runs-on: ubuntu-latest
13-
14-
strategy:
15-
matrix:
16-
node-version: [12.x]
17-
18-
steps:
19-
- uses: actions/checkout@v2
20-
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v1
22-
with:
23-
node-version: ${{ matrix.node-version }}
24-
- run: npm install
25-
- run: npm test
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [14.x]
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v1
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
- run: npm install
25+
- run: npm test

.github/workflows/publish.yml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
name: npm-publish
2-
on:
3-
push:
4-
branches:
5-
- master # Change this to your default branch
6-
jobs:
7-
npm-publish:
8-
name: npm-publish
9-
runs-on: ubuntu-latest
10-
steps:
11-
- name: Checkout repository
12-
uses: actions/checkout@master
13-
- name: Set up Node.js
14-
uses: actions/setup-node@master
15-
with:
16-
node-version: 10.0.0
17-
- name: Publish if version has been updated
18-
uses: pascalgn/npm-publish-action@4f4bf159e299f65d21cd1cbd96fc5d53228036df
19-
with: # All of theses inputs are optional
20-
tag_name: "%s"
21-
tag_message: "%s"
22-
commit_pattern: "^Release (\\S+)"
23-
env: # More info about the environment variables in the README
24-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this as is, it's automatically generated
25-
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # You need to set this in your repo settings
1+
name: npm-publish
2+
on:
3+
push:
4+
branches:
5+
- master # Change this to your default branch
6+
jobs:
7+
npm-publish:
8+
name: npm-publish
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@master
13+
- name: Set up Node.js
14+
uses: actions/setup-node@master
15+
with:
16+
node-version: 10.0.0
17+
- name: Publish if version has been updated
18+
uses: pascalgn/npm-publish-action@4f4bf159e299f65d21cd1cbd96fc5d53228036df
19+
with: # All of theses inputs are optional
20+
tag_name: "%s"
21+
tag_message: "%s"
22+
commit_pattern: "^Release (\\S+)"
23+
env: # More info about the environment variables in the README
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this as is, it's automatically generated
25+
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # You need to set this in your repo settings

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/*
22
npm-debug.log
33
package-lock.json
44
yarn.lock
5+
lib

HISTORY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## History
22

3+
## 1.5.0
4+
* Add async support and typings with typescript and convert to node-fetch (thanks @Rob9315)
5+
36
## 1.4.0
47
* Add ability to request user from token refresh (thanks @ph0t0shop)
58

README.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,29 @@ ygg.auth({
2828
user: '', //Username
2929
pass: '', //Password
3030
requestUser: false //Optional. Request the user object to be included in response
31-
}, function(err, data){});
31+
}).then(
32+
(response)=>{},
33+
(error)=>{}
34+
);
3235

3336
//Refresh an accessToken
34-
ygg.refresh(oldtoken, clienttoken, true, function(err, newtoken, response body){});
37+
ygg.refresh(oldAccessToken, clientToken, true).then(
38+
({accessToken, clientToken, user?})=>{},
39+
(error)=>{}
40+
);
3541
// Note that requestUser is an optional parameter. If set to true, it requests the user object from Mojang's authentication servers as well.
3642

3743
//Validate an accessToken
38-
ygg.validate(token, function(err){});
44+
ygg.validate(token).then(
45+
(response)=>{},
46+
(error)=>{}
47+
);
3948

4049
//Invalidate all accessTokens
41-
ygg.signout(username, password, function(err));
50+
ygg.signout(username, password).then(
51+
(response)=>{},
52+
(error)=>{}
53+
);
4254
```
4355
4456
## Server
@@ -49,10 +61,16 @@ const yggserver = require('yggdrasil').server({
4961
});
5062

5163
//Join a server (clientside)
52-
yggserver.join(token, profile, serverid, sharedsecret, serverkey, function(err, response body){});
64+
yggserver.join(token, profile, serverid, sharedsecret, serverkey).then(
65+
(response)=>{},
66+
(error)=>{}
67+
);
5368

5469
//Join a server (serverside)
55-
yggserver.hasJoined(username, serverid, sharedsecret, serverkey, function(err, client info){});
70+
yggserver.hasJoined(username, serverid, sharedsecret, serverkey).then(
71+
(clientInfo)=>{},
72+
(error)=>{}
73+
);
5674
```
5775
## Proxy Support
5876
```js
@@ -69,14 +87,21 @@ const ygg = require('yggdrasil')({
6987
/**
7088
* Import Client or Server from 'yggdrasil/es6'.
7189
* Note that the library is stateless when imported this way vs the CommonJS way.
90+
* You have typings though ;D
7291
*/
7392
import { Client as ygg, Server as yggServ } from 'yggdrasil/es6'
7493

7594
// Use it like you normally would.
7695

77-
ygg.validate(token, function(err){})
96+
ygg.validate(token).then(
97+
(response)=>{},
98+
(error)=>{}
99+
);
78100

79-
yggServ.join(token, profile, serverid, sharedsecret, serverkey, function(err, response body){});
101+
yggServ.join(token, profile, serverid, sharedsecret, serverkey).then(
102+
response=>{},
103+
error=>{}
104+
);
80105
```
81106
82107
# Further Reading

es6.d.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
interface authOptions{
2-
token?: String,
3-
agent?: String,
4-
user: String,
5-
pass: String,
6-
requestUser?: boolean
7-
}
8-
9-
export const Client: {
10-
auth(options: authOptions, cb: (err?: Error, data?: any)=>any): void
11-
refresh(access: String, client: String, requestUser: any, cb: (err?:Error, data?:any)=>any): void
12-
validate(token: String, cb: (err?:Error)=>any): void
13-
signout(user: String, pass: String, cb: (err?:Error)=>any): void
14-
}
15-
16-
export const Server: {
17-
join(token: String, profile: String, serverid: String, sharedsecret: String, serverkey: String, cb: (err?:Error, data?:any)=>any): void
18-
hasJoined(username: String, serverid: String, sharedsecret: String, serverkey: String, cb: (err?:Error, body?:any)=>any): void
19-
}
1+
import Client from './lib/Client'
2+
import Server from './lib/Server'
3+
export { Client, Server }

es6.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
'use strict'
2-
3-
const Client = require('./lib/Client')
4-
const Server = require('./lib/Server')
5-
6-
module.exports = { Client, Server }
1+
// @ts-nocheck
2+
'use strict'
3+
4+
const Client = require('./lib/Client')
5+
const Server = require('./lib/Server')
6+
7+
module.exports = { Client, Server }

lib/Client.js

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)