From 8203a5b21e6f61e64c996f057e8180840d37d31a Mon Sep 17 00:00:00 2001 From: cond0r <1243434+cond0r@users.noreply.github.com> Date: Tue, 10 Jan 2023 10:16:50 +0200 Subject: [PATCH] Requested changes --- .../customer/get-logged-in-customer.ts | 4 +++- .../api/operations/get-customer-wishlist.ts | 6 +++--- .../bigcommerce/src/api/operations/login.ts | 1 - .../src/api/utils/fetch-graphql-api.ts | 4 ++-- .../src/api/utils/get-customer-id.ts | 4 +++- packages/commerce/src/api/index.ts | 4 +++- packages/commerce/src/schemas/customer.ts | 18 ++++++++---------- site/components/auth/LoginView.tsx | 2 +- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/packages/bigcommerce/src/api/endpoints/customer/get-logged-in-customer.ts b/packages/bigcommerce/src/api/endpoints/customer/get-logged-in-customer.ts index f3db6ce94..02de28b23 100644 --- a/packages/bigcommerce/src/api/endpoints/customer/get-logged-in-customer.ts +++ b/packages/bigcommerce/src/api/endpoints/customer/get-logged-in-customer.ts @@ -34,7 +34,9 @@ const getLoggedInCustomer: CustomerEndpoint['handlers']['getLoggedInCustomer'] = getLoggedInCustomerQuery, undefined, { - cookie: `${config.customerCookie}=${token}`, + headers: { + cookie: `${config.customerCookie}=${token}`, + }, } ) const { customer } = data diff --git a/packages/bigcommerce/src/api/operations/get-customer-wishlist.ts b/packages/bigcommerce/src/api/operations/get-customer-wishlist.ts index e94297204..c7ff1697f 100644 --- a/packages/bigcommerce/src/api/operations/get-customer-wishlist.ts +++ b/packages/bigcommerce/src/api/operations/get-customer-wishlist.ts @@ -48,9 +48,9 @@ export default function getCustomerWishlistOperation({ if (includeProducts && wishlist?.items?.length) { const ids = [] - for (let i = 0; i < wishlist.items.length; i++) { - if (wishlist.items[i].product_id) { - ids.push(String(wishlist.items[i]?.product_id)) + for (const wishlistItem of wishlist.items) { + if (wishlistItem.product_id) { + ids.push(String(wishlistItem.product_id)) } } diff --git a/packages/bigcommerce/src/api/operations/login.ts b/packages/bigcommerce/src/api/operations/login.ts index 96bdb5119..da63e21f0 100644 --- a/packages/bigcommerce/src/api/operations/login.ts +++ b/packages/bigcommerce/src/api/operations/login.ts @@ -5,7 +5,6 @@ import type { import type { LoginOperation } from '@vercel/commerce/types/login' import type { LoginMutation } from '../../../schema' import type { RecursivePartial } from '../utils/types' -import concatHeader from '../utils/concat-cookie' import type { BigcommerceConfig, Provider } from '..' export const loginMutation = /* GraphQL */ ` diff --git a/packages/bigcommerce/src/api/utils/fetch-graphql-api.ts b/packages/bigcommerce/src/api/utils/fetch-graphql-api.ts index c98010422..9072b2432 100644 --- a/packages/bigcommerce/src/api/utils/fetch-graphql-api.ts +++ b/packages/bigcommerce/src/api/utils/fetch-graphql-api.ts @@ -7,7 +7,7 @@ const fetchGraphqlApi: (getConfig: () => BigcommerceConfig) => GraphQLFetcher = async ( query: string, { variables, preview } = {}, - headers?: HeadersInit + options: { headers?: HeadersInit } = {} ): Promise => { // log.warn(query) const config = getConfig() @@ -16,7 +16,7 @@ const fetchGraphqlApi: (getConfig: () => BigcommerceConfig) => GraphQLFetcher = method: 'POST', headers: { Authorization: `Bearer ${config.apiToken}`, - ...headers, + ...options.headers, 'Content-Type': 'application/json', }, body: JSON.stringify({ diff --git a/packages/bigcommerce/src/api/utils/get-customer-id.ts b/packages/bigcommerce/src/api/utils/get-customer-id.ts index e77951948..7344e017b 100644 --- a/packages/bigcommerce/src/api/utils/get-customer-id.ts +++ b/packages/bigcommerce/src/api/utils/get-customer-id.ts @@ -20,7 +20,9 @@ async function getCustomerId({ getCustomerIdQuery, undefined, { - cookie: `${config.customerCookie}=${customerToken}`, + headers: { + cookie: `${config.customerCookie}=${customerToken}`, + }, } ) diff --git a/packages/commerce/src/api/index.ts b/packages/commerce/src/api/index.ts index 7cd52eb94..95b5804e2 100644 --- a/packages/commerce/src/api/index.ts +++ b/packages/commerce/src/api/index.ts @@ -165,7 +165,9 @@ export interface CommerceAPIConfig { fetch( query: string, queryData?: CommerceAPIFetchOptions, - headers?: HeadersInit + options?: { + headers: HeadersInit + } ): Promise> } diff --git a/packages/commerce/src/schemas/customer.ts b/packages/commerce/src/schemas/customer.ts index 6ff017cfd..a48ba06ab 100644 --- a/packages/commerce/src/schemas/customer.ts +++ b/packages/commerce/src/schemas/customer.ts @@ -5,16 +5,14 @@ export const getCustomerAddressBodySchema = z.object({ }) export const customerSchema = z.object({ - customer: z.object({ - id: z.string(), - firstName: z.string(), - lastName: z.string(), - email: z.string().optional(), - phone: z.string().optional(), - company: z.string().optional(), - notes: z.string().optional(), - acceptsMarketing: z.boolean().optional(), - }), + id: z.string(), + firstName: z.string(), + lastName: z.string(), + email: z.string().optional(), + phone: z.string().optional(), + company: z.string().optional(), + notes: z.string().optional(), + acceptsMarketing: z.boolean().optional(), }) export const addressSchema = z.object({ diff --git a/site/components/auth/LoginView.tsx b/site/components/auth/LoginView.tsx index 26e649cda..c30f71834 100644 --- a/site/components/auth/LoginView.tsx +++ b/site/components/auth/LoginView.tsx @@ -1,4 +1,4 @@ -import { FC, useEffect, useState, useCallback } from 'react' +import { useEffect, useState, useCallback } from 'react' import { Logo, Button, Input } from '@components/ui' import useLogin from '@framework/auth/use-login' import { useUI } from '@components/ui/context'