Skip to content

Commit 5a96f08

Browse files
authored
feat: migrate all server routes to new project structure (#156)
1 parent 4208122 commit 5a96f08

20 files changed

+999
-840
lines changed

client/components/fastlane/html/src/fastlane.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async function renderFastlaneGuestExperience() {
121121

122122
async function createOrder(paymentToken) {
123123
const response = await fetch(
124-
"/paypal-api/checkout/orders/create-order-for-fastlane",
124+
"/paypal-api/checkout/orders/create-order-for-card-with-single-use-token",
125125
{
126126
method: "POST",
127127
headers: {

server/node/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ export const PRODUCT_CATALOG: Record<string, Product> = {
108108

109109
- `getProduct(sku: string)` - Get product by SKU
110110
- `getAllProducts()` - Get all products as array
111-
- `getProductPrice(sku: string)` - Get price for a specific SKU
112111

113112
---
114113

server/node/src/customApiEndpoints/createSubscriptionProduct.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ export async function createSubscriptionProduct(
3535
body: JSON.stringify(productDetails),
3636
});
3737

38-
const jsonResponse = await response.json();
38+
const result = await response.json();
3939

4040
if (!response.ok) {
41-
const { message } = jsonResponse as CreateSubscriptionProductErrorResponse;
41+
const { message } = result as CreateSubscriptionProductErrorResponse;
4242
throw new CustomApiError({
4343
message: message,
4444
statusCode: response.status,
45-
jsonResponse,
45+
result,
4646
});
4747
}
4848

49-
return jsonResponse as CreateSubscriptionProductSuccessResponse;
49+
return result as CreateSubscriptionProductSuccessResponse;
5050
}

server/node/src/customApiEndpoints/findEligibleMethods.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,7 @@ export async function findEligibleMethods({
6868
userAgent?: string;
6969
}) {
7070
const accessToken = await getFullScopeAccessToken();
71-
const { success, error, data } =
72-
FindEligibleMethodsRequestSchema.safeParse(body);
73-
74-
if (!success) {
75-
throw new Error(z.prettifyError(error));
76-
}
71+
const data = FindEligibleMethodsRequestSchema.parse(body);
7772

7873
const response = await fetch(
7974
`${BASE_URL}/v2/payments/find-eligible-methods`,
@@ -89,16 +84,16 @@ export async function findEligibleMethods({
8984
},
9085
);
9186

92-
const jsonResponse = await response.json();
87+
const result = await response.json();
9388

9489
if (!response.ok) {
95-
const { message } = jsonResponse as FindEligibleMethodsErrorResponse;
90+
const { message } = result as FindEligibleMethodsErrorResponse;
9691
throw new CustomApiError({
9792
message: message || "Failed to find eligible methods",
9893
statusCode: response.status,
99-
jsonResponse,
94+
result,
10095
});
10196
}
10297

103-
return jsonResponse as FindEligibleMethodsSuccessResponse;
98+
return result as FindEligibleMethodsSuccessResponse;
10499
}

server/node/src/customApiEndpoints/utils.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,36 @@ export async function getFullScopeAccessToken() {
3232
},
3333
});
3434

35-
const jsonResponse = await response.json();
35+
const result = await response.json();
3636

3737
if (!response.ok) {
38-
const { error_description } = jsonResponse as AuthTokenErrorResponse;
38+
const { error_description } = result as AuthTokenErrorResponse;
3939
throw new CustomApiError({
4040
message: error_description || "Failed to create full scope access token",
4141
statusCode: response.status,
42-
jsonResponse,
42+
result,
4343
});
4444
}
4545

46-
const { access_token } = jsonResponse as AuthTokenSuccessResponse;
46+
const { access_token } = result as AuthTokenSuccessResponse;
4747
return access_token;
4848
}
4949

5050
export class CustomApiError extends Error {
5151
statusCode: number;
52-
jsonResponse: Record<string, unknown>;
52+
result: Record<string, unknown>;
5353

5454
constructor({
5555
message,
5656
statusCode,
57-
jsonResponse,
57+
result,
5858
}: {
5959
message: string;
6060
statusCode: number;
61-
jsonResponse: Record<string, unknown>;
61+
result: Record<string, unknown>;
6262
}) {
6363
super(message);
6464
this.statusCode = statusCode;
65-
this.jsonResponse = jsonResponse;
65+
this.result = result;
6666
}
6767
}

server/node/src/middleware/errorMiddleware.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { z, ZodError } from "zod/v4";
22
import { ApiError } from "@paypal/paypal-server-sdk";
33
import type { Request, Response, NextFunction } from "express";
44

5+
import { CustomApiError } from "../customApiEndpoints/utils";
6+
57
export default async function errorMiddleware(
68
error: Error,
79
_request: Request,
@@ -13,7 +15,7 @@ export default async function errorMiddleware(
1315
error: "Bad Request",
1416
errorDescription: z.prettifyError(error),
1517
});
16-
} else if (error instanceof ApiError) {
18+
} else if (error instanceof ApiError || error instanceof CustomApiError) {
1719
const { result, statusCode } = error;
1820
response.status(statusCode).json(result);
1921
} else {

0 commit comments

Comments
 (0)