Correctly use the extended got instance for target-state

In practice this fixes the missing user-agent

Change-type: patch
This commit is contained in:
Pagan Gazzard 2023-01-16 19:41:49 +00:00
parent 6c7193e0c1
commit 63cc4ad58c
2 changed files with 17 additions and 20 deletions

View File

@ -120,7 +120,6 @@ export const update = async (
const got = await getGotInstance(); const got = await getGotInstance();
const { statusCode, headers, body } = await got(endpoint, { const { statusCode, headers, body } = await got(endpoint, {
responseType: 'json',
headers: { headers: {
Authorization: `Bearer ${deviceApiKey}`, Authorization: `Bearer ${deviceApiKey}`,
'If-None-Match': cache?.etag, 'If-None-Match': cache?.etag,

View File

@ -69,7 +69,16 @@ const getRequestInstances = once(async () => {
retryInterval: DEFAULT_REQUEST_RETRY_INTERVAL, retryInterval: DEFAULT_REQUEST_RETRY_INTERVAL,
}; };
got.extend({ const requestHandle = requestLib.defaults(requestOpts);
// @ts-expect-error promisifyAll is a bit wonky
const request = Bluebird.promisifyAll(requestHandle, {
multiArgs: true,
}) as PromisifiedRequest;
const resumable = resumableRequestLib.defaults(resumableOpts);
return {
got: got.extend({
responseType: 'json', responseType: 'json',
decompress: true, decompress: true,
timeout: { timeout: {
@ -85,18 +94,7 @@ const getRequestInstances = once(async () => {
headers: { headers: {
'User-Agent': userAgent, 'User-Agent': userAgent,
}, },
}); }),
const requestHandle = requestLib.defaults(requestOpts);
// @ts-expect-error promisifyAll is a bit wonky
const request = Bluebird.promisifyAll(requestHandle, {
multiArgs: true,
}) as PromisifiedRequest;
const resumable = resumableRequestLib.defaults(resumableOpts);
return {
got,
requestOpts, requestOpts,
request, request,
resumable, resumable,