connect-sdk-nodejs
Version:
SDK to communicate with the Worldline Global Collect platform using the Worldline Connect Server API
44 lines • 1.99 kB
JavaScript
;
/*
* This file was auto-generated from the API references found at
* https://apireference.connect.worldline-solutions.com/
*/
/* eslint-disable @typescript-eslint/no-non-null-assertion */
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.v1WebhooksFactory = void 0;
const types_1 = require("../../model/webhooks/types");
const validation_1 = require("../../webhooks/validation");
function validateApiVersion(event) {
if ("v1" !== event.apiVersion) {
throw new types_1.ApiVersionMismatchError(`event API version ${event.apiVersion} is not compatible with SDK API version v1`, event.apiVersion, "v1");
}
}
function unmarshal(body, requestHeaders, validator) {
return __awaiter(this, void 0, void 0, function* () {
yield validator.validate(body, requestHeaders);
const event = JSON.parse(body.toString());
validateApiVersion(event);
return event;
});
}
function newWebhooksHelper(validator) {
return {
unmarshal: (body, requestHeaders) => unmarshal(body, requestHeaders, validator)
};
}
exports.v1WebhooksFactory = {
init: context => {
const validator = (0, validation_1.newSignatureValidator)(context);
return newWebhooksHelper(validator);
}
};
//# sourceMappingURL=index.js.map