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

[6.0.0] feat(Singleton): implement the API wrapper as a singleton #88

Merged
merged 5 commits into from
Sep 23, 2024

Conversation

marcelscr
Copy link
Contributor

Esse PR modifica a classe IncogniaApi para usar um singleton e ter métodos estáticos.

Por limitar o acesso à instância, tive que refatorar a classe para extrair as lógicas de gestão de token e de request para arquivos próprios, permitindo que essa lógica fosse testada direitinho.

O novo uso vai ficar assim:

import { IncogniaApi } from '@incognia/api'

IncogniaApi.init({
  clientId: 'clientId',
  clientSecret: 'clientSecret'
})

const signup = await IncogniaApi.registerSignup({
  installationId: 'installation_id',
  ...
})

Essa mudança é quebrante, e o release deve ser feito em um major release na v6.0.0.

@marcelscr marcelscr self-assigned this Jul 31, 2024
@marcelscr marcelscr changed the base branch from master to feat/add-web-payment July 31, 2024 14:41
@marcelscr marcelscr changed the base branch from feat/add-web-payment to feat/web-payment July 31, 2024 14:42
Copy link
Contributor

@FranciscoGileno FranciscoGileno left a comment

Choose a reason for hiding this comment

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

👏🏽

Copy link
Contributor

@leonardoAnjos16 leonardoAnjos16 left a comment

Choose a reason for hiding this comment

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

Nice 👏🏼

README.md Outdated

Instead of creating an instance of the `IncogniaApi` class using your API credentials, just initialize the `IncogniaApi` with your credentials using the `init()` method. Initializing the `IncogniaApi` is a required step and must be done before calling any of the other `IncogniaApi` methods.

```
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```
```js

if (!installationId) {
throw new IncogniaError('No installationId provided')
}
if (!IncogniaApi.instance) throw new IncogniaError(errorMessages.INIT)
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking: it would be nice to have a decorator function that performs this check. I think we could avoid a lot of repetition. But I realize there are not a lot of functions and the check is simple. Do you think it would be worth it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pensei em não fazer só pelo código de check ser simples mesmo. Acho que seria parecido em termos de complexidade.

@marcelscr marcelscr changed the title feat(Singleton): implement the API wrapper as a singleton [6.0.0] feat(Singleton): implement the API wrapper as a singleton Aug 5, 2024
@marcelscr marcelscr changed the base branch from feat/web-payment to master September 23, 2024 11:09
@marcelscr marcelscr merged commit 9dfcff2 into master Sep 23, 2024
4 checks passed
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