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