Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function validateBasket(crystallizeBasket, _opt) {
ow(crystallizeBasket, ow.object);
const { items, coupon } = crystallizeBasket;
ow(items, ow.array);
ow(coupon, ow.any(ow.string, ow.null));
ow(_opt, ow.any(ow.object, ow.undefined));
const options = Object.assign(
{
excludeDiscount: true,
excludeShipping: true
},
_opt
);
let discount = null;
if (items.length === 0) {
return {
success: false,
validatedBasket: {
coupon,
this.actionWrapper(async () => {
if (file) ow(file, ow_extend.parentDirExists("file"));
ow(options.format, ow.string.label("format").oneOf(["yml", "json"]));
ow(options.override, ow.any(ow.undefined, ow.boolean.label("override")));
if (options.account) ow(options.account, ow.string.minLength(3));
ow(options.stdout, ow.any(ow.undefined, ow.boolean.label("override")));
return new DownloadRulesAction(this.context).doAction(await this.loadConfig(true), file, options);
}),
);
this.actionWrapper(async () => {
if (path) ow(path, ow_extend.fileExists("path"));
ow(options.global, ow.any(ow.undefined, ow.boolean.label("global")));
if (options.config) ow(options.config, ow_extend.fileExists("config"));
if (options.rules) ow(options.rules, ow_extend.fileExists("rules"));
if (options.username) ow(options.username, ow.string.minLength(3));
ow(options.savePostingKey, ow.any(ow.undefined, ow.boolean.label("savePostingKey")));
ow(options.dontSavePostingKey, ow.any(ow.undefined, ow.boolean.label("dontSavePostingKey")));
ow(
options.sinceBlockNum,
ow.any(ow.undefined, ow.number.label("sinceBlockNum").finite.greaterThan(0)),
);
if (options.syncedBlockNumPath) {
ow(options.syncedBlockNumPath, ow_extend.fileExists("syncedBlockNumPath"));
}
return new InitAction(this.context).doAction(options, path);
}),
);