From eed9c96e7f060ce69a5c6e1e946b0f5a71b4469d Mon Sep 17 00:00:00 2001 From: Krishna Thota Date: Fri, 16 Jan 2026 11:53:17 -0800 Subject: [PATCH] chore: fix linter warnings in nodejs sample --- rest/nodejs/src/api/checkout.ts | 14 +++++++------- rest/nodejs/src/api/discovery.ts | 4 ++-- rest/nodejs/src/api/order.ts | 4 ++-- rest/nodejs/src/api/testing.ts | 6 +++--- rest/nodejs/src/data/transactions.ts | 2 +- rest/nodejs/src/models/extensions.ts | 2 +- rest/nodejs/src/utils/validation.ts | 6 +++--- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/rest/nodejs/src/api/checkout.ts b/rest/nodejs/src/api/checkout.ts index 0a588a6..40bce24 100644 --- a/rest/nodejs/src/api/checkout.ts +++ b/rest/nodejs/src/api/checkout.ts @@ -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. @@ -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}; } } @@ -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); } @@ -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; } } diff --git a/rest/nodejs/src/api/discovery.ts b/rest/nodejs/src/api/discovery.ts index 2f70284..208bc77 100644 --- a/rest/nodejs/src/api/discovery.ts +++ b/rest/nodejs/src/api/discovery.ts @@ -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. diff --git a/rest/nodejs/src/api/order.ts b/rest/nodejs/src/api/order.ts index 463172b..aeb7b39 100644 --- a/rest/nodejs/src/api/order.ts +++ b/rest/nodejs/src/api/order.ts @@ -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. diff --git a/rest/nodejs/src/api/testing.ts b/rest/nodejs/src/api/testing.ts index 6425aac..02cd35a 100644 --- a/rest/nodejs/src/api/testing.ts +++ b/rest/nodejs/src/api/testing.ts @@ -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) {} @@ -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); } diff --git a/rest/nodejs/src/data/transactions.ts b/rest/nodejs/src/data/transactions.ts index 0198755..22b9dbf 100644 --- a/rest/nodejs/src/data/transactions.ts +++ b/rest/nodejs/src/data/transactions.ts @@ -1,4 +1,4 @@ -import {type ExtendedCheckoutResponse, type Order} from '../models'; +import type {ExtendedCheckoutResponse, Order} from '../models'; import {getTransactionsDb} from './db'; diff --git a/rest/nodejs/src/models/extensions.ts b/rest/nodejs/src/models/extensions.ts index 14804cf..29704f7 100644 --- a/rest/nodejs/src/models/extensions.ts +++ b/rest/nodejs/src/models/extensions.ts @@ -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(), diff --git a/rest/nodejs/src/utils/validation.ts b/rest/nodejs/src/utils/validation.ts index 3ebf6bf..501f7cf 100644 --- a/rest/nodejs/src/utils/validation.ts +++ b/rest/nodejs/src/utils/validation.ts @@ -1,4 +1,4 @@ -import {type Context} from 'hono'; +import type {Context} from 'hono'; import * as z from 'zod'; /** @@ -11,8 +11,8 @@ import * as z from 'zod'; */ export function prettyValidation( 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) {