Skip to content

Commit 6adffcf

Browse files
committed
v1.0 release
1 parent a1557ee commit 6adffcf

17 files changed

+92
-70
lines changed
File renamed without changes.

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ See:
112112
113113
## History
114114
115-
### master v0.5
115+
### master v1.0 (Nov 28, 2021)
116+
117+
1. ES Module support
118+
1. TypeScript 4.5
119+
1. Wechaty Token Discovery output `JSON.stringify` format
120+
121+
### v0.5 (Sep 8, 2021)
116122
117123
1. Wechaty Token format standard released: `SNI_UUID`
118124
1. `SNI` will be used as Server Indicator Name (SNI) when we are using TLS

bin/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
22
/**
33
* https://github.com/huan/sidecar
44
*

package.json

+28-17
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,33 @@
22
"name": "wechaty-token",
33
"version": "0.5.8",
44
"description": "Wechaty Token Based Authentication Manager",
5-
"main": "dist/src/mod.js",
6-
"typings": "dist/src/mod.d.ts",
5+
"type": "module",
6+
"exports": {
7+
".": {
8+
"import": "./dist/esm/src/mod.js",
9+
"require": "./dist/cjs/src/mod.js"
10+
}
11+
},
12+
"typings": "./dist/esm/src/mod.d.ts",
713
"engines": {
8-
"wechaty": ">=0.60"
14+
"node": ">=16",
15+
"npm": ">=7"
916
},
1017
"bin": {
1118
"wechaty-token": "dist/bin/cli.js"
1219
},
1320
"scripts": {
1421
"clean": "shx rm -fr dist/*",
15-
"dist": "npm run clean && tsc",
16-
"pack": "npm pack",
17-
"start": "ts-node examples/ding-dong-bot.ts",
18-
"lint": "npm run lint:es && npm run lint:ts && npm run lint:md",
22+
"dist": "npm-run-all clean build dist:commonjs",
23+
"build": "tsc && tsc -p tsconfig.cjs.json",
24+
"dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json",
25+
"lint": "npm-run-all lint:es lint:ts lint:md",
26+
"lint:ts": "tsc --isolatedModules --noEmit",
1927
"lint:md": "markdownlint README.md",
20-
"lint:ts": "tsc --noEmit",
2128
"lint:es": "eslint \"src/**/*.ts\" \"tests/**/*.spec.ts\" --ignore-pattern tests/fixtures/",
22-
"test": "npm run lint && npm run test:unit",
29+
"test": "npm-run-all lint test:unit",
2330
"test:pack": "bash -x scripts/npm-pack-testing.sh",
24-
"test:unit": "tap --node-arg=--require=ts-node/register \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\""
31+
"test:unit": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" tap \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\""
2532
},
2633
"repository": {
2734
"type": "git",
@@ -38,16 +45,16 @@
3845
},
3946
"homepage": "https://github.com/wechaty/token#readme",
4047
"devDependencies": {
41-
"@chatie/eslint-config": "^0.12.4",
48+
"@chatie/eslint-config": "^1.0.4",
4249
"@chatie/git-scripts": "^0.6.2",
4350
"@chatie/semver": "^0.4.7",
44-
"@chatie/tsconfig": "^0.16.2",
45-
"@grpc/grpc-js": "^1.3.6",
46-
"@types/uuid": "^8.3.1",
47-
"nock": "^13.1.1",
51+
"@chatie/tsconfig": "^4.6.2",
52+
"@grpc/grpc-js": "^1.4.4",
53+
"@types/uuid": "^8.3.3",
54+
"nock": "^13.2.1",
4855
"pkg-jq": "^0.2.11",
4956
"shx": "^0.3.3",
50-
"tstest": "^0.5.16"
57+
"tstest": "^1.0.1"
5158
},
5259
"publishConfig": {
5360
"access": "public",
@@ -58,11 +65,15 @@
5865
"pre-push": "npx git-scripts-pre-push"
5966
}
6067
},
68+
"files": [
69+
"dist",
70+
"src"
71+
],
6172
"tap": {
6273
"check-coverage": false
6374
},
6475
"dependencies": {
65-
"brolog": "^1.12.4",
76+
"brolog": "^1.14.2",
6677
"cmd-ts": "^0.7.0",
6778
"cockatiel": "^2.0.2",
6879
"uuid": "^8.3.2"

src/cli/discover.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
string,
66
} from 'cmd-ts'
77

8-
import { WechatyToken } from '../wechaty-token'
8+
import { WechatyToken } from '../wechaty-token.js'
99

1010
async function handler (args: any) {
1111
let address

src/cli/generate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
string,
77
} from 'cmd-ts'
88

9-
import { WechatyToken } from '../wechaty-token'
9+
import { WechatyToken } from '../wechaty-token.js'
1010

