@jazzdev/dpd-local-sdk 1.0.4 → 1.0.6

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/dist/index.d.mts CHANGED
@@ -50,7 +50,7 @@ interface PricingConfig {
50
50
  };
51
51
  }
52
52
  interface LabelConfig {
53
- format: 'thermal' | 'a4';
53
+ format: 'zpl' | 'clp' | 'html';
54
54
  printer: {
55
55
  model: string;
56
56
  dpi: number;
@@ -263,7 +263,7 @@ interface CreateShipmentResult {
263
263
  }
264
264
  interface GenerateLabelParams {
265
265
  shipmentId: string | number;
266
- format: 'thermal' | 'html';
266
+ labelFormat: 'zpl' | 'clp' | 'html';
267
267
  }
268
268
  interface GenerateLabelResult {
269
269
  success: boolean;
@@ -356,7 +356,7 @@ interface CreateDPDConfigOptions {
356
356
  default?: DPDServiceCode;
357
357
  };
358
358
  labels?: {
359
- format?: 'thermal' | 'a4';
359
+ format?: 'zpl' | 'clp' | 'html';
360
360
  printer?: {
361
361
  model: string;
362
362
  dpi: number;
@@ -420,7 +420,7 @@ declare function generateConsignmentRef(orderId: string): string;
420
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" | "html" | undefined, credentials: DPDCredentials, storageAdapter: StorageAdapter): Promise<GenerateLabelResult>;
423
+ declare function generateAndUploadLabel(shipmentId: string | number, consignmentNumber: string, labelFormat: 'zpl' | 'clp' | 'html', credentials: DPDCredentials, storageAdapter: StorageAdapter): Promise<GenerateLabelResult>;
424
424
  declare function validateDeliveryAddress(params: ValidateAddressParams, credentials: DPDCredentials): Promise<ValidateAddressResult>;
425
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[]>;
@@ -428,7 +428,7 @@ declare function getSavedAddress(addressId: string, dbAdapter: DatabaseAdapter):
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" | "html" | undefined, credentials: DPDCredentials, storageAdapter: StorageAdapter): Promise<GenerateLabelResult>;
431
+ declare function regenerateLabel(shipmentId: string | number, consignmentNumber: string, labelFormat: 'zpl' | 'clp' | 'html', 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,7 +50,7 @@ interface PricingConfig {
50
50
  };
51
51
  }
52
52
  interface LabelConfig {
53
- format: 'thermal' | 'a4';
53
+ format: 'zpl' | 'clp' | 'html';
54
54
  printer: {
55
55
  model: string;
56
56
  dpi: number;
@@ -263,7 +263,7 @@ interface CreateShipmentResult {
263
263
  }
264
264
  interface GenerateLabelParams {
265
265
  shipmentId: string | number;
266
- format: 'thermal' | 'html';
266
+ labelFormat: 'zpl' | 'clp' | 'html';
267
267
  }
268
268
  interface GenerateLabelResult {
269
269
  success: boolean;
@@ -356,7 +356,7 @@ interface CreateDPDConfigOptions {
356
356
  default?: DPDServiceCode;
357
357
  };
358
358
  labels?: {
359
- format?: 'thermal' | 'a4';
359
+ format?: 'zpl' | 'clp' | 'html';
360
360
  printer?: {
361
361
  model: string;
362
362
  dpi: number;
@@ -420,7 +420,7 @@ declare function generateConsignmentRef(orderId: string): string;
420
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" | "html" | undefined, credentials: DPDCredentials, storageAdapter: StorageAdapter): Promise<GenerateLabelResult>;
423
+ declare function generateAndUploadLabel(shipmentId: string | number, consignmentNumber: string, labelFormat: 'zpl' | 'clp' | 'html', credentials: DPDCredentials, storageAdapter: StorageAdapter): Promise<GenerateLabelResult>;
424
424
  declare function validateDeliveryAddress(params: ValidateAddressParams, credentials: DPDCredentials): Promise<ValidateAddressResult>;
425
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[]>;
@@ -428,7 +428,7 @@ declare function getSavedAddress(addressId: string, dbAdapter: DatabaseAdapter):
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" | "html" | undefined, credentials: DPDCredentials, storageAdapter: StorageAdapter): Promise<GenerateLabelResult>;
431
+ declare function regenerateLabel(shipmentId: string | number, consignmentNumber: string, labelFormat: 'zpl' | 'clp' | 'html', 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
@@ -139,7 +139,7 @@ function createDPDConfig(options) {
139
139
  default: "12"
140
140
  };
141
141
  const defaultLabels = {
142
- format: "thermal",
142
+ format: "zpl",
143
143
  printer: {
144
144
  model: "TSC-DA210",
145
145
  dpi: 203,
@@ -406,16 +406,16 @@ async function testConnection(credentials) {
406
406
  }
407
407
 
408
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":
409
+ function getAcceptHeader(format) {
410
+ switch (format) {
411
+ case "html":
412
+ return "text/html";
413
+ case "zpl":
415
414
  return "text/vnd.zebra-zpl";
416
- case "citizen-clp":
417
- default:
415
+ case "clp":
418
416
  return "text/vnd.citizen-clp";
417
+ default:
418
+ return "text/vnd.zebra-zpl";
419
419
  }
420
420
  }
421
421
 
@@ -530,15 +530,29 @@ async function createShipment(credentials, params, businessConfig) {
530
530
  }
531
531
  async function generateLabel(credentials, params) {
532
532
  try {
533
- const { shipmentId, format } = params;
533
+ const { shipmentId, labelFormat } = params;
534
534
  const endpoint = `${DPD_API.ENDPOINTS.LABEL}/${shipmentId}/label/`;
535
535
  const response = await authenticatedRequest(credentials, {
536
536
  method: "GET",
537
537
  endpoint,
538
538
  headers: {
539
- Accept: getAcceptHeader(format, "zebra-zpl")
539
+ Accept: getAcceptHeader(labelFormat)
540
540
  }
541
541
  });
542
+ console.log({
543
+ endpoint,
544
+ labelFormat,
545
+ header: getAcceptHeader(labelFormat),
546
+ response
547
+ });
548
+ if (typeof response === "object" && response.error) {
549
+ const errorObj = response.error;
550
+ const errorMessage = errorObj.errorMessage || errorObj.name || JSON.stringify(errorObj);
551
+ return {
552
+ success: false,
553
+ error: `DPD API error: ${errorMessage}`
554
+ };
555
+ }
542
556
  if (!response || typeof response === "object" && !response.data) {
543
557
  return {
544
558
  success: false,
@@ -695,7 +709,7 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
695
709
  const labelResult = await generateAndUploadLabel(
696
710
  shipmentResult.shipmentId,
697
711
  shipmentResult.consignmentNumber,
698
- "thermal",
712
+ "zpl",
699
713
  config2.credentials,
700
714
  storageAdapter
701
715
  );
@@ -781,17 +795,17 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
781
795
  };
782
796
  }
783
797
  }
784
- async function generateAndUploadLabel(shipmentId, consignmentNumber, format = "thermal", credentials, storageAdapter) {
798
+ async function generateAndUploadLabel(shipmentId, consignmentNumber, labelFormat, credentials, storageAdapter) {
785
799
  try {
786
800
  const labelResult = await generateLabel(credentials, {
787
801
  shipmentId,
788
- format
802
+ labelFormat
789
803
  });
790
804
  if (!labelResult.success || !labelResult.labelData) {
791
805
  return labelResult;
792
806
  }
793
807
  const timestamp = Date.now();
794
- const extension = format === "thermal" ? "txt" : "html";
808
+ const extension = labelFormat === "html" ? "html" : "txt";
795
809
  const fileName = `${consignmentNumber}-${timestamp}.${extension}`;
796
810
  const labelUrl = await storageAdapter.uploadLabel(
797
811
  labelResult.labelData,
@@ -849,11 +863,11 @@ async function getLabelUrl(consignmentNumber, storageAdapter) {
849
863
  return null;
850
864
  }
851
865
  }
852
- async function regenerateLabel(shipmentId, consignmentNumber, format = "thermal", credentials, storageAdapter) {
866
+ async function regenerateLabel(shipmentId, consignmentNumber, labelFormat, credentials, storageAdapter) {
853
867
  return await generateAndUploadLabel(
854
868
  shipmentId,
855
869
  consignmentNumber,
856
- format,
870
+ labelFormat,
857
871
  credentials,
858
872
  storageAdapter
859
873
  );
package/dist/index.mjs CHANGED
@@ -51,7 +51,7 @@ function createDPDConfig(options) {
51
51
  default: "12"
52
52
  };
53
53
  const defaultLabels = {
54
- format: "thermal",
54
+ format: "zpl",
55
55
  printer: {
56
56
  model: "TSC-DA210",
57
57
  dpi: 203,
@@ -318,16 +318,16 @@ async function testConnection(credentials) {
318
318
  }
319
319
 
320
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":
321
+ function getAcceptHeader(format) {
322
+ switch (format) {
323
+ case "html":
324
+ return "text/html";
325
+ case "zpl":
327
326
  return "text/vnd.zebra-zpl";
328
- case "citizen-clp":
329
- default:
327
+ case "clp":
330
328
  return "text/vnd.citizen-clp";
329
+ default:
330
+ return "text/vnd.zebra-zpl";
331
331
  }
332
332
  }
333
333
 
@@ -442,15 +442,29 @@ async function createShipment(credentials, params, businessConfig) {
442
442
  }
443
443
  async function generateLabel(credentials, params) {
444
444
  try {
445
- const { shipmentId, format } = params;
445
+ const { shipmentId, labelFormat } = params;
446
446
  const endpoint = `${DPD_API.ENDPOINTS.LABEL}/${shipmentId}/label/`;
447
447
  const response = await authenticatedRequest(credentials, {
448
448
  method: "GET",
449
449
  endpoint,
450
450
  headers: {
451
- Accept: getAcceptHeader(format, "zebra-zpl")
451
+ Accept: getAcceptHeader(labelFormat)
452
452
  }
453
453
  });
454
+ console.log({
455
+ endpoint,
456
+ labelFormat,
457
+ header: getAcceptHeader(labelFormat),
458
+ response
459
+ });
460
+ if (typeof response === "object" && response.error) {
461
+ const errorObj = response.error;
462
+ const errorMessage = errorObj.errorMessage || errorObj.name || JSON.stringify(errorObj);
463
+ return {
464
+ success: false,
465
+ error: `DPD API error: ${errorMessage}`
466
+ };
467
+ }
454
468
  if (!response || typeof response === "object" && !response.data) {
455
469
  return {
456
470
  success: false,
@@ -607,7 +621,7 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
607
621
  const labelResult = await generateAndUploadLabel(
608
622
  shipmentResult.shipmentId,
609
623
  shipmentResult.consignmentNumber,
610
- "thermal",
624
+ "zpl",
611
625
  config2.credentials,
612
626
  storageAdapter
613
627
  );
@@ -693,17 +707,17 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
693
707
  };
694
708
  }
695
709
  }
696
- async function generateAndUploadLabel(shipmentId, consignmentNumber, format = "thermal", credentials, storageAdapter) {
710
+ async function generateAndUploadLabel(shipmentId, consignmentNumber, labelFormat, credentials, storageAdapter) {
697
711
  try {
698
712
  const labelResult = await generateLabel(credentials, {
699
713
  shipmentId,
700
- format
714
+ labelFormat
701
715
  });
702
716
  if (!labelResult.success || !labelResult.labelData) {
703
717
  return labelResult;
704
718
  }
705
719
  const timestamp = Date.now();
706
- const extension = format === "thermal" ? "txt" : "html";
720
+ const extension = labelFormat === "html" ? "html" : "txt";
707
721
  const fileName = `${consignmentNumber}-${timestamp}.${extension}`;
708
722
  const labelUrl = await storageAdapter.uploadLabel(
709
723
  labelResult.labelData,
@@ -761,11 +775,11 @@ async function getLabelUrl(consignmentNumber, storageAdapter) {
761
775
  return null;
762
776
  }
763
777
  }
764
- async function regenerateLabel(shipmentId, consignmentNumber, format = "thermal", credentials, storageAdapter) {
778
+ async function regenerateLabel(shipmentId, consignmentNumber, labelFormat, credentials, storageAdapter) {
765
779
  return await generateAndUploadLabel(
766
780
  shipmentId,
767
781
  consignmentNumber,
768
- format,
782
+ labelFormat,
769
783
  credentials,
770
784
  storageAdapter
771
785
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jazzdev/dpd-local-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "TypeScript SDK for DPD Local shipping API integration - database-agnostic and framework-independent",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",