Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
241226c
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
a1502e4
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
efbf171
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
aa73e20
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
d000080
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
2c313d7
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
e7cc2c2
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
8f3fef7
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
347175b
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
fb09877
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
5590156
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
f1b8b86
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
6c1c27e
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
6ac4993
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
f793593
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
a6a0141
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
3a0f3d6
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
741f6d4
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
cfcba7d
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
ae34302
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
fc8764e
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
d4ef43f
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
04bdea7
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
954e3ec
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
470c011
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
d21023c
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
6f6418c
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
43f85a7
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
4ad4500
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
1cb5535
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
dc44dd6
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
5676b00
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
2fa623b
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
f3d49d1
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
c5aeb47
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
a8fc58e
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
8c8ab1d
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
0b0f5d9
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
e687111
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
766f496
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
eddcc66
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
2f2a04b
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
083f6f6
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
07ecef1
chore: retrigger flaky CodeQL on TSM-08
Justintime50 Aug 11, 2026
d77189c
TSM-10: convert Group E services to TypeScript
Justintime50 Aug 7, 2026
01f4b4e
TSM-10: add permissive create parameter types for Group E services
Justintime50 Aug 11, 2026
76fef5e
TSM-10: convert Group E tests and beta referral service to TypeScript
Justintime50 Aug 11, 2026
392665b
TSM-10: convert remaining service test harness files to TypeScript
Justintime50 Aug 11, 2026
bb6aca4
TSM-10: add source-derived fixture type assertions in tests
Justintime50 Aug 11, 2026
575b277
TSM-10: simplify ESM module default typing in compat test
Justintime50 Aug 11, 2026
6f77d20
Type service returns for group E services
Justintime50 Aug 12, 2026
d1308b6
Format remaining TS service tests
Justintime50 Aug 12, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import util from 'util';

import Constants from '../constants';
import FilteringError from '../errors/general/filtering_error';
import ApiKey from '../models/api_key';
import baseService from './base_service';

type ApiKeyUser = Record<string, unknown> & {
id?: string;
keys?: ApiKey[];
children?: Array<Record<string, unknown> & { id?: string; keys?: ApiKey[] }>;
};
type ApiKeyAllResponse = Record<string, unknown>;

