@jazzdev/dpd-local-sdk 1.0.4 → 1.0.5

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,21 @@ 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
+ });
542
548
  if (!response || typeof response === "object" && !response.data) {
543
549
  return {
544
550
  success: false,
@@ -695,7 +701,7 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
695
701
  const labelResult = await generateAndUploadLabel(
696
702
  shipmentResult.shipmentId,
697
703
  shipmentResult.consignmentNumber,
698
- "thermal",
704
+ "zpl",
699
705
  config2.credentials,
700
706
  storageAdapter
701
707
  );
@@ -781,17 +787,17 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
781
787
  };
782
788
  }
783
789
  }
784
- async function generateAndUploadLabel(shipmentId, consignmentNumber, format = "thermal", credentials, storageAdapter) {
790
+ async function generateAndUploadLabel(shipmentId, consignmentNumber, labelFormat, credentials, storageAdapter) {
785
791
  try {
786
792
  const labelResult = await generateLabel(credentials, {
787
793
  shipmentId,
788
- format
794
+ labelFormat
789
795
  });
790
796
  if (!labelResult.success || !labelResult.labelData) {
791
797
  return labelResult;
792
798
  }
793
799
  const timestamp = Date.now();
794
- const extension = format === "thermal" ? "txt" : "html";
800
+ const extension = labelFormat === "html" ? "html" : "txt";
795
801
  const fileName = `${consignmentNumber}-${timestamp}.${extension}`;
796
802
  const labelUrl = await storageAdapter.uploadLabel(
797
803
  labelResult.labelData,
@@ -849,11 +855,11 @@ async function getLabelUrl(consignmentNumber, storageAdapter) {
849
855
  return null;
850
856
  }
851
857
  }
852
- async function regenerateLabel(shipmentId, consignmentNumber, format = "thermal", credentials, storageAdapter) {
858
+ async function regenerateLabel(shipmentId, consignmentNumber, labelFormat, credentials, storageAdapter) {
853
859
  return await generateAndUploadLabel(
854
860
  shipmentId,
855
861
  consignmentNumber,
856
- format,
862
+ labelFormat,
857
863
  credentials,
858
864
  storageAdapter
859
865
  );
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,21 @@ 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
+ });
454
460
  if (!response || typeof response === "object" && !response.data) {
455
461
  return {
456
462
  success: false,
@@ -607,7 +613,7 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
607
613
  const labelResult = await generateAndUploadLabel(
608
614
  shipmentResult.shipmentId,
609
615
  shipmentResult.consignmentNumber,
610
- "thermal",
616
+ "zpl",
611
617
  config2.credentials,
612
618
  storageAdapter
613
619
  );
@@ -693,17 +699,17 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
693
699
  };
694
700
  }
695
701
  }
696
- async function generateAndUploadLabel(shipmentId, consignmentNumber, format = "thermal", credentials, storageAdapter) {
702
+ async function generateAndUploadLabel(shipmentId, consignmentNumber, labelFormat, credentials, storageAdapter) {
697
703
  try {
698
704
  const labelResult = await generateLabel(credentials, {
699
705
  shipmentId,
700
- format
706
+ labelFormat
701
707
  });
702
708
  if (!labelResult.success || !labelResult.labelData) {
703
709
  return labelResult;
704
710
  }
705
711
  const timestamp = Date.now();
706
- const extension = format === "thermal" ? "txt" : "html";
712
+ const extension = labelFormat === "html" ? "html" : "txt";
707
713
  const fileName = `${consignmentNumber}-${timestamp}.${extension}`;
708
714
  const labelUrl = await storageAdapter.uploadLabel(
709
715
  labelResult.labelData,
@@ -761,11 +767,11 @@ async function getLabelUrl(consignmentNumber, storageAdapter) {
761
767
  return null;
762
768
  }
763
769
  }
764
- async function regenerateLabel(shipmentId, consignmentNumber, format = "thermal", credentials, storageAdapter) {
770
+ async function regenerateLabel(shipmentId, consignmentNumber, labelFormat, credentials, storageAdapter) {
765
771
  return await generateAndUploadLabel(
766
772
  shipmentId,
767
773
  consignmentNumber,
768
- format,
774
+ labelFormat,
769
775
  credentials,
770
776
  storageAdapter
771
777
  );
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.5",
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",