diff --git a/src/index.ts b/src/index.ts index 6d123ae..cc28e55 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,11 +2,11 @@ import { getToken } from "./get-token"; import { Options, Result } from "./types"; -export async function githubAppJwt({ +export async function githubAppJwt({ id, privateKey, now = Math.floor(Date.now() / 1000), -}: Options): Promise { +}: Options): Promise> { // When creating a JSON Web Token, it sets the "issued at time" (iat) to 30s // in the past as we have seen people running situations where the GitHub API // claimed the iat would be in future. It turned out the clocks on the diff --git a/src/types.ts b/src/types.ts index 75746e1..dea97a2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,16 +1,15 @@ export type PrivateKey = string; -export type AppId = number; export type Expiration = number; export type Token = string; -export type Options = { - id: AppId; +export type Options = { + id: IdType; privateKey: PrivateKey; now?: number; }; -export type Result = { - appId: AppId; +export type Result = { + appId: IdType; expiration: Expiration; token: Token; }; @@ -18,7 +17,7 @@ export type Result = { export type Payload = { iat: number; exp: number; - iss: number; + iss: number | string; }; export type GetTokenOptions = { diff --git a/test/node.test.ts b/test/node.test.ts index 1d3b643..d0abdef 100644 --- a/test/node.test.ts +++ b/test/node.test.ts @@ -116,14 +116,12 @@ test("Include the time difference in the expiration and issued_at field", async }); // New test for id set to Client ID -test("id set to Client ID", async (t) => { - MockDate.set(0); - +test("id set to Client ID", async () => { const result = await githubAppJwt({ id: "client_id_string", privateKey: PRIVATE_KEY_PKCS8, }); - t.is(typeof result.token, "string"); - t.is(result.appId, "client_id_string"); + expect(typeof result.token).toEqual("string"); + expect(result.appId).toEqual("client_id_string"); });