export default (easypostClient) =>
/**
* The ApiKeyService class provides methods for interacting with EasyPost {@link ApiKey} objects.
Expand All @@ -17,20 +25,20 @@ export default (easypostClient) =>
* @returns {Array} - List of associated API Keys.
* @throws {FilteringError} If user or API Keys are not found.
*/
static async retrieveApiKeysForUser(id) {
static async retrieveApiKeysForUser(id: string): Promise<ApiKey[]> {
const url = `api_keys`;

try {
const response = await easypostClient._get(url);
const user = this._convertToEasyPostObject(response.body);
const user = this._convertToEasyPostObject(response.body) as ApiKeyUser;

if (user.id == id) {
return user.keys;
return user.keys ?? [];
}

user.children.forEach((child) => {
user.children?.forEach((child) => {
if (child.id == id) {
return child.keys;
return child.keys ?? [];
}
});
} catch (e) {
Expand All @@ -45,7 +53,7 @@ export default (easypostClient) =>
* See {@link https://docs.easypost.com/docs/api-keys#retrieve-an-api-key EasyPost API Documentation} for more information.
* @returns {Object} - An object containing the API keys associated with the current authenticated user and its child users.
*/
static async all(params = {}) {
static async all(params: Record<string, unknown> = {}): Promise<ApiKeyAllResponse> {
const url = 'api_keys';

return this._all(url, params);
Expand All @@ -57,7 +65,7 @@ export default (easypostClient) =>
* @param {string} mode - The mode for the API key (either "production" or "test").
* @returns {ApiKey} - The created API key.
*/
static async create(mode) {
static async create(mode: string): Promise<ApiKey> {
const url = 'api_keys';
const params = { mode };

Expand All @@ -70,7 +78,7 @@ export default (easypostClient) =>
* @param {string} id - The ID of the API key to delete.
* @returns {Promise|Promise<never>} - A promise that resolves if the API key was successfully deleted.
*/
static async delete(id) {
static async delete(id: string): Promise<void> {
const url = `api_keys/${id}`;

try {
Expand All @@ -88,7 +96,7 @@ export default (easypostClient) =>
* @param {string} id - The ID of the API key to enable.
* @returns {ApiKey} - The enabled API key.
*/
static async enable(id) {
static async enable(id: string): Promise<ApiKey> {
const url = `api_keys/${id}/enable`;

try {
Expand All @@ -106,7 +114,7 @@ export default (easypostClient) =>
* @param {string} id - The ID of the API key to disable.
* @returns {ApiKey} - The disabled API key.
*/
static async disable(id) {
static async disable(id: string): Promise<ApiKey> {
const url = `api_keys/${id}/disable`;

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import baseService from './base_service';

type BetaPaymentMethodResponse = Record<string, unknown>;
type BetaRefundResponse = Record<string, unknown>;
type BetaClientSecretResponse = Record<string, unknown>;

export default (easypostClient) =>
class BetaReferralCustomerService extends baseService(easypostClient) {
/**
Expand All @@ -9,7 +13,11 @@ export default (easypostClient) =>
* @param {string} [priority] - Which priority to set the payment method to ('primary' or 'secondary').
* @returns {Object} - A JSON object representing the payment method.
*/
static async addPaymentMethod(stripeCustomerId, paymentMethodReference, priority = 'primary') {
static async addPaymentMethod(
stripeCustomerId: string,
paymentMethodReference: string,
priority: string = 'primary',
): Promise<BetaPaymentMethodResponse> {
const params = {
payment_method: {
stripe_customer_id: stripeCustomerId,
Expand All @@ -30,7 +38,7 @@ export default (easypostClient) =>
* @param {number} refundAmount - Amount to be refunded by cents.
* @returns {Object} - A JSON object representing the refund.
*/
static async refundByAmount(refundAmount) {
static async refundByAmount(refundAmount: number): Promise<BetaRefundResponse> {
const params = {
refund_amount: refundAmount,
};
Expand All @@ -47,7 +55,7 @@ export default (easypostClient) =>
* @param {string} paymentLogId - ID of the payment log.
* @returns {object} - Returns BetaPaymentRefund object.
*/
static async refundByPaymentLog(paymentLogId) {
static async refundByPaymentLog(paymentLogId: string): Promise<BetaRefundResponse> {
const params = {
payment_log_id: paymentLogId,
};
Expand All @@ -63,7 +71,7 @@ export default (easypostClient) =>
* Creates a client secret to use with Stripe when adding a credit card.
* @returns {object} - A JSON object representing the client secret.
*/
static async createCreditCardClientSecret() {
static async createCreditCardClientSecret(): Promise<BetaClientSecretResponse> {
const url = 'beta/setup_intents';

const response = await easypostClient._post(url, null);
Expand All @@ -75,7 +83,9 @@ export default (easypostClient) =>
* Creates a client secret to use with Stripe when adding a credit card.
* @returns {object} - A JSON object representing the client secret.
*/
static async createBankAccountClientSecret(returnUrl) {
static async createBankAccountClientSecret(
returnUrl: string | null,
): Promise<BetaClientSecretResponse> {
const params = returnUrl ? { return_url: returnUrl } : null;

const url = 'beta/financial_connections_sessions';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import baseService from './base_service';
import type { ICustomerPortalAccountLink } from '../../types/CustomerPortal/CustomerPortalAccountLink';

type CustomerPortalAccountLinkCreateParameters = Record<string, unknown> & {
session_type?: 'account_onboarding' | 'account_management' | null;
user_id?: string | null;
refresh_url?: string | null;
return_url?: string | null;
metadata?: Record<string, unknown> | null;
};

export default (easypostClient) =>
/**
Expand All @@ -11,7 +20,9 @@ export default (easypostClient) =>
* @param {Object} [params] - The parameters to create a session from.
* @returns {Object} - An object containing the created session.
*/
static async createAccountLink(params = {}) {
static async createAccountLink(
params: CustomerPortalAccountLinkCreateParameters = {},
): Promise<ICustomerPortalAccountLink> {
const url = 'customer_portal/account_link';

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import baseService from './base_service';
import type { IEmbeddablesSession } from '../../types/Embeddable/EmbeddablesSession';

type EmbeddablesSessionCreateParameters = Record<string, unknown> & {
origin_host?: string | null;
user_id?: string | null;
};

export default (easypostClient) =>
/**
Expand All @@ -11,7 +17,9 @@ export default (easypostClient) =>
* @param {Object} [params] - The parameters to create a session from.
* @returns {Object} - An object containing the created session.
*/
static async createSession(params = {}) {
static async createSession(
params: EmbeddablesSessionCreateParameters = {},
): Promise<IEmbeddablesSession> {
const url = 'embeddables/session';

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import baseService from './base_service';
import EndShipper from '../models/end_shipper';

type EndShipperCreateParameters = Record<string, unknown> & {
name?: string | null;
company?: string | null;
street1?: string | null;
street2?: string | null;
city?: string | null;
state?: string | null;
zip?: string | null;
country?: string | null;
phone?: string | null;
email?: string | null;
};
type EndShipperListResponse = { end_shippers: EndShipper[]; has_more: boolean };

export default (easypostClient) =>
/**
Expand All @@ -12,7 +27,7 @@ export default (easypostClient) =>
* @param {Object} params - Parameters for the end shipper to be created.
* @returns {EndShipper} - The created end shipper.
*/
static async create(params) {
static async create(params: EndShipperCreateParameters): Promise<EndShipper> {
const url = 'end_shippers';
const wrappedParams = { address: params };

Expand All @@ -26,7 +41,7 @@ export default (easypostClient) =>
* @param {Object} params - Parameters for the end shipper to be updated.
* @returns {EndShipper} - The updated end shipper.
*/
static async update(id, params) {
static async update(id: string, params: EndShipperCreateParameters): Promise<EndShipper> {
const url = `end_shippers/${id}`;
const wrappedParams = { address: params };

Expand All @@ -45,7 +60,7 @@ export default (easypostClient) =>
* @param {string} id - The ID of the end shipper to retrieve.
* @returns {EndShipper} - The retrieved end shipper.
*/
static async retrieve(id) {
static async retrieve(id: string): Promise<EndShipper> {
const url = `end_shippers/${id}`;

return this._retrieve(url);
Expand All @@ -57,7 +72,7 @@ export default (easypostClient) =>
* @param {Object} [params] - Parameters to filter the list of end shippers.
* @returns {Object} - An object containing a list of {@link EndShipper end shippers} and pagination information.
*/
static async all(params = {}) {
static async all(params: Record<string, unknown> = {}): Promise<EndShipperListResponse> {
const url = 'end_shippers';

return this._all(url, params);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { v4 as uuid } from 'uuid';

import type {
IFedExAccountValidationResponse,
IFedExRequestPinResponse,
} from '../../types/FedExRegistration/FedExRegistration';
import baseService from './base_service';

type FedExValidationMap = Record<string, unknown> & { name?: string | null };
type FedExParams = Record<string, unknown> & {
address_validation?: FedExValidationMap;
pin_validation?: FedExValidationMap;
invoice_validation?: FedExValidationMap;
easypost_details?: Record<string, unknown>;
};

export default (easypostClient) =>
/**
* The FedExRegistrationService class provides methods for registering FedEx carrier accounts with MFA.
Expand All @@ -14,7 +26,10 @@ export default (easypostClient) =>
* @param {Object} params - Map of parameters.
* @returns {Object}
*/
static async registerAddress(fedexAccountNumber, params) {
static async registerAddress(
fedexAccountNumber: string,
params: FedExParams,
): Promise<IFedExAccountValidationResponse> {
const wrappedParams = this._wrapAddressValidation(params);
const endpoint = `fedex_registrations/${fedexAccountNumber}/address`;

Expand All @@ -33,7 +48,11 @@ export default (easypostClient) =>
* @param {Object} params - Map of parameters.
* @returns {Object}
*/
static async requestPin(fedexAccountNumber, pinMethodOption, params) {
static async requestPin(
fedexAccountNumber: string,
pinMethodOption: string,
params: FedExParams,
): Promise<IFedExRequestPinResponse> {
const wrappedParams = this._wrapPinValidation(params);
wrappedParams.pin_method = {
option: pinMethodOption,
Expand All @@ -54,7 +73,10 @@ export default (easypostClient) =>
* @param {Object} params - Map of parameters.
* @returns {Object}
*/
static async validatePin(fedexAccountNumber, params) {
static async validatePin(
fedexAccountNumber: string,
params: FedExParams,
): Promise<IFedExAccountValidationResponse> {
const wrappedParams = this._wrapPinValidation(params);
const endpoint = `fedex_registrations/${fedexAccountNumber}/pin/validate`;

Expand All @@ -72,7 +94,10 @@ export default (easypostClient) =>
* @param {Object} params - Map of parameters.
* @returns {Object}
*/
static async submitInvoice(fedexAccountNumber, params) {
static async submitInvoice(
fedexAccountNumber: string,
params: FedExParams,
): Promise<IFedExAccountValidationResponse> {
const wrappedParams = this._wrapInvoiceValidation(params);
const endpoint = `fedex_registrations/${fedexAccountNumber}/invoice`;

Expand All @@ -91,8 +116,8 @@ export default (easypostClient) =>
* @param {Object} params - The original parameters map.
* @returns {Object} - A new map with properly wrapped address_validation and easypost_details.
*/
static _wrapAddressValidation(params) {
const wrappedParams = {};
static _wrapAddressValidation(params: FedExParams): Record<string, unknown> {
const wrappedParams: Record<string, unknown> = {};

if (params.address_validation) {
const addressValidation = { ...params.address_validation };
Expand All @@ -114,8 +139,8 @@ export default (easypostClient) =>
* @param {Object} params - The original parameters map.
* @returns {Object} - A new map with properly wrapped pin_validation and easypost_details.
*/
static _wrapPinValidation(params) {
const wrappedParams = {};
static _wrapPinValidation(params: FedExParams): Record<string, unknown> {
const wrappedParams: Record<string, unknown> = {};

if (params.pin_validation) {
const pinValidation = { ...params.pin_validation };
Expand All @@ -137,8 +162,8 @@ export default (easypostClient) =>
* @param {Object} params - The original parameters map.
* @returns {Object} - A new map with properly wrapped invoice_validation and easypost_details.
*/
static _wrapInvoiceValidation(params) {
const wrappedParams = {};
static _wrapInvoiceValidation(params: FedExParams): Record<string, unknown> {
const wrappedParams: Record<string, unknown> = {};

if (params.invoice_validation) {
const invoiceValidation = { ...params.invoice_validation };
Expand All @@ -160,7 +185,7 @@ export default (easypostClient) =>
* @private
* @param {Object} map - The map to ensure the "name" field in.
*/
static _ensureNameField(map) {
static _ensureNameField(map: FedExValidationMap): void {
if (!map.name || map.name === null) {
const uuidValue = uuid().replace(/-/g, '');
map.name = uuidValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import baseService from './base_service';
import type { ILumaPromise } from '../../types/Luma/Luma';

type LumaParams = Record<string, unknown>;

export default (easypostClient) =>
/**
Expand All @@ -11,7 +14,7 @@ export default (easypostClient) =>
* @param {Object} params - The parameters to get a Luma promise with.
* @returns {Object} - An object containing the Luma promise.
*/
static async getPromise(params) {
static async getPromise(params: LumaParams): Promise<ILumaPromise> {
const url = `luma/promise`;

const wrappedParams = {
Expand Down
Loading