From b88d3345f10ed96b6096330ab53f459067bfa36c Mon Sep 17 00:00:00 2001 From: Oliver Heywood <38010640+oliverheywood451@users.noreply.github.com> Date: Tue, 4 Jan 2022 12:32:03 -0600 Subject: [PATCH] #629: Type error: Property 'token' does not exist on type Global (#630) --- framework/ordercloud/api/utils/fetch-rest.ts | 14 +++++++++----- framework/ordercloud/types/node.d.ts | 6 ++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/framework/ordercloud/api/utils/fetch-rest.ts b/framework/ordercloud/api/utils/fetch-rest.ts index fd686b958..b7f4ac6a6 100644 --- a/framework/ordercloud/api/utils/fetch-rest.ts +++ b/framework/ordercloud/api/utils/fetch-rest.ts @@ -1,5 +1,6 @@ import vercelFetch from '@vercel/fetch' import { FetcherError } from '@commerce/utils/errors' +import { CustomNodeJsGlobal } from '../../types/node'; import { OrdercloudConfig } from '../index' @@ -143,17 +144,20 @@ export const createBuyerFetcher: ( body?: Record, fetchOptions?: Record ) => { + const customGlobal = global as CustomNodeJsGlobal; + // Get provider config const config = getConfig() + // If a token was passed, set it on global if (fetchOptions?.token) { - global.token = fetchOptions.token + customGlobal.token = fetchOptions.token } // Get a token - if (!global.token) { - global.token = await getToken({ + if (!customGlobal.token) { + customGlobal.token = await getToken({ baseUrl: config.commerceUrl, clientId: process.env.ORDERCLOUD_BUYER_CLIENT_ID as string, }) @@ -161,7 +165,7 @@ export const createBuyerFetcher: ( // Return the data and specify the expected type const data = await fetchData({ - token: global.token as string, + token: customGlobal.token as string, fetchOptions, config, method, @@ -171,6 +175,6 @@ export const createBuyerFetcher: ( return { ...data, - meta: { token: global.token as string }, + meta: { token: customGlobal.token as string }, } } diff --git a/framework/ordercloud/types/node.d.ts b/framework/ordercloud/types/node.d.ts index f4e4a21f4..ee2452c30 100644 --- a/framework/ordercloud/types/node.d.ts +++ b/framework/ordercloud/types/node.d.ts @@ -1,5 +1,3 @@ -declare module NodeJS { - interface Global { - token: string | null | undefined - } +export interface CustomNodeJsGlobal extends NodeJS.Global { + token: string | null | undefined }