UNPKG

@hotwax/oms-api

Version:

The OMS API package comes with prebuilt methods that helps communicate with HotWax Commerce OMS using Rest API

73 lines (69 loc) 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.productTransformRule = void 0; var productTransformRule = { item: { productId: "productId", pseudoId: "internalName", productName: "productName", salesIntroductionDate: "introductionDate", variants: "variantProductIds", parent: { "productName": "parentProductName", "id": "groupId" }, images: { mainImageUrl: "mainImageUrl", additionalImageUrls: "additionalImageUrls" }, features: "productFeatures", identifications: "goodIdentifications", brandName: "brandName", sku: "sku" }, operate: [{ run: function run(features) { // Used productFeatures that contains values in the format(featureId/featureValue) if (features) { var productFeatures = features === null || features === void 0 ? void 0 : features.reduce(function (acc, feature) { var key = feature.split('/')[0]; var value = feature.split('/')[1]; if (acc[key]) { acc[key].push(value); } else { acc[key] = [value]; } return acc; }, {}); return Object.keys(productFeatures).map(function (key) { return { "desc": key, "value": productFeatures[key] }; }); } }, on: "features" }, { run: function run(identifications) { // used goodIdentifications that contains values in the format(id/value OR id/child-id/value) if (identifications !== null && identifications !== void 0 && identifications.length) { return identifications.map(function (identification) { // using lastIndexOf `/` as some of the identifiers are in the format `ABC/abc/123` and thus to handle check for `ABC/abc` var index = identification.lastIndexOf('/'); var key = identification.slice(0, index); var value = identification.slice(index + 1); return { productIdTypeEnumId: key, idValue: value }; }); } return []; }, on: "identifications" }] }; exports.productTransformRule = productTransformRule;