@jazzdev/dpd-local-sdk 1.0.3 → 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 +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +23 -18
- package/dist/index.mjs +23 -18
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -50,7 +50,7 @@ interface PricingConfig {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
interface LabelConfig {
|
|
53
|
-
format: '
|
|
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
|
-
|
|
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?: '
|
|
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,
|
|
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,
|
|
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: '
|
|
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
|
-
|
|
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?: '
|
|
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,
|
|
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,
|
|
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: "
|
|
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
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
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 "
|
|
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,16 +530,21 @@ async function createShipment(credentials, params, businessConfig) {
|
|
|
530
530
|
}
|
|
531
531
|
async function generateLabel(credentials, params) {
|
|
532
532
|
try {
|
|
533
|
-
const { shipmentId,
|
|
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(
|
|
539
|
+
Accept: getAcceptHeader(labelFormat)
|
|
540
540
|
}
|
|
541
541
|
});
|
|
542
|
-
console.log({
|
|
542
|
+
console.log({
|
|
543
|
+
endpoint,
|
|
544
|
+
labelFormat,
|
|
545
|
+
header: getAcceptHeader(labelFormat),
|
|
546
|
+
response
|
|
547
|
+
});
|
|
543
548
|
if (!response || typeof response === "object" && !response.data) {
|
|
544
549
|
return {
|
|
545
550
|
success: false,
|
|
@@ -696,7 +701,7 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
|
|
|
696
701
|
const labelResult = await generateAndUploadLabel(
|
|
697
702
|
shipmentResult.shipmentId,
|
|
698
703
|
shipmentResult.consignmentNumber,
|
|
699
|
-
"
|
|
704
|
+
"zpl",
|
|
700
705
|
config2.credentials,
|
|
701
706
|
storageAdapter
|
|
702
707
|
);
|
|
@@ -782,17 +787,17 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
|
|
|
782
787
|
};
|
|
783
788
|
}
|
|
784
789
|
}
|
|
785
|
-
async function generateAndUploadLabel(shipmentId, consignmentNumber,
|
|
790
|
+
async function generateAndUploadLabel(shipmentId, consignmentNumber, labelFormat, credentials, storageAdapter) {
|
|
786
791
|
try {
|
|
787
792
|
const labelResult = await generateLabel(credentials, {
|
|
788
793
|
shipmentId,
|
|
789
|
-
|
|
794
|
+
labelFormat
|
|
790
795
|
});
|
|
791
796
|
if (!labelResult.success || !labelResult.labelData) {
|
|
792
797
|
return labelResult;
|
|
793
798
|
}
|
|
794
799
|
const timestamp = Date.now();
|
|
795
|
-
const extension =
|
|
800
|
+
const extension = labelFormat === "html" ? "html" : "txt";
|
|
796
801
|
const fileName = `${consignmentNumber}-${timestamp}.${extension}`;
|
|
797
802
|
const labelUrl = await storageAdapter.uploadLabel(
|
|
798
803
|
labelResult.labelData,
|
|
@@ -850,11 +855,11 @@ async function getLabelUrl(consignmentNumber, storageAdapter) {
|
|
|
850
855
|
return null;
|
|
851
856
|
}
|
|
852
857
|
}
|
|
853
|
-
async function regenerateLabel(shipmentId, consignmentNumber,
|
|
858
|
+
async function regenerateLabel(shipmentId, consignmentNumber, labelFormat, credentials, storageAdapter) {
|
|
854
859
|
return await generateAndUploadLabel(
|
|
855
860
|
shipmentId,
|
|
856
861
|
consignmentNumber,
|
|
857
|
-
|
|
862
|
+
labelFormat,
|
|
858
863
|
credentials,
|
|
859
864
|
storageAdapter
|
|
860
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: "
|
|
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
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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 "
|
|
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,16 +442,21 @@ async function createShipment(credentials, params, businessConfig) {
|
|
|
442
442
|
}
|
|
443
443
|
async function generateLabel(credentials, params) {
|
|
444
444
|
try {
|
|
445
|
-
const { shipmentId,
|
|
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(
|
|
451
|
+
Accept: getAcceptHeader(labelFormat)
|
|
452
452
|
}
|
|
453
453
|
});
|
|
454
|
-
console.log({
|
|
454
|
+
console.log({
|
|
455
|
+
endpoint,
|
|
456
|
+
labelFormat,
|
|
457
|
+
header: getAcceptHeader(labelFormat),
|
|
458
|
+
response
|
|
459
|
+
});
|
|
455
460
|
if (!response || typeof response === "object" && !response.data) {
|
|
456
461
|
return {
|
|
457
462
|
success: false,
|
|
@@ -608,7 +613,7 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
|
|
|
608
613
|
const labelResult = await generateAndUploadLabel(
|
|
609
614
|
shipmentResult.shipmentId,
|
|
610
615
|
shipmentResult.consignmentNumber,
|
|
611
|
-
"
|
|
616
|
+
"zpl",
|
|
612
617
|
config2.credentials,
|
|
613
618
|
storageAdapter
|
|
614
619
|
);
|
|
@@ -694,17 +699,17 @@ async function createCompleteShipment(orderId, params, config2, dbAdapter, stora
|
|
|
694
699
|
};
|
|
695
700
|
}
|
|
696
701
|
}
|
|
697
|
-
async function generateAndUploadLabel(shipmentId, consignmentNumber,
|
|
702
|
+
async function generateAndUploadLabel(shipmentId, consignmentNumber, labelFormat, credentials, storageAdapter) {
|
|
698
703
|
try {
|
|
699
704
|
const labelResult = await generateLabel(credentials, {
|
|
700
705
|
shipmentId,
|
|
701
|
-
|
|
706
|
+
labelFormat
|
|
702
707
|
});
|
|
703
708
|
if (!labelResult.success || !labelResult.labelData) {
|
|
704
709
|
return labelResult;
|
|
705
710
|
}
|
|
706
711
|
const timestamp = Date.now();
|
|
707
|
-
const extension =
|
|
712
|
+
const extension = labelFormat === "html" ? "html" : "txt";
|
|
708
713
|
const fileName = `${consignmentNumber}-${timestamp}.${extension}`;
|
|
709
714
|
const labelUrl = await storageAdapter.uploadLabel(
|
|
710
715
|
labelResult.labelData,
|
|
@@ -762,11 +767,11 @@ async function getLabelUrl(consignmentNumber, storageAdapter) {
|
|
|
762
767
|
return null;
|
|
763
768
|
}
|
|
764
769
|
}
|
|
765
|
-
async function regenerateLabel(shipmentId, consignmentNumber,
|
|
770
|
+
async function regenerateLabel(shipmentId, consignmentNumber, labelFormat, credentials, storageAdapter) {
|
|
766
771
|
return await generateAndUploadLabel(
|
|
767
772
|
shipmentId,
|
|
768
773
|
consignmentNumber,
|
|
769
|
-
|
|
774
|
+
labelFormat,
|
|
770
775
|
credentials,
|
|
771
776
|
storageAdapter
|
|
772
777
|
);
|
package/package.json
CHANGED