Skip to content

Commit 1c7db68

Browse files
authored
chore(types): Tweak options.waitUntil to use Promise<any> (#14)
1 parent fbb6268 commit 1c7db68

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ app.get("/", ({ env, executionCtx, json }) => {
132132
You're very welcome to [create a PR](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)
133133
or send me a message on [Discord](https://discord.gg/bSsv7XM).
134134

135+
In order to unit test this library locally you will need [Node.js](https://nodejs.org/) v18+ with [corepack enabled](https://nodejs.org/api/corepack.html), a Google Cloud [service account key](https://cloud.google.com/iam/docs/keys-create-delete) ([here](https://console.cloud.google.com/iam-admin/serviceaccounts)) and Firebase API Key ([here](https://console.cloud.google.com/apis/credentials)) that you can save into the [`test/test.override.env`](./test/test.env) file, for example:
136+
137+
```
138+
GOOGLE_CLOUD_PROJECT=example
139+
GOOGLE_CLOUD_CREDENTIALS={"type":"service_account","project_id":"example",...}
140+
FIREBASE_API_KEY=AIzaSyAZEmdfRWvEYgZpwm6EBLkYJf6ySIMF3Hy
141+
```
142+
143+
Then run unit tests via `yarn test [--watch]`.
144+
135145
## License
136146

137147
Copyright © 2022-present Kriasoft. This source code is licensed under the MIT license found in the

core/env.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* SPDX-FileCopyrightText: 2022-present Kriasoft */
22
/* SPDX-License-Identifier: MIT */
33

4-
export const canUseDefaultCache = typeof caches?.default?.put === "function";
4+
export const canUseDefaultCache =
5+
typeof self.caches?.default?.put === "function";

google/accessToken.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ export async function getAccessToken(options: Options) {
9999
const body = new URLSearchParams();
100100
body.append("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer");
101101
body.append("assertion", jwt);
102-
res = await fetch(tokenUrl, { method: "POST", body });
102+
res = await fetch(tokenUrl, {
103+
method: "POST",
104+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
105+
body,
106+
});
103107

104108
if (!res.ok) {
105109
const error = await res
@@ -171,7 +175,8 @@ type Options = {
171175
*/
172176
GOOGLE_CLOUD_CREDENTIALS: string;
173177
};
174-
waitUntil?: <T = unknown>(promise: Promise<T>) => void;
178+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
179+
waitUntil?: (promise: Promise<any>) => void;
175180
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
176181
cache?: Map<string, any>;
177182
};

google/credentials.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export async function importPublicKey(options: {
4343
* @default "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]"
4444
*/
4545
certificateURL?: string;
46-
waitUntil?: <T = unknown>(promise: Promise<T>) => void;
46+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
47+
waitUntil?: (promise: Promise<any>) => void;
4748
}) {
4849
const keyId = options.keyId;
4950
const certificateURL = options.certificateURL ?? "https://www.googleapis.com/robot/v1/metadata/x509/[email protected]"; // prettier-ignore

google/idToken.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ export async function verifyIdToken(options: {
180180
*/
181181
GOOGLE_CLOUD_CREDENTIALS?: string;
182182
};
183-
waitUntil?: <T = unknown>(promise: Promise<T>) => void;
183+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
184+
waitUntil?: (promise: Promise<any>) => void;
184185
}): Promise<UserToken> {
185186
if (!options?.idToken) {
186187
throw new TypeError(`Missing "idToken"`);

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-auth-library",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"packageManager": "[email protected]",
55
"description": "Authentication library for the browser environment using Web Crypto API",
66
"license": "MIT",
@@ -26,7 +26,7 @@
2626
"url": "https://www.patreon.com/koistya"
2727
}
2828
],
29-
"repository": "kriasoft/web-auth-library",
29+
"repository": "github:kriasoft/web-auth-library",
3030
"keywords": [
3131
"auth",
3232
"authentication",

0 commit comments

Comments
 (0)