Skip to content
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

docs(numbers): adding doc blocks #884

Merged
merged 1 commit into from
Dec 6, 2023
Merged

docs(numbers): adding doc blocks #884

merged 1 commit into from
Dec 6, 2023

Conversation

manchuck
Copy link
Contributor

@manchuck manchuck commented Nov 1, 2023

Description

Motivation and Context

Testing Details

Example Output or Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

packages/numbers/package.json Show resolved Hide resolved
const resp = await this.sendFormSubmitRequest<NumbersEmptyResponse>(
`${this.config.restHost}/number/buy`,
data,
Client.transformers.snakeCaseObjectKeys(params) as Record<string, string>,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not complicate things like this? Code should be written to be easily readable rather than look smart. What is the benefit of adding transformers here? Why not just a simple inline mapping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done to normalize out responses and requests. Since our API's do not follow a consistent casing scheme (most use snake_case, some have kebab-case), we convert all responses to be camelCase for ease of use.

In the cases where kebab-case is used, a developer would have to access the object like resp.data['content-type] rather than resp.data.contentType.

Camel Case was chosen since the popular linter rules require camelCasing for variable names (Google, React, Airbnb)

Using the transformer instead of defining the mapping, alleviates the need to push updates when new variables are introduced and prevent keys from being improperly mapped through fat fingering. If the API gets an update, the user will be able to access the new data without waiting for a new release of the SDK. We do map the response in verifyv2 which is why there has to be work done to enable silent auth.

PS for users of Typescript, we export all the types in our packages to allow for this use case. If there is an update to the API they can simple merge of the types with the new propert(ies) added.

@manchuck manchuck requested a review from pardel December 5, 2023 21:07
@manchuck manchuck merged commit 2e18e79 into docblocks Dec 6, 2023
2 of 11 checks passed
@manchuck manchuck deleted the doc-numbers branch December 6, 2023 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants