Skip to content

Commit 31ff604

Browse files
Justintime50claude
andauthored
fix: Comprehensive TypeScript definitions audit and fixes (#534)
## Summary This PR addresses multiple critical issues with TypeScript definitions found during a comprehensive audit of the codebase. > NOTE: AI was used to generate these changes which would have been difficult to identify by hand. Closes #438 (partially) Closes #515 ## Fixes - Fixes #515 - ReferralCustomer type export issue - Property now correctly exported as `ReferralCustomer` (not `Referral`) to match JavaScript implementation - Added missing `api_keys` field to Referral interface ## Changes ### Critical Issues Fixed #### 1. Duplicate Rate Definitions - **Problem**: Two separate IRate interfaces in `types/Rate/Rate.d.ts` and `types/Shipment/Rate.d.ts` - **Fix**: Consolidated into single canonical definition, removed duplicate - **Files**: Deleted `types/Shipment/Rate.d.ts`, updated `types/Shipment/index.d.ts` to re-export from `../Rate` #### 2. Missing Exports Added missing exports to `types/index.d.ts`: - Referral - Claim - CustomerPortal - Embeddable - SmartRate - Luma #### 3. Missing Service Definitions Added missing services to EasyPost client (`types/EasyPost.d.ts`): - Luma - Claim - CustomerPortal (as CustomerPortalAccountLink) - Embeddable (as EmbeddablesSession) - SmartRate - ReferralCustomer (as Referral) ← **Fixes #515** #### 4. Missing Type Definitions - **Luma**: Created complete type definitions based on `src/services/luma_service.js` - `types/Luma/Luma.d.ts` - `types/Luma/index.d.ts` - **SmartRate**: Created missing `types/SmartRate/index.d.ts` - **TaxIdentifier**: Created `types/Shipment/TaxIdentifier.d.ts` for embedded tax identifier objects ### High Priority Fixes #### 5. Interface/Class Property Mismatches - **Pickup.instructions**: Made class property optional nullable to match interface - **Order**: Fixed `return_address`, `buyer_address`, `is_return` to be optional nullable - **User.reference**: Added missing field to IUser interface #### 6. Typos and Inconsistencies - **Options.d.ts**: Fixed typo `pickup_man_datetime` → `pickup_max_datetime` - **ScanForm.d.ts**: Standardized `getNextPage()` return type to use `scan_forms` - **Referral.d.ts**: Standardized `getNextPage()` return type to use `referral_customers` ## Testing - ✅ Build successful: `npm run build` - ✅ All tests passing: 173 tests across 34 test files - ✅ All new type files created correctly - ✅ Duplicate files removed successfully ## Files Changed **Modified (12)**: - types/EasyPost.d.ts - types/Order/Order.d.ts - types/Pickup/Pickup.d.ts - types/Referral/Referral.d.ts - types/ScanForm/ScanForm.d.ts - types/Shipment/Options/Options.d.ts - types/Shipment/Shipment.d.ts - types/Shipment/ShipmentCreateParameters.d.ts - types/Shipment/index.d.ts - types/User/User.d.ts - types/index.d.ts **Created (5)**: - types/Luma/Luma.d.ts - types/Luma/index.d.ts - types/SmartRate/index.d.ts - types/Shipment/TaxIdentifier.d.ts **Deleted (1)**: - types/Shipment/Rate.d.ts 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 6d434a8 commit 31ff604

17 files changed

Lines changed: 118 additions & 88 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- `ApiKey.enable`
99
- `ApiKey.disable`
1010
- Adds a `Tracker.delete` function
11+
- Fixes various Typescript definitions (adding missing items, correcting invalid items, consolidating duplicates, etc)
1112

1213
## v8.4.0 (2025-11-24)
1314

types/EasyPost.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import { Batch } from './Batch';
44
import { Billing } from './Billing';
55
import { Brand } from './Brand';
66
import { CarrierAccount, CarrierMetadata, CarrierType } from './Carrier';
7+
import { Claim } from './Claim';
8+
import { CustomerPortalAccountLink } from './CustomerPortal';
79
import { CustomsInfo, CustomsItem } from './Customs';
10+
import { EmbeddablesSession } from './Embeddable';
811
import { EndShipper } from './EndShipper';
912
import { Event } from './Event';
1013
import { Fee } from './Fee';
1114
import { Insurance } from './Insurance';
15+
import { Luma } from './Luma';
1216
import { Order } from './Order';
1317
import { Parcel } from './Parcel';
1418
import { PaymentMethod } from './PaymentMethod';
@@ -19,6 +23,7 @@ import { Refund } from './Refund';
1923
import { Report } from './Report';
2024
import { ScanForm } from './ScanForm';
2125
import { Shipment } from './Shipment';
26+
import { SmartRate } from './SmartRate';
2227
import { Tracker } from './Tracker';
2328
import { User } from './User';
2429
import { Utils } from './Utility';
@@ -77,22 +82,27 @@ export default class EasyPost {
7782
public CarrierAccount: typeof CarrierAccount;
7883
public CarrierMetadata: typeof CarrierMetadata;
7984
public CarrierType: typeof CarrierType;
85+
public Claim: typeof Claim;
86+
public CustomerPortal: typeof CustomerPortalAccountLink;
8087
public CustomsInfo: typeof CustomsInfo;
8188
public CustomsItem: typeof CustomsItem;
89+
public Embeddable: typeof EmbeddablesSession;
8290
public EndShipper: typeof EndShipper;
8391
public Event: typeof Event;
8492
public Fee: typeof Fee; // TODO: Fix IFee
8593
public Insurance: typeof Insurance;
94+
public Luma: typeof Luma;
8695
public Order: typeof Order;
8796
public Parcel: typeof Parcel;
8897
public PaymentMethod: typeof PaymentMethod;
8998
public Pickup: typeof Pickup;
9099
public Rate: typeof Rate;
91-
public Referral: typeof Referral;
100+
public ReferralCustomer: typeof Referral;
92101
public Refund: typeof Refund;
93102
public Report: typeof Report;
94103
public ScanForm: typeof ScanForm;
95104
public Shipment: typeof Shipment;
105+
public SmartRate: typeof SmartRate;
96106
public Tracker: typeof Tracker;
97107
public User: typeof User;
98108
public Utils: typeof Utils;

types/Luma/Luma.d.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Interface representing an EasyPost Luma promise object.
3+
*
4+
* @see https://docs.easypost.com/docs/luma
5+
*/
6+
export declare interface ILumaPromise {
7+
/** Always returns "LumaInfo". */
8+
object: string;
9+
10+
/** The delivery date and time commitment. */
11+
delivery_datetime: string | null;
12+
13+
/** The delivery date commitment. */
14+
delivery_date: string | null;
15+
16+
/** The pickup date and time commitment. */
17+
pickup_datetime: string | null;
18+
19+
/** The pickup date commitment. */
20+
pickup_date: string | null;
21+
22+
/** The carrier account used for the promise. */
23+
carrier_account_id: string | null;
24+
25+
/** The service level used for the promise. */
26+
service: string | null;
27+
28+
/** The carrier used for the promise. */
29+
carrier: string | null;
30+
}
31+
32+
/**
33+
* The Luma class interacts with the Luma API to provide service recommendations.
34+
*
35+
* @see https://docs.easypost.com/docs/luma
36+
*/
37+
export declare class Luma {
38+
/**
39+
* Get service recommendations from Luma that meet the criteria of your ruleset.
40+
*
41+
* @see https://docs.easypost.com/docs/luma
42+
*
43+
* @param params - The parameters to get a Luma promise with (shipment parameters).
44+
* @returns {Promise<ILumaPromise>} - An object containing the Luma promise.
45+
*/
46+
static getPromise(params: object): Promise<ILumaPromise>;
47+
}

types/Luma/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Luma';

types/Order/Order.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ export declare class Order implements IOrder {
6767
id: string;
6868
mode: 'test' | 'production';
6969
object: 'Order';
70-
reference?: string;
70+
reference?: string | null;
7171
to_address: IAddress;
7272
from_address: IAddress;
73-
return_address: IAddress;
74-
buyer_address: IAddress;
73+
return_address?: IAddress | null;
74+
buyer_address?: IAddress | null;
7575
shipments: IShipment[];
7676
rates: IRate[];
7777
messages: IMessage[];
78-
is_return: boolean;
78+
is_return?: boolean | null;
7979
created_at: string;
8080
updated_at: string;
8181

types/Pickup/Pickup.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export declare class Pickup implements IPickup {
101101
min_datetime: string;
102102
max_datetime: string;
103103
is_account_address?: boolean | null;
104-
instructions: string;
104+
instructions?: string | null;
105105
messages: IMessage[];
106106
confirmation: string;
107107
shipment: IShipment;

types/Referral/Referral.d.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { IApiKey } from '../ApiKey';
12
import { IUser } from '../User';
23
import { IReferralCreateParameters } from './ReferralCreateParameters';
34
import { IReferralListParameters } from './ReferralListParameters';
@@ -7,7 +8,14 @@ import { IReferralListParameters } from './ReferralListParameters';
78
*
89
* @see https://docs.easypost.com/docs/users/referral-customers
910
*/
10-
export declare interface IReferral extends IUser {}
11+
export declare interface IReferral extends IUser {
12+
/**
13+
* API keys for the referral customer (only returned on creation).
14+
* Contains both test and production API keys.
15+
* These keys should be saved securely as they cannot be retrieved again later.
16+
*/
17+
api_keys?: IApiKey[];
18+
}
1119

1220
export declare class Referral implements IReferral {
1321
public constructor(input: IReferralCreateParameters);
@@ -26,6 +34,7 @@ export declare class Referral implements IReferral {
2634
secondary_recharge_amount: string;
2735
recharge_threshold: string;
2836
children: IUser[];
37+
api_keys?: IApiKey[];
2938

3039
/**
3140
* Creates a referral customer.
@@ -111,5 +120,5 @@ export declare class Referral implements IReferral {
111120
static getNextPage(
112121
referralCustomers: Object,
113122
pageSize?: number,
114-
): Promise<{ referrals: Referral[]; has_more: boolean }>;
123+
): Promise<{ referral_customers: Referral[]; has_more: boolean }>;
115124
}

types/ScanForm/ScanForm.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,5 @@ export declare class ScanForm implements IScanForm {
122122
static getNextPage(
123123
scanforms: Object,
124124
pageSize?: number,
125-
): Promise<{ scanforms: ScanForm[]; has_more: boolean }>;
125+
): Promise<{ scan_forms: ScanForm[]; has_more: boolean }>;
126126
}

types/Shipment/Options/Options.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export declare interface IOptions {
275275
/**
276276
* The latest a package should be picked up. Supported carriers vary.
277277
*/
278-
pickup_man_datetime: string | null;
278+
pickup_max_datetime: string | null;
279279

280280
/**
281281
* You can optionally print custom messages on labels.

types/Shipment/Rate.d.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)