@veroao/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -0
- package/dist/client.d.ts +11 -0
- package/dist/client.js +36 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/types.d.ts +93 -0
- package/dist/types.js +1 -0
- package/package.json +24 -0
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @veroao/core
|
|
2
|
+
|
|
3
|
+
Cliente partilhado, mínimo, para os endpoints de **widget** do Vero - a base usada internamente
|
|
4
|
+
pelos pacotes [`@veroao/react`](https://www.npmjs.com/package/@veroao/react) e
|
|
5
|
+
[`@veroao/widget`](https://www.npmjs.com/package/@veroao/widget).
|
|
6
|
+
|
|
7
|
+
> **A maioria dos integradores não precisa deste pacote directamente.** Se estás a construir no
|
|
8
|
+
> browser (checkout, formulário de factura embutido), usa `@veroao/react` ou `@veroao/widget`. Se
|
|
9
|
+
> estás no servidor com acesso à API completa, usa [`@veroao/node`](https://www.npmjs.com/package/@veroao/node).
|
|
10
|
+
|
|
11
|
+
## Porque é que isto existe
|
|
12
|
+
|
|
13
|
+
Os endpoints `/v1/widget/...` são uma superfície deliberadamente pequena e segura para expor no
|
|
14
|
+
browser: só pesquisa de clientes e criação de factura, pensados para serem usados com uma
|
|
15
|
+
**chave publicável** (`vero_live_pk_...`), que o servidor recusa em qualquer outra rota. Este
|
|
16
|
+
pacote só fala com essas duas rotas.
|
|
17
|
+
|
|
18
|
+
## Instalação
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @veroao/core
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Uso
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { VeroAOClient } from '@veroao/core'
|
|
28
|
+
|
|
29
|
+
const client = new VeroAOClient({
|
|
30
|
+
apiKey: 'vero_live_pk_...', // chave publicável - segura para o browser
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const { data: customers } = await client.listCustomers(orgId, { search: 'Maria', limit: 8 })
|
|
34
|
+
|
|
35
|
+
const invoice = await client.createInvoice(orgId, {
|
|
36
|
+
customerId: customers[0].id,
|
|
37
|
+
documentType: 'FR',
|
|
38
|
+
items: [{ description: 'Plano Pro', quantity: 1, unitPrice: 500000, taxRate: 14 }],
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
console.log(invoice.pdfUrl) // link público de download, sem autenticação
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Tratamento de erros
|
|
45
|
+
|
|
46
|
+
Um pedido falhado lança o corpo de erro da API directamente:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
try {
|
|
50
|
+
await client.createInvoice(orgId, input)
|
|
51
|
+
} catch (err) {
|
|
52
|
+
const apiErr = err as { error: string; message?: string }
|
|
53
|
+
if (apiErr.error === 'customer_not_found') {
|
|
54
|
+
// ...
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Referência
|
|
60
|
+
|
|
61
|
+
### `new VeroAOClient(config)`
|
|
62
|
+
|
|
63
|
+
| Campo | Obrigatório | Descrição |
|
|
64
|
+
|---------------|:-----------:|----------------------------------------------|
|
|
65
|
+
| `apiKey` | sim | Chave publicável (`vero_live_pk_...` / `vero_test_pk_...`) |
|
|
66
|
+
| `baseUrl` | não | Default `https://api.vero.ao/v1` |
|
|
67
|
+
|
|
68
|
+
### `client.listCustomers(orgId, params?)`
|
|
69
|
+
|
|
70
|
+
`params`: `{ search?: string; limit?: number }` - devolve `{ data: Customer[] }`.
|
|
71
|
+
|
|
72
|
+
### `client.createInvoice(orgId, input)`
|
|
73
|
+
|
|
74
|
+
`input`: `{ customerId, items, documentType?, notes?, idempotencyKey? }` - devolve a factura criada.
|
|
75
|
+
|
|
76
|
+
## Preciso de mais do que isto
|
|
77
|
+
|
|
78
|
+
Não é possível com uma chave publicável - o servidor só a aceita nestas duas rotas. Para gerir
|
|
79
|
+
produtos, listar facturas existentes, emitir notas de crédito/débito, etc., usa um backend teu com
|
|
80
|
+
`@veroao/node` e a chave secreta; este pacote (e o browser em geral) fala com esse backend, nunca
|
|
81
|
+
directamente com o Vero para essas operações.
|
|
82
|
+
|
|
83
|
+
Esse backend não precisa de ser Node - é só a opção mais directa. Qualquer linguagem (PHP,
|
|
84
|
+
Python, Ruby, etc.) consegue chamar a API REST directamente com o seu próprio cliente HTTP, com
|
|
85
|
+
as mesmas operações disponíveis. Exemplos em cURL, Python e PHP em [vero.ao/docs](https://vero.ao/docs).
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { VeroAOConfig, Customer, Invoice, CreateInvoiceInput, SearchCustomersParams } from "./types.js";
|
|
2
|
+
export declare class VeroAOClient {
|
|
3
|
+
private apiKey;
|
|
4
|
+
private baseUrl;
|
|
5
|
+
constructor(config: VeroAOConfig);
|
|
6
|
+
private request;
|
|
7
|
+
listCustomers(orgId: string, params?: SearchCustomersParams): Promise<{
|
|
8
|
+
data: Customer[];
|
|
9
|
+
}>;
|
|
10
|
+
createInvoice(orgId: string, input: CreateInvoiceInput): Promise<Invoice>;
|
|
11
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export class VeroAOClient {
|
|
2
|
+
apiKey;
|
|
3
|
+
baseUrl;
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.apiKey = config.apiKey;
|
|
6
|
+
this.baseUrl = config.baseUrl || "https://api.vero.ao/v1";
|
|
7
|
+
}
|
|
8
|
+
async request(method, path, body, params) {
|
|
9
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
10
|
+
if (params) {
|
|
11
|
+
Object.entries(params).forEach(([k, v]) => {
|
|
12
|
+
if (v !== undefined)
|
|
13
|
+
url.searchParams.append(k, String(v));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
const response = await fetch(url.toString(), {
|
|
17
|
+
method,
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
20
|
+
"Content-Type": "application/json",
|
|
21
|
+
},
|
|
22
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
23
|
+
});
|
|
24
|
+
const data = await response.json();
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
throw data;
|
|
27
|
+
}
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
async listCustomers(orgId, params = {}) {
|
|
31
|
+
return this.request("GET", `/widget/organisations/${orgId}/customers`, undefined, params);
|
|
32
|
+
}
|
|
33
|
+
async createInvoice(orgId, input) {
|
|
34
|
+
return this.request("POST", `/widget/organisations/${orgId}/invoices`, input);
|
|
35
|
+
}
|
|
36
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export interface VeroAOConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
environment?: "live" | "test";
|
|
5
|
+
}
|
|
6
|
+
export interface VeroAOError {
|
|
7
|
+
error: string;
|
|
8
|
+
message?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ListMeta {
|
|
11
|
+
total: number;
|
|
12
|
+
page: number;
|
|
13
|
+
limit: number;
|
|
14
|
+
pages: number;
|
|
15
|
+
}
|
|
16
|
+
export interface Customer {
|
|
17
|
+
id: string;
|
|
18
|
+
orgId: string;
|
|
19
|
+
name: string;
|
|
20
|
+
email?: string | null;
|
|
21
|
+
taxId?: string | null;
|
|
22
|
+
phone?: string | null;
|
|
23
|
+
addressLine1?: string | null;
|
|
24
|
+
addressLine2?: string | null;
|
|
25
|
+
city?: string | null;
|
|
26
|
+
province?: string | null;
|
|
27
|
+
country?: string | null;
|
|
28
|
+
externalId?: string | null;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
updatedAt: string;
|
|
31
|
+
}
|
|
32
|
+
export interface Organisation {
|
|
33
|
+
id: string;
|
|
34
|
+
userId: string;
|
|
35
|
+
name: string;
|
|
36
|
+
legalName?: string;
|
|
37
|
+
taxId?: string;
|
|
38
|
+
email?: string;
|
|
39
|
+
phone?: string;
|
|
40
|
+
addressLine1?: string;
|
|
41
|
+
city?: string;
|
|
42
|
+
country?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface InvoiceItem {
|
|
45
|
+
description: string;
|
|
46
|
+
quantity: number;
|
|
47
|
+
unitPrice: number;
|
|
48
|
+
taxRate?: number;
|
|
49
|
+
}
|
|
50
|
+
export interface Invoice {
|
|
51
|
+
id: string;
|
|
52
|
+
orgId: string;
|
|
53
|
+
customerId: string;
|
|
54
|
+
number?: string | null;
|
|
55
|
+
displayCode?: string | null;
|
|
56
|
+
status: "pending" | "issued" | "paid" | "failed" | "cancelled";
|
|
57
|
+
total: number;
|
|
58
|
+
subtotal: number;
|
|
59
|
+
taxAmount: number;
|
|
60
|
+
currency: string;
|
|
61
|
+
items?: InvoiceItem[];
|
|
62
|
+
pdfUrl?: string | null;
|
|
63
|
+
atcud?: string | null;
|
|
64
|
+
hash?: string | null;
|
|
65
|
+
issuedAt?: string | null;
|
|
66
|
+
createdAt: string;
|
|
67
|
+
customerSnapshot?: Record<string, unknown>;
|
|
68
|
+
orgSnapshot?: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
export interface CreateInvoiceInput {
|
|
71
|
+
customerId: string;
|
|
72
|
+
items: InvoiceItem[];
|
|
73
|
+
notes?: string;
|
|
74
|
+
idempotencyKey?: string;
|
|
75
|
+
documentType?: "FT" | "FR";
|
|
76
|
+
}
|
|
77
|
+
export interface CreateCustomerDTO {
|
|
78
|
+
name: string;
|
|
79
|
+
taxId?: string;
|
|
80
|
+
email?: string;
|
|
81
|
+
phone?: string;
|
|
82
|
+
addressLine1?: string;
|
|
83
|
+
addressLine2?: string;
|
|
84
|
+
city?: string;
|
|
85
|
+
province?: string;
|
|
86
|
+
country?: string;
|
|
87
|
+
externalId?: string;
|
|
88
|
+
}
|
|
89
|
+
export interface SearchCustomersParams {
|
|
90
|
+
search?: string;
|
|
91
|
+
page?: number;
|
|
92
|
+
limit?: number;
|
|
93
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@veroao/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Cliente partilhado e mínimo para os endpoints de widget do Vero — base do @veroao/react e @veroao/widget",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": ["dist"],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"dev": "tsc --watch",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"keywords": ["vero-ao", "faturacao", "agt", "angola", "invoicing"],
|
|
15
|
+
"author": "Eterim Prestação de Serviços",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/eadafonso/vero-sdk-core.git"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"typescript": "^5.3.3"
|
|
23
|
+
}
|
|
24
|
+
}
|