1111
async function handler (args: any) {
1212
try {

src/grpc-js.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import { ServiceConfig } from '@grpc/grpc-js/build/src/service-config'
2-
import { StatusObject } from '@grpc/grpc-js/build/src/call-stream'
3-
import {
1+
import type { ServiceConfig } from '@grpc/grpc-js/build/src/service-config.js'
2+
import type { StatusObject } from '@grpc/grpc-js/build/src/call-stream.js'
3+
import type {
44
TcpSubchannelAddress,
5-
} from '@grpc/grpc-js/build/src/subchannel'
5+
} from '@grpc/grpc-js/build/src/subchannel-address.js'
66
import {
77
parseUri,
88
uriToString,
9-
GrpcUri,
10-
} from '@grpc/grpc-js/build/src/uri-parser'
11-
import * as resolverManager from '@grpc/grpc-js/build/src/resolver'
12-
import { ChannelOptions } from '@grpc/grpc-js/build/src/channel-options'
13-
import { Metadata } from '@grpc/grpc-js/build/src/metadata'
14-
import { BackoffTimeout } from '@grpc/grpc-js/build/src/backoff-timeout'
9+
type GrpcUri,
10+
} from '@grpc/grpc-js/build/src/uri-parser.js'
11+
import * as resolverManager from '@grpc/grpc-js/build/src/resolver.js'
12+
import type { ChannelOptions } from '@grpc/grpc-js/build/src/channel-options.js'
13+
import { Metadata } from '@grpc/grpc-js/build/src/metadata.js'
14+
import { BackoffTimeout } from '@grpc/grpc-js/build/src/backoff-timeout.js'
1515

1616
import {
1717
status as GrpcStatus,
18-
} from '@grpc/grpc-js'
18+
} from '@grpc/grpc-js'
1919

