@jazzdev/dpd-local-sdk 1.0.0 → 1.0.2
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 +23 -23
- package/dist/index.d.ts +23 -23
- package/dist/index.js +22 -5
- package/dist/index.mjs +22 -5
- 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' | 'html';
|
|
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,18 +417,18 @@ 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
|
-
declare function generateAndUploadLabel(shipmentId: string | number, consignmentNumber: string, format: "thermal" | "
|
|
423
|
+
declare function generateAndUploadLabel(shipmentId: string | number, consignmentNumber: string, format: "thermal" | "html" | 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>;
|
|
429
429
|
declare function deleteSavedAddress(addressId: string, dbAdapter: DatabaseAdapter): Promise<void>;
|
|
430
430
|
declare function getLabelUrl(consignmentNumber: string, storageAdapter: StorageAdapter): Promise<string | null>;
|
|
431
|
-
declare function regenerateLabel(shipmentId: string | number, consignmentNumber: string, format: "thermal" | "
|
|
431
|
+
declare function regenerateLabel(shipmentId: string | number, consignmentNumber: string, format: "thermal" | "html" | undefined, credentials: DPDCredentials, storageAdapter: StorageAdapter): Promise<GenerateLabelResult>;
|
|
432
432
|
declare function testDPDConnection(credentials: DPDCredentials): Promise<{
|
|
433
433
|
success: boolean;
|
|
434
434
|
message: string;
|
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' | 'html';
|
|
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,18 +417,18 @@ 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
|
-
declare function generateAndUploadLabel(shipmentId: string | number, consignmentNumber: string, format: "thermal" | "
|
|
423
|
+
declare function generateAndUploadLabel(shipmentId: string | number, consignmentNumber: string, format: "thermal" | "html" | 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>;
|
|
429
429
|
declare function deleteSavedAddress(addressId: string, dbAdapter: DatabaseAdapter): Promise<void>;
|
|
430
430
|
declare function getLabelUrl(consignmentNumber: string, storageAdapter: StorageAdapter): Promise<string | null>;
|
|
431
|
-
declare function regenerateLabel(shipmentId: string | number, consignmentNumber: string, format: "thermal" | "
|
|
431
|
+
declare function regenerateLabel(shipmentId: string | number, consignmentNumber: string, format: "thermal" | "html" | undefined, credentials: DPDCredentials, storageAdapter: StorageAdapter): Promise<GenerateLabelResult>;
|
|
432
432
|
declare function testDPDConnection(credentials: DPDCredentials): Promise<{
|
|
433
433
|
success: boolean;
|
|
434
434
|
message: string;
|
package/dist/index.js
CHANGED
|
@@ -321,7 +321,7 @@ async function authenticatedRequest(credentials, options) {
|
|
|
321
321
|
});
|
|
322
322
|
const raw = await response.text();
|
|
323
323
|
const acceptHeader = headers.Accept || headers.accept;
|
|
324
|
-
const isLabelRequest = acceptHeader === "text/vnd.citizen-clp" || acceptHeader === "text/vnd.eltron-epl" || acceptHeader === "text/html";
|
|
324
|
+
const isLabelRequest = acceptHeader === "text/vnd.zebra-zpl" || acceptHeader === "text/vnd.citizen-clp" || acceptHeader === "text/vnd.eltron-epl" || acceptHeader === "text/html";
|
|
325
325
|
let data = null;
|
|
326
326
|
if (isLabelRequest) {
|
|
327
327
|
if (!response.ok) {
|
|
@@ -405,6 +405,20 @@ async function testConnection(credentials) {
|
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
+
// src/utils/getAcceptHeader.ts
|
|
409
|
+
function getAcceptHeader(format, thermalLanguage) {
|
|
410
|
+
if (format === "html") {
|
|
411
|
+
return "text/html";
|
|
412
|
+
}
|
|
413
|
+
switch (thermalLanguage) {
|
|
414
|
+
case "zebra-zpl":
|
|
415
|
+
return "text/vnd.zebra-zpl";
|
|
416
|
+
case "citizen-clp":
|
|
417
|
+
default:
|
|
418
|
+
return "text/vnd.citizen-clp";
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
408
422
|
// src/lib/shipment.ts
|
|
409
423
|
async function createShipment(credentials, params, businessConfig) {
|
|
410
424
|
try {
|
|
@@ -517,13 +531,12 @@ async function createShipment(credentials, params, businessConfig) {
|
|
|
517
531
|
async function generateLabel(credentials, params) {
|
|
518
532
|
try {
|
|
519
533
|
const { shipmentId, format } = params;
|
|
520
|
-
const contentType = format === "thermal" ? "text/vnd.citizen-clp" : "text/html";
|
|
521
534
|
const endpoint = `${DPD_API.ENDPOINTS.LABEL}/${shipmentId}/label/`;
|
|
522
535
|
const response = await authenticatedRequest(credentials, {
|
|
523
536
|
method: "GET",
|
|
524
537
|
endpoint,
|
|
525
538
|
headers: {
|
|
526
|
-
Accept:
|
|
539
|
+
Accept: getAcceptHeader(format)
|
|
527
540
|
}
|
|
528
541
|
});
|
|
529
542
|
if (!response || typeof response === "object" && !response.data) {
|
|
@@ -692,7 +705,11 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
|
|
|
692
705
|
error: `Shipment created but label generation failed: ${labelResult.error}`
|
|
693
706
|
};
|
|
694
707
|
}
|
|
695
|
-
const dpdCost = calculateDPDCost(
|
|
708
|
+
const dpdCost = calculateDPDCost(
|
|
709
|
+
params.totalWeight,
|
|
710
|
+
params.service,
|
|
711
|
+
config2
|
|
712
|
+
);
|
|
696
713
|
const customerCharge = calculateDeliveryFee(0, params.service, config2);
|
|
697
714
|
const now = /* @__PURE__ */ new Date();
|
|
698
715
|
const shippingData = {
|
|
@@ -1188,7 +1205,7 @@ function logToConsole(logData) {
|
|
|
1188
1205
|
* TypeScript SDK for integrating DPD Local shipping services
|
|
1189
1206
|
* Database-agnostic and framework-independent
|
|
1190
1207
|
*
|
|
1191
|
-
* @package @
|
|
1208
|
+
* @package @jazzdev/dpd-local-sdk
|
|
1192
1209
|
* @version 1.0.0
|
|
1193
1210
|
* @author Your Name
|
|
1194
1211
|
* @license MIT
|
package/dist/index.mjs
CHANGED
|
@@ -233,7 +233,7 @@ async function authenticatedRequest(credentials, options) {
|
|
|
233
233
|
});
|
|
234
234
|
const raw = await response.text();
|
|
235
235
|
const acceptHeader = headers.Accept || headers.accept;
|
|
236
|
-
const isLabelRequest = acceptHeader === "text/vnd.citizen-clp" || acceptHeader === "text/vnd.eltron-epl" || acceptHeader === "text/html";
|
|
236
|
+
const isLabelRequest = acceptHeader === "text/vnd.zebra-zpl" || acceptHeader === "text/vnd.citizen-clp" || acceptHeader === "text/vnd.eltron-epl" || acceptHeader === "text/html";
|
|
237
237
|
let data = null;
|
|
238
238
|
if (isLabelRequest) {
|
|
239
239
|
if (!response.ok) {
|
|
@@ -317,6 +317,20 @@ async function testConnection(credentials) {
|
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
+
// src/utils/getAcceptHeader.ts
|
|
321
|
+
function getAcceptHeader(format, thermalLanguage) {
|
|
322
|
+
if (format === "html") {
|
|
323
|
+
return "text/html";
|
|
324
|
+
}
|
|
325
|
+
switch (thermalLanguage) {
|
|
326
|
+
case "zebra-zpl":
|
|
327
|
+
return "text/vnd.zebra-zpl";
|
|
328
|
+
case "citizen-clp":
|
|
329
|
+
default:
|
|
330
|
+
return "text/vnd.citizen-clp";
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
320
334
|
// src/lib/shipment.ts
|
|
321
335
|
async function createShipment(credentials, params, businessConfig) {
|
|
322
336
|
try {
|
|
@@ -429,13 +443,12 @@ async function createShipment(credentials, params, businessConfig) {
|
|
|
429
443
|
async function generateLabel(credentials, params) {
|
|
430
444
|
try {
|
|
431
445
|
const { shipmentId, format } = params;
|
|
432
|
-
const contentType = format === "thermal" ? "text/vnd.citizen-clp" : "text/html";
|
|
433
446
|
const endpoint = `${DPD_API.ENDPOINTS.LABEL}/${shipmentId}/label/`;
|
|
434
447
|
const response = await authenticatedRequest(credentials, {
|
|
435
448
|
method: "GET",
|
|
436
449
|
endpoint,
|
|
437
450
|
headers: {
|
|
438
|
-
Accept:
|
|
451
|
+
Accept: getAcceptHeader(format)
|
|
439
452
|
}
|
|
440
453
|
});
|
|
441
454
|
if (!response || typeof response === "object" && !response.data) {
|
|
@@ -604,7 +617,11 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
|
|
|
604
617
|
error: `Shipment created but label generation failed: ${labelResult.error}`
|
|
605
618
|
};
|
|
606
619
|
}
|
|
607
|
-
const dpdCost = calculateDPDCost(
|
|
620
|
+
const dpdCost = calculateDPDCost(
|
|
621
|
+
params.totalWeight,
|
|
622
|
+
params.service,
|
|
623
|
+
config2
|
|
624
|
+
);
|
|
608
625
|
const customerCharge = calculateDeliveryFee(0, params.service, config2);
|
|
609
626
|
const now = /* @__PURE__ */ new Date();
|
|
610
627
|
const shippingData = {
|
|
@@ -1099,7 +1116,7 @@ export {
|
|
|
1099
1116
|
* TypeScript SDK for integrating DPD Local shipping services
|
|
1100
1117
|
* Database-agnostic and framework-independent
|
|
1101
1118
|
*
|
|
1102
|
-
* @package @
|
|
1119
|
+
* @package @jazzdev/dpd-local-sdk
|
|
1103
1120
|
* @version 1.0.0
|
|
1104
1121
|
* @author Your Name
|
|
1105
1122
|
* @license MIT
|
package/package.json
CHANGED