customerio-node
Version:
A node client for the Customer.io event API. http://customer.io
48 lines (47 loc) • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MissingParamError = exports.CustomerIORequestError = exports.isIdentifierType = exports.cleanEmail = exports.isEmpty = void 0;
const types_1 = require("../lib/types");
const isEmpty = (value) => {
return value === null || value === undefined || (typeof value === 'string' && value.trim() === '');
};
exports.isEmpty = isEmpty;
const cleanEmail = (email) => {
return email.split('@').map(encodeURIComponent).join('@');
};
exports.cleanEmail = cleanEmail;
const isIdentifierType = (value) => {
return Object.values(types_1.IdentifierType).includes(value);
};
exports.isIdentifierType = isIdentifierType;
class CustomerIORequestError extends Error {
static composeMessage(json) {
if (!json) {
return 'Unknown error';
}
if (json.meta && json.meta.error) {
return json.meta.error;
}
else if (json.meta && json.meta.errors) {
const count = json.meta.errors.length;
return `${count} ${count === 1 ? 'error' : 'errors'}:
${json.meta.errors.map((error) => ` - ${error}`).join('\n')}`;
}
return 'Unknown error';
}
constructor(json, statusCode, response, body) {
super(CustomerIORequestError.composeMessage(json));
this.name = 'CustomerIORequestError';
this.statusCode = statusCode;
this.response = response;
this.body = body;
}
}
exports.CustomerIORequestError = CustomerIORequestError;
class MissingParamError extends Error {
constructor(param) {
super(param);
this.message = `${param} is required`;
}
}
exports.MissingParamError = MissingParamError;