From 19a5e22302afe5f59d69d2d94b016aef27adfb51 Mon Sep 17 00:00:00 2001 From: goncy Date: Thu, 30 Sep 2021 15:50:30 -0300 Subject: [PATCH] Update fetch rest --- framework/ordercloud/api/utils/fetch-rest.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/framework/ordercloud/api/utils/fetch-rest.ts b/framework/ordercloud/api/utils/fetch-rest.ts index a083cc58b..fd686b958 100644 --- a/framework/ordercloud/api/utils/fetch-rest.ts +++ b/framework/ordercloud/api/utils/fetch-rest.ts @@ -1,4 +1,3 @@ -import Cookies from 'js-cookie' import vercelFetch from '@vercel/fetch' import { FetcherError } from '@commerce/utils/errors' @@ -86,13 +85,7 @@ export async function fetchData(opts: { try { // Return data response as json - const data = (await dataResponse.json()) as Promise - - // Return data with meta - return { - meta: { token }, - ...data, - } + return (await dataResponse.json()) as Promise } catch (error) { // If response is empty return it as text return null as unknown as Promise @@ -167,7 +160,7 @@ export const createBuyerFetcher: ( } // Return the data and specify the expected type - return fetchData({ + const data = await fetchData({ token: global.token as string, fetchOptions, config, @@ -175,4 +168,9 @@ export const createBuyerFetcher: ( path, body, }) + + return { + ...data, + meta: { token: global.token as string }, + } }