@jazzdev/dpd-local-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/LICENSE +21 -0
- package/README.md +442 -0
- package/dist/index.d.mts +525 -0
- package/dist/index.d.ts +525 -0
- package/dist/index.js +1195 -0
- package/dist/index.mjs +1106 -0
- package/package.json +60 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
type TimestampType = Date | {
|
|
2
|
+
toDate(): Date;
|
|
3
|
+
} | string;
|
|
4
|
+
interface DPDModuleConfig {
|
|
5
|
+
credentials: DPDCredentials;
|
|
6
|
+
business: BusinessConfig;
|
|
7
|
+
services: ServiceConfig;
|
|
8
|
+
pricing: PricingConfig;
|
|
9
|
+
labels: LabelConfig;
|
|
10
|
+
notifications: NotificationConfig;
|
|
11
|
+
testMode: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface DPDCredentials {
|
|
14
|
+
accountNumber: string;
|
|
15
|
+
username: string;
|
|
16
|
+
password: string;
|
|
17
|
+
geoSession?: string;
|
|
18
|
+
geoSessionExpiry?: Date;
|
|
19
|
+
}
|
|
20
|
+
interface BusinessConfig {
|
|
21
|
+
name: string;
|
|
22
|
+
collectionAddress: {
|
|
23
|
+
organisation: string;
|
|
24
|
+
property: string;
|
|
25
|
+
street: string;
|
|
26
|
+
locality: string;
|
|
27
|
+
town: string;
|
|
28
|
+
county: string;
|
|
29
|
+
postcode: string;
|
|
30
|
+
countryCode: string;
|
|
31
|
+
};
|
|
32
|
+
contactName: string;
|
|
33
|
+
contactPhone: string;
|
|
34
|
+
contactEmail: string;
|
|
35
|
+
}
|
|
36
|
+
interface ServiceConfig {
|
|
37
|
+
enabled: DPDServiceCode[];
|
|
38
|
+
default: DPDServiceCode;
|
|
39
|
+
}
|
|
40
|
+
interface PricingConfig {
|
|
41
|
+
freeDeliveryThreshold: number;
|
|
42
|
+
flatDeliveryFee: number;
|
|
43
|
+
minimumOrderValue: number;
|
|
44
|
+
services: {
|
|
45
|
+
[key in DPDServiceCode]?: {
|
|
46
|
+
basePrice: number;
|
|
47
|
+
perKgPrice: number;
|
|
48
|
+
customerPrice: number;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
interface LabelConfig {
|
|
53
|
+
format: "thermal" | "a4";
|
|
54
|
+
printer: {
|
|
55
|
+
model: string;
|
|
56
|
+
dpi: number;
|
|
57
|
+
speed: number;
|
|
58
|
+
connection: "USB" | "Network";
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
interface NotificationConfig {
|
|
62
|
+
email: {
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
provider: "resend" | "sendgrid" | "ses";
|
|
65
|
+
fromEmail: string;
|
|
66
|
+
adminEmail: string;
|
|
67
|
+
};
|
|
68
|
+
sms: {
|
|
69
|
+
enabled: boolean;
|
|
70
|
+
provider: "dpd";
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
type DPDServiceCode = "12" | "07";
|
|
74
|
+
interface DPDAuthResponse {
|
|
75
|
+
data: {
|
|
76
|
+
geoSession: string;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
interface DPDAddress {
|
|
80
|
+
organisation: string;
|
|
81
|
+
property: string;
|
|
82
|
+
street: string;
|
|
83
|
+
locality: string;
|
|
84
|
+
town: string;
|
|
85
|
+
county: string;
|
|
86
|
+
postcode: string;
|
|
87
|
+
countryCode: string;
|
|
88
|
+
}
|
|
89
|
+
interface DPDContact {
|
|
90
|
+
name: string;
|
|
91
|
+
telephone: string;
|
|
92
|
+
email?: string;
|
|
93
|
+
}
|
|
94
|
+
interface DPDParcel {
|
|
95
|
+
weight: number;
|
|
96
|
+
width?: number;
|
|
97
|
+
height?: number;
|
|
98
|
+
depth?: number;
|
|
99
|
+
}
|
|
100
|
+
interface DPDShipmentRequest {
|
|
101
|
+
jobId: string | null;
|
|
102
|
+
collectionOnDelivery: boolean;
|
|
103
|
+
invoice: null;
|
|
104
|
+
collectionDate: string;
|
|
105
|
+
consolidate: boolean;
|
|
106
|
+
consignment: DPDConsignment[];
|
|
107
|
+
}
|
|
108
|
+
interface DPDConsignment {
|
|
109
|
+
consignmentNumber: string | null;
|
|
110
|
+
consignmentRef: string;
|
|
111
|
+
parcel: DPDParcel[];
|
|
112
|
+
collectionDetails: {
|
|
113
|
+
address: DPDAddress;
|
|
114
|
+
contactDetails: DPDContact;
|
|
115
|
+
};
|
|
116
|
+
deliveryDetails: {
|
|
117
|
+
address: DPDAddress;
|
|
118
|
+
contactDetails: DPDContact;
|
|
119
|
+
notificationDetails: {
|
|
120
|
+
email?: string;
|
|
121
|
+
mobile?: string;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
networkCode: DPDServiceCode;
|
|
125
|
+
numberOfParcels: number;
|
|
126
|
+
totalWeight: number;
|
|
127
|
+
shippingRef1: string;
|
|
128
|
+
shippingRef2?: string;
|
|
129
|
+
shippingRef3?: string;
|
|
130
|
+
deliveryInstructions?: string;
|
|
131
|
+
liabilityValue?: number;
|
|
132
|
+
liability?: boolean;
|
|
133
|
+
}
|
|
134
|
+
interface DPDShipmentResponse {
|
|
135
|
+
data?: {
|
|
136
|
+
shipmentId: number | string;
|
|
137
|
+
consolidated: boolean;
|
|
138
|
+
consignmentDetail?: Array<{
|
|
139
|
+
consignmentNumber: string;
|
|
140
|
+
parcelNumbers: string[];
|
|
141
|
+
}>;
|
|
142
|
+
consignment?: Array<{
|
|
143
|
+
consignmentNumber: string;
|
|
144
|
+
}>;
|
|
145
|
+
};
|
|
146
|
+
error?: DPDError | null;
|
|
147
|
+
}
|
|
148
|
+
interface DPDLabelRequest {
|
|
149
|
+
consignment: {
|
|
150
|
+
consignmentNumber: string;
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
interface DPDLabelResponse {
|
|
154
|
+
data: string;
|
|
155
|
+
error?: DPDError;
|
|
156
|
+
}
|
|
157
|
+
interface DPDError {
|
|
158
|
+
errorCode: string;
|
|
159
|
+
errorMessage: string;
|
|
160
|
+
obj: string;
|
|
161
|
+
errorType: string;
|
|
162
|
+
}
|
|
163
|
+
interface ShippingData {
|
|
164
|
+
provider: "dpd";
|
|
165
|
+
service: DPDServiceCode;
|
|
166
|
+
shipmentId: string | number;
|
|
167
|
+
consignmentNumber: string;
|
|
168
|
+
parcelNumber: string;
|
|
169
|
+
trackingUrl: string;
|
|
170
|
+
labelUrl: string;
|
|
171
|
+
status: ShipmentStatus;
|
|
172
|
+
statusHistory: ShipmentStatusUpdate[];
|
|
173
|
+
cost: {
|
|
174
|
+
basePrice: number;
|
|
175
|
+
weightCharge: number;
|
|
176
|
+
totalCost: number;
|
|
177
|
+
customerCharge: number;
|
|
178
|
+
};
|
|
179
|
+
weight: {
|
|
180
|
+
total: number;
|
|
181
|
+
unit: "kg";
|
|
182
|
+
};
|
|
183
|
+
parcels: number;
|
|
184
|
+
collectionDate: string;
|
|
185
|
+
estimatedDelivery: string;
|
|
186
|
+
actualDelivery?: string;
|
|
187
|
+
createdAt: TimestampType;
|
|
188
|
+
updatedAt: TimestampType;
|
|
189
|
+
}
|
|
190
|
+
type ShipmentStatus = "created" | "label_generated" | "collected" | "in_transit" | "out_for_delivery" | "delivered" | "failed" | "cancelled";
|
|
191
|
+
interface ShipmentStatusUpdate {
|
|
192
|
+
status: ShipmentStatus;
|
|
193
|
+
timestamp: TimestampType;
|
|
194
|
+
message?: string;
|
|
195
|
+
location?: string;
|
|
196
|
+
}
|
|
197
|
+
interface SavedAddress {
|
|
198
|
+
id: string;
|
|
199
|
+
userId: string;
|
|
200
|
+
isDefault: boolean;
|
|
201
|
+
label?: string;
|
|
202
|
+
organisation?: string;
|
|
203
|
+
property: string;
|
|
204
|
+
street: string;
|
|
205
|
+
locality?: string;
|
|
206
|
+
town: string;
|
|
207
|
+
county?: string;
|
|
208
|
+
postcode: string;
|
|
209
|
+
countryCode: string;
|
|
210
|
+
contactName: string;
|
|
211
|
+
contactPhone: string;
|
|
212
|
+
validated: boolean;
|
|
213
|
+
validatedAt?: TimestampType;
|
|
214
|
+
createdAt: TimestampType;
|
|
215
|
+
updatedAt: TimestampType;
|
|
216
|
+
}
|
|
217
|
+
interface DPDLogDocument {
|
|
218
|
+
id: string;
|
|
219
|
+
orderId: string;
|
|
220
|
+
consignmentNumber?: string;
|
|
221
|
+
operation: "auth" | "validate_address" | "create_shipment" | "generate_label" | "track_shipment" | "webhook";
|
|
222
|
+
request: {
|
|
223
|
+
endpoint: string;
|
|
224
|
+
method: string;
|
|
225
|
+
headers?: Record<string, string>;
|
|
226
|
+
body?: any;
|
|
227
|
+
};
|
|
228
|
+
response: {
|
|
229
|
+
status: number;
|
|
230
|
+
headers?: Record<string, string>;
|
|
231
|
+
body?: any;
|
|
232
|
+
};
|
|
233
|
+
duration: number;
|
|
234
|
+
success: boolean;
|
|
235
|
+
error?: {
|
|
236
|
+
code: string;
|
|
237
|
+
message: string;
|
|
238
|
+
stack?: string;
|
|
239
|
+
};
|
|
240
|
+
createdAt: TimestampType;
|
|
241
|
+
}
|
|
242
|
+
interface CreateShipmentParams {
|
|
243
|
+
orderId: string;
|
|
244
|
+
orderRef: string;
|
|
245
|
+
service: DPDServiceCode;
|
|
246
|
+
deliveryAddress: SavedAddress;
|
|
247
|
+
totalWeight: number;
|
|
248
|
+
numberOfParcels: number;
|
|
249
|
+
customerEmail: string;
|
|
250
|
+
customerPhone?: string;
|
|
251
|
+
deliveryInstructions?: string;
|
|
252
|
+
collectionDate: string;
|
|
253
|
+
}
|
|
254
|
+
interface CreateShipmentResult {
|
|
255
|
+
success: boolean;
|
|
256
|
+
shipmentId?: string | number;
|
|
257
|
+
consignmentNumber?: string;
|
|
258
|
+
parcelNumber?: string;
|
|
259
|
+
trackingUrl?: string;
|
|
260
|
+
labelUrl?: string;
|
|
261
|
+
error?: string;
|
|
262
|
+
errorCode?: string;
|
|
263
|
+
}
|
|
264
|
+
interface GenerateLabelParams {
|
|
265
|
+
shipmentId: string | number;
|
|
266
|
+
format: "thermal" | "a4";
|
|
267
|
+
}
|
|
268
|
+
interface GenerateLabelResult {
|
|
269
|
+
success: boolean;
|
|
270
|
+
labelUrl?: string;
|
|
271
|
+
labelData?: string;
|
|
272
|
+
error?: string;
|
|
273
|
+
}
|
|
274
|
+
interface ValidateAddressParams {
|
|
275
|
+
postcode: string;
|
|
276
|
+
town: string;
|
|
277
|
+
}
|
|
278
|
+
interface ValidateAddressResult {
|
|
279
|
+
valid: boolean;
|
|
280
|
+
serviceable: boolean;
|
|
281
|
+
message?: string;
|
|
282
|
+
}
|
|
283
|
+
interface TrackShipmentParams {
|
|
284
|
+
consignmentNumber: string;
|
|
285
|
+
}
|
|
286
|
+
interface TrackShipmentResult {
|
|
287
|
+
success: boolean;
|
|
288
|
+
status?: ShipmentStatus;
|
|
289
|
+
statusHistory?: ShipmentStatusUpdate[];
|
|
290
|
+
estimatedDelivery?: string;
|
|
291
|
+
actualDelivery?: string;
|
|
292
|
+
error?: string;
|
|
293
|
+
}
|
|
294
|
+
interface DatabaseAdapter {
|
|
295
|
+
getOrder(orderId: string): Promise<any>;
|
|
296
|
+
updateOrder(orderId: string, data: any): Promise<void>;
|
|
297
|
+
getSavedAddresses(userId: string): Promise<SavedAddress[]>;
|
|
298
|
+
getSavedAddress(addressId: string): Promise<SavedAddress | null>;
|
|
299
|
+
createSavedAddress(address: Omit<SavedAddress, "id">): Promise<string>;
|
|
300
|
+
updateSavedAddress(addressId: string, data: Partial<SavedAddress>): Promise<void>;
|
|
301
|
+
deleteSavedAddress(addressId: string): Promise<void>;
|
|
302
|
+
createDPDLog(log: Omit<DPDLogDocument, "id">): Promise<string>;
|
|
303
|
+
getDPDLogs(filters: LogFilters): Promise<DPDLogDocument[]>;
|
|
304
|
+
}
|
|
305
|
+
interface StorageAdapter {
|
|
306
|
+
uploadLabel(labelData: string, fileName: string): Promise<string>;
|
|
307
|
+
getLabel(fileName: string): Promise<string>;
|
|
308
|
+
deleteLabel(fileName: string): Promise<void>;
|
|
309
|
+
}
|
|
310
|
+
interface LogFilters {
|
|
311
|
+
orderId?: string;
|
|
312
|
+
consignmentNumber?: string;
|
|
313
|
+
operation?: DPDLogDocument["operation"];
|
|
314
|
+
success?: boolean;
|
|
315
|
+
startDate?: Date;
|
|
316
|
+
endDate?: Date;
|
|
317
|
+
limit?: number;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
declare const DPD_API: {
|
|
321
|
+
readonly BASE_URL: "https://api.dpdlocal.co.uk";
|
|
322
|
+
readonly ENDPOINTS: {
|
|
323
|
+
readonly AUTH: "/user/?action=login";
|
|
324
|
+
readonly SHIPMENT: "/shipping/shipment";
|
|
325
|
+
readonly LABEL: "/shipping/shipment";
|
|
326
|
+
readonly TRACKING: "/shipping/network/";
|
|
327
|
+
};
|
|
328
|
+
readonly TIMEOUT: 30000;
|
|
329
|
+
readonly RETRY_ATTEMPTS: 3;
|
|
330
|
+
readonly RETRY_DELAY: 1000;
|
|
331
|
+
};
|
|
332
|
+
declare const SERVICE_NAMES: Record<DPDServiceCode, string>;
|
|
333
|
+
declare const SERVICE_DESCRIPTIONS: Record<DPDServiceCode, string>;
|
|
334
|
+
interface CreateDPDConfigOptions {
|
|
335
|
+
credentials: DPDCredentials;
|
|
336
|
+
business: BusinessConfig;
|
|
337
|
+
pricing?: {
|
|
338
|
+
freeDeliveryThreshold?: number;
|
|
339
|
+
flatDeliveryFee?: number;
|
|
340
|
+
minimumOrderValue?: number;
|
|
341
|
+
services?: {
|
|
342
|
+
"12"?: {
|
|
343
|
+
basePrice: number;
|
|
344
|
+
perKgPrice: number;
|
|
345
|
+
customerPrice: number;
|
|
346
|
+
};
|
|
347
|
+
"07"?: {
|
|
348
|
+
basePrice: number;
|
|
349
|
+
perKgPrice: number;
|
|
350
|
+
customerPrice: number;
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
services?: {
|
|
355
|
+
enabled?: DPDServiceCode[];
|
|
356
|
+
default?: DPDServiceCode;
|
|
357
|
+
};
|
|
358
|
+
labels?: {
|
|
359
|
+
format?: "thermal" | "a4";
|
|
360
|
+
printer?: {
|
|
361
|
+
model: string;
|
|
362
|
+
dpi: number;
|
|
363
|
+
speed: number;
|
|
364
|
+
connection: "USB" | "Network";
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
notifications?: {
|
|
368
|
+
email?: {
|
|
369
|
+
enabled: boolean;
|
|
370
|
+
provider: "resend" | "sendgrid" | "ses";
|
|
371
|
+
fromEmail: string;
|
|
372
|
+
adminEmail: string;
|
|
373
|
+
};
|
|
374
|
+
sms?: {
|
|
375
|
+
enabled: boolean;
|
|
376
|
+
provider: "dpd";
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
testMode?: boolean;
|
|
380
|
+
}
|
|
381
|
+
declare function createDPDConfig(options: CreateDPDConfigOptions): DPDModuleConfig;
|
|
382
|
+
declare const calculateDeliveryFee: (subtotal: number, service: DPDServiceCode | undefined, config: DPDModuleConfig) => number;
|
|
383
|
+
declare const calculateDPDCost: (weight: number, service: DPDServiceCode, config: DPDModuleConfig) => number;
|
|
384
|
+
declare const qualifiesForFreeDelivery: (subtotal: number, config: DPDModuleConfig) => boolean;
|
|
385
|
+
declare const meetsMinimumOrderValue: (subtotal: number, config: DPDModuleConfig) => boolean;
|
|
386
|
+
declare const getNextCollectionDate: () => string;
|
|
387
|
+
declare const getEstimatedDeliveryDate: (_service: DPDServiceCode, collectionDate?: string) => string;
|
|
388
|
+
declare const getTrackingUrl: (parcelNumber: string) => string;
|
|
389
|
+
declare const isValidServiceCode: (code: string, config: DPDModuleConfig) => code is DPDServiceCode;
|
|
390
|
+
declare const getServiceName: (code: DPDServiceCode) => string;
|
|
391
|
+
declare const getServiceDescription: (code: DPDServiceCode) => string;
|
|
392
|
+
|
|
393
|
+
declare function authenticate(credentials: DPDCredentials): Promise<string>;
|
|
394
|
+
declare function getGeoSession(credentials: DPDCredentials, forceRefresh?: boolean): Promise<string>;
|
|
395
|
+
declare function clearGeoSession(): void;
|
|
396
|
+
declare function hasValidToken(): boolean;
|
|
397
|
+
declare function getTokenExpiry(): Date | null;
|
|
398
|
+
interface DPDRequestOptions {
|
|
399
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
400
|
+
endpoint: string;
|
|
401
|
+
body?: any;
|
|
402
|
+
headers?: Record<string, string>;
|
|
403
|
+
retry?: boolean;
|
|
404
|
+
retryAttempts?: number;
|
|
405
|
+
}
|
|
406
|
+
declare function authenticatedRequest<T = unknown>(credentials: DPDCredentials, options: DPDRequestOptions): Promise<T>;
|
|
407
|
+
declare function testConnection(credentials: DPDCredentials): Promise<{
|
|
408
|
+
success: boolean;
|
|
409
|
+
message: string;
|
|
410
|
+
}>;
|
|
411
|
+
|
|
412
|
+
declare function createShipment(credentials: DPDCredentials, params: CreateShipmentParams, businessConfig: any): Promise<CreateShipmentResult>;
|
|
413
|
+
declare function generateLabel(credentials: DPDCredentials, params: GenerateLabelParams): Promise<GenerateLabelResult>;
|
|
414
|
+
declare function validateAddress(_credentials: DPDCredentials, params: ValidateAddressParams): Promise<ValidateAddressResult>;
|
|
415
|
+
declare function trackShipment(credentials: DPDCredentials, params: TrackShipmentParams): Promise<TrackShipmentResult>;
|
|
416
|
+
declare function calculateParcels(totalWeight: number): number;
|
|
417
|
+
declare function validateServiceCode(code: string): code is DPDServiceCode;
|
|
418
|
+
declare function generateConsignmentRef(orderId: string): string;
|
|
419
|
+
|
|
420
|
+
declare function createCompleteShipment(orderId: string, params: Omit<CreateShipmentParams, "orderId">, config: DPDModuleConfig, dbAdapter: DatabaseAdapter, storageAdapter: StorageAdapter): Promise<CreateShipmentResult & {
|
|
421
|
+
labelUrl?: string;
|
|
422
|
+
}>;
|
|
423
|
+
declare function generateAndUploadLabel(shipmentId: string | number, consignmentNumber: string, format: "thermal" | "a4" | undefined, credentials: DPDCredentials, storageAdapter: StorageAdapter): Promise<GenerateLabelResult>;
|
|
424
|
+
declare function validateDeliveryAddress(params: ValidateAddressParams, credentials: DPDCredentials): Promise<ValidateAddressResult>;
|
|
425
|
+
declare function saveAddress(userId: string, address: Omit<SavedAddress, "id" | "userId" | "createdAt" | "updatedAt">, credentials: DPDCredentials, dbAdapter: DatabaseAdapter): Promise<string>;
|
|
426
|
+
declare function getSavedAddresses(userId: string, dbAdapter: DatabaseAdapter): Promise<SavedAddress[]>;
|
|
427
|
+
declare function getSavedAddress(addressId: string, dbAdapter: DatabaseAdapter): Promise<SavedAddress | null>;
|
|
428
|
+
declare function updateSavedAddress(addressId: string, data: Partial<SavedAddress>, dbAdapter: DatabaseAdapter): Promise<void>;
|
|
429
|
+
declare function deleteSavedAddress(addressId: string, dbAdapter: DatabaseAdapter): Promise<void>;
|
|
430
|
+
declare function getLabelUrl(consignmentNumber: string, storageAdapter: StorageAdapter): Promise<string | null>;
|
|
431
|
+
declare function regenerateLabel(shipmentId: string | number, consignmentNumber: string, format: "thermal" | "a4" | undefined, credentials: DPDCredentials, storageAdapter: StorageAdapter): Promise<GenerateLabelResult>;
|
|
432
|
+
declare function testDPDConnection(credentials: DPDCredentials): Promise<{
|
|
433
|
+
success: boolean;
|
|
434
|
+
message: string;
|
|
435
|
+
}>;
|
|
436
|
+
declare function getAuthStatus(credentials: DPDCredentials): Promise<{
|
|
437
|
+
authenticated: boolean;
|
|
438
|
+
expiresAt?: Date | null;
|
|
439
|
+
}>;
|
|
440
|
+
declare const _default: {
|
|
441
|
+
createCompleteShipment: typeof createCompleteShipment;
|
|
442
|
+
generateAndUploadLabel: typeof generateAndUploadLabel;
|
|
443
|
+
validateDeliveryAddress: typeof validateDeliveryAddress;
|
|
444
|
+
saveAddress: typeof saveAddress;
|
|
445
|
+
getSavedAddresses: typeof getSavedAddresses;
|
|
446
|
+
getSavedAddress: typeof getSavedAddress;
|
|
447
|
+
updateSavedAddress: typeof updateSavedAddress;
|
|
448
|
+
deleteSavedAddress: typeof deleteSavedAddress;
|
|
449
|
+
getLabelUrl: typeof getLabelUrl;
|
|
450
|
+
regenerateLabel: typeof regenerateLabel;
|
|
451
|
+
testDPDConnection: typeof testDPDConnection;
|
|
452
|
+
getAuthStatus: typeof getAuthStatus;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
declare function generateEncryptionKey(): string;
|
|
456
|
+
declare function encrypt(text: string): string;
|
|
457
|
+
declare function decrypt(encryptedHex: string): string;
|
|
458
|
+
declare function encryptCredentials(credentials: {
|
|
459
|
+
accountNumber: string;
|
|
460
|
+
username: string;
|
|
461
|
+
password: string;
|
|
462
|
+
}): {
|
|
463
|
+
accountNumber: string;
|
|
464
|
+
username: string;
|
|
465
|
+
passwordHash: string;
|
|
466
|
+
};
|
|
467
|
+
declare function decryptCredentials(encryptedCredentials: {
|
|
468
|
+
accountNumber: string;
|
|
469
|
+
username: string;
|
|
470
|
+
passwordHash: string;
|
|
471
|
+
}): {
|
|
472
|
+
accountNumber: string;
|
|
473
|
+
username: string;
|
|
474
|
+
password: string;
|
|
475
|
+
};
|
|
476
|
+
declare function hash(data: string): string;
|
|
477
|
+
declare function verifyHash(data: string, hashToVerify: string): boolean;
|
|
478
|
+
|
|
479
|
+
interface LoggerConfig {
|
|
480
|
+
enabled: boolean;
|
|
481
|
+
logToConsole: boolean;
|
|
482
|
+
logToDatabase: boolean;
|
|
483
|
+
adapter?: DatabaseAdapter;
|
|
484
|
+
}
|
|
485
|
+
declare function configureLogger(newConfig: Partial<LoggerConfig>): void;
|
|
486
|
+
declare function setLoggerAdapter(adapter: DatabaseAdapter): void;
|
|
487
|
+
interface LogParams {
|
|
488
|
+
orderId: string;
|
|
489
|
+
consignmentNumber?: string;
|
|
490
|
+
operation: DPDLogDocument["operation"];
|
|
491
|
+
request: {
|
|
492
|
+
endpoint: string;
|
|
493
|
+
method: string;
|
|
494
|
+
headers?: Record<string, string>;
|
|
495
|
+
body?: any;
|
|
496
|
+
};
|
|
497
|
+
response: {
|
|
498
|
+
status: number;
|
|
499
|
+
headers?: Record<string, string>;
|
|
500
|
+
body?: any;
|
|
501
|
+
};
|
|
502
|
+
duration: number;
|
|
503
|
+
success: boolean;
|
|
504
|
+
error?: {
|
|
505
|
+
code: string;
|
|
506
|
+
message: string;
|
|
507
|
+
stack?: string;
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
declare function logOperation(params: LogParams): Promise<void>;
|
|
511
|
+
declare function startTimer(): () => number;
|
|
512
|
+
declare function loggedOperation<T>(params: {
|
|
513
|
+
orderId: string;
|
|
514
|
+
consignmentNumber?: string;
|
|
515
|
+
operation: DPDLogDocument["operation"];
|
|
516
|
+
endpoint: string;
|
|
517
|
+
method: string;
|
|
518
|
+
requestBody?: any;
|
|
519
|
+
}, operation: () => Promise<{
|
|
520
|
+
data: T;
|
|
521
|
+
status: number;
|
|
522
|
+
headers?: Record<string, string>;
|
|
523
|
+
}>): Promise<T>;
|
|
524
|
+
|
|
525
|
+
export { type BusinessConfig, type CreateShipmentParams, type CreateShipmentResult, type DPDAddress, type DPDAuthResponse, type DPDConsignment, type DPDContact, type DPDCredentials, type DPDError, type DPDLabelRequest, type DPDLabelResponse, type DPDLogDocument, type DPDModuleConfig, type DPDParcel, _default as DPDService, type DPDServiceCode, type DPDShipmentRequest, type DPDShipmentResponse, DPD_API, type DatabaseAdapter, type GenerateLabelParams, type GenerateLabelResult, type LabelConfig, type LogFilters, type NotificationConfig, type PricingConfig, SERVICE_DESCRIPTIONS, SERVICE_NAMES, type SavedAddress, type ServiceConfig, type ShipmentStatus, type ShipmentStatusUpdate, type ShippingData, type StorageAdapter, type TimestampType, type TrackShipmentParams, type TrackShipmentResult, type ValidateAddressParams, type ValidateAddressResult, authenticate, authenticatedRequest, calculateDPDCost, calculateDeliveryFee, calculateParcels, clearGeoSession, configureLogger, createCompleteShipment, createDPDConfig, createShipment, decrypt, decryptCredentials, deleteSavedAddress, encrypt, encryptCredentials, generateAndUploadLabel, generateConsignmentRef, generateEncryptionKey, generateLabel, getAuthStatus, getEstimatedDeliveryDate, getGeoSession, getLabelUrl, getNextCollectionDate, getSavedAddress, getSavedAddresses, getServiceDescription, getServiceName, getTokenExpiry, getTrackingUrl, hasValidToken, hash, isValidServiceCode, logOperation, loggedOperation, meetsMinimumOrderValue, qualifiesForFreeDelivery, regenerateLabel, saveAddress, setLoggerAdapter, startTimer, testConnection, testDPDConnection, trackShipment, updateSavedAddress, validateAddress, validateDeliveryAddress, validateServiceCode, verifyHash };
|