Skip to content
Draft
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
18 changes: 12 additions & 6 deletions src/services/claim_service.js → src/services/claim_service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import baseService from './base_service';

type ClaimParams = Record<string, unknown>;
type ClaimCollection = Record<string, unknown>;

export default (easypostClient) =>
/**
* The ClaimService class provides methods for interacting with EasyPost {@link Claim} objects.
Expand All @@ -11,7 +14,7 @@ export default (easypostClient) =>
* @param {Object} params - Parameters for the claim to be created.
* @returns {Claim} - The created claim.
*/
static async create(params) {
static async create(params: ClaimParams): Promise<unknown> {
const url = 'claims';

return this._create(url, params);
Expand All @@ -22,7 +25,7 @@ export default (easypostClient) =>
* @param {Object} [params] - Parameters to filter the claim records.
* @returns {Object} - An object containing the list of {@link Claim claim} records and pagination information.
*/
static async all(params = {}) {
static async all(params: Record<string, unknown> = {}): Promise<unknown> {
const url = 'claims';

return this._all(url, params);
Expand All @@ -34,7 +37,10 @@ export default (easypostClient) =>
* @param {Number} pageSize The number of records to return on each page
* @returns {EasyPostObject|Promise<never>} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error.
*/
static async getNextPage(claims, pageSize = null) {
static async getNextPage(
claims: ClaimCollection,
pageSize: number | null = null,
): Promise<unknown> {
const url = 'claims';
return this._getNextPage(url, 'claims', claims, pageSize);
}
Expand All @@ -44,7 +50,7 @@ export default (easypostClient) =>
* @param {string} id - The ID of the claim to retrieve.
* @returns {Claim} - The retrieved claim.
*/
static async retrieve(id) {
static async retrieve(id: string): Promise<unknown> {
const url = `claims/${id}`;

return this._retrieve(url);
Expand All @@ -55,8 +61,8 @@ export default (easypostClient) =>
* @param {string} id - The ID of the claim to be canceled.
* @returns {Claim} - The canceled claim.
*/
static async cancel(id) {
static async cancel(id: string): Promise<unknown> {
const url = `claims/${id}/cancel`;
return this._create(url);
return this._create(url, {});
}
};
15 changes: 10 additions & 5 deletions src/services/event_service.js → src/services/event_service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import baseService from './base_service';

type EventCollection = Record<string, unknown>;

export default (easypostClient) =>
/**
* The EventService class provides methods for interacting with EasyPost {@link Event} objects.
Expand All @@ -12,7 +14,7 @@ export default (easypostClient) =>
* @param {string} id - The ID of the event to retrieve payloads for.
* @returns {Payload[]} - A list of {@link Payload payloads} for the event.
*/
static async retrieveAllPayloads(id) {
static async retrieveAllPayloads(id: string): Promise<unknown> {
const url = `events/${id}/payloads`;

try {
Expand All @@ -31,7 +33,7 @@ export default (easypostClient) =>
* @param {string} payloadId - The ID of the payload to retrieve.
* @returns {Payload} - The {@link Payload payload} for the event.
*/
static async retrievePayload(id, payloadId) {
static async retrievePayload(id: string, payloadId: string): Promise<unknown> {
const url = `events/${id}/payloads/${payloadId}`;

try {
Expand All @@ -49,7 +51,7 @@ export default (easypostClient) =>
* @param {Object} [params] - Parameters to filter the list of events.
* @returns {Object} - An object containing the list of {@link Event events} and pagination information.
*/
static async all(params = {}) {
static async all(params: Record<string, unknown> = {}): Promise<unknown> {
const url = 'events';

return this._all(url, params);
Expand All @@ -61,7 +63,10 @@ export default (easypostClient) =>
* @param {Number} pageSize The number of records to return on each page
* @returns {EasyPostObject|Promise<never>} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error.
*/
static async getNextPage(events, pageSize = null) {
static async getNextPage(
events: EventCollection,
pageSize: number | null = null,
): Promise<unknown> {
const url = 'events';
return this._getNextPage(url, 'events', events, pageSize);
}
Expand All @@ -72,7 +77,7 @@ export default (easypostClient) =>
* @param {string} id - The ID of the event to retrieve.
* @returns {Event} - The retrieved event.
*/
static async retrieve(id) {
static async retrieve(id: string): Promise<unknown> {
const url = `events/${id}`;

return this._retrieve(url);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import baseService from './base_service';

type InsuranceParams = Record<string, unknown>;
type InsuranceCollection = Record<string, unknown>;

export default (easypostClient) =>
/**
* The InsuranceService class provides methods for interacting with EasyPost {@link Insurance} objects.
Expand All @@ -12,7 +15,7 @@ export default (easypostClient) =>
* @param {Object} params - Parameters for the insurance to be created.
* @returns {Insurance} - The created insurance.
*/
static async create(params) {
static async create(params: InsuranceParams): Promise<unknown> {
const url = 'insurances';

const wrappedParams = {
Expand All @@ -28,7 +31,7 @@ export default (easypostClient) =>
* @param {Object} [params] - Parameters to filter the insurance records.
* @returns {Object} - An object containing the list of {@link Insurance insurance} records and pagination information.
*/
static async all(params = {}) {
static async all(params: Record<string, unknown> = {}): Promise<unknown> {
const url = 'insurances';

return this._all(url, params);
Expand All @@ -40,7 +43,10 @@ export default (easypostClient) =>
* @param {Number} pageSize The number of records to return on each page
* @returns {EasyPostObject|Promise<never>} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error.
*/
static async getNextPage(insurances, pageSize = null) {
static async getNextPage(
insurances: InsuranceCollection,
pageSize: number | null = null,
): Promise<unknown> {
const url = 'insurances';
return this._getNextPage(url, 'insurances', insurances, pageSize);
}
Expand All @@ -51,7 +57,7 @@ export default (easypostClient) =>
* @param {string} id - The ID of the insurance to retrieve.
* @returns {Insurance} - The retrieved insurance.
*/
static async retrieve(id) {
static async retrieve(id: string): Promise<unknown> {
const url = `insurances/${id}`;

return this._retrieve(url);
Expand All @@ -63,7 +69,7 @@ export default (easypostClient) =>
* @param {string} id - The ID of the insurance to be refunded.
* @returns {Insurance} - The refunded insurance.
*/
static async refund(id) {
static async refund(id: string): Promise<unknown> {
const url = `insurances/${id}/refund`;
const response = await easypostClient._post(url);

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

type TrackerParams = Record<string, unknown>;
type TrackerCollection = Record<string, unknown>;

export default (easypostClient) =>
/**
* The TrackerService class provides methods for interacting with EasyPost {@link Tracker} objects.
Expand All @@ -12,7 +15,7 @@ export default (easypostClient) =>
* @param {Object} params - The parameters to create a tracker with.
* @returns {Tracker} - The created tracker.
*/
static async create(params) {
static async create(params: TrackerParams): Promise<unknown> {
const url = 'trackers';

const wrappedParams = {
Expand All @@ -28,7 +31,7 @@ export default (easypostClient) =>
* @param {Object} [params] - The parameters to filter the trackers by.
* @returns {Object} - An object containing the list of {@link Tracker trackers} and pagination information.
*/
static async all(params = {}) {
static async all(params: Record<string, unknown> = {}): Promise<unknown> {
const url = 'trackers';

return this._all(url, params);
Expand All @@ -40,7 +43,10 @@ export default (easypostClient) =>
* @param {Number} pageSize The number of records to return on each page
* @returns {EasyPostObject|Promise<never>} The retrieved {@link EasyPostObject}-based class instance, or a `Promise` that rejects with an error.
*/
static async getNextPage(trackers, pageSize = null) {
static async getNextPage(
trackers: TrackerCollection,
pageSize: number | null = null,
): Promise<unknown> {
const url = 'trackers';

return this._getNextPage(url, 'trackers', trackers, pageSize);
Expand All @@ -52,7 +58,7 @@ export default (easypostClient) =>
* @param {string} id - The ID of the tracker to retrieve.
* @returns {Tracker} - The retrieved tracker.
*/
static async retrieve(id) {
static async retrieve(id: string): Promise<unknown> {
const url = `trackers/${id}`;

return this._retrieve(url);
Expand All @@ -63,7 +69,7 @@ export default (easypostClient) =>
* @param {Object} [params] - The parameters to filter the trackers by.
* @returns {Object} - An object containing the list of {@link Tracker trackers}.
*/
static async retrieveBatch(params = {}) {
static async retrieveBatch(params: Record<string, unknown> = {}): Promise<unknown> {
const url = 'trackers/batch';

try {
Expand All @@ -81,7 +87,7 @@ export default (easypostClient) =>
* @param {string} id - The ID of the tracker to delete.
* @returns {Promise<void>}
*/
static async delete(id) {
static async delete(id: string): Promise<void> {
const url = `trackers/${id}`;

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

type WebhookParams = Record<string, unknown>;

export default (easypostClient) =>
/**
* The WebhookService class provides methods for interacting with EasyPost {@link Webhook} objects.
Expand All @@ -12,7 +14,7 @@ export default (easypostClient) =>
* @param {Object} params - The parameters to create a webhook with.
* @returns {Webhook} - The created webhook.
*/
static async create(params) {
static async create(params: WebhookParams): Promise<unknown> {
const url = 'webhooks';

const wrappedParams = {
Expand All @@ -30,7 +32,7 @@ export default (easypostClient) =>
* @param {Object} params - The parameters to update the webhook with.
* @returns {Webhook} - The updated webhook.
*/
static async update(id, params) {
static async update(id: string, params: Record<string, unknown>): Promise<unknown> {
const url = `webhooks/${id}`;

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

try {
Expand All @@ -66,7 +68,7 @@ export default (easypostClient) =>
* @param {Object} [params]
* @returns {Webhook[]}
*/
static async all(params = {}) {
static async all(params: Record<string, unknown> = {}): Promise<unknown> {
const url = 'webhooks';

return this._all(url, params);
Expand All @@ -78,7 +80,7 @@ export default (easypostClient) =>
* @param {string} id - The ID of the webhook to retrieve.
* @returns {Webhook} - The retrieved webhook.
*/
static async retrieve(id) {
static async retrieve(id: string): Promise<unknown> {
const url = `webhooks/${id}`;

return this._retrieve(url);
Expand Down