-
Notifications
You must be signed in to change notification settings - Fork 57
TSM-06: convert Group A services to TypeScript #563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Justin Hammond (Justintime50)
wants to merge
10
commits into
ts-migrate/05-base-service-hydration
from
ts-migrate/06-services-group-a
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4d88d78
step6: convert group a services to ts
Justintime50 d915317
step6: add explicit TS signatures for Group A services
Justintime50 f1023c7
tsm-06: finalize typed boundaries after rebasing
Justintime50 111aaa4
chore(tsm-06): format service TS files for lint
Justintime50 8cdd155
TSM-06: add permissive create parameter types for Group A services
Justintime50 a43f6d7
Fix shipment create type ref and audit-ci allowlist
Justintime50 71957ac
TSM-06: convert Group A tests to TS and add suite test typecheck
Justintime50 8a94ade
TSM-06: restore address verify assignments and cassettes
Justintime50 7cf53aa
TSM-06: add source-derived fixture type assertions in tests
Justintime50 779d139
TSM-06: include vitest globals in tsconfig build
Justintime50 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,26 @@ | ||
| import baseService from './base_service'; | ||
|
|
||
| type AddressCreateParameters = 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; | ||
| residential?: boolean | null; | ||
| federal_tax_id?: string | null; | ||
| state_tax_id?: string | null; | ||
| verify?: boolean | string | Array<boolean | string> | null; | ||
| verify_strict?: boolean | string | Array<boolean | string> | null; | ||
| verify_carrier?: string | null; | ||
| }; | ||
|
|
||
| type PaginationCollection = Record<string, unknown>; | ||
|
|
||
| export default (easypostClient) => | ||
| /** | ||
| * The AddressService class provides methods for interacting with EasyPost {@link Address} objects. | ||
|
|
@@ -12,10 +33,10 @@ export default (easypostClient) => | |
| * @param {Object} params - Parameters for the address to be created. | ||
| * @returns {Address} - The created address. | ||
| */ | ||
| static async create(params) { | ||
| static async create(params: AddressCreateParameters): Promise<unknown> { | ||
| const url = 'addresses'; | ||
|
|
||
| const wrappedParams = {}; | ||
| const wrappedParams: Record<string, unknown> = {}; | ||
|
|
||
| if (params.verify) { | ||
| wrappedParams.verify = params.verify; | ||
|
|
@@ -43,10 +64,10 @@ export default (easypostClient) => | |
| * @param {Object} params - Parameters for the address to be created. | ||
| * @returns {Address} - The created and verified address. | ||
| */ | ||
| static async createAndVerify(params) { | ||
| static async createAndVerify(params: AddressCreateParameters): Promise<unknown> { | ||
| const url = `addresses/create_and_verify`; | ||
|
|
||
| const wrappedParams = {}; | ||
| const wrappedParams: Record<string, unknown> = {}; | ||
|
|
||
| if (params.verify_carrier) { | ||
| wrappedParams.verify_carrier = params.verify_carrier; | ||
|
|
@@ -70,7 +91,7 @@ export default (easypostClient) => | |
| * @param {Object} [params] - Parameters to filter the list of addresses. | ||
| * @returns {Object} - An object containing a list of {@link Address addresses} and pagination information. | ||
| */ | ||
| static async all(params = {}) { | ||
| static async all(params: Record<string, unknown> = {}): Promise<unknown> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| const url = 'addresses'; | ||
|
|
||
| return this._all(url, params); | ||
|
|
@@ -82,7 +103,7 @@ 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(addresses, pageSize = null) { | ||
| static async getNextPage(addresses: PaginationCollection, pageSize?: number): Promise<unknown> { | ||
| const url = 'addresses'; | ||
| return this._getNextPage(url, 'addresses', addresses, pageSize); | ||
| } | ||
|
|
@@ -93,7 +114,7 @@ export default (easypostClient) => | |
| * @param {string} id - The ID of the address to retrieve. | ||
| * @returns {Address} - The retrieved address. | ||
| */ | ||
| static async retrieve(id) { | ||
| static async retrieve(id: string): Promise<unknown> { | ||
| const url = `addresses/${id}`; | ||
|
|
||
| return this._retrieve(url); | ||
|
|
@@ -105,12 +126,12 @@ export default (easypostClient) => | |
| * @param {string} id - The ID of the address to verify. | ||
| * @returns {Address} - The verified address. | ||
| */ | ||
| static async verifyAddress(id) { | ||
| static async verifyAddress(id: string): Promise<unknown> { | ||
| try { | ||
| const url = `addresses/${id}/verify`; | ||
| const response = await easypostClient._get(url); | ||
|
|
||
| return this._convertToEasyPostObject(response.body.address); | ||
| return this._convertToEasyPostObject(response.body.address, {}); | ||
| } catch (e) { | ||
| return Promise.reject(e); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
Looks like this is a known type, and could probably strengthen it just a little bit.