Skip to content

Commit 9d06356

Browse files
Merge pull request #2 from migtibincoski/dev
- Github Actions configuration file to automatically send the package to NPM (`~/.github/workflows/publish.yml`); - Creation of the `README.md` file, with introductory documentation for the project (`~/README.md`); - Export of the `AsaasSDK` class, in addition to a `utils` object, which has a CPF formatting function and CPF validator (`~/src/index.ts`); - Creation of the first function, to create a new payment (`~/src/sdk/payments/create-new-payment.ts`); - Definition of types in TypeScript (`~/src/sdk/payments/types.ts`) - Creation of the error class (`~/src/utils/error.ts`); - Creation of the CPF formatting function (`~/src/utils/format-cpf.ts`); - Creation of the CPF validation function (`~/src/utils/validate-cpf.ts`); - Creation of the test code for the create new payment function (`~/tests/payments/create-new-payment.test.ts`) - Creation of the test code for the CPF formatting function (`~/tests/utils/cpf/format.test.ts`); - Creation of the test code for the CPF validation function (`~/tests/utils/cpf/validate.test.ts`); - Creating the TypeScript configuration file (`~/tsconfig.json`) Thank you for your attention and for reading this description. Kind regards, Miguel Tibincoski <@migtibincoski>
2 parents bc885c5 + 4b776fc commit 9d06356

File tree

13 files changed

+1081
-0
lines changed

13 files changed

+1081
-0
lines changed

