Skip to content

Commit

Permalink
Merge pull request #93 from bigcommerce/prerelease
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemasta authored Sep 30, 2021
2 parents 28634a3 + b76e8e9 commit 21e5f24
Show file tree
Hide file tree
Showing 18 changed files with 3,085 additions and 62 deletions.
41 changes: 41 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = {
plugins: [
'prettier',
],
extends: [
"plugin:@typescript-eslint/recommended",
"prettier",
],
env: {
node: true,
browser: true,
jest: true,
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
project: "./tsconfig.json"
},
settings: {
react: {},
},
rules: {
'prettier/prettier': 'error',
// Makes no sense to allow type inferrence for expression parameters, but require typing the response
'@typescript-eslint/explicit-function-return-type': [
'error',
{ allowExpressions: true, allowTypedFunctionExpressions: true },
],
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-use-before-define': [
'error',
{ functions: false, classes: true, variables: true, typedefs: true },
],
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': 0 // It's not working as expected
},
}
38 changes: 38 additions & 0 deletions .github/workflows/release-beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This is a basic workflow to help you get started with Actions

name: Release to Beta Track

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the develop branch
push:
branches: [ develop ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: git config
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- run: yarn
- name: Authenticate with registry
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: npm run release -- --preRelease=beta
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ dist
node_modules

*.js
!.eslintrc.js
*.d.ts
/address
/api
/cart
/commerce
/products
/scripts
/wishlist
/wishlist
.env
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 100,
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
21 changes: 21 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"plugins": {
"@release-it/conventional-changelog": {
"infile": "CHANGELOG.md",
"preset": {
"name": "conventionalcommits",
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{}
]
}
}
}
}
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# 1.6.0

## Add extra values to `useSignup` hook

Add support to more values that are supported in the Customer V3 API:

```
- phone
- company
- notes
- addresses
- accepts_product_review_abandoned_cart_emails
```

In addition, **`eslint/prettier`** has been configured.

## Category images

- Return (if exists) category images

## Add product options to product query

- Return specific product options for checkbox option
- Return specific product options for product pick list option
- Return `isDefault` for multiple choice option

## Add customer id to cart

Add the customer id (if the customer is logged) to the cart when creating it using the addItem hook
# 1.5.2
## Fix Address API imports
Export edit and delete handlers correctly. They were swapped.
Expand Down
4 changes: 2 additions & 2 deletions codegen.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"schema": {
"https://buybutton.store/graphql": {
"${BIGCOMMERCE_STOREFRONT_API_URL}": {
"headers": {
"Authorization": "Bearer xzy"
"Authorization": "Bearer ${BIGCOMMERCE_STOREFRONT_API_TOKEN}"
}
}
},
Expand Down
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bigcommerce/storefront-data-hooks",
"version": "1.5.2",
"version": "1.6.0",
"main": "index.js",
"repository": "[email protected]:bigcommerce/storefront-data-hooks.git",
"license": "MIT",
Expand All @@ -19,8 +19,9 @@
"build": "npm run clean && tsc && cp src/schema.d.ts schema.d.ts",
"start": "npm run clean && tsc -w",
"prepublish": "npm run build",
"generate": "graphql-codegen",
"generate:definitions": "node src/scripts/generate-definitions.js"
"generate": "graphql-codegen -r dotenv/config",
"generate:definitions": "node src/scripts/generate-definitions.js",
"release": "release-it"
},
"prettier": {
"semi": false,
Expand All @@ -40,15 +41,22 @@
"@graphql-codegen/typescript": "^1.17.11",
"@graphql-codegen/typescript-operations": "^1.17.8",
"@manifoldco/swagger-to-ts": "^2.1.0",
"@release-it/conventional-changelog": "^3.0.1",
"@types/cookie": "^0.4.0",
"@types/js-cookie": "^2.2.6",
"@types/lodash.debounce": "^4.0.6",
"@types/lodash.omit": "^4.5.6",
"@types/node": "^14.14.3",
"@types/react": "^16.9.53",
"@typescript-eslint/eslint-plugin": "^4.29.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"graphql": "^15.4.0",
"next": "^10.0.8",
"prettier": "^2.1.2",
"prettier": "^2.3.2",
"prettier-eslint": "^13.0.0",
"release-it": "^14.10.1",
"rimraf": "^3.0.2",
"typescript": "^4.0.3"
},
Expand Down
22 changes: 17 additions & 5 deletions src/api/cart/handlers/add-item.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import getCustomerId from '../../operations/get-customer-id'
import { parseCartItem } from '../../utils/parse-item'
import getCartCookie from '../../utils/get-cart-cookie'
import type { CartHandlers } from '..'

// Return current cart info
const addItem: CartHandlers['addItem'] = async ({
res,
req,
body: { cartId, locale, item, include },
config,
}) => {
Expand All @@ -16,23 +18,33 @@ const addItem: CartHandlers['addItem'] = async ({
}
if (!item.quantity) item.quantity = 1

const { cookies } = req
const customerToken = cookies[config.customerCookie]
const customerId =
customerToken && (await getCustomerId({ customerToken, config }))

// Use a dummy base as we only care about the relative path
const url = new URL(cartId ? `/v3/carts/${cartId}/items` : '/v3/carts', 'http://a')
const url = new URL(
cartId ? `/v3/carts/${cartId}/items` : '/v3/carts',
'http://a'
)
if (include) url.searchParams.set('include', include)

const options = {
method: 'POST',
body: JSON.stringify({
customer_id: customerId,
line_items: [parseCartItem(item)],
...(!cartId && config.storeChannelId
? { channel_id: config.storeChannelId }
: {}),
...(!cartId
? { locale }
: {}),
...(!cartId ? { locale } : {}),
}),
}
const { data } = await config.storeApiFetch(url.pathname + url.search, options)
const { data } = await config.storeApiFetch(
url.pathname + url.search,
options
)

// Create or update the cart cookie
res.setHeader(
Expand Down
17 changes: 16 additions & 1 deletion src/api/customers/handlers/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ import { SignupHandlers } from '../signup'
const signup: SignupHandlers['signup'] = async ({
req,
res,
body: { firstName, lastName, email, password },
body: {
firstName,
lastName,
email,
password,
phone,
company,
acceptsEmails,
notes,
addresses,
},
config,
}) => {
// TODO: Add proper validations with something like Ajv
Expand All @@ -27,6 +37,11 @@ const signup: SignupHandlers['signup'] = async ({
first_name: firstName,
last_name: lastName,
email,
phone,
company,
notes,
addresses,
accepts_product_review_abandoned_cart_emails: acceptsEmails,
authentication: {
new_password: password,
},
Expand Down
9 changes: 2 additions & 7 deletions src/api/customers/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import isAllowedMethod from '../utils/is-allowed-method'
import { BigcommerceApiError } from '../utils/errors'
import signup from './handlers/signup'

export type SignupBody = {
firstName: string
lastName: string
email: string
password: string
}
import { SignupBody } from './signup.types'

export type SignupHandlers = {
signup: BigcommerceHandler<null, { cartId?: string } & Partial<SignupBody>>
Expand Down Expand Up @@ -46,5 +41,5 @@ const signupApi: BigcommerceApiHandler<null, SignupHandlers> = async (
}

export const handlers = { signup }

export * from './signup.types'
export default createApiHandler(signupApi, handlers, {})
Loading

0 comments on commit 21e5f24

Please sign in to comment.