Skip to content

Commit

Permalink
Merge branch 'main' into rapyd-zod-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
rico191013 committed Jan 17, 2024
2 parents 6004441 + 4e4e522 commit 89908f2
Show file tree
Hide file tree
Showing 65 changed files with 638 additions and 585 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v4.1.0
uses: mikepenz/release-changelog-builder-action@v4.1.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
"wallet:frontend": "pnpm --filter @wallet/frontend --"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"concurrently": "^8.2.2",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"only-allow": "^1.2.1",
"prettier": "^3.1.1",
"prettier": "^3.2.2",
"prettier-plugin-tailwindcss": "^0.5.11",
"typescript": "^5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/boutique/backend/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare global {
interface TypedResponseBody<T = any> {
success: boolean
message: string
data?: T
result?: T
errors?: Record<string, string>
}

Expand Down
12 changes: 6 additions & 6 deletions packages/boutique/backend/src/order/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextFunction, Request } from 'express'
import { IOrderService } from './service'
import { Order } from './model'
import { BadRequest, InternalServerError } from '@/errors'
import { toSuccessReponse } from '@/shared/utils'
import { toSuccessResponse } from '@/shared/utils'
import { Logger } from 'winston'
import { IOpenPayments, TokenInfo } from '@/open-payments/service'
import { validate } from '@/middleware/validate'
Expand Down Expand Up @@ -57,7 +57,7 @@ export class OrderController implements IOrderController {

const order = await this.orderService.get(params.id)

res.status(200).json(toSuccessReponse(order))
res.status(200).json(toSuccessResponse(order))
} catch (err) {
this.logger.error(err)
next(err)
Expand Down Expand Up @@ -91,7 +91,7 @@ export class OrderController implements IOrderController {
this.logger.debug(JSON.stringify(grant, null, 2))
res
.status(201)
.json(toSuccessReponse({ redirectUrl: grant.interact.redirect }))
.json(toSuccessResponse({ redirectUrl: grant.interact.redirect }))
} catch (err) {
next(err)
}
Expand Down Expand Up @@ -153,7 +153,7 @@ export class OrderController implements IOrderController {
amount
)

res.status(200).json(toSuccessReponse({ redirectUrl }))
res.status(200).json(toSuccessResponse({ redirectUrl }))
} catch (err) {
next(err)
}
Expand Down Expand Up @@ -202,7 +202,7 @@ export class OrderController implements IOrderController {
})

