Skip to content

Commit b88d334

Browse files
vercel#629: Type error: Property 'token' does not exist on type Global (vercel#630)
1 parent c95f292 commit b88d334

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

framework/ordercloud/api/utils/fetch-rest.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import vercelFetch from '@vercel/fetch'
22
import { FetcherError } from '@commerce/utils/errors'
3+
import { CustomNodeJsGlobal } from '../../types/node';
34

45
import { OrdercloudConfig } from '../index'
56

@@ -143,25 +144,28 @@ export const createBuyerFetcher: (
143144
body?: Record<string, unknown>,
144145
fetchOptions?: Record<string, any>
145146
) => {
147+
const customGlobal = global as CustomNodeJsGlobal;
148+
146149
// Get provider config
147150
const config = getConfig()
148151

152+
149153
// If a token was passed, set it on global
150154
if (fetchOptions?.token) {
151-
global.token = fetchOptions.token
155+
customGlobal.token = fetchOptions.token
152156
}
153157

154158
// Get a token
155-
if (!global.token) {
156-
global.token = await getToken({
159+
if (!customGlobal.token) {
160+
customGlobal.token = await getToken({
157161
baseUrl: config.commerceUrl,
158162
clientId: process.env.ORDERCLOUD_BUYER_CLIENT_ID as string,
159163
})
160164
}
161165

162166
// Return the data and specify the expected type
163167
const data = await fetchData<T>({
164-
token: global.token as string,
168+
token: customGlobal.token as string,
165169
fetchOptions,
166170
config,
167171
method,
@@ -171,6 +175,6 @@ export const createBuyerFetcher: (
171175

172176
return {
173177
...data,
174-
meta: { token: global.token as string },
178+
meta: { token: customGlobal.token as string },
175179
}
176180
}

framework/ordercloud/types/node.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
declare module NodeJS {
2-
interface Global {
3-
token: string | null | undefined
4-
}
1+
export interface CustomNodeJsGlobal extends NodeJS.Global {
2+
token: string | null | undefined
53
}

0 commit comments

Comments
 (0)