UNPKG

gofrugal-ecommerce-sdk

Version:

GoFrugal ERP Ecommerce SDK for Node.js, Bun, Deno, and Web

77 lines (75 loc) 1.9 kB
// src/client/gofrugal-sdk.ts class GoFrugalSDK { apiKey; baseUrl; constructor(options) { this.apiKey = options.apiKey; this.baseUrl = options.baseUrl; } async request(path, method = "GET", body) { const headers = { "Content-Type": "application/json", "X-Auth-Token": this.apiKey }; const res = await fetch(`${this.baseUrl}${path}`, { method, headers, body: body ? JSON.stringify(body) : undefined }); if (!res.ok) { const errText = await res.text(); throw new Error(`HTTP ${res.status}: ${errText}`); } return res.json(); } async getItems() { return this.request("/items"); } async createSalesOrder(order) { return this.request("/salesOrders", "POST", { salesOrder: order }); } async getSalesOrders() { return this.request("/salesOrders"); } async getSalesOrderById(id) { return this.request(`/salesOrder?id=${id}`); } async getCustomers() { return this.request("/customers"); } async getCustomerById(id) { return this.request(`/customers/${id}`); } async getCategories() { return this.request("/categories"); } async getCategoryValues(categoryId) { return this.request(`/categoryValues?categoryId=${categoryId}`); } async getCategoryDetails(id) { return this.request(`/categoryDetails/${id}`); } async getItemMaster() { return this.request("/itemMaster"); } async getItemByEan(eanCode) { return this.request(`/eanCode/${eanCode}`); } async getItemStockByBatchPrice(itemId) { return this.request(`/itemStockByBatchPrice?itemId=${itemId}`); } } // src/index.ts function detectRuntime() { if (typeof Bun !== "undefined") return "bun"; if (typeof Deno !== "undefined") return "deno"; if (typeof window !== "undefined") return "browser"; return "node"; } export { detectRuntime, GoFrugalSDK };