4
0
forked from crowetic/commerce
kibo-kevinwatts 9a4772cdb4
feat(provider): Implement Kibo Commerce provider (#575)
* Icky 161 folder and env setup (#1)

* folder and env setup

* codegen.json headers removed

Co-authored-by: Chandradeepta <43542673+Chandradeepta@users.noreply.github.com>

* Feature/icky 194 (#5)

* folder and env setup

* codegen.json headers removed

* use-cart code flow updated

* use-cart code flow updated

* Implemented get-cart functionality

* removed unused file

* getAnonymousShopperToken function added

* normalization mapping updated

* PR points resolved

* Anonymous shopper token query added

* getAnonymousShopperToken function added

* Anonymous shopper token query added

Co-authored-by: Chandradeepta <43542673+Chandradeepta@users.noreply.github.com>

* Icky 175 (#3)

* folder and env setup

* codegen.json headers removed

* icky-175-get-site-info

* PR comments resolved

* update category Id

Co-authored-by: Chandradeepta <43542673+Chandradeepta@users.noreply.github.com>

* Icky-169-LogIn (#4)

* Update README.md

* Initial Commit

* Commited Keys

* GraphQL Changes

* GraphQL Query

* Final Changes

* Changed login.ts

* Made changes in login.ts

* Final Changes

* Refactored login.ts

* SignUp Initial Checkin

* logout Initial

* Customer Account Initial Commit

* Logout - deleted cookie

* Reverted ReadMe and UserNav file

* Final Changes

* Resolved comments

* Resolved comments 1

* Resolved comments 2

* Resolved comments 3

* Resolved comments 4

Co-authored-by: SushantJadhav <Sushant.Jadhav@kibocommerce.com>

* ICKY-166-getProducts-and-getProduct (#6)

* GetProduct Initial Commit

* Passed productCode as Slug to get-product

* Moved currencyCode in Config file

* Icky 173 (#9)

* Initial commit related to getAllPages

* Initial Changes

* Making documentListName configurable

* fixing dynamic page rendering and adding typescript code

Co-authored-by: amolnadagonde <amol.nadagonde@kibocommerce.com>
Co-authored-by: kibo-sushant <sushant.jadhav@blueconchtech.com>

* Feature/icky 176 (#8)

* GetProduct Initial Commit

* addItemToCart function implemneted

* Add Item to cart functionality implemented

* ICKY-166-getProducts-and-getProduct (#6)

* GetProduct Initial Commit

* Passed productCode as Slug to get-product

* Moved currencyCode in Config file

* Icky 173 (#9)

* Initial commit related to getAllPages

* Initial Changes

* Making documentListName configurable

* fixing dynamic page rendering and adding typescript code

Co-authored-by: amolnadagonde <amol.nadagonde@kibocommerce.com>
Co-authored-by: kibo-sushant <sushant.jadhav@blueconchtech.com>

* addItemToCart function implemneted

Conflicts resolved

* Add Item to cart functionality implemented

* booleans removed from query

* cart size option enabled

* updated addItem for with and without variants products

Co-authored-by: kibo-sushant <sushant.jadhav@blueconchtech.com>
Co-authored-by: Chandradeepta <43542673+Chandradeepta@users.noreply.github.com>
Co-authored-by: kibo-sushant <89385472+kibo-sushant@users.noreply.github.com>
Co-authored-by: kibo-kevinwatts <85258296+kibo-kevinwatts@users.noreply.github.com>
Co-authored-by: amolnadagonde <amol.nadagonde@kibocommerce.com>

* Removed types from schema.d.ts (#11)

* Final Changes (#16)

* Icky 177 (#13)

* addItemToCart function implemneted

Conflicts resolved

* Add Item to cart functionality implemented

* remove Item from cart implemented

* removed unused code

Co-authored-by: Chandradeepta <43542673+Chandradeepta@users.noreply.github.com>

* Icky 178 - Update Cart Quantity implemented (#14)

* update cart quantity implemented

* add item to cart bug fixed

Co-authored-by: Chandradeepta <43542673+Chandradeepta@users.noreply.github.com>

* Icky 182 (#12)

* initial commit

* useSearch hook

* remove extra spaces

* revert pages and component changes

* remove extra spacing in search.tsx

* changes in catalog/products and product-search-vars

* initial commit

* useSearch hook

* remove extra spaces

* revert pages and component changes

* remove extra spacing in search.tsx

* changes in catalog/products and product-search-vars

* changes in product-search-vars

* remove unwanted boolean

* Feature/icky 179 (#17)

* initial commit

* useSearch hook

* remove extra spaces

* revert pages and component changes

* remove extra spacing in search.tsx

* changes in catalog/products and product-search-vars

* initial commit

* useSearch hook

* remove extra spaces

* revert pages and component changes

* remove extra spacing in search.tsx

* changes in catalog/products and product-search-vars

* changes in product-search-vars

* remove unwanted boolean

* initial commit

* updated Provider

* usewishlist/getwishlist

* changes in provider.ts

* initial commit

* useSearch hook

* revert pages and component changes

* remove extra spacing in search.tsx

* changes in catalog/products and product-search-vars

* initial commit

* useSearch hook

* revert pages and component changes

* remove extra spacing in search.tsx

* changes in catalog/products and product-search-vars

* initial commit

* usewishlist/getwishlist

* updated Provider

* changes in provider.ts

* normalize wishlistitem

* changes in get-customer-account

* remove unwanted code

* resolve empty wishlist case

* resolve pr comments

Co-authored-by: kibo-sushant <sushant.jadhav@blueconchtech.com>

* token encoding and decoding fixed (#19)

Co-authored-by: Chandradeepta <43542673+Chandradeepta@users.noreply.github.com>

* Feature/icky- 180 & 181 (#20)

* initial commit

* useSearch hook

* revert pages and component changes

* remove extra spacing in search.tsx

* changes in catalog/products and product-search-vars

* initial commit

* useSearch hook

* revert pages and component changes

* remove extra spacing in search.tsx

* changes in catalog/products and product-search-vars

* usewishlist/getwishlist

* changes in provider.ts

* changes in get-customer-account

* initial commit

* useSearch hook

* revert pages and component changes

* remove extra spacing in search.tsx

* changes in catalog/products and product-search-vars

* initial commit

* useSearch hook

* revert pages and component changes

* remove extra spacing in search.tsx

* changes in catalog/products and product-search-vars

* usewishlist/getwishlist

* changes in provider.ts

* remove unwanted code

* initial commit

* resolve pr comments

* changes in add-item

* remove wishlist fragment

* remove item from wishlist

* changes in normalize.ts

* changes in additemtowishlist mutation

* resove pr comments

* Feature/icky 291 (#22)

* Kibo API authentication helper handling oauth token generation / refresh and making auth ticket available to process via next server runtime config

* Update .env template with placeholder for Kibo Auth Url

* resolve ICKY-275 (#24)

* Fix/icky 276 (#21)

* remove Item from cart implemented

* update cart quantity implemented

* removed unused code

* ICKY 176 and 263 implemented

* ICKY 263 removed

* PR points resolved

Co-authored-by: Chandradeepta <43542673+Chandradeepta@users.noreply.github.com>

* ICKY-263 (#23)

* ICKY-263

* resolve pr comments

* resolve pr comments for customer typescript

* docs: update kibo commerce readme with env details (#26)

* resolve icky-264 (#25)

* chore: remove extra field from .env.template

* chore: remove extra .vscode launch json file

* chore: cleanup test message from kibocommerce fork

* chore(docs): remove extra field from .env template and .env related docs

* chore: remove test data json file

* chore: delete yarn.lock

* refactor: remove unused fetch from kibo config, remove unused CommerceProvider

* refactor: rename queries and util modules for consistency

* chore: add checkout related api noop handlers and hooks

* chore: revert modified core files

* chore(config): add kibo production sandbox cdn to image domains config

* fix: page normalizer and query for static pages

* chore: remove commented code and unnecessary imports

* fix(module paths): switch framework alias for relative path

Co-authored-by: kibo-chandradeeptalaha <89371824+kibo-chandradeeptalaha@users.noreply.github.com>
Co-authored-by: Chandradeepta <43542673+Chandradeepta@users.noreply.github.com>
Co-authored-by: kibo-geetanshuchhabra <89399259+kibo-geetanshuchhabra@users.noreply.github.com>
Co-authored-by: kibo-sushant <89385472+kibo-sushant@users.noreply.github.com>
Co-authored-by: SushantJadhav <Sushant.Jadhav@kibocommerce.com>
Co-authored-by: amolnadagonde <amol.nadagonde@kibocommerce.com>
Co-authored-by: kibo-sushant <sushant.jadhav@blueconchtech.com>
Co-authored-by: kibo-amolnadagonde <75060520+kibo-amolnadagonde@users.noreply.github.com>
2021-12-15 10:25:09 -03:00

195 lines
4.9 KiB
TypeScript

import update from './immutability'
import getSlug from './get-slug'
import type { PrCategory, CustomerAccountInput, Document } from '../schema'
import { Page } from '../types/page';
import { Customer } from '../types/customer'
function normalizeProductOption(productOption: any) {
const {
node: { entityId, values: { edges = [] } = {}, ...rest },
} = productOption
return {
id: entityId,
values: edges?.map(({ node }: any) => node),
...rest,
}
}
export function normalizeProduct(productNode: any, config: any): any {
const product = {
id: productNode.productCode,
name: productNode.content.productName,
vendor: '',
path: `/${productNode.productCode}`,
slug: productNode.productCode,
price: {
value: productNode?.price?.price,
currencyCode: config.currencyCode,
},
descriptionHtml: productNode.content.productShortDescription,
images: productNode.content.productImages.map((p: any) => ({
url: `http:${p.imageUrl}`,
altText: p.imageLabel,
})),
variants: productNode.variations?.map((v: any) => ({
id: v.productCode,
options: v.options.map((o: any) => ({
['__typename']: 'MultipleChoiceOption',
id: o.attributeFQN,
displayName:
o.attributeFQN.split('~')[1][0].toUpperCase() +
o.attributeFQN.split('~')[1].slice(1).toLowerCase(),
values: [{ label: o.value.toString() }],
})),
})) || [
{
id: '',
},
],
options:
productNode.options?.map((o: any) => ({
id: o.attributeFQN,
displayName: o.attributeDetail.name,
values: o.values.map((v: any) => ({
label: v.value.toString(),
hexColors: '',
})),
})) || [],
}
return product
}
export function normalizePage(page: Document): Page {
return {
id: String(page.id),
name: String(page.name),
url: page.properties.url,
body: page.properties.body,
is_visible: page.properties.is_visible,
sort_order: page.properties.sort_order
}
}
export function normalizeCart(data: any): any {
return {
id: data.id,
customerId: data.userId,
email: data?.email,
createdAt: data?.created_time,
currency: {
code: 'USD',
},
taxesIncluded: true,
lineItems: data.items.map(normalizeLineItem),
lineItemsSubtotalPrice: data?.items.reduce(
(acc: number, obj: { subtotal: number }) => acc + obj.subtotal,
0
),
subtotalPrice: data?.subtotal,
totalPrice: data?.total,
discounts: data.orderDiscounts?.map((discount: any) => ({
value: discount.impact,
})),
}
}
export function normalizeCustomer(customer: CustomerAccountInput): Customer {
return {
id: customer.id,
firstName: customer.firstName,
lastName: customer.lastName,
email: customer.emailAddress,
userName: customer.userName,
isAnonymous: customer.isAnonymous
}
}
function normalizeLineItem(item: any): any {
return {
id: item.id,
variantId: item.product.variationProductCode,
productId: String(item.product.productCode),
name: item.product.name,
quantity: item.quantity,
variant: {
id: item.product.variationProductCode,
sku: item.product?.sku,
name: item.product.name,
image: {
url: item?.product?.imageUrl,
},
requiresShipping: item?.is_require_shipping,
price: item?.unitPrice.extendedAmount,
listPrice: 0,
},
options: item.product.options,
path: `${item.product.productCode}`,
discounts: item?.discounts?.map((discount: any) => ({
value: discount.discounted_amount,
})),
}
}
export function normalizeCategory(category: PrCategory): any {
return {
id: category?.categoryCode,
name: category?.content?.name,
slug: category?.content?.slug,
path: `/${category?.content?.slug}`,
}
}
export function normalizeWishlistItem(
item: any,
config: any,
includeProducts=false
): any {
if (includeProducts) {
return {
id: item.id,
product: getProuducts(item, config),
}
} else {
return getProuducts(item, config)
}
}
function getProuducts(item: any, config: any): any {
return {
variant_id: item.product.variationProductCode || '',
id: String(item.product.productCode),
product_id: String(item.product.productCode),
name: item.product.name,
quantity: item.quantity,
images: [
{
url: `http:${item.product.imageUrl}`,
alt: item.product.imageAlternateText,
},
],
price: {
value: item.product.price.price,
retailPrice: item.product.price.retailPrice || 0,
currencyCode: config.currencyCode,
},
variants: [
{
id: item.product.variationProductCode || '',
sku: item.product?.sku,
name: item.product.name,
image: {
url: item?.product.imageUrl,
},
},
],
options: item.product.options,
path: `/${item.product.productCode}`,
description: item.product.description,
}
}