connect-sdk-nodejs
Version:
SDK to communicate with the Ingenico ePayments platform using the Ingenico Connect Server API
66 lines • 2.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.contentLength = exports.dispositionFilename = exports.isJSON = exports.isBinaryContent = exports.serverMetaInfo = exports.date = void 0;
const dateformat = require("dateformat");
function date() {
return dateformat("GMT:ddd, dd mmm yyyy HH:MM:ss") + " GMT";
}
exports.date = date;
function serverMetaInfo(sdkContext) {
const info = {
sdkCreator: "Ingenico",
sdkIdentifier: "NodejsServerSDK/v4.8.0",
platformIdentifier: process.env["OS"] + " Node.js/" + process.versions.node
};
if (sdkContext.getIntegrator() !== null) {
info.integrator = sdkContext.getIntegrator();
}
if (sdkContext.getShoppingCartExtension() !== null) {
info.shoppingCartExtension = sdkContext.getShoppingCartExtension();
}
return {
key: "X-GCS-ServerMetaInfo",
value: Buffer.from(JSON.stringify(info)).toString("base64")
};
}
exports.serverMetaInfo = serverMetaInfo;
function isBinaryContent(contentType) {
return !!contentType && !contentType.startsWith("text/") && contentType.indexOf("json") === -1 && contentType.indexOf("xml") === -1;
}
exports.isBinaryContent = isBinaryContent;
function isJSON(contentType) {
return contentType == null || contentType.toLowerCase().startsWith("application/json");
}
exports.isJSON = isJSON;
const dispositionFilenamePattern = /(?:^|;)\s*filename\s*=\s*(.*?)\s*(?:;|$)/i;
function trimQuotes(filename) {
if (filename.length < 2) {
return filename;
}
if ((filename.startsWith('"') && filename.endsWith('"')) || (filename.startsWith("'") && filename.endsWith("'"))) {
return filename.substring(1, filename.length - 1);
}
return filename;
}
function dispositionFilename(headers) {
const disposition = headers["content-disposition"];
if (disposition) {
const match = disposition.match(dispositionFilenamePattern);
if (match) {
const filename = match[1];
return trimQuotes(filename);
}
}
return null;
}
exports.dispositionFilename = dispositionFilename;
function contentLength(headers) {
const length = headers["content-length"];
if (length) {
const intLength = parseInt(length);
return isNaN(intLength) ? length : intLength;
}
return null;
}
exports.contentLength = contentLength;
//# sourceMappingURL=headers.js.map