@tosave04/dolibarr-utils-ts v1.3.5
@tosave04/dolibarr-utils-ts
Typescript communication tools, Zod schemas, and utilities for the Dolibarr REST API.
Description
@tosave04/dolibarr-utils-ts is a TypeScript library designed to facilitate communication with the Dolibarr REST API. It includes a collection of methods, interfaces, and schemas that simplify the process of interacting with Dolibarr, a popular open-source ERP and CRM system. The library provides a structured way to perform CRUD operations and other common actions on various Dolibarr modules.
Dolibarr
The module was developed and tested on Dolibarr version 17.0.2. Further changes to the Dolibarr REST API are not supported at this time.
Installation
To install the package, use npm:
npm install @tosave04/dolibarr-utils-tsor
yarn add @tosave04/dolibarr-utils-tsUsage
Here's a quick guide on how to use the @tosave04/dolibarr-utils-ts module in your project.
Importing and Instantiating the API
First, you need to import and instantiate the DolibarrApi class. You'll need to provide your Dolibarr API URL and API key.
import { DolibarrApi } from "@tosave04/dolibarr-utils-ts"
const url = String(process.env.DOLIBARR_API_URL)
const key = String(process.env.DOLIBARR_API_KEY)
const dolibarrApi = new DolibarrApi(url, key)Example Usage
Ping the API
Check the API status using the ping method:
dolibarrApi
.ping()
.then((response) => {
console.log("API Status:", response)
})
.catch((error) => {
console.error("Error:", error)
})List Proposals
Retrieve a list of proposals with optional sorting:
dolibarrApi.proposals
.list({ sortfield: "t.rowid", sortorder: "ASC" })
.then((proposals) => {
console.log("Proposals:", proposals)
})
.catch((error) => {
console.error("Error:", error)
})Create a New Product
Create a new product in Dolibarr:
const newProduct = {
label: "New Product",
price: 100,
// Other product fields...
}
dolibarrApi.products
.create(newProduct)
.then((productId) => {
console.log("Created Product ID:", productId)
})
.catch((error) => {
console.error("Error:", error)
})Update an Existing Product
Update an existing product by its ID:
const updatedProduct = {
label: "Updated Product",
price: 150,
// Other product fields...
}
dolibarrApi.products
.update(1, updatedProduct)
.then((response) => {
console.log("Update Response:", response)
})
.catch((error) => {
console.error("Error:", error)
})Delete a Product
Delete a product by its ID:
dolibarrApi.products
.delete(1)
.then((response) => {
console.log("Delete Response:", response)
})
.catch((error) => {
console.error("Error:", error)
})Modules
The DolibarrApi class provides methods for various Dolibarr modules, including:
agendaeventsbankaccountscategoriescontactsdocumentsinvoicesloginordersproductsproposalssetupshipmentsstatusstockmovementsthirdpartiesticketsuserswarehouses
Each module includes methods for listing, creating, updating, and deleting resources.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub.
Tricks
- Regex to help format comments :
find: @(param|return)\s*([\w|<>]+)\s*(\$(\w*))?\s*
replace: @$1\t$2\t\t$4\t\tAdded method: clone
_template.tsfile.Added interface: clone
_template.interfaces.tsfile and add the export ininterfaces/index.ts.Added test: clone
tests/template.tsfile and replace.tsby.test.ts.Build
distfolder :
yarn test # To check the cohesion of the methods
yarn build # tsup compilation of the dist folder
yarn test-dist # Run the `test.js` file created in the dist folderLicense
This project is licensed under the GPL-3.0 License.