-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Update API method names and parameters
- Loading branch information
Showing
22 changed files
with
1,060 additions
and
534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* SPDX-FileCopyrightText: 2022-present Kriasoft */ | ||
/* SPDX-License-Identifier: MIT */ | ||
|
||
export class FetchError extends Error { | ||
readonly name: string = "FetchError"; | ||
readonly response: Response; | ||
|
||
constructor( | ||
message: string, | ||
options: { response: Response; cause?: unknown } | ||
) { | ||
super(message, { cause: options?.cause }); | ||
this.response = options.response; | ||
|
||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, Error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* SPDX-FileCopyrightText: 2022-present Kriasoft */ | ||
/* SPDX-License-Identifier: MIT */ | ||
|
||
import { decodeJwt } from "jose"; | ||
import env from "../test/env.js"; | ||
import { getAccessToken } from "./accessToken.js"; | ||
|
||
test("getAccessToken({ credentials, scope })", async () => { | ||
const accessToken = await getAccessToken({ | ||
credentials: env.GOOGLE_CLOUD_CREDENTIALS, | ||
scope: "https://www.googleapis.com/auth/cloud-platform", | ||
}); | ||
|
||
expect(accessToken?.substring(0, 30)).toEqual( | ||
expect.stringContaining("ya29.c.") | ||
); | ||
}); | ||
|
||
test("getAccessToken({ credentials, audience })", async () => { | ||
const idToken = await getAccessToken({ | ||
credentials: env.GOOGLE_CLOUD_CREDENTIALS, | ||
audience: "https://example.com", | ||
}); | ||
|
||
expect(idToken?.substring(0, 30)).toEqual( | ||
expect.stringContaining("eyJhbGciOi") | ||
); | ||
|
||
expect(decodeJwt(idToken)).toEqual( | ||
expect.objectContaining({ | ||
aud: "https://example.com", | ||
email_verified: true, | ||
iss: "https://accounts.google.com", | ||
}) | ||
); | ||
}); |
Oops, something went wrong.