UNPKG

@whitebox-co/walmart-marketplace-api

Version:

A fully typed TypeScript, Javascript, and Node.js API library for the Walmart Marketplace API

207 lines 7.8 kB
"use strict"; /* tslint:disable */ /* eslint-disable */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Convert = exports.ReplaceAll = exports.ProcessMode = exports.PriceDisplayCodes = exports.CurrentPriceType = exports.ComparisonPriceType = exports.Currency = void 0; var Currency; (function (Currency) { Currency["CAD"] = "CAD"; Currency["Usd"] = "USD"; })(Currency = exports.Currency || (exports.Currency = {})); var ComparisonPriceType; (function (ComparisonPriceType) { ComparisonPriceType["Base"] = "BASE"; })(ComparisonPriceType = exports.ComparisonPriceType || (exports.ComparisonPriceType = {})); var CurrentPriceType; (function (CurrentPriceType) { CurrentPriceType["Base"] = "BASE"; CurrentPriceType["Clearance"] = "CLEARANCE"; CurrentPriceType["Reduced"] = "REDUCED"; })(CurrentPriceType = exports.CurrentPriceType || (exports.CurrentPriceType = {})); var PriceDisplayCodes; (function (PriceDisplayCodes) { PriceDisplayCodes["Cart"] = "CART"; PriceDisplayCodes["Checkout"] = "CHECKOUT"; })(PriceDisplayCodes = exports.PriceDisplayCodes || (exports.PriceDisplayCodes = {})); var ProcessMode; (function (ProcessMode) { ProcessMode["Delete"] = "DELETE"; ProcessMode["Upsert"] = "UPSERT"; })(ProcessMode = exports.ProcessMode || (exports.ProcessMode = {})); var ReplaceAll; (function (ReplaceAll) { ReplaceAll["False"] = "false"; ReplaceAll["True"] = "true"; })(ReplaceAll = exports.ReplaceAll || (exports.ReplaceAll = {})); // Converts JSON strings to/from your types // and asserts the results of JSON.parse at runtime class Convert { static toPrice(json) { return cast(JSON.parse(json), r('Price')); } static priceToJson(value) { return JSON.stringify(uncast(value, r('Price')), null, 2); } } exports.Convert = Convert; function invalidValue(typ, val, key = '') { if (key) { throw Error(`Invalid value for key "${key}". Expected type ${JSON.stringify(typ)} but got ${JSON.stringify(val)}`); } throw Error(`Invalid value ${JSON.stringify(val)} for type ${JSON.stringify(typ)}`); } function jsonToJSProps(typ) { if (typ.jsonToJS === undefined) { const map = {}; typ.props.forEach((p) => (map[p.json] = { key: p.js, typ: p.typ })); typ.jsonToJS = map; } return typ.jsonToJS; } function jsToJSONProps(typ) { if (typ.jsToJSON === undefined) { const map = {}; typ.props.forEach((p) => (map[p.js] = { key: p.json, typ: p.typ })); typ.jsToJSON = map; } return typ.jsToJSON; } function transform(val, typ, getProps, key = '') { function transformPrimitive(typ, val) { if (typeof typ === typeof val) return val; return invalidValue(typ, val, key); } function transformUnion(typs, val) { // val must validate against one typ in typs const l = typs.length; for (let i = 0; i < l; i++) { const typ = typs[i]; try { return transform(val, typ, getProps); } catch (_) { } } return invalidValue(typs, val); } function transformEnum(cases, val) { if (cases.indexOf(val) !== -1) return val; return invalidValue(cases, val); } function transformArray(typ, val) { // val must be an array with no invalid elements if (!Array.isArray(val)) return invalidValue('array', val); return val.map((el) => transform(el, typ, getProps)); } function transformDate(val) { if (val === null) { return null; } const d = new Date(val); if (isNaN(d.valueOf())) { return invalidValue('Date', val); } return d; } function transformObject(props, additional, val) { if (val === null || typeof val !== 'object' || Array.isArray(val)) { return invalidValue('object', val); } const result = {}; Object.getOwnPropertyNames(props).forEach((key) => { const prop = props[key]; const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; result[prop.key] = transform(v, prop.typ, getProps, prop.key); }); Object.getOwnPropertyNames(val).forEach((key) => { if (!Object.prototype.hasOwnProperty.call(props, key)) { result[key] = transform(val[key], additional, getProps, key); } }); return result; } if (typ === 'any') return val; if (typ === null) { if (val === null) return val; return invalidValue(typ, val); } if (typ === false) return invalidValue(typ, val); while (typeof typ === 'object' && typ.ref !== undefined) { typ = typeMap[typ.ref]; } if (Array.isArray(typ)) return transformEnum(typ, val); if (typeof typ === 'object') { return typ.hasOwnProperty('unionMembers') ? transformUnion(typ.unionMembers, val) : typ.hasOwnProperty('arrayItems') ? transformArray(typ.arrayItems, val) : typ.hasOwnProperty('props') ? transformObject(getProps(typ), typ.additional, val) : invalidValue(typ, val); } // Numbers can be parsed by Date but shouldn't be. if (typ === Date && typeof val !== 'number') return transformDate(val); return transformPrimitive(typ, val); } function cast(val, typ) { return transform(val, typ, jsonToJSProps); } function uncast(val, typ) { return transform(val, typ, jsToJSONProps); } function a(typ) { return { arrayItems: typ }; } function u(...typs) { return { unionMembers: typs }; } function o(props, additional) { return { props, additional }; } function m(additional) { return { props: [], additional }; } function r(name) { return { ref: name }; } const typeMap = { Price: o([ { json: 'offerId', js: 'offerId', typ: u(undefined, '') }, { json: 'pricing', js: 'pricing', typ: a(r('Pricing')) }, { json: 'replaceAll', js: 'replaceAll', typ: u(undefined, r('ReplaceAll')) }, { json: 'sku', js: 'sku', typ: '' }, ], false), Pricing: o([ { json: 'comparisonPrice', js: 'comparisonPrice', typ: u(undefined, r('ComparisonPrice')) }, { json: 'comparisonPriceType', js: 'comparisonPriceType', typ: u(undefined, r('ComparisonPriceType')) }, { json: 'currentPrice', js: 'currentPrice', typ: u(undefined, r('CurrentPrice')) }, { json: 'currentPriceType', js: 'currentPriceType', typ: u(undefined, r('CurrentPriceType')) }, { json: 'effectiveDate', js: 'effectiveDate', typ: u(undefined, Date) }, { json: 'expirationDate', js: 'expirationDate', typ: u(undefined, Date) }, { json: 'priceDisplayCodes', js: 'priceDisplayCodes', typ: u(undefined, r('PriceDisplayCodes')) }, { json: 'processMode', js: 'processMode', typ: u(undefined, r('ProcessMode')) }, { json: 'promoId', js: 'promoId', typ: u(undefined, '') }, ], false), ComparisonPrice: o([ { json: 'amount', js: 'amount', typ: u(undefined, 3.14) }, { json: 'currency', js: 'currency', typ: u(undefined, r('Currency')) }, ], false), CurrentPrice: o([ { json: 'amount', js: 'amount', typ: u(undefined, 3.14) }, { json: 'currency', js: 'currency', typ: u(undefined, r('Currency')) }, ], false), Currency: ['CAD', 'USD'], ComparisonPriceType: ['BASE'], CurrentPriceType: ['BASE', 'CLEARANCE', 'REDUCED'], PriceDisplayCodes: ['CART', 'CHECKOUT'], ProcessMode: ['DELETE', 'UPSERT'], ReplaceAll: ['false', 'true'], }; //# sourceMappingURL=price.js.map