Skip to content
This repository was archived by the owner on Mar 29, 2025. It is now read-only.

Commit 3f46fa1

Browse files
authored
fix(typescript): avoid object type (#36)
1 parent d2a5e22 commit 3f46fa1

File tree

5 files changed

+43
-18
lines changed

5 files changed

+43
-18
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ jobs:
2424
check-latest: true
2525
- run: npm clean-install
2626
- run: npm run test
27+
- run: npm run test-types

package-lock.json

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
],
3030
"scripts": {
3131
"test": "ava",
32+
"test-types": "tsc --project types",
3233
"watch": "ava --watch"
3334
},
3435
"ava": {
@@ -39,7 +40,8 @@
3940
"devDependencies": {
4041
"@types/node": "^16.4.0",
4142
"ava": "^3.15.0",
42-
"sinon": "^11.1.2"
43+
"sinon": "^11.1.2",
44+
"typescript": "^3.6.0"
4345
},
4446
"engines": {
4547
"node": ">=16.0.0"

types/index.d.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface ProduceOptions {
55
assertion?: string | Buffer
66
audience?: string
77
expiresIn?: string
8-
footer?: object | string | Buffer
8+
footer?: Record<PropertyKey, unknown> | string | Buffer
99
iat?: boolean
1010
issuer?: string
1111
jti?: string
@@ -30,7 +30,7 @@ export interface ConsumeOptions<TComplete extends boolean> {
3030
}
3131
export interface CompleteResult {
3232
footer?: Buffer
33-
payload: object
33+
payload: Record<string, unknown>
3434
purpose: 'local' | 'public'
3535
version: string
3636
}
@@ -47,7 +47,7 @@ export interface CompleteResultBuffer {
4747
}
4848
export interface DecodeResult {
4949
footer?: Buffer
50-
payload?: object
50+
payload?: Record<string, unknown>
5151
purpose: 'local' | 'public'
5252
version: string
5353
}
@@ -60,20 +60,20 @@ export interface DecodeResultBuffer {
6060
export function decode(token: string): DecodeResult
6161
export namespace V1 {
6262
function sign(
63-
payload: object | Buffer,
63+
payload: Record<PropertyKey, unknown> | Buffer,
6464
key: KeyObject | Buffer | PrivateKeyInput | JsonWebKeyInput | string,
6565
options?: Omit<ProduceOptions, 'assertion'>,
6666
): Promise<string>
6767
function encrypt(
68-
payload: object | Buffer,
68+
payload: Record<PropertyKey, unknown> | Buffer,
6969
key: KeyObject | Buffer | string,
7070
options?: Omit<ProduceOptions, 'assertion'>,
7171
): Promise<string>
7272
function verify(
7373
token: string,
7474
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
7575
options?: Omit<ConsumeOptions<false>, 'assertion'>,
76-
): Promise<object>
76+
): Promise<Record<string, unknown>>
7777
function verify(
7878
token: string,
7979
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
@@ -93,7 +93,7 @@ export namespace V1 {
9393
token: string,
9494
key: KeyObject | Buffer | string,
9595
options?: Omit<ConsumeOptions<false>, 'assertion'>,
96-
): Promise<object>
96+
): Promise<Record<string, unknown>>
9797
function decrypt(
9898
token: string,
9999
key: KeyObject | Buffer | string,
@@ -116,15 +116,15 @@ export namespace V1 {
116116
}
117117
export namespace V2 {
118118
function sign(
119-
payload: object | Buffer,
119+
payload: Record<PropertyKey, unknown> | Buffer,
120120
key: KeyObject | Buffer | PrivateKeyInput | JsonWebKeyInput | string,
121121
options?: Omit<ProduceOptions, 'assertion'>,
122122
): Promise<string>
123123
function verify(
124124
token: string,
125125
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
126126
options?: Omit<ConsumeOptions<false>, 'assertion'>,
127-
): Promise<object>
127+
): Promise<Record<string, unknown>>
128128
function verify(
129129
token: string,
130130
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
@@ -148,20 +148,20 @@ export namespace V2 {
148148
}
149149
export namespace V3 {
150150
function sign(
151-
payload: object | Buffer,
151+
payload: Record<PropertyKey, unknown> | Buffer,
152152
key: KeyObject | Buffer | PrivateKeyInput | JsonWebKeyInput | string,
153153
options?: ProduceOptions,
154154
): Promise<string>
155155
function encrypt(
156-
payload: object | Buffer,
156+
payload: Record<PropertyKey, unknown> | Buffer,
157157
key: KeyObject | Buffer | string,
158158
options?: ProduceOptions,
159159
): Promise<string>
160160
function verify(
161161
token: string,
162162
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
163163
options?: ConsumeOptions<false>,
164-
): Promise<object>
164+
): Promise<Record<string, unknown>>
165165
function verify(
166166
token: string,
167167
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
@@ -181,7 +181,7 @@ export namespace V3 {
181181
token: string,
182182
key: KeyObject | Buffer | string,
183183
options?: ConsumeOptions<false>,
184-
): Promise<object>
184+
): Promise<Record<string, unknown>>
185185
function decrypt(
186186
token: string,
187187
key: KeyObject | Buffer | string,
@@ -206,15 +206,15 @@ export namespace V3 {
206206
}
207207
export namespace V4 {
208208
function sign(
209-
payload: object | Buffer,
209+
payload: Record<PropertyKey, unknown> | Buffer,
210210
key: KeyObject | Buffer | PrivateKeyInput | JsonWebKeyInput | string,
211211
options?: ProduceOptions,
212212
): Promise<string>
213213
function verify(
214214
token: string,
215215
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
216216
options?: ConsumeOptions<false>,
217-
): Promise<object>
217+
): Promise<Record<string, unknown>>
218218
function verify(
219219
token: string,
220220
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,

types/paseto-tests.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ import * as paseto from './index.d'
121121
a.purpose
122122
a.version
123123

124-
await paseto.V1.decrypt(token, key, {
124+
const b = await paseto.V1.decrypt(token, key, {
125125
audience: 'string',
126126
clockTolerance: '60s',
127127
ignoreExp: true,
@@ -132,5 +132,7 @@ import * as paseto from './index.d'
132132
now: new Date(),
133133
subject: 'string',
134134
})
135+
136+
b['arbitrary claim']
135137
}
136138
})()

0 commit comments

Comments
 (0)