zata-vsdc-sdk 1.1.0 → 1.1.2
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 +253 -58
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,108 +1,303 @@
|
|
|
1
1
|
# zata-vsdc-sdk
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/zata-vsdc-sdk)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
4
6
|
|
|
5
|
-
TypeScript SDK for the Zata API
|
|
7
|
+
A production-friendly TypeScript/JavaScript SDK for the Zata API.
|
|
8
|
+
Built for Rwanda e-invoicing and tax-compliance workflows: companies, branches, parties, products, expenses, transactions, insurance, patient flows, and signed invoice downloads.
|
|
6
9
|
|
|
7
|
-
##
|
|
10
|
+
## Why use this SDK
|
|
11
|
+
|
|
12
|
+
- Fast onboarding to the Zata API with a single client
|
|
13
|
+
- Automatic `Authorization`, `companyId`, and `branchId` header handling
|
|
14
|
+
- Clean method names that map directly to documented API actions
|
|
15
|
+
- Works in both TypeScript and JavaScript projects
|
|
16
|
+
- Built-in request error formatting for faster debugging
|
|
17
|
+
|
|
18
|
+
## Install
|
|
8
19
|
|
|
9
20
|
```bash
|
|
10
21
|
npm install zata-vsdc-sdk
|
|
11
22
|
```
|
|
12
23
|
|
|
13
|
-
|
|
24
|
+
Or with yarn:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
yarn add zata-vsdc-sdk
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or with pnpm:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pnpm add zata-vsdc-sdk
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
14
37
|
|
|
15
38
|
```ts
|
|
16
39
|
import { ZataClient } from "zata-vsdc-sdk";
|
|
17
40
|
|
|
18
41
|
const client = new ZataClient({
|
|
42
|
+
// token is preferred. apiKey is also supported as an alias.
|
|
19
43
|
token: process.env.ZATA_TOKEN,
|
|
20
44
|
companyId: 1,
|
|
21
45
|
branchId: 1,
|
|
22
|
-
baseUrl: "https://api.zata.rw",
|
|
46
|
+
baseUrl: "https://api.zata.rw", // default (direct)
|
|
47
|
+
// baseUrl: "https://proxy.zata.rw", // optional gateway/proxy base
|
|
48
|
+
timeout: 30000, // default
|
|
23
49
|
});
|
|
50
|
+
|
|
51
|
+
async function run() {
|
|
52
|
+
// 1) Pull reference data
|
|
53
|
+
const paymentModes = await client.getPaymentModes();
|
|
54
|
+
const taxes = await client.getProductTaxes();
|
|
55
|
+
|
|
56
|
+
// 2) Create a customer
|
|
57
|
+
await client.createCustomer({
|
|
58
|
+
name: "John Doe",
|
|
59
|
+
address: "Kigali",
|
|
60
|
+
phone: "0780000000",
|
|
61
|
+
email: "john@example.com",
|
|
62
|
+
tin: "123456789",
|
|
63
|
+
hasInsurance: "no",
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// 3) Create a product
|
|
67
|
+
await client.createProduct({
|
|
68
|
+
name: "Service Item",
|
|
69
|
+
packagingUnitID: 1,
|
|
70
|
+
quantityUnitID: 1,
|
|
71
|
+
countryID: 1,
|
|
72
|
+
taxID: 1,
|
|
73
|
+
branchProductCategoryID: 1,
|
|
74
|
+
hasStock: "yes",
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// 4) Create a sale transaction
|
|
78
|
+
const sale = await client.createSaleTransaction({
|
|
79
|
+
paymentMethodID: 1,
|
|
80
|
+
transactionDate: "2026-01-01",
|
|
81
|
+
items: [{ productID: 1, units: 1, unitPrice: 1000, discountRate: 0 }],
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return { paymentModes, taxes, sale };
|
|
85
|
+
}
|
|
24
86
|
```
|
|
25
87
|
|
|
26
|
-
|
|
88
|
+
## JavaScript (CommonJS)
|
|
27
89
|
|
|
28
|
-
|
|
90
|
+
```js
|
|
91
|
+
const { ZataClient } = require("zata-vsdc-sdk");
|
|
29
92
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
password: "your-password",
|
|
93
|
+
const client = new ZataClient({
|
|
94
|
+
token: process.env.ZATA_TOKEN,
|
|
95
|
+
companyId: 1,
|
|
96
|
+
branchId: 1,
|
|
35
97
|
});
|
|
36
98
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
99
|
+
client
|
|
100
|
+
.listTransactions({ page: 1, perPage: 20 })
|
|
101
|
+
.then((res) => console.log(res))
|
|
102
|
+
.catch((err) => console.error(err.message));
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Authentication and context
|
|
106
|
+
|
|
107
|
+
Most business endpoints need:
|
|
108
|
+
|
|
109
|
+
- `Authorization: Bearer <token>`
|
|
110
|
+
- `companyId`
|
|
111
|
+
- `branchId`
|
|
112
|
+
|
|
113
|
+
You can define these once at client creation, then update later when needed:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
client.setContext({ companyId: 2, branchId: 7 });
|
|
117
|
+
client.setToken("new-token-value");
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## End-to-end implementation flow
|
|
121
|
+
|
|
122
|
+
Recommended sequence for most integrators:
|
|
123
|
+
|
|
124
|
+
1. Authenticate (`login`) and set token
|
|
125
|
+
2. Validate company and branch (`getCompany`, `listCompanyBranches`)
|
|
126
|
+
3. Fetch reference data (`getPaymentModes`, product tax/unit/category lookups)
|
|
127
|
+
4. Create parties (`createCustomer`, `createSupplier`)
|
|
128
|
+
5. Create products (`createProduct`)
|
|
129
|
+
6. Create expense and transactions
|
|
130
|
+
7. Retrieve transaction PDF signature and download invoice
|
|
131
|
+
|
|
132
|
+
This mirrors the practical order required by dependent IDs across endpoints.
|
|
133
|
+
|
|
134
|
+
## API reference (SDK methods)
|
|
135
|
+
|
|
136
|
+
### Auth and utility
|
|
50
137
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
138
|
+
- `login(data)`
|
|
139
|
+
- `createAccount(data)`
|
|
140
|
+
- `getTestStatus()`
|
|
141
|
+
|
|
142
|
+
### Company and branches
|
|
143
|
+
|
|
144
|
+
- `listCompanies(params?)`
|
|
145
|
+
- `getCompany(companyId)`
|
|
146
|
+
- `createCompany(data)`
|
|
147
|
+
- `updateCompany(data)`
|
|
148
|
+
- `listCompanyBranches(params?)`
|
|
149
|
+
- `createCompanyBranch(data)`
|
|
150
|
+
- `updateCompanyBranch(data)`
|
|
151
|
+
- `getCompanyFinance()`
|
|
152
|
+
- `getCompanyTaxInfo()`
|
|
153
|
+
|
|
154
|
+
### Reference data
|
|
155
|
+
|
|
156
|
+
- `getPaymentModes()`
|
|
157
|
+
- `getProductCategories()`
|
|
158
|
+
- `getProductClasses()`
|
|
159
|
+
- `getProductCountryOrigins()`
|
|
160
|
+
- `getProductPackagingUnits()`
|
|
161
|
+
- `getProductQuantityUnits()`
|
|
162
|
+
- `getProductTaxes()`
|
|
163
|
+
- `getProductTypes()`
|
|
164
|
+
|
|
165
|
+
### Parties
|
|
166
|
+
|
|
167
|
+
- `listParties(params?)`
|
|
168
|
+
- `createCustomer(data)`
|
|
169
|
+
- `createSupplier(data)`
|
|
170
|
+
|
|
171
|
+
### Products
|
|
172
|
+
|
|
173
|
+
- `createProduct(data)`
|
|
174
|
+
- `listBranchProducts(params?)`
|
|
175
|
+
- `getProduct(productId)`
|
|
176
|
+
- `updateProduct(productId, data)`
|
|
177
|
+
- `increaseProductQuantity(productId, data)`
|
|
178
|
+
- `reduceProductQuantity(productId, data)`
|
|
179
|
+
|
|
180
|
+
### Expenses
|
|
181
|
+
|
|
182
|
+
- `listExpenses(params?)`
|
|
183
|
+
- `createExpense(data)`
|
|
184
|
+
- `getExpenseCategories()`
|
|
185
|
+
|
|
186
|
+
### Insurance
|
|
187
|
+
|
|
188
|
+
- `listInsurances()`
|
|
189
|
+
- `createPresetInsurance(data)`
|
|
190
|
+
- `createCustomInsurance(data)`
|
|
191
|
+
- `updateCustomInsurance(insuranceId, data)`
|
|
192
|
+
- `updateBranchInsurance(companyInsuranceId, data)`
|
|
193
|
+
|
|
194
|
+
### Patients
|
|
195
|
+
|
|
196
|
+
- `listPatients(params?)`
|
|
197
|
+
- `createPatient(data)`
|
|
198
|
+
- `getPatient(patientId)`
|
|
199
|
+
- `updatePatient(patientId, data)`
|
|
200
|
+
- `getPatientByParty(partyId)`
|
|
201
|
+
|
|
202
|
+
### Transactions
|
|
203
|
+
|
|
204
|
+
- `listTransactions(params?)`
|
|
205
|
+
- `calculateTransaction(data)`
|
|
206
|
+
- `createSaleTransaction(data)`
|
|
207
|
+
- `createPurchaseTransaction(data)`
|
|
208
|
+
- `createProformaTransaction(data)`
|
|
209
|
+
- `createRefundTransaction(transactionId, data)`
|
|
210
|
+
- `getTransaction(transactionId, params?)`
|
|
211
|
+
- `getTransactionDownloadSignature(transactionId, params?)`
|
|
212
|
+
- `downloadTransaction(params)`
|
|
213
|
+
|
|
214
|
+
## Transaction examples
|
|
215
|
+
|
|
216
|
+
### Calculate before create
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
const calc = await client.calculateTransaction({
|
|
220
|
+
items: [
|
|
221
|
+
{ productID: 1, units: 2, unitPrice: 1000, discountRate: 5, batchNumber: "B-001" }
|
|
222
|
+
]
|
|
59
223
|
});
|
|
224
|
+
```
|
|
60
225
|
|
|
61
|
-
|
|
62
|
-
|
|
226
|
+
### Create sale
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
const sale = await client.createSaleTransaction({
|
|
63
230
|
paymentMethodID: 1,
|
|
64
|
-
|
|
65
|
-
|
|
231
|
+
customerID: 1,
|
|
232
|
+
transactionDate: "2026-04-01",
|
|
233
|
+
note: "Sale from SDK",
|
|
234
|
+
items: [{ productID: 1, units: 2, unitPrice: 1000, discountRate: 0 }],
|
|
66
235
|
});
|
|
67
236
|
```
|
|
68
237
|
|
|
69
|
-
|
|
238
|
+
### Download invoice PDF
|
|
70
239
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
- Auth and account: `login`, `createAccount`
|
|
74
|
-
- Company and branches: `listCompanies`, `getCompany`, `createCompany`, `updateCompany`, `listCompanyBranches`, `createCompanyBranch`, `updateCompanyBranch`, `getCompanyFinance`, `getCompanyTaxInfo`
|
|
75
|
-
- Reference data: `getPaymentModes`, `getProductCategories`, `getProductClasses`, `getProductCountryOrigins`, `getProductPackagingUnits`, `getProductQuantityUnits`, `getProductTaxes`, `getProductTypes`
|
|
76
|
-
- Parties: `listParties`, `createCustomer`, `createSupplier`
|
|
77
|
-
- Product: `createProduct`, `listBranchProducts`, `getProduct`, `updateProduct`, `increaseProductQuantity`, `reduceProductQuantity`
|
|
78
|
-
- Expense: `listExpenses`, `createExpense`, `getExpenseCategories`
|
|
79
|
-
- Insurance: `listInsurances`, `createPresetInsurance`, `createCustomInsurance`, `updateCustomInsurance`, `updateBranchInsurance`
|
|
80
|
-
- Patient: `listPatients`, `createPatient`, `getPatient`, `updatePatient`, `getPatientByParty`
|
|
81
|
-
- Transactions: `listTransactions`, `calculateTransaction`, `createSaleTransaction`, `createPurchaseTransaction`, `createProformaTransaction`, `createRefundTransaction`, `getTransaction`, `getTransactionDownloadSignature`, `downloadTransaction`
|
|
240
|
+
```ts
|
|
241
|
+
const signature = await client.getTransactionDownloadSignature(123, { downloadSize: "A4" });
|
|
82
242
|
|
|
83
|
-
|
|
243
|
+
const pdf = await client.downloadTransaction({
|
|
244
|
+
expires: signature.expires,
|
|
245
|
+
id: signature.id,
|
|
246
|
+
signature: signature.signature,
|
|
247
|
+
});
|
|
248
|
+
```
|
|
84
249
|
|
|
85
|
-
|
|
250
|
+
## Error handling
|
|
86
251
|
|
|
87
|
-
|
|
88
|
-
- `companyId` header (when set)
|
|
89
|
-
- `branchId` header (when set)
|
|
252
|
+
The client throws normalized errors in this format:
|
|
90
253
|
|
|
91
|
-
|
|
254
|
+
- `Zata API Error <status>: <response-json>`
|
|
255
|
+
- `Network/Request Error: <message>`
|
|
92
256
|
|
|
93
257
|
```ts
|
|
94
|
-
|
|
95
|
-
client.
|
|
258
|
+
try {
|
|
259
|
+
await client.getTransaction(999999);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.error(error.message);
|
|
262
|
+
}
|
|
96
263
|
```
|
|
97
264
|
|
|
98
|
-
##
|
|
265
|
+
## Best practices
|
|
266
|
+
|
|
267
|
+
- Cache lookup/reference data (payment modes, taxes, units)
|
|
268
|
+
- Validate IDs and required fields before calling write endpoints
|
|
269
|
+
- Use `calculateTransaction` before creating high-value invoices
|
|
270
|
+
- Store entity IDs you create (party, product, transaction)
|
|
271
|
+
- Use retries/backoff for transient network or 5xx failures
|
|
272
|
+
|
|
273
|
+
## Development
|
|
99
274
|
|
|
100
275
|
```bash
|
|
276
|
+
npm install
|
|
101
277
|
npm run build
|
|
102
278
|
npm test
|
|
103
279
|
```
|
|
104
280
|
|
|
105
|
-
##
|
|
281
|
+
## API docs & base URLs
|
|
282
|
+
|
|
283
|
+
- Taxes docs: [https://docs.zata.rw](https://docs.zata.rw)
|
|
284
|
+
- Unified gateway docs: [https://proxy.zata.rw/api/v1/docs](https://proxy.zata.rw/api/v1/docs)
|
|
285
|
+
- Direct taxes base URL: `https://api.zata.rw`
|
|
286
|
+
- Gateway base URL (taxes under `/api/v1/*`): `https://proxy.zata.rw`
|
|
287
|
+
|
|
288
|
+
## Links
|
|
106
289
|
|
|
107
290
|
- API docs: [https://docs.zata.rw](https://docs.zata.rw)
|
|
108
291
|
- Website: [https://zata.rw](https://zata.rw)
|
|
292
|
+
- npm: [https://www.npmjs.com/package/zata-vsdc-sdk](https://www.npmjs.com/package/zata-vsdc-sdk)
|
|
293
|
+
- GitHub: [https://github.com/HiQ-Africa/zata-npm](https://github.com/HiQ-Africa/zata-npm)
|
|
294
|
+
- Integration guide: [./guide.md](./guide.md)
|
|
295
|
+
|
|
296
|
+
## Support
|
|
297
|
+
|
|
298
|
+
- Email: `hirwa@hiq.africa`
|
|
299
|
+
- Issues: [https://github.com/HiQ-Africa/zata-npm/issues](https://github.com/HiQ-Africa/zata-npm/issues)
|
|
300
|
+
|
|
301
|
+
## License
|
|
302
|
+
|
|
303
|
+
MIT
|