@abacatepay/types 2.0.1 → 2.0.3
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 +27 -25
- package/dist/index.d.ts +12 -0
- package/dist/index.js +21 -0
- package/dist/v1/rest.d.ts +0 -1
- package/dist/v2/entities/coupon.d.ts +1 -1
- package/dist/v2/entities/subscription.d.ts +1 -1
- package/dist/v2/rest.d.ts +24 -0
- package/dist/v2/utils.d.ts +0 -7
- package/dist/v2/utils.js +0 -17
- package/dist/version.d.ts +2 -2
- package/dist/version.js +2 -2
- package/package.json +14 -2
package/README.md
CHANGED
|
@@ -2,41 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
## AbacatePay API Types
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
O [@abacatepay/types](https://www.npmjs.com/package/@abacatepay/types) fornece **tipagens oficiais** e **helpers modernos** para trabalhar com a API da AbacatePay de forma **segura**, **previsível** e **alinhada** à documentação oficial.
|
|
6
|
+
|
|
7
|
+
O pacote é **TypeScript-first** e serve como base para integrações diretas via **fetch**, **SDKs** internos, **CLIs** e validações em **aplicações** backend.
|
|
6
8
|
|
|
7
9
|
<img src="https://res.cloudinary.com/dkok1obj5/image/upload/v1767631413/avo_clhmaf.png" width="100%" alt="AbacatePay Open Source"/>
|
|
8
10
|
|
|
9
11
|
## Instalação
|
|
10
12
|
|
|
11
|
-
Use
|
|
13
|
+
Use o *package manager* da sua preferência:
|
|
12
14
|
|
|
13
15
|
</div>
|
|
14
16
|
|
|
15
17
|
```bash
|
|
16
18
|
bun add @abacatepay/types
|
|
19
|
+
# ou
|
|
17
20
|
pnpm add @abacatepay/types
|
|
21
|
+
# ou
|
|
18
22
|
npm install @abacatepay/types
|
|
19
23
|
```
|
|
20
24
|
|
|
21
25
|
<div align="center">
|
|
22
26
|
|
|
23
|
-
##
|
|
27
|
+
## Versionamento dos Tipos
|
|
24
28
|
|
|
25
|
-
Antes de tudo, você deve
|
|
29
|
+
Antes de tudo, você deve especificar a versão da API que deseja usar, adicionando **/v*** na importação:
|
|
26
30
|
|
|
27
31
|
</div>
|
|
28
32
|
|
|
29
33
|
```ts
|
|
30
|
-
import { APICustomer } from '@abacatepay/types/
|
|
34
|
+
import { APICustomer } from '@abacatepay/types/v2';
|
|
31
35
|
```
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
<p align="center">Para tipos globais como <code>API_BASE_URL</code>, <code>API_VERSION</code>, <code>version</code> e <code>Routes</code>, apenas import normalmente sem a versão.</p>
|
|
37
|
+
<p align="center">Tipos e constantes globais não são versionados e devem ser importados diretamente sem a versão:</p>
|
|
35
38
|
|
|
36
39
|
```ts
|
|
37
|
-
import { version } from '@abacatepay/types'
|
|
40
|
+
import { version, API_BASE_URL, API_VERSION } from '@abacatepay/types';
|
|
38
41
|
```
|
|
39
42
|
|
|
43
|
+
## Como a AbacatePay API Types documenta
|
|
44
|
+
|
|
40
45
|
- Prefixo `API*`
|
|
41
46
|
Representa estruturas gerais da API (Objetos retornados, modelos internos etc.).
|
|
42
47
|
|
|
@@ -69,36 +74,33 @@ São campos que não têm definição formal na documentação, mas cujo tipo fo
|
|
|
69
74
|
|
|
70
75
|
```ts
|
|
71
76
|
import {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
} from '@abacatepay/types/v1';
|
|
78
|
-
|
|
79
|
-
async function createCoupon(body: RESTPostCreateCouponBody) {
|
|
80
|
-
const path = `${API_BASE_URL}/${API_VERSION}/${Routes.coupon.create}`;
|
|
77
|
+
Routes,
|
|
78
|
+
type APICoupon,
|
|
79
|
+
type RESTPostCreateCouponBody,
|
|
80
|
+
} from '@abacatepay/types/v2';
|
|
81
|
+
import { REST } from '@abacatepay/rest';
|
|
81
82
|
|
|
82
|
-
|
|
83
|
-
method: 'POST',
|
|
84
|
-
body: JSON.stringify(body),
|
|
85
|
-
});
|
|
83
|
+
const client = new REST({ secret });
|
|
86
84
|
|
|
87
|
-
|
|
85
|
+
async function createCoupon(body: RESTPostCreateCouponBody) {
|
|
86
|
+
const data = await client.post<APICoupon>(Routes.coupons.create, { body });
|
|
88
87
|
|
|
89
|
-
|
|
88
|
+
return data;
|
|
90
89
|
}
|
|
91
90
|
```
|
|
92
91
|
|
|
93
92
|
<p align="center"><strong>Crie um servidor e escute eventos de Webhooks do Aabacate</strong></p>
|
|
94
93
|
|
|
95
94
|
```ts
|
|
96
|
-
import {
|
|
95
|
+
import { WebhookEvent } from '@abacatepay/zod/v2';
|
|
96
|
+
import { WebhookEventType } from '@abacatepay/types/v2';
|
|
97
97
|
|
|
98
98
|
Bun.serve({
|
|
99
99
|
routes: {
|
|
100
100
|
async '/webhooks/abacate'(request) {
|
|
101
|
-
const
|
|
101
|
+
const raw = await request.json();
|
|
102
|
+
|
|
103
|
+
const { data, event } = WebhookEvent.parse(raw);
|
|
102
104
|
|
|
103
105
|
switch (event) {
|
|
104
106
|
case WebhookEventType.BillingPaid:
|
package/dist/index.d.ts
CHANGED
|
@@ -5,3 +5,15 @@ export { API_VERSION, version } from './version';
|
|
|
5
5
|
* @see {@link https://docs.abacatepay.com/}
|
|
6
6
|
*/
|
|
7
7
|
export declare const API_BASE_URL = "https://api.abacatepay.com/";
|
|
8
|
+
/**
|
|
9
|
+
* Official URL for the AbacatePay API Documentation
|
|
10
|
+
*/
|
|
11
|
+
export declare const ABACATEPAY_DOCS_URL = "https://docs.abacatepay.com/";
|
|
12
|
+
export declare const ABACATEPAY_SHARED_KEY = "t9dXRhHHo3yDEj5pVDYz0frf7q6bMKyMRmxxCPIPp3RCplBfXRxqlC6ZpiWmOqj4L63qEaeUOtrCI8P0VMUgo6iIga2ri9ogaHFs0WIIywSMg0q7RmBfybe1E5XJcfC4IW3alNqym0tXoAKkzvfEjZxV6bE0oG2zJrNNYmUCKZyV0KZ3JS8Votf9EAWWYdiDkMkpbMdPggfh1EqHlVkMiTady6jOR3hyzGEHrIz2Ret0xHKMbiqkr9HS1JhNHDX9";
|
|
13
|
+
/**
|
|
14
|
+
* Verify whether the signature is valid or not.
|
|
15
|
+
* @param raw Raw body response (string).
|
|
16
|
+
* @param signature The content of the`X-Webhook-Signature` header.
|
|
17
|
+
* @returns A boolean that indicates if the signature is valid.
|
|
18
|
+
*/
|
|
19
|
+
export declare const verifyWebhookSignature: (raw: string, signature: string) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
export { API_VERSION, version } from './version';
|
|
2
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
2
3
|
/**
|
|
3
4
|
* Base URL for the AbacatePay API (Version not included).
|
|
4
5
|
*
|
|
5
6
|
* @see {@link https://docs.abacatepay.com/}
|
|
6
7
|
*/
|
|
7
8
|
export const API_BASE_URL = 'https://api.abacatepay.com/';
|
|
9
|
+
/**
|
|
10
|
+
* Official URL for the AbacatePay API Documentation
|
|
11
|
+
*/
|
|
12
|
+
export const ABACATEPAY_DOCS_URL = 'https://docs.abacatepay.com/';
|
|
13
|
+
export const ABACATEPAY_SHARED_KEY = 't9dXRhHHo3yDEj5pVDYz0frf7q6bMKyMRmxxCPIPp3RCplBfXRxqlC6ZpiWmOqj4L63qEaeUOtrCI8P0VMUgo6iIga2ri9ogaHFs0WIIywSMg0q7RmBfybe1E5XJcfC4IW3alNqym0tXoAKkzvfEjZxV6bE0oG2zJrNNYmUCKZyV0KZ3JS8Votf9EAWWYdiDkMkpbMdPggfh1EqHlVkMiTady6jOR3hyzGEHrIz2Ret0xHKMbiqkr9HS1JhNHDX9';
|
|
14
|
+
/**
|
|
15
|
+
* Verify whether the signature is valid or not.
|
|
16
|
+
* @param raw Raw body response (string).
|
|
17
|
+
* @param signature The content of the`X-Webhook-Signature` header.
|
|
18
|
+
* @returns A boolean that indicates if the signature is valid.
|
|
19
|
+
*/
|
|
20
|
+
export const verifyWebhookSignature = (raw, signature) => {
|
|
21
|
+
const bodyBuffer = Buffer.from(raw, 'utf8');
|
|
22
|
+
const expectedSig = createHmac('sha256', ABACATEPAY_SHARED_KEY)
|
|
23
|
+
.update(bodyBuffer)
|
|
24
|
+
.digest('base64');
|
|
25
|
+
const A = Buffer.from(expectedSig);
|
|
26
|
+
const B = Buffer.from(signature);
|
|
27
|
+
return A.length === B.length && timingSafeEqual(A, B);
|
|
28
|
+
};
|
package/dist/v1/rest.d.ts
CHANGED
|
@@ -86,7 +86,6 @@ export interface RESTPostCreateNewChargeBody {
|
|
|
86
86
|
*/
|
|
87
87
|
customerId?: string;
|
|
88
88
|
/**
|
|
89
|
-
* /**
|
|
90
89
|
* Your customer's data to create it.
|
|
91
90
|
* The customer object is not mandatory, but when entering any `customer` information, all `name`, `cellphone`, `email` and `taxId` fields are mandatory.
|
|
92
91
|
*/
|
|
@@ -27,7 +27,7 @@ export interface APICoupon {
|
|
|
27
27
|
/**
|
|
28
28
|
* Counter of how many times the coupon has been used by customers.
|
|
29
29
|
*/
|
|
30
|
-
redeemsCount:
|
|
30
|
+
redeemsCount: number;
|
|
31
31
|
/**
|
|
32
32
|
* Indicates whether the coupon was created in a development (true) or production (false) environment.
|
|
33
33
|
*/
|
package/dist/v2/rest.d.ts
CHANGED
|
@@ -10,12 +10,20 @@ export type APIResponse<Data> = {
|
|
|
10
10
|
*/
|
|
11
11
|
data: Data;
|
|
12
12
|
error: null;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the request was successful or not.
|
|
15
|
+
*/
|
|
16
|
+
success: true;
|
|
13
17
|
} | {
|
|
14
18
|
data: null;
|
|
15
19
|
/**
|
|
16
20
|
* Error message returned from the API.
|
|
17
21
|
*/
|
|
18
22
|
error: string;
|
|
23
|
+
/**
|
|
24
|
+
* Whether the request was successful or not.
|
|
25
|
+
*/
|
|
26
|
+
success: false;
|
|
19
27
|
};
|
|
20
28
|
/**
|
|
21
29
|
* Any response returned by the AbacatePay API that has a `pagination` field (Not cursor based).
|
|
@@ -26,6 +34,10 @@ export type APIResponseWithPagination<Data> = {
|
|
|
26
34
|
*/
|
|
27
35
|
data: Data;
|
|
28
36
|
error: null;
|
|
37
|
+
/**
|
|
38
|
+
* Whether the request was successful or not.
|
|
39
|
+
*/
|
|
40
|
+
success: true;
|
|
29
41
|
/**
|
|
30
42
|
* Pagination info.
|
|
31
43
|
*/
|
|
@@ -53,6 +65,10 @@ export type APIResponseWithPagination<Data> = {
|
|
|
53
65
|
* Error message returned from the API.
|
|
54
66
|
*/
|
|
55
67
|
error: string;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the request was successful or not.
|
|
70
|
+
*/
|
|
71
|
+
success: false;
|
|
56
72
|
};
|
|
57
73
|
/**
|
|
58
74
|
* Any response returned by the AbacatePay API that has a `pagination` field and is cursor-based.
|
|
@@ -63,6 +79,10 @@ export type APIResponseWithCursorBasedPagination<Data> = {
|
|
|
63
79
|
*/
|
|
64
80
|
data: Data;
|
|
65
81
|
error: null;
|
|
82
|
+
/**
|
|
83
|
+
* Whether the request was successful or not.
|
|
84
|
+
*/
|
|
85
|
+
success: true;
|
|
66
86
|
/**
|
|
67
87
|
* Pagination info.
|
|
68
88
|
*/
|
|
@@ -90,6 +110,10 @@ export type APIResponseWithCursorBasedPagination<Data> = {
|
|
|
90
110
|
* Error message returned from the API.
|
|
91
111
|
*/
|
|
92
112
|
error: string;
|
|
113
|
+
/**
|
|
114
|
+
* Whether the request was successful or not.
|
|
115
|
+
*/
|
|
116
|
+
success: false;
|
|
93
117
|
};
|
|
94
118
|
/**
|
|
95
119
|
* https://api.abacatepay.com/v2/customers/create
|
package/dist/v2/utils.d.ts
CHANGED
|
@@ -17,10 +17,3 @@ export declare function isPayoutFailedWebhookEvent(event: WebhookEvent): event i
|
|
|
17
17
|
* @returns A boolean that indicates if the webhook is a billing paid webhook.
|
|
18
18
|
*/
|
|
19
19
|
export declare function isBillingPaidWebhookEvent(event: WebhookEvent): event is import("./webhook").WebhookBillingPaidEvent;
|
|
20
|
-
/**
|
|
21
|
-
* Verify whether the signature is valid or not.
|
|
22
|
-
* @param raw Raw body response (string).
|
|
23
|
-
* @param signature The content of the`X-Webhook-Signature` header.
|
|
24
|
-
* @returns A boolean that indicates if the signature is valid.
|
|
25
|
-
*/
|
|
26
|
-
export declare const verifyWebhookSignature: (raw: string, signature: string) => boolean;
|
package/dist/v2/utils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
2
1
|
import { WebhookEventType } from './webhook';
|
|
3
2
|
/**
|
|
4
3
|
* A type guard check for `payout.done` webhook events.
|
|
@@ -24,19 +23,3 @@ export function isPayoutFailedWebhookEvent(event) {
|
|
|
24
23
|
export function isBillingPaidWebhookEvent(event) {
|
|
25
24
|
return event.event === WebhookEventType.BillingPaid;
|
|
26
25
|
}
|
|
27
|
-
const ABACATEPAY_PUBLIC_KEY = 't9dXRhHHo3yDEj5pVDYz0frf7q6bMKyMRmxxCPIPp3RCplBfXRxqlC6ZpiWmOqj4L63qEaeUOtrCI8P0VMUgo6iIga2ri9ogaHFs0WIIywSMg0q7RmBfybe1E5XJcfC4IW3alNqym0tXoAKkzvfEjZxV6bE0oG2zJrNNYmUCKZyV0KZ3JS8Votf9EAWWYdiDkMkpbMdPggfh1EqHlVkMiTady6jOR3hyzGEHrIz2Ret0xHKMbiqkr9HS1JhNHDX9';
|
|
28
|
-
/**
|
|
29
|
-
* Verify whether the signature is valid or not.
|
|
30
|
-
* @param raw Raw body response (string).
|
|
31
|
-
* @param signature The content of the`X-Webhook-Signature` header.
|
|
32
|
-
* @returns A boolean that indicates if the signature is valid.
|
|
33
|
-
*/
|
|
34
|
-
export const verifyWebhookSignature = (raw, signature) => {
|
|
35
|
-
const bodyBuffer = Buffer.from(raw, 'utf8');
|
|
36
|
-
const expectedSig = createHmac('sha256', ABACATEPAY_PUBLIC_KEY)
|
|
37
|
-
.update(bodyBuffer)
|
|
38
|
-
.digest('base64');
|
|
39
|
-
const A = Buffer.from(expectedSig);
|
|
40
|
-
const B = Buffer.from(signature);
|
|
41
|
-
return A.length === B.length && timingSafeEqual(A, B);
|
|
42
|
-
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Current version of [@abacatepay/types](https://www.npmjs.com/package/@abacatepay/types).
|
|
3
3
|
*/
|
|
4
|
-
export declare const version: "2.0.
|
|
4
|
+
export declare const version: "2.0.3";
|
|
5
5
|
/**
|
|
6
|
-
* Current version of the AbacatePay API
|
|
6
|
+
* Current version of the AbacatePay API.
|
|
7
7
|
*/
|
|
8
8
|
export declare const API_VERSION: "2";
|
package/dist/version.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Current version of [@abacatepay/types](https://www.npmjs.com/package/@abacatepay/types).
|
|
4
4
|
*/
|
|
5
|
-
export const version = '2.0.
|
|
5
|
+
export const version = '2.0.3';
|
|
6
6
|
/**
|
|
7
|
-
* Current version of the AbacatePay API
|
|
7
|
+
* Current version of the AbacatePay API.
|
|
8
8
|
*/
|
|
9
9
|
export const API_VERSION = '2';
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.0.
|
|
2
|
+
"version": "2.0.3",
|
|
3
3
|
"name": "@abacatepay/types",
|
|
4
4
|
"description": "Abacate Pay API typings that are always up to date.",
|
|
5
5
|
"type": "module",
|
|
@@ -46,12 +46,24 @@
|
|
|
46
46
|
"build": "bun run gen:version && tsc",
|
|
47
47
|
"prepublishOnly": "bun run build",
|
|
48
48
|
"gen:version": "bun run scripts/version.ts",
|
|
49
|
+
"test": "bun test",
|
|
49
50
|
"fmt": "bunx biome check --write package.json types && clear"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@biomejs/biome": "^2.3.8",
|
|
53
54
|
"typescript": "^5.9.3"
|
|
54
55
|
},
|
|
56
|
+
"author": {
|
|
57
|
+
"name": "AbacatePay",
|
|
58
|
+
"email": "opensource@abacatepay.com",
|
|
59
|
+
"url": "https://abacatepay.com"
|
|
60
|
+
},
|
|
61
|
+
"maintainers": [
|
|
62
|
+
{
|
|
63
|
+
"name": "Almeida",
|
|
64
|
+
"url": "https://github.com/almeidazs"
|
|
65
|
+
}
|
|
66
|
+
],
|
|
55
67
|
"keywords": [
|
|
56
68
|
"api",
|
|
57
69
|
"abacatepay",
|
|
@@ -63,6 +75,6 @@
|
|
|
63
75
|
},
|
|
64
76
|
"repository": {
|
|
65
77
|
"type": "git",
|
|
66
|
-
"url": "https://github.com/
|
|
78
|
+
"url": "git+https://github.com/AbacatePay/ecosystem.git"
|
|
67
79
|
}
|
|
68
80
|
}
|