Skip to content

Commit

Permalink
Fix uploadExisting types (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Sep 30, 2024
1 parent 858ffb7 commit 81369df
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit 81369df

Please sign in to comment.