@jazzdev/dpd-local-sdk 1.0.1 → 1.0.3
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 +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +17 -3
- package/dist/index.mjs +17 -3
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -263,7 +263,7 @@ interface CreateShipmentResult {
|
|
|
263
263
|
}
|
|
264
264
|
interface GenerateLabelParams {
|
|
265
265
|
shipmentId: string | number;
|
|
266
|
-
format: 'thermal' | '
|
|
266
|
+
format: 'thermal' | 'html';
|
|
267
267
|
}
|
|
268
268
|
interface GenerateLabelResult {
|
|
269
269
|
success: boolean;
|
|
@@ -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" | "
|
|
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
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" | "
|
|
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
|
@@ -263,7 +263,7 @@ interface CreateShipmentResult {
|
|
|
263
263
|
}
|
|
264
264
|
interface GenerateLabelParams {
|
|
265
265
|
shipmentId: string | number;
|
|
266
|
-
format: 'thermal' | '
|
|
266
|
+
format: 'thermal' | 'html';
|
|
267
267
|
}
|
|
268
268
|
interface GenerateLabelResult {
|
|
269
269
|
success: boolean;
|
|
@@ -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" | "
|
|
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
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" | "
|
|
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,15 +531,15 @@ 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
|
});
|
|
542
|
+
console.log({ endpoint, format, header: getAcceptHeader(format), response });
|
|
529
543
|
if (!response || typeof response === "object" && !response.data) {
|
|
530
544
|
return {
|
|
531
545
|
success: false,
|
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,15 +443,15 @@ 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
|
});
|
|
454
|
+
console.log({ endpoint, format, header: getAcceptHeader(format), response });
|
|
441
455
|
if (!response || typeof response === "object" && !response.data) {
|
|
442
456
|
return {
|
|
443
457
|
success: false,
|
package/package.json
CHANGED