salsify-experiences-sdk
Version:
SDK to be used by commerce websites to implement product experiences.
28 lines • 1.07 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const base_1 = __importDefault(require("../base"));
const CURRENCY_REGEX = new RegExp(/^[A-Z]{3}$/);
/** @internal */
class AddToCartEventHandler extends base_1.default {
eventName = 'add_to_cart';
handle(options, extraProperties) {
const errorMessage = this.#validateOptions(options);
if (errorMessage) {
this.handleValidationError(errorMessage);
}
else {
super.handle(options, extraProperties);
}
}
#validateOptions(options) {
if (options.currency && !CURRENCY_REGEX.test(options.currency)) {
return `Invalid 3-character alphabetic ISO-4217 currency code: ${options.currency}. See: https://www.iso.org/iso-4217-currency-codes.html.`;
}
return undefined;
}
}
exports.default = AddToCartEventHandler;
//# sourceMappingURL=index.js.map