@jazzdev/dpd-local-sdk 1.0.12 → 1.0.13
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 +18 -23
- package/dist/index.d.mts +1 -25
- package/dist/index.d.ts +1 -25
- package/dist/index.js +4 -119
- package/dist/index.mjs +3 -101
- package/package.json +5 -6
- package/CHANGELOG.md +0 -38
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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/@jazzdev/dpd-local-sdk)
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
|
|
@@ -419,30 +419,25 @@ app.post('/api/shipping/create', async (req, res) => {
|
|
|
419
419
|
});
|
|
420
420
|
```
|
|
421
421
|
|
|
422
|
-
##
|
|
422
|
+
## Configuration
|
|
423
423
|
|
|
424
|
-
|
|
425
|
-
# DPD Credentials (Required)
|
|
426
|
-
DPD_ACCOUNT_NUMBER=your_account_number
|
|
427
|
-
DPD_USERNAME=your_username
|
|
428
|
-
DPD_PASSWORD=your_password
|
|
429
|
-
|
|
430
|
-
# Encryption (Required in production)
|
|
431
|
-
DPD_ENCRYPTION_KEY=your_32_byte_hex_key
|
|
432
|
-
|
|
433
|
-
# Optional
|
|
434
|
-
NODE_ENV=production
|
|
435
|
-
```
|
|
436
|
-
|
|
437
|
-
### Generating Encryption Key
|
|
424
|
+
The SDK requires DPD credentials which you pass directly to the configuration:
|
|
438
425
|
|
|
439
426
|
```typescript
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
427
|
+
const config = createDPDConfig({
|
|
428
|
+
credentials: {
|
|
429
|
+
accountNumber: 'YOUR_ACCOUNT_NUMBER',
|
|
430
|
+
username: 'YOUR_USERNAME',
|
|
431
|
+
password: 'YOUR_PASSWORD',
|
|
432
|
+
},
|
|
433
|
+
business: {
|
|
434
|
+
// Your business details
|
|
435
|
+
}
|
|
436
|
+
});
|
|
444
437
|
```
|
|
445
438
|
|
|
439
|
+
**Important**: Credentials are passed programmatically - the SDK itself doesn't read from environment variables. How you store and retrieve credentials in your application is up to you.
|
|
440
|
+
|
|
446
441
|
## Adapter Examples
|
|
447
442
|
|
|
448
443
|
Complete adapter examples are available in the `examples/` directory:
|
|
@@ -498,7 +493,7 @@ import type {
|
|
|
498
493
|
|
|
499
494
|
## Contributing
|
|
500
495
|
|
|
501
|
-
Contributions are welcome! Please
|
|
496
|
+
Contributions are welcome! Please open an issue or submit a pull request on [GitHub](https://github.com/TheJazzDev/dpd-local-sdk).
|
|
502
497
|
|
|
503
498
|
## License
|
|
504
499
|
|
|
@@ -507,8 +502,8 @@ MIT © [Taiow Babarinde](https://github.com/TheJazzDev)
|
|
|
507
502
|
## Support
|
|
508
503
|
|
|
509
504
|
- 📧 Email: babsman4all@gmail.com
|
|
510
|
-
- 🐛 Issues: [GitHub Issues](https://github.com/TheJazzDev/dpd-local-sdk
|
|
505
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/TheJazzDev/dpd-local-sdk/issues)
|
|
511
506
|
|
|
512
507
|
## Changelog
|
|
513
508
|
|
|
514
|
-
See [CHANGELOG.md](CHANGELOG.md) for release history.
|
|
509
|
+
See [CHANGELOG.md](https://github.com/TheJazzDev/dpd-local-sdk/blob/main/CHANGELOG.md) for release history.
|
package/dist/index.d.mts
CHANGED
|
@@ -452,30 +452,6 @@ declare const _default: {
|
|
|
452
452
|
getAuthStatus: typeof getAuthStatus;
|
|
453
453
|
};
|
|
454
454
|
|
|
455
|
-
declare function generateEncryptionKey(): string;
|
|
456
|
-
declare function encrypt(text: string): string;
|
|
457
|
-
declare function decrypt(encryptedHex: string): string;
|
|
458
|
-
declare function encryptCredentials(credentials: {
|
|
459
|
-
accountNumber: string;
|
|
460
|
-
username: string;
|
|
461
|
-
password: string;
|
|
462
|
-
}): {
|
|
463
|
-
accountNumber: string;
|
|
464
|
-
username: string;
|
|
465
|
-
passwordHash: string;
|
|
466
|
-
};
|
|
467
|
-
declare function decryptCredentials(encryptedCredentials: {
|
|
468
|
-
accountNumber: string;
|
|
469
|
-
username: string;
|
|
470
|
-
passwordHash: string;
|
|
471
|
-
}): {
|
|
472
|
-
accountNumber: string;
|
|
473
|
-
username: string;
|
|
474
|
-
password: string;
|
|
475
|
-
};
|
|
476
|
-
declare function hash(data: string): string;
|
|
477
|
-
declare function verifyHash(data: string, hashToVerify: string): boolean;
|
|
478
|
-
|
|
479
455
|
interface LoggerConfig {
|
|
480
456
|
enabled: boolean;
|
|
481
457
|
logToConsole: boolean;
|
|
@@ -522,4 +498,4 @@ declare function loggedOperation<T>(params: {
|
|
|
522
498
|
headers?: Record<string, string>;
|
|
523
499
|
}>): Promise<T>;
|
|
524
500
|
|
|
525
|
-
export { type BusinessConfig, type CreateShipmentParams, type CreateShipmentResult, type DPDAddress, type DPDAuthResponse, type DPDConsignment, type DPDContact, type DPDCredentials, type DPDError, type DPDLabelRequest, type DPDLabelResponse, type DPDLogDocument, type DPDModuleConfig, type DPDParcel, _default as DPDService, type DPDServiceCode, type DPDShipmentRequest, type DPDShipmentResponse, DPD_API, type DatabaseAdapter, type GenerateLabelParams, type GenerateLabelResult, type LabelConfig, type LogFilters, type NotificationConfig, type PricingConfig, SERVICE_DESCRIPTIONS, SERVICE_NAMES, type SavedAddress, type ServiceConfig, type ShipmentStatus, type ShipmentStatusUpdate, type ShippingData, type StorageAdapter, type TimestampType, type TrackShipmentParams, type TrackShipmentResult, type ValidateAddressParams, type ValidateAddressResult, authenticate, authenticatedRequest, calculateDPDCost, calculateDeliveryFee, calculateParcels, clearGeoSession, configureLogger, createCompleteShipment, createDPDConfig, createShipment,
|
|
501
|
+
export { type BusinessConfig, type CreateShipmentParams, type CreateShipmentResult, type DPDAddress, type DPDAuthResponse, type DPDConsignment, type DPDContact, type DPDCredentials, type DPDError, type DPDLabelRequest, type DPDLabelResponse, type DPDLogDocument, type DPDModuleConfig, type DPDParcel, _default as DPDService, type DPDServiceCode, type DPDShipmentRequest, type DPDShipmentResponse, DPD_API, type DatabaseAdapter, type GenerateLabelParams, type GenerateLabelResult, type LabelConfig, type LogFilters, type NotificationConfig, type PricingConfig, SERVICE_DESCRIPTIONS, SERVICE_NAMES, type SavedAddress, type ServiceConfig, type ShipmentStatus, type ShipmentStatusUpdate, type ShippingData, type StorageAdapter, type TimestampType, type TrackShipmentParams, type TrackShipmentResult, type ValidateAddressParams, type ValidateAddressResult, authenticate, authenticatedRequest, calculateDPDCost, calculateDeliveryFee, calculateParcels, clearGeoSession, configureLogger, createCompleteShipment, createDPDConfig, createShipment, deleteSavedAddress, generateAndUploadLabel, generateConsignmentRef, generateLabel, getAuthStatus, getEstimatedDeliveryDate, getGeoSession, getLabelUrl, getNextCollectionDate, getSavedAddress, getSavedAddresses, getServiceDescription, getServiceName, getTokenExpiry, getTrackingUrl, hasValidToken, isValidServiceCode, logOperation, loggedOperation, meetsMinimumOrderValue, qualifiesForFreeDelivery, regenerateLabel, saveAddress, setLoggerAdapter, startTimer, testConnection, testDPDConnection, trackShipment, updateSavedAddress, validateAddress, validateDeliveryAddress, validateServiceCode };
|
package/dist/index.d.ts
CHANGED
|
@@ -452,30 +452,6 @@ declare const _default: {
|
|
|
452
452
|
getAuthStatus: typeof getAuthStatus;
|
|
453
453
|
};
|
|
454
454
|
|
|
455
|
-
declare function generateEncryptionKey(): string;
|
|
456
|
-
declare function encrypt(text: string): string;
|
|
457
|
-
declare function decrypt(encryptedHex: string): string;
|
|
458
|
-
declare function encryptCredentials(credentials: {
|
|
459
|
-
accountNumber: string;
|
|
460
|
-
username: string;
|
|
461
|
-
password: string;
|
|
462
|
-
}): {
|
|
463
|
-
accountNumber: string;
|
|
464
|
-
username: string;
|
|
465
|
-
passwordHash: string;
|
|
466
|
-
};
|
|
467
|
-
declare function decryptCredentials(encryptedCredentials: {
|
|
468
|
-
accountNumber: string;
|
|
469
|
-
username: string;
|
|
470
|
-
passwordHash: string;
|
|
471
|
-
}): {
|
|
472
|
-
accountNumber: string;
|
|
473
|
-
username: string;
|
|
474
|
-
password: string;
|
|
475
|
-
};
|
|
476
|
-
declare function hash(data: string): string;
|
|
477
|
-
declare function verifyHash(data: string, hashToVerify: string): boolean;
|
|
478
|
-
|
|
479
455
|
interface LoggerConfig {
|
|
480
456
|
enabled: boolean;
|
|
481
457
|
logToConsole: boolean;
|
|
@@ -522,4 +498,4 @@ declare function loggedOperation<T>(params: {
|
|
|
522
498
|
headers?: Record<string, string>;
|
|
523
499
|
}>): Promise<T>;
|
|
524
500
|
|
|
525
|
-
export { type BusinessConfig, type CreateShipmentParams, type CreateShipmentResult, type DPDAddress, type DPDAuthResponse, type DPDConsignment, type DPDContact, type DPDCredentials, type DPDError, type DPDLabelRequest, type DPDLabelResponse, type DPDLogDocument, type DPDModuleConfig, type DPDParcel, _default as DPDService, type DPDServiceCode, type DPDShipmentRequest, type DPDShipmentResponse, DPD_API, type DatabaseAdapter, type GenerateLabelParams, type GenerateLabelResult, type LabelConfig, type LogFilters, type NotificationConfig, type PricingConfig, SERVICE_DESCRIPTIONS, SERVICE_NAMES, type SavedAddress, type ServiceConfig, type ShipmentStatus, type ShipmentStatusUpdate, type ShippingData, type StorageAdapter, type TimestampType, type TrackShipmentParams, type TrackShipmentResult, type ValidateAddressParams, type ValidateAddressResult, authenticate, authenticatedRequest, calculateDPDCost, calculateDeliveryFee, calculateParcels, clearGeoSession, configureLogger, createCompleteShipment, createDPDConfig, createShipment,
|
|
501
|
+
export { type BusinessConfig, type CreateShipmentParams, type CreateShipmentResult, type DPDAddress, type DPDAuthResponse, type DPDConsignment, type DPDContact, type DPDCredentials, type DPDError, type DPDLabelRequest, type DPDLabelResponse, type DPDLogDocument, type DPDModuleConfig, type DPDParcel, _default as DPDService, type DPDServiceCode, type DPDShipmentRequest, type DPDShipmentResponse, DPD_API, type DatabaseAdapter, type GenerateLabelParams, type GenerateLabelResult, type LabelConfig, type LogFilters, type NotificationConfig, type PricingConfig, SERVICE_DESCRIPTIONS, SERVICE_NAMES, type SavedAddress, type ServiceConfig, type ShipmentStatus, type ShipmentStatusUpdate, type ShippingData, type StorageAdapter, type TimestampType, type TrackShipmentParams, type TrackShipmentResult, type ValidateAddressParams, type ValidateAddressResult, authenticate, authenticatedRequest, calculateDPDCost, calculateDeliveryFee, calculateParcels, clearGeoSession, configureLogger, createCompleteShipment, createDPDConfig, createShipment, deleteSavedAddress, generateAndUploadLabel, generateConsignmentRef, generateLabel, getAuthStatus, getEstimatedDeliveryDate, getGeoSession, getLabelUrl, getNextCollectionDate, getSavedAddress, getSavedAddresses, getServiceDescription, getServiceName, getTokenExpiry, getTrackingUrl, hasValidToken, isValidServiceCode, logOperation, loggedOperation, meetsMinimumOrderValue, qualifiesForFreeDelivery, regenerateLabel, saveAddress, setLoggerAdapter, startTimer, testConnection, testDPDConnection, trackShipment, updateSavedAddress, validateAddress, validateDeliveryAddress, validateServiceCode };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -44,14 +34,9 @@ __export(index_exports, {
|
|
|
44
34
|
createCompleteShipment: () => createCompleteShipment,
|
|
45
35
|
createDPDConfig: () => createDPDConfig,
|
|
46
36
|
createShipment: () => createShipment,
|
|
47
|
-
decrypt: () => decrypt,
|
|
48
|
-
decryptCredentials: () => decryptCredentials,
|
|
49
37
|
deleteSavedAddress: () => deleteSavedAddress,
|
|
50
|
-
encrypt: () => encrypt,
|
|
51
|
-
encryptCredentials: () => encryptCredentials,
|
|
52
38
|
generateAndUploadLabel: () => generateAndUploadLabel,
|
|
53
39
|
generateConsignmentRef: () => generateConsignmentRef,
|
|
54
|
-
generateEncryptionKey: () => generateEncryptionKey,
|
|
55
40
|
generateLabel: () => generateLabel,
|
|
56
41
|
getAuthStatus: () => getAuthStatus,
|
|
57
42
|
getEstimatedDeliveryDate: () => getEstimatedDeliveryDate,
|
|
@@ -65,7 +50,6 @@ __export(index_exports, {
|
|
|
65
50
|
getTokenExpiry: () => getTokenExpiry,
|
|
66
51
|
getTrackingUrl: () => getTrackingUrl,
|
|
67
52
|
hasValidToken: () => hasValidToken,
|
|
68
|
-
hash: () => hash,
|
|
69
53
|
isValidServiceCode: () => isValidServiceCode,
|
|
70
54
|
logOperation: () => logOperation,
|
|
71
55
|
loggedOperation: () => loggedOperation,
|
|
@@ -81,8 +65,7 @@ __export(index_exports, {
|
|
|
81
65
|
updateSavedAddress: () => updateSavedAddress,
|
|
82
66
|
validateAddress: () => validateAddress,
|
|
83
67
|
validateDeliveryAddress: () => validateDeliveryAddress,
|
|
84
|
-
validateServiceCode: () => validateServiceCode
|
|
85
|
-
verifyHash: () => verifyHash
|
|
68
|
+
validateServiceCode: () => validateServiceCode
|
|
86
69
|
});
|
|
87
70
|
module.exports = __toCommonJS(index_exports);
|
|
88
71
|
|
|
@@ -923,97 +906,6 @@ var dpd_service_default = {
|
|
|
923
906
|
getAuthStatus
|
|
924
907
|
};
|
|
925
908
|
|
|
926
|
-
// src/utils/encryption.ts
|
|
927
|
-
var import_crypto = __toESM(require("crypto"));
|
|
928
|
-
var ALGORITHM = "aes-256-gcm";
|
|
929
|
-
var KEY_LENGTH = 32;
|
|
930
|
-
var IV_LENGTH = 16;
|
|
931
|
-
var SALT_LENGTH = 64;
|
|
932
|
-
var TAG_LENGTH = 16;
|
|
933
|
-
var TAG_POSITION = SALT_LENGTH + IV_LENGTH;
|
|
934
|
-
var ENCRYPTED_POSITION = TAG_POSITION + TAG_LENGTH;
|
|
935
|
-
function getEncryptionKey() {
|
|
936
|
-
const envKey = process.env.DPD_ENCRYPTION_KEY;
|
|
937
|
-
if (envKey) {
|
|
938
|
-
return Buffer.from(envKey, "hex");
|
|
939
|
-
}
|
|
940
|
-
if (process.env.NODE_ENV !== "production") {
|
|
941
|
-
console.warn(
|
|
942
|
-
"\u26A0\uFE0F Using default encryption key. Set DPD_ENCRYPTION_KEY in production!"
|
|
943
|
-
);
|
|
944
|
-
return import_crypto.default.scryptSync("dpd-dev-key", "salt", KEY_LENGTH);
|
|
945
|
-
}
|
|
946
|
-
throw new Error(
|
|
947
|
-
"DPD_ENCRYPTION_KEY environment variable is required in production"
|
|
948
|
-
);
|
|
949
|
-
}
|
|
950
|
-
function generateEncryptionKey() {
|
|
951
|
-
const key = import_crypto.default.randomBytes(KEY_LENGTH);
|
|
952
|
-
return key.toString("hex");
|
|
953
|
-
}
|
|
954
|
-
function encrypt(text) {
|
|
955
|
-
try {
|
|
956
|
-
const salt = import_crypto.default.randomBytes(SALT_LENGTH);
|
|
957
|
-
const iv = import_crypto.default.randomBytes(IV_LENGTH);
|
|
958
|
-
const key = import_crypto.default.scryptSync(getEncryptionKey(), salt, KEY_LENGTH);
|
|
959
|
-
const cipher = import_crypto.default.createCipheriv(ALGORITHM, key, iv);
|
|
960
|
-
const encrypted = Buffer.concat([
|
|
961
|
-
cipher.update(text, "utf8"),
|
|
962
|
-
cipher.final()
|
|
963
|
-
]);
|
|
964
|
-
const tag = cipher.getAuthTag();
|
|
965
|
-
const result = Buffer.concat([salt, iv, tag, encrypted]);
|
|
966
|
-
return result.toString("hex");
|
|
967
|
-
} catch (error) {
|
|
968
|
-
console.error("Encryption error:", error);
|
|
969
|
-
throw new Error("Failed to encrypt data");
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
function decrypt(encryptedHex) {
|
|
973
|
-
try {
|
|
974
|
-
const data = Buffer.from(encryptedHex, "hex");
|
|
975
|
-
const salt = data.subarray(0, SALT_LENGTH);
|
|
976
|
-
const iv = data.subarray(SALT_LENGTH, TAG_POSITION);
|
|
977
|
-
const tag = data.subarray(TAG_POSITION, ENCRYPTED_POSITION);
|
|
978
|
-
const encrypted = data.subarray(ENCRYPTED_POSITION);
|
|
979
|
-
const key = import_crypto.default.scryptSync(getEncryptionKey(), salt, KEY_LENGTH);
|
|
980
|
-
const decipher = import_crypto.default.createDecipheriv(ALGORITHM, key, iv);
|
|
981
|
-
decipher.setAuthTag(tag);
|
|
982
|
-
const decrypted = Buffer.concat([
|
|
983
|
-
decipher.update(encrypted),
|
|
984
|
-
decipher.final()
|
|
985
|
-
]);
|
|
986
|
-
return decrypted.toString("utf8");
|
|
987
|
-
} catch (error) {
|
|
988
|
-
console.error("Decryption error:", error);
|
|
989
|
-
throw new Error("Failed to decrypt data");
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
function encryptCredentials(credentials) {
|
|
993
|
-
return {
|
|
994
|
-
accountNumber: credentials.accountNumber,
|
|
995
|
-
username: credentials.username,
|
|
996
|
-
passwordHash: encrypt(credentials.password)
|
|
997
|
-
};
|
|
998
|
-
}
|
|
999
|
-
function decryptCredentials(encryptedCredentials) {
|
|
1000
|
-
return {
|
|
1001
|
-
accountNumber: encryptedCredentials.accountNumber,
|
|
1002
|
-
username: encryptedCredentials.username,
|
|
1003
|
-
password: decrypt(encryptedCredentials.passwordHash)
|
|
1004
|
-
};
|
|
1005
|
-
}
|
|
1006
|
-
function hash(data) {
|
|
1007
|
-
return import_crypto.default.createHash("sha256").update(data).digest("hex");
|
|
1008
|
-
}
|
|
1009
|
-
function verifyHash(data, hashToVerify) {
|
|
1010
|
-
const computed = hash(data);
|
|
1011
|
-
return import_crypto.default.timingSafeEqual(
|
|
1012
|
-
Buffer.from(computed),
|
|
1013
|
-
Buffer.from(hashToVerify)
|
|
1014
|
-
);
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
909
|
// src/utils/logger.ts
|
|
1018
910
|
var defaultConfig = {
|
|
1019
911
|
enabled: true,
|
|
@@ -1193,14 +1085,9 @@ function logToConsole(logData) {
|
|
|
1193
1085
|
createCompleteShipment,
|
|
1194
1086
|
createDPDConfig,
|
|
1195
1087
|
createShipment,
|
|
1196
|
-
decrypt,
|
|
1197
|
-
decryptCredentials,
|
|
1198
1088
|
deleteSavedAddress,
|
|
1199
|
-
encrypt,
|
|
1200
|
-
encryptCredentials,
|
|
1201
1089
|
generateAndUploadLabel,
|
|
1202
1090
|
generateConsignmentRef,
|
|
1203
|
-
generateEncryptionKey,
|
|
1204
1091
|
generateLabel,
|
|
1205
1092
|
getAuthStatus,
|
|
1206
1093
|
getEstimatedDeliveryDate,
|
|
@@ -1214,7 +1101,6 @@ function logToConsole(logData) {
|
|
|
1214
1101
|
getTokenExpiry,
|
|
1215
1102
|
getTrackingUrl,
|
|
1216
1103
|
hasValidToken,
|
|
1217
|
-
hash,
|
|
1218
1104
|
isValidServiceCode,
|
|
1219
1105
|
logOperation,
|
|
1220
1106
|
loggedOperation,
|
|
@@ -1230,8 +1116,7 @@ function logToConsole(logData) {
|
|
|
1230
1116
|
updateSavedAddress,
|
|
1231
1117
|
validateAddress,
|
|
1232
1118
|
validateDeliveryAddress,
|
|
1233
|
-
validateServiceCode
|
|
1234
|
-
verifyHash
|
|
1119
|
+
validateServiceCode
|
|
1235
1120
|
});
|
|
1236
1121
|
/**
|
|
1237
1122
|
* DPD Local SDK
|
|
@@ -1240,7 +1125,7 @@ function logToConsole(logData) {
|
|
|
1240
1125
|
* Database-agnostic and framework-independent
|
|
1241
1126
|
*
|
|
1242
1127
|
* @package @jazzdev/dpd-local-sdk
|
|
1243
|
-
* @version 1.0.
|
|
1244
|
-
* @author
|
|
1128
|
+
* @version 1.0.12
|
|
1129
|
+
* @author Taiow Babarinde <babsman4all@gmail.com>
|
|
1245
1130
|
* @license MIT
|
|
1246
1131
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -835,97 +835,6 @@ var dpd_service_default = {
|
|
|
835
835
|
getAuthStatus
|
|
836
836
|
};
|
|
837
837
|
|
|
838
|
-
// src/utils/encryption.ts
|
|
839
|
-
import crypto from "crypto";
|
|
840
|
-
var ALGORITHM = "aes-256-gcm";
|
|
841
|
-
var KEY_LENGTH = 32;
|
|
842
|
-
var IV_LENGTH = 16;
|
|
843
|
-
var SALT_LENGTH = 64;
|
|
844
|
-
var TAG_LENGTH = 16;
|
|
845
|
-
var TAG_POSITION = SALT_LENGTH + IV_LENGTH;
|
|
846
|
-
var ENCRYPTED_POSITION = TAG_POSITION + TAG_LENGTH;
|
|
847
|
-
function getEncryptionKey() {
|
|
848
|
-
const envKey = process.env.DPD_ENCRYPTION_KEY;
|
|
849
|
-
if (envKey) {
|
|
850
|
-
return Buffer.from(envKey, "hex");
|
|
851
|
-
}
|
|
852
|
-
if (process.env.NODE_ENV !== "production") {
|
|
853
|
-
console.warn(
|
|
854
|
-
"\u26A0\uFE0F Using default encryption key. Set DPD_ENCRYPTION_KEY in production!"
|
|
855
|
-
);
|
|
856
|
-
return crypto.scryptSync("dpd-dev-key", "salt", KEY_LENGTH);
|
|
857
|
-
}
|
|
858
|
-
throw new Error(
|
|
859
|
-
"DPD_ENCRYPTION_KEY environment variable is required in production"
|
|
860
|
-
);
|
|
861
|
-
}
|
|
862
|
-
function generateEncryptionKey() {
|
|
863
|
-
const key = crypto.randomBytes(KEY_LENGTH);
|
|
864
|
-
return key.toString("hex");
|
|
865
|
-
}
|
|
866
|
-
function encrypt(text) {
|
|
867
|
-
try {
|
|
868
|
-
const salt = crypto.randomBytes(SALT_LENGTH);
|
|
869
|
-
const iv = crypto.randomBytes(IV_LENGTH);
|
|
870
|
-
const key = crypto.scryptSync(getEncryptionKey(), salt, KEY_LENGTH);
|
|
871
|
-
const cipher = crypto.createCipheriv(ALGORITHM, key, iv);
|
|
872
|
-
const encrypted = Buffer.concat([
|
|
873
|
-
cipher.update(text, "utf8"),
|
|
874
|
-
cipher.final()
|
|
875
|
-
]);
|
|
876
|
-
const tag = cipher.getAuthTag();
|
|
877
|
-
const result = Buffer.concat([salt, iv, tag, encrypted]);
|
|
878
|
-
return result.toString("hex");
|
|
879
|
-
} catch (error) {
|
|
880
|
-
console.error("Encryption error:", error);
|
|
881
|
-
throw new Error("Failed to encrypt data");
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
function decrypt(encryptedHex) {
|
|
885
|
-
try {
|
|
886
|
-
const data = Buffer.from(encryptedHex, "hex");
|
|
887
|
-
const salt = data.subarray(0, SALT_LENGTH);
|
|
888
|
-
const iv = data.subarray(SALT_LENGTH, TAG_POSITION);
|
|
889
|
-
const tag = data.subarray(TAG_POSITION, ENCRYPTED_POSITION);
|
|
890
|
-
const encrypted = data.subarray(ENCRYPTED_POSITION);
|
|
891
|
-
const key = crypto.scryptSync(getEncryptionKey(), salt, KEY_LENGTH);
|
|
892
|
-
const decipher = crypto.createDecipheriv(ALGORITHM, key, iv);
|
|
893
|
-
decipher.setAuthTag(tag);
|
|
894
|
-
const decrypted = Buffer.concat([
|
|
895
|
-
decipher.update(encrypted),
|
|
896
|
-
decipher.final()
|
|
897
|
-
]);
|
|
898
|
-
return decrypted.toString("utf8");
|
|
899
|
-
} catch (error) {
|
|
900
|
-
console.error("Decryption error:", error);
|
|
901
|
-
throw new Error("Failed to decrypt data");
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
function encryptCredentials(credentials) {
|
|
905
|
-
return {
|
|
906
|
-
accountNumber: credentials.accountNumber,
|
|
907
|
-
username: credentials.username,
|
|
908
|
-
passwordHash: encrypt(credentials.password)
|
|
909
|
-
};
|
|
910
|
-
}
|
|
911
|
-
function decryptCredentials(encryptedCredentials) {
|
|
912
|
-
return {
|
|
913
|
-
accountNumber: encryptedCredentials.accountNumber,
|
|
914
|
-
username: encryptedCredentials.username,
|
|
915
|
-
password: decrypt(encryptedCredentials.passwordHash)
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
function hash(data) {
|
|
919
|
-
return crypto.createHash("sha256").update(data).digest("hex");
|
|
920
|
-
}
|
|
921
|
-
function verifyHash(data, hashToVerify) {
|
|
922
|
-
const computed = hash(data);
|
|
923
|
-
return crypto.timingSafeEqual(
|
|
924
|
-
Buffer.from(computed),
|
|
925
|
-
Buffer.from(hashToVerify)
|
|
926
|
-
);
|
|
927
|
-
}
|
|
928
|
-
|
|
929
838
|
// src/utils/logger.ts
|
|
930
839
|
var defaultConfig = {
|
|
931
840
|
enabled: true,
|
|
@@ -1104,14 +1013,9 @@ export {
|
|
|
1104
1013
|
createCompleteShipment,
|
|
1105
1014
|
createDPDConfig,
|
|
1106
1015
|
createShipment,
|
|
1107
|
-
decrypt,
|
|
1108
|
-
decryptCredentials,
|
|
1109
1016
|
deleteSavedAddress,
|
|
1110
|
-
encrypt,
|
|
1111
|
-
encryptCredentials,
|
|
1112
1017
|
generateAndUploadLabel,
|
|
1113
1018
|
generateConsignmentRef,
|
|
1114
|
-
generateEncryptionKey,
|
|
1115
1019
|
generateLabel,
|
|
1116
1020
|
getAuthStatus,
|
|
1117
1021
|
getEstimatedDeliveryDate,
|
|
@@ -1125,7 +1029,6 @@ export {
|
|
|
1125
1029
|
getTokenExpiry,
|
|
1126
1030
|
getTrackingUrl,
|
|
1127
1031
|
hasValidToken,
|
|
1128
|
-
hash,
|
|
1129
1032
|
isValidServiceCode,
|
|
1130
1033
|
logOperation,
|
|
1131
1034
|
loggedOperation,
|
|
@@ -1141,8 +1044,7 @@ export {
|
|
|
1141
1044
|
updateSavedAddress,
|
|
1142
1045
|
validateAddress,
|
|
1143
1046
|
validateDeliveryAddress,
|
|
1144
|
-
validateServiceCode
|
|
1145
|
-
verifyHash
|
|
1047
|
+
validateServiceCode
|
|
1146
1048
|
};
|
|
1147
1049
|
/**
|
|
1148
1050
|
* DPD Local SDK
|
|
@@ -1151,7 +1053,7 @@ export {
|
|
|
1151
1053
|
* Database-agnostic and framework-independent
|
|
1152
1054
|
*
|
|
1153
1055
|
* @package @jazzdev/dpd-local-sdk
|
|
1154
|
-
* @version 1.0.
|
|
1155
|
-
* @author
|
|
1056
|
+
* @version 1.0.12
|
|
1057
|
+
* @author Taiow Babarinde <babsman4all@gmail.com>
|
|
1156
1058
|
* @license MIT
|
|
1157
1059
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jazzdev/dpd-local-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
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",
|
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
17
|
"README.md",
|
|
18
|
-
"LICENSE"
|
|
19
|
-
"CHANGELOG.md"
|
|
18
|
+
"LICENSE"
|
|
20
19
|
],
|
|
21
20
|
"scripts": {
|
|
22
21
|
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
@@ -43,12 +42,12 @@
|
|
|
43
42
|
"license": "MIT",
|
|
44
43
|
"repository": {
|
|
45
44
|
"type": "git",
|
|
46
|
-
"url": "https://github.com/TheJazzDev/dpd-local-sdk
|
|
45
|
+
"url": "https://github.com/TheJazzDev/dpd-local-sdk"
|
|
47
46
|
},
|
|
48
47
|
"bugs": {
|
|
49
|
-
"url": "https://github.com/TheJazzDev/dpd-local-sdk
|
|
48
|
+
"url": "https://github.com/TheJazzDev/dpd-local-sdk/issues"
|
|
50
49
|
},
|
|
51
|
-
"homepage": "https://github.com/TheJazzDev/dpd-local-sdk
|
|
50
|
+
"homepage": "https://github.com/TheJazzDev/dpd-local-sdk#readme",
|
|
52
51
|
"devDependencies": {
|
|
53
52
|
"@types/node": "^20.0.0",
|
|
54
53
|
"dotenv": "^17.2.3",
|
package/CHANGELOG.md
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
-
|
|
8
|
-
## [1.0.0] - 2024-01-04
|
|
9
|
-
|
|
10
|
-
### Added
|
|
11
|
-
- Initial release of DPD Local SDK
|
|
12
|
-
- Complete DPD API integration (authentication, shipments, labels, tracking)
|
|
13
|
-
- Database-agnostic adapter pattern
|
|
14
|
-
- TypeScript-first design with full type definitions
|
|
15
|
-
- Address validation using postcodes.io API
|
|
16
|
-
- Automatic token management and caching
|
|
17
|
-
- Request retry logic with exponential backoff
|
|
18
|
-
- Comprehensive error handling
|
|
19
|
-
- Detailed logging system
|
|
20
|
-
- Encryption utilities for sensitive data
|
|
21
|
-
- Configuration factory function
|
|
22
|
-
- Helper functions for pricing, dates, and tracking
|
|
23
|
-
- Example adapters for Firestore and Firebase Storage
|
|
24
|
-
- Complete documentation and usage examples
|
|
25
|
-
|
|
26
|
-
### Features
|
|
27
|
-
- ✅ Create shipments with DPD
|
|
28
|
-
- ✅ Generate and upload shipping labels (thermal/A4)
|
|
29
|
-
- ✅ Validate UK delivery addresses
|
|
30
|
-
- ✅ Save and manage customer addresses
|
|
31
|
-
- ✅ Calculate shipping costs and delivery fees
|
|
32
|
-
- ✅ Track shipments
|
|
33
|
-
- ✅ Multi-parcel support
|
|
34
|
-
- ✅ Service selection (Next Day, By 12 PM)
|
|
35
|
-
- ✅ Customer notifications (email, SMS via DPD)
|
|
36
|
-
- ✅ Comprehensive logging and audit trail
|
|
37
|
-
|
|
38
|
-
[1.0.0]: https://github.com/your-org/dpd-local-sdk/releases/tag/v1.0.0
|