Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions rest/nodejs/src/api/checkout.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {createHash} from 'crypto';
import {type Context} from 'hono';
import type {Context} from 'hono';
import {v4 as uuidv4} from 'uuid';
import {z} from 'zod';

import {getCheckoutSession, getIdempotencyRecord, getInventory, getOrder, getProduct, logRequest, releaseStock, reserveStock, saveCheckout, saveIdempotencyRecord, saveOrder} from '../data';
import {CheckoutResponseStatusSchema, type Expectation, type ExpectationLineItem, type ExtendedCheckoutCreateRequest, type ExtendedCheckoutResponse, type ExtendedCheckoutUpdateRequest, ExtendedPaymentCredentialSchema, type FulfillmentDestinationRequest, type FulfillmentDestinationResponse, type FulfillmentOptionResponse, type FulfillmentRequest, type FulfillmentResponse, type LineItemCreateRequest, type LineItemResponse, type Order, type OrderLineItem, type PaymentCreateRequest, PaymentDataSchema, type PostalAddress} from '../models';
import {CheckoutResponseStatusSchema, type Expectation, type ExpectationLineItem, type ExtendedCheckoutCreateRequest, type ExtendedCheckoutResponse, type ExtendedCheckoutUpdateRequest, ExtendedPaymentCredentialSchema, type FulfillmentDestinationResponse, type FulfillmentOptionResponse, type FulfillmentRequest, type FulfillmentResponse, type LineItemResponse, type Order, type OrderLineItem, PaymentDataSchema, type PostalAddress} from '../models';

/**
* Schema for the request body when completing a checkout session.
Expand Down Expand Up @@ -71,11 +71,11 @@ export class CheckoutService {
}
}

if (profileData && profileData.ucp && profileData.ucp.capabilities) {
if (profileData?.ucp?.capabilities) {
const orderCap = profileData.ucp.capabilities.find(
(c) => c.name === 'dev.ucp.shopping.order',
);
if (orderCap && orderCap.config && orderCap.config.webhook_url) {
if (orderCap?.config?.webhook_url) {
return {webhook_url: orderCap.config.webhook_url};
}
}
Expand All @@ -93,7 +93,7 @@ export class CheckoutService {
return;
}
const webhookUrl = checkout.platform.webhook_url;
let orderData: Order|undefined = undefined;
let orderData: Order|undefined ;
if (checkout.order_id) {
orderData = getOrder(checkout.order_id);
}
Expand Down Expand Up @@ -163,13 +163,13 @@ export class CheckoutService {
id: d.id || `dest_${uuidv4()}`,
}),
);
} else if (existingFulfillment && existingFulfillment.methods) {
} else if (existingFulfillment?.methods) {
// Default to shipping if type is not provided in request
const targetType = m.type || 'shipping';
const existingMethod = existingFulfillment.methods.find(
(em) => em.type === targetType,
);
if (existingMethod && existingMethod.destinations) {
if (existingMethod?.destinations) {
destinations = existingMethod.destinations;
}
}
Expand Down
4 changes: 2 additions & 2 deletions rest/nodejs/src/api/discovery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {type Context} from 'hono';
import {type UcpDiscoveryProfile} from '../models';
import type {Context} from 'hono';
import type {UcpDiscoveryProfile} from '../models';

/**
* Service for handling UCP discovery requests.
Expand Down
4 changes: 2 additions & 2 deletions rest/nodejs/src/api/order.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type Context} from 'hono';
import type {Context} from 'hono';
import {getOrder, logRequest, saveOrder} from '../data';
import {type Order} from '../models';
import type {Order} from '../models';

/**
* Service for managing orders.
Expand Down
6 changes: 3 additions & 3 deletions rest/nodejs/src/api/testing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type Context} from 'hono';
import type {Context} from 'hono';

import {CheckoutService} from './checkout';
import type {CheckoutService} from './checkout';

export class TestingService {
constructor(private readonly checkoutService: CheckoutService) {}
Expand All @@ -18,7 +18,7 @@ export class TestingService {
try {
await this.checkoutService.shipOrder(id);
return c.json({status: 'shipped'}, 200);
} catch (e: any) {
} catch (e: unknown) {
if (e.message === 'Order not found') {
return c.json({detail: 'Order not found'}, 404);
}
Expand Down
2 changes: 1 addition & 1 deletion rest/nodejs/src/data/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {type ExtendedCheckoutResponse, type Order} from '../models';
import type {ExtendedCheckoutResponse, Order} from '../models';

import {getTransactionsDb} from './db';

Expand Down
2 changes: 1 addition & 1 deletion rest/nodejs/src/models/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {z} from 'zod';

import {CheckoutCreateRequestSchema, CheckoutUpdateRequestSchema, CheckoutWithBuyerConsentSchema, CheckoutWithDiscountSchema, CheckoutWithFulfillmentCreateRequestSchema, CheckoutWithFulfillmentResponseSchema, CheckoutWithFulfillmentUpdateRequestSchema, FulfillmentDestinationResponseSchema, OrderSchema, PaymentCredentialSchema} from './spec_generated';
import {CheckoutCreateRequestSchema, CheckoutUpdateRequestSchema, CheckoutWithBuyerConsentSchema, CheckoutWithDiscountSchema, CheckoutWithFulfillmentCreateRequestSchema, CheckoutWithFulfillmentResponseSchema, CheckoutWithFulfillmentUpdateRequestSchema, OrderSchema, PaymentCredentialSchema} from './spec_generated';

export const ExtendedPaymentCredentialSchema = PaymentCredentialSchema.extend({
token: z.string().optional(),
Expand Down
6 changes: 3 additions & 3 deletions rest/nodejs/src/utils/validation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {type Context} from 'hono';
import type {Context} from 'hono';
import * as z from 'zod';

/**
Expand All @@ -11,8 +11,8 @@ import * as z from 'zod';
*/
export function prettyValidation<T>(
result:
| {success: true; data: T; target: string}
| {success: false; error: any},
| {success: true; data: T; target: string}
| {success: false; error: z.ZodError},
c: Context,
) {
if (result.success) {
Expand Down