Skip to content

Commit

Permalink
Merge pull request #4 from AlexandreBellas/develop
Browse files Browse the repository at this point in the history
Crazily enhance bling entity logic, extend available entities and start testing the created code
  • Loading branch information
vitor-sanc authored Nov 2, 2021
2 parents e1e8e8f + 671e717 commit e31673b
Show file tree
Hide file tree
Showing 27 changed files with 1,523 additions and 258 deletions.
43 changes: 28 additions & 15 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
{
"env": {
"es2021": true,
"node": true
"env": {
"es2021": true,
"node": true
},
"extends": [
"standard",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {},
"overrides": [
{
"files": ["*.spec.js", "*.test.ts", "*.test.js"],
"rules": {
"no-undef": "off"
}
},
"extends": [
"standard"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
{
"files": ["src/entities/*"],
"rules": {
"camelcase": "off"
}
}
]
}
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ npm i bling-erp-api
### Javascript

```js
const Bling = require('bling-erp-api')
const { Bling } = require('bling-erp-api')
```

### Typescript

```ts
import Bling from 'bling-erp-api'
import { Bling } from 'bling-erp-api'
```

## Criação de uma nova conexão

Para criar uma conexão ao serviço do Bling, basta instanciar o objeto com a [API
key](https://ajuda.bling.com.br/hc/pt-br/articles/360046937853-Introdu%C3%A7%C3%A3o-para-a-API-do-Bling-para-desenvolvedores-) em seu construtor.
key](https://ajuda.bling.com.br/hc/pt-br/articles/360046937853-Introdu%C3%A7%C3%A3o-para-a-API-do-Bling-para-desenvolvedores-) em seu construtor. Lembre-se de sempre guardar a sua API key em seu arquivo `.env`.

```js
const apiKey = 'sua_api_key'
Expand All @@ -43,12 +43,19 @@ const blingConnection = new Bling(apiKey)

## Entidades disponíveis

As entidades atualmente permitidas para interação são somente:
As entidades atualmente permitidas para interação são:

- Produtos
- Pedidos
- Contatos (`.contacts()`)
- Depósitos (`.deposits()`)
- Pedidos (`.orders()`)
- Pedidos de compra (`.purchaseOrders()`)
- Produtos (`.products()`)
- Propostas comerciais (`.commercialProposals()`)

Em breve serão adicionadas mais.
Adicionaremos as restantes de acordo com as _releases_. Por ora, estamos focando
no funcionamento do pacote e no teste correto das entidades.
Além disso, as entidades no código estão em inglês. Em breve também deixaremos
disponíveis os métodos em português.

## Métodos permitidos

Expand Down Expand Up @@ -85,4 +92,4 @@ tecnologias e estrutura do projeto são:
- Alexandre Batistella Bellas; [LinkedIn](https://linkedin.com/in/alebatistella/)
- Vitor Santana Cordeiro; [LinkedIn](https://linkedin.com/in/vitorsanc)

No futuro, contribuições da comunidade serão extremamente apreciadas! Ainda não possuímos as *guidelines de contribuição* definidas (`CONTRIBUTING.md`), mas assim que as tivermos nós iremos apreciar fortemente a contribuição da comunidade, inclusive por meio da abertura de *issues* 😊
No futuro, contribuições da comunidade serão extremamente apreciadas! Ainda não possuímos as _guidelines de contribuição_ definidas (`CONTRIBUTING.md`), mas assim que as tivermos nós iremos apreciar fortemente a contribuição da comunidade, inclusive por meio da abertura de _issues_ 😊
19 changes: 17 additions & 2 deletions jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
"^.+\\.(t|j)sx?$": "ts-jest"
},
"testRegex": "(/test/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"transformIgnorePatterns": ["/node_modules/", "\\.pnp\\.[^\\\/]+$"]
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"transformIgnorePatterns": [
"/node_modules/",
"\\.pnp\\.[^\\\/]+$"
],
"testPathIgnorePatterns": [
"<rootDir>/test/config/"
],
"maxWorkers": 1,
"maxConcurrency": 2
}
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bling-erp-api",
"version": "1.0.2",
"description": "Pacote de interação com a REST API do serviço Bling ERP",
"main": "src/bling.ts",
"main": "lib/bling.js",
"directories": {
"test": "test"
},
Expand Down Expand Up @@ -48,6 +48,11 @@
"prettier --write",
"eslint --fix",
"git add"
],
"*.ts": [
"prettier --write",
"eslint --fix",
"git add"
]
},
"dependencies": {
Expand All @@ -64,11 +69,13 @@
"commitizen": "^4.2.4",
"coveralls": "^3.1.1",
"cross-env": "^7.0.3",
"dotenv": "^10.0.0",
"eslint": "^7.32.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"gerar-cpf": "^2.0.3",
"husky": "^4.3.6",
"jest": "^27.3.0",
"lint-staged": "^10.5.3",
Expand Down
64 changes: 55 additions & 9 deletions src/bling.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
'use strict'

import CommercialProposals from './entities/commercialProposals'
import Contacts from './entities/contacts'
import Deposits from './entities/deposits'
import Products from './entities/products'
import Orders from './entities/orders'
import PurchaseOrders from './entities/purchaseOrders'

import createError, {
IBlingError as IStandardBlingError
} from './core/createError'

import axios, { AxiosInstance } from 'axios'

import createError from './core/createError'
export type IBlingError = IStandardBlingError

export default class Bling {
export class Bling {
#api: AxiosInstance
#products: Products | undefined
#apiKey: string
#commercialProposals: CommercialProposals | undefined
#contacts: Contacts | undefined
#deposits: Deposits | undefined
#orders: Orders | undefined
#products: Products | undefined
#purchaseOrders: PurchaseOrders | undefined

constructor (apiKey: string) {
if (!apiKey || typeof apiKey !== 'string') {
throw createError(
"The API key wasn't correctly provided for Bling connection.",
500,
this,
apiKey,
'ERR_NO_API_KEY'
)
}
Expand All @@ -33,20 +47,52 @@ export default class Bling {
return config
})

this.#apiKey = apiKey
this.#api = api
}

public products () {
if (!this.#products) {
this.#products = new Products(this.#api)
public commercialProposals () {
if (!this.#commercialProposals) {
this.#commercialProposals = new CommercialProposals(
this.#api,
this.#apiKey
)
}
return this.#products
return this.#commercialProposals
}

public contacts () {
if (!this.#contacts) {
this.#contacts = new Contacts(this.#api, this.#apiKey)
}
return this.#contacts
}

public deposits () {
if (!this.#deposits) {
this.#deposits = new Deposits(this.#api, this.#apiKey)
}
return this.#deposits
}

public orders () {
if (!this.#orders) {
this.#orders = new Orders(this.#api)
this.#orders = new Orders(this.#api, this.#apiKey)
}
return this.#orders
}

public products () {
if (!this.#products) {
this.#products = new Products(this.#api, this.#apiKey)
}
return this.#products
}

public purchaseOrders () {
if (!this.#purchaseOrders) {
this.#purchaseOrders = new PurchaseOrders(this.#api, this.#apiKey)
}
return this.#purchaseOrders
}
}
20 changes: 10 additions & 10 deletions src/core/createError.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
export interface IBlingError extends Error {
status: number
config: any
data: any
code: string
toJSON: () => {
message: string
name: string
stack?: string
config: any
data: any
code: string
}
}

/**
* Create an Error with the specified message, config, error code and status.
*
* @param {string} message The error message.
* @param {number} status The error status.
* @param {Bling} config The config.
* @param {string} [code] The error code (for example, 'ECONNABORTED').
* @returns {IBlingError} The created error.
* @param message The error message.
* @param status The error status.
* @param data The error data.
* @param [code] The error code (for example, 'E_CONN_ABORTED').
* @returns The created error.
*/
export default function createError (
message: string,
status: number,
config: any,
data: any,
code: string
) {
const rawError = new Error(message)
Expand All @@ -32,14 +32,14 @@ export default function createError (
...rawError,
message,
status,
config,
data,
code,
toJSON: () => {
return {
message,
name: rawError.name,
stack: rawError.stack,
config,
data,
code
}
}
Expand Down
Loading

0 comments on commit e31673b

Please sign in to comment.