UNPKG

@integromat/proto

Version:
95 lines 3.63 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.IMTHook = void 0; var events_1 = require("events"); /** * Base class for all Hooks. * * @property {Object} data Collection of data specific to this hook. Read only. */ var IMTHook = /** @class */ (function (_super) { __extends(IMTHook, _super); function IMTHook() { return _super !== null && _super.apply(this, arguments) || this; } /** * Initializes the hook. Function that overrides should always call super. * * @callback done Callback to call when hook is initialized. * @param {Error} err Error on error, otherwise null. */ IMTHook.prototype.initialize = function (done) { if ('function' === typeof done) done(); }; /** * Finalizes the hook. Function that overrides should always call super. * * @callback done Callback to call when hook is finalized. * @param {Error} err Error on error, otherwise null. */ IMTHook.prototype.finalize = function (done) { if ('function' === typeof done) done(); }; /** * Parse request. * * @param {Request} request Request object. * @callback done Callback to call when test is complete. * @param {Error} err Error on error, otherwise null. * @param {Array} items Array of items parsed from request. */ IMTHook.prototype.parse = function (request, done) { void request; void done; throw new Error("Must override a superclass method 'parse'."); }; /** * Filter received items. Only effective in shared webhooks. * * @param {Object} Item * @param {Object} Hook's data object. * @callback done Callback to call when filter was resolved. * @param {Error} err Error on error, otherwise null. * @param {Boolean} passed Whether the item should be accepted. */ IMTHook.prototype.filter = function (item, data, done) { if ('function' === typeof done) done(null, true); }; /** * Builds the Form Specification. * If the Hook is capable of providing the Input Structure as the Form Specification, * this function will pass the specification to the callback. * Relies on the hook.data. * Used for Form Hooks. * * @param {Request} req Request object to make headers and stuff available inside * @callback done Callback to call when the Form is built. * @param {Error} err Error on error, otherwise null. * @param {Object} form The Form Specification */ IMTHook.prototype.getFormSpec = function (req, done) { if ('function' === typeof done) done(); }; return IMTHook; }(events_1.EventEmitter)); exports.IMTHook = IMTHook; //# sourceMappingURL=hook.js.map