Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uploadExisting types #101

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// https://developer.chrome.com/docs/webstore/api
// https://developer.chrome.com/docs/webstore/using-api

import { type ReadStream } from 'node:fs';
import { type JsonObject } from 'type-fest';

const rootURI = 'https://www.googleapis.com';
Expand Down Expand Up @@ -69,7 +70,10 @@ class APIClient {
this.clientSecret = options.clientSecret;
}

async uploadExisting(readStream: ReadableStream, token = this.fetchToken()): Promise<JsonObject> {
async uploadExisting(
readStream: ReadStream | ReadableStream,
token = this.fetchToken(),
): Promise<JsonObject> {
if (!readStream) {
throw new Error('Read stream missing');
}
Expand All @@ -81,7 +85,9 @@ class APIClient {
headers: this._headers(await token),
// @ts-expect-error Node extension? 🤷‍♂️ Required https://github.com/nodejs/node/issues/46221
duplex: 'half',
body: readStream,

// Until they figure it out, this seems to work. Alternatively use https://stackoverflow.com/a/76780381/288906
body: readStream as unknown as ReadableStream,
});

const response = await request.json() as JsonObject;
Expand Down