vsf-utilities
Version:
Utilities functions shared between vsf projects
30 lines • 1.16 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const getProductOptions_1 = __importDefault(require("./getProductOptions"));
const sha3_1 = require("sha3");
const getDataToHash = (product) => {
if (!product.product_option) {
return null;
}
const supportedProductOptions = ['bundle_options', 'custom_options', 'configurable_item_options'];
// returns first options that has array with options
for (const optionName of supportedProductOptions) {
const options = getProductOptions_1.default(product, optionName);
if (options.length) {
return options;
}
}
// if there are options that are not supported then just return all options
return product.product_option;
};
const productChecksum = (product) => {
const hash = new sha3_1.SHA3(224);
return hash
.update(JSON.stringify(getDataToHash(product)))
.digest('hex');
};
exports.default = productChecksum;
//# sourceMappingURL=productChecksum.js.map