@classytic/commerce-sdk 0.1.1

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.
Files changed (133) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +164 -0
  3. package/dist/adjustment-MNH3AT6S.js +5 -0
  4. package/dist/adjustment-MNH3AT6S.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 +571 -0
  14. package/dist/catalog/index.js +9 -0
  15. package/dist/catalog/index.js.map +1 -0
  16. package/dist/chunk-24FDD6UR.js +75 -0
  17. package/dist/chunk-24FDD6UR.js.map +1 -0
  18. package/dist/chunk-2TF7QNYV.js +159 -0
  19. package/dist/chunk-2TF7QNYV.js.map +1 -0
  20. package/dist/chunk-2YAZ5WG6.js +479 -0
  21. package/dist/chunk-2YAZ5WG6.js.map +1 -0
  22. package/dist/chunk-36NLLAVH.js +177 -0
  23. package/dist/chunk-36NLLAVH.js.map +1 -0
  24. package/dist/chunk-3OYSJB3P.js +126 -0
  25. package/dist/chunk-3OYSJB3P.js.map +1 -0
  26. package/dist/chunk-5E57JODA.js +135 -0
  27. package/dist/chunk-5E57JODA.js.map +1 -0
  28. package/dist/chunk-7LZCW4VF.js +13 -0
  29. package/dist/chunk-7LZCW4VF.js.map +1 -0
  30. package/dist/chunk-ANYGZ6O5.js +830 -0
  31. package/dist/chunk-ANYGZ6O5.js.map +1 -0
  32. package/dist/chunk-AQAISI4F.js +183 -0
  33. package/dist/chunk-AQAISI4F.js.map +1 -0
  34. package/dist/chunk-B6MPVOV7.js +328 -0
  35. package/dist/chunk-B6MPVOV7.js.map +1 -0
  36. package/dist/chunk-CILP56G2.js +94 -0
  37. package/dist/chunk-CILP56G2.js.map +1 -0
  38. package/dist/chunk-ERQ52WHY.js +534 -0
  39. package/dist/chunk-ERQ52WHY.js.map +1 -0
  40. package/dist/chunk-FOTUJPM4.js +640 -0
  41. package/dist/chunk-FOTUJPM4.js.map +1 -0
  42. package/dist/chunk-IHCBBLLW.js +198 -0
  43. package/dist/chunk-IHCBBLLW.js.map +1 -0
  44. package/dist/chunk-J4JBQET2.js +76 -0
  45. package/dist/chunk-J4JBQET2.js.map +1 -0
  46. package/dist/chunk-L4OEI4VZ.js +123 -0
  47. package/dist/chunk-L4OEI4VZ.js.map +1 -0
  48. package/dist/chunk-LRV7MWWX.js +616 -0
  49. package/dist/chunk-LRV7MWWX.js.map +1 -0
  50. package/dist/chunk-N43VE355.js +126 -0
  51. package/dist/chunk-N43VE355.js.map +1 -0
  52. package/dist/chunk-PYYLHUV6.js +3 -0
  53. package/dist/chunk-PYYLHUV6.js.map +1 -0
  54. package/dist/chunk-QCTXAMLA.js +261 -0
  55. package/dist/chunk-QCTXAMLA.js.map +1 -0
  56. package/dist/chunk-RIKAPJNG.js +40 -0
  57. package/dist/chunk-RIKAPJNG.js.map +1 -0
  58. package/dist/chunk-U3XT35GZ.js +202 -0
  59. package/dist/chunk-U3XT35GZ.js.map +1 -0
  60. package/dist/chunk-W22WB3WZ.js +148 -0
  61. package/dist/chunk-W22WB3WZ.js.map +1 -0
  62. package/dist/chunk-WTIJMKML.js +27 -0
  63. package/dist/chunk-WTIJMKML.js.map +1 -0
  64. package/dist/chunk-X2CQFJPR.js +75 -0
  65. package/dist/chunk-X2CQFJPR.js.map +1 -0
  66. package/dist/chunk-YYFKLOKO.js +769 -0
  67. package/dist/chunk-YYFKLOKO.js.map +1 -0
  68. package/dist/client-Cs7E_usr.d.ts +113 -0
  69. package/dist/content/index.d.ts +309 -0
  70. package/dist/content/index.js +6 -0
  71. package/dist/content/index.js.map +1 -0
  72. package/dist/core/index.d.ts +166 -0
  73. package/dist/core/index.js +5 -0
  74. package/dist/core/index.js.map +1 -0
  75. package/dist/core/react.d.ts +107 -0
  76. package/dist/core/react.js +5 -0
  77. package/dist/core/react.js.map +1 -0
  78. package/dist/coupon-BZSZ0y3n.d.ts +129 -0
  79. package/dist/coupon-CDzL4bJG.d.ts +655 -0
  80. package/dist/crud.factory-DyKaPHcU.d.ts +181 -0
  81. package/dist/finance/index.d.ts +81 -0
  82. package/dist/finance/index.js +5 -0
  83. package/dist/finance/index.js.map +1 -0
  84. package/dist/finance-BJdfKRw0.d.ts +135 -0
  85. package/dist/index.d.ts +32 -0
  86. package/dist/index.js +29 -0
  87. package/dist/index.js.map +1 -0
  88. package/dist/inventory/index.d.ts +512 -0
  89. package/dist/inventory/index.js +16 -0
  90. package/dist/inventory/index.js.map +1 -0
  91. package/dist/inventory-B5pssqRx.d.ts +748 -0
  92. package/dist/logistics/index.d.ts +248 -0
  93. package/dist/logistics/index.js +7 -0
  94. package/dist/logistics/index.js.map +1 -0
  95. package/dist/logistics-CrpKadKE.d.ts +410 -0
  96. package/dist/media-CNLJK93J.d.ts +721 -0
  97. package/dist/movement-R3CERFAM.js +5 -0
  98. package/dist/movement-R3CERFAM.js.map +1 -0
  99. package/dist/order-B3dCvHgK.d.ts +360 -0
  100. package/dist/payment-BRboLqvU.d.ts +127 -0
  101. package/dist/payments/index.d.ts +55 -0
  102. package/dist/payments/index.js +6 -0
  103. package/dist/payments/index.js.map +1 -0
  104. package/dist/platform/index.d.ts +645 -0
  105. package/dist/platform/index.js +8 -0
  106. package/dist/platform/index.js.map +1 -0
  107. package/dist/pos-BCqkx2-K.d.ts +527 -0
  108. package/dist/product-p09zXkXB.d.ts +260 -0
  109. package/dist/purchase-54PER2PY.js +5 -0
  110. package/dist/purchase-54PER2PY.js.map +1 -0
  111. package/dist/request-MP6NV5ZE.js +5 -0
  112. package/dist/request-MP6NV5ZE.js.map +1 -0
  113. package/dist/sales/index.d.ts +587 -0
  114. package/dist/sales/index.js +9 -0
  115. package/dist/sales/index.js.map +1 -0
  116. package/dist/server.d.ts +23 -0
  117. package/dist/server.js +37 -0
  118. package/dist/server.js.map +1 -0
  119. package/dist/size-guide-DgjzjM5P.d.ts +554 -0
  120. package/dist/stock-2LP4HJSB.js +5 -0
  121. package/dist/stock-2LP4HJSB.js.map +1 -0
  122. package/dist/stock-CfrU5_Wr.d.ts +632 -0
  123. package/dist/supplier-BWJTRZ5Z.js +5 -0
  124. package/dist/supplier-BWJTRZ5Z.js.map +1 -0
  125. package/dist/transaction/index.d.ts +104 -0
  126. package/dist/transaction/index.js +8 -0
  127. package/dist/transaction/index.js.map +1 -0
  128. package/dist/transaction-Bf6WjYCh.d.ts +84 -0
  129. package/dist/transaction-dL3WW-er.d.ts +442 -0
  130. package/dist/transfer-4XSS6HWT.js +5 -0
  131. package/dist/transfer-4XSS6HWT.js.map +1 -0
  132. package/dist/user-data-DdLjAGwO.d.ts +132 -0
  133. package/package.json +147 -0
