UNPKG

ghost-image-store

Version:

Ghost storage adapter that automatically creates a webp version of your uploaded images

2,048 lines (1,637 loc) 1.73 MB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define("image-store", [], factory); else if(typeof exports === 'object') exports["image-store"] = factory(); else root["image-store"] = factory(); })(global, function() { return /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 46010: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { module.exports = __webpack_require__(72914); /***/ }), /***/ 3619: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const path = __webpack_require__(85622); var urljoin = __webpack_require__(34078); const utils = __webpack_require__(16988); const STATIC_IMAGE_URL_PREFIX = 'content/images'; module.exports = Object.assign(utils.loadConfig(__dirname), { getContentPath(name) { if (this.paths && this.paths.contentPath) { return path.join(this.paths.contentPath, name); } return path.join(path.dirname(this._configPath), 'content', name); }, getContentUrl(filePath) { const url = new URL(this.url); return urljoin(url.pathname, STATIC_IMAGE_URL_PREFIX, filePath); } }); /***/ }), /***/ 79693: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const path = __webpack_require__(85622); const fs = __webpack_require__(55674); function exists(fileName, targetDir) { const filePath = path.join(targetDir || this.storagePath, fileName); return fs.stat(filePath) .then(() => { return true; }) .catch(() => { return false; }); } module.exports = function (Store) { Object.assign(Store.prototype, { exists }); }; /***/ }), /***/ 79507: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const path = __webpack_require__(85622); const fs = __webpack_require__(55674); const errors = __webpack_require__(32517); /** * Reads bytes from disk for a target image * - path of target image (without content path!) * * @param options */ function read(options) { options = options || {}; // remove trailing slashes options.path = (options.path || '').replace(/\/$|\\$/, ''); const targetPath = path.join(this.storagePath, options.path); return new Promise((resolve, reject) => { fs.readFile(targetPath, (err, bytes) => { if (err) { if (err.code === 'ENOENT' || err.code === 'ENOTDIR') { return reject(new errors.NotFoundError({ err: err, message: `Image not found: ${options.path}` })); } if (err.code === 'ENAMETOOLONG') { return reject(new errors.BadRequestError({err: err})); } if (err.code === 'EACCES') { return reject(new errors.NoPermissionError({err: err})); } return reject(new errors.GhostError({ err: err, message: `Cannot read image: ${options.path}` })); } resolve(bytes); }); }); } module.exports = function (Store) { Object.assign(Store.prototype, { read }); }; /***/ }), /***/ 58072: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const path = __webpack_require__(85622); const fs = __webpack_require__(55674); const config = __webpack_require__(3619); /** * Saves the image to storage (the file system) * - image is the express image object * - returns a promise which ultimately returns the full url to the uploaded image * * @param image * @param targetDir * @returns {*} */ function saveAs(image, targetDir) { let targetFilename; // NOTE: the base implementation of `getTargetDir` returns the format this.storagePath/YYYY/MM targetDir = targetDir || this.getTargetDir(this.storagePath); return this.getUniqueFileName(image, targetDir).then((filename) => { targetFilename = filename; return fs.mkdirs(targetDir); }).then(() => { return fs.copy(image.path, targetFilename); }).then(() => { // The src for the image must be in URI format, not a file system path, which in Windows uses \ // For local file system storage can use relative path so add a slash return { url: config.getContentUrl(path.relative(this.storagePath, targetFilename)).replace( new RegExp(`\\${path.sep}`, 'g'), '/' ), path: targetFilename }; }).catch((e) => { return Promise.reject(e); }); } module.exports = function (Store) { Object.assign(Store.prototype, { saveAs }); }; /***/ }), /***/ 87901: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const path = __webpack_require__(85622); const fs = __webpack_require__(55674); const config = __webpack_require__(3619); /** * Saves a buffer in the targetPath * - buffer is an instance of Buffer * - returns a Promise which returns the full URL to retrieve the data */ function saveRawAs(buffer, targetPath) { const storagePath = path.join(this.storagePath, targetPath); const targetDir = path.dirname(storagePath); return fs.mkdirs(targetDir) .then(() => { return fs.writeFile(storagePath, buffer); }) .then(() => { // For local file system storage can use relative path so add a slash return { url: config.getContentUrl(targetPath).replace( new RegExp(`\\${path.sep}`, 'g'), '/' ), path: storagePath }; }); } module.exports = function (Store) { Object.assign(Store.prototype, { saveRawAs }); }; /***/ }), /***/ 96775: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const moment = __webpack_require__(30381); const constants = __webpack_require__(49361); const errors = __webpack_require__(32517); const server = __webpack_require__(19377); /** * For some reason send divides the max age number by 1000 * Fallthrough: false ensures that if an image isn't found, it automatically 404s * Wrap server static errors * * @returns {function(*=, *=, *): any} */ function serve() { const {storagePath} = this; return function serveStaticContent(req, res, next) { const startedAtMoment = moment(); return server.static( storagePath, { maxAge: constants.ONE_YEAR_MS, fallthrough: false, onEnd: /* istanbul ignore next */ () => { console.log('serve', req.path, `${moment().diff(startedAtMoment, 'ms')}ms`); } } )(req, res, (err) => { if (err) { if (err.statusCode === 404) { return next(new errors.NotFoundError({ message: 'Image not found', code: 'STATIC_FILE_NOT_FOUND', property: err.path })); } if (err.statusCode === 400) { return next(new errors.BadRequestError({err: err})); } if (err.statusCode === 403) { return next(new errors.NoPermissionError({err: err})); } return next(new errors.GhostError({err: err})); } next(); }); }; } module.exports = function (Store) { Object.assign(Store.prototype, { serve }); }; /***/ }), /***/ 19377: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const serveStatic = __webpack_require__(28636); module.exports = { static: serveStatic }; /***/ }), /***/ 72914: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const sharp = __webpack_require__(742); const StorageBase = __webpack_require__(31235); const utils = __webpack_require__(16988); const config = __webpack_require__(3619); /* * 80 might be 'too good' * https://www.jefftk.com/p/webp-quality-settings */ const WEBP_QUALITY = 80; class ImageFileStore extends StorageBase { constructor(options = {}) { super(options); this.storagePath = config.getContentPath('images'); this.webpQuality = options.webQuality || WEBP_QUALITY; } canConvertToWebP(ext) { return ['.jpg', '.jpeg', '.png'].includes(ext); } saveRaw(buffer, targetPath) { return this.saveRawAs(buffer, targetPath).then((result) => { const ext = utils.fileExtension(result.path); if (!this.canConvertToWebP(ext)) { return result.url; } return sharp(result.path).webp({quality: this.webpQuality}).toFile(`${result.path }.webp`) .then(() => { return result.url; }) .catch((err) => { console.error(`Failed to convert '${result.path} to webp: ${err.message}`); return Promise.resolve(result.url); }); }).catch((err) => { return Promise.reject(err); }); } save(image, targetDir) { return this.saveAs(image, targetDir).then((result) => { const ext = utils.fileExtension(result.path); if (!this.canConvertToWebP(ext)) { return result.url; } return sharp(result.path).webp({quality: this.webpQuality}).toFile(`${result.path }.webp`) .then(() => { return result.url; }) .catch((err) => { console.error(`Failed to convert '${result.path} to webp: ${err.message}`); return Promise.resolve(result.url); }); }).catch((err) => { return Promise.reject(err); }); } /** * Not implemented. * @returns {Promise.<*>} */ delete() { return Promise.reject('not implemented'); } } __webpack_require__(79693)(ImageFileStore); __webpack_require__(79507)(ImageFileStore); __webpack_require__(96775)(ImageFileStore); __webpack_require__(58072)(ImageFileStore); __webpack_require__(87901)(ImageFileStore); module.exports = ImageFileStore; /***/ }), /***/ 16988: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const fs = __webpack_require__(35747); const path = __webpack_require__(85622); module.exports = { findConfigJson(dirPath) { if (!dirPath) { return null; } let filePath = path.join(dirPath, 'config.production.json'); if (fs.existsSync(filePath)) { return filePath; } filePath = path.join(dirPath, 'config.development.json'); if (fs.existsSync(filePath)) { return filePath; } if (dirPath === '/') { return null; } return this.findConfigJson(path.join(dirPath, '..')); }, loadConfig(dirPath) { const configPath = this.findConfigJson(dirPath); if (configPath) { const result = JSON.parse(fs.readFileSync(configPath, 'utf-8')); result._configPath = configPath; return result; } return {}; }, fileExtension(targetPath) { return path.parse(targetPath).ext.toLowerCase(); } }; /***/ }), /***/ 49361: /***/ ((module) => { module.exports = { ONE_HOUR_S: 3600, ONE_DAY_S: 86400, ONE_MONTH_S: 2628000, SIX_MONTH_S: 15768000, ONE_YEAR_S: 31536000, FIVE_MINUTES_MS: 300000, ONE_HOUR_MS: 3600000, ONE_DAY_MS: 86400000, ONE_WEEK_MS: 604800000, ONE_MONTH_MS: 2628000000, SIX_MONTH_MS: 15768000000, ONE_YEAR_MS: 31536000000 }; /***/ }), /***/ 32517: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { module.exports = __webpack_require__(79889); /***/ }), /***/ 79889: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const merge = __webpack_require__(82492); const each = __webpack_require__(66073); const util = __webpack_require__(31669); const errors = __webpack_require__(52325); class GhostError extends errors.IgnitionError { constructor(options) { options = options || {}; super(options); this.value = options.value; } } const ghostErrors = { DataExportError: class DataExportError extends GhostError { constructor(options) { super(merge({ statusCode: 500, errorType: 'DataExportError' }, options)); } }, DataImportError: class DataImportError extends GhostError { constructor(options) { super(merge({ statusCode: 500, errorType: 'DataImportError' }, options)); } }, DatabaseVersionError: class DatabaseVersionError extends GhostError { constructor(options) { super(merge({ hideStack: true, statusCode: 500, errorType: 'DatabaseVersionError' }, options)); } }, EmailError: class EmailError extends GhostError { constructor(options) { super(merge({ statusCode: 500, errorType: 'EmailError' }, options)); } }, ThemeValidationError: class ThemeValidationError extends GhostError { constructor(options) { super(merge({ statusCode: 422, errorType: 'ThemeValidationError', errorDetails: {} }, options)); } }, DisabledFeatureError: class DisabledFeatureError extends GhostError { constructor(options) { super(merge({ statusCode: 409, errorType: 'DisabledFeatureError' }, options)); } }, UpdateCollisionError: class UpdateCollisionError extends GhostError { constructor(options) { super(merge({ statusCode: 409, errorType: 'UpdateCollisionError' }, options)); } }, HostLimitError: class HostLimitError extends GhostError { constructor(options) { super(merge({ errorType: 'HostLimitError', hideStack: true, statusCode: 403 }, options)); } }, HelperWarning: class HelperWarning extends GhostError { constructor(options) { super(merge({ errorType: 'HelperWarning', hideStack: true }, options)); } }, PasswordResetRequiredError: class PasswordResetRequiredError extends GhostError { constructor(options) { super(merge({ errorType: 'PasswordResetRequiredError', statusCode: 401, message: 'For security, you need to create a new password. An email has been sent to you with instructions!' }, options)); } } }; // we need to inherit all general errors from GhostError, otherwise we have to check instanceof IgnitionError each(errors, function (error) { if (error.name === 'IgnitionError' || typeof error === 'object') { return; } util.inherits(error, GhostError); }); module.exports = merge(ghostErrors, errors); module.exports.GhostError = GhostError; /***/ }), /***/ 52325: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { module.exports = __webpack_require__(40499); /***/ }), /***/ 40499: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { const uuid = __webpack_require__(42277); const utils = __webpack_require__(9947); const merge = __webpack_require__(82492); const isString = __webpack_require__(47037); /** * @description Ignition Error Prototype. * * Ignition offers a set of general & pre-configured error definitions you can use in your project. * If you instantiate an error, Ignition will try to set up all error properties based on your input. * Ignition errors stick to the format of native errors + add's more custom attributes. * * @TODO: Move this code into errors.js. * * @param {Object} options * @constructor */ class IgnitionError extends Error { constructor(options) { options = options || {}; if (isString(options)) { /* eslint-disable no-restricted-syntax */ throw new Error('Please instantiate Errors with the option pattern. e.g. new errors.IgnitionError({message: ...})'); /* eslint-enable no-restricted-syntax */ } super(); /** * defaults */ this.statusCode = 500; this.errorType = 'InternalServerError'; this.level = 'normal'; this.message = 'The server has encountered an error.'; this.id = uuid.v1(); /** * custom overrides */ this.id = options.id || this.id; this.statusCode = options.statusCode || this.statusCode; this.level = options.level || this.level; this.context = options.context || this.context; this.help = options.help || this.help; this.errorType = this.name = options.errorType || this.errorType; this.errorDetails = options.errorDetails; this.code = options.code || null; this.property = options.property || null; this.redirect = options.redirect || null; this.message = options.message || this.message; this.hideStack = options.hideStack; // NOTE: Error to inherit from, override! // Nested objects are getting copied over in one piece (can be changed, but not needed right now) if (options.err) { // CASE: Support err as string (it happens that third party libs return a string instead of an error instance) if (isString(options.err)) { /* eslint-disable no-restricted-syntax */ options.err = new Error(options.err); /* eslint-enable no-restricted-syntax */ } Object.getOwnPropertyNames(options.err).forEach((property) => { if (['errorType', 'name', 'statusCode', 'message', 'level'].indexOf(property) !== -1) { return; } // CASE: `code` should put options as priority over err if (property === 'code') { this[property] = this[property] || options.err[property]; return; } if (property === 'stack') { this[property] += '\n\n' + options.err[property]; return; } this[property] = options.err[property] || this[property]; }); } } } const errors = { InternalServerError: class InternalServerError extends IgnitionError { constructor(options) { super(merge({ statusCode: 500, level: 'critical', errorType: 'InternalServerError', message: 'The server has encountered an error.' }, options)); } }, IncorrectUsageError: class IncorrectUsageError extends IgnitionError { constructor(options) { super(merge({ statusCode: 400, level: 'critical', errorType: 'IncorrectUsageError', message: 'We detected a misuse. Please read the stack trace.' }, options)); } }, NotFoundError: class NotFoundError extends IgnitionError { constructor(options) { super(merge({ statusCode: 404, errorType: 'NotFoundError', message: 'Resource could not be found.' }, options)); } }, BadRequestError: class BadRequestError extends IgnitionError { constructor(options) { super(merge({ statusCode: 400, errorType: 'BadRequestError', message: 'The request could not be understood.' }, options)); } }, UnauthorizedError: class UnauthorizedError extends IgnitionError { constructor(options) { super(merge({ statusCode: 401, errorType: 'UnauthorizedError', message: 'You are not authorised to make this request.' }, options)); } }, PasswordResetRequiredError: class PasswordResetRequiredError extends IgnitionError { constructor(options) { super(merge({ statusCode: 401, errorType: 'PasswordResetRequiredError', message: 'As a security precaution, your password must be reset. Click "Forgot?" to receive an email with instructions.' }, options)); } }, NoPermissionError: class NoPermissionError extends IgnitionError { constructor(options) { super(merge({ statusCode: 403, errorType: 'NoPermissionError', message: 'You do not have permission to perform this request.' }, options)); } }, ValidationError: class ValidationError extends IgnitionError { constructor(options) { super(merge({ statusCode: 422, errorType: 'ValidationError', message: 'The request failed validation.' }, options)); } }, UnsupportedMediaTypeError: class UnsupportedMediaTypeError extends IgnitionError { constructor(options) { super(merge({ statusCode: 415, errorType: 'UnsupportedMediaTypeError', message: 'The media in the request is not supported by the server.' }, options)); } }, TooManyRequestsError: class TooManyRequestsError extends IgnitionError { constructor(options) { super(merge({ statusCode: 429, errorType: 'TooManyRequestsError', message: 'Server has received too many similar requests in a short space of time.' }, options)); } }, MaintenanceError: class MaintenanceError extends IgnitionError { constructor(options) { super(merge({ statusCode: 503, errorType: 'MaintenanceError', message: 'The server is temporarily down for maintenance.' }, options)); } }, MethodNotAllowedError: class MethodNotAllowedError extends IgnitionError { constructor(options) { super(merge({ statusCode: 405, errorType: 'MethodNotAllowedError', message: 'Method not allowed for resource.' }, options)); } }, RequestEntityTooLargeError: class RequestEntityTooLargeError extends IgnitionError { constructor(options) { super(merge({ statusCode: 413, errorType: 'RequestEntityTooLargeError', message: 'Request was too big for the server to handle.' }, options)); } }, TokenRevocationError: class TokenRevocationError extends IgnitionError { constructor(options) { super(merge({ statusCode: 503, errorType: 'TokenRevocationError', message: 'Token is no longer available.' }, options)); } }, VersionMismatchError: class VersionMismatchError extends IgnitionError { constructor(options) { super(merge({ statusCode: 400, errorType: 'VersionMismatchError', message: 'Requested version does not match server version.' }, options)); } } }; module.exports = errors; module.exports.IgnitionError = IgnitionError; module.exports.utils = { serialize: utils.serialize.bind(errors), deserialize: utils.deserialize.bind(errors), isIgnitionError: utils.isIgnitionError.bind(errors) }; /***/ }), /***/ 9947: /***/ ((__unused_webpack_module, exports, __webpack_require__) => { const omit = __webpack_require__(57557); const merge = __webpack_require__(82492); const extend = __webpack_require__(22205); const _private = {}; _private.serialize = function serialize(err) { try { return { id: err.id, status: err.statusCode, code: err.code || err.errorType, title: err.name, detail: err.message, meta: { context: err.context, help: err.help, errorDetails: err.errorDetails, level: err.level, errorType: err.errorType } }; } catch (error) { return { detail: 'Something went wrong.' }; } }; _private.deserialize = function deserialize(obj) { try { return { id: obj.id, message: obj.detail || obj.error_description || obj.message, statusCode: obj.status, code: obj.code || obj.error, level: obj.meta && obj.meta.level, help: obj.meta && obj.meta.help, context: obj.meta && obj.meta.context }; } catch (err) { return { message: 'Something went wrong.' }; } }; /** * @description Serialize error instance into oauth format. * * @see https://tools.ietf.org/html/rfc6749#page-45 * * To not loose any error data when sending errors between internal services, we use the suggested OAuth properties and add ours as well. */ _private.OAuthSerialize = function OAuthSerialize(err) { const matchTable = {}; matchTable[this.NoPermissionError.name] = 'access_denied'; matchTable[this.MaintenanceError.name] = 'temporarily_unavailable'; matchTable[this.BadRequestError.name] = matchTable[this.ValidationError.name] = 'invalid_request'; matchTable.default = 'server_error'; return merge({ error: err.code || matchTable[err.name] || 'server_error', error_description: err.message }, omit(_private.serialize(err), ['detail', 'code'])); }; /** * @description Deserialize oauth error format into Ignition error instance. * @param {Object} errorFormat * @return {Error} * @constructor */ _private.OAuthDeserialize = function OAuthDeserialize(errorFormat) { try { return new this[errorFormat.title || errorFormat.name || this.InternalServerError.name](_private.deserialize(errorFormat)); } catch (err) { // CASE: you receive an OAuth formatted error, but the error prototype is unknown return new this.InternalServerError(extend({ errorType: errorFormat.title || errorFormat.name }, _private.deserialize(errorFormat))); } }; /** * @description Serialize Ignition error instance into jsonapi.org format. * @param {Error} err * @return {Object} */ _private.JSONAPISerialize = function JSONAPISerialize(err) { const errorFormat = { errors: [_private.serialize(err)] }; errorFormat.errors[0].source = {}; if (err.property) { errorFormat.errors[0].source.pointer = '/data/attributes/' + err.property; } return errorFormat; }; /** * @description Deserialize JSON api format into Ignition error instance. * @param {Object} errorFormat * @return {Error} */ _private.JSONAPIDeserialize = function JSONAPIDeserialize(errorFormat) { errorFormat = errorFormat.errors && errorFormat.errors[0] || {}; let internalError; try { internalError = new this[errorFormat.title || errorFormat.name || this.InternalServerError.name](_private.deserialize(errorFormat)); } catch (err) { // CASE: you receive a JSON format error, but the error prototype is unknown internalError = new this.InternalServerError(extend({ errorType: errorFormat.title || errorFormat.name }, _private.deserialize(errorFormat))); } if (errorFormat.source && errorFormat.source.pointer) { internalError.property = errorFormat.source.pointer.split('/')[3]; } return internalError; }; /** * @description Serialize Ignition error instance to error JSON format * * jsonapi.org error format: * * source: { * parameter: URL query parameter (no support yet) * pointer: HTTP body attribute * } * * @see http://jsonapi.org/format/#errors * * @param {Error} err * @param {Object} options { format: [String] (jsonapi || oauth) } */ exports.serialize = function serialize(err, options) { options = options || {format: 'jsonapi'}; let errorFormat = {}; try { if (options.format === 'jsonapi') { errorFormat = _private.JSONAPISerialize.bind(this)(err); } else { errorFormat = _private.OAuthSerialize.bind(this)(err); } } catch (error) { errorFormat.message = 'Something went wrong.'; } // no need to sanitize the undefined values, on response send JSON.stringify get's called return errorFormat; }; /** * @description Deserialize from error JSON format to Ignition error instance * @param {Object} errorFormat */ exports.deserialize = function deserialize(errorFormat) { let internalError = {}; if (errorFormat.errors) { internalError = _private.JSONAPIDeserialize.bind(this)(errorFormat); } else { internalError = _private.OAuthDeserialize.bind(this)(errorFormat); } return internalError; }; /** * @description Check whether an error instance is an Ignition error. * * NOTE: `instanceof` will fail, if multiple sub dependencies use it's own ignition installation. */ exports.isIgnitionError = function isIgnitionError(err) { const IgnitionName = this.IgnitionError.name; const recursiveIsIgnitionError = function recursiveIsIgnitionError(obj) { // no super constructor available anymore if (!obj || !obj.name) { return false; } if (obj.name === IgnitionName) { return true; } return recursiveIsIgnitionError(Object.getPrototypeOf(obj)); }; return recursiveIsIgnitionError(err.constructor); }; /***/ }), /***/ 3736: /***/ ((module) => { module.exports = r => { const n = process.versions.node.split('.').map(x => parseInt(x, 10)) r = r.split('.').map(x => parseInt(x, 10)) return n[0] > r[0] || (n[0] === r[0] && (n[1] > r[1] || (n[1] === r[1] && n[2] >= r[2]))) } /***/ }), /***/ 40412: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { /*! * depd * Copyright(c) 2014-2017 Douglas Christopher Wilson * MIT Licensed */ /** * Module dependencies. */ var callSiteToString = __webpack_require__(32316).callSiteToString var eventListenerCount = __webpack_require__(32316).eventListenerCount var relative = __webpack_require__(85622).relative /** * Module exports. */ module.exports = depd /** * Get the path to base files on. */ var basePath = process.cwd() /** * Determine if namespace is contained in the string. */ function containsNamespace (str, namespace) { var vals = str.split(/[ ,]+/) var ns = String(namespace).toLowerCase() for (var i = 0; i < vals.length; i++) { var val = vals[i] // namespace contained if (val && (val === '*' || val.toLowerCase() === ns)) { return true } } return false } /** * Convert a data descriptor to accessor descriptor. */ function convertDataDescriptorToAccessor (obj, prop, message) { var descriptor = Object.getOwnPropertyDescriptor(obj, prop) var value = descriptor.value descriptor.get = function getter () { return value } if (descriptor.writable) { descriptor.set = function setter (val) { return (value = val) } } delete descriptor.value delete descriptor.writable Object.defineProperty(obj, prop, descriptor) return descriptor } /** * Create arguments string to keep arity. */ function createArgumentsString (arity) { var str = '' for (var i = 0; i < arity; i++) { str += ', arg' + i } return str.substr(2) } /** * Create stack string from stack. */ function createStackString (stack) { var str = this.name + ': ' + this.namespace if (this.message) { str += ' deprecated ' + this.message } for (var i = 0; i < stack.length; i++) { str += '\n at ' + callSiteToString(stack[i]) } return str } /** * Create deprecate for namespace in caller. */ function depd (namespace) { if (!namespace) { throw new TypeError('argument namespace is required') } var stack = getStack() var site = callSiteLocation(stack[1]) var file = site[0] function deprecate (message) { // call to self as log log.call(deprecate, message) } deprecate._file = file deprecate._ignored = isignored(namespace) deprecate._namespace = namespace deprecate._traced = istraced(namespace) deprecate._warned = Object.create(null) deprecate.function = wrapfunction deprecate.property = wrapproperty return deprecate } /** * Determine if namespace is ignored. */ function isignored (namespace) { /* istanbul ignore next: tested in a child processs */ if (process.noDeprecation) { // --no-deprecation support return true } var str = process.env.NO_DEPRECATION || '' // namespace ignored return containsNamespace(str, namespace) } /** * Determine if namespace is traced. */ function istraced (namespace) { /* istanbul ignore next: tested in a child processs */ if (process.traceDeprecation) { // --trace-deprecation support return true } var str = process.env.TRACE_DEPRECATION || '' // namespace traced return containsNamespace(str, namespace) } /** * Display deprecation message. */ function log (message, site) { var haslisteners = eventListenerCount(process, 'deprecation') !== 0 // abort early if no destination if (!haslisteners && this._ignored) { return } var caller var callFile var callSite var depSite var i = 0 var seen = false var stack = getStack() var file = this._file if (site) { // provided site depSite = site callSite = callSiteLocation(stack[1]) callSite.name = depSite.name file = callSite[0] } else { // get call site i = 2 depSite = callSiteLocation(stack[i]) callSite = depSite } // get caller of deprecated thing in relation to file for (; i < stack.length; i++) { caller = callSiteLocation(stack[i]) callFile = caller[0] if (callFile === file) { seen = true } else if (callFile === this._file) { file = this._file } else if (seen) { break } } var key = caller ? depSite.join(':') + '__' + caller.join(':') : undefined if (key !== undefined && key in this._warned) { // already warned return } this._warned[key] = true // generate automatic message from call site var msg = message if (!msg) { msg = callSite === depSite || !callSite.name ? defaultMessage(depSite) : defaultMessage(callSite) } // emit deprecation if listeners exist if (haslisteners) { var err = DeprecationError(this._namespace, msg, stack.slice(i)) process.emit('deprecation', err) return } // format and write message var format = process.stderr.isTTY ? formatColor : formatPlain var output = format.call(this, msg, caller, stack.slice(i)) process.stderr.write(output + '\n', 'utf8') } /** * Get call site location as array. */ function callSiteLocation (callSite) { var file = callSite.getFileName() || '<anonymous>' var line = callSite.getLineNumber() var colm = callSite.getColumnNumber() if (callSite.isEval()) { file = callSite.getEvalOrigin() + ', ' + file } var site = [file, line, colm] site.callSite = callSite site.name = callSite.getFunctionName() return site } /** * Generate a default message from the site. */ function defaultMessage (site) { var callSite = site.callSite var funcName = site.name // make useful anonymous name if (!funcName) { funcName = '<anonymous@' + formatLocation(site) + '>' } var context = callSite.getThis() var typeName = context && callSite.getTypeName() // ignore useless type name if (typeName === 'Object') { typeName = undefined } // make useful type name if (typeName === 'Function') { typeName = context.name || typeName } return typeName && callSite.getMethodName() ? typeName + '.' + funcName : funcName } /** * Format deprecation message without color. */ function formatPlain (msg, caller, stack) { var timestamp = new Date().toUTCString() var formatted = timestamp + ' ' + this._namespace + ' deprecated ' + msg // add stack trace if (this._traced) { for (var i = 0; i < stack.length; i++) { formatted += '\n at ' + callSiteToString(stack[i]) } return formatted } if (caller) { formatted += ' at ' + formatLocation(caller) } return formatted } /** * Format deprecation message with color. */ function formatColor (msg, caller, stack) { var formatted = '\x1b[36;1m' + this._namespace + '\x1b[22;39m' + // bold cyan ' \x1b[33;1mdeprecated\x1b[22;39m' + // bold yellow ' \x1b[0m' + msg + '\x1b[39m' // reset // add stack trace if (this._traced) { for (var i = 0; i < stack.length; i++) { formatted += '\n \x1b[36mat ' + callSiteToString(stack[i]) + '\x1b[39m' // cyan } return formatted } if (caller) { formatted += ' \x1b[36m' + formatLocation(caller) + '\x1b[39m' // cyan } return formatted } /** * Format call site location. */ function formatLocation (callSite) { return relative(basePath, callSite[0]) + ':' + callSite[1] + ':' + callSite[2] } /** * Get the stack as array of call sites. */ function getStack () { var limit = Error.stackTraceLimit var obj = {} var prep = Error.prepareStackTrace Error.prepareStackTrace = prepareObjectStackTrace Error.stackTraceLimit = Math.max(10, limit) // capture the stack Error.captureStackTrace(obj) // slice this function off the top var stack = obj.stack.slice(1) Error.prepareStackTrace = prep Error.stackTraceLimit = limit return stack } /** * Capture call site stack from v8. */ function prepareObjectStackTrace (obj, stack) { return stack } /** * Return a wrapped function in a deprecation message. */ function wrapfunction (fn, message) { if (typeof fn !== 'function') { throw new TypeError('argument fn must be a function') } var args = createArgumentsString(fn.length) var deprecate = this // eslint-disable-line no-unused-vars var stack = getStack() var site = callSiteLocation(stack[1]) site.name = fn.name // eslint-disable-next-line no-eval var deprecatedfn = eval('(function (' + args + ') {\n' + '"use strict"\n' + 'log.call(deprecate, message, site)\n' + 'return fn.apply(this, arguments)\n' + '})') return deprecatedfn } /** * Wrap property in a deprecation message. */ function wrapproperty (obj, prop, message) { if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) { throw new TypeError('argument obj must be object') } var descriptor = Object.getOwnPropertyDescriptor(obj, prop) if (!descriptor) { throw new TypeError('must call property on owner object') } if (!descriptor.configurable) { throw new TypeError('property must be configurable') } var deprecate = this var stack = getStack() var site = callSiteLocation(stack[1]) // set site name site.name = prop // convert data descriptor if ('value' in descriptor) { descriptor = convertDataDescriptorToAccessor(obj, prop, message) } var get = descriptor.get var set = descriptor.set // wrap getter if (typeof get === 'function') { descriptor.get = function getter () { log.call(deprecate, message, site) return get.apply(this, arguments) } } // wrap setter if (typeof set === 'function') { descriptor.set = function setter () { log.call(deprecate, message, site) return set.apply(this, arguments) } } Object.defineProperty(obj, prop, descriptor) } /** * Create DeprecationError for deprecation */ function DeprecationError (namespace, message, stack) { var error = new Error() var stackString Object.defineProperty(error, 'constructor', { value: DeprecationError }) Object.defineProperty(error, 'message', { configurable: true, enumerable: false, value: message, writable: true }) Object.defineProperty(error, 'name', { enumerable: false, configurable: true, value: 'DeprecationError', writable: true }) Object.defineProperty(error, 'namespace', { configurable: true, enumerable: false, value: namespace, writable: true }) Object.defineProperty(error, 'stack', { configurable: true, enumerable: false, get: function () { if (stackString !== undefined) { return stackString } // prepare stack trace return (stackString = createStackString.call(this, stack)) }, set: function setter (val) { stackString = val } }) return error } /***/ }), /***/ 45868: /***/ ((module) => { "use strict"; /*! * depd * Copyright(c) 2014 Douglas Christopher Wilson * MIT Licensed */ /** * Module exports. */ module.exports = callSiteToString /** * Format a CallSite file location to a string. */ function callSiteFileLocation (callSite) { var fileName var fileLocation = '' if (callSite.isNative()) { fileLocation = 'native' } else if (callSite.isEval()) { fileName = callSite.getScriptNameOrSourceURL() if (!fileName) { fileLocation = callSite.getEvalOrigin() } } else { fileName = callSite.getFileName() } if (fileName) { fileLocation += fileName var lineNumber = callSite.getLineNumber() if (lineNumber != null) { fileLocation += ':' + lineNumber var columnNumber = callSite.getColumnNumber() if (columnNumber) { fileLocation += ':' + columnNumber } } } return fileLocation || 'unknown source' } /** * Format a CallSite to a string. */ function callSiteToString (callSite) { var addSuffix = true var fileLocation = callSiteFileLocation(callSite) var functionName = callSite.getFunctionName() var isConstructor = callSite.isConstructor() var isMethodCall = !(callSite.isToplevel() || isConstructor) var line = '' if (isMethodCall) { var methodName = callSite.getMethodName() var typeName = getConstructorName(callSite) if (functionName) { if (typeName && functionName.indexOf(typeName) !== 0) { line += typeName + '.' } line += functionName if (methodName && functionName.lastIndexOf('.' + methodName) !== functionName.length - methodName.length - 1) { line += ' [as ' + methodName + ']' } } else { line += typeName + '.' + (methodName || '<anonymous>') } } else if (isConstructor) { line += 'new ' + (functionName || '<anonymous>') } else if (functionName) { line += functionName } else { addSuffix = false line += fileLocation } if (addSuffix) { line += ' (' + fileLocation + ')' } return line } /** * Get constructor name of reviver. */ function getConstructorName (obj) { var receiver = obj.receiver return (receiver.constructor && receiver.constructor.name) || null } /***/ }), /***/ 51671: /***/ ((module) => { "use strict"; /*! * depd * Copyright(c) 2015 Douglas Christopher Wilson * MIT Licensed */ /** * Module exports. * @public */ module.exports = eventListenerCount /** * Get the count of listeners on an event emitter of a specific type. */ function eventListenerCount (emitter, type) { return emitter.listeners(type).length } /***/ }), /***/ 32316: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; /*! * depd * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ /** * Module dependencies. * @private */ var EventEmitter = __webpack_require__(28614).EventEmitter /** * Module exports. * @public */ lazyProperty(module.exports, 'callSiteToString', function callSiteToString () { var limit = Error.stackTraceLimit var obj = {} var prep = Error.prepareStackTrace function prepareObjectStackTrace (obj, stack) { return stack } Error.prepareStackTrace = prepareObjectStackTrace Error.stackTraceLimit = 2 // capture the stack Error.captureStackTrace(obj) // slice the stack var stack = obj.stack.slice() Error.prepareStackTrace = prep Error.stackTraceLimit = limit return stack[0].toString ? toString : __webpack_require__(45868) }) lazyProperty(module.exports, 'eventListenerCount', function eventListenerCount () { return EventEmitter.listenerCount || __webpack_require__(51671) }) /** * Define a lazy property. */ function lazyProperty (obj, prop, getter) { function get () { var val = getter() Object.defineProperty(obj, prop, { configurable: true, enumerable: true, value: val }) return val } Object.defineProperty(obj, prop, { configurable: true, enumerable: true, get: get }) } /** * Call toString() on the obj */ function toString (obj) { return obj.toString() } /***/ }), /***/ 26149: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; /*! * destroy * Copyright(c) 2014 Jonathan Ong * MIT Licensed */ /** * Module dependencies. * @private */ var ReadStream = __webpack_require__(35747).ReadStream var Stream = __webpack_require__(92413) /** * Module exports. * @public */ module.exports = destroy /** * Destroy a stream. * * @param {object} stream * @public */ function destroy(stream) { if (stream instanceof ReadStream) { return destroyReadStream(stream) } if (!(stream instanceof Stream)) { return stream } if (typeof stream.destroy === 'function') { stream.destroy() } return stream } /** * Destroy a ReadStream. * * @param {object} stream * @private */ function destroyReadStream(stream) { stream.destroy() if (typeof stream.close === 'function') { // node.js core bug work-around stream.on('open', onOpenClose) } return stream } /** * On open handler to close stream. * @private */ function onOpenClose() { if (typeof this.fd === 'number') { // actually close down the fd this.close() } } /***/ }), /***/ 94331: /***/ ((module) => { "use strict"; /*! * ee-first * Copyright(c) 2014 Jonathan Ong * MIT Licensed */ /** * Module exports. * @public */ module.exports = first /** * Get the first event in a set of event emitters and event pairs. * * @param {array} stuff * @param {function} done * @public */ function first(stuff, done) { if (!Array.isArray(stuff)) throw new TypeError('arg must be an array of [ee, events...] arrays') var cleanups = [] for (var i = 0; i < stuff.length; i++) { var arr = stuff[i] if (!Array.isArray(arr) || arr.length < 2) throw new TypeError('each array member must be [ee, events...]') var ee = arr[0] for (var j = 1; j < arr.length; j++) { var event = arr[j] var fn = listener(event, callback) // listen to the event ee.on(event, fn) // push this listener to the list of cleanups cleanups.push({ ee: ee, event: event, fn: fn, }) } } function callback() { cleanup() done.apply(null, arguments) } function cleanup() { var x for (var i = 0; i < cleanups.length; i++) { x = cleanups[i] x.ee.removeListener(x.event, x.fn) } } function thunk(fn) { done = fn } thunk.cancel = cleanup return thunk } /** * Create the event listener. * @private */ function listener(event, done) { return function onevent(arg1) { var args = new Array(arguments.length) var ee = this var err = event === 'error' ? arg1 : null // copy args to prevent arguments escaping scope for (var i = 0; i < args.length; i++) { args[i] = arguments[i] } done(err, ee, event, args) } } /***/ }), /***/ 10517: /***/ ((module) => { "use strict"; /*! * encodeurl * Copyright(c) 2016 Douglas Christopher Wilson * MIT Licensed */ /** * Module exports. * @public */ module.exports = encodeUrl /** * RegExp to match non-URL code points, *after* encoding (i.e. not including "%") * and including invalid escape sequences. * @private */ var ENCODE_CHARS_REGEXP = /(?:[^\x21\x25\x26-\x3B\x3D\x3F-\x5B\x5D\x5F\x61-\x7A\x7E]|%(?:[^0-9A-Fa-f]|[0-9A-Fa-f][^0-9A-Fa-f]|$))+/g /** * RegExp to match unmatched surrogate pair. * @private */ var UNMATCHED_SURROGATE_PAIR_REGEXP = /(^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF]([^\uDC00-\uDFFF]|$)/g /** * String to replace unmatched surrogate pair with. * @private */ var UNMATCHED_SURROGATE_PAIR_REPLACE = '$1\uFFFD$2' /** * Encode a URL to a percent-encoded form, excluding already-encoded sequences. * * This function will take an already-encoded URL and encode all the non-URL * code points. This function will not encode the "%" character unless it is * not part of a valid sequence (`%20` will be left as-is,