Skip to content

Commit

Permalink
Release 1.5.2 (#58)
Browse files Browse the repository at this point in the history
* fix for npm publish

* add dry-run publish test

* bump version

* new version

* publish all files

* change ci actions

Co-authored-by: rob9315 <[email protected]>
  • Loading branch information
rob9315 and rob9315 authored Jan 29, 2021
1 parent 81f5b44 commit a4c212e
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 67 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
- run: npm run test
- run: npm publish --dry-run
69 changes: 35 additions & 34 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
name: npm-publish
on:
push:
branches:
- master # Change this to your default branch
jobs:
npm-publish:
name: npm-publish
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Set up Node.js
uses: actions/setup-node@master
with:
node-version: 14.0.0
- name: Install
run: npm install
- id: publish
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_AUTH_TOKEN }}
- name: Create Release
if: steps.publish.outputs.type != 'none'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.publish.outputs.version }}
release_name: Release ${{ steps.publish.outputs.version }}
body: ${{ steps.publish.outputs.version }}
draft: false
prerelease: false
name: npm-publish
on:
push:
branches:
- master # Change this to your default branch
jobs:
npm-publish:
name: npm-publish
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Set up Node.js
uses: actions/setup-node@master
with:
node-version: 14.0.0
- name: Install
run: npm install && npm run build
- id: publish
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_AUTH_TOKEN }}
- name: Create Release
if: steps.publish.outputs.type != 'none'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.publish.outputs.version }}
release_name: Release ${{ steps.publish.outputs.version }}
body: ${{ steps.publish.outputs.version }}
draft: false
prerelease: false

4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/*
npm-debug.log
package-lock.json
yarn.lock
4 changes: 2 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## History

## 1.5.1
## 1.5.2
* Fix the release

## 1.5.0
* Add async support and typings with typescript and convert to node-fetch (thanks @Rob9315)
* Add async support and typings with typescript and convert to node-fetch (thanks @Rob9315)

## 1.4.0
* Add ability to request user from token refresh (thanks @ph0t0shop)
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "yggdrasil",
"version": "1.5.1",
"version": "1.5.2",
"author": "Zeke Sonxx <[email protected]>",
"description": "Mojang authentication (Yggdrasil) client",
"scripts": {
"build": "tsc",
"test": "mocha -R spec",
"pretest": "npm run lint && npm run build",
"prepublish": "npm run lint && npm run build",
"lint": "ts-standard",
"fix": "ts-standard --fix",
"build": "npx tsc"
"fix": "ts-standard --fix"
},
"main": "./lib/index",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/PrismarineJS/node-yggdrasil.git"
Expand Down
11 changes: 6 additions & 5 deletions src/Client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import uuid from 'uuid'
import * as utils from './utils.js'
import type { Agent } from 'http'

const defaultHost = 'https://authserver.mojang.com'

Expand All @@ -16,7 +17,7 @@ const Client = {
options.agent = options.agent ?? 'Minecraft'

return await utils.call(
this?.host ?? defaultHost,
(this as any)?.host as string ?? defaultHost,
'authenticate',
{
agent: {
Expand All @@ -28,7 +29,7 @@ const Client = {
clientToken: options.token,
requestUser: options.requestUser === true
},
this?.agent
(this as any)?.agent as Agent
)
},
/**
Expand All @@ -39,7 +40,7 @@ const Client = {
* @param {Function} cb (err, new token, full response body)
*/
refresh: async function (accessToken: string, clientToken: string, requestUser?: boolean) {
const data = await utils.call(this?.host as string ?? defaultHost, 'refresh', { accessToken, clientToken, requestUser: requestUser ?? false }, this?.agent)
const data = await utils.call((this as any)?.host as string ?? defaultHost, 'refresh', { accessToken, clientToken, requestUser: requestUser ?? false }, (this as any)?.agent as Agent)
if (data.clientToken !== clientToken) throw new Error('clientToken assertion failed')
return [data.accessToken, data]
},
Expand All @@ -49,7 +50,7 @@ const Client = {
* @param {Function} cb (error)
*/
validate: async function (accessToken: string) {
return await utils.call(this?.host as string ?? defaultHost, 'validate', { accessToken }, this?.agent)
return await utils.call((this as any)?.host as string ?? defaultHost, 'validate', { accessToken }, (this as any)?.agent as Agent)
},

/**
Expand All @@ -59,7 +60,7 @@ const Client = {
* @param {Function} cb (error)
*/
signout: async function (username: string, password: string) {
return await utils.call(this?.host as string ?? defaultHost, 'signout', { username, password }, this?.agent)
return await utils.call((this as any)?.host as string ?? defaultHost, 'signout', { username, password }, (this as any)?.agent as Agent)
}
}

Expand Down
16 changes: 9 additions & 7 deletions src/Server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import crypto from 'crypto'
import { createHash } from 'crypto'
import utils from './utils.js'
import nf from 'node-fetch'
import type { Agent } from 'http'

const defaultHost = 'https://sessionserver.mojang.com'

Expand All @@ -18,14 +19,15 @@ const Server = {
*/
join: async function (accessToken: string, selectedProfile: string, serverid: string, sharedsecret: string, serverkey: string) {
return await utils.call(
this?.host as string ?? defaultHost,
(this as any)?.host as string ??
defaultHost,
'session/minecraft/join',
{
accessToken,
selectedProfile,
serverId: utils.mcHexDigest(crypto.createHash('sha1').update(serverid).update(sharedsecret).update(serverkey).digest())
serverId: utils.mcHexDigest(createHash('sha1').update(serverid).update(sharedsecret).update(serverkey).digest())
},
this?.agent
(this as any)?.agent as Agent
)
},

Expand All @@ -39,9 +41,9 @@ const Server = {
* @async
*/
hasJoined: async function (username: string, serverid: string, sharedsecret: string, serverkey: string) {
const host: string = this?.host as string ?? defaultHost
const hash: string = utils.mcHexDigest(crypto.createHash('sha1').update(serverid).update(sharedsecret).update(serverkey).digest())
const data = await nf(`${host}/session/minecraft/hasJoined?username=${username}&serverId=${hash}`, { agent: this?.agent, method: 'GET' })
const host: string = (this as any)?.host as string ?? defaultHost
const hash: string = utils.mcHexDigest(createHash('sha1').update(serverid).update(sharedsecret).update(serverkey).digest())
const data = await nf(`${host}/session/minecraft/hasJoined?username=${username}&serverId=${hash}`, { agent: (this as any)?.agent as Agent, method: 'GET' })
const body = JSON.parse(await data.text())
if (body.id !== undefined) return body
else throw new Error('Failed to verify username!')
Expand Down
34 changes: 21 additions & 13 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
{
"compilerOptions": {
"target": "es2019",
"module": "CommonJS",
"strict": true,
"target": "ES2020",
"module": "commonjs",
"sourceMap": true,
"declaration": true,
// "resolveJsonModule": true, because of ts-standard had to disable...
"strict": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true,
"types": ["node"],
"outDir": "lib",
"noImplicitThis": false
},
"include": [
"src"
],
"exclude": [
"lib","node_modules"
]
}
"removeComments": false
},
"compileOnSave": true,
"include": [
"./src/**/*",
"./test/**/*"
],
"exclude": [
"lib",
"node_modules",
"bin",
"examples",
"scripts"
],
}

0 comments on commit a4c212e

Please sign in to comment.