res.status(200).json(
toSuccessReponse({
toSuccessResponse({
...tokenInfo,
walletAddressUrl: identifierData.walletAddressUrl
})
Expand Down Expand Up @@ -230,7 +230,7 @@ export class OrderController implements IOrderController {
const tokenInfo = await this.openPayments.instantBuy({ order, ...args })

res.status(200).json(
toSuccessReponse({
toSuccessResponse({
...tokenInfo,
walletAddressUrl: args.walletAddressUrl
})
Expand Down
6 changes: 3 additions & 3 deletions packages/boutique/backend/src/product/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextFunction, Request } from 'express'
import { IProductService } from './service'
import { Product } from './model'
import { BadRequest } from '@/errors'
import { toSuccessReponse } from '@/shared/utils'
import { toSuccessResponse } from '@/shared/utils'
import { Logger } from 'winston'

interface GetParams {
Expand Down Expand Up @@ -36,7 +36,7 @@ export class ProductController implements IProductController {

const product = await this.productService.getBySlug(params.slug)

res.status(200).json(toSuccessReponse(product))
res.status(200).json(toSuccessResponse(product))
} catch (err) {
next(err)
}
Expand All @@ -49,7 +49,7 @@ export class ProductController implements IProductController {
) {
try {
const products = await this.productService.list()
res.status(200).json(toSuccessReponse(products))
res.status(200).json(toSuccessResponse(products))
} catch (err) {
this.logger.error(err)
next(err)
Expand Down
6 changes: 3 additions & 3 deletions packages/boutique/backend/src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export function deleteProperty<T, K extends keyof T>(
interface SuccessResponse extends Omit<TypedResponseBody, 'errors'> {}
interface ErrorResponse extends Omit<TypedResponseBody, 'data'> {}

export function toSuccessReponse<T>(
data: T,
export function toSuccessResponse<T>(
result: T,
message: string = 'SUCCESS'
): SuccessResponse {
return {
success: true,
message: message,
data
result
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/boutique/backend/tests/product/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ describe('Application', (): void => {
expect(res._getJSONData()).toMatchObject({
success: true
})
expect(res._getJSONData().data.length).toBe(6)
expect(res._getJSONData().result.length).toBe(6)
})

it('should return an empty array if there are no products', async (): Promise<void> => {
await productController.list(req, res, next)
expect(res.statusCode).toBe(200)
expect(res._getJSONData()).toMatchObject({
success: true,
data: []
result: []
})
})

Expand Down Expand Up @@ -136,7 +136,7 @@ describe('Application', (): void => {
expect(res._getJSONData()).toMatchObject({
success: true,
message: 'SUCCESS',
data: product
result: product
})
})
})
Expand Down
6 changes: 3 additions & 3 deletions packages/boutique/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toast": "^1.1.5",
"@tanstack/react-query": "^5.17.9",
"@tanstack/react-query": "^5.17.15",
"class-variance-authority": "^0.7.0",
"framer-motion": "^10.18.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.49.3",
"react-router-dom": "^6.21.1",
"react-router-dom": "^6.21.2",
"remix-params-helper": "^0.5.1",
"tailwind-merge": "^2.2.0",
"tailwindcss-animate": "^1.0.7",
Expand All @@ -31,7 +31,7 @@
"devDependencies": {
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.10",
"@types/react": "18.2.47",
"@types/react": "18.2.48",
"@types/react-dom": "18.2.18",
"@vitejs/plugin-react-swc": "^3.5.0",
"autoprefixer": "^10.4.16",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const OneClickSetupDialog = ({
}
})

if (data?.data.redirectUrl) {
window.location.href = data.data.redirectUrl
if (data?.result.redirectUrl) {
window.location.href = data.result.redirectUrl
}

return (
Expand Down
4 changes: 2 additions & 2 deletions packages/boutique/frontend/src/app/cart/finish.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export function Component() {
result
},
{
onSuccess({ data }) {
setToken(data)
onSuccess({ result }) {
setToken(result)
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ const OpenPaymentsForm = () => {
}
})

if (data?.data.redirectUrl) {
if (data?.result.redirectUrl) {
resetCart()
window.location.href = data.data.redirectUrl
window.location.href = data.result.redirectUrl
}

return (
Expand Down
12 changes: 6 additions & 6 deletions packages/boutique/frontend/src/app/products/$slug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,29 @@ export function Component() {

if (data) {
return (
<ProductContext.Provider value={{ product: data.data }}>
<ProductContext.Provider value={{ product: data.result }}>
<div className="lg:grid lg:grid-cols-3 lg:gap-x-12">
<div className="aspect-h-1 aspect-w-1 mx-auto h-80 w-80 overflow-hidden rounded-md bg-gray-50 lg:w-full">
<img
src={`${IMAGES_URL}${data.data.image}`}
alt={data.data.name}
src={`${IMAGES_URL}${data.result.image}`}
alt={data.result.name}
className="h-full w-full object-cover object-center"
/>
</div>

<div className="col-span-2 mt-10 px-4 sm:mt-16 sm:px-0 lg:mt-0">
<h1 className="text-3xl font-bold tracking-tight">
{data.data.name}
{data.result.name}
</h1>
<div className="mt-3">
<p className="text-3xl tracking-tight">
{formatPrice(data.data.price)}
{formatPrice(data.result.price)}
</p>
</div>
<div className="prose mt-6 max-w-full">
<blockquote
className="quote space-y-6"
dangerouslySetInnerHTML={{ __html: data.data.description }}
dangerouslySetInnerHTML={{ __html: data.result.description }}
/>
</div>
<ProductCTA />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const ProductCTA = () => {
}
})

if (data?.data.accessToken) {
setToken(data.data)
if (data?.result.accessToken) {
setToken(data.result)
return (
<Navigate to="/checkout/confirmation?instantBuy=true" replace={true} />
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ProductsList = () => {
if (products.data) {
return (
<ProductsListWrapper>
{products.data.data.map((product) => (
{products.data.result.map((product) => (
<ProductCard key={product.id} product={product} />
))}
</ProductsListWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIError } from '@/lib/fetcher.ts'
import { SuccessReponse } from '@/lib/types.ts'
import { SuccessResponse } from '@/lib/types.ts'
import { UseMutationOptions } from '@tanstack/react-query'
import { z } from 'zod'
import { useCustomMutation } from './use-custom-mutation.ts'
Expand All @@ -24,7 +24,7 @@ export const createOrderSchema = z.object({

export function useCreateOrderMutation(
options?: UseMutationOptions<
SuccessReponse<CreateOrderMutationResponse>,
SuccessResponse<CreateOrderMutationResponse>,
APIError<z.infer<typeof createOrderSchema>>,
CreateOrderMutationParams
>
Expand Down
6 changes: 3 additions & 3 deletions packages/boutique/frontend/src/hooks/use-custom-mutation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIError, fetcher } from '@/lib/fetcher.ts'
import { SuccessReponse } from '@/lib/types.ts'
import { SuccessResponse } from '@/lib/types.ts'
import {
UseMutationOptions,
UseMutationResult,
Expand All @@ -21,11 +21,11 @@ export function useCustomMutation<
>(
fetcherOptions: FetcherOptions,
options?: UseMutationOptions<
SuccessReponse<TData>,
SuccessResponse<TData>,
APIError<TSchema>,
TParams
>
): UseMutationResult<SuccessReponse<TData>, APIError<TSchema>, TParams> {
): UseMutationResult<SuccessResponse<TData>, APIError<TSchema>, TParams> {
const { method, endpoint } = fetcherOptions
return useMutation({
mutationFn: async function (params: TParams) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIError } from '@/lib/fetcher.ts'
import { SuccessReponse } from '@/lib/types.ts'
import { SuccessResponse } from '@/lib/types.ts'
import { UseMutationOptions } from '@tanstack/react-query'
import { z } from 'zod'
import { useCustomMutation } from './use-custom-mutation.ts'
Expand All @@ -15,7 +15,7 @@ export const finishCheckoutSchema = z.object({
export function useFinishCheckoutMutation(
orderId: string,
options?: UseMutationOptions<
SuccessReponse,
SuccessResponse,
APIError<z.infer<typeof finishCheckoutSchema>>,
FinishCheckoutMutationParams
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIError } from '@/lib/fetcher.ts'
import { SuccessReponse } from '@/lib/types.ts'
import { SuccessResponse } from '@/lib/types.ts'
import { UseMutationOptions } from '@tanstack/react-query'
import { z } from 'zod'
import { useCustomMutation } from './use-custom-mutation.ts'
Expand All @@ -14,7 +14,7 @@ export const finishSetupSchema = finishCheckoutSchema.extend({

export function useFinishSetupMutation(
options?: UseMutationOptions<
SuccessReponse<TokenState>,
SuccessResponse<TokenState>,
APIError<z.infer<typeof finishSetupSchema>>,
FinishSetupMutationParams
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIError } from '@/lib/fetcher.ts'
import { SuccessReponse } from '@/lib/types.ts'
import { SuccessResponse } from '@/lib/types.ts'
import { UseMutationOptions } from '@tanstack/react-query'
import { z } from 'zod'
import { useCustomMutation } from './use-custom-mutation.ts'
Expand Down Expand Up @@ -32,7 +32,7 @@ export const instantBuySchema = z.object({

export function useInstantBuyMutation(
options?: UseMutationOptions<
SuccessReponse<InstantBuyMutationResponse>,
SuccessResponse<InstantBuyMutationResponse>,
APIError<z.infer<typeof instantBuySchema>>,
InstantBuyMutationParams
>
Expand Down
4 changes: 2 additions & 2 deletions packages/boutique/frontend/src/hooks/use-product-query.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { UseQueryResult, useQuery } from '@tanstack/react-query'
import { fetcher, APIError } from '@/lib/fetcher.ts'
import { SuccessReponse } from '@/lib/types.ts'
import { SuccessResponse } from '@/lib/types.ts'
import { Product } from './use-products-query.ts'
import { useZodRouteParams } from './use-zod-params.ts'
import { productSlugParamsSchema } from '@/app/route-schemas.ts'

export function useProductQuery(): UseQueryResult<
SuccessReponse<Product>,
SuccessResponse<Product>,
APIError
> {
const { slug } = useZodRouteParams(productSlugParamsSchema)
Expand Down
4 changes: 2 additions & 2 deletions packages/boutique/frontend/src/hooks/use-products-query.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UseQueryResult, useQuery } from '@tanstack/react-query'
import { fetcher, APIError } from '@/lib/fetcher.ts'
import { SuccessReponse } from '@/lib/types.ts'
import { SuccessResponse } from '@/lib/types.ts'

export interface Product {
id: string
Expand All @@ -12,7 +12,7 @@ export interface Product {
}

export function useProductsQuery(): UseQueryResult<
SuccessReponse<Product[]>,
SuccessResponse<Product[]>,
APIError
> {
return useQuery({
Expand Down
Loading

0 comments on commit 89908f2

Please sign in to comment.