@classytic/commerce-sdk 0.1.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.

Potentially problematic release.


This version of @classytic/commerce-sdk might be problematic. Click here for more details.

Files changed (131) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +104 -0
  3. package/dist/adjustment-DTSLM7AN.js +5 -0
  4. package/dist/adjustment-DTSLM7AN.js.map +1 -0
  5. package/dist/analytics/index.d.ts +27 -0
  6. package/dist/analytics/index.js +6 -0
  7. package/dist/analytics/index.js.map +1 -0
  8. package/dist/analytics-DMcD-o8w.d.ts +76 -0
  9. package/dist/api-factory-B_h4RKBm.d.ts +280 -0
  10. package/dist/auth/index.d.ts +39 -0
  11. package/dist/auth/index.js +5 -0
  12. package/dist/auth/index.js.map +1 -0
  13. package/dist/catalog/index.d.ts +479 -0
  14. package/dist/catalog/index.js +9 -0
  15. package/dist/catalog/index.js.map +1 -0
  16. package/dist/chunk-4ZQK3FFN.js +40 -0
  17. package/dist/chunk-4ZQK3FFN.js.map +1 -0
  18. package/dist/chunk-5L6EXDGH.js +465 -0
  19. package/dist/chunk-5L6EXDGH.js.map +1 -0
  20. package/dist/chunk-5ZFW3FEI.js +183 -0
  21. package/dist/chunk-5ZFW3FEI.js.map +1 -0
  22. package/dist/chunk-66OQAZSL.js +94 -0
  23. package/dist/chunk-66OQAZSL.js.map +1 -0
  24. package/dist/chunk-6RYGA6MF.js +123 -0
  25. package/dist/chunk-6RYGA6MF.js.map +1 -0
  26. package/dist/chunk-B6MPVOV7.js +328 -0
  27. package/dist/chunk-B6MPVOV7.js.map +1 -0
  28. package/dist/chunk-BDA2WSJA.js +148 -0
  29. package/dist/chunk-BDA2WSJA.js.map +1 -0
  30. package/dist/chunk-EIVYT3HM.js +126 -0
  31. package/dist/chunk-EIVYT3HM.js.map +1 -0
  32. package/dist/chunk-EPQN7ZKZ.js +27 -0
  33. package/dist/chunk-EPQN7ZKZ.js.map +1 -0
  34. package/dist/chunk-FA7QFJ2G.js +177 -0
  35. package/dist/chunk-FA7QFJ2G.js.map +1 -0
  36. package/dist/chunk-I5TIKUIQ.js +261 -0
  37. package/dist/chunk-I5TIKUIQ.js.map +1 -0
  38. package/dist/chunk-ILQUH444.js +135 -0
  39. package/dist/chunk-ILQUH444.js.map +1 -0
  40. package/dist/chunk-IXMWZJLV.js +616 -0
  41. package/dist/chunk-IXMWZJLV.js.map +1 -0
  42. package/dist/chunk-KZIGRIQG.js +75 -0
  43. package/dist/chunk-KZIGRIQG.js.map +1 -0
  44. package/dist/chunk-OF5M6R2S.js +769 -0
  45. package/dist/chunk-OF5M6R2S.js.map +1 -0
  46. package/dist/chunk-PYYLHUV6.js +3 -0
  47. package/dist/chunk-PYYLHUV6.js.map +1 -0
  48. package/dist/chunk-QO5AGZFP.js +159 -0
  49. package/dist/chunk-QO5AGZFP.js.map +1 -0
  50. package/dist/chunk-QUMTBLNE.js +76 -0
  51. package/dist/chunk-QUMTBLNE.js.map +1 -0
  52. package/dist/chunk-R5Z7NYLH.js +126 -0
  53. package/dist/chunk-R5Z7NYLH.js.map +1 -0
  54. package/dist/chunk-SZYWG5IB.js +75 -0
  55. package/dist/chunk-SZYWG5IB.js.map +1 -0
  56. package/dist/chunk-U3XT35GZ.js +202 -0
  57. package/dist/chunk-U3XT35GZ.js.map +1 -0
  58. package/dist/chunk-UGELTUIZ.js +830 -0
  59. package/dist/chunk-UGELTUIZ.js.map +1 -0
  60. package/dist/chunk-VR36QVX2.js +122 -0
  61. package/dist/chunk-VR36QVX2.js.map +1 -0
  62. package/dist/chunk-WUOQK7BO.js +13 -0
  63. package/dist/chunk-WUOQK7BO.js.map +1 -0
  64. package/dist/chunk-X6PV5MHG.js +582 -0
  65. package/dist/chunk-X6PV5MHG.js.map +1 -0
  66. package/dist/chunk-ZWLMFLLH.js +534 -0
  67. package/dist/chunk-ZWLMFLLH.js.map +1 -0
  68. package/dist/content/index.d.ts +309 -0
  69. package/dist/content/index.js +6 -0
  70. package/dist/content/index.js.map +1 -0
  71. package/dist/core/index.d.ts +107 -0
  72. package/dist/core/index.js +5 -0
  73. package/dist/core/index.js.map +1 -0
  74. package/dist/core/react.d.ts +107 -0
  75. package/dist/core/react.js +5 -0
  76. package/dist/core/react.js.map +1 -0
  77. package/dist/coupon-CHFcw7cd.d.ts +632 -0
  78. package/dist/coupon-zGkvO-Xx.d.ts +129 -0
  79. package/dist/crud.factory-DyKaPHcU.d.ts +181 -0
  80. package/dist/finance/index.d.ts +81 -0
  81. package/dist/finance/index.js +5 -0
  82. package/dist/finance/index.js.map +1 -0
  83. package/dist/finance-BJdfKRw0.d.ts +135 -0
  84. package/dist/index.d.ts +31 -0
  85. package/dist/index.js +29 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/inventory/index.d.ts +512 -0
  88. package/dist/inventory/index.js +16 -0
  89. package/dist/inventory/index.js.map +1 -0
  90. package/dist/inventory-DCiIZh8P.d.ts +742 -0
  91. package/dist/logistics/index.d.ts +226 -0
  92. package/dist/logistics/index.js +7 -0
  93. package/dist/logistics/index.js.map +1 -0
  94. package/dist/logistics-V8a9lUN3.d.ts +428 -0
  95. package/dist/media-CNLJK93J.d.ts +721 -0
  96. package/dist/movement-7MV3ADY5.js +5 -0
  97. package/dist/movement-7MV3ADY5.js.map +1 -0
  98. package/dist/payment-BRboLqvU.d.ts +127 -0
  99. package/dist/payments/index.d.ts +55 -0
  100. package/dist/payments/index.js +6 -0
  101. package/dist/payments/index.js.map +1 -0
  102. package/dist/platform/index.d.ts +645 -0
  103. package/dist/platform/index.js +8 -0
  104. package/dist/platform/index.js.map +1 -0
  105. package/dist/pos-D1jkkFl0.d.ts +885 -0
  106. package/dist/product-p09zXkXB.d.ts +260 -0
  107. package/dist/purchase-24BGT2HA.js +5 -0
  108. package/dist/purchase-24BGT2HA.js.map +1 -0
  109. package/dist/request-652PS6VR.js +5 -0
  110. package/dist/request-652PS6VR.js.map +1 -0
  111. package/dist/sales/index.d.ts +585 -0
  112. package/dist/sales/index.js +9 -0
  113. package/dist/sales/index.js.map +1 -0
  114. package/dist/server.d.ts +120 -0
  115. package/dist/server.js +27 -0
  116. package/dist/server.js.map +1 -0
  117. package/dist/size-guide-DgjzjM5P.d.ts +554 -0
  118. package/dist/stock-DEApGC-w.d.ts +632 -0
  119. package/dist/stock-OOUW57VQ.js +5 -0
  120. package/dist/stock-OOUW57VQ.js.map +1 -0
  121. package/dist/supplier-OC6JAWV6.js +5 -0
  122. package/dist/supplier-OC6JAWV6.js.map +1 -0
  123. package/dist/transaction/index.d.ts +104 -0
  124. package/dist/transaction/index.js +8 -0
  125. package/dist/transaction/index.js.map +1 -0
  126. package/dist/transaction-BTmoHpWh.d.ts +428 -0
  127. package/dist/transaction-u5oaNuav.d.ts +84 -0
  128. package/dist/transfer-7SYSH3RG.js +5 -0
  129. package/dist/transfer-7SYSH3RG.js.map +1 -0
  130. package/dist/user-data-DdLjAGwO.d.ts +132 -0
  131. package/package.json +146 -0
