Skip to content

Commit 9f4c2f3

Browse files
authored
fix(scopeToken): return token from response, not options. Also fix options type (#7)
1 parent 1fc4039 commit 9f4c2f3

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

src/scope-token.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,35 @@ import btoa from "btoa-lite";
44

55
import { GitHubAppAuthentication } from "./types";
66

7-
type TargetOption =
8-
| {
9-
target: string;
10-
}
11-
| {
12-
target_id: number;
13-
};
14-
type RepositoriesOption =
15-
| {
16-
repositories?: string[];
17-
}
18-
| {
19-
repository_ids?: number[];
20-
};
21-
type Endpoint = Endpoints["POST /applications/{client_id}/token/scoped"];
22-
23-
export type ScopeTokenOptions = {
7+
type CommonOptions = {
248
clientType: "github-app";
259
clientId: string;
2610
clientSecret: string;
2711
token: string;
2812
permissions?: Endpoint["parameters"]["permissions"];
2913
request?: RequestInterface;
30-
} & TargetOption &
31-
RepositoriesOption;
14+
};
15+
16+
type TargetOption = {
17+
target: string;
18+
};
19+
type TargetIdOption = {
20+
target_id: number;
21+
};
22+
type RepositoriesOption = {
23+
repositories?: string[];
24+
};
25+
type RepositoryIdsOption = {
26+
repository_ids?: number[];
27+
};
28+
29+
type Endpoint = Endpoints["POST /applications/{client_id}/token/scoped"];
30+
31+
export type ScopeTokenOptions =
32+
| (CommonOptions & TargetOption & RepositoriesOption)
33+
| (CommonOptions & TargetIdOption & RepositoriesOption)
34+
| (CommonOptions & TargetOption & RepositoryIdsOption)
35+
| (CommonOptions & TargetIdOption & RepositoryIdsOption);
3236

3337
export type ScopeTokenResponse = Endpoint["response"] & {
3438
authentication: GitHubAppAuthentication;
@@ -62,7 +66,7 @@ export async function scopeToken(
6266
clientType,
6367
clientId,
6468
clientSecret,
65-
token: options.token,
69+
token: response.data.token,
6670
};
6771

6872
return { ...response, authentication };

test/scope-token.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe("scopeToken()", () => {
1111
login: "octokit",
1212
id: 1,
1313
},
14+
token: "usertoken456",
1415
},
1516
{
1617
headers: {
@@ -55,14 +56,15 @@ describe("scopeToken()", () => {
5556
"id": 1,
5657
"login": "octokit",
5758
},
59+
"token": "usertoken456",
5860
}
5961
`);
6062
expect(authentication).toMatchInlineSnapshot(`
6163
Object {
6264
"clientId": "lv1.1234567890abcdef",
6365
"clientSecret": "1234567890abcdef12347890abcdef12345678",
6466
"clientType": "github-app",
65-
"token": "usertoken123",
67+
"token": "usertoken456",
6668
}
6769
`);
6870
});

0 commit comments

Comments
 (0)