mashroo3
v0.1.0
Published
Simple JavaScript client for the Mashroo3 API.
Maintainers
Readme
mashroo3
Simple JavaScript client for the Mashroo3 API.
Install
npm install mashroo3Quick Start
const { Mashroo3 } = require("mashroo3");
const mashroo3 = new Mashroo3("YOUR_API_KEY");
const catalog = await mashroo3.catalog.list();
console.log(catalog);Also supported:
const { mashroo3 } = require("mashroo3");
const client = new mashroo3("YOUR_API_KEY");
const orders = await client.orders.list();ESM:
import Mashroo3 from "mashroo3";
const mashroo3 = new Mashroo3("YOUR_API_KEY");
const orders = await mashroo3.orders.list();Constructor
new Mashroo3(apiKey, options?)Options:
baseUrl(default:https://mashroo3.net)timeoutMs(default:30000)fetchcustom fetch implementation (optional)
API
Catalog
await mashroo3.catalog.list();Customers
await mashroo3.customers.list();
await mashroo3.customers.create({
name: "John Doe",
phone: "+15550000000",
});Orders
// Returns latest orders from /api/orders (currently last 10 on server side)
await mashroo3.orders.list();
await mashroo3.orders.get(44);
await mashroo3.orders.create({
customer_id: 12,
items: [
{ product_id: 1, qty: 2 },
{ product_id: 5, qty: 1 }
],
paid: 20
});
await mashroo3.orders.refund(44, {
items: [
{ order_item_id: 101, qty: 1 }
],
reason: "Damaged item"
});Low-level request
await mashroo3.request("GET", "/api/catalog");Error Handling
try {
await mashroo3.orders.get(999999);
} catch (error) {
if (error.name === "Mashroo3Error") {
console.error(error.message);
console.error(error.status);
console.error(error.data);
}
}