@jazzdev/dpd-local-sdk 1.0.0 → 1.0.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/README.md +63 -60
- package/dist/index.d.mts +21 -21
- package/dist/index.d.ts +21 -21
- package/dist/index.js +6 -2
- package/dist/index.mjs +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
> TypeScript SDK for integrating DPD Local shipping services into your application. Database-agnostic, framework-independent, and production-ready.
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/@
|
|
5
|
+
[](https://www.npmjs.com/package/@jazzdev/dpd-local-sdk)
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
11
|
✅ **Complete DPD Integration**
|
|
12
|
+
|
|
12
13
|
- Create shipments and generate labels
|
|
13
14
|
- Address validation (UK postcodes)
|
|
14
15
|
- Real-time tracking
|
|
@@ -16,11 +17,13 @@
|
|
|
16
17
|
- Service selection (Next Day, By 12 PM)
|
|
17
18
|
|
|
18
19
|
✅ **Database-Agnostic**
|
|
20
|
+
|
|
19
21
|
- Works with any database (Firestore, MongoDB, PostgreSQL, etc.)
|
|
20
22
|
- Adapter pattern for easy integration
|
|
21
23
|
- TypeScript-first design
|
|
22
24
|
|
|
23
25
|
✅ **Production-Ready**
|
|
26
|
+
|
|
24
27
|
- Battle-tested in production
|
|
25
28
|
- Comprehensive error handling
|
|
26
29
|
- Automatic token management
|
|
@@ -28,6 +31,7 @@
|
|
|
28
31
|
- Detailed logging
|
|
29
32
|
|
|
30
33
|
✅ **Developer-Friendly**
|
|
34
|
+
|
|
31
35
|
- Full TypeScript support
|
|
32
36
|
- Comprehensive JSDoc comments
|
|
33
37
|
- Example implementations included
|
|
@@ -36,11 +40,11 @@
|
|
|
36
40
|
## Installation
|
|
37
41
|
|
|
38
42
|
```bash
|
|
39
|
-
npm install @
|
|
43
|
+
npm install @jazzdev/dpd-local-sdk
|
|
40
44
|
# or
|
|
41
|
-
yarn add @
|
|
45
|
+
yarn add @jazzdev/dpd-local-sdk
|
|
42
46
|
# or
|
|
43
|
-
pnpm add @
|
|
47
|
+
pnpm add @jazzdev/dpd-local-sdk
|
|
44
48
|
```
|
|
45
49
|
|
|
46
50
|
## Quick Start
|
|
@@ -48,7 +52,7 @@ pnpm add @your-org/dpd-local-sdk
|
|
|
48
52
|
### 1. Create Configuration
|
|
49
53
|
|
|
50
54
|
```typescript
|
|
51
|
-
import { createDPDConfig } from
|
|
55
|
+
import { createDPDConfig } from '@jazzdev/dpd-local-sdk';
|
|
52
56
|
|
|
53
57
|
const config = createDPDConfig({
|
|
54
58
|
credentials: {
|
|
@@ -57,20 +61,20 @@ const config = createDPDConfig({
|
|
|
57
61
|
password: process.env.DPD_PASSWORD!,
|
|
58
62
|
},
|
|
59
63
|
business: {
|
|
60
|
-
name:
|
|
64
|
+
name: 'Your Business Name',
|
|
61
65
|
collectionAddress: {
|
|
62
|
-
organisation:
|
|
63
|
-
property:
|
|
64
|
-
street:
|
|
65
|
-
locality:
|
|
66
|
-
town:
|
|
67
|
-
county:
|
|
68
|
-
postcode:
|
|
69
|
-
countryCode:
|
|
66
|
+
organisation: 'Your Company Ltd',
|
|
67
|
+
property: 'Unit 1',
|
|
68
|
+
street: '123 Main Street',
|
|
69
|
+
locality: '',
|
|
70
|
+
town: 'London',
|
|
71
|
+
county: 'Greater London',
|
|
72
|
+
postcode: 'SW1A 1AA',
|
|
73
|
+
countryCode: 'GB',
|
|
70
74
|
},
|
|
71
|
-
contactName:
|
|
72
|
-
contactPhone:
|
|
73
|
-
contactEmail:
|
|
75
|
+
contactName: 'Your Name',
|
|
76
|
+
contactPhone: '+441234567890',
|
|
77
|
+
contactEmail: 'shipping@yourcompany.com',
|
|
74
78
|
},
|
|
75
79
|
});
|
|
76
80
|
```
|
|
@@ -82,7 +86,7 @@ The SDK requires two adapters to work with your database and storage:
|
|
|
82
86
|
#### Database Adapter
|
|
83
87
|
|
|
84
88
|
```typescript
|
|
85
|
-
import { DatabaseAdapter } from
|
|
89
|
+
import { DatabaseAdapter } from '@jazzdev/dpd-local-sdk';
|
|
86
90
|
|
|
87
91
|
const myDatabaseAdapter: DatabaseAdapter = {
|
|
88
92
|
async getOrder(orderId: string) {
|
|
@@ -137,7 +141,7 @@ const myDatabaseAdapter: DatabaseAdapter = {
|
|
|
137
141
|
#### Storage Adapter
|
|
138
142
|
|
|
139
143
|
```typescript
|
|
140
|
-
import { StorageAdapter } from
|
|
144
|
+
import { StorageAdapter } from '@jazzdev/dpd-local-sdk';
|
|
141
145
|
|
|
142
146
|
const myStorageAdapter: StorageAdapter = {
|
|
143
147
|
async uploadLabel(labelData: string, fileName: string) {
|
|
@@ -161,34 +165,34 @@ const myStorageAdapter: StorageAdapter = {
|
|
|
161
165
|
### 3. Create a Shipment
|
|
162
166
|
|
|
163
167
|
```typescript
|
|
164
|
-
import { createCompleteShipment } from
|
|
168
|
+
import { createCompleteShipment } from '@jazzdev/dpd-local-sdk';
|
|
165
169
|
|
|
166
170
|
const result = await createCompleteShipment(
|
|
167
|
-
|
|
171
|
+
'ORDER123', // Your order ID
|
|
168
172
|
{
|
|
169
|
-
orderRef:
|
|
170
|
-
service:
|
|
173
|
+
orderRef: 'ORDER123',
|
|
174
|
+
service: '12', // Next Day Delivery
|
|
171
175
|
deliveryAddress: {
|
|
172
|
-
id:
|
|
173
|
-
userId:
|
|
176
|
+
id: 'addr_123',
|
|
177
|
+
userId: 'user_123',
|
|
174
178
|
isDefault: true,
|
|
175
|
-
property:
|
|
176
|
-
street:
|
|
177
|
-
town:
|
|
178
|
-
postcode:
|
|
179
|
-
countryCode:
|
|
180
|
-
contactName:
|
|
181
|
-
contactPhone:
|
|
179
|
+
property: '10',
|
|
180
|
+
street: 'Downing Street',
|
|
181
|
+
town: 'London',
|
|
182
|
+
postcode: 'SW1A 2AA',
|
|
183
|
+
countryCode: 'GB',
|
|
184
|
+
contactName: 'John Doe',
|
|
185
|
+
contactPhone: '+441234567890',
|
|
182
186
|
validated: true,
|
|
183
187
|
createdAt: new Date(),
|
|
184
188
|
updatedAt: new Date(),
|
|
185
189
|
},
|
|
186
190
|
totalWeight: 2.5, // kg
|
|
187
191
|
numberOfParcels: 1,
|
|
188
|
-
customerEmail:
|
|
189
|
-
customerPhone:
|
|
190
|
-
deliveryInstructions:
|
|
191
|
-
collectionDate:
|
|
192
|
+
customerEmail: 'customer@example.com',
|
|
193
|
+
customerPhone: '+441234567890',
|
|
194
|
+
deliveryInstructions: 'Leave with neighbor if not home',
|
|
195
|
+
collectionDate: '2024-01-15',
|
|
192
196
|
},
|
|
193
197
|
config,
|
|
194
198
|
myDatabaseAdapter,
|
|
@@ -196,11 +200,11 @@ const result = await createCompleteShipment(
|
|
|
196
200
|
);
|
|
197
201
|
|
|
198
202
|
if (result.success) {
|
|
199
|
-
console.log(
|
|
200
|
-
console.log(
|
|
201
|
-
console.log(
|
|
203
|
+
console.log('Shipment created!');
|
|
204
|
+
console.log('Tracking URL:', result.trackingUrl);
|
|
205
|
+
console.log('Label URL:', result.labelUrl);
|
|
202
206
|
} else {
|
|
203
|
-
console.error(
|
|
207
|
+
console.error('Failed:', result.error);
|
|
204
208
|
}
|
|
205
209
|
```
|
|
206
210
|
|
|
@@ -213,6 +217,7 @@ if (result.success) {
|
|
|
213
217
|
Creates a complete DPD module configuration.
|
|
214
218
|
|
|
215
219
|
**Parameters:**
|
|
220
|
+
|
|
216
221
|
- `options.credentials` - DPD API credentials
|
|
217
222
|
- `options.business` - Your business information
|
|
218
223
|
- `options.pricing` (optional) - Custom pricing configuration
|
|
@@ -230,6 +235,7 @@ Creates a complete DPD module configuration.
|
|
|
230
235
|
Create a complete shipment including label generation and database update.
|
|
231
236
|
|
|
232
237
|
**Parameters:**
|
|
238
|
+
|
|
233
239
|
- `orderId` - Your internal order ID
|
|
234
240
|
- `params` - Shipment parameters (address, weight, service, etc.)
|
|
235
241
|
- `config` - DPD configuration
|
|
@@ -243,6 +249,7 @@ Create a complete shipment including label generation and database update.
|
|
|
243
249
|
Validate a UK delivery address using postcodes.io API.
|
|
244
250
|
|
|
245
251
|
**Parameters:**
|
|
252
|
+
|
|
246
253
|
- `params.postcode` - UK postcode
|
|
247
254
|
- `params.town` - Town/city name
|
|
248
255
|
- `credentials` - DPD credentials
|
|
@@ -254,6 +261,7 @@ Validate a UK delivery address using postcodes.io API.
|
|
|
254
261
|
Test connection to DPD API.
|
|
255
262
|
|
|
256
263
|
**Parameters:**
|
|
264
|
+
|
|
257
265
|
- `credentials` - DPD credentials
|
|
258
266
|
|
|
259
267
|
**Returns:** `Promise<{ success: boolean; message: string }>`
|
|
@@ -286,8 +294,8 @@ Generate DPD tracking URL.
|
|
|
286
294
|
|
|
287
295
|
```typescript
|
|
288
296
|
// app/api/shipping/create/route.ts
|
|
289
|
-
import { createCompleteShipment } from
|
|
290
|
-
import { NextRequest, NextResponse } from
|
|
297
|
+
import { createCompleteShipment } from '@jazzdev/dpd-local-sdk';
|
|
298
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
291
299
|
|
|
292
300
|
export async function POST(req: NextRequest) {
|
|
293
301
|
const { orderId, deliveryAddress, weight } = await req.json();
|
|
@@ -296,12 +304,12 @@ export async function POST(req: NextRequest) {
|
|
|
296
304
|
orderId,
|
|
297
305
|
{
|
|
298
306
|
orderRef: orderId,
|
|
299
|
-
service:
|
|
307
|
+
service: '12',
|
|
300
308
|
deliveryAddress,
|
|
301
309
|
totalWeight: weight,
|
|
302
310
|
numberOfParcels: 1,
|
|
303
311
|
customerEmail: deliveryAddress.contactEmail,
|
|
304
|
-
collectionDate: new Date().toISOString().split(
|
|
312
|
+
collectionDate: new Date().toISOString().split('T')[0],
|
|
305
313
|
},
|
|
306
314
|
dpdConfig,
|
|
307
315
|
databaseAdapter,
|
|
@@ -315,24 +323,24 @@ export async function POST(req: NextRequest) {
|
|
|
315
323
|
### Express.js
|
|
316
324
|
|
|
317
325
|
```typescript
|
|
318
|
-
import express from
|
|
319
|
-
import { createCompleteShipment } from
|
|
326
|
+
import express from 'express';
|
|
327
|
+
import { createCompleteShipment } from '@jazzdev/dpd-local-sdk';
|
|
320
328
|
|
|
321
329
|
const app = express();
|
|
322
330
|
|
|
323
|
-
app.post(
|
|
331
|
+
app.post('/api/shipping/create', async (req, res) => {
|
|
324
332
|
const { orderId, deliveryAddress, weight } = req.body;
|
|
325
333
|
|
|
326
334
|
const result = await createCompleteShipment(
|
|
327
335
|
orderId,
|
|
328
336
|
{
|
|
329
337
|
orderRef: orderId,
|
|
330
|
-
service:
|
|
338
|
+
service: '12',
|
|
331
339
|
deliveryAddress,
|
|
332
340
|
totalWeight: weight,
|
|
333
341
|
numberOfParcels: 1,
|
|
334
342
|
customerEmail: deliveryAddress.contactEmail,
|
|
335
|
-
collectionDate: new Date().toISOString().split(
|
|
343
|
+
collectionDate: new Date().toISOString().split('T')[0],
|
|
336
344
|
},
|
|
337
345
|
dpdConfig,
|
|
338
346
|
databaseAdapter,
|
|
@@ -361,10 +369,10 @@ NODE_ENV=production
|
|
|
361
369
|
### Generating Encryption Key
|
|
362
370
|
|
|
363
371
|
```typescript
|
|
364
|
-
import { generateEncryptionKey } from
|
|
372
|
+
import { generateEncryptionKey } from '@jazzdev/dpd-local-sdk';
|
|
365
373
|
|
|
366
374
|
const key = generateEncryptionKey();
|
|
367
|
-
console.log(
|
|
375
|
+
console.log('DPD_ENCRYPTION_KEY=' + key);
|
|
368
376
|
```
|
|
369
377
|
|
|
370
378
|
## Adapter Examples
|
|
@@ -416,7 +424,7 @@ import type {
|
|
|
416
424
|
ShippingData,
|
|
417
425
|
DatabaseAdapter,
|
|
418
426
|
StorageAdapter,
|
|
419
|
-
} from
|
|
427
|
+
} from '@jazzdev/dpd-local-sdk';
|
|
420
428
|
```
|
|
421
429
|
|
|
422
430
|
## Contributing
|
|
@@ -425,18 +433,13 @@ Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for de
|
|
|
425
433
|
|
|
426
434
|
## License
|
|
427
435
|
|
|
428
|
-
MIT © [
|
|
436
|
+
MIT © [Taiow Babarinde](https://github.com/TheJazzDev)
|
|
429
437
|
|
|
430
438
|
## Support
|
|
431
439
|
|
|
432
|
-
- 📧 Email:
|
|
433
|
-
- 🐛 Issues: [GitHub Issues](https://github.com/
|
|
434
|
-
- 📖 Documentation: [Full Docs](https://docs.your-org.com/dpd-local-sdk)
|
|
440
|
+
- 📧 Email: babsman4all@gmail.com
|
|
441
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/TheJazzDev/dpd-local-sdk.git/issues)
|
|
435
442
|
|
|
436
443
|
## Changelog
|
|
437
444
|
|
|
438
445
|
See [CHANGELOG.md](CHANGELOG.md) for release history.
|
|
439
|
-
|
|
440
|
-
---
|
|
441
|
-
|
|
442
|
-
**Made with ❤️ for the developer community**
|
package/dist/index.d.mts
CHANGED
|
@@ -50,27 +50,27 @@ interface PricingConfig {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
interface LabelConfig {
|
|
53
|
-
format:
|
|
53
|
+
format: 'thermal' | 'a4';
|
|
54
54
|
printer: {
|
|
55
55
|
model: string;
|
|
56
56
|
dpi: number;
|
|
57
57
|
speed: number;
|
|
58
|
-
connection:
|
|
58
|
+
connection: 'USB' | 'Network';
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
interface NotificationConfig {
|
|
62
62
|
email: {
|
|
63
63
|
enabled: boolean;
|
|
64
|
-
provider:
|
|
64
|
+
provider: 'resend' | 'sendgrid' | 'ses';
|
|
65
65
|
fromEmail: string;
|
|
66
66
|
adminEmail: string;
|
|
67
67
|
};
|
|
68
68
|
sms: {
|
|
69
69
|
enabled: boolean;
|
|
70
|
-
provider:
|
|
70
|
+
provider: 'dpd';
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
type DPDServiceCode =
|
|
73
|
+
type DPDServiceCode = '12' | '07';
|
|
74
74
|
interface DPDAuthResponse {
|
|
75
75
|
data: {
|
|
76
76
|
geoSession: string;
|
|
@@ -161,7 +161,7 @@ interface DPDError {
|
|
|
161
161
|
errorType: string;
|
|
162
162
|
}
|
|
163
163
|
interface ShippingData {
|
|
164
|
-
provider:
|
|
164
|
+
provider: 'dpd';
|
|
165
165
|
service: DPDServiceCode;
|
|
166
166
|
shipmentId: string | number;
|
|
167
167
|
consignmentNumber: string;
|
|
@@ -178,7 +178,7 @@ interface ShippingData {
|
|
|
178
178
|
};
|
|
179
179
|
weight: {
|
|
180
180
|
total: number;
|
|
181
|
-
unit:
|
|
181
|
+
unit: 'kg';
|
|
182
182
|
};
|
|
183
183
|
parcels: number;
|
|
184
184
|
collectionDate: string;
|
|
@@ -187,7 +187,7 @@ interface ShippingData {
|
|
|
187
187
|
createdAt: TimestampType;
|
|
188
188
|
updatedAt: TimestampType;
|
|
189
189
|
}
|
|
190
|
-
type ShipmentStatus =
|
|
190
|
+
type ShipmentStatus = 'created' | 'label_generated' | 'collected' | 'in_transit' | 'out_for_delivery' | 'delivered' | 'failed' | 'cancelled';
|
|
191
191
|
interface ShipmentStatusUpdate {
|
|
192
192
|
status: ShipmentStatus;
|
|
193
193
|
timestamp: TimestampType;
|
|
@@ -218,7 +218,7 @@ interface DPDLogDocument {
|
|
|
218
218
|
id: string;
|
|
219
219
|
orderId: string;
|
|
220
220
|
consignmentNumber?: string;
|
|
221
|
-
operation:
|
|
221
|
+
operation: 'auth' | 'validate_address' | 'create_shipment' | 'generate_label' | 'track_shipment' | 'webhook';
|
|
222
222
|
request: {
|
|
223
223
|
endpoint: string;
|
|
224
224
|
method: string;
|
|
@@ -263,7 +263,7 @@ interface CreateShipmentResult {
|
|
|
263
263
|
}
|
|
264
264
|
interface GenerateLabelParams {
|
|
265
265
|
shipmentId: string | number;
|
|
266
|
-
format:
|
|
266
|
+
format: 'thermal' | 'a4';
|
|
267
267
|
}
|
|
268
268
|
interface GenerateLabelResult {
|
|
269
269
|
success: boolean;
|
|
@@ -296,10 +296,10 @@ interface DatabaseAdapter {
|
|
|
296
296
|
updateOrder(orderId: string, data: any): Promise<void>;
|
|
297
297
|
getSavedAddresses(userId: string): Promise<SavedAddress[]>;
|
|
298
298
|
getSavedAddress(addressId: string): Promise<SavedAddress | null>;
|
|
299
|
-
createSavedAddress(address: Omit<SavedAddress,
|
|
299
|
+
createSavedAddress(address: Omit<SavedAddress, 'id'>): Promise<string>;
|
|
300
300
|
updateSavedAddress(addressId: string, data: Partial<SavedAddress>): Promise<void>;
|
|
301
301
|
deleteSavedAddress(addressId: string): Promise<void>;
|
|
302
|
-
createDPDLog(log: Omit<DPDLogDocument,
|
|
302
|
+
createDPDLog(log: Omit<DPDLogDocument, 'id'>): Promise<string>;
|
|
303
303
|
getDPDLogs(filters: LogFilters): Promise<DPDLogDocument[]>;
|
|
304
304
|
}
|
|
305
305
|
interface StorageAdapter {
|
|
@@ -310,7 +310,7 @@ interface StorageAdapter {
|
|
|
310
310
|
interface LogFilters {
|
|
311
311
|
orderId?: string;
|
|
312
312
|
consignmentNumber?: string;
|
|
313
|
-
operation?: DPDLogDocument[
|
|
313
|
+
operation?: DPDLogDocument['operation'];
|
|
314
314
|
success?: boolean;
|
|
315
315
|
startDate?: Date;
|
|
316
316
|
endDate?: Date;
|
|
@@ -339,12 +339,12 @@ interface CreateDPDConfigOptions {
|
|
|
339
339
|
flatDeliveryFee?: number;
|
|
340
340
|
minimumOrderValue?: number;
|
|
341
341
|
services?: {
|
|
342
|
-
|
|
342
|
+
'12'?: {
|
|
343
343
|
basePrice: number;
|
|
344
344
|
perKgPrice: number;
|
|
345
345
|
customerPrice: number;
|
|
346
346
|
};
|
|
347
|
-
|
|
347
|
+
'07'?: {
|
|
348
348
|
basePrice: number;
|
|
349
349
|
perKgPrice: number;
|
|
350
350
|
customerPrice: number;
|
|
@@ -356,24 +356,24 @@ interface CreateDPDConfigOptions {
|
|
|
356
356
|
default?: DPDServiceCode;
|
|
357
357
|
};
|
|
358
358
|
labels?: {
|
|
359
|
-
format?:
|
|
359
|
+
format?: 'thermal' | 'a4';
|
|
360
360
|
printer?: {
|
|
361
361
|
model: string;
|
|
362
362
|
dpi: number;
|
|
363
363
|
speed: number;
|
|
364
|
-
connection:
|
|
364
|
+
connection: 'USB' | 'Network';
|
|
365
365
|
};
|
|
366
366
|
};
|
|
367
367
|
notifications?: {
|
|
368
368
|
email?: {
|
|
369
369
|
enabled: boolean;
|
|
370
|
-
provider:
|
|
370
|
+
provider: 'resend' | 'sendgrid' | 'ses';
|
|
371
371
|
fromEmail: string;
|
|
372
372
|
adminEmail: string;
|
|
373
373
|
};
|
|
374
374
|
sms?: {
|
|
375
375
|
enabled: boolean;
|
|
376
|
-
provider:
|
|
376
|
+
provider: 'dpd';
|
|
377
377
|
};
|
|
378
378
|
};
|
|
379
379
|
testMode?: boolean;
|
|
@@ -417,12 +417,12 @@ declare function calculateParcels(totalWeight: number): number;
|
|
|
417
417
|
declare function validateServiceCode(code: string): code is DPDServiceCode;
|
|
418
418
|
declare function generateConsignmentRef(orderId: string): string;
|
|
419
419
|
|
|
420
|
-
declare function createCompleteShipment(orderId: string, params: Omit<CreateShipmentParams,
|
|
420
|
+
declare function createCompleteShipment(orderId: string, params: Omit<CreateShipmentParams, 'orderId'>, config: DPDModuleConfig, dbAdapter: DatabaseAdapter, storageAdapter: StorageAdapter): Promise<CreateShipmentResult & {
|
|
421
421
|
labelUrl?: string;
|
|
422
422
|
}>;
|
|
423
423
|
declare function generateAndUploadLabel(shipmentId: string | number, consignmentNumber: string, format: "thermal" | "a4" | undefined, credentials: DPDCredentials, storageAdapter: StorageAdapter): Promise<GenerateLabelResult>;
|
|
424
424
|
declare function validateDeliveryAddress(params: ValidateAddressParams, credentials: DPDCredentials): Promise<ValidateAddressResult>;
|
|
425
|
-
declare function saveAddress(userId: string, address: Omit<SavedAddress,
|
|
425
|
+
declare function saveAddress(userId: string, address: Omit<SavedAddress, 'id' | 'userId' | 'createdAt' | 'updatedAt'>, credentials: DPDCredentials, dbAdapter: DatabaseAdapter): Promise<string>;
|
|
426
426
|
declare function getSavedAddresses(userId: string, dbAdapter: DatabaseAdapter): Promise<SavedAddress[]>;
|
|
427
427
|
declare function getSavedAddress(addressId: string, dbAdapter: DatabaseAdapter): Promise<SavedAddress | null>;
|
|
428
428
|
declare function updateSavedAddress(addressId: string, data: Partial<SavedAddress>, dbAdapter: DatabaseAdapter): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -50,27 +50,27 @@ interface PricingConfig {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
interface LabelConfig {
|
|
53
|
-
format:
|
|
53
|
+
format: 'thermal' | 'a4';
|
|
54
54
|
printer: {
|
|
55
55
|
model: string;
|
|
56
56
|
dpi: number;
|
|
57
57
|
speed: number;
|
|
58
|
-
connection:
|
|
58
|
+
connection: 'USB' | 'Network';
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
interface NotificationConfig {
|
|
62
62
|
email: {
|
|
63
63
|
enabled: boolean;
|
|
64
|
-
provider:
|
|
64
|
+
provider: 'resend' | 'sendgrid' | 'ses';
|
|
65
65
|
fromEmail: string;
|
|
66
66
|
adminEmail: string;
|
|
67
67
|
};
|
|
68
68
|
sms: {
|
|
69
69
|
enabled: boolean;
|
|
70
|
-
provider:
|
|
70
|
+
provider: 'dpd';
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
type DPDServiceCode =
|
|
73
|
+
type DPDServiceCode = '12' | '07';
|
|
74
74
|
interface DPDAuthResponse {
|
|
75
75
|
data: {
|
|
76
76
|
geoSession: string;
|
|
@@ -161,7 +161,7 @@ interface DPDError {
|
|
|
161
161
|
errorType: string;
|
|
162
162
|
}
|
|
163
163
|
interface ShippingData {
|
|
164
|
-
provider:
|
|
164
|
+
provider: 'dpd';
|
|
165
165
|
service: DPDServiceCode;
|
|
166
166
|
shipmentId: string | number;
|
|
167
167
|
consignmentNumber: string;
|
|
@@ -178,7 +178,7 @@ interface ShippingData {
|
|
|
178
178
|
};
|
|
179
179
|
weight: {
|
|
180
180
|
total: number;
|
|
181
|
-
unit:
|
|
181
|
+
unit: 'kg';
|
|
182
182
|
};
|
|
183
183
|
parcels: number;
|
|
184
184
|
collectionDate: string;
|
|
@@ -187,7 +187,7 @@ interface ShippingData {
|
|
|
187
187
|
createdAt: TimestampType;
|
|
188
188
|
updatedAt: TimestampType;
|
|
189
189
|
}
|
|
190
|
-
type ShipmentStatus =
|
|
190
|
+
type ShipmentStatus = 'created' | 'label_generated' | 'collected' | 'in_transit' | 'out_for_delivery' | 'delivered' | 'failed' | 'cancelled';
|
|
191
191
|
interface ShipmentStatusUpdate {
|
|
192
192
|
status: ShipmentStatus;
|
|
193
193
|
timestamp: TimestampType;
|
|
@@ -218,7 +218,7 @@ interface DPDLogDocument {
|
|
|
218
218
|
id: string;
|
|
219
219
|
orderId: string;
|
|
220
220
|
consignmentNumber?: string;
|
|
221
|
-
operation:
|
|
221
|
+
operation: 'auth' | 'validate_address' | 'create_shipment' | 'generate_label' | 'track_shipment' | 'webhook';
|
|
222
222
|
request: {
|
|
223
223
|
endpoint: string;
|
|
224
224
|
method: string;
|
|
@@ -263,7 +263,7 @@ interface CreateShipmentResult {
|
|
|
263
263
|
}
|
|
264
264
|
interface GenerateLabelParams {
|
|
265
265
|
shipmentId: string | number;
|
|
266
|
-
format:
|
|
266
|
+
format: 'thermal' | 'a4';
|
|
267
267
|
}
|
|
268
268
|
interface GenerateLabelResult {
|
|
269
269
|
success: boolean;
|
|
@@ -296,10 +296,10 @@ interface DatabaseAdapter {
|
|
|
296
296
|
updateOrder(orderId: string, data: any): Promise<void>;
|
|
297
297
|
getSavedAddresses(userId: string): Promise<SavedAddress[]>;
|
|
298
298
|
getSavedAddress(addressId: string): Promise<SavedAddress | null>;
|
|
299
|
-
createSavedAddress(address: Omit<SavedAddress,
|
|
299
|
+
createSavedAddress(address: Omit<SavedAddress, 'id'>): Promise<string>;
|
|
300
300
|
updateSavedAddress(addressId: string, data: Partial<SavedAddress>): Promise<void>;
|
|
301
301
|
deleteSavedAddress(addressId: string): Promise<void>;
|
|
302
|
-
createDPDLog(log: Omit<DPDLogDocument,
|
|
302
|
+
createDPDLog(log: Omit<DPDLogDocument, 'id'>): Promise<string>;
|
|
303
303
|
getDPDLogs(filters: LogFilters): Promise<DPDLogDocument[]>;
|
|
304
304
|
}
|
|
305
305
|
interface StorageAdapter {
|
|
@@ -310,7 +310,7 @@ interface StorageAdapter {
|
|
|
310
310
|
interface LogFilters {
|
|
311
311
|
orderId?: string;
|
|
312
312
|
consignmentNumber?: string;
|
|
313
|
-
operation?: DPDLogDocument[
|
|
313
|
+
operation?: DPDLogDocument['operation'];
|
|
314
314
|
success?: boolean;
|
|
315
315
|
startDate?: Date;
|
|
316
316
|
endDate?: Date;
|
|
@@ -339,12 +339,12 @@ interface CreateDPDConfigOptions {
|
|
|
339
339
|
flatDeliveryFee?: number;
|
|
340
340
|
minimumOrderValue?: number;
|
|
341
341
|
services?: {
|
|
342
|
-
|
|
342
|
+
'12'?: {
|
|
343
343
|
basePrice: number;
|
|
344
344
|
perKgPrice: number;
|
|
345
345
|
customerPrice: number;
|
|
346
346
|
};
|
|
347
|
-
|
|
347
|
+
'07'?: {
|
|
348
348
|
basePrice: number;
|
|
349
349
|
perKgPrice: number;
|
|
350
350
|
customerPrice: number;
|
|
@@ -356,24 +356,24 @@ interface CreateDPDConfigOptions {
|
|
|
356
356
|
default?: DPDServiceCode;
|
|
357
357
|
};
|
|
358
358
|
labels?: {
|
|
359
|
-
format?:
|
|
359
|
+
format?: 'thermal' | 'a4';
|
|
360
360
|
printer?: {
|
|
361
361
|
model: string;
|
|
362
362
|
dpi: number;
|
|
363
363
|
speed: number;
|
|
364
|
-
connection:
|
|
364
|
+
connection: 'USB' | 'Network';
|
|
365
365
|
};
|
|
366
366
|
};
|
|
367
367
|
notifications?: {
|
|
368
368
|
email?: {
|
|
369
369
|
enabled: boolean;
|
|
370
|
-
provider:
|
|
370
|
+
provider: 'resend' | 'sendgrid' | 'ses';
|
|
371
371
|
fromEmail: string;
|
|
372
372
|
adminEmail: string;
|
|
373
373
|
};
|
|
374
374
|
sms?: {
|
|
375
375
|
enabled: boolean;
|
|
376
|
-
provider:
|
|
376
|
+
provider: 'dpd';
|
|
377
377
|
};
|
|
378
378
|
};
|
|
379
379
|
testMode?: boolean;
|
|
@@ -417,12 +417,12 @@ declare function calculateParcels(totalWeight: number): number;
|
|
|
417
417
|
declare function validateServiceCode(code: string): code is DPDServiceCode;
|
|
418
418
|
declare function generateConsignmentRef(orderId: string): string;
|
|
419
419
|
|
|
420
|
-
declare function createCompleteShipment(orderId: string, params: Omit<CreateShipmentParams,
|
|
420
|
+
declare function createCompleteShipment(orderId: string, params: Omit<CreateShipmentParams, 'orderId'>, config: DPDModuleConfig, dbAdapter: DatabaseAdapter, storageAdapter: StorageAdapter): Promise<CreateShipmentResult & {
|
|
421
421
|
labelUrl?: string;
|
|
422
422
|
}>;
|
|
423
423
|
declare function generateAndUploadLabel(shipmentId: string | number, consignmentNumber: string, format: "thermal" | "a4" | undefined, credentials: DPDCredentials, storageAdapter: StorageAdapter): Promise<GenerateLabelResult>;
|
|
424
424
|
declare function validateDeliveryAddress(params: ValidateAddressParams, credentials: DPDCredentials): Promise<ValidateAddressResult>;
|
|
425
|
-
declare function saveAddress(userId: string, address: Omit<SavedAddress,
|
|
425
|
+
declare function saveAddress(userId: string, address: Omit<SavedAddress, 'id' | 'userId' | 'createdAt' | 'updatedAt'>, credentials: DPDCredentials, dbAdapter: DatabaseAdapter): Promise<string>;
|
|
426
426
|
declare function getSavedAddresses(userId: string, dbAdapter: DatabaseAdapter): Promise<SavedAddress[]>;
|
|
427
427
|
declare function getSavedAddress(addressId: string, dbAdapter: DatabaseAdapter): Promise<SavedAddress | null>;
|
|
428
428
|
declare function updateSavedAddress(addressId: string, data: Partial<SavedAddress>, dbAdapter: DatabaseAdapter): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -692,7 +692,11 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
|
|
|
692
692
|
error: `Shipment created but label generation failed: ${labelResult.error}`
|
|
693
693
|
};
|
|
694
694
|
}
|
|
695
|
-
const dpdCost = calculateDPDCost(
|
|
695
|
+
const dpdCost = calculateDPDCost(
|
|
696
|
+
params.totalWeight,
|
|
697
|
+
params.service,
|
|
698
|
+
config2
|
|
699
|
+
);
|
|
696
700
|
const customerCharge = calculateDeliveryFee(0, params.service, config2);
|
|
697
701
|
const now = /* @__PURE__ */ new Date();
|
|
698
702
|
const shippingData = {
|
|
@@ -1188,7 +1192,7 @@ function logToConsole(logData) {
|
|
|
1188
1192
|
* TypeScript SDK for integrating DPD Local shipping services
|
|
1189
1193
|
* Database-agnostic and framework-independent
|
|
1190
1194
|
*
|
|
1191
|
-
* @package @
|
|
1195
|
+
* @package @jazzdev/dpd-local-sdk
|
|
1192
1196
|
* @version 1.0.0
|
|
1193
1197
|
* @author Your Name
|
|
1194
1198
|
* @license MIT
|
package/dist/index.mjs
CHANGED
|
@@ -604,7 +604,11 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
|
|
|
604
604
|
error: `Shipment created but label generation failed: ${labelResult.error}`
|
|
605
605
|
};
|
|
606
606
|
}
|
|
607
|
-
const dpdCost = calculateDPDCost(
|
|
607
|
+
const dpdCost = calculateDPDCost(
|
|
608
|
+
params.totalWeight,
|
|
609
|
+
params.service,
|
|
610
|
+
config2
|
|
611
|
+
);
|
|
608
612
|
const customerCharge = calculateDeliveryFee(0, params.service, config2);
|
|
609
613
|
const now = /* @__PURE__ */ new Date();
|
|
610
614
|
const shippingData = {
|
|
@@ -1099,7 +1103,7 @@ export {
|
|
|
1099
1103
|
* TypeScript SDK for integrating DPD Local shipping services
|
|
1100
1104
|
* Database-agnostic and framework-independent
|
|
1101
1105
|
*
|
|
1102
|
-
* @package @
|
|
1106
|
+
* @package @jazzdev/dpd-local-sdk
|
|
1103
1107
|
* @version 1.0.0
|
|
1104
1108
|
* @author Your Name
|
|
1105
1109
|
* @license MIT
|
package/package.json
CHANGED