rerobe-js-orm 4.4.4 → 4.4.5
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.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polyfill for Node.js crypto module to work in React Native environments
|
|
3
|
+
* Provides the same interface as Node.js crypto.createHash() but uses crypto-js
|
|
4
|
+
*/
|
|
5
|
+
export declare function createHash(algorithm: string): {
|
|
6
|
+
update: (data: string) => {
|
|
7
|
+
digest: (encoding: string) => string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createHash = void 0;
|
|
4
|
+
const CryptoJS = require("crypto-js");
|
|
5
|
+
/**
|
|
6
|
+
* Polyfill for Node.js crypto module to work in React Native environments
|
|
7
|
+
* Provides the same interface as Node.js crypto.createHash() but uses crypto-js
|
|
8
|
+
*/
|
|
9
|
+
function createHash(algorithm) {
|
|
10
|
+
return {
|
|
11
|
+
update: (data) => {
|
|
12
|
+
return {
|
|
13
|
+
digest: (encoding) => {
|
|
14
|
+
let hash;
|
|
15
|
+
switch (algorithm.toLowerCase()) {
|
|
16
|
+
case 'sha256':
|
|
17
|
+
hash = CryptoJS.SHA256(data).toString();
|
|
18
|
+
break;
|
|
19
|
+
case 'md5':
|
|
20
|
+
hash = CryptoJS.MD5(data).toString();
|
|
21
|
+
break;
|
|
22
|
+
case 'sha1':
|
|
23
|
+
hash = CryptoJS.SHA1(data).toString();
|
|
24
|
+
break;
|
|
25
|
+
case 'sha512':
|
|
26
|
+
hash = CryptoJS.SHA512(data).toString();
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
throw new Error(`Unsupported hash algorithm: ${algorithm}`);
|
|
30
|
+
}
|
|
31
|
+
// Return hex string (crypto-js default) or convert if needed
|
|
32
|
+
if (encoding === 'hex') {
|
|
33
|
+
return hash;
|
|
34
|
+
}
|
|
35
|
+
else if (encoding === 'base64') {
|
|
36
|
+
return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Hex.parse(hash));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new Error(`Unsupported encoding: ${encoding}`);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.createHash = createHash;
|
|
@@ -4,7 +4,7 @@ const Order_1 = require("../models/Order");
|
|
|
4
4
|
const Utilities_1 = require("../helpers/Utilities");
|
|
5
5
|
const order_constants_1 = require("../constants/order-constants");
|
|
6
6
|
const translations_1 = require("../translations");
|
|
7
|
-
const
|
|
7
|
+
const CryptoPolyfill_1 = require("./CryptoPolyfill");
|
|
8
8
|
class OrderHelpers {
|
|
9
9
|
getOrderIdFromShopifyObj(order) {
|
|
10
10
|
const { id, tags } = order;
|
|
@@ -717,7 +717,7 @@ class OrderHelpers {
|
|
|
717
717
|
// Filter out empty values and join
|
|
718
718
|
const keyString = keyComponents.filter((component) => component && String(component).trim().length > 0).join('|');
|
|
719
719
|
// Generate SHA-256 hash for consistent length and uniqueness
|
|
720
|
-
return (0,
|
|
720
|
+
return (0, CryptoPolyfill_1.createHash)('sha256').update(keyString).digest('hex').substring(0, 32); // Truncate to 32 characters for manageable length
|
|
721
721
|
}
|
|
722
722
|
/**
|
|
723
723
|
* Generates a time bucket string for idempotency key
|
|
@@ -754,7 +754,7 @@ class OrderHelpers {
|
|
|
754
754
|
return (a.productId || '').localeCompare(b.productId || '');
|
|
755
755
|
});
|
|
756
756
|
const itemsString = JSON.stringify(normalizedItems);
|
|
757
|
-
return (0,
|
|
757
|
+
return (0, CryptoPolyfill_1.createHash)('md5').update(itemsString).digest('hex').substring(0, 16); // Truncate MD5 to 16 characters
|
|
758
758
|
}
|
|
759
759
|
}
|
|
760
760
|
exports.default = OrderHelpers;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rerobe-js-orm",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.5",
|
|
4
4
|
"description": "ReRobe's Javascript ORM Framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/ReRobe/rerobe-product#readme",
|
|
30
30
|
"devDependencies": {
|
|
31
|
+
"@types/crypto-js": "^4.2.2",
|
|
31
32
|
"@types/jest": "^26.0.23",
|
|
32
33
|
"@types/slug": "^5.0.9",
|
|
33
34
|
"jest": "^26.6.3",
|
|
@@ -41,6 +42,7 @@
|
|
|
41
42
|
"lib/**/*"
|
|
42
43
|
],
|
|
43
44
|
"dependencies": {
|
|
45
|
+
"crypto-js": "^4.2.0",
|
|
44
46
|
"js-base64": "^3.3.3",
|
|
45
47
|
"lodash": "^4.17.21",
|
|
46
48
|
"slug": "^9.1.0"
|