@riocrypto/common-server 1.0.2665 → 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.
@@ -20,7 +20,7 @@ const node_cache_1 = __importDefault(require("node-cache"));
20
20
  const cache = new node_cache_1.default({ stdTTL: 60 });
21
21
  const cache2 = new node_cache_1.default({ stdTTL: 10000 });
22
22
  const POLYGON_FEE_CONFIG = {
23
- gasPrice: "10000",
23
+ gasPrice: "5000",
24
24
  gasLimit: "100000",
25
25
  };
26
26
  const POLYGON_ASSETS = [
@@ -2,7 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateReference = void 0;
4
4
  const generateReference = (order) => {
5
- const referenceNumber = order.id.slice(-6);
6
- return referenceNumber;
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 last6Chars = bulkPaymentId.slice(-6);
34
- return referenceText.includes(last6Chars);
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 last6Chars = orderId.slice(-6);
53
- if (referenceText.includes(last6Chars)) {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2665",
3
+ "version": "1.0.2667",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",