@bibike/erp-sdk 1.0.0

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 ADDED
@@ -0,0 +1,328 @@
1
+ # Bibike ERP TypeScript SDK
2
+
3
+ Official TypeScript SDK for the Bibike ERP API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @bibike/erp-sdk
9
+ # or
10
+ yarn add @bibike/erp-sdk
11
+ # or
12
+ pnpm add @bibike/erp-sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { BibikeClient } from '@bibike/erp-sdk';
19
+
20
+ const client = new BibikeClient({
21
+ baseUrl: 'https://bibike.fivorana.com/api.php',
22
+ });
23
+
24
+ // Login
25
+ const auth = await client.login({
26
+ email: 'user@example.com',
27
+ password: 'password123',
28
+ });
29
+
30
+ console.log('Logged in as:', auth.user.full_name);
31
+
32
+ // Or use an existing token
33
+ client.setToken('your-api-token');
34
+ ```
35
+
36
+ ## Usage Examples
37
+
38
+ ### Products
39
+
40
+ ```typescript
41
+ // List products
42
+ const products = await client.products.list({ page: 1, per_page: 20 });
43
+
44
+ // Search products
45
+ const results = await client.products.search('laptop');
46
+
47
+ // Get a single product
48
+ const product = await client.products.get(123);
49
+
50
+ // Create a product
51
+ const newProduct = await client.products.create({
52
+ name: 'New Product',
53
+ sku: 'SKU-001',
54
+ unit_price: 1500,
55
+ cost_price: 1000,
56
+ });
57
+
58
+ // Update a product
59
+ await client.products.update(123, { unit_price: 1600 });
60
+ ```
61
+
62
+ ### Sales
63
+
64
+ ```typescript
65
+ // List sales
66
+ const sales = await client.sales.list({
67
+ start_date: '2024-01-01',
68
+ end_date: '2024-12-31',
69
+ });
70
+
71
+ // Create a sale
72
+ const sale = await client.sales.create({
73
+ customer_id: 1,
74
+ payment_method: 'cash',
75
+ items: [
76
+ { product_id: 1, quantity: 2, unit_price: 500 },
77
+ { product_id: 2, quantity: 1, unit_price: 1000 },
78
+ ],
79
+ });
80
+
81
+ // Get sales analytics
82
+ const analytics = await client.sales.analytics({
83
+ start_date: '2024-01-01',
84
+ end_date: '2024-12-31',
85
+ });
86
+ ```
87
+
88
+ ### Inventory
89
+
90
+ ```typescript
91
+ // List inventory
92
+ const inventory = await client.inventory.list({ warehouse_id: 1 });
93
+
94
+ // Get low stock products
95
+ const lowStock = await client.inventory.lowStock();
96
+
97
+ // Create stock transfer
98
+ const transfer = await client.inventory.createTransfer({
99
+ from_warehouse_id: 1,
100
+ to_warehouse_id: 2,
101
+ items: [
102
+ { product_id: 1, quantity: 10 },
103
+ ],
104
+ });
105
+
106
+ // Create stock adjustment
107
+ await client.inventory.createAdjustment({
108
+ product_id: 1,
109
+ warehouse_id: 1,
110
+ quantity: 5,
111
+ adjustment_type: 'increase',
112
+ reason: 'Stock count correction',
113
+ });
114
+ ```
115
+
116
+ ### Customers
117
+
118
+ ```typescript
119
+ // List customers
120
+ const customers = await client.customers.list({ search: 'john' });
121
+
122
+ // Create customer
123
+ const customer = await client.customers.create({
124
+ name: 'John Doe',
125
+ email: 'john@example.com',
126
+ phone: '+250788123456',
127
+ });
128
+
129
+ // Get customer balance
130
+ const balance = await client.customers.balance(customer.data!.id);
131
+ ```
132
+
133
+ ### Purchasing
134
+
135
+ ```typescript
136
+ // List purchase orders
137
+ const orders = await client.purchasing.orders({ status: 'pending' });
138
+
139
+ // Create purchase order
140
+ const po = await client.purchasing.createOrder({
141
+ supplier_id: 1,
142
+ items: [
143
+ { product_id: 1, quantity: 100, unit_price: 800 },
144
+ ],
145
+ });
146
+
147
+ // Approve purchase order
148
+ await client.purchasing.approveOrder(po.data!.id);
149
+ ```
150
+
151
+ ### Accounting
152
+
153
+ ```typescript
154
+ // List accounts
155
+ const accounts = await client.accounting.accounts({ type: 'asset' });
156
+
157
+ // Create journal entry
158
+ const journal = await client.accounting.createJournal({
159
+ entry_date: '2024-01-15',
160
+ description: 'Monthly rent payment',
161
+ lines: [
162
+ { account_id: 1, debit: 50000, credit: 0 },
163
+ { account_id: 2, debit: 0, credit: 50000 },
164
+ ],
165
+ });
166
+
167
+ // Post journal entry
168
+ await client.accounting.postJournal(journal.data!.id);
169
+
170
+ // Get trial balance
171
+ const trialBalance = await client.accounting.trialBalance('2024-12-31');
172
+ ```
173
+
174
+ ### HR
175
+
176
+ ```typescript
177
+ // List employees
178
+ const employees = await client.hr.employees({ department_id: 1 });
179
+
180
+ // Clock in
181
+ await client.hr.clockIn(employeeId);
182
+
183
+ // Clock out
184
+ await client.hr.clockOut(employeeId);
185
+
186
+ // Approve leave request
187
+ await client.hr.approveLeave(leaveRequestId);
188
+ ```
189
+
190
+ ### CRM
191
+
192
+ ```typescript
193
+ // List leads
194
+ const leads = await client.crm.leads({ status: 'new' });
195
+
196
+ // Create lead
197
+ const lead = await client.crm.createLead({
198
+ name: 'Potential Customer',
199
+ email: 'lead@example.com',
200
+ source: 'website',
201
+ });
202
+
203
+ // Convert lead to customer
204
+ await client.crm.convertLead(lead.data!.id);
205
+
206
+ // Get pipeline
207
+ const pipeline = await client.crm.pipeline();
208
+ ```
209
+
210
+ ### Webhooks
211
+
212
+ ```typescript
213
+ // List webhooks
214
+ const webhooks = await client.webhooks.list();
215
+
216
+ // Create webhook
217
+ const webhook = await client.webhooks.create({
218
+ url: 'https://your-app.com/webhooks/bibike',
219
+ events: ['sale.completed', 'inventory.low_stock'],
220
+ });
221
+
222
+ // The secret is only returned on creation
223
+ console.log('Webhook secret:', webhook.data!.secret);
224
+
225
+ // Test webhook
226
+ await client.webhooks.test(webhook.data!.id);
227
+ ```
228
+
229
+ ### POS & Reports
230
+
231
+ ```typescript
232
+ // Open POS session
233
+ const session = await client.pos.openSession({
234
+ warehouse_id: 1,
235
+ opening_balance: 50000,
236
+ });
237
+
238
+ // Close POS session
239
+ await client.pos.closeSession(session.data!.id, {
240
+ closing_balance: 150000,
241
+ });
242
+
243
+ // Get reports
244
+ const salesReport = await client.reports.sales({
245
+ start_date: '2024-01-01',
246
+ end_date: '2024-12-31',
247
+ group_by: 'month',
248
+ });
249
+
250
+ const inventoryReport = await client.reports.inventory();
251
+ const profitLoss = await client.reports.profitLoss({
252
+ start_date: '2024-01-01',
253
+ end_date: '2024-12-31',
254
+ });
255
+
256
+ const dashboard = await client.reports.dashboard();
257
+ ```
258
+
259
+ ## Error Handling
260
+
261
+ ```typescript
262
+ import { BibikeClient, BibikeApiError } from '@bibike/erp-sdk';
263
+
264
+ try {
265
+ const product = await client.products.get(999);
266
+ } catch (error) {
267
+ if (error instanceof BibikeApiError) {
268
+ console.error('API Error:', error.message);
269
+ console.error('Status Code:', error.statusCode);
270
+ console.error('Error Code:', error.code);
271
+ }
272
+ }
273
+ ```
274
+
275
+ ## Configuration Options
276
+
277
+ ```typescript
278
+ const client = new BibikeClient({
279
+ baseUrl: 'https://bibike.fivorana.com/api.php',
280
+ token: 'your-api-token', // Optional: set token directly
281
+ timeout: 30000, // Request timeout in milliseconds (default: 30000)
282
+ headers: {
283
+ 'X-Custom-Header': 'value', // Custom headers
284
+ },
285
+ });
286
+ ```
287
+
288
+ ## TypeScript Support
289
+
290
+ All types are exported for use in your TypeScript projects:
291
+
292
+ ```typescript
293
+ import type {
294
+ Product,
295
+ Sale,
296
+ Customer,
297
+ PurchaseOrder,
298
+ Employee,
299
+ Lead,
300
+ Opportunity,
301
+ Webhook,
302
+ } from '@bibike/erp-sdk';
303
+
304
+ const products: Product[] = [];
305
+ ```
306
+
307
+ ## API Coverage
308
+
309
+ | Module | Methods |
310
+ |--------|---------|
311
+ | **Authentication** | login, logout, me, setToken |
312
+ | **Products** | list, get, create, update, delete, search |
313
+ | **Inventory** | list, transfers, createTransfer, approveTransfer, adjustments, createAdjustment, lowStock, outOfStock, valuation, movementHistory |
314
+ | **Sales** | list, get, create, quotations, createQuotation, orders, createOrder, analytics |
315
+ | **Customers** | list, get, create, update, delete, balance |
316
+ | **Suppliers** | list, get, create, update, delete |
317
+ | **Purchasing** | orders, getOrder, createOrder, approveOrder, requisitions, createRequisition, analytics |
318
+ | **Accounting** | accounts, getAccount, createAccount, journals, getJournal, createJournal, postJournal, trialBalance, taxRates |
319
+ | **HR** | employees, getEmployee, createEmployee, departments, positions, attendance, clockIn, clockOut, leaveRequests, approveLeave |
320
+ | **CRM** | leads, getLead, createLead, convertLead, opportunities, getOpportunity, createOpportunity, activities, createActivity, pipeline |
321
+ | **Webhooks** | list, get, create, update, delete, logs, test |
322
+ | **POS** | sessions, getSession, openSession, closeSession |
323
+ | **Reports** | sales, inventory, profitLoss, dashboard |
324
+ | **Locations** | warehouses, shops, all |
325
+
326
+ ## License
327
+
328
+ MIT