@riocrypto/common-server 1.0.2666 → 1.0.2667
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.
|
@@ -2,7 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateReference = void 0;
|
|
4
4
|
const generateReference = (order) => {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// MongoDB ObjectId structure (24 hex chars):
|
|
6
|
+
// - chars 0-7: timestamp (4 bytes)
|
|
7
|
+
// - chars 8-17: random value (5 bytes)
|
|
8
|
+
// - chars 18-23: incrementing counter (3 bytes)
|
|
9
|
+
//
|
|
10
|
+
// Using last 6 chars alone caused collisions (~50/month) because the counter
|
|
11
|
+
// portion can overlap across different MongoDB instances/pods.
|
|
12
|
+
//
|
|
13
|
+
// Solution: Use 7 consecutive chars from the random portion (8-14).
|
|
14
|
+
// This gives 16^7 = 268 million combinations vs 16^6 = 16.7 million (16x better).
|
|
15
|
+
// Using consecutive chars from the ID keeps it simple and traceable.
|
|
16
|
+
return order.id.slice(8, 15).toUpperCase();
|
|
7
17
|
};
|
|
8
18
|
exports.generateReference = generateReference;
|
|
@@ -28,10 +28,11 @@ const getBulkPaymentFromReference = (reference, mongoose) => __awaiter(void 0, v
|
|
|
28
28
|
],
|
|
29
29
|
},
|
|
30
30
|
});
|
|
31
|
+
// Reference format uses 7 consecutive chars from the random portion (8-14)
|
|
31
32
|
const bulkPayment = bulkPayments.find((bulkPayment) => {
|
|
32
33
|
const bulkPaymentId = bulkPayment.id.toString().toLowerCase();
|
|
33
|
-
const
|
|
34
|
-
return referenceText.includes(
|
|
34
|
+
const reference7Chars = bulkPaymentId.slice(8, 15);
|
|
35
|
+
return referenceText.includes(reference7Chars);
|
|
35
36
|
});
|
|
36
37
|
if (!bulkPayment) {
|
|
37
38
|
throw new Error("Bulk payment not found");
|
|
@@ -47,10 +47,11 @@ const getOrderFromReference = (reference, mongoose) => __awaiter(void 0, void 0,
|
|
|
47
47
|
break;
|
|
48
48
|
}
|
|
49
49
|
// Check each order ID against the reference
|
|
50
|
+
// Reference format uses 7 consecutive chars from the random portion (8-14)
|
|
50
51
|
for (const order of orders) {
|
|
51
52
|
const orderId = order._id.toString().toLowerCase();
|
|
52
|
-
const
|
|
53
|
-
if (referenceText.includes(
|
|
53
|
+
const reference7Chars = orderId.slice(8, 15);
|
|
54
|
+
if (referenceText.includes(reference7Chars)) {
|
|
54
55
|
// Found a match, now fetch the full order document
|
|
55
56
|
foundOrder = yield Order.findById(order._id);
|
|
56
57
|
break;
|