@@ -0,0 +1,769 @@
1
+ import { BaseApi } from './chunk-I5TIKUIQ.js';
2
+ import { createQueryKeys, createCrudHooks } from './chunk-B6MPVOV7.js';
3
+ import { getToastHandler } from './chunk-U3XT35GZ.js';
4
+ import { handleApiRequest } from './chunk-VR36QVX2.js';
5
+ import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
6
+
7
+ // src/platform/api/config.ts
8
+ var PlatformConfigApi = class {
9
+ constructor() {
10
+ this.baseUrl = "/api/v1/platform";
11
+ }
12
+ /**
13
+ * Get platform configuration
14
+ *
15
+ * @param options.token - Optional access token (public without, authenticated with)
16
+ * @param options.select - Optional field selection (e.g., "paymentMethods", "checkout,vat")
17
+ * @returns Platform configuration (full or selected fields)
18
+ *
19
+ * @example
20
+ * // Full config (public)
21
+ * const config = await platformConfigApi.getConfig({});
22
+ *
23
+ * // Selected fields (public)
24
+ * const config = await platformConfigApi.getConfig({ select: "paymentMethods" });
25
+ *
26
+ * // Authenticated (admin sees more fields)
27
+ * const config = await platformConfigApi.getConfig({ token, select: "checkout,vat" });
28
+ */
29
+ async getConfig({
30
+ token,
31
+ select
32
+ } = {}) {
33
+ const queryParams = select ? `?select=${select}` : "";
34
+ return handleApiRequest("GET", `${this.baseUrl}/config${queryParams}`, {
35
+ token: token ?? void 0,
36
+ cache: token ? "no-store" : "force-cache",
37
+ revalidate: token ? void 0 : 3600,
38
+ // 1 hour for public
39
+ tags: ["platform-config"]
40
+ });
41
+ }
42
+ /**
43
+ * Update platform configuration
44
+ *
45
+ * @param options.token - Admin access token (required)
46
+ * @param options.data - Configuration data to update (partial update)
47
+ * @returns Updated platform configuration
48
+ *
49
+ * @example
50
+ * // Update payment methods
51
+ * await platformConfigApi.updateConfig({
52
+ * token,
53
+ * data: {
54
+ * paymentMethods: [
55
+ * { type: 'cash', name: 'Cash on Delivery', isActive: true },
56
+ * { type: 'mfs', provider: 'bkash', name: 'bKash', walletNumber: '01712345678' },
57
+ * ]
58
+ * }
59
+ * });
60
+ *
61
+ * // Update checkout settings
62
+ * await platformConfigApi.updateConfig({
63
+ * token,
64
+ * data: {
65
+ * checkout: {
66
+ * freeDeliveryThreshold: 2000,
67
+ * deliveryZones: [
68
+ * { name: 'Dhaka', region: 'dhaka', price: 60, estimatedDays: 2, isActive: true }
69
+ * ]
70
+ * }
71
+ * }
72
+ * });
73
+ */
74
+ async updateConfig({
75
+ token,
76
+ data
77
+ }) {
78
+ if (!token) {
79
+ throw new Error("Authentication required to update platform config");
80
+ }
81
+ return handleApiRequest("PATCH", `${this.baseUrl}/config`, {
82
+ token,
83
+ body: data,
84
+ tags: ["platform-config"]
85
+ });
86
+ }
87
+ /**
88
+ * Get payment methods only
89
+ * Convenience method for checkout/POS
90
+ *
91
+ * @param options.token - Optional access token
92
+ * @returns Platform config with only paymentMethods field
93
+ */
94
+ async getPaymentMethods({
95
+ token
96
+ } = {}) {
97
+ return this.getConfig({ token, select: "paymentMethods" });
98
+ }
99
+ /**
100
+ * Get checkout settings only
101
+ * Convenience method for checkout flow
102
+ *
103
+ * @param options.token - Optional access token
104
+ * @returns Platform config with only checkout field
105
+ */
106
+ async getCheckoutSettings({
107
+ token
108
+ } = {}) {
109
+ return this.getConfig({ token, select: "checkout" });
110
+ }
111
+ /**
112
+ * Get delivery zones
113
+ * Convenience method for delivery selection
114
+ *
115
+ * @param options.token - Optional access token
116
+ * @returns Platform config with checkout.deliveryZones
117
+ */
118
+ async getDeliveryZones({
119
+ token
120
+ } = {}) {
121
+ return this.getConfig({ token, select: "checkout" });
122
+ }
123
+ /**
124
+ * Get VAT configuration
125
+ * Convenience method for invoice/tax calculations
126
+ *
127
+ * @param options.token - Optional access token
128
+ * @returns Platform config with only vat field
129
+ */
130
+ async getVatConfig({
131
+ token
132
+ } = {}) {
133
+ return this.getConfig({ token, select: "vat" });
134
+ }
135
+ /**
136
+ * Get membership configuration
137
+ * Convenience method for loyalty programs
138
+ *
139
+ * @param options.token - Optional access token
140
+ * @returns Platform config with only membership field
141
+ */
142
+ async getMembershipConfig({
143
+ token
144
+ } = {}) {
145
+ return this.getConfig({ token, select: "membership" });
146
+ }
147
+ };
148
+ var platformConfigApi = new PlatformConfigApi();
149
+ var platformApi = platformConfigApi;
150
+ var businessApi = platformConfigApi;
151
+
152
+ // src/platform/api/branch.ts
153
+ var BranchApi = class extends BaseApi {
154
+ constructor(config = {}) {
155
+ super("branches", config);
156
+ }
157
+ /**
158
+ * Get branch by code
159
+ * GET /branches/code/:code
160
+ *
161
+ * @example
162
+ * branchApi.getByCode({ token, code: 'DHK-1' })
163
+ */
164
+ async getByCode({
165
+ token,
166
+ code,
167
+ options = {}
168
+ }) {
169
+ if (!code) {
170
+ throw new Error("Branch code is required");
171
+ }
172
+ return handleApiRequest("GET", `${this.baseUrl}/code/${code}`, {
173
+ token,
174
+ cache: this.config.cache,
175
+ ...options
176
+ });
177
+ }
178
+ /**
179
+ * Get default branch (auto-creates if none exists)
180
+ * GET /branches/default
181
+ *
182
+ * @example
183
+ * branchApi.getDefault({ token })
184
+ */
185
+ async getDefault({
186
+ token,
187
+ options = {}
188
+ }) {
189
+ return handleApiRequest("GET", `${this.baseUrl}/default`, {
190
+ token,
191
+ cache: this.config.cache,
192
+ ...options
193
+ });
194
+ }
195
+ // For active branches, use: getAll({ token, params: { isActive: true } })
196
+ /**
197
+ * Set a branch as the default
198
+ * POST /branches/:id/set-default
199
+ *
200
+ * @example
201
+ * branchApi.setDefault({ token, id: '507f1f77bcf86cd799439011' })
202
+ */
203
+ async setDefault({
204
+ token,
205
+ id,
206
+ options = {}
207
+ }) {
208
+ if (!id) {
209
+ throw new Error("Branch ID is required");
210
+ }
211
+ return handleApiRequest("POST", `${this.baseUrl}/${id}/set-default`, {
212
+ token,
213
+ ...options
214
+ });
215
+ }
216
+ };
217
+ var branchApi = new BranchApi();
218
+
219
+ // src/platform/api/user.ts
220
+ var UserApi = class extends BaseApi {
221
+ constructor(config = {}) {
222
+ super("users", config);
223
+ }
224
+ };
225
+ var userApi = new UserApi();
226
+
227
+ // src/platform/api/coupon.ts
228
+ var CouponApi = class extends BaseApi {
229
+ constructor(config = {}) {
230
+ super("coupons", config);
231
+ }
232
+ /**
233
+ * Validate coupon by code with order amount
234
+ * POST /coupons/validate/:code
235
+ *
236
+ * @example
237
+ * const result = await couponApi.validateCoupon({
238
+ * code: 'SUMMER20',
239
+ * data: { orderAmount: 1500 }
240
+ * });
241
+ *
242
+ * if (result.data?.valid) {
243
+ * console.log('Discount:', result.data.discountAmount);
244
+ * }
245
+ */
246
+ async validateCoupon({
247
+ code,
248
+ data,
249
+ options = {}
250
+ }) {
251
+ return handleApiRequest("POST", `${this.baseUrl}/validate/${code}`, {
252
+ cache: this.config.cache,
253
+ body: data,
254
+ ...options
255
+ });
256
+ }
257
+ };
258
+ var couponApi = new CouponApi();
259
+
260
+ // src/platform/api/webhook.ts
261
+ var WebhookApi = class {
262
+ constructor() {
263
+ this.baseUrl = "/webhooks/payments";
264
+ }
265
+ /**
266
+ * Verify a manual payment (superadmin only)
267
+ * POST /webhooks/payments/manual/verify
268
+ *
269
+ * Flow:
270
+ * 1. Customer places order with manual payment (cash, bKash, Nagad, bank)
271
+ * 2. Customer pays and provides transaction reference
272
+ * 3. Admin verifies payment via this endpoint
273
+ * 4. Transaction status -> 'verified'
274
+ * 5. Order payment status -> 'verified', order status -> 'confirmed'
275
+ *
276
+ * @param params.transactionId - Transaction ID to verify
277
+ * @param params.notes - Optional verification notes
278
+ * @param params.token - Auth token (superadmin required)
279
+ * @param params.options - Additional fetch options
280
+ * @returns Verification result with transaction details
281
+ *
282
+ * @example
283
+ * ```typescript
284
+ * const result = await webhookApi.verifyPayment({
285
+ * token: adminToken,
286
+ * transactionId: '507f1f77bcf86cd799439011',
287
+ * notes: 'Verified bKash TrxID via app',
288
+ * });
289
+ * ```
290
+ */
291
+ async verifyPayment({
292
+ token,
293
+ transactionId,
294
+ notes,
295
+ options = {}
296
+ }) {
297
+ if (!transactionId) throw new Error("Transaction ID is required");
298
+ if (!token) throw new Error("Authentication required");
299
+ const body = { transactionId };
300
+ if (notes) body.notes = notes;
301
+ return handleApiRequest("POST", `${this.baseUrl}/manual/verify`, {
302
+ token,
303
+ body,
304
+ cache: "no-store",
305
+ ...options
306
+ });
307
+ }
308
+ /**
309
+ * Reject a manual payment (superadmin only)
310
+ * POST /webhooks/payments/manual/reject
311
+ *
312
+ * Flow:
313
+ * 1. Customer claims to have paid but admin finds issue
314
+ * 2. Admin rejects payment with reason via this endpoint
315
+ * 3. Transaction status -> 'failed', failureReason recorded
316
+ * 4. Order payment status -> 'failed'
317
+ *
318
+ * Common rejection reasons:
319
+ * - Invalid transaction reference
320
+ * - Amount mismatch
321
+ * - Duplicate claim
322
+ * - Suspected fraud
323
+ * - Payment not received
324
+ *
325
+ * @param params.transactionId - Transaction ID to reject
326
+ * @param params.reason - Rejection reason (required)
327
+ * @param params.token - Auth token (superadmin required)
328
+ * @param params.options - Additional fetch options
329
+ * @returns Rejection result with failure details
330
+ *
331
+ * @example
332
+ * ```typescript
333
+ * const result = await webhookApi.rejectPayment({
334
+ * token: adminToken,
335
+ * transactionId: '507f1f77bcf86cd799439011',
336
+ * reason: 'Invalid bKash TrxID - no matching transaction found',
337
+ * });
338
+ * ```
339
+ */
340
+ async rejectPayment({
341
+ token,
342
+ transactionId,
343
+ reason,
344
+ options = {}
345
+ }) {
346
+ if (!transactionId) throw new Error("Transaction ID is required");
347
+ if (!reason) throw new Error("Rejection reason is required");
348
+ if (!token) throw new Error("Authentication required");
349
+ const body = { transactionId, reason };
350
+ return handleApiRequest("POST", `${this.baseUrl}/manual/reject`, {
351
+ token,
352
+ body,
353
+ cache: "no-store",
354
+ ...options
355
+ });
356
+ }
357
+ /**
358
+ * Alias for verifyPayment - more explicit naming
359
+ * @deprecated Use verifyPayment instead
360
+ */
361
+ async verifyManualPayment(params) {
362
+ return this.verifyPayment(params);
363
+ }
364
+ /**
365
+ * Alias for rejectPayment - more explicit naming
366
+ * @deprecated Use rejectPayment instead
367
+ */
368
+ async rejectManualPayment(params) {
369
+ return this.rejectPayment(params);
370
+ }
371
+ };
372
+ var webhookApi = new WebhookApi();
373
+
374
+ // src/platform/api/export.ts
375
+ var ExportApi = class {
376
+ constructor() {
377
+ this.basePath = "/api/v1/export";
378
+ }
379
+ /**
380
+ * Build query string from export parameters
381
+ */
382
+ buildQueryString(params) {
383
+ const searchParams = new URLSearchParams();
384
+ if (params.select) {
385
+ searchParams.append("select", params.select);
386
+ }
387
+ if (params.filter) {
388
+ const filterString = typeof params.filter === "string" ? params.filter : JSON.stringify(params.filter);
389
+ searchParams.append("filter", filterString);
390
+ }
391
+ return searchParams.toString();
392
+ }
393
+ /**
394
+ * Export data to CSV format
395
+ * GET /export/csv
396
+ *
397
+ * Returns CSV file as blob for download or processing.
398
+ *
399
+ * @example
400
+ * // Export all products
401
+ * const blob = await exportApi.toCSV({ token, collection: 'product' });
402
+ *
403
+ * // Export filtered transactions
404
+ * const blob = await exportApi.toCSV({
405
+ * token,
406
+ * collection: 'transaction',
407
+ * filter: { status: 'verified' },
408
+ * select: 'amount,method,status,createdAt'
409
+ * });
410
+ */
411
+ async toCSV({
412
+ token,
413
+ collection,
414
+ filter,
415
+ select,
416
+ options = {}
417
+ }) {
418
+ const params = this.buildQueryString({ filter, select });
419
+ const url = `${this.basePath}/csv?collection=${collection}${params ? `&${params}` : ""}`;
420
+ const response = await handleApiRequest("GET", url, {
421
+ token,
422
+ cache: "no-store",
423
+ ...options
424
+ });
425
+ return response.data;
426
+ }
427
+ /**
428
+ * Export data to XLSX (Excel) format
429
+ * GET /export/xlsx
430
+ *
431
+ * Returns Excel file as blob for download or processing.
432
+ *
433
+ * @example
434
+ * // Export stock movements
435
+ * const blob = await exportApi.toXLSX({
436
+ * token,
437
+ * collection: 'stockMovement',
438
+ * filter: { type: 'sale', createdAt: { $gte: '2024-01-01' } }
439
+ * });
440
+ */
441
+ async toXLSX({
442
+ token,
443
+ collection,
444
+ filter,
445
+ select,
446
+ options = {}
447
+ }) {
448
+ const params = this.buildQueryString({ filter, select });
449
+ const url = `${this.basePath}/xlsx?collection=${collection}${params ? `&${params}` : ""}`;
450
+ const response = await handleApiRequest("GET", url, {
451
+ token,
452
+ cache: "no-store",
453
+ ...options
454
+ });
455
+ return response.data;
456
+ }
457
+ /**
458
+ * Export data with specified format
459
+ * Convenience method for format-agnostic exports
460
+ *
461
+ * @example
462
+ * const format = userPreference.exportFormat; // 'csv' | 'xlsx'
463
+ * const blob = await exportApi.export({
464
+ * token,
465
+ * format,
466
+ * collection: 'customer',
467
+ * select: 'name,phone,email'
468
+ * });
469
+ */
470
+ async export({
471
+ token,
472
+ format,
473
+ collection,
474
+ filter,
475
+ select,
476
+ options = {}
477
+ }) {
478
+ if (format === "csv") {
479
+ return this.toCSV({ token, collection, filter, select, options });
480
+ } else {
481
+ return this.toXLSX({ token, collection, filter, select, options });
482
+ }
483
+ }
484
+ /**
485
+ * Trigger browser download of blob
486
+ * Creates temporary link and clicks it to download file
487
+ *
488
+ * @example
489
+ * const blob = await exportApi.toCSV({ token, collection: 'product' });
490
+ * exportApi.downloadFile(blob, 'products.csv');
491
+ */
492
+ downloadFile(blob, filename) {
493
+ const url = window.URL.createObjectURL(blob);
494
+ const link = document.createElement("a");
495
+ link.href = url;
496
+ link.download = filename;
497
+ document.body.appendChild(link);
498
+ link.click();
499
+ document.body.removeChild(link);
500
+ window.URL.revokeObjectURL(url);
501
+ }
502
+ /**
503
+ * Get suggested filename based on collection and format
504
+ *
505
+ * @example
506
+ * const filename = exportApi.getSuggestedFilename('product', 'csv');
507
+ * // Returns: 'products-2024-12-11.csv'
508
+ */
509
+ getSuggestedFilename(collection, format) {
510
+ const date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
511
+ const collectionPlural = collection.endsWith("y") ? collection.slice(0, -1) + "ies" : collection + "s";
512
+ return `${collectionPlural}-${date}.${format}`;
513
+ }
514
+ };
515
+ var exportApi = new ExportApi();
516
+ async function exportAndDownload({
517
+ token,
518
+ format,
519
+ collection,
520
+ filter,
521
+ select,
522
+ filename
523
+ }) {
524
+ const blob = await exportApi.export({ token, format, collection, filter, select });
525
+ const finalFilename = filename || exportApi.getSuggestedFilename(collection, format);
526
+ exportApi.downloadFile(blob, finalFilename);
527
+ }
528
+ async function readCSVBlob(blob) {
529
+ return blob.text();
530
+ }
531
+ function parseCSV(csvText) {
532
+ const lines = csvText.trim().split("\n");
533
+ if (lines.length < 2) return [];
534
+ const headers = lines[0].split(",").map((h) => h.trim());
535
+ const data = [];
536
+ for (let i = 1; i < lines.length; i++) {
537
+ const values = lines[i].split(",").map((v) => v.trim());
538
+ const row = {};
539
+ headers.forEach((header, index) => {
540
+ row[header] = values[index] || "";
541
+ });
542
+ data.push(row);
543
+ }
544
+ return data;
545
+ }
546
+ var ExportFilters = {
547
+ /** Orders by date range */
548
+ ordersByDateRange: (startDate, endDate) => ({
549
+ createdAt: { $gte: startDate, $lte: endDate }
550
+ }),
551
+ /** Orders by status */
552
+ ordersByStatus: (status) => Array.isArray(status) ? { status: { $in: status } } : { status },
553
+ /** Transactions by date and status */
554
+ transactionsByDate: (startDate, endDate, status) => ({
555
+ transactionDate: { $gte: startDate, $lte: endDate },
556
+ ...status && { status }
557
+ }),
558
+ /** Stock movements by type and date */
559
+ movementsByType: (type, startDate, endDate) => ({
560
+ type,
561
+ ...startDate && endDate && { createdAt: { $gte: startDate, $lte: endDate } }
562
+ }),
563
+ /** Products by category */
564
+ productsByCategory: (category) => Array.isArray(category) ? { category: { $in: category } } : { category },
565
+ /** Customers with orders */
566
+ customersWithOrders: () => ({
567
+ "stats.totalOrders": { $gt: 0 }
568
+ })
569
+ };
570
+ var ExportFields = {
571
+ /** Product essentials */
572
+ productBasic: "name,sku,basePrice,quantity,category",
573
+ productFull: "name,sku,barcode,basePrice,costPrice,quantity,category,isActive",
574
+ /** Order essentials */
575
+ orderBasic: "orderNumber,customer,status,totalAmount,createdAt",
576
+ orderFull: "orderNumber,customer,items,totalAmount,status,paymentStatus,deliveryMethod,createdAt",
577
+ /** Customer essentials */
578
+ customerBasic: "name,phone,email",
579
+ customerFull: "name,phone,email,stats,addresses,createdAt",
580
+ /** Transaction essentials */
581
+ transactionBasic: "amount,method,status,transactionDate",
582
+ transactionFull: "amount,type,method,status,referenceModel,referenceId,transactionDate",
583
+ /** Stock essentials */
584
+ stockBasic: "product,branch,quantity,reorderPoint",
585
+ stockFull: "product,variantSku,branch,quantity,reservedQuantity,costPrice,reorderPoint",
586
+ /** Movement essentials */
587
+ movementBasic: "product,branch,type,quantity,balanceAfter,createdAt",
588
+ movementFull: "product,variantSku,branch,type,quantity,balanceAfter,costPerUnit,reference,actor,createdAt"
589
+ };
590
+
591
+ // src/platform/types/branch.ts
592
+ function isHeadOffice(branch) {
593
+ return branch.role === "head_office";
594
+ }
595
+ function isSubBranch(branch) {
596
+ return branch.role === "sub_branch";
597
+ }
598
+ var PLATFORM_KEYS = createQueryKeys("platform-config");
599
+ function usePlatformConfig(token = null, select = null) {
600
+ const queryResult = useQuery({
601
+ queryKey: [...PLATFORM_KEYS.all, select],
602
+ queryFn: async () => {
603
+ const response = await platformConfigApi.getConfig({ token, select });
604
+ if (response.success && response.data) {
605
+ return response.data;
606
+ }
607
+ throw new Error(response.message || "Failed to fetch platform config");
608
+ },
609
+ staleTime: token ? 0 : 5 * 60 * 1e3,
610
+ // 5 minutes for public, 0 for authenticated
611
+ gcTime: 10 * 60 * 1e3
612
+ // 10 minutes
613
+ });
614
+ return {
615
+ config: queryResult.data,
616
+ isLoading: queryResult.isLoading,
617
+ isError: queryResult.isError,
618
+ error: queryResult.error,
619
+ refetch: queryResult.refetch
620
+ };
621
+ }
622
+ function useUpdatePlatformConfig(token) {
623
+ const queryClient = useQueryClient();
624
+ const toast = getToastHandler();
625
+ const mutation = useMutation({
626
+ mutationFn: async (data) => {
627
+ if (!token) {
628
+ throw new Error("Authentication required");
629
+ }
630
+ const response = await platformConfigApi.updateConfig({ token, data });
631
+ if (response.success) {
632
+ return response.data;
633
+ }
634
+ throw new Error(response.message || "Failed to update platform config");
635
+ },
636
+ onSuccess: () => {
637
+ queryClient.invalidateQueries({ queryKey: PLATFORM_KEYS.all });
638
+ toast.success("Configuration updated successfully");
639
+ },
640
+ onError: (error) => {
641
+ toast.error(error.message || "Failed to update configuration");
642
+ }
643
+ });
644
+ return {
645
+ updateConfig: mutation.mutateAsync,
646
+ isUpdating: mutation.isPending,
647
+ error: mutation.error
648
+ };
649
+ }
650
+ function usePaymentMethods(token = null) {
651
+ const queryResult = useQuery({
652
+ queryKey: [...PLATFORM_KEYS.all, "paymentMethods"],
653
+ queryFn: async () => {
654
+ const response = await platformConfigApi.getPaymentMethods({ token });
655
+ if (response.success) {
656
+ return response.data?.paymentMethods || [];
657
+ }
658
+ throw new Error(response.message || "Failed to fetch payment methods");
659
+ },
660
+ staleTime: 5 * 60 * 1e3,
661
+ gcTime: 10 * 60 * 1e3
662
+ });
663
+ return {
664
+ paymentMethods: queryResult.data || [],
665
+ isLoading: queryResult.isLoading,
666
+ isError: queryResult.isError,
667
+ error: queryResult.error,
668
+ refetch: queryResult.refetch
669
+ };
670
+ }
671
+ function useDeliveryZones(token = null) {
672
+ const queryResult = useQuery({
673
+ queryKey: [...PLATFORM_KEYS.all, "checkout"],
674
+ queryFn: async () => {
675
+ const response = await platformConfigApi.getCheckoutSettings({ token });
676
+ if (response.success) {
677
+ return response.data?.checkout || {};
678
+ }
679
+ throw new Error(response.message || "Failed to fetch checkout settings");
680
+ },
681
+ staleTime: 5 * 60 * 1e3,
682
+ gcTime: 10 * 60 * 1e3
683
+ });
684
+ const checkout = queryResult.data;
685
+ return {
686
+ deliveryZones: checkout?.deliveryZones || [],
687
+ freeDeliveryThreshold: checkout?.freeDeliveryThreshold || 0,
688
+ allowStorePickup: checkout?.allowStorePickup || false,
689
+ pickupBranches: checkout?.pickupBranches || [],
690
+ isLoading: queryResult.isLoading,
691
+ isError: queryResult.isError,
692
+ error: queryResult.error,
693
+ refetch: queryResult.refetch
694
+ };
695
+ }
696
+ function useMembershipConfig(token = null) {
697
+ const queryResult = useQuery({
698
+ queryKey: [...PLATFORM_KEYS.all, "membership"],
699
+ queryFn: async () => {
700
+ const response = await platformConfigApi.getMembershipConfig({ token });
701
+ if (response.success) {
702
+ return response.data?.membership || null;
703
+ }
704
+ throw new Error(response.message || "Failed to fetch membership config");
705
+ },
706
+ staleTime: 5 * 60 * 1e3,
707
+ gcTime: 10 * 60 * 1e3
708
+ });
709
+ return {
710
+ membership: queryResult.data,
711
+ isLoading: queryResult.isLoading,
712
+ isError: queryResult.isError,
713
+ error: queryResult.error,
714
+ refetch: queryResult.refetch
715
+ };
716
+ }
717
+
718
+ // src/platform/hooks/branch.ts
719
+ var branchHooks = createCrudHooks({
720
+ api: branchApi,
721
+ entityKey: "branches",
722
+ singular: "Branch",
723
+ plural: "Branches",
724
+ defaults: {
725
+ staleTime: 15 * 60 * 1e3
726
+ // 15 minutes (branches rarely change)
727
+ }
728
+ });
729
+ var {
730
+ KEYS: BRANCH_KEYS,
731
+ useList: useBranches,
732
+ useDetail: useBranchDetail,
733
+ useActions: useBranchActions,
734
+ useNavigation: useBranchNavigation
735
+ } = branchHooks;
736
+
737
+ // src/platform/hooks/user.ts
738
+ var userHooks = createCrudHooks({
739
+ api: userApi,
740
+ entityKey: "users",
741
+ singular: "User",
742
+ plural: "Users"
743
+ });
744
+ var {
745
+ KEYS: USER_KEYS,
746
+ useList: useUsers,
747
+ useDetail: useUserDetail,
748
+ useActions: useUserActions,
749
+ useNavigation: useUserNavigation
750
+ } = userHooks;
751
+
752
+ // src/platform/hooks/coupon.ts
753
+ var couponHooks = createCrudHooks({
754
+ api: couponApi,
755
+ entityKey: "coupons",
756
+ singular: "Coupon",
757
+ plural: "Coupons"
758
+ });
759
+ var {
760
+ KEYS: COUPON_KEYS,
761
+ useList: useCoupons,
762
+ useDetail: useCouponDetail,
763
+ useActions: useCouponActions,
764
+ useNavigation: useCouponNavigation
765
+ } = couponHooks;
766
+
767
+ export { BRANCH_KEYS, BranchApi, COUPON_KEYS, CouponApi, ExportApi, ExportFields, ExportFilters, PLATFORM_KEYS, PlatformConfigApi, USER_KEYS, UserApi, WebhookApi, branchApi, branchHooks, businessApi, couponApi, couponHooks, exportAndDownload, exportApi, isHeadOffice, isSubBranch, parseCSV, platformApi, platformConfigApi, readCSVBlob, useBranchActions, useBranchDetail, useBranchNavigation, useBranches, useCouponActions, useCouponDetail, useCouponNavigation, useCoupons, useDeliveryZones, useMembershipConfig, usePaymentMethods, usePlatformConfig, useUpdatePlatformConfig, useUserActions, useUserDetail, useUserNavigation, useUsers, userApi, userHooks, webhookApi };
768
+ //# sourceMappingURL=chunk-OF5M6R2S.js.map
769
+ //# sourceMappingURL=chunk-OF5M6R2S.js.map