UNPKG

ketting

Version:

Opiniated HATEAOS / Rest client.

34 lines 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const LinkHeader = require("http-link-header"); const uri_1 = require("../util/uri"); /** * This middleware will emit warnings based on HTTP responses. * * Currently it just inspects the 'Deprecation' HTTP header from * draft-dalal-deprecation-header */ function default_1() { return async (request, next) => { const response = await next(request); const deprecation = response.headers.get('Deprecation'); if (deprecation) { const sunset = response.headers.get('Sunset'); let msg = `[Ketting] The resource ${request.url} is deprecated.`; if (sunset) { msg += ' It will no longer respond ' + sunset; } if (response.headers.has('Link')) { for (const httpLink of LinkHeader.parse(response.headers.get('Link')).rel('deprecation')) { const uri = (0, uri_1.resolve)(request.url, httpLink.uri); msg += `See ${uri} for more information.`; } } /* eslint-disable-next-line no-console */ console.warn(msg); } return response; }; } //# sourceMappingURL=warning.js.map