2020
export {
2121
BackoffTimeout,
2222
ChannelOptions,
2323
GrpcStatus,
24-
GrpcUri,
24+
type GrpcUri,
2525
Metadata,
2626
parseUri,
2727
resolverManager,

src/mod.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { WechatyToken } from './wechaty-token'
2-
import { WechatyResolver } from './resolver-wechaty'
3-
import { VERSION } from './version'
1+
import { WechatyToken } from './wechaty-token.js'
2+
import { WechatyResolver } from './resolver-wechaty.js'
3+
import { VERSION } from './version.js'
44

55
export {
66
VERSION,

src/resolver-wechaty.spec.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env ts-node
1+
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
22

33
import {
44
test,
@@ -11,12 +11,12 @@ import {
1111
TcpSubchannelAddress,
1212
parseUri,
1313
resolverManager,
14-
} from './grpc-js'
14+
} from './grpc-js.js'
1515

16-
import { WechatyToken } from './wechaty-token'
16+
import { WechatyToken } from './wechaty-token.js'
1717
import {
1818
WechatyResolver,
19-
} from './resolver-wechaty'
19+
} from './resolver-wechaty.js'
2020

2121
test('wechaty resolver smoke testing', async t => {
2222
const TOKEN = '__token__'
@@ -33,12 +33,12 @@ test('wechaty resolver smoke testing', async t => {
3333

3434
WechatyResolver.setup()
3535
const target = resolverManager.mapUriDefaultScheme(
36-
parseUri(`wechaty:///${TOKEN}`)!
36+
parseUri(`wechaty:///${TOKEN}`)!,
3737
)!
3838

39-
t.equal(target.authority, '', 'should get empty authority')
40-
t.equal(target.scheme, 'wechaty', 'should get schema')
41-
t.equal(target.path, TOKEN, 'should get token')
39+
t.equal(target.authority, '', 'should get empty authority')
40+
t.equal(target.scheme, 'wechaty', 'should get schema')
41+
t.equal(target.path, TOKEN, 'should get token')
4242

4343
const rr = {} as any
4444
const future = new Promise<TcpSubchannelAddress[]>((resolve, reject) => {
@@ -53,7 +53,7 @@ test('wechaty resolver smoke testing', async t => {
5353
onSuccessfulResolution: (
5454
addressList : TcpSubchannelAddress[],
5555
_serviceConfig : ServiceConfig | null,
56-
_serviceConfigError : StatusObject | null
56+
_serviceConfigError : StatusObject | null,
5757
) => {
5858
// Only handle the first resolution result
5959
listener.onSuccessfulResolution = () => {}
@@ -65,8 +65,8 @@ test('wechaty resolver smoke testing', async t => {
6565

6666
const result = await future
6767

68-
t.same(result[0].host, HOST, 'should get puppet server host')
69-
t.same(result[0].port, PORT, 'should get puppet server port')
68+
t.same(result[0]!.host, HOST, 'should get puppet server host')
69+
t.same(result[0]!.port, PORT, 'should get puppet server port')
7070

7171
sandbox.restore()
7272
})
@@ -96,7 +96,7 @@ test('wechaty resolver with custom authority', async t => {
9696

9797
WechatyResolver.setup()
9898
const target = resolverManager.mapUriDefaultScheme(
99-
parseUri(`wechaty://${AUTHORITY}/token`)!
99+
parseUri(`wechaty://${AUTHORITY}/token`)!,
100100
)!
101101

102102
const listener: resolverManager.ResolverListener = {

src/resolver-wechaty.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
log,
33
DEFAULT_AUTHORITY,
4-
} from './config'
4+
} from './config.js'
55

66
import {
77
ChannelOptions,
@@ -11,9 +11,9 @@ import {
1111
resolverManager,
1212
TcpSubchannelAddress,
1313
uriToString,
14-
} from './grpc-js'
14+
} from './grpc-js.js'
1515

16-
import { WechatyToken } from './wechaty-token'
16+
import { WechatyToken } from './wechaty-token.js'
1717

1818
class WechatyResolver implements resolverManager.Resolver {
1919

@@ -32,7 +32,7 @@ class WechatyResolver implements resolverManager.Resolver {
3232
constructor (
3333
public target: GrpcUri,
3434
public listener: resolverManager.ResolverListener,
35-
public channelOptions: ChannelOptions
35+
public channelOptions: ChannelOptions,
3636
) {
3737
log.verbose('WechatyResolver', 'constructor("%s",)', JSON.stringify(target))
3838
log.silly('WechatyResolver', 'constructor(,,"%s")', JSON.stringify(channelOptions))
@@ -44,7 +44,7 @@ class WechatyResolver implements resolverManager.Resolver {
4444
this.listener.onError({
4545
code: GrpcStatus.UNAVAILABLE,
4646
details: `Wechaty service discovery / resolution failed for target ${uriToString(
47-
this.target
47+
this.target,
4848
)}: ${reason}`,
4949
metadata: new Metadata(),
5050
})
@@ -61,9 +61,9 @@ class WechatyResolver implements resolverManager.Resolver {
6161
token : this.target.path, // `__token__` in `wechaty://api.chatie.io/__token__`
6262
}).discover()
6363
} catch (e) {
64-
log.warn('WechatyResolver', 'updateResolution() wechatyToken.discover() error for target ' + uriToString(this.target) + ' due to error ' + e.message)
64+
log.warn('WechatyResolver', 'updateResolution() wechatyToken.discover() error for target ' + uriToString(this.target) + ' due to error ' + (e as Error).message)
6565
console.error(e)
66-
this.reportResolutionError(e.message)
66+
this.reportResolutionError((e as Error).message)
6767
}
6868

6969
if (!address || !address.port) {
@@ -83,7 +83,7 @@ class WechatyResolver implements resolverManager.Resolver {
8383
null,
8484
null,
8585
null,
86-
{}
86+
{},
8787
)
8888
}
8989

src/retry-policy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55

66
import {
77
log,
8-
} from './config'
8+
} from './config.js'
99

1010
/**
1111
* Create a retry policy that'll try whatever function we execute 3

src/version.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/usr/bin/env ts-node
1+
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
22

33
import { test } from 'tstest'
44

5-
import { VERSION } from './version'
5+
import { VERSION } from './version.js'
66

77
test('Make sure the VERSION is fresh in source code', async t => {
88
t.equal(VERSION, '0.0.0', 'version should be 0.0.0 in source code, only updated before publish to NPM')

src/wechaty-token.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#!/usr/bin/env ts-node
1+
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
22

33
import {
44
test,
55
} from 'tstest'
66

77
import nock from 'nock'
88

9-
import { WechatyToken } from './wechaty-token'
9+
import { WechatyToken } from './wechaty-token.js'
1010

1111
test('WechatyToken sni() & toString()', async t => {
1212
/**

src/wechaty-token.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { v4 } from 'uuid'
66
import {
77
DEFAULT_AUTHORITY,
88
log,
9-
} from './config'
9+
} from './config.js'
1010
import {
1111
VERSION,
12-
} from './version'
12+
} from './version.js'
1313
import {
1414
retryPolicy,
15-
} from './retry-policy'
15+
} from './retry-policy.js'
1616

1717
interface PuppetServiceAddress {
1818
host: string,
@@ -129,10 +129,10 @@ class WechatyToken {
129129

130130
try {
131131
jsonStr = await retryPolicy.execute(
132-
() => this.discoverApi(url)
132+
() => this.discoverApi(url),
133133
)
134134
} catch (e) {
135-
log.warn('WechatyToken', 'discover() retry.execute(discoverApi) fail: %s', e.message)
135+
log.warn('WechatyToken', 'discover() retry.execute(discoverApi) fail: %s', (e as Error).message)
136136
// console.error(e)
137137
return undefined
138138
}

tests/integration.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/usr/bin/env ts-node
1+
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
22

33
import { test } from 'tstest'
44

55
import {
66
WechatyToken,
7-
} from '../src/mod'
7+
} from '../src/mod.js'
88

99
test('integration testing', async t => {
1010
void WechatyToken

tsconfig.cjs.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "CommonJS",
5+
"outDir": "dist/cjs",
6+
},
7+
}

tsconfig.json

-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
"tests/fixtures/",
1010
],
1111
"include": [
12-
"app/**/*.ts",
1312
"bin/*.ts",
14-
"bot/**/*.ts",
1513
"examples/**/*.ts",
1614
"scripts/**/*.ts",
1715
"src/**/*.ts",

0 commit comments

Comments
 (0)