@riocrypto/common-server 1.0.2667 → 1.0.2668

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.
@@ -10,9 +10,11 @@ const generateReference = (order) => {
10
10
  // Using last 6 chars alone caused collisions (~50/month) because the counter
11
11
  // portion can overlap across different MongoDB instances/pods.
12
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();
13
+ // Solution: 2 chars from random portion (8-9) + last 6 chars of order ID.
14
+ // Last 6 chars are kept for easy traceability by finance team.
15
+ // This gives 16^8 = 4.3 billion combinations vs 16^6 = 16.7 million (256x better).
16
+ const randomPrefix = order.id.slice(8, 10);
17
+ const last6 = order.id.slice(-6);
18
+ return (randomPrefix + last6).toUpperCase();
17
19
  };
18
20
  exports.generateReference = generateReference;
@@ -28,11 +28,13 @@ 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
+ // Reference format: 2 chars from random portion (8-9) + last 6 chars of ID
32
32
  const bulkPayment = bulkPayments.find((bulkPayment) => {
33
33
  const bulkPaymentId = bulkPayment.id.toString().toLowerCase();
34
- const reference7Chars = bulkPaymentId.slice(8, 15);
35
- return referenceText.includes(reference7Chars);
34
+ const randomPrefix = bulkPaymentId.slice(8, 10);
35
+ const last6 = bulkPaymentId.slice(-6);
36
+ const reference8Chars = randomPrefix + last6;
37
+ return referenceText.includes(reference8Chars);
36
38
  });
37
39
  if (!bulkPayment) {
38
40
  throw new Error("Bulk payment not found");
@@ -47,11 +47,13 @@ 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
+ // Reference format: 2 chars from random portion (8-9) + last 6 chars of order ID
51
51
  for (const order of orders) {
52
52
  const orderId = order._id.toString().toLowerCase();
53
- const reference7Chars = orderId.slice(8, 15);
54
- if (referenceText.includes(reference7Chars)) {
53
+ const randomPrefix = orderId.slice(8, 10);
54
+ const last6 = orderId.slice(-6);
55
+ const reference8Chars = randomPrefix + last6;
56
+ if (referenceText.includes(reference8Chars)) {
55
57
  // Found a match, now fetch the full order document
56
58
  foundOrder = yield Order.findById(order._id);
57
59
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2667",
3
+ "version": "1.0.2668",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",