.github/workflows/publish.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Asaas SDK - build and publish
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build-and-publish:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v3
14+
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: "20"
19+
registry-url: "https://registry.npmjs.org/"
20+
21+
- name: Install dependencies
22+
run: yarn install
23+
24+
- name: Run tests
25+
run: yarn test
26+
27+
- name: Build project
28+
run: yarn build
29+
30+
- name: Minify files
31+
run: |
32+
yarn global add esbuild
33+
for file in $(find build -name '*.js' -type f); do
34+
esbuild "$file" --minify --minify-syntax --minify-whitespace --outfile="$file"
35+
done
36+
37+
- name: Publish to NPM
38+
if: success()
39+
run: yarn publish --access public
40+
env:
41+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# asaas-node-sdk
2+
3+
A modern and developer-friendly Node.js SDK for the [Asaas API](https://docs.asaas.com/), designed to simplify and streamline integration with the Asaas platform. Whether you're working with payments, subscriptions, or customer management, this SDK has you covered with clean, intuitive methods and TypeScript support.
4+
5+
## ✨ Features
6+
7+
- **Full support** for Asaas REST API (v3)
8+
- **Easy-to-use methods** for common operations
9+
- **Built-in TypeScript types** and IntelliSense
10+
- **Response normalization**
11+
- **Future-proof** and actively maintained
12+
- **Promise-based architecture** – orks with `.then/.catch` and `async/await`
13+
14+
## 📦 Installation
15+
16+
This package is not yet available for use.
17+
18+
## 📚 Documentation
19+
20+
For a full list of methods and features, visit the [official Asaas API Reference](https://docs.asaas.com/) or explore our detailed SDK docs available [here](https://github.com/migtibincoski/asaas-node-sdk/wiki).
21+
22+
### Available Modules
23+
24+
- ⚠️ Payments
25+
-[Create new payment](https://docs.asaas.com/reference/create-new-payment)
26+
- ⚠️ [List charges](https://docs.asaas.com/reference/list-payments)
27+
-[Create new payment with credit card](https://docs.asaas.com/reference/create-new-payment-with-credit-card)
28+
-[Capture payment with pre-authorization](https://docs.asaas.com/reference/capture-payment-with-pre-authorization)
29+
-[Pay a charge with a credit card](https://docs.asaas.com/reference/pay-a-charge-with-credit-card)
30+
-[Retrieve payment billing information](https://docs.asaas.com/reference/retrieve-payment-billing-information)
31+
-[Payment viewing information](https://docs.asaas.com/reference/payment-viewing-information)
32+
-[Retrieve a single payment](https://docs.asaas.com/reference/retrieve-a-single-payment)
33+
-[Update existing payment](https://docs.asaas.com/reference/update-existing-payment)
34+
-[Delete payment](https://docs.asaas.com/reference/delete-payment)
35+
-[Restore removed payment](https://docs.asaas.com/reference/restore-removed-payment)
36+
-[Retrieve status of a payment](https://docs.asaas.com/reference/retrieve-status-of-a-payment)
37+
-[Refund payment](https://docs.asaas.com/reference/refund-payment)
38+
-[Get digitable bill line](https://docs.asaas.com/reference/get-digitable-bill-line)
39+
-[Get QR Code for Pix payments](https://docs.asaas.com/reference/get-qr-code-for-pix-payments)
40+
-[Confirm cash receipt](https://docs.asaas.com/reference/confirm-cash-receipt)
41+
-[Undo cash receipt confirmation](https://docs.asaas.com/reference/undo-cash-receipt-confirmation)
42+
-[Sales simulator](https://docs.asaas.com/reference/sales-simulator)
43+
-[Retrieve payment escrow in the Escrow Account](https://docs.asaas.com/reference/retrieve-payment-escrow-in-the-escrow-account)
44+
-[Recover payment limits](https://docs.asaas.com/reference/recovering-payment-limits)
45+
- ❌ Sandbox Actions
46+
- ❌ Payment with summary data
47+
- ❌ Credit Card
48+
- ❌ Payment Refund
49+
- ❌ Payment Split
50+
- ❌ Payment Document
51+
- ❌ Customer
52+
- ❌ Notification
53+
- ❌ Installment
54+
- ❌ Subscription
55+
- ❌ Pix
56+
- ❌ Pix Transaction
57+
- ❌ Recurring Pix
58+
- ❌ Payment Link
59+
- ❌ Checkout
60+
- ❌ Transfer
61+
- ❌ Anticipation
62+
- ❌ Payment Dunning
63+
- ❌ Bill
64+
- ❌ Mobile Phone Recharge
65+
- ❌ Credit Bureau Report
66+
- ❌ Financial Transaction
67+
- ❌ Finance
68+
- ❌ Account Info
69+
- ❌ Invoice
70+
- ❌ Fiscal Info
71+
- ❌ Webhook
72+
- ❌ Subaccount
73+
- ❌ Account Document
74+
- ❌ Chargeback
75+
76+
## 🧪 Testing
77+
78+
All methods are covered with unit and integration tests. To run tests locally:
79+
80+
```bash
81+
npm run test
82+
# or
83+
yarn test
84+
```
85+
86+
## 🛠️ Built With
87+
88+
- Node.js
89+
- TypeScript
90+
- JavaScript
91+
- Jest
92+
- and so much coffee and love! ☕ 💙
93+
94+
## 🤝 Contributing
95+
96+
We welcome contributions! If you'd like to report bugs, request features or submit pull requests, feel free to open an issue or fork the repo.
97+
98+
## 📄 License
99+
100+
MIT License. See [LICENSE](./LICENSE) for more information.
101+
102+
---
103+
104+
Developed with 💙 by [Miguel Tibincoski](https://github.com/migtibincoski), based on [official Asaas API](https://docs.asaas.com).

src/index.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import Payments from "./sdk/payments";
2+
import type { CreateNewPaymentBody } from "./sdk/payments/types";
3+
import AsaasSdkError from "./utils/error";
4+
import formatCPF from "./utils/format-cpf";
5+
import validateCPF from "./utils/validate-cpf";
6+
7+
export type AsaasSdkConstructorConfig = {
8+
baseURL?: string;
9+
apiKey: string;
10+
version?: string;
11+
debug?: boolean;
12+
};
13+
14+
class AsaasSDK {
15+
baseURL: string = "https://api-sandbox.asaas.com";
16+
apiKey: string = "";
17+
version: string = "v3";
18+
debug: boolean = false;
19+
20+
constructor(data: AsaasSdkConstructorConfig) {
21+
if (!data)
22+
throw new AsaasSdkError({
23+
name: "INITIALIZATION_ERROR",
24+
message: "Failed to initialize Asaas SDK",
25+
cause: "No data provided",
26+
});
27+
28+
if (typeof data !== "object")
29+
throw new AsaasSdkError({
30+
name: "INITIALIZATION_ERROR",
31+
message: "Failed to initialize Asaas SDK",
32+
cause: `Invalid data type. Expected object, got ${typeof data}`,
33+
});
34+
35+
const oldWarn = console.warn;
36+
console.warn = (...args: any[]) => this.debug && oldWarn(...args);
37+
38+
this.debug.toString().toLowerCase() == "true"
39+
? (this.debug = true)
40+
: (this.debug = false);
41+
42+
if (!data.baseURL) {
43+
console.warn(
44+
"\x1b[33mBase URL not provided. Defaulting to sandbox URL: https://api-sandbox.asaas.com\x1b[0m"
45+
);
46+
data.baseURL = "https://api-sandbox.asaas.com";
47+
}
48+
49+
let url = null;
50+
try {
51+
url = new URL(data.baseURL);
52+
} catch {
53+
throw new AsaasSdkError({
54+
name: "INITIALIZATION_ERROR",
55+
message: "Failed to initialize Asaas SDK",
56+
cause: `Invalid base URL. You provided: ${data.baseURL}`,
57+
});
58+
}
59+
60+
if (url.protocol !== "https:") {
61+
console.warn(
62+
"\x1b[33mBase URL is not using HTTPS. This may cause issues with the API. Automatically switching to HTTPS...\x1b[0m"
63+
);
64+
url.protocol = "https:";
65+
data.baseURL = url.toString();
66+
}
67+
68+
if (!data.version) {
69+
console.warn(
70+
"\x1b[33mVersion not provided. Defaulting to v3. Please specify the version in the future.\x1b[0m"
71+
);
72+
this.version = "v3";
73+
}
74+
75+
if (!data.apiKey)
76+
throw new AsaasSdkError({
77+
name: "INITIALIZATION_ERROR",
78+
message: "Failed to initialize Asaas SDK",
79+
cause: "Missing API key",
80+
});
81+
82+
if (typeof data.apiKey !== "string")
83+
throw new AsaasSdkError({
84+
name: "INITIALIZATION_ERROR",
85+
message: "Failed to initialize Asaas SDK",
86+
cause: `Invalid API key type. Expected string, got ${typeof data.apiKey}`,
87+
});
88+
89+
this.baseURL = data.baseURL;
90+
this.apiKey = data.apiKey;
91+
}
92+
93+
payments = {
94+
createNewPayment: (request: CreateNewPaymentBody) =>
95+
Payments.createNewPayment(this, request),
96+
};
97+
}
98+
99+
const utils = {
100+
cpf: {
101+
format: formatCPF,
102+
validate: validateCPF,
103+
},
104+
};
105+
106+
export { utils, AsaasSDK };

0 commit comments

Comments
 (0)