Skip to content

Commit fedd51d

Browse files
committed
feat: Finalize first version
1 parent 9e30d42 commit fedd51d

20 files changed

+679
-149
lines changed

.github/workflows/publish.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
npm-publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
- uses: actions/setup-node@v1
13+
with:
14+
node-version: 18
15+
- run: npm install
16+
- run: npm run build
17+
- name: Upload Release Asset
18+
id: upload-release-asset
19+
uses: sekwah41/upload-release-assets@v1
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
with:
23+
upload_url: ${{ github.event.release.upload_url }}
24+
asset_path: ./dist/hwt.tar.gz
25+
asset_name: hwt.tar.gz
26+
asset_content_type: application/tar+gzip

index.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
11
import clipboard from 'clipboardy';
2-
import JWT from './src/index.js';
2+
import { program } from 'commander';
33
import chalk from 'chalk';
4+
import Debug from 'debug';
5+
import JWT from './src/index.js';
6+
import { Render } from './src/table.js';
7+
8+
global.debug = Debug('hwt')
49

5-
const input = clipboard.readSync()
610
try {
7-
const result = JWT(input, { format: 'aw' })
11+
program
12+
.option('--raw')
13+
.option('-c, --claims <claims>')
14+
.hook('preAction', (command, actionCommand) => {
15+
const options = command.opts()
16+
let format = 'human'
17+
if (options.raw) {
18+
format = 'raw'
19+
}
20+
if (options.claims) {
21+
command.opts().claims = options.claims.split(',').map(_ => _.trim())
22+
}
23+
command.opts().format = format
24+
})
25+
.action(({ format, claims }) => {
26+
debug('received token:')
27+
const input = clipboard.readSync()
28+
debug(input)
29+
const result = JWT(input, { format, claims })
30+
process.stdout.write(Render(result, { format }) + '\n')
31+
})
32+
.parse()
833
} catch(e) {
9-
process.stdout.write(`😩 Oups ${chalk.red(e.message)}\n`)
34+
debug(e)
35+
let { message } = e
36+
if (e instanceof SyntaxError) {
37+
const input = clipboard.readSync()
38+
message = `The clipboard ${chalk.red('does not contain a JWT')}, here what I got 👇` + '\n'
39+
message += '---' + '\n'
40+
message += input + '\n'
41+
message += '---' + '\n'
42+
} else {
43+
message = '😩 something went wrong: ' + chalk.red(message) + '\n'
44+
}
45+
process.stdout.write(message)
1046
}

package-lock.json

Lines changed: 44 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
{
22
"name": "simple-jwt",
3-
"version": "1.0.0",
4-
"description": "",
3+
"version": "0.0.1",
4+
"description": "A human friendly JWT inspector for your terminal. ",
55
"type": "module",
66
"main": "index.js",
77
"scripts": {
8-
"build": "esbuild index.js --inject:./import-meta-url.js --define:import.meta.url=import_meta_url --sourcemap --bundle --platform=node --outfile=dist/jwt.cjs && pkg --out-path dist --compress GZip dist/jwt.cjs ",
9-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js tests/",
10-
"test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch tests/",
11-
"test:debug": "DEBUG=* node --experimental-vm-modules node_modules/jest/bin/jest.js --watch tests/"
8+
"prebuild": "esbuild index.js --inject:./scripts/import-meta-url.build.js --define:import.meta.url=import_meta_url --sourcemap --bundle --platform=node --outfile=dist/hwt.cjs",
9+
"build": "pkg --out-path dist --compress GZip dist/hwt.cjs ",
10+
"postbuild": "tar -cvzf dist/hwt.tar.gz dist/hwt-*",
11+
"test": "TZ=UTC node --experimental-vm-modules node_modules/jest/bin/jest.js tests/",
12+
"test:watch": "TZ=UTC node --experimental-vm-modules node_modules/jest/bin/jest.js --watch tests/",
13+
"test:debug": "DEBUG=* TZ=UTC node --experimental-vm-modules node_modules/jest/bin/jest.js --watch tests/"
1214
},
1315
"keywords": [],
1416
"author": "Olivier Rodomond",
1517
"license": "ISC",
1618
"dependencies": {
1719
"chalk": "^5.2.0",
1820
"clipboardy": "^3.0.0",
21+
"commander": "^9.4.1",
22+
"console-table-printer": "^2.11.1",
23+
"debug": "^4.3.4",
1924
"moment": "^2.29.4"
2025
},
2126
"devDependencies": {
@@ -24,5 +29,10 @@
2429
"jwt-simple": "^0.5.6",
2530
"pkg": "^5.8.0",
2631
"yaml": "^2.2.1"
32+
},
33+
"jest": {
34+
"moduleNameMapper": {
35+
"#(.*)": "<rootDir>/node_modules/$1"
36+
}
2737
}
2838
}
File renamed without changes.

scripts/install.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echoerr() { echo -e "\n$@\n" 1>&2; }
5+
6+
if [ -z ${HOME+x} ]; then
7+
echoerr "\$HOME is unset, you need to have this variable to use this installer.";
8+
exit 1
9+
fi
10+
11+
if [ "$(uname)" == "Darwin" ]; then
12+
OS=darwin
13+
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
14+
OS=linux
15+
else
16+
echoerr "This installer is only supported on Linux and MacOS"
17+
exit 1
18+
fi
19+
20+
ARCH="$(uname -m)"
21+
if [ "$ARCH" == "x86_64" ]; then
22+
ARCH=x64
23+
fi
24+
25+
mkdir -p $HOME/.local/bin
26+
mkdir -p $HOME/.local/lib
27+
cd $HOME/.local/lib
28+
29+
# @TODO
30+

src/data.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
export default {
2+
"jti": {
3+
"title": "🎫 Token Id",
4+
"comment": "The id of the token",
5+
"order": 1
6+
},
7+
"typ": {
8+
"title": "👮 Type",
9+
"comment": "The authorization header type",
10+
"order": 2
11+
},
12+
"exp": {
13+
"title": "👈 Expirate at",
14+
"comment": "The time when the token will be expired",
15+
"order": 3
16+
},
17+
"iat": {
18+
"title": "👉 Issued at",
19+
"comment": "The time when the token has been issued",
20+
"order": 4
21+
},
22+
"iss": {
23+
"title": "🌐 Issued by",
24+
"comment": "The authority that issued the token",
25+
"order": 5
26+
},
27+
"sub": {
28+
"title": "🤗 User Id",
29+
"comment": "The unique Id of the user identity",
30+
"order": 6
31+
},
32+
"azp": {
33+
"title": "🚂 Client ID",
34+
"comment": "The Unique ID of the Application requesting the current token",
35+
"order": 7
36+
},
37+
"sid": {
38+
"title": "🍬 Session Id",
39+
"comment": "The Unique ID of the current session",
40+
"order": 8
41+
},
42+
"session_state": {
43+
"title": "🍬 Session State",
44+
"comment": "The current state of the session",
45+
"order": 9
46+
},
47+
"scope": {
48+
"title": "🔑 Permissions",
49+
"comment": "The List of permission carried by the jwt",
50+
"order": 10
51+
}
52+
}

src/format/human.js

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

src/format/json.js

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

0 commit comments

Comments
 (0)