@abacatepay/types 0.0.4 → 2.0.1

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.
@@ -0,0 +1,129 @@
1
+ import type { RESTGetListCouponsQueryParams, RESTGetListCustomersQueryParams, RESTGetListPayoutsQueryParams, RESTGetListProductsQueryParams, RESTGetListSubscriptionsQueryParams, RESTGetProductQueryParams } from './rest';
2
+ export declare const Routes: {
3
+ readonly customers: {
4
+ /**
5
+ * POST - https://api.abacatepay.com/v2/customers/create
6
+ */
7
+ readonly create: "/customers/create";
8
+ /**
9
+ * GET - https://api.abacatepay.com/v2/customers/list
10
+ */
11
+ readonly list: ({ page, limit }?: RESTGetListCustomersQueryParams) => `/customers/list?page=${number}&limit=${number}`;
12
+ /**
13
+ * GET - https://api.abacatepay.com/v2/customers/get
14
+ */
15
+ readonly get: (id: string) => `/customers/get?id=${string}`;
16
+ /**
17
+ * DELETE - https://api.abacatepay.com/v2/customers/delete
18
+ */
19
+ readonly delete: "/customers/delete";
20
+ };
21
+ readonly checkouts: {
22
+ /**
23
+ * POST - https://api.abacatepay.com/v2/checkouts/create
24
+ */
25
+ readonly create: "/checkouts/create";
26
+ /**
27
+ * GET - https://api.abacatepay.com/v2/checkouts/list
28
+ */
29
+ readonly list: "/checkouts/list";
30
+ /**
31
+ * GET - https://api.abacatepay.com/v2/checkouts/get
32
+ */
33
+ readonly get: (id: string) => `/checkouts/get?id=${string}`;
34
+ };
35
+ readonly transparents: {
36
+ /**
37
+ * POST - https://api.abacatepay.com/v2/transparents/create
38
+ */
39
+ readonly createQRCode: "/transparents/create";
40
+ /**
41
+ * POST - https://api.abacatepay.com/v2/transparents/simulate-payment
42
+ */
43
+ readonly simulatePayment: (id: string) => `/transparents/simulate-payment?id=${string}`;
44
+ /**
45
+ * GET - https://api.abacatepay.com/v2/transparents/check
46
+ */
47
+ readonly checkStatus: (id: string) => `/transparents/check?id=${string}`;
48
+ };
49
+ readonly coupons: {
50
+ /**
51
+ * POST - https://api.abacatepay.com/v2/coupons/create
52
+ */
53
+ readonly create: "/coupons/create";
54
+ /**
55
+ * GET - https://api.abacatepay.com/v2/coupons/list
56
+ */
57
+ readonly list: ({ page, limit }?: RESTGetListCouponsQueryParams) => `/coupons/list?page=${number}&limit=${number}`;
58
+ /**
59
+ * GET - https://api.abacatepay.com/v2/coupons/get
60
+ */
61
+ readonly get: (id: string) => `/coupons/get?id=${string}`;
62
+ /**
63
+ * DELETE - https://api.abacatepay.com/v2/coupons/delete
64
+ */
65
+ readonly delete: "/coupons/delete";
66
+ /**
67
+ * PATCH - https://api.abacatepay.com/v2/coupons/toggle
68
+ */
69
+ readonly toggleStatus: "/coupons/toggle";
70
+ };
71
+ readonly payouts: {
72
+ /**
73
+ * POST - https://api.abacatepay.com/v2/payouts/create
74
+ */
75
+ readonly create: "/payouts/create";
76
+ /**
77
+ * GET - https://api.abacatepay.com/v2/payouts/get
78
+ */
79
+ readonly get: (externalId: string) => `/payouts/get?externalId=${string}`;
80
+ /**
81
+ * GET - https://api.abacatepay.com/v2/payouts/list
82
+ */
83
+ readonly list: ({ page, limit }?: RESTGetListPayoutsQueryParams) => string;
84
+ };
85
+ readonly store: {
86
+ /**
87
+ * GET - https://api.abacatepay.com/v2/store/get
88
+ */
89
+ readonly get: "/store/get";
90
+ };
91
+ readonly mrr: {
92
+ /**
93
+ * GET - https://api.abacatepay.com/v2/public-mrr/mrr
94
+ */
95
+ readonly get: "/public-mrr/mrr";
96
+ /**
97
+ * GET - https://api.abacatepay.com/v2/public-mrr/merchant-info
98
+ */
99
+ readonly merchant: "/public-mrr/merchant-info";
100
+ /**
101
+ * GET - https://api.abacatepay.com/v2/public-mrr/renevue
102
+ */
103
+ readonly revenue: (start: string, end: string) => `/public-mrr/revenue?startDate=${string}&endDate=${string}`;
104
+ };
105
+ readonly subscriptions: {
106
+ /**
107
+ * POST - https://api.abacatepay.com/v2/subscriptions/create
108
+ */
109
+ readonly create: "/subscriptions/create";
110
+ /**
111
+ * GET - https://api.abacatepay.com/v2/subscriptions/list
112
+ */
113
+ readonly list: ({ cursor, limit }?: RESTGetListSubscriptionsQueryParams) => `/subscriptions/list?${string}`;
114
+ };
115
+ readonly products: {
116
+ /**
117
+ * POST - https://api.abacatepay.com/v2/products/create
118
+ */
119
+ readonly create: "/products/create";
120
+ /**
121
+ * GET - https://api.abacatepay.com/v2/products/list
122
+ */
123
+ readonly list: ({ page, limit }?: RESTGetListProductsQueryParams) => `/products/list?page=${number}&limit=${number}`;
124
+ /**
125
+ * GET - https://api.abacatepay.com/v2/products/get
126
+ */
127
+ readonly get: ({ id, externalId }?: RESTGetProductQueryParams) => `/products/get?${string}`;
128
+ };
129
+ };
@@ -0,0 +1,162 @@
1
+ export const Routes = {
2
+ customers: {
3
+ /**
4
+ * POST - https://api.abacatepay.com/v2/customers/create
5
+ */
6
+ create: '/customers/create',
7
+ /**
8
+ * GET - https://api.abacatepay.com/v2/customers/list
9
+ */
10
+ list({ page = 1, limit = 20 } = {}) {
11
+ return `/customers/list?page=${page}&limit=${limit}`;
12
+ },
13
+ /**
14
+ * GET - https://api.abacatepay.com/v2/customers/get
15
+ */
16
+ get(id) {
17
+ return `/customers/get?id=${id}`;
18
+ },
19
+ /**
20
+ * DELETE - https://api.abacatepay.com/v2/customers/delete
21
+ */
22
+ delete: '/customers/delete',
23
+ },
24
+ checkouts: {
25
+ /**
26
+ * POST - https://api.abacatepay.com/v2/checkouts/create
27
+ */
28
+ create: '/checkouts/create',
29
+ /**
30
+ * GET - https://api.abacatepay.com/v2/checkouts/list
31
+ */
32
+ list: '/checkouts/list',
33
+ /**
34
+ * GET - https://api.abacatepay.com/v2/checkouts/get
35
+ */
36
+ get(id) {
37
+ return `/checkouts/get?id=${id}`;
38
+ },
39
+ },
40
+ transparents: {
41
+ /**
42
+ * POST - https://api.abacatepay.com/v2/transparents/create
43
+ */
44
+ createQRCode: '/transparents/create',
45
+ /**
46
+ * POST - https://api.abacatepay.com/v2/transparents/simulate-payment
47
+ */
48
+ simulatePayment(id) {
49
+ return `/transparents/simulate-payment?id=${id}`;
50
+ },
51
+ /**
52
+ * GET - https://api.abacatepay.com/v2/transparents/check
53
+ */
54
+ checkStatus(id) {
55
+ return `/transparents/check?id=${id}`;
56
+ },
57
+ },
58
+ coupons: {
59
+ /**
60
+ * POST - https://api.abacatepay.com/v2/coupons/create
61
+ */
62
+ create: '/coupons/create',
63
+ /**
64
+ * GET - https://api.abacatepay.com/v2/coupons/list
65
+ */
66
+ list({ page = 1, limit = 20 } = {}) {
67
+ return `/coupons/list?page=${page}&limit=${limit}`;
68
+ },
69
+ /**
70
+ * GET - https://api.abacatepay.com/v2/coupons/get
71
+ */
72
+ get(id) {
73
+ return `/coupons/get?id=${id}`;
74
+ },
75
+ /**
76
+ * DELETE - https://api.abacatepay.com/v2/coupons/delete
77
+ */
78
+ delete: '/coupons/delete',
79
+ /**
80
+ * PATCH - https://api.abacatepay.com/v2/coupons/toggle
81
+ */
82
+ toggleStatus: '/coupons/toggle',
83
+ },
84
+ payouts: {
85
+ /**
86
+ * POST - https://api.abacatepay.com/v2/payouts/create
87
+ */
88
+ create: '/payouts/create',
89
+ /**
90
+ * GET - https://api.abacatepay.com/v2/payouts/get
91
+ */
92
+ get(externalId) {
93
+ return `/payouts/get?externalId=${externalId}`;
94
+ },
95
+ /**
96
+ * GET - https://api.abacatepay.com/v2/payouts/list
97
+ */
98
+ list({ page = 1, limit = 20 } = {}) {
99
+ return `/payouts/list?page=${page}&limit=${limit}`;
100
+ },
101
+ },
102
+ store: {
103
+ /**
104
+ * GET - https://api.abacatepay.com/v2/store/get
105
+ */
106
+ get: '/store/get',
107
+ },
108
+ mrr: {
109
+ /**
110
+ * GET - https://api.abacatepay.com/v2/public-mrr/mrr
111
+ */
112
+ get: '/public-mrr/mrr',
113
+ /**
114
+ * GET - https://api.abacatepay.com/v2/public-mrr/merchant-info
115
+ */
116
+ merchant: '/public-mrr/merchant-info',
117
+ /**
118
+ * GET - https://api.abacatepay.com/v2/public-mrr/renevue
119
+ */
120
+ revenue(start, end) {
121
+ return `/public-mrr/revenue?startDate=${start}&endDate=${end}`;
122
+ },
123
+ },
124
+ subscriptions: {
125
+ /**
126
+ * POST - https://api.abacatepay.com/v2/subscriptions/create
127
+ */
128
+ create: '/subscriptions/create',
129
+ /**
130
+ * GET - https://api.abacatepay.com/v2/subscriptions/list
131
+ */
132
+ list({ cursor, limit = 20 } = {}) {
133
+ const query = new URLSearchParams({ limit: `${limit}` });
134
+ if (cursor)
135
+ query.append('cursor', cursor);
136
+ return `/subscriptions/list?${query}`;
137
+ },
138
+ },
139
+ products: {
140
+ /**
141
+ * POST - https://api.abacatepay.com/v2/products/create
142
+ */
143
+ create: '/products/create',
144
+ /**
145
+ * GET - https://api.abacatepay.com/v2/products/list
146
+ */
147
+ list({ page = 1, limit = 20 } = {}) {
148
+ return `/products/list?page=${page}&limit=${limit}`;
149
+ },
150
+ /**
151
+ * GET - https://api.abacatepay.com/v2/products/get
152
+ */
153
+ get({ id, externalId } = {}) {
154
+ const query = new URLSearchParams();
155
+ if (id)
156
+ query.append('id', id);
157
+ if (externalId)
158
+ query.append('externalId', externalId);
159
+ return `/products/get?${query}`;
160
+ },
161
+ },
162
+ };
@@ -0,0 +1,26 @@
1
+ import { type WebhookEvent } from './webhook';
2
+ /**
3
+ * A type guard check for `payout.done` webhook events.
4
+ * @param event - The webhook event to check against.
5
+ * @returns A boolean that indicates if the webhook is a payout done webhook.
6
+ */
7
+ export declare function isPayoutDoneWebhookEvent(event: WebhookEvent): event is import("./webhook").WebhookPayoutDoneEvent;
8
+ /**
9
+ * A type guard check for `payout.failed` webhook events.
10
+ * @param event - The webhook event to check against.
11
+ * @returns A boolean that indicates if the webhook is a payout failed webhook.
12
+ */
13
+ export declare function isPayoutFailedWebhookEvent(event: WebhookEvent): event is import("./webhook").WebhookPayoutFailedEvent;
14
+ /**
15
+ * A type guard check for `billing.paid` webhook events.
16
+ * @param event - The webhook event to check against.
17
+ * @returns A boolean that indicates if the webhook is a billing paid webhook.
18
+ */
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;
@@ -0,0 +1,42 @@
1
+ import { createHmac, timingSafeEqual } from 'node:crypto';
2
+ import { WebhookEventType } from './webhook';
3
+ /**
4
+ * A type guard check for `payout.done` webhook events.
5
+ * @param event - The webhook event to check against.
6
+ * @returns A boolean that indicates if the webhook is a payout done webhook.
7
+ */
8
+ export function isPayoutDoneWebhookEvent(event) {
9
+ return event.event === WebhookEventType.PayoutDone;
10
+ }
11
+ /**
12
+ * A type guard check for `payout.failed` webhook events.
13
+ * @param event - The webhook event to check against.
14
+ * @returns A boolean that indicates if the webhook is a payout failed webhook.
15
+ */
16
+ export function isPayoutFailedWebhookEvent(event) {
17
+ return event.event === WebhookEventType.PayoutFailed;
18
+ }
19
+ /**
20
+ * A type guard check for `billing.paid` webhook events.
21
+ * @param event - The webhook event to check against.
22
+ * @returns A boolean that indicates if the webhook is a billing paid webhook.
23
+ */
24
+ export function isBillingPaidWebhookEvent(event) {
25
+ return event.event === WebhookEventType.BillingPaid;
26
+ }
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
+ };
@@ -0,0 +1,135 @@
1
+ import type { APIPayout, PaymentMethod, PaymentStatus, PayoutStatus } from '.';
2
+ export interface BaseWebhookEvent<Type extends WebhookEventType, Data extends object> {
3
+ /**
4
+ * The data received in the event.
5
+ */
6
+ data: Data;
7
+ /**
8
+ * Unique identifier for the webhook.
9
+ */
10
+ id: string;
11
+ /**
12
+ * This field identifies the type of event received.
13
+ */
14
+ event: Type;
15
+ /**
16
+ * Indicates whether the event occurred in the development environment.
17
+ */
18
+ devMode: boolean;
19
+ }
20
+ /**
21
+ * https://docs.abacatepay.com/pages/webhooks#payout-failed
22
+ */
23
+ export type WebhookPayoutFailedEvent = BaseWebhookEvent<WebhookEventType.PayoutFailed, {
24
+ /**
25
+ * Transaction data.
26
+ */
27
+ transaction: Omit<APIPayout, 'status'> & {
28
+ /**
29
+ * Status of the payout. Always `PayoutStatus.Cancelled`.
30
+ *
31
+ * @see {@link PayoutStatus.Cancelled}
32
+ */
33
+ status: PayoutStatus.Cancelled;
34
+ };
35
+ }>;
36
+ /**
37
+ * https://docs.abacatepay.com/pages/webhooks#payout-done
38
+ */
39
+ export type WebhookPayoutDoneEvent = BaseWebhookEvent<WebhookEventType.PayoutDone, {
40
+ /**
41
+ * Transaction data.
42
+ */
43
+ transaction: Omit<APIPayout, 'status'> & {
44
+ /**
45
+ * Status of the payout. Always `PayoutStatus.Complete`.
46
+ *
47
+ * @see {@link PayoutStatus.Complete}
48
+ */
49
+ status: PayoutStatus.Complete;
50
+ };
51
+ }>;
52
+ /**
53
+ * https://docs.abacatepay.com/pages/webhooks#billing-paid
54
+ */
55
+ export type WebhookBillingPaidEvent = BaseWebhookEvent<WebhookEventType.BillingPaid, {
56
+ /**
57
+ * Payment data.
58
+ */
59
+ payment: {
60
+ /**
61
+ * Charge amount in cents (e.g. 4000 = R$40.00).
62
+ */
63
+ amount: number;
64
+ /**
65
+ * The fee charged by AbacatePay.
66
+ */
67
+ fee: 80;
68
+ /**
69
+ * Payment method.
70
+ *
71
+ * @see {@link PaymentMethod}
72
+ */
73
+ method: PaymentMethod;
74
+ };
75
+ } & ({
76
+ pixQrCode: {
77
+ /**
78
+ * Charge amount in cents (e.g. 4000 = R$40.00).
79
+ */
80
+ amount: number;
81
+ /**
82
+ * Unique billing identifier.
83
+ */
84
+ id: string;
85
+ /**
86
+ * Kind of the payment.
87
+ */
88
+ kind: 'PIX';
89
+ /**
90
+ * Billing status, can only be `PAID` here.
91
+ *
92
+ * @see {@link PaymentStatus.Paid}
93
+ */
94
+ status: PaymentStatus.Paid;
95
+ };
96
+ } | {
97
+ billing: {
98
+ /**
99
+ * Charge amount in cents (e.g. 4000 = R$40.00).
100
+ */
101
+ amount: number;
102
+ /**
103
+ * Unique billing identifier.
104
+ */
105
+ id: string;
106
+ /**
107
+ * Bill ID in your system.
108
+ */
109
+ externalId: string;
110
+ /**
111
+ * Status of the payment. Always `PaymentStatus.Paid`.
112
+ *
113
+ * @see {@link PaymentStatus.Paid}
114
+ */
115
+ status: PaymentStatus.Paid;
116
+ /**
117
+ * URL where the user can complete the payment.
118
+ */
119
+ url: string;
120
+ };
121
+ })>;
122
+ /**
123
+ * https://docs.abacatepay.com/pages/webhooks
124
+ *
125
+ * Any field that contains the tag "@unstable" means that the field is an assumption, it is uncertain (Since AbacatePay does not provide any information about).
126
+ */
127
+ export type WebhookEvent = WebhookPayoutDoneEvent | WebhookPayoutFailedEvent | WebhookBillingPaidEvent;
128
+ /**
129
+ * https://docs.abacatepay.com/pages/webhooks
130
+ */
131
+ export declare enum WebhookEventType {
132
+ PayoutFailed = "payout.failed",
133
+ PayoutDone = "payout.done",
134
+ BillingPaid = "billing.paid"
135
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * https://docs.abacatepay.com/pages/webhooks
3
+ */
4
+ export var WebhookEventType;
5
+ (function (WebhookEventType) {
6
+ WebhookEventType["PayoutFailed"] = "payout.failed";
7
+ WebhookEventType["PayoutDone"] = "payout.done";
8
+ WebhookEventType["BillingPaid"] = "billing.paid";
9
+ })(WebhookEventType || (WebhookEventType = {}));
package/dist/version.d.ts CHANGED
@@ -1,2 +1,8 @@
1
- export declare const version: "0.0.4";
2
- export declare const API_VERSION: "1";
1
+ /**
2
+ * Current version of [@abacatepay/types](https://www.npmjs.com/package/@abacatepay/types).
3
+ */
4
+ export declare const version: "2.0.1";
5
+ /**
6
+ * Current version of the AbacatePay API
7
+ */
8
+ export declare const API_VERSION: "2";
package/dist/version.js CHANGED
@@ -1,4 +1,9 @@
1
- // Auto-generated in build (DO NOT edit)
2
- export const version = '0.0.4';
3
- // Current AbacatePay API version - https://docs.abacatepay.com/pages/introduction
4
- export const API_VERSION = '1';
1
+ // AUTO-GENERATED DO NOT EDIT
2
+ /**
3
+ * Current version of [@abacatepay/types](https://www.npmjs.com/package/@abacatepay/types).
4
+ */
5
+ export const version = '2.0.1';
6
+ /**
7
+ * Current version of the AbacatePay API
8
+ */
9
+ export const API_VERSION = '2';
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
- "version": "0.0.4",
2
+ "version": "2.0.1",
3
3
  "name": "@abacatepay/types",
4
4
  "description": "Abacate Pay API typings that are always up to date.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
+ "license": "Apache-2.0",
8
9
  "exports": {
9
10
  ".": {
10
11
  "import": "./dist/index.js",
@@ -13,12 +14,28 @@
13
14
  "./v1": {
14
15
  "import": "./dist/v1/index.js",
15
16
  "types": "./dist/v1/index.d.ts"
16
- }
17
+ },
18
+ "./v1/*": {
19
+ "import": "./dist/v1/*.js",
20
+ "types": "./dist/v1/*.d.ts"
21
+ },
22
+ "./v2": {
23
+ "import": "./dist/v2/index.js",
24
+ "types": "./dist/v2/index.d.ts"
25
+ },
26
+ "./v2/*": {
27
+ "import": "./dist/v2/*.js",
28
+ "types": "./dist/v2/*.d.ts"
29
+ },
30
+ "./v*": null
17
31
  },
18
32
  "typesVersions": {
19
33
  "*": {
20
34
  "v1": [
21
35
  "dist/v1/index.d.ts"
36
+ ],
37
+ "v2": [
38
+ "dist/v2/index.d.ts"
22
39
  ]
23
40
  }
24
41
  },
@@ -26,10 +43,10 @@
26
43
  "dist"
27
44
  ],
28
45
  "scripts": {
29
- "gen:version": "bun run scripts/version.ts",
30
46
  "build": "bun run gen:version && tsc",
31
47
  "prepublishOnly": "bun run build",
32
- "fmt": "bunx biome check --write types && clear"
48
+ "gen:version": "bun run scripts/version.ts",
49
+ "fmt": "bunx biome check --write package.json types && clear"
33
50
  },
34
51
  "devDependencies": {
35
52
  "@biomejs/biome": "^2.3.8",
@@ -43,5 +60,9 @@
43
60
  ],
44
61
  "publishConfig": {
45
62
  "access": "public"
63
+ },
64
+ "repository": {
65
+ "type": "git",
66
+ "url": "https://github.com/almeidazs/ecosystem"
46
67
  }
47
68
  }