@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.
- package/LICENSE +14 -0
- package/README.md +164 -0
- package/dist/adjustment-MNH3AT6S.js +5 -0
- package/dist/adjustment-MNH3AT6S.js.map +1 -0
- package/dist/analytics/index.d.ts +27 -0
- package/dist/analytics/index.js +6 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/analytics-DMcD-o8w.d.ts +76 -0
- package/dist/api-factory-B_h4RKBm.d.ts +280 -0
- package/dist/auth/index.d.ts +39 -0
- package/dist/auth/index.js +5 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/catalog/index.d.ts +571 -0
- package/dist/catalog/index.js +9 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/chunk-24FDD6UR.js +75 -0
- package/dist/chunk-24FDD6UR.js.map +1 -0
- package/dist/chunk-2TF7QNYV.js +159 -0
- package/dist/chunk-2TF7QNYV.js.map +1 -0
- package/dist/chunk-2YAZ5WG6.js +479 -0
- package/dist/chunk-2YAZ5WG6.js.map +1 -0
- package/dist/chunk-36NLLAVH.js +177 -0
- package/dist/chunk-36NLLAVH.js.map +1 -0
- package/dist/chunk-3OYSJB3P.js +126 -0
- package/dist/chunk-3OYSJB3P.js.map +1 -0
- package/dist/chunk-5E57JODA.js +135 -0
- package/dist/chunk-5E57JODA.js.map +1 -0
- package/dist/chunk-7LZCW4VF.js +13 -0
- package/dist/chunk-7LZCW4VF.js.map +1 -0
- package/dist/chunk-ANYGZ6O5.js +830 -0
- package/dist/chunk-ANYGZ6O5.js.map +1 -0
- package/dist/chunk-AQAISI4F.js +183 -0
- package/dist/chunk-AQAISI4F.js.map +1 -0
- package/dist/chunk-B6MPVOV7.js +328 -0
- package/dist/chunk-B6MPVOV7.js.map +1 -0
- package/dist/chunk-CILP56G2.js +94 -0
- package/dist/chunk-CILP56G2.js.map +1 -0
- package/dist/chunk-ERQ52WHY.js +534 -0
- package/dist/chunk-ERQ52WHY.js.map +1 -0
- package/dist/chunk-FOTUJPM4.js +640 -0
- package/dist/chunk-FOTUJPM4.js.map +1 -0
- package/dist/chunk-IHCBBLLW.js +198 -0
- package/dist/chunk-IHCBBLLW.js.map +1 -0
- package/dist/chunk-J4JBQET2.js +76 -0
- package/dist/chunk-J4JBQET2.js.map +1 -0
- package/dist/chunk-L4OEI4VZ.js +123 -0
- package/dist/chunk-L4OEI4VZ.js.map +1 -0
- package/dist/chunk-LRV7MWWX.js +616 -0
- package/dist/chunk-LRV7MWWX.js.map +1 -0
- package/dist/chunk-N43VE355.js +126 -0
- package/dist/chunk-N43VE355.js.map +1 -0
- package/dist/chunk-PYYLHUV6.js +3 -0
- package/dist/chunk-PYYLHUV6.js.map +1 -0
- package/dist/chunk-QCTXAMLA.js +261 -0
- package/dist/chunk-QCTXAMLA.js.map +1 -0
- package/dist/chunk-RIKAPJNG.js +40 -0
- package/dist/chunk-RIKAPJNG.js.map +1 -0
- package/dist/chunk-U3XT35GZ.js +202 -0
- package/dist/chunk-U3XT35GZ.js.map +1 -0
- package/dist/chunk-W22WB3WZ.js +148 -0
- package/dist/chunk-W22WB3WZ.js.map +1 -0
- package/dist/chunk-WTIJMKML.js +27 -0
- package/dist/chunk-WTIJMKML.js.map +1 -0
- package/dist/chunk-X2CQFJPR.js +75 -0
- package/dist/chunk-X2CQFJPR.js.map +1 -0
- package/dist/chunk-YYFKLOKO.js +769 -0
- package/dist/chunk-YYFKLOKO.js.map +1 -0
- package/dist/client-Cs7E_usr.d.ts +113 -0
- package/dist/content/index.d.ts +309 -0
- package/dist/content/index.js +6 -0
- package/dist/content/index.js.map +1 -0
- package/dist/core/index.d.ts +166 -0
- package/dist/core/index.js +5 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/react.d.ts +107 -0
- package/dist/core/react.js +5 -0
- package/dist/core/react.js.map +1 -0
- package/dist/coupon-BZSZ0y3n.d.ts +129 -0
- package/dist/coupon-CDzL4bJG.d.ts +655 -0
- package/dist/crud.factory-DyKaPHcU.d.ts +181 -0
- package/dist/finance/index.d.ts +81 -0
- package/dist/finance/index.js +5 -0
- package/dist/finance/index.js.map +1 -0
- package/dist/finance-BJdfKRw0.d.ts +135 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/inventory/index.d.ts +512 -0
- package/dist/inventory/index.js +16 -0
- package/dist/inventory/index.js.map +1 -0
- package/dist/inventory-B5pssqRx.d.ts +748 -0
- package/dist/logistics/index.d.ts +248 -0
- package/dist/logistics/index.js +7 -0
- package/dist/logistics/index.js.map +1 -0
- package/dist/logistics-CrpKadKE.d.ts +410 -0
- package/dist/media-CNLJK93J.d.ts +721 -0
- package/dist/movement-R3CERFAM.js +5 -0
- package/dist/movement-R3CERFAM.js.map +1 -0
- package/dist/order-B3dCvHgK.d.ts +360 -0
- package/dist/payment-BRboLqvU.d.ts +127 -0
- package/dist/payments/index.d.ts +55 -0
- package/dist/payments/index.js +6 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/platform/index.d.ts +645 -0
- package/dist/platform/index.js +8 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/pos-BCqkx2-K.d.ts +527 -0
- package/dist/product-p09zXkXB.d.ts +260 -0
- package/dist/purchase-54PER2PY.js +5 -0
- package/dist/purchase-54PER2PY.js.map +1 -0
- package/dist/request-MP6NV5ZE.js +5 -0
- package/dist/request-MP6NV5ZE.js.map +1 -0
- package/dist/sales/index.d.ts +587 -0
- package/dist/sales/index.js +9 -0
- package/dist/sales/index.js.map +1 -0
- package/dist/server.d.ts +23 -0
- package/dist/server.js +37 -0
- package/dist/server.js.map +1 -0
- package/dist/size-guide-DgjzjM5P.d.ts +554 -0
- package/dist/stock-2LP4HJSB.js +5 -0
- package/dist/stock-2LP4HJSB.js.map +1 -0
- package/dist/stock-CfrU5_Wr.d.ts +632 -0
- package/dist/supplier-BWJTRZ5Z.js +5 -0
- package/dist/supplier-BWJTRZ5Z.js.map +1 -0
- package/dist/transaction/index.d.ts +104 -0
- package/dist/transaction/index.js +8 -0
- package/dist/transaction/index.js.map +1 -0
- package/dist/transaction-Bf6WjYCh.d.ts +84 -0
- package/dist/transaction-dL3WW-er.d.ts +442 -0
- package/dist/transfer-4XSS6HWT.js +5 -0
- package/dist/transfer-4XSS6HWT.js.map +1 -0
- package/dist/user-data-DdLjAGwO.d.ts +132 -0
- package/package.json +147 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { g as PickupStore, P as ProviderName, d as ProviderCharges, f as TrackingResult, j as CreateShipmentPayload, C as CancelShipmentResult } from '../logistics-CrpKadKE.js';
|
|
2
|
+
export { A as Area, m as CalculateChargeParams, k as CancelShipmentPayload, p as CheckoutSettings, n as DeliveryFeeSource, q as DeliveryMethod, r as DeliveryOption, b as District, D as Division, L as LogisticsApi, i as LogisticsConfig, c as LogisticsProvider, o as PickupBranchInfo, a as ProviderAreaIds, h as ProviderConfig, S as ShipmentStatus, e as ShipmentTimelineEvent, T as TrackingData, U as UpdateShipmentStatusPayload, l as logisticsApi } from '../logistics-CrpKadKE.js';
|
|
3
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
4
|
+
import { h as OrderShipping, S as ShippingStatus } from '../order-B3dCvHgK.js';
|
|
5
|
+
import '../api-factory-B_h4RKBm.js';
|
|
6
|
+
|
|
7
|
+
declare const LOGISTICS_KEYS: {
|
|
8
|
+
all: readonly ["logistics"];
|
|
9
|
+
pickupStores: (provider?: string) => readonly ["logistics", "pickup-stores", string | undefined];
|
|
10
|
+
shipment: (id: string) => readonly ["logistics", "shipment", string];
|
|
11
|
+
tracking: (id: string) => readonly ["logistics", "tracking", string];
|
|
12
|
+
charge: (params: {
|
|
13
|
+
deliveryAreaId: number;
|
|
14
|
+
amount: number;
|
|
15
|
+
weight?: number;
|
|
16
|
+
}) => readonly ["logistics", "charge", {
|
|
17
|
+
deliveryAreaId: number;
|
|
18
|
+
amount: number;
|
|
19
|
+
weight?: number;
|
|
20
|
+
}];
|
|
21
|
+
config: () => readonly ["logistics", "config"];
|
|
22
|
+
};
|
|
23
|
+
interface QueryOptions {
|
|
24
|
+
enabled?: boolean;
|
|
25
|
+
staleTime?: number;
|
|
26
|
+
refetchInterval?: number | false;
|
|
27
|
+
}
|
|
28
|
+
interface ChargeParams {
|
|
29
|
+
deliveryAreaId: number;
|
|
30
|
+
pickupAreaId?: number;
|
|
31
|
+
amount: number;
|
|
32
|
+
weight?: number;
|
|
33
|
+
provider?: ProviderName;
|
|
34
|
+
}
|
|
35
|
+
interface UseDeliveryChargeParams {
|
|
36
|
+
deliveryAreaId: number | null | undefined;
|
|
37
|
+
amount: number;
|
|
38
|
+
weight?: number;
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
}
|
|
41
|
+
interface UseDeliveryChargeReturn {
|
|
42
|
+
charges: ProviderCharges | null;
|
|
43
|
+
deliveryCharge: number;
|
|
44
|
+
codCharge: number;
|
|
45
|
+
totalCharge: number;
|
|
46
|
+
isLoading: boolean;
|
|
47
|
+
isFetching: boolean;
|
|
48
|
+
error: Error | null;
|
|
49
|
+
refetch: () => void;
|
|
50
|
+
}
|
|
51
|
+
interface UseLogisticsActionsReturn {
|
|
52
|
+
createShipment: (params: {
|
|
53
|
+
orderId: string;
|
|
54
|
+
data: CreateShipmentPayload;
|
|
55
|
+
}) => Promise<OrderShipping | undefined>;
|
|
56
|
+
isCreatingShipment: boolean;
|
|
57
|
+
cancelShipment: (params: {
|
|
58
|
+
shipmentId: string;
|
|
59
|
+
reason?: string;
|
|
60
|
+
}) => Promise<CancelShipmentResult | undefined>;
|
|
61
|
+
isCancellingShipment: boolean;
|
|
62
|
+
updateShipmentStatus: (params: {
|
|
63
|
+
shipmentId: string;
|
|
64
|
+
data: UpdateShipmentStatusParams;
|
|
65
|
+
}) => Promise<OrderShipping | undefined>;
|
|
66
|
+
isUpdatingStatus: boolean;
|
|
67
|
+
isLoading: boolean;
|
|
68
|
+
}
|
|
69
|
+
interface UpdateShipmentStatusParams {
|
|
70
|
+
status: ShippingStatus | string;
|
|
71
|
+
note?: string;
|
|
72
|
+
metadata?: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Fetch pickup stores from logistics provider
|
|
76
|
+
*
|
|
77
|
+
* @param token - Auth token (admin required)
|
|
78
|
+
* @param provider - Optional provider filter
|
|
79
|
+
* @param options - Query options
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```tsx
|
|
83
|
+
* function PickupStoreSelect() {
|
|
84
|
+
* const { data: stores, isLoading } = usePickupStores(token);
|
|
85
|
+
*
|
|
86
|
+
* return (
|
|
87
|
+
* <Select>
|
|
88
|
+
* {stores?.map(store => (
|
|
89
|
+
* <SelectItem key={store.id} value={store.id.toString()}>
|
|
90
|
+
* {store.name} - {store.areaName}
|
|
91
|
+
* </SelectItem>
|
|
92
|
+
* ))}
|
|
93
|
+
* </Select>
|
|
94
|
+
* );
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare function usePickupStores(token: string, provider?: string, options?: QueryOptions): _tanstack_react_query.UseQueryResult<PickupStore[], Error>;
|
|
99
|
+
/**
|
|
100
|
+
* Calculate delivery charge via provider API
|
|
101
|
+
*
|
|
102
|
+
* @param token - Auth token (optional for public)
|
|
103
|
+
* @param params - Charge calculation parameters
|
|
104
|
+
* @param options - Query options
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```tsx
|
|
108
|
+
* const { data: charges } = useDeliveryChargeCalculation(token, {
|
|
109
|
+
* deliveryAreaId: 1206,
|
|
110
|
+
* amount: isCOD ? cartTotal : 0,
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare function useDeliveryChargeCalculation(token: string | null, params: ChargeParams | null, options?: QueryOptions): _tanstack_react_query.UseQueryResult<ProviderCharges, Error>;
|
|
115
|
+
/**
|
|
116
|
+
* Convenience hook for delivery charge with extracted values
|
|
117
|
+
*
|
|
118
|
+
* @param params - Delivery charge parameters
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```tsx
|
|
122
|
+
* function CheckoutDelivery({ areaId, subtotal, isCOD }) {
|
|
123
|
+
* const { deliveryCharge, isLoading } = useDeliveryCharge({
|
|
124
|
+
* deliveryAreaId: areaId,
|
|
125
|
+
* amount: isCOD ? subtotal : 0,
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* return (
|
|
129
|
+
* <p>Delivery: {isLoading ? "..." : `৳${deliveryCharge}`}</p>
|
|
130
|
+
* );
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
declare function useDeliveryCharge({ deliveryAreaId, amount, weight, enabled, }: UseDeliveryChargeParams): UseDeliveryChargeReturn;
|
|
135
|
+
/**
|
|
136
|
+
* Get shipping info by order ID
|
|
137
|
+
*
|
|
138
|
+
* @param token - Auth token
|
|
139
|
+
* @param orderId - Order ID
|
|
140
|
+
* @param options - Query options
|
|
141
|
+
*/
|
|
142
|
+
declare function useShipment(token: string, orderId: string | null, options?: QueryOptions): _tanstack_react_query.UseQueryResult<OrderShipping, Error>;
|
|
143
|
+
/**
|
|
144
|
+
* Track shipment - fetches latest status from provider
|
|
145
|
+
*
|
|
146
|
+
* @param token - Auth token
|
|
147
|
+
* @param shipmentId - Order ID or tracking number
|
|
148
|
+
* @param options - Query options (supports refetchInterval for auto-refresh)
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```tsx
|
|
152
|
+
* function ShipmentTracker({ shipmentId }) {
|
|
153
|
+
* const { data, isLoading } = useTrackShipment(token, shipmentId, {
|
|
154
|
+
* refetchInterval: 5 * 60 * 1000, // Auto-refresh every 5 minutes
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* return (
|
|
158
|
+
* <Timeline events={data?.tracking?.timeline || []} />
|
|
159
|
+
* );
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
declare function useTrackShipment(token: string, shipmentId: string | null, options?: QueryOptions): _tanstack_react_query.UseQueryResult<TrackingResult, Error>;
|
|
164
|
+
/**
|
|
165
|
+
* Create shipment mutation
|
|
166
|
+
*
|
|
167
|
+
* @param token - Auth token
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```tsx
|
|
171
|
+
* function CreateShipmentButton({ order }) {
|
|
172
|
+
* const { mutate, isPending } = useCreateShipment(token);
|
|
173
|
+
*
|
|
174
|
+
* return (
|
|
175
|
+
* <Button
|
|
176
|
+
* onClick={() =>
|
|
177
|
+
* mutate({
|
|
178
|
+
* orderId: order._id,
|
|
179
|
+
* data: { provider: "redx", useProviderApi: true },
|
|
180
|
+
* })
|
|
181
|
+
* }
|
|
182
|
+
* disabled={isPending}
|
|
183
|
+
* >
|
|
184
|
+
* Create Shipment
|
|
185
|
+
* </Button>
|
|
186
|
+
* );
|
|
187
|
+
* }
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
declare function useCreateShipment(token: string): _tanstack_react_query.UseMutationResult<OrderShipping | undefined, Error, {
|
|
191
|
+
orderId: string;
|
|
192
|
+
data: CreateShipmentPayload;
|
|
193
|
+
}, unknown>;
|
|
194
|
+
/**
|
|
195
|
+
* Cancel shipment mutation
|
|
196
|
+
*
|
|
197
|
+
* @param token - Auth token
|
|
198
|
+
*/
|
|
199
|
+
declare function useCancelShipment(token: string): _tanstack_react_query.UseMutationResult<CancelShipmentResult | undefined, Error, {
|
|
200
|
+
shipmentId: string;
|
|
201
|
+
reason?: string;
|
|
202
|
+
}, unknown>;
|
|
203
|
+
/**
|
|
204
|
+
* Update shipment status mutation
|
|
205
|
+
*
|
|
206
|
+
* @param token - Auth token
|
|
207
|
+
*/
|
|
208
|
+
declare function useUpdateShipmentStatus(token: string): _tanstack_react_query.UseMutationResult<OrderShipping | undefined, Error, {
|
|
209
|
+
shipmentId: string;
|
|
210
|
+
data: UpdateShipmentStatusParams;
|
|
211
|
+
}, unknown>;
|
|
212
|
+
/**
|
|
213
|
+
* Combined hook for all logistics mutations
|
|
214
|
+
*
|
|
215
|
+
* @param token - Auth token
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```tsx
|
|
219
|
+
* function ShipmentActions({ order }) {
|
|
220
|
+
* const {
|
|
221
|
+
* createShipment,
|
|
222
|
+
* cancelShipment,
|
|
223
|
+
* isLoading,
|
|
224
|
+
* } = useLogisticsActions(token);
|
|
225
|
+
*
|
|
226
|
+
* return (
|
|
227
|
+
* <>
|
|
228
|
+
* <Button
|
|
229
|
+
* onClick={() =>
|
|
230
|
+
* createShipment({
|
|
231
|
+
* orderId: order._id,
|
|
232
|
+
* data: { provider: "redx", useProviderApi: true },
|
|
233
|
+
* })
|
|
234
|
+
* }
|
|
235
|
+
* >
|
|
236
|
+
* Create Shipment
|
|
237
|
+
* </Button>
|
|
238
|
+
* <Button onClick={() => cancelShipment({ shipmentId: order._id })}>
|
|
239
|
+
* Cancel
|
|
240
|
+
* </Button>
|
|
241
|
+
* </>
|
|
242
|
+
* );
|
|
243
|
+
* }
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
declare function useLogisticsActions(token: string): UseLogisticsActionsReturn;
|
|
247
|
+
|
|
248
|
+
export { CancelShipmentResult, CreateShipmentPayload, LOGISTICS_KEYS, PickupStore, ProviderCharges, ProviderName, TrackingResult, type UseDeliveryChargeReturn, type UseLogisticsActionsReturn, useCancelShipment, useCreateShipment, useDeliveryCharge, useDeliveryChargeCalculation, useLogisticsActions, usePickupStores, useShipment, useTrackShipment, useUpdateShipmentStatus };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
export { LOGISTICS_KEYS, LogisticsApi, logisticsApi, useCancelShipment, useCreateShipment, useDeliveryCharge, useDeliveryChargeCalculation, useLogisticsActions, usePickupStores, useShipment, useTrackShipment, useUpdateShipmentStatus } from '../chunk-2YAZ5WG6.js';
|
|
3
|
+
import '../chunk-QCTXAMLA.js';
|
|
4
|
+
import '../chunk-U3XT35GZ.js';
|
|
5
|
+
import '../chunk-IHCBBLLW.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { B as BaseApi, R as RequestOptions, A as ApiResponse } from './api-factory-B_h4RKBm.js';
|
|
2
|
+
import { a as ShippingProvider, h as OrderShipping, S as ShippingStatus } from './order-B3dCvHgK.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Logistics Types
|
|
6
|
+
*
|
|
7
|
+
* Types for logistics API responses (tracking, charges, config).
|
|
8
|
+
* For area data types, install @classytic/bd-areas:
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import type { Area, Division, District, ProviderAreaIds } from '@classytic/bd-areas';
|
|
12
|
+
* import { searchAreas, getAreasByDistrict } from '@classytic/bd-areas';
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
type ProviderName = 'redx' | 'pathao' | 'steadfast' | 'paperfly' | 'sundarban' | 'sa_paribahan' | 'dhl' | 'fedex' | 'manual' | 'other';
|
|
17
|
+
interface ProviderAreaIds {
|
|
18
|
+
redx?: number;
|
|
19
|
+
pathao?: number;
|
|
20
|
+
steadfast?: number;
|
|
21
|
+
paperfly?: number;
|
|
22
|
+
}
|
|
23
|
+
interface Area {
|
|
24
|
+
internalId: number;
|
|
25
|
+
name: string;
|
|
26
|
+
districtId: number;
|
|
27
|
+
districtName: string;
|
|
28
|
+
divisionId: number;
|
|
29
|
+
divisionName: string;
|
|
30
|
+
postCode?: string;
|
|
31
|
+
providerAreaIds?: ProviderAreaIds;
|
|
32
|
+
}
|
|
33
|
+
interface Division {
|
|
34
|
+
id: number;
|
|
35
|
+
name: string;
|
|
36
|
+
nameBn?: string;
|
|
37
|
+
}
|
|
38
|
+
interface District {
|
|
39
|
+
id: number;
|
|
40
|
+
divisionId: number;
|
|
41
|
+
name: string;
|
|
42
|
+
nameBn?: string;
|
|
43
|
+
}
|
|
44
|
+
type ShipmentStatus = 'pickup-requested' | 'pickup-pending' | 'picked-up' | 'ready-for-delivery' | 'in-transit' | 'agent-hold' | 'delivery-in-progress' | 'out-for-delivery' | 'delivered' | 'failed-attempt' | 'agent-returning' | 'returning' | 'returned' | 'cancelled' | 'on-hold';
|
|
45
|
+
type LogisticsProvider = 'redx' | 'pathao' | 'steadfast' | 'paperfly' | 'sundarban' | 'sa_paribahan' | 'dhl' | 'fedex' | 'manual' | 'other';
|
|
46
|
+
/**
|
|
47
|
+
* Response from GET /logistics/charge
|
|
48
|
+
*
|
|
49
|
+
* Use deliveryCharge for customer-facing price.
|
|
50
|
+
* codCharge is the provider's fee for cash collection (not charged to customer).
|
|
51
|
+
*/
|
|
52
|
+
interface ProviderCharges {
|
|
53
|
+
/** Base delivery charge from provider */
|
|
54
|
+
deliveryCharge: number;
|
|
55
|
+
/** COD charge (provider's fee, not customer-facing) */
|
|
56
|
+
codCharge: number;
|
|
57
|
+
/** Total charge (deliveryCharge + codCharge) */
|
|
58
|
+
totalCharge: number;
|
|
59
|
+
/** Currency code (default: BDT) */
|
|
60
|
+
currency?: string;
|
|
61
|
+
}
|
|
62
|
+
interface ShipmentTimelineEvent {
|
|
63
|
+
status: ShipmentStatus;
|
|
64
|
+
message?: string;
|
|
65
|
+
messageLocal?: string;
|
|
66
|
+
timestamp: string;
|
|
67
|
+
raw?: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
interface TrackingData {
|
|
70
|
+
trackingId: string;
|
|
71
|
+
status: ShipmentStatus;
|
|
72
|
+
providerStatus?: string;
|
|
73
|
+
currentLocation?: string;
|
|
74
|
+
estimatedDelivery?: string;
|
|
75
|
+
timeline: ShipmentTimelineEvent[];
|
|
76
|
+
}
|
|
77
|
+
interface TrackingResult {
|
|
78
|
+
orderId: string;
|
|
79
|
+
shipping: OrderShipping;
|
|
80
|
+
tracking: TrackingData;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Pickup store from RedX API
|
|
84
|
+
* Admin creates these via RedX dashboard
|
|
85
|
+
* Used for: selecting pickup location when creating shipments
|
|
86
|
+
*/
|
|
87
|
+
interface PickupStore {
|
|
88
|
+
/** RedX store ID */
|
|
89
|
+
id: number;
|
|
90
|
+
/** Store name */
|
|
91
|
+
name: string;
|
|
92
|
+
/** Store address */
|
|
93
|
+
address?: string;
|
|
94
|
+
/** Contact phone */
|
|
95
|
+
phone?: string;
|
|
96
|
+
/** Area ID (RedX area) - used for charge calculation */
|
|
97
|
+
areaId?: number;
|
|
98
|
+
/** Area name */
|
|
99
|
+
areaName?: string;
|
|
100
|
+
/** Creation date */
|
|
101
|
+
createdAt?: string;
|
|
102
|
+
}
|
|
103
|
+
interface ProviderConfig {
|
|
104
|
+
provider: LogisticsProvider;
|
|
105
|
+
apiUrl?: string;
|
|
106
|
+
apiKey?: string;
|
|
107
|
+
isActive: boolean;
|
|
108
|
+
isDefault?: boolean;
|
|
109
|
+
settings?: Record<string, unknown>;
|
|
110
|
+
}
|
|
111
|
+
interface LogisticsConfig {
|
|
112
|
+
_id: string;
|
|
113
|
+
defaultProvider: LogisticsProvider;
|
|
114
|
+
providers: ProviderConfig[];
|
|
115
|
+
supportedProviders: LogisticsProvider[];
|
|
116
|
+
}
|
|
117
|
+
interface CreateShipmentPayload {
|
|
118
|
+
/** Shipping provider */
|
|
119
|
+
provider: ShippingProvider;
|
|
120
|
+
/** Use provider API integration (e.g., RedX) */
|
|
121
|
+
useProviderApi?: boolean;
|
|
122
|
+
/** Pickup store ID for provider API shipments */
|
|
123
|
+
pickupStoreId?: number;
|
|
124
|
+
/** Parcel weight in grams */
|
|
125
|
+
weight?: number;
|
|
126
|
+
/** Special handling instructions */
|
|
127
|
+
instructions?: string;
|
|
128
|
+
/** Manual tracking number (for non-API shipments) */
|
|
129
|
+
trackingNumber?: string;
|
|
130
|
+
/** Manual consignment ID (optional) */
|
|
131
|
+
consignmentId?: string;
|
|
132
|
+
/** Manual tracking URL */
|
|
133
|
+
trackingUrl?: string;
|
|
134
|
+
/** Shipping label URL */
|
|
135
|
+
labelUrl?: string;
|
|
136
|
+
/** Estimated delivery date */
|
|
137
|
+
estimatedDelivery?: string;
|
|
138
|
+
/** Extra metadata for audit or provider data */
|
|
139
|
+
metadata?: Record<string, unknown>;
|
|
140
|
+
}
|
|
141
|
+
interface UpdateShipmentStatusPayload {
|
|
142
|
+
status: ShippingStatus | string;
|
|
143
|
+
note?: string;
|
|
144
|
+
metadata?: Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
interface CancelShipmentPayload {
|
|
147
|
+
reason?: string;
|
|
148
|
+
}
|
|
149
|
+
interface CancelShipmentResult {
|
|
150
|
+
orderId: string;
|
|
151
|
+
shipping: OrderShipping;
|
|
152
|
+
}
|
|
153
|
+
interface CalculateChargeParams {
|
|
154
|
+
/** Delivery area internalId from bd-areas */
|
|
155
|
+
deliveryAreaId: number;
|
|
156
|
+
/** COD amount in BDT (use 0 for prepaid) */
|
|
157
|
+
amount: number;
|
|
158
|
+
/** Parcel weight in grams (default: 500g) */
|
|
159
|
+
weight?: number;
|
|
160
|
+
/** Pickup area internalId (optional - auto-fetched from merchant's RedX pickup store) */
|
|
161
|
+
pickupAreaId?: number;
|
|
162
|
+
/** Specific provider (optional - uses default provider if not specified) */
|
|
163
|
+
provider?: ProviderName;
|
|
164
|
+
}
|
|
165
|
+
type DeliveryFeeSource = 'static' | 'provider';
|
|
166
|
+
/**
|
|
167
|
+
* Branch info for store pickup
|
|
168
|
+
*/
|
|
169
|
+
interface PickupBranchInfo {
|
|
170
|
+
branchId: string;
|
|
171
|
+
branchCode: string;
|
|
172
|
+
branchName: string;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Checkout settings from platform config
|
|
176
|
+
*/
|
|
177
|
+
interface CheckoutSettings {
|
|
178
|
+
/** Enable store pickup option */
|
|
179
|
+
allowStorePickup: boolean;
|
|
180
|
+
/** Branches available for pickup (empty = all active) */
|
|
181
|
+
pickupBranches: PickupBranchInfo[];
|
|
182
|
+
/** Fee source: 'static' (from zones) or 'provider' (from RedX API) */
|
|
183
|
+
deliveryFeeSource: DeliveryFeeSource;
|
|
184
|
+
/** Minimum order for free delivery (0 = disabled) */
|
|
185
|
+
freeDeliveryThreshold: number;
|
|
186
|
+
}
|
|
187
|
+
type DeliveryMethod = 'standard' | 'express' | 'pickup';
|
|
188
|
+
/**
|
|
189
|
+
* Delivery option for checkout UI
|
|
190
|
+
*/
|
|
191
|
+
interface DeliveryOption {
|
|
192
|
+
method: DeliveryMethod;
|
|
193
|
+
label: string;
|
|
194
|
+
price: number;
|
|
195
|
+
estimatedDays?: string;
|
|
196
|
+
/** For pickup: branch info */
|
|
197
|
+
pickupBranch?: PickupBranchInfo;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
type FetchOptions = Omit<RequestOptions, 'token' | 'organizationId'>;
|
|
201
|
+
/**
|
|
202
|
+
* Logistics API
|
|
203
|
+
*
|
|
204
|
+
* Manages logistics utilities and delivery charge calculation.
|
|
205
|
+
*
|
|
206
|
+
* NOTE: For area data (divisions, districts, areas), use @classytic/bd-areas directly:
|
|
207
|
+
* ```typescript
|
|
208
|
+
* import { searchAreas, getAreasByDistrict, getArea } from '@classytic/bd-areas';
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* Public Endpoints:
|
|
212
|
+
* - GET /logistics/charge - Calculate delivery charge via provider (RedX)
|
|
213
|
+
*
|
|
214
|
+
* Shipping Endpoints (Admin/Store Manager):
|
|
215
|
+
* - POST /orders/:id/shipping - Request shipping (manual or provider API)
|
|
216
|
+
* - PATCH /orders/:id/shipping - Update shipping status
|
|
217
|
+
* - GET /orders/:id/shipping - Get shipping info
|
|
218
|
+
* - GET /logistics/shipments/:id/track - Track shipment
|
|
219
|
+
* - POST /logistics/shipments/:id/cancel - Cancel shipment
|
|
220
|
+
*
|
|
221
|
+
* Admin Endpoints:
|
|
222
|
+
* - GET /logistics/config - Get config (read-only)
|
|
223
|
+
* - GET /logistics/pickup-stores - List pickup stores
|
|
224
|
+
* - GET /logistics/health/circuit-status - Get circuit breaker status
|
|
225
|
+
* - POST /logistics/health/circuit-reset/:provider - Reset circuit breaker
|
|
226
|
+
*/
|
|
227
|
+
declare class LogisticsApi extends BaseApi<OrderShipping, CreateShipmentPayload> {
|
|
228
|
+
constructor(config?: {});
|
|
229
|
+
/**
|
|
230
|
+
* Calculate delivery charge via provider API (e.g., RedX)
|
|
231
|
+
* GET /logistics/charge
|
|
232
|
+
*
|
|
233
|
+
* Use this to get real-time delivery charges from the logistics provider
|
|
234
|
+
* before creating an order.
|
|
235
|
+
*
|
|
236
|
+
* @param deliveryAreaId - Area internalId from @classytic/bd-areas
|
|
237
|
+
* @param amount - COD amount in BDT (use 0 for prepaid orders)
|
|
238
|
+
* @param weight - Parcel weight in grams (default: 500g)
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* import { searchAreas } from '@classytic/bd-areas';
|
|
242
|
+
*
|
|
243
|
+
* // 1. User selects area
|
|
244
|
+
* const areas = searchAreas('mohamm');
|
|
245
|
+
* const selectedArea = areas[0]; // { internalId: 1206, name: 'Mohammadpur', ... }
|
|
246
|
+
*
|
|
247
|
+
* // 2. Calculate delivery charge
|
|
248
|
+
* const { data } = await logisticsApi.calculateCharge({
|
|
249
|
+
* deliveryAreaId: selectedArea.internalId,
|
|
250
|
+
* amount: isCOD ? cartTotal : 0,
|
|
251
|
+
* });
|
|
252
|
+
* // { deliveryCharge: 60, codCharge: 15, totalCharge: 75 }
|
|
253
|
+
*/
|
|
254
|
+
calculateCharge({ deliveryAreaId, pickupAreaId, amount, weight, provider, options, }: {
|
|
255
|
+
deliveryAreaId: number;
|
|
256
|
+
pickupAreaId?: number;
|
|
257
|
+
amount: number;
|
|
258
|
+
weight?: number;
|
|
259
|
+
provider?: ProviderName;
|
|
260
|
+
options?: FetchOptions;
|
|
261
|
+
}): Promise<ApiResponse<ProviderCharges>>;
|
|
262
|
+
/**
|
|
263
|
+
* Get logistics configuration (read-only from .env)
|
|
264
|
+
* GET /logistics/config
|
|
265
|
+
*
|
|
266
|
+
* NOTE: Configuration is managed via environment variables.
|
|
267
|
+
* To change settings, update .env file and restart server.
|
|
268
|
+
*/
|
|
269
|
+
getConfig({ token, options, }: {
|
|
270
|
+
token: string;
|
|
271
|
+
options?: FetchOptions;
|
|
272
|
+
}): Promise<ApiResponse<LogisticsConfig>>;
|
|
273
|
+
/**
|
|
274
|
+
* Get pickup stores from RedX API
|
|
275
|
+
* GET /logistics/pickup-stores
|
|
276
|
+
*
|
|
277
|
+
* Pickup stores are created by admin in RedX dashboard.
|
|
278
|
+
* Use this to list available pickup locations when creating shipments.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* // Admin: List pickup stores for shipment creation
|
|
282
|
+
* const { data: stores } = await logisticsApi.getPickupStores({ token });
|
|
283
|
+
*
|
|
284
|
+
* // Display in dropdown for admin to select
|
|
285
|
+
* stores.forEach(store => {
|
|
286
|
+
* console.log(`${store.name} - ${store.areaName} (ID: ${store.id})`);
|
|
287
|
+
* });
|
|
288
|
+
*
|
|
289
|
+
* // Use selected store when creating shipment
|
|
290
|
+
* await logisticsApi.createShipment({
|
|
291
|
+
* token,
|
|
292
|
+
* data: {
|
|
293
|
+
* orderId: order._id,
|
|
294
|
+
* pickupStoreId: selectedStore.id, // From dropdown
|
|
295
|
+
* },
|
|
296
|
+
* });
|
|
297
|
+
*/
|
|
298
|
+
getPickupStores({ token, provider, options, }: {
|
|
299
|
+
token: string;
|
|
300
|
+
provider?: string;
|
|
301
|
+
options?: FetchOptions;
|
|
302
|
+
}): Promise<ApiResponse<PickupStore[]>>;
|
|
303
|
+
/**
|
|
304
|
+
* Request shipping for an order (manual or provider API)
|
|
305
|
+
* POST /orders/:id/shipping
|
|
306
|
+
*
|
|
307
|
+
* This updates the order.shipping object and optionally triggers
|
|
308
|
+
* provider API shipment creation when useProviderApi=true.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* // Manual: Record tracking details
|
|
312
|
+
* const shipping = await logisticsApi.createShipment({
|
|
313
|
+
* token,
|
|
314
|
+
* orderId: order._id,
|
|
315
|
+
* data: {
|
|
316
|
+
* provider: "other",
|
|
317
|
+
* trackingNumber: "COURIER123456",
|
|
318
|
+
* trackingUrl: "https://courier-website.com/track/COURIER123456",
|
|
319
|
+
* },
|
|
320
|
+
* });
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* // Provider API: Create shipment with pickup store
|
|
324
|
+
* const { data: stores } = await logisticsApi.getPickupStores({ token });
|
|
325
|
+
* const shipping = await logisticsApi.createShipment({
|
|
326
|
+
* token,
|
|
327
|
+
* orderId: order._id,
|
|
328
|
+
* data: {
|
|
329
|
+
* provider: "redx",
|
|
330
|
+
* useProviderApi: true,
|
|
331
|
+
* pickupStoreId: stores[0].id, // Select pickup location
|
|
332
|
+
* weight: 500, // Parcel weight in grams
|
|
333
|
+
* instructions: 'Handle with care',
|
|
334
|
+
* },
|
|
335
|
+
* });
|
|
336
|
+
*/
|
|
337
|
+
createShipment({ token, orderId, data, options, }: {
|
|
338
|
+
token: string;
|
|
339
|
+
orderId: string;
|
|
340
|
+
data: CreateShipmentPayload;
|
|
341
|
+
options?: FetchOptions;
|
|
342
|
+
}): Promise<ApiResponse<OrderShipping>>;
|
|
343
|
+
/**
|
|
344
|
+
* Get shipping info for an order
|
|
345
|
+
* GET /orders/:id/shipping
|
|
346
|
+
*/
|
|
347
|
+
getShipment({ token, id, options, }: {
|
|
348
|
+
token: string;
|
|
349
|
+
id: string;
|
|
350
|
+
options?: FetchOptions;
|
|
351
|
+
}): Promise<ApiResponse<OrderShipping | null>>;
|
|
352
|
+
/**
|
|
353
|
+
* Track shipment (fetch latest from provider)
|
|
354
|
+
* GET /logistics/shipments/:id/track
|
|
355
|
+
*
|
|
356
|
+
* @param id - Order ID or tracking number
|
|
357
|
+
*/
|
|
358
|
+
trackShipment({ token, id, options, }: {
|
|
359
|
+
token: string;
|
|
360
|
+
id: string;
|
|
361
|
+
options?: FetchOptions;
|
|
362
|
+
}): Promise<ApiResponse<TrackingResult>>;
|
|
363
|
+
/**
|
|
364
|
+
* Update shipping status for an order
|
|
365
|
+
* PATCH /orders/:id/shipping
|
|
366
|
+
*/
|
|
367
|
+
updateShipmentStatus({ token, id, data, options, }: {
|
|
368
|
+
token: string;
|
|
369
|
+
id: string;
|
|
370
|
+
data: UpdateShipmentStatusPayload;
|
|
371
|
+
options?: FetchOptions;
|
|
372
|
+
}): Promise<ApiResponse<OrderShipping>>;
|
|
373
|
+
/**
|
|
374
|
+
* Cancel shipment
|
|
375
|
+
* POST /logistics/shipments/:id/cancel
|
|
376
|
+
*
|
|
377
|
+
* @param id - Order ID or tracking number
|
|
378
|
+
*/
|
|
379
|
+
cancelShipment({ token, id, data, options, }: {
|
|
380
|
+
token: string;
|
|
381
|
+
id: string;
|
|
382
|
+
data?: CancelShipmentPayload;
|
|
383
|
+
options?: FetchOptions;
|
|
384
|
+
}): Promise<ApiResponse<CancelShipmentResult>>;
|
|
385
|
+
/**
|
|
386
|
+
* Get circuit breaker status for all providers
|
|
387
|
+
* GET /logistics/health/circuit-status
|
|
388
|
+
*/
|
|
389
|
+
getCircuitStatus({ token, options, }: {
|
|
390
|
+
token: string;
|
|
391
|
+
options?: FetchOptions;
|
|
392
|
+
}): Promise<ApiResponse<Record<string, {
|
|
393
|
+
state: string;
|
|
394
|
+
failureCount: number;
|
|
395
|
+
}>>>;
|
|
396
|
+
/**
|
|
397
|
+
* Reset circuit breaker for a provider
|
|
398
|
+
* POST /logistics/health/circuit-reset/:provider
|
|
399
|
+
*/
|
|
400
|
+
resetProviderCircuit({ token, provider, options, }: {
|
|
401
|
+
token: string;
|
|
402
|
+
provider: string;
|
|
403
|
+
options?: FetchOptions;
|
|
404
|
+
}): Promise<ApiResponse<{
|
|
405
|
+
message: string;
|
|
406
|
+
}>>;
|
|
407
|
+
}
|
|
408
|
+
declare const logisticsApi: LogisticsApi;
|
|
409
|
+
|
|
410
|
+
export { type Area as A, type CancelShipmentResult as C, type Division as D, LogisticsApi as L, type ProviderName as P, type ShipmentStatus as S, type TrackingData as T, type UpdateShipmentStatusPayload as U, type ProviderAreaIds as a, type District as b, type LogisticsProvider as c, type ProviderCharges as d, type ShipmentTimelineEvent as e, type TrackingResult as f, type PickupStore as g, type ProviderConfig as h, type LogisticsConfig as i, type CreateShipmentPayload as j, type CancelShipmentPayload as k, logisticsApi as l, type CalculateChargeParams as m, type DeliveryFeeSource as n, type PickupBranchInfo as o, type CheckoutSettings as p, type DeliveryMethod as q, type DeliveryOption as r };
|