@unito/integration-debugger
Version:
The Unito Integration Debugger
50 lines (49 loc) • 2 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const headers_1 = __importDefault(require("../../resources/headers"));
/** Check: An integration answers a "408 Request Timeout" on a outdated request.
*
* Each request receives a X-Unito-Operation-Deadline header which represents the deadline before
* which the operation must complete. The value is a Unix timestamp (epoch).
*
* For example:
*
* X-Unito-Operation-Deadline: 1679342914
*
* An integration can use this information to cancel an ongoing operation and emit a 408 Request Timeout response.
*/
const check = {
label: 'Performance - Operation Deadline',
prepareOnPreparedSteps: false,
validateOnError: true,
activatedByDefault: false,
prepare: async (stepResult, _crawlerDriver) => {
const step = stepResult.step;
step.headersIn ??= {};
step.headersIn[headers_1.default.OPERATION_DEADLINE] = '0';
return [step];
},
validate: (step, _crawlerDriver) => {
const deadline = step.headersIn && step.headersIn[headers_1.default.OPERATION_DEADLINE] === '0';
if (!deadline) {
return;
}
const payload = step.payloadOut;
if (!payload || payload.code !== '408') {
step.warnings.push({
keyword: 'unito',
message: `Handle the '${headers_1.default.OPERATION_DEADLINE}' header in your integration to avoid processing outdated requests.`,
detailedMessage: `The step was processed after '${deadline}' (unix epoch) when it could have been discarded`,
instancePath: step.path,
schemaPath: step.schemaPath ?? '',
params: {
code: 'OPERATION_DEADLINE_IGNORED',
},
});
}
},
};
exports.default = check;
;