@@ -0,0 +1,159 @@
1
+ import { BaseApi } from './chunk-QCTXAMLA.js';
2
+ import { handleApiRequest } from './chunk-IHCBBLLW.js';
3
+
4
+ // src/inventory/api/request.ts
5
+ var RequestApi = class extends BaseApi {
6
+ constructor(config = {}) {
7
+ super("inventory/requests", config);
8
+ }
9
+ /**
10
+ * List stock requests
11
+ * GET /inventory/requests
12
+ */
13
+ async list({
14
+ token,
15
+ params = {},
16
+ options = {}
17
+ }) {
18
+ const processedParams = this.prepareParams(params);
19
+ const queryString = this.createQueryString(processedParams);
20
+ return handleApiRequest("GET", `${this.baseUrl}?${queryString}`, {
21
+ token,
22
+ cache: this.config.cache,
23
+ ...options
24
+ });
25
+ }
26
+ /**
27
+ * List pending stock requests
28
+ * GET /inventory/requests?status=pending
29
+ */
30
+ async listPending({
31
+ token,
32
+ options = {}
33
+ }) {
34
+ return this.list({ token, params: { status: "pending" }, options });
35
+ }
36
+ /**
37
+ * Get stock request by ID
38
+ * GET /inventory/requests/:id
39
+ */
40
+ async getById({
41
+ token,
42
+ id,
43
+ options = {}
44
+ }) {
45
+ if (!id) {
46
+ throw new Error("Request ID is required");
47
+ }
48
+ return handleApiRequest("GET", `${this.baseUrl}/${id}`, {
49
+ token,
50
+ cache: this.config.cache,
51
+ ...options
52
+ });
53
+ }
54
+ /**
55
+ * Create a stock request
56
+ * POST /inventory/requests
57
+ */
58
+ async create({
59
+ token,
60
+ data,
61
+ options = {}
62
+ }) {
63
+ return handleApiRequest("POST", this.baseUrl, {
64
+ token,
65
+ body: data,
66
+ cache: this.config.cache,
67
+ ...options
68
+ });
69
+ }
70
+ // ==================== Stock Request Actions ====================
71
+ /**
72
+ * Generic action endpoint
73
+ * POST /inventory/requests/:id/action
74
+ */
75
+ async action({
76
+ token,
77
+ id,
78
+ action,
79
+ data = {},
80
+ options = {}
81
+ }) {
82
+ if (!id) {
83
+ throw new Error("Request ID is required");
84
+ }
85
+ return handleApiRequest("POST", `${this.baseUrl}/${id}/action`, {
86
+ token,
87
+ body: { action, ...data },
88
+ cache: this.config.cache,
89
+ ...options
90
+ });
91
+ }
92
+ /**
93
+ * Approve a stock request
94
+ */
95
+ async approve({
96
+ token,
97
+ id,
98
+ items,
99
+ reviewNotes,
100
+ notes,
101
+ options = {}
102
+ }) {
103
+ return this.action({
104
+ token,
105
+ id,
106
+ action: "approve",
107
+ data: { items, reviewNotes: reviewNotes ?? notes },
108
+ options
109
+ });
110
+ }
111
+ /**
112
+ * Reject a stock request
113
+ */
114
+ async reject({
115
+ token,
116
+ id,
117
+ reason,
118
+ options = {}
119
+ }) {
120
+ return this.action({ token, id, action: "reject", data: { reason }, options });
121
+ }
122
+ /**
123
+ * Fulfill a stock request (creates a transfer)
124
+ * Head office assigns carton numbers here for label printing
125
+ */
126
+ async fulfill({
127
+ token,
128
+ id,
129
+ remarks,
130
+ documentType,
131
+ items,
132
+ transport,
133
+ options = {}
134
+ }) {
135
+ return this.action({
136
+ token,
137
+ id,
138
+ action: "fulfill",
139
+ data: { remarks, documentType, items, transport },
140
+ options
141
+ });
142
+ }
143
+ /**
144
+ * Cancel a stock request
145
+ */
146
+ async cancel({
147
+ token,
148
+ id,
149
+ reason,
150
+ options = {}
151
+ }) {
152
+ return this.action({ token, id, action: "cancel", data: { reason }, options });
153
+ }
154
+ };
155
+ var requestApi = new RequestApi();
156
+
157
+ export { RequestApi, requestApi };
158
+ //# sourceMappingURL=chunk-2TF7QNYV.js.map
159
+ //# sourceMappingURL=chunk-2TF7QNYV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/inventory/api/request.ts"],"names":[],"mappings":";;;;AAgBA,IAAM,UAAA,GAAN,cAAyB,OAAA,CAAiD;AAAA,EACxE,WAAA,CAAY,MAAA,GAAS,EAAC,EAAG;AACvB,IAAA,KAAA,CAAM,sBAAsB,MAAM,CAAA;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,IAAA,CAAK;AAAA,IACT,KAAA;AAAA,IACA,SAAS,EAAC;AAAA,IACV,UAAU;AAAC,GACb,EAI6C;AAC3C,IAAA,MAAM,eAAA,GAAkB,IAAA,CAAK,aAAA,CAAc,MAAM,CAAA;AACjD,IAAA,MAAM,WAAA,GAAc,IAAA,CAAK,iBAAA,CAAkB,eAAe,CAAA;AAE1D,IAAA,OAAO,iBAAiB,KAAA,EAAO,CAAA,EAAG,KAAK,OAAO,CAAA,CAAA,EAAI,WAAW,CAAA,CAAA,EAAI;AAAA,MAC/D,KAAA;AAAA,MACA,KAAA,EAAO,KAAK,MAAA,CAAO,KAAA;AAAA,MACnB,GAAG;AAAA,KACJ,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAA,CAAY;AAAA,IAChB,KAAA;AAAA,IACA,UAAU;AAAC,GACb,EAG6C;AAC3C,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,EAAE,KAAA,EAAO,MAAA,EAAQ,EAAE,MAAA,EAAQ,SAAA,EAAU,EAAG,OAAA,EAAS,C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;AAAA,IACX,KAAA;AAAA,IACA,EAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAU;AAAC,GACb,EAKuC;AACrC,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,EAAE,KAAA,EAAO,EAAA,EAAI,MAAA,EAAQ,QAAA,EAAU,IAAA,EAAM,EAAE,MAAA,EAAO,EAAG,OAAA,EAAS,CAAA;AAAA,EAC/E;AACF;AAEO,IAAM,UAAA,GAAa,IAAI,UAAA","file":"chunk-2TF7QNYV.js","sourcesContent":["/**\r\n * Stock Request API - Sub-branch -> Head Office requests\r\n *\r\n * Handles stock requests from sub-branches following the Stripe action-based pattern.\r\n * Status flow: pending -> approved -> fulfilled (or rejected/cancelled)\r\n */\r\n\r\nimport { BaseApi, type ApiResponse, type PaginatedResponse, type RequestOptions } from \"../../core/api-factory\";\r\nimport { handleApiRequest } from \"../../core/api-handler\";\r\nimport type {\r\n StockRequest,\r\n CreateStockRequestPayload,\r\n} from \"../types\";\r\n\r\ntype FetchOptions = Omit<RequestOptions, \"token\" | \"organizationId\">;\r\n\r\nclass RequestApi extends BaseApi<StockRequest, CreateStockRequestPayload> {\r\n constructor(config = {}) {\r\n super(\"inventory/requests\", config);\r\n }\r\n\r\n /**\r\n * List stock requests\r\n * GET /inventory/requests\r\n */\r\n async list({\r\n token,\r\n params = {},\r\n options = {},\r\n }: {\r\n token: string;\r\n params?: Record<string, unknown>;\r\n options?: FetchOptions;\r\n }): Promise<PaginatedResponse<StockRequest>> {\r\n const processedParams = this.prepareParams(params);\r\n const queryString = this.createQueryString(processedParams);\r\n\r\n return handleApiRequest(\"GET\", `${this.baseUrl}?${queryString}`, {\r\n token,\r\n cache: this.config.cache,\r\n ...options,\r\n });\r\n }\r\n\r\n /**\r\n * List pending stock requests\r\n * GET /inventory/requests?status=pending\r\n */\r\n async listPending({\r\n token,\r\n options = {},\r\n }: {\r\n token: string;\r\n options?: FetchOptions;\r\n }): Promise<PaginatedResponse<StockRequest>> {\r\n return this.list({ token, params: { status: \"pending\" }, options });\r\n }\r\n\r\n /**\r\n * Get stock request by ID\r\n * GET /inventory/requests/:id\r\n */\r\n async getById({\r\n token,\r\n id,\r\n options = {},\r\n }: {\r\n token: string;\r\n id: string;\r\n options?: FetchOptions;\r\n }): Promise<ApiResponse<StockRequest>> {\r\n if (!id) {\r\n throw new Error(\"Request ID is required\");\r\n }\r\n\r\n return handleApiRequest(\"GET\", `${this.baseUrl}/${id}`, {\r\n token,\r\n cache: this.config.cache,\r\n ...options,\r\n });\r\n }\r\n\r\n /**\r\n * Create a stock request\r\n * POST /inventory/requests\r\n */\r\n async create({\r\n token,\r\n data,\r\n options = {},\r\n }: {\r\n token: string;\r\n data: CreateStockRequestPayload;\r\n options?: FetchOptions;\r\n }): Promise<ApiResponse<StockRequest>> {\r\n return handleApiRequest(\"POST\", this.baseUrl, {\r\n token,\r\n body: data,\r\n cache: this.config.cache,\r\n ...options,\r\n });\r\n }\r\n\r\n // ==================== Stock Request Actions ====================\r\n\r\n /**\r\n * Generic action endpoint\r\n * POST /inventory/requests/:id/action\r\n */\r\n async action({\r\n token,\r\n id,\r\n action,\r\n data = {},\r\n options = {},\r\n }: {\r\n token: string;\r\n id: string;\r\n action: \"approve\" | \"reject\" | \"fulfill\" | \"cancel\";\r\n data?: Record<string, unknown>;\r\n options?: FetchOptions;\r\n }): Promise<ApiResponse<StockRequest>> {\r\n if (!id) {\r\n throw new Error(\"Request ID is required\");\r\n }\r\n\r\n return handleApiRequest(\"POST\", `${this.baseUrl}/${id}/action`, {\r\n token,\r\n body: { action, ...data },\r\n cache: this.config.cache,\r\n ...options,\r\n });\r\n }\r\n\r\n /**\r\n * Approve a stock request\r\n */\r\n async approve({\r\n token,\r\n id,\r\n items,\r\n reviewNotes,\r\n notes,\r\n options = {},\r\n }: {\r\n token: string;\r\n id: string;\r\n items?: { productId: string; variantSku?: string; quantityApproved: number }[];\r\n reviewNotes?: string;\r\n notes?: string;\r\n options?: FetchOptions;\r\n }): Promise<ApiResponse<StockRequest>> {\r\n return this.action({\r\n token,\r\n id,\r\n action: \"approve\",\r\n data: { items, reviewNotes: reviewNotes ?? notes },\r\n options,\r\n });\r\n }\r\n\r\n /**\r\n * Reject a stock request\r\n */\r\n async reject({\r\n token,\r\n id,\r\n reason,\r\n options = {},\r\n }: {\r\n token: string;\r\n id: string;\r\n reason: string;\r\n options?: FetchOptions;\r\n }): Promise<ApiResponse<StockRequest>> {\r\n return this.action({ token, id, action: \"reject\", data: { reason }, options });\r\n }\r\n\r\n /**\r\n * Fulfill a stock request (creates a transfer)\r\n * Head office assigns carton numbers here for label printing\r\n */\r\n async fulfill({\r\n token,\r\n id,\r\n remarks,\r\n documentType,\r\n items,\r\n transport,\r\n options = {},\r\n }: {\r\n token: string;\r\n id: string;\r\n remarks?: string;\r\n documentType?: string;\r\n items?: { productId: string; variantSku?: string; quantity: number; cartonNumber?: string }[];\r\n transport?: { vehicleNumber?: string; driverName?: string; driverPhone?: string };\r\n options?: FetchOptions;\r\n }): Promise<ApiResponse<StockRequest>> {\r\n return this.action({\r\n token,\r\n id,\r\n action: \"fulfill\",\r\n data: { remarks, documentType, items, transport },\r\n options,\r\n });\r\n }\r\n\r\n /**\r\n * Cancel a stock request\r\n */\r\n async cancel({\r\n token,\r\n id,\r\n reason,\r\n options = {},\r\n }: {\r\n token: string;\r\n id: string;\r\n reason?: string;\r\n options?: FetchOptions;\r\n }): Promise<ApiResponse<StockRequest>> {\r\n return this.action({ token, id, action: \"cancel\", data: { reason }, options });\r\n }\r\n}\r\n\r\nexport const requestApi = new RequestApi();\r\nexport { RequestApi };\r\n"]}
@@ -0,0 +1,479 @@
1
+ import { BaseApi } from './chunk-QCTXAMLA.js';
2
+ import { getToastHandler } from './chunk-U3XT35GZ.js';
3
+ import { handleApiRequest } from './chunk-IHCBBLLW.js';
4
+ import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
5
+
6
+ // src/logistics/api/logistics.ts
7
+ var LogisticsApi = class extends BaseApi {
8
+ constructor(config = {}) {
9
+ super("logistics", config);
10
+ }
11
+ // ============================================
12
+ // CHARGE CALCULATION (Public)
13
+ // ============================================
14
+ /**
15
+ * Calculate delivery charge via provider API (e.g., RedX)
16
+ * GET /logistics/charge
17
+ *
18
+ * Use this to get real-time delivery charges from the logistics provider
19
+ * before creating an order.
20
+ *
21
+ * @param deliveryAreaId - Area internalId from @classytic/bd-areas
22
+ * @param amount - COD amount in BDT (use 0 for prepaid orders)
23
+ * @param weight - Parcel weight in grams (default: 500g)
24
+ *
25
+ * @example
26
+ * import { searchAreas } from '@classytic/bd-areas';
27
+ *
28
+ * // 1. User selects area
29
+ * const areas = searchAreas('mohamm');
30
+ * const selectedArea = areas[0]; // { internalId: 1206, name: 'Mohammadpur', ... }
31
+ *
32
+ * // 2. Calculate delivery charge
33
+ * const { data } = await logisticsApi.calculateCharge({
34
+ * deliveryAreaId: selectedArea.internalId,
35
+ * amount: isCOD ? cartTotal : 0,
36
+ * });
37
+ * // { deliveryCharge: 60, codCharge: 15, totalCharge: 75 }
38
+ */
39
+ async calculateCharge({
40
+ deliveryAreaId,
41
+ pickupAreaId,
42
+ amount,
43
+ weight,
44
+ provider,
45
+ options = {}
46
+ }) {
47
+ if (!deliveryAreaId || amount === void 0) {
48
+ throw new Error("deliveryAreaId and amount are required");
49
+ }
50
+ const queryString = this.createQueryString({
51
+ deliveryAreaId,
52
+ pickupAreaId,
53
+ amount,
54
+ weight,
55
+ provider
56
+ });
57
+ return handleApiRequest("GET", `${this.baseUrl}/charge?${queryString}`, {
58
+ cache: "no-store",
59
+ ...options
60
+ });
61
+ }
62
+ // ============================================
63
+ // CONFIG ENDPOINTS (Admin - Read-only)
64
+ // ============================================
65
+ /**
66
+ * Get logistics configuration (read-only from .env)
67
+ * GET /logistics/config
68
+ *
69
+ * NOTE: Configuration is managed via environment variables.
70
+ * To change settings, update .env file and restart server.
71
+ */
72
+ async getConfig({
73
+ token,
74
+ options = {}
75
+ }) {
76
+ return handleApiRequest("GET", `${this.baseUrl}/config`, {
77
+ token,
78
+ cache: "no-store",
79
+ ...options
80
+ });
81
+ }
82
+ // ============================================
83
+ // PICKUP STORES (Admin)
84
+ // ============================================
85
+ /**
86
+ * Get pickup stores from RedX API
87
+ * GET /logistics/pickup-stores
88
+ *
89
+ * Pickup stores are created by admin in RedX dashboard.
90
+ * Use this to list available pickup locations when creating shipments.
91
+ *
92
+ * @example
93
+ * // Admin: List pickup stores for shipment creation
94
+ * const { data: stores } = await logisticsApi.getPickupStores({ token });
95
+ *
96
+ * // Display in dropdown for admin to select
97
+ * stores.forEach(store => {
98
+ * console.log(`${store.name} - ${store.areaName} (ID: ${store.id})`);
99
+ * });
100
+ *
101
+ * // Use selected store when creating shipment
102
+ * await logisticsApi.createShipment({
103
+ * token,
104
+ * data: {
105
+ * orderId: order._id,
106
+ * pickupStoreId: selectedStore.id, // From dropdown
107
+ * },
108
+ * });
109
+ */
110
+ async getPickupStores({
111
+ token,
112
+ provider,
113
+ options = {}
114
+ }) {
115
+ const queryString = provider ? `?provider=${provider}` : "";
116
+ return handleApiRequest(
117
+ "GET",
118
+ `${this.baseUrl}/pickup-stores${queryString}`,
119
+ {
120
+ token,
121
+ cache: "no-store",
122
+ ...options
123
+ }
124
+ );
125
+ }
126
+ // ============================================
127
+ // SHIPPING ENDPOINTS (Admin/Store Manager)
128
+ // ============================================
129
+ /**
130
+ * Request shipping for an order (manual or provider API)
131
+ * POST /orders/:id/shipping
132
+ *
133
+ * This updates the order.shipping object and optionally triggers
134
+ * provider API shipment creation when useProviderApi=true.
135
+ *
136
+ * @example
137
+ * // Manual: Record tracking details
138
+ * const shipping = await logisticsApi.createShipment({
139
+ * token,
140
+ * orderId: order._id,
141
+ * data: {
142
+ * provider: "other",
143
+ * trackingNumber: "COURIER123456",
144
+ * trackingUrl: "https://courier-website.com/track/COURIER123456",
145
+ * },
146
+ * });
147
+ *
148
+ * @example
149
+ * // Provider API: Create shipment with pickup store
150
+ * const { data: stores } = await logisticsApi.getPickupStores({ token });
151
+ * const shipping = await logisticsApi.createShipment({
152
+ * token,
153
+ * orderId: order._id,
154
+ * data: {
155
+ * provider: "redx",
156
+ * useProviderApi: true,
157
+ * pickupStoreId: stores[0].id, // Select pickup location
158
+ * weight: 500, // Parcel weight in grams
159
+ * instructions: 'Handle with care',
160
+ * },
161
+ * });
162
+ */
163
+ async createShipment({
164
+ token,
165
+ orderId,
166
+ data,
167
+ options = {}
168
+ }) {
169
+ if (!orderId) throw new Error("Order ID is required");
170
+ const response = await handleApiRequest("POST", `${this.config.basePath}/orders/${orderId}/shipping`, {
171
+ token,
172
+ body: data,
173
+ ...options
174
+ });
175
+ const normalizedData = response.data && typeof response.data === "object" && "shipping" in response.data ? response.data.shipping : response.data;
176
+ return {
177
+ success: response.success,
178
+ message: response.message,
179
+ ...normalizedData ? { data: normalizedData } : {}
180
+ };
181
+ }
182
+ /**
183
+ * Get shipping info for an order
184
+ * GET /orders/:id/shipping
185
+ */
186
+ async getShipment({
187
+ token,
188
+ id,
189
+ options = {}
190
+ }) {
191
+ if (!id) throw new Error("Order ID is required");
192
+ return handleApiRequest("GET", `${this.config.basePath}/orders/${id}/shipping`, {
193
+ token,
194
+ cache: "no-store",
195
+ ...options
196
+ });
197
+ }
198
+ /**
199
+ * Track shipment (fetch latest from provider)
200
+ * GET /logistics/shipments/:id/track
201
+ *
202
+ * @param id - Order ID or tracking number
203
+ */
204
+ async trackShipment({
205
+ token,
206
+ id,
207
+ options = {}
208
+ }) {
209
+ if (!id) throw new Error("Shipment ID or tracking number is required");
210
+ return handleApiRequest("GET", `${this.baseUrl}/shipments/${id}/track`, {
211
+ token,
212
+ cache: "no-store",
213
+ ...options
214
+ });
215
+ }
216
+ /**
217
+ * Update shipping status for an order
218
+ * PATCH /orders/:id/shipping
219
+ */
220
+ async updateShipmentStatus({
221
+ token,
222
+ id,
223
+ data,
224
+ options = {}
225
+ }) {
226
+ if (!id) throw new Error("Order ID is required");
227
+ if (!data?.status) throw new Error("Status is required");
228
+ return handleApiRequest("PATCH", `${this.config.basePath}/orders/${id}/shipping`, {
229
+ token,
230
+ body: data,
231
+ ...options
232
+ });
233
+ }
234
+ /**
235
+ * Cancel shipment
236
+ * POST /logistics/shipments/:id/cancel
237
+ *
238
+ * @param id - Order ID or tracking number
239
+ */
240
+ async cancelShipment({
241
+ token,
242
+ id,
243
+ data,
244
+ options = {}
245
+ }) {
246
+ if (!id) throw new Error("Shipment ID or tracking number is required");
247
+ return handleApiRequest("POST", `${this.baseUrl}/shipments/${id}/cancel`, {
248
+ token,
249
+ body: data || {},
250
+ ...options
251
+ });
252
+ }
253
+ // ============================================
254
+ // HEALTH & MONITORING (Admin)
255
+ // ============================================
256
+ /**
257
+ * Get circuit breaker status for all providers
258
+ * GET /logistics/health/circuit-status
259
+ */
260
+ async getCircuitStatus({
261
+ token,
262
+ options = {}
263
+ }) {
264
+ return handleApiRequest("GET", `${this.baseUrl}/health/circuit-status`, {
265
+ token,
266
+ cache: "no-store",
267
+ ...options
268
+ });
269
+ }
270
+ /**
271
+ * Reset circuit breaker for a provider
272
+ * POST /logistics/health/circuit-reset/:provider
273
+ */
274
+ async resetProviderCircuit({
275
+ token,
276
+ provider,
277
+ options = {}
278
+ }) {
279
+ if (!provider) throw new Error("Provider name is required");
280
+ return handleApiRequest(
281
+ "POST",
282
+ `${this.baseUrl}/health/circuit-reset/${provider}`,
283
+ {
284
+ token,
285
+ body: {},
286
+ ...options
287
+ }
288
+ );
289
+ }
290
+ };
291
+ var logisticsApi = new LogisticsApi();
292
+ var LOGISTICS_KEYS = {
293
+ all: ["logistics"],
294
+ pickupStores: (provider) => [...LOGISTICS_KEYS.all, "pickup-stores", provider],
295
+ shipment: (id) => [...LOGISTICS_KEYS.all, "shipment", id],
296
+ tracking: (id) => [...LOGISTICS_KEYS.all, "tracking", id],
297
+ charge: (params) => [...LOGISTICS_KEYS.all, "charge", params],
298
+ config: () => [...LOGISTICS_KEYS.all, "config"]
299
+ };
300
+ function usePickupStores(token, provider, options = {}) {
301
+ return useQuery({
302
+ queryKey: LOGISTICS_KEYS.pickupStores(provider),
303
+ queryFn: async () => {
304
+ const response = await logisticsApi.getPickupStores({ token, provider });
305
+ return response.data || [];
306
+ },
307
+ enabled: options.enabled !== false && !!token,
308
+ staleTime: options.staleTime ?? 5 * 60 * 1e3
309
+ });
310
+ }
311
+ function useDeliveryChargeCalculation(token, params, options = {}) {
312
+ const hasValidParams = !!params?.deliveryAreaId && params?.amount !== void 0;
313
+ return useQuery({
314
+ queryKey: LOGISTICS_KEYS.charge(
315
+ params ? { deliveryAreaId: params.deliveryAreaId, amount: params.amount, weight: params.weight } : { deliveryAreaId: 0, amount: 0 }
316
+ ),
317
+ queryFn: async () => {
318
+ if (!params) throw new Error("Params required");
319
+ const response = await logisticsApi.calculateCharge({
320
+ deliveryAreaId: params.deliveryAreaId,
321
+ pickupAreaId: params.pickupAreaId,
322
+ amount: params.amount,
323
+ weight: params.weight,
324
+ provider: params.provider
325
+ });
326
+ if (!response.data) throw new Error("No charge data returned");
327
+ return response.data;
328
+ },
329
+ enabled: options.enabled !== false && hasValidParams,
330
+ staleTime: options.staleTime ?? 60 * 1e3
331
+ });
332
+ }
333
+ function useDeliveryCharge({
334
+ deliveryAreaId,
335
+ amount,
336
+ weight = 500,
337
+ enabled = true
338
+ }) {
339
+ const { data, isLoading, isFetching, error, refetch } = useQuery({
340
+ queryKey: LOGISTICS_KEYS.charge({
341
+ deliveryAreaId: deliveryAreaId || 0,
342
+ amount,
343
+ weight
344
+ }),
345
+ queryFn: async () => {
346
+ if (!deliveryAreaId) return null;
347
+ const response = await logisticsApi.calculateCharge({
348
+ deliveryAreaId,
349
+ amount,
350
+ weight
351
+ });
352
+ return response.data || null;
353
+ },
354
+ enabled: enabled && !!deliveryAreaId,
355
+ staleTime: 5 * 60 * 1e3,
356
+ gcTime: 10 * 60 * 1e3,
357
+ retry: 1
358
+ });
359
+ return {
360
+ charges: data || null,
361
+ deliveryCharge: data?.deliveryCharge ?? 0,
362
+ codCharge: data?.codCharge ?? 0,
363
+ totalCharge: data?.totalCharge ?? 0,
364
+ isLoading,
365
+ isFetching,
366
+ error,
367
+ refetch
368
+ };
369
+ }
370
+ function useShipment(token, orderId, options = {}) {
371
+ return useQuery({
372
+ queryKey: LOGISTICS_KEYS.shipment(orderId || ""),
373
+ queryFn: async () => {
374
+ if (!orderId) throw new Error("Order ID required");
375
+ const response = await logisticsApi.getShipment({ token, id: orderId });
376
+ if (!response.data) throw new Error("Shipping info not found");
377
+ return response.data;
378
+ },
379
+ enabled: options.enabled !== false && !!token && !!orderId,
380
+ staleTime: options.staleTime ?? 30 * 1e3
381
+ });
382
+ }
383
+ function useTrackShipment(token, shipmentId, options = {}) {
384
+ return useQuery({
385
+ queryKey: LOGISTICS_KEYS.tracking(shipmentId || ""),
386
+ queryFn: async () => {
387
+ if (!shipmentId) throw new Error("Order ID or tracking number required");
388
+ const response = await logisticsApi.trackShipment({ token, id: shipmentId });
389
+ if (!response.data) throw new Error("Tracking data not found");
390
+ return response.data;
391
+ },
392
+ enabled: options.enabled !== false && !!token && !!shipmentId,
393
+ staleTime: options.staleTime ?? 60 * 1e3,
394
+ refetchInterval: options.refetchInterval ?? 5 * 60 * 1e3
395
+ });
396
+ }
397
+ function useCreateShipment(token) {
398
+ const queryClient = useQueryClient();
399
+ const toast = getToastHandler();
400
+ return useMutation({
401
+ mutationFn: async ({ orderId, data }) => {
402
+ const response = await logisticsApi.createShipment({ token, orderId, data });
403
+ return response.data;
404
+ },
405
+ onSuccess: () => {
406
+ toast.success("Shipment created successfully");
407
+ queryClient.invalidateQueries({ queryKey: ["orders"] });
408
+ queryClient.invalidateQueries({ queryKey: LOGISTICS_KEYS.all });
409
+ },
410
+ onError: (error) => {
411
+ toast.error(error.message || "Failed to create shipment");
412
+ }
413
+ });
414
+ }
415
+ function useCancelShipment(token) {
416
+ const queryClient = useQueryClient();
417
+ const toast = getToastHandler();
418
+ return useMutation({
419
+ mutationFn: async ({ shipmentId, reason }) => {
420
+ const response = await logisticsApi.cancelShipment({
421
+ token,
422
+ id: shipmentId,
423
+ data: { reason }
424
+ });
425
+ return response.data;
426
+ },
427
+ onSuccess: () => {
428
+ toast.success("Shipment cancelled");
429
+ queryClient.invalidateQueries({ queryKey: ["orders"] });
430
+ queryClient.invalidateQueries({ queryKey: LOGISTICS_KEYS.all });
431
+ },
432
+ onError: (error) => {
433
+ toast.error(error.message || "Failed to cancel shipment");
434
+ }
435
+ });
436
+ }
437
+ function useUpdateShipmentStatus(token) {
438
+ const queryClient = useQueryClient();
439
+ const toast = getToastHandler();
440
+ return useMutation({
441
+ mutationFn: async ({
442
+ shipmentId,
443
+ data
444
+ }) => {
445
+ const response = await logisticsApi.updateShipmentStatus({
446
+ token,
447
+ id: shipmentId,
448
+ data
449
+ });
450
+ return response.data;
451
+ },
452
+ onSuccess: () => {
453
+ toast.success("Shipment status updated");
454
+ queryClient.invalidateQueries({ queryKey: ["orders"] });
455
+ queryClient.invalidateQueries({ queryKey: LOGISTICS_KEYS.all });
456
+ },
457
+ onError: (error) => {
458
+ toast.error(error.message || "Failed to update status");
459
+ }
460
+ });
461
+ }
462
+ function useLogisticsActions(token) {
463
+ const createShipmentMutation = useCreateShipment(token);
464
+ const cancelShipmentMutation = useCancelShipment(token);
465
+ const updateStatusMutation = useUpdateShipmentStatus(token);
466
+ return {
467
+ createShipment: createShipmentMutation.mutateAsync,
468
+ isCreatingShipment: createShipmentMutation.isPending,
469
+ cancelShipment: cancelShipmentMutation.mutateAsync,
470
+ isCancellingShipment: cancelShipmentMutation.isPending,
471
+ updateShipmentStatus: updateStatusMutation.mutateAsync,
472
+ isUpdatingStatus: updateStatusMutation.isPending,
473
+ isLoading: createShipmentMutation.isPending || cancelShipmentMutation.isPending || updateStatusMutation.isPending
474
+ };
475
+ }
476
+
477
+ export { LOGISTICS_KEYS, LogisticsApi, logisticsApi, useCancelShipment, useCreateShipment, useDeliveryCharge, useDeliveryChargeCalculation, useLogisticsActions, usePickupStores, useShipment, useTrackShipment, useUpdateShipmentStatus };
478
+ //# sourceMappingURL=chunk-2YAZ5WG6.js.map
479
+ //# sourceMappingURL=chunk-2YAZ5WG6.js.map