1
1
import vercelFetch from '@vercel/fetch'
2
2
import { FetcherError } from '@commerce/utils/errors'
3
+ import { CustomNodeJsGlobal } from '../../types/node' ;
3
4
4
5
import { OrdercloudConfig } from '../index'
5
6
@@ -143,25 +144,28 @@ export const createBuyerFetcher: (
143
144
body ?: Record < string , unknown > ,
144
145
fetchOptions ?: Record < string , any >
145
146
) => {
147
+ const customGlobal = global as CustomNodeJsGlobal ;
148
+
146
149
// Get provider config
147
150
const config = getConfig ( )
148
151
152
+
149
153
// If a token was passed, set it on global
150
154
if ( fetchOptions ?. token ) {
151
- global . token = fetchOptions . token
155
+ customGlobal . token = fetchOptions . token
152
156
}
153
157
154
158
// Get a token
155
- if ( ! global . token ) {
156
- global . token = await getToken ( {
159
+ if ( ! customGlobal . token ) {
160
+ customGlobal . token = await getToken ( {
157
161
baseUrl : config . commerceUrl ,
158
162
clientId : process . env . ORDERCLOUD_BUYER_CLIENT_ID as string ,
159
163
} )
160
164
}
161
165
162
166
// Return the data and specify the expected type
163
167
const data = await fetchData < T > ( {
164
- token : global . token as string ,
168
+ token : customGlobal . token as string ,
165
169
fetchOptions,
166
170
config,
167
171
method,
@@ -171,6 +175,6 @@ export const createBuyerFetcher: (
171
175
172
176
return {
173
177
...data ,
174
- meta : { token : global . token as string } ,
178
+ meta : { token : customGlobal . token as string } ,
175
179
}
176
180
}
0 commit comments