@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/dist/index.mjs ADDED
@@ -0,0 +1,399 @@
1
+ // src/client.ts
2
+ var BibikeClient = class {
3
+ constructor(config) {
4
+ this.token = null;
5
+ // ============ Products ============
6
+ this.products = {
7
+ list: async (params) => {
8
+ return this.request("products", "list", "GET", void 0, params);
9
+ },
10
+ get: async (id) => {
11
+ return this.request("products", "view", "GET", void 0, { id });
12
+ },
13
+ create: async (data) => {
14
+ return this.request("products", "create", "POST", data);
15
+ },
16
+ update: async (id, data) => {
17
+ return this.request("products", "update", "POST", data, { id });
18
+ },
19
+ delete: async (id) => {
20
+ return this.request("products", "delete", "POST", void 0, { id });
21
+ },
22
+ search: async (query) => {
23
+ return this.request("products", "search", "GET", void 0, { q: query });
24
+ }
25
+ };
26
+ // ============ Inventory ============
27
+ this.inventory = {
28
+ list: async (params) => {
29
+ return this.request("inventory", "list", "GET", void 0, params);
30
+ },
31
+ transfers: async () => {
32
+ return this.request("inventory_extended", "transfers");
33
+ },
34
+ createTransfer: async (data) => {
35
+ return this.request("inventory_extended", "create_transfer", "POST", data);
36
+ },
37
+ approveTransfer: async (id) => {
38
+ return this.request("inventory_extended", "approve_transfer", "POST", void 0, { id });
39
+ },
40
+ adjustments: async () => {
41
+ return this.request("inventory_extended", "adjustments");
42
+ },
43
+ createAdjustment: async (data) => {
44
+ return this.request("inventory_extended", "create_adjustment", "POST", data);
45
+ },
46
+ lowStock: async () => {
47
+ return this.request("inventory_extended", "low_stock");
48
+ },
49
+ outOfStock: async () => {
50
+ return this.request("inventory_extended", "out_of_stock");
51
+ },
52
+ valuation: async () => {
53
+ return this.request("inventory_extended", "valuation");
54
+ },
55
+ movementHistory: async (params) => {
56
+ return this.request("inventory_extended", "movement_history", "GET", void 0, params);
57
+ }
58
+ };
59
+ // ============ Sales ============
60
+ this.sales = {
61
+ list: async (params) => {
62
+ return this.request("sales", "list", "GET", void 0, params);
63
+ },
64
+ get: async (id) => {
65
+ return this.request("sales", "view", "GET", void 0, { id });
66
+ },
67
+ create: async (data) => {
68
+ return this.request("sales", "create", "POST", data);
69
+ },
70
+ quotations: async (params) => {
71
+ return this.request("sales_extended", "quotations", "GET", void 0, params);
72
+ },
73
+ createQuotation: async (data) => {
74
+ return this.request("sales_extended", "create_quotation", "POST", data);
75
+ },
76
+ orders: async (params) => {
77
+ return this.request("sales_extended", "orders", "GET", void 0, params);
78
+ },
79
+ createOrder: async (data) => {
80
+ return this.request("sales_extended", "create_order", "POST", data);
81
+ },
82
+ analytics: async (params) => {
83
+ return this.request("sales_extended", "analytics", "GET", void 0, params);
84
+ }
85
+ };
86
+ // ============ Customers ============
87
+ this.customers = {
88
+ list: async (params) => {
89
+ return this.request("customers", "list", "GET", void 0, params);
90
+ },
91
+ get: async (id) => {
92
+ return this.request("customers", "view", "GET", void 0, { id });
93
+ },
94
+ create: async (data) => {
95
+ return this.request("customers", "create", "POST", data);
96
+ },
97
+ update: async (id, data) => {
98
+ return this.request("customers", "update", "POST", data, { id });
99
+ },
100
+ delete: async (id) => {
101
+ return this.request("customers", "delete", "POST", void 0, { id });
102
+ },
103
+ balance: async (id) => {
104
+ return this.request("customers", "balance", "GET", void 0, { id });
105
+ }
106
+ };
107
+ // ============ Suppliers ============
108
+ this.suppliers = {
109
+ list: async (params) => {
110
+ return this.request("suppliers", "list", "GET", void 0, params);
111
+ },
112
+ get: async (id) => {
113
+ return this.request("suppliers", "view", "GET", void 0, { id });
114
+ },
115
+ create: async (data) => {
116
+ return this.request("suppliers", "create", "POST", data);
117
+ },
118
+ update: async (id, data) => {
119
+ return this.request("suppliers", "update", "POST", data, { id });
120
+ },
121
+ delete: async (id) => {
122
+ return this.request("suppliers", "delete", "POST", void 0, { id });
123
+ }
124
+ };
125
+ // ============ Purchasing ============
126
+ this.purchasing = {
127
+ orders: async (params) => {
128
+ return this.request("purchase_orders", "list", "GET", void 0, params);
129
+ },
130
+ getOrder: async (id) => {
131
+ return this.request("purchase_orders", "view", "GET", void 0, { id });
132
+ },
133
+ createOrder: async (data) => {
134
+ return this.request("purchase_orders", "create", "POST", data);
135
+ },
136
+ approveOrder: async (id) => {
137
+ return this.request("purchase_orders", "approve", "POST", void 0, { id });
138
+ },
139
+ requisitions: async (params) => {
140
+ return this.request("purchasing_extended", "requisitions", "GET", void 0, params);
141
+ },
142
+ createRequisition: async (data) => {
143
+ return this.request("purchasing_extended", "create_requisition", "POST", data);
144
+ },
145
+ analytics: async (params) => {
146
+ return this.request("purchasing_extended", "analytics", "GET", void 0, params);
147
+ }
148
+ };
149
+ // ============ Accounting ============
150
+ this.accounting = {
151
+ accounts: async (params) => {
152
+ return this.request("accounting", "accounts", "GET", void 0, params);
153
+ },
154
+ getAccount: async (id) => {
155
+ return this.request("accounting", "account", "GET", void 0, { id });
156
+ },
157
+ createAccount: async (data) => {
158
+ return this.request("accounting", "create_account", "POST", data);
159
+ },
160
+ journals: async (params) => {
161
+ return this.request("accounting", "journals", "GET", void 0, params);
162
+ },
163
+ getJournal: async (id) => {
164
+ return this.request("accounting", "journal", "GET", void 0, { id });
165
+ },
166
+ createJournal: async (data) => {
167
+ return this.request("accounting", "create_journal", "POST", data);
168
+ },
169
+ postJournal: async (id) => {
170
+ return this.request("accounting", "post_journal", "POST", void 0, { id });
171
+ },
172
+ trialBalance: async (asOfDate) => {
173
+ return this.request("accounting", "trial_balance", "GET", void 0, { as_of_date: asOfDate });
174
+ },
175
+ taxRates: async () => {
176
+ return this.request("accounting", "tax_rates");
177
+ }
178
+ };
179
+ // ============ HR ============
180
+ this.hr = {
181
+ employees: async (params) => {
182
+ return this.request("hr", "employees", "GET", void 0, params);
183
+ },
184
+ getEmployee: async (id) => {
185
+ return this.request("hr", "employee", "GET", void 0, { id });
186
+ },
187
+ createEmployee: async (data) => {
188
+ return this.request("hr", "create_employee", "POST", data);
189
+ },
190
+ departments: async () => {
191
+ return this.request("hr", "departments");
192
+ },
193
+ positions: async () => {
194
+ return this.request("hr", "positions");
195
+ },
196
+ attendance: async (params) => {
197
+ return this.request("hr", "attendance", "GET", void 0, params);
198
+ },
199
+ clockIn: async (employeeId) => {
200
+ return this.request("hr", "clock_in", "POST", { employee_id: employeeId });
201
+ },
202
+ clockOut: async (employeeId) => {
203
+ return this.request("hr", "clock_out", "POST", { employee_id: employeeId });
204
+ },
205
+ leaveRequests: async (params) => {
206
+ return this.request("hr", "leave_requests", "GET", void 0, params);
207
+ },
208
+ approveLeave: async (id) => {
209
+ return this.request("hr", "approve_leave", "POST", void 0, { id });
210
+ }
211
+ };
212
+ // ============ CRM ============
213
+ this.crm = {
214
+ leads: async (params) => {
215
+ return this.request("crm", "leads", "GET", void 0, params);
216
+ },
217
+ getLead: async (id) => {
218
+ return this.request("crm", "lead", "GET", void 0, { id });
219
+ },
220
+ createLead: async (data) => {
221
+ return this.request("crm", "create_lead", "POST", data);
222
+ },
223
+ convertLead: async (id) => {
224
+ return this.request("crm", "convert_lead", "POST", void 0, { id });
225
+ },
226
+ opportunities: async (params) => {
227
+ return this.request("crm", "opportunities", "GET", void 0, params);
228
+ },
229
+ getOpportunity: async (id) => {
230
+ return this.request("crm", "opportunity", "GET", void 0, { id });
231
+ },
232
+ createOpportunity: async (data) => {
233
+ return this.request("crm", "create_opportunity", "POST", data);
234
+ },
235
+ activities: async (params) => {
236
+ return this.request("crm", "activities", "GET", void 0, params);
237
+ },
238
+ createActivity: async (data) => {
239
+ return this.request("crm", "create_activity", "POST", data);
240
+ },
241
+ pipeline: async () => {
242
+ return this.request("crm", "pipeline");
243
+ }
244
+ };
245
+ // ============ Webhooks ============
246
+ this.webhooks = {
247
+ list: async () => {
248
+ return this.request("webhooks", "list");
249
+ },
250
+ get: async (id) => {
251
+ return this.request("webhooks", "view", "GET", void 0, { id });
252
+ },
253
+ create: async (data) => {
254
+ return this.request("webhooks", "create", "POST", data);
255
+ },
256
+ update: async (id, data) => {
257
+ return this.request("webhooks", "update", "POST", data, { id });
258
+ },
259
+ delete: async (id) => {
260
+ return this.request("webhooks", "delete", "POST", void 0, { id });
261
+ },
262
+ logs: async (id) => {
263
+ return this.request("webhooks", "logs", "GET", void 0, { id });
264
+ },
265
+ test: async (id) => {
266
+ return this.request("webhooks", "test", "POST", void 0, { id });
267
+ }
268
+ };
269
+ // ============ POS & Reports ============
270
+ this.pos = {
271
+ sessions: async () => {
272
+ return this.request("pos_reports", "sessions");
273
+ },
274
+ getSession: async (id) => {
275
+ return this.request("pos_reports", "session", "GET", void 0, { id });
276
+ },
277
+ openSession: async (data) => {
278
+ return this.request("pos_reports", "open_session", "POST", data);
279
+ },
280
+ closeSession: async (id, data) => {
281
+ return this.request("pos_reports", "close_session", "POST", data, { id });
282
+ }
283
+ };
284
+ this.reports = {
285
+ sales: async (params) => {
286
+ return this.request("pos_reports", "sales_report", "GET", void 0, params);
287
+ },
288
+ inventory: async () => {
289
+ return this.request("pos_reports", "inventory_report");
290
+ },
291
+ profitLoss: async (params) => {
292
+ return this.request("pos_reports", "profit_loss", "GET", void 0, params);
293
+ },
294
+ dashboard: async () => {
295
+ return this.request("pos_reports", "dashboard_stats");
296
+ }
297
+ };
298
+ // ============ Locations ============
299
+ this.locations = {
300
+ warehouses: async () => {
301
+ return this.request("warehouses", "list");
302
+ },
303
+ shops: async () => {
304
+ return this.request("shops", "list");
305
+ },
306
+ all: async (params) => {
307
+ return this.request("locations", "list", "GET", void 0, params);
308
+ }
309
+ };
310
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
311
+ this.token = config.token || null;
312
+ this.timeout = config.timeout || 3e4;
313
+ this.customHeaders = config.headers || {};
314
+ }
315
+ // ============ Auth ============
316
+ async login(credentials) {
317
+ const response = await this.request("auth", "login", "POST", credentials);
318
+ if (response.data?.token) {
319
+ this.token = response.data.token;
320
+ }
321
+ return response.data;
322
+ }
323
+ async logout() {
324
+ await this.request("auth", "logout", "POST");
325
+ this.token = null;
326
+ }
327
+ async me() {
328
+ const response = await this.request("auth", "me");
329
+ return response.data;
330
+ }
331
+ setToken(token) {
332
+ this.token = token;
333
+ }
334
+ // ============ Core Request Method ============
335
+ async request(resource, action, method = "GET", body, params) {
336
+ const url = new URL(this.baseUrl);
337
+ url.searchParams.set("resource", resource);
338
+ url.searchParams.set("action", action);
339
+ if (params) {
340
+ for (const [key, value] of Object.entries(params)) {
341
+ if (value !== void 0 && value !== null) {
342
+ url.searchParams.set(key, String(value));
343
+ }
344
+ }
345
+ }
346
+ const headers = {
347
+ "Content-Type": "application/json",
348
+ ...this.customHeaders
349
+ };
350
+ if (this.token) {
351
+ headers["Authorization"] = `Bearer ${this.token}`;
352
+ }
353
+ const controller = new AbortController();
354
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
355
+ try {
356
+ const response = await fetch(url.toString(), {
357
+ method,
358
+ headers,
359
+ body: body ? JSON.stringify(body) : void 0,
360
+ signal: controller.signal
361
+ });
362
+ clearTimeout(timeoutId);
363
+ const data = await response.json();
364
+ if (!response.ok) {
365
+ throw new BibikeApiError(
366
+ data.message || data.error || "Request failed",
367
+ response.status,
368
+ data.code
369
+ );
370
+ }
371
+ return data;
372
+ } catch (error) {
373
+ clearTimeout(timeoutId);
374
+ if (error instanceof BibikeApiError) {
375
+ throw error;
376
+ }
377
+ if (error instanceof Error && error.name === "AbortError") {
378
+ throw new BibikeApiError("Request timeout", 408, "TIMEOUT");
379
+ }
380
+ throw new BibikeApiError(
381
+ error instanceof Error ? error.message : "Unknown error",
382
+ 0,
383
+ "NETWORK_ERROR"
384
+ );
385
+ }
386
+ }
387
+ };
388
+ var BibikeApiError = class extends Error {
389
+ constructor(message, statusCode, code) {
390
+ super(message);
391
+ this.statusCode = statusCode;
392
+ this.code = code;
393
+ this.name = "BibikeApiError";
394
+ }
395
+ };
396
+ export {
397
+ BibikeApiError,
398
+ BibikeClient
399
+ };
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@bibike/erp-sdk",
3
+ "version": "1.0.0",
4
+ "description": "TypeScript SDK for Bibike ERP API",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "module": "dist/index.mjs",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsup src/index.ts --format cjs,esm --dts",
21
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
22
+ "lint": "eslint src/",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest",
25
+ "test:integration": "vitest run --config vitest.integration.config.ts",
26
+ "prepublishOnly": "npm run build && npm run test"
27
+ },
28
+ "keywords": [
29
+ "bibike",
30
+ "erp",
31
+ "api",
32
+ "sdk",
33
+ "typescript",
34
+ "inventory",
35
+ "sales",
36
+ "accounting",
37
+ "africa",
38
+ "rwanda"
39
+ ],
40
+ "author": "Bibike ERP <support@bibike.fivorana.com>",
41
+ "license": "MIT",
42
+ "homepage": "https://bibike.fivorana.com",
43
+ "bugs": {
44
+ "url": "https://github.com/nrep/bibike-erp-sdk/issues"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/nrep/bibike-erp-sdk"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^20.10.0",
55
+ "tsup": "^8.0.0",
56
+ "typescript": "^5.3.0",
57
+ "vitest": "^1.0.0"
58
+ },
59
+ "engines": {
60
+ "node": ">=18.0.0"
61
+ }
62
+ }