UNPKG

@strawbinary-io/api-video-strapi-5-plugin

Version:

A powerful Strapi plugin to easily manage your videos and integrate them in your project

1,709 lines 463 kB
"use strict"; const strapi$1 = require("@strapi/strapi"); const ApiVideoClient = require("@api.video/nodejs-client"); const require$$0$2 = require("util"); const require$$0$1 = require("os"); const require$$0$3 = require("events"); const require$$2$1 = require("buffer"); const require$$10 = require("string_decoder/"); const require$$0$4 = require("fs"); const require$$1$1 = require("path"); const require$$3 = require("zlib"); const require$$1 = require("string_decoder"); const require$$0$5 = require("http"); const require$$1$2 = require("https"); const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; const ApiVideoClient__default = /* @__PURE__ */ _interopDefault(ApiVideoClient); const require$$0__default$1 = /* @__PURE__ */ _interopDefault(require$$0$2); const require$$0__default = /* @__PURE__ */ _interopDefault(require$$0$1); const require$$0__default$2 = /* @__PURE__ */ _interopDefault(require$$0$3); const require$$2__default = /* @__PURE__ */ _interopDefault(require$$2$1); const require$$10__default = /* @__PURE__ */ _interopDefault(require$$10); const require$$0__default$3 = /* @__PURE__ */ _interopDefault(require$$0$4); const require$$1__default$1 = /* @__PURE__ */ _interopDefault(require$$1$1); const require$$3__default = /* @__PURE__ */ _interopDefault(require$$3); const require$$1__default = /* @__PURE__ */ _interopDefault(require$$1); const require$$0__default$4 = /* @__PURE__ */ _interopDefault(require$$0$5); const require$$1__default$2 = /* @__PURE__ */ _interopDefault(require$$1$2); const PLUGIN_ID = "api-video-strapi-5-plugin"; const bootstrap = async ({ strapi: strapi2 }) => { const actions = [ // App { section: "plugins", displayName: "Read", uid: "read", pluginName: PLUGIN_ID }, { section: "plugins", displayName: "Create", uid: "create", pluginName: PLUGIN_ID }, { section: "plugins", displayName: "Update", uid: "update", pluginName: PLUGIN_ID }, { section: "plugins", displayName: "Delete", uid: "delete", pluginName: PLUGIN_ID }, // Settings { section: "plugins", displayName: "Read", subCategory: "settings", uid: "settings.read", pluginName: PLUGIN_ID }, { section: "plugins", displayName: "Update", subCategory: "settings", uid: "settings.update", pluginName: PLUGIN_ID } ]; await strapi2.admin.services.permission.actionProvider.registerMany(actions); }; const destroy$2 = ({ strapi: strapi2 }) => { }; const register = ({ strapi: strapi2 }) => { }; const config$5 = { default: {}, validator() { } }; const contentTypes = { "api-video-asset": { schema: { kind: "collectionType", collectionName: "api_video_assets", info: { name: "api-video-asset", singularName: "api-video-asset", pluralName: "api-video-assets", displayName: "api.video Asset" }, pluginOptions: { "content-manager": { visible: true }, "content-type-builder": { visible: true } }, options: { draftAndPublish: false, comment: "" }, attributes: { title: { type: "string", required: true }, description: { type: "string", required: true }, _public: { type: "boolean", default: true, required: true }, videoId: { type: "string", required: true, maxLength: 255 }, hls: { type: "string", required: true }, iframe: { type: "string", required: true }, mp4: { type: "string", required: true }, player: { type: "string", required: true }, thumbnail: { type: "string", required: true }, tags: { type: "json" }, metadata: { type: "json" } } } } }; const settingsReadAction = `plugin::${PLUGIN_ID}.settings.read`; const settingsUpdateAction = `plugin::${PLUGIN_ID}.settings.update`; const mainReadAction = `plugin::${PLUGIN_ID}.read`; const mainCreateAction = `plugin::${PLUGIN_ID}.create`; const mainUpdateAction = `plugin::${PLUGIN_ID}.update`; const mainDeleteAction = `plugin::${PLUGIN_ID}.delete`; const adminController = ({ strapi: strapi2 }) => ({ async createVideoId(ctx) { try { if (!isAllowedTo(strapi2, ctx, mainCreateAction)) { return ctx.forbidden(); } return await strapi2.plugin(PLUGIN_ID).service("api-video-asset").createVideoId(ctx.request.body.body); } catch (err) { ctx.throw(500, err); } }, async create(ctx) { try { if (!isAllowedTo(strapi2, ctx, mainCreateAction)) { return ctx.forbidden(); } ctx.body = await strapi2.plugin(PLUGIN_ID).service("api-video-asset").create(ctx.request.body.body); } catch (err) { ctx.throw(500, err); } }, async findAll(ctx) { try { if (!isAllowedTo(strapi2, ctx, mainReadAction)) { return ctx.forbidden(); } ctx.body = await strapi2.plugin(PLUGIN_ID).service("api-video-asset").findAll(ctx.request.body.body); } catch (err) { ctx.throw(500, err); } }, async token(ctx) { try { if (!isAllowedTo(strapi2, ctx, mainReadAction)) { return ctx.forbidden(); } ctx.body = await strapi2.plugin(PLUGIN_ID).service("api-video-asset").token(ctx.params.videoId); } catch (err) { ctx.throw(500, err); } }, async update(ctx) { try { if (!isAllowedTo(strapi2, ctx, mainUpdateAction)) { return ctx.forbidden(); } ctx.body = await strapi2.plugin(PLUGIN_ID).service("api-video-asset").update(ctx.params.id, ctx.params.videoId, ctx.request.body.body); } catch (err) { ctx.throw(500, err); } }, async delete(ctx) { try { if (!isAllowedTo(strapi2, ctx, mainDeleteAction)) { return ctx.forbidden(); } return await strapi2.plugin(PLUGIN_ID).service("api-video-asset").delete(ctx.params.id, ctx.params.videoId); } catch (err) { ctx.throw(500, err); } }, async getTopVideos(ctx) { if (!isAllowedTo(strapi2, ctx, mainReadAction)) { return ctx.forbidden(); } return await strapi2.plugin(PLUGIN_ID).service("api-video-asset").getTopVideos(ctx.query); } }); const settingsController = ({ strapi: strapi2 }) => ({ async getSettings(ctx) { try { if (!isAllowedTo(strapi2, ctx, settingsReadAction) && !isAllowedTo(strapi2, ctx, mainReadAction) && !!isAllowedTo(strapi2, ctx, mainCreateAction) && !!isAllowedTo(strapi2, ctx, mainUpdateAction) && !!isAllowedTo(strapi2, ctx, mainDeleteAction)) { return ctx.forbidden(); } return await strapi2.plugin(PLUGIN_ID).service("settings").getSettings(ctx); } catch (err) { ctx.throw(500, err); } }, async saveSettings(ctx) { try { if (!isAllowedTo(strapi2, ctx, settingsUpdateAction)) { return ctx.forbidden(); } return await strapi2.plugin(PLUGIN_ID).service("settings").saveSettings(ctx.request.body.body); } catch (err) { ctx.throw(500, err); } } }); const replacePrivateVideoTokens = async (video, token2) => { if (video._public) { return video; } token2 = token2 ?? (await strapi.plugin(PLUGIN_ID).service("api-video-asset").token(video.videoId)).token; return { ...video, mp4: video.mp4.replace(/token\/[\w-]+\//, `token/${token2}/`), thumbnail: video.thumbnail.replace(/token\/[\w-]+\//, `token/${token2}/`), hls: video.hls.replace(/token\/[\w-]+\//, `token/${token2}/`), iframe: video.iframe.replace(/token=[\w-]+/, `token=${token2}`), player: video.player.replace(/token=[\w-]+/, `token=${token2}`) }; }; const uid$1 = `plugin::${PLUGIN_ID}.api-video-asset`; const findOneWithPrivateVideoTransform = async (documentId, strapi2, params) => { const video = await strapi2.documents(uid$1).findOne({ documentId, ...params ?? {} }); if (!video) { return null; } video._public = video._public ?? true; return video._public ? video : await replacePrivateVideoTokens(video); }; const findWithPrivateVideoTransform = async (strapi2, params) => { try { const videos = await strapi2.documents(uid$1).findMany({ ...params ?? {} }); return await Promise.all( videos.map((video) => ({ ...video, _public: video._public ?? true })).map( async (video) => video._public ? video : await replacePrivateVideoTokens(video) ) ); } catch (e) { console.error("Error finding videos", e); } }; const contentApiControler = strapi$1.factories.createCoreController( `plugin::${PLUGIN_ID}.api-video-asset`, ({ strapi: strapi2 }) => ({ async count(ctx) { return await strapi2.documents(uid$1).count(ctx.query); }, async find(ctx) { return await findWithPrivateVideoTransform(strapi2, ctx); }, async findOne(ctx) { return await findOneWithPrivateVideoTransform(ctx.params.id, strapi2, ctx.query) ?? ctx.notFound(); } }) ); const model$1 = `plugin::${PLUGIN_ID}.api-video-asset`; const isAllowedTo = (strapi2, ctx, action) => { const pm = strapi2.admin.services.permission.createPermissionsManager({ ability: ctx.state.userAbility, action, model: model$1 }); return pm.isAllowed; }; const controllers = { admin: adminController, "api-video-asset": contentApiControler, settings: settingsController }; const middlewares = {}; const policies = {}; const apiVideoContentApiRoutes = [ { method: "GET", path: "/api-video-asset", handler: "api-video-asset.find" }, { method: "GET", path: "/api-video-asset/count", handler: "api-video-asset.count" }, { method: "GET", path: "/api-video-asset/:id", handler: "api-video-asset.findOne" } ]; const apiVideoAdminRoutes = [ { method: "GET", path: "/api-video-asset", handler: "admin.findAll", config: { policies: [] } }, { method: "GET", path: "/api-video-asset/token/:videoId", handler: "admin.token", config: { policies: [] } }, { method: "GET", path: "/api-video-asset/getTopVideos", handler: "admin.getTopVideos", config: { policies: [] } }, { method: "POST", path: "/api-video-asset", handler: "admin.create", config: { policies: [] } }, { method: "PUT", path: "/api-video-asset/:id/:videoId", handler: "admin.update", config: { policies: [] } }, { method: "DELETE", path: "/api-video-asset/:id/:videoId", handler: "admin.delete", config: { policies: [] } }, { method: "POST", path: "/api-video-asset/create", handler: "admin.createVideoId", config: { policies: [] } } ]; const apiVideoSettingsRoutes = [ { method: "GET", path: "/settings", handler: "settings.getSettings", config: { policies: [] } }, { method: "POST", path: "/settings", handler: "settings.saveSettings", config: { policies: [] } } ]; const routes = { // routes for the admin panel (/api-video-strapi-5-plugin/api-video-asset/...) admin: { type: "admin", routes: apiVideoAdminRoutes }, // routes for the plugin settings panel (/api-video-strapi-5-plugin/settings) settings: { routes: apiVideoSettingsRoutes }, // routes for the content api (/api/api-video-strapi-5-plugin/...) // Must be prefixed with 'api-video-asset' to match the name of the content type "api-video-asset": { type: "content-api", routes: apiVideoContentApiRoutes } }; const version$1 = "1.0.0"; const getConfig = async () => { const pluginStore = strapi.store({ environment: strapi.config.environment, type: "plugin", name: PLUGIN_ID }); const defaultPublic = await pluginStore.get({ key: "defaultPublic" }); const configKey = await pluginStore.get({ key: "apiKey" }); const res = { apiKey: configKey, defaultPublic: defaultPublic ?? true }; return res; }; const isValidApiKey = async (apiKey) => { const client = await configClient(apiKey); try { const { accessToken } = await client.getAccessToken(); return accessToken ? true : false; } catch (error) { return false; } }; const configClient = async (apiKey) => new ApiVideoClient__default.default({ apiKey: apiKey ? apiKey : (await getConfig()).apiKey, sdkName: "strapi-plugin", sdkVersion: version$1 }); const model = `plugin::${PLUGIN_ID}.api-video-asset`; const settingsServices = strapi$1.factories.createCoreService(model, (params) => ({ async getSettings() { const pluginStore = strapi.store({ environment: strapi.config.environment, type: "plugin", name: PLUGIN_ID }); const defaultPublic = await pluginStore.get({ key: "defaultPublic" }); const configKey = await pluginStore.get({ key: "apiKey" }); const res = { apiKey: configKey, defaultPublic: defaultPublic ?? true }; return res; }, async saveSettings(settings) { const pluginStore = strapi.store({ environment: strapi.config.environment, type: "plugin", name: PLUGIN_ID }); try { const isValid = await isValidApiKey(settings.apiKey); if (isValid) { await pluginStore.set({ key: "apiKey", value: settings.apiKey }); await pluginStore.set({ key: "defaultPublic", value: settings.defaultPublic }); return true; } else { return false; } } catch { return false; } } })); var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {}; function getAugmentedNamespace(n) { if (n.__esModule) return n; var f = n.default; if (typeof f == "function") { var a = function a2() { if (this instanceof a2) { return Reflect.construct(f, arguments, this.constructor); } return f.apply(this, arguments); }; a.prototype = f.prototype; } else a = {}; Object.defineProperty(a, "__esModule", { value: true }); Object.keys(n).forEach(function(k) { var d2 = Object.getOwnPropertyDescriptor(n, k); Object.defineProperty(a, k, d2.get ? d2 : { enumerable: true, get: function() { return n[k]; } }); }); return a; } var winston = {}; var browser$2 = {}; function _typeof$e(o) { "@babel/helpers - typeof"; return _typeof$e = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) { return typeof o2; } : function(o2) { return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2; }, _typeof$e(o); } function _createClass$c(e, r, t) { return Object.defineProperty(e, "prototype", { writable: false }), e; } function _classCallCheck$c(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _callSuper(t, o, e) { return o = _getPrototypeOf$3(o), _possibleConstructorReturn$3(t, _isNativeReflectConstruct$3() ? Reflect.construct(o, e || [], _getPrototypeOf$3(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn$3(t, e) { if (e && ("object" == _typeof$e(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized$3(t); } function _assertThisInitialized$3(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _inherits$3(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: true, configurable: true } }), Object.defineProperty(t, "prototype", { writable: false }), e && _setPrototypeOf$3(t, e); } function _wrapNativeSuper(t) { var r = "function" == typeof Map ? /* @__PURE__ */ new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper2(t2) { if (null === t2 || !_isNativeFunction(t2)) return t2; if ("function" != typeof t2) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t2)) return r.get(t2); r.set(t2, Wrapper); } function Wrapper() { return _construct(t2, arguments, _getPrototypeOf$3(this).constructor); } return Wrapper.prototype = Object.create(t2.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }), _setPrototypeOf$3(Wrapper, t2); }, _wrapNativeSuper(t); } function _construct(t, e, r) { if (_isNativeReflectConstruct$3()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf$3(p, r.prototype), p; } function _isNativeReflectConstruct$3() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() { })); } catch (t2) { } return (_isNativeReflectConstruct$3 = function _isNativeReflectConstruct2() { return !!t; })(); } function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } } function _setPrototypeOf$3(t, e) { return _setPrototypeOf$3 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(t2, e2) { return t2.__proto__ = e2, t2; }, _setPrototypeOf$3(t, e); } function _getPrototypeOf$3(t) { return _getPrototypeOf$3 = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(t2) { return t2.__proto__ || Object.getPrototypeOf(t2); }, _getPrototypeOf$3(t); } var InvalidFormatError = /* @__PURE__ */ function(_Error) { function InvalidFormatError2(formatFn) { var _this2; _classCallCheck$c(this, InvalidFormatError2); _this2 = _callSuper(this, InvalidFormatError2, ["Format functions must be synchronous taking a two arguments: (info, opts)\nFound: ".concat(formatFn.toString().split("\n")[0], "\n")]); Error.captureStackTrace(_this2, InvalidFormatError2); return _this2; } _inherits$3(InvalidFormatError2, _Error); return _createClass$c(InvalidFormatError2); }(/* @__PURE__ */ _wrapNativeSuper(Error)); var format$f = function(formatFn) { if (formatFn.length > 2) { throw new InvalidFormatError(formatFn); } function Format() { var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; this.options = options; } Format.prototype.transform = formatFn; function createFormatWrap(opts) { return new Format(opts); } createFormatWrap.Format = Format; return createFormatWrap; }; var colorize = { exports: {} }; var safe = { exports: {} }; var colors$2 = { exports: {} }; var styles = { exports: {} }; (function(module2) { var styles2 = {}; module2["exports"] = styles2; var codes2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], brightRed: [91, 39], brightGreen: [92, 39], brightYellow: [93, 39], brightBlue: [94, 39], brightMagenta: [95, 39], brightCyan: [96, 39], brightWhite: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgGray: [100, 49], bgGrey: [100, 49], bgBrightRed: [101, 49], bgBrightGreen: [102, 49], bgBrightYellow: [103, 49], bgBrightBlue: [104, 49], bgBrightMagenta: [105, 49], bgBrightCyan: [106, 49], bgBrightWhite: [107, 49], // legacy styles for colors pre v1.0.0 blackBG: [40, 49], redBG: [41, 49], greenBG: [42, 49], yellowBG: [43, 49], blueBG: [44, 49], magentaBG: [45, 49], cyanBG: [46, 49], whiteBG: [47, 49] }; Object.keys(codes2).forEach(function(key) { var val = codes2[key]; var style = styles2[key] = []; style.open = "\x1B[" + val[0] + "m"; style.close = "\x1B[" + val[1] + "m"; }); })(styles); var stylesExports = styles.exports; var hasFlag$1 = function(flag, argv) { argv = argv || process.argv || []; var terminatorPos = argv.indexOf("--"); var prefix = /^-{1,2}/.test(flag) ? "" : "--"; var pos = argv.indexOf(prefix + flag); return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos); }; var os$2 = require$$0__default.default; var hasFlag = hasFlag$1; var env = process.env; var forceColor = void 0; if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false")) { forceColor = false; } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) { forceColor = true; } if ("FORCE_COLOR" in env) { forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0; } function translateLevel(level) { if (level === 0) { return false; } return { level, hasBasic: true, has256: level >= 2, has16m: level >= 3 }; } function supportsColor(stream2) { if (forceColor === false) { return 0; } if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) { return 3; } if (hasFlag("color=256")) { return 2; } if (stream2 && !stream2.isTTY && forceColor !== true) { return 0; } var min = forceColor ? 1 : 0; if (process.platform === "win32") { var osRelease = os$2.release().split("."); if (Number(process.versions.node.split(".")[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) { return Number(osRelease[2]) >= 14931 ? 3 : 2; } return 1; } if ("CI" in env) { if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI"].some(function(sign) { return sign in env; }) || env.CI_NAME === "codeship") { return 1; } return min; } if ("TEAMCITY_VERSION" in env) { return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0; } if ("TERM_PROGRAM" in env) { var version2 = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10); switch (env.TERM_PROGRAM) { case "iTerm.app": return version2 >= 3 ? 3 : 2; case "Hyper": return 3; case "Apple_Terminal": return 2; } } if (/-256(color)?$/i.test(env.TERM)) { return 2; } if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) { return 1; } if ("COLORTERM" in env) { return 1; } if (env.TERM === "dumb") { return min; } return min; } function getSupportLevel(stream2) { var level = supportsColor(stream2); return translateLevel(level); } var supportsColors = { supportsColor: getSupportLevel, stdout: getSupportLevel(process.stdout), stderr: getSupportLevel(process.stderr) }; var trap = { exports: {} }; var hasRequiredTrap; function requireTrap() { if (hasRequiredTrap) return trap.exports; hasRequiredTrap = 1; (function(module2) { module2["exports"] = function runTheTrap(text, options) { var result = ""; text = text || "Run the trap, drop the bass"; text = text.split(""); var trap2 = { a: ["@", "Ą", "Ⱥ", "Ʌ", "Δ", "Λ", "Д"], b: ["ß", "Ɓ", "Ƀ", "ɮ", "β", "฿"], c: ["©", "Ȼ", "Ͼ"], d: ["Ð", "Ɗ", "Ԁ", "ԁ", "Ԃ", "ԃ"], e: [ "Ë", "ĕ", "Ǝ", "ɘ", "Σ", "ξ", "Ҽ", "੬" ], f: ["Ӻ"], g: ["ɢ"], h: ["Ħ", "ƕ", "Ң", "Һ", "Ӈ", "Ԋ"], i: ["༏"], j: ["Ĵ"], k: ["ĸ", "Ҡ", "Ӄ", "Ԟ"], l: ["Ĺ"], m: ["ʍ", "Ӎ", "ӎ", "Ԡ", "ԡ", "൩"], n: ["Ñ", "ŋ", "Ɲ", "Ͷ", "Π", "Ҋ"], o: [ "Ø", "õ", "ø", "Ǿ", "ʘ", "Ѻ", "ם", "۝", "๏" ], p: ["Ƿ", "Ҏ"], q: ["্"], r: ["®", "Ʀ", "Ȑ", "Ɍ", "ʀ", "Я"], s: ["§", "Ϟ", "ϟ", "Ϩ"], t: ["Ł", "Ŧ", "ͳ"], u: ["Ʊ", "Ս"], v: ["ט"], w: ["Ш", "Ѡ", "Ѽ", "൰"], x: ["Ҳ", "Ӿ", "Ӽ", "ӽ"], y: ["¥", "Ұ", "Ӌ"], z: ["Ƶ", "ɀ"] }; text.forEach(function(c) { c = c.toLowerCase(); var chars = trap2[c] || [" "]; var rand = Math.floor(Math.random() * chars.length); if (typeof trap2[c] !== "undefined") { result += trap2[c][rand]; } else { result += c; } }); return result; }; })(trap); return trap.exports; } var zalgo = { exports: {} }; var hasRequiredZalgo; function requireZalgo() { if (hasRequiredZalgo) return zalgo.exports; hasRequiredZalgo = 1; (function(module2) { module2["exports"] = function zalgo2(text, options) { text = text || " he is here "; var soul = { "up": [ "̍", "̎", "̄", "̅", "̿", "̑", "̆", "̐", "͒", "͗", "͑", "̇", "̈", "̊", "͂", "̓", "̈", "͊", "͋", "͌", "̃", "̂", "̌", "͐", "̀", "́", "̋", "̏", "̒", "̓", "̔", "̽", "̉", "ͣ", "ͤ", "ͥ", "ͦ", "ͧ", "ͨ", "ͩ", "ͪ", "ͫ", "ͬ", "ͭ", "ͮ", "ͯ", "̾", "͛", "͆", "̚" ], "down": [ "̖", "̗", "̘", "̙", "̜", "̝", "̞", "̟", "̠", "̤", "̥", "̦", "̩", "̪", "̫", "̬", "̭", "̮", "̯", "̰", "̱", "̲", "̳", "̹", "̺", "̻", "̼", "ͅ", "͇", "͈", "͉", "͍", "͎", "͓", "͔", "͕", "͖", "͙", "͚", "̣" ], "mid": [ "̕", "̛", "̀", "́", "͘", "̡", "̢", "̧", "̨", "̴", "̵", "̶", "͜", "͝", "͞", "͟", "͠", "͢", "̸", "̷", "͡", " ҉" ] }; var all = [].concat(soul.up, soul.down, soul.mid); function randomNumber(range) { var r = Math.floor(Math.random() * range); return r; } function isChar(character) { var bool = false; all.filter(function(i) { bool = i === character; }); return bool; } function heComes(text2, options2) { var result = ""; var counts; var l; options2 = options2 || {}; options2["up"] = typeof options2["up"] !== "undefined" ? options2["up"] : true; options2["mid"] = typeof options2["mid"] !== "undefined" ? options2["mid"] : true; options2["down"] = typeof options2["down"] !== "undefined" ? options2["down"] : true; options2["size"] = typeof options2["size"] !== "undefined" ? options2["size"] : "maxi"; text2 = text2.split(""); for (l in text2) { if (isChar(l)) { continue; } result = result + text2[l]; counts = { "up": 0, "down": 0, "mid": 0 }; switch (options2.size) { case "mini": counts.up = randomNumber(8); counts.mid = randomNumber(2); counts.down = randomNumber(8); break; case "maxi": counts.up = randomNumber(16) + 3; counts.mid = randomNumber(4) + 1; counts.down = randomNumber(64) + 3; break; default: counts.up = randomNumber(8) + 1; counts.mid = randomNumber(6) / 2; counts.down = randomNumber(8) + 1; break; } var arr = ["up", "mid", "down"]; for (var d2 in arr) { var index2 = arr[d2]; for (var i = 0; i <= counts[index2]; i++) { if (options2[index2]) { result = result + soul[index2][randomNumber(soul[index2].length)]; } } } } return result; } return heComes(text, options); }; })(zalgo); return zalgo.exports; } var america = { exports: {} }; var hasRequiredAmerica; function requireAmerica() { if (hasRequiredAmerica) return america.exports; hasRequiredAmerica = 1; (function(module2) { module2["exports"] = function(colors2) { return function(letter, i, exploded) { if (letter === " ") return letter; switch (i % 3) { case 0: return colors2.red(letter); case 1: return colors2.white(letter); case 2: return colors2.blue(letter); } }; }; })(america); return america.exports; } var zebra = { exports: {} }; var hasRequiredZebra; function requireZebra() { if (hasRequiredZebra) return zebra.exports; hasRequiredZebra = 1; (function(module2) { module2["exports"] = function(colors2) { return function(letter, i, exploded) { return i % 2 === 0 ? letter : colors2.inverse(letter); }; }; })(zebra); return zebra.exports; } var rainbow = { exports: {} }; var hasRequiredRainbow; function requireRainbow() { if (hasRequiredRainbow) return rainbow.exports; hasRequiredRainbow = 1; (function(module2) { module2["exports"] = function(colors2) { var rainbowColors = ["red", "yellow", "green", "blue", "magenta"]; return function(letter, i, exploded) { if (letter === " ") { return letter; } else { return colors2[rainbowColors[i++ % rainbowColors.length]](letter); } }; }; })(rainbow); return rainbow.exports; } var random = { exports: {} }; var hasRequiredRandom; function requireRandom() { if (hasRequiredRandom) return random.exports; hasRequiredRandom = 1; (function(module2) { module2["exports"] = function(colors2) { var available = [ "underline", "inverse", "grey", "yellow", "red", "green", "blue", "white", "cyan", "magenta", "brightYellow", "brightRed", "brightGreen", "brightBlue", "brightWhite", "brightCyan", "brightMagenta" ]; return function(letter, i, exploded) { return letter === " " ? letter : colors2[available[Math.round(Math.random() * (available.length - 2))]](letter); }; }; })(random); return random.exports; } (function(module2) { var colors2 = {}; module2["exports"] = colors2; colors2.themes = {}; var util2 = require$$0__default$1.default; var ansiStyles = colors2.styles = stylesExports; var defineProps = Object.defineProperties; var newLineRegex = new RegExp(/[\r\n]+/g); colors2.supportsColor = supportsColors.supportsColor; if (typeof colors2.enabled === "undefined") { colors2.enabled = colors2.supportsColor() !== false; } colors2.enable = function() { colors2.enabled = true; }; colors2.disable = function() { colors2.enabled = false; }; colors2.stripColors = colors2.strip = function(str) { return ("" + str).replace(/\x1B\[\d+m/g, ""); }; colors2.stylize = function stylize(str, style) { if (!colors2.enabled) { return str + ""; } var styleMap = ansiStyles[style]; if (!styleMap && style in colors2) { return colors2[style](str); } return styleMap.open + str + styleMap.close; }; var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g; var escapeStringRegexp = function(str) { if (typeof str !== "string") { throw new TypeError("Expected a string"); } return str.replace(matchOperatorsRe, "\\$&"); }; function build(_styles) { var builder = function builder2() { return applyStyle.apply(builder2, arguments); }; builder._styles = _styles; builder.__proto__ = proto; return builder; } var styles2 = function() { var ret = {}; ansiStyles.grey = ansiStyles.gray; Object.keys(ansiStyles).forEach(function(key) { ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), "g"); ret[key] = { get: function() { return build(this._styles.concat(key)); } }; }); return ret; }(); var proto = defineProps(function colors3() { }, styles2); function applyStyle() { var args = Array.prototype.slice.call(arguments); var str = args.map(function(arg) { if (arg != null && arg.constructor === String) { return arg; } else { return util2.inspect(arg); } }).join(" "); if (!colors2.enabled || !str) { return str; } var newLinesPresent = str.indexOf("\n") != -1; var nestedStyles = this._styles; var i = nestedStyles.length; while (i--) { var code = ansiStyles[nestedStyles[i]]; str = code.open + str.replace(code.closeRe, code.open) + code.close; if (newLinesPresent) { str = str.replace(newLineRegex, function(match) { return code.close + match + code.open; }); } } return str; } colors2.setTheme = function(theme) { if (typeof theme === "string") { console.log("colors.setTheme now only accepts an object, not a string. If you are trying to set a theme from a file, it is now your (the caller's) responsibility to require the file. The old syntax looked like colors.setTheme(__dirname + '/../themes/generic-logging.js'); The new syntax looks like colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));"); return; } for (var style in theme) { (function(style2) { colors2[style2] = function(str) { if (typeof theme[style2] === "object") { var out = str; for (var i in theme[style2]) { out = colors2[theme[style2][i]](out); } return out; } return colors2[theme[style2]](str); }; })(style); } }; function init() { var ret = {}; Object.keys(styles2).forEach(function(name3) { ret[name3] = { get: function() { return build([name3]); } }; }); return ret; } var sequencer = function sequencer2(map2, str) { var exploded = str.split(""); exploded = exploded.map(map2); return exploded.join(""); }; colors2.trap = requireTrap(); colors2.zalgo = requireZalgo(); colors2.maps = {}; colors2.maps.america = requireAmerica()(colors2); colors2.maps.zebra = requireZebra()(colors2); colors2.maps.rainbow = requireRainbow()(colors2); colors2.maps.random = requireRandom()(colors2); for (var map in colors2.maps) { (function(map2) { colors2[map2] = function(str) { return sequencer(colors2.maps[map2], str); }; })(map); } defineProps(colors2, init()); })(colors$2); var colorsExports = colors$2.exports; (function(module2) { var colors2 = colorsExports; module2["exports"] = colors2; })(safe); var safeExports = safe.exports; var tripleBeam = {}; var config$4 = {}; var cli$1 = {}; cli$1.levels = { error: 0, warn: 1, help: 2, data: 3, info: 4, debug: 5, prompt: 6, verbose: 7, input: 8, silly: 9 }; cli$1.colors = { error: "red", warn: "yellow", help: "cyan", data: "grey", info: "green", debug: "blue", prompt: "grey", verbose: "cyan", input: "grey", silly: "magenta" }; var npm = {}; npm.levels = { error: 0, warn: 1, info: 2, http: 3, verbose: 4, debug: 5, silly: 6 }; npm.colors = { error: "red", warn: "yellow", info: "green", http: "green", verbose: "cyan", debug: "blue", silly: "magenta" }; var syslog = {}; syslog.levels = { emerg: 0, alert: 1, crit: 2, error: 3, warning: 4, notice: 5, info: 6, debug: 7 }; syslog.colors = { emerg: "red", alert: "yellow", crit: "red", error: "red", warning: "red", notice: "yellow", info: "green", debug: "blue" }; (function(exports2) { Object.defineProperty(exports2, "cli", { value: cli$1 }); Object.defineProperty(exports2, "npm", { value: npm }); Object.defineProperty(exports2, "syslog", { value: syslog }); })(config$4); (function(exports2) { Object.defineProperty(exports2, "LEVEL", { value: Symbol.for("level") }); Object.defineProperty(exports2, "MESSAGE", { value: Symbol.for("message") }); Object.defineProperty(exports2, "SPLAT", { value: Symbol.for("splat") }); Object.defineProperty(exports2, "configs", { value: config$4 }); })(tripleBeam); function _typeof$d(o) { "@babel/helpers - typeof"; return _typeof$d = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) { return typeof o2; } : function(o2) { return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2; }, _typeof$d(o); } function _classCallCheck$b(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties$a(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey$c(o.key), o); } } function _createClass$b(e, r, t) { return r && _defineProperties$a(e.prototype, r), t && _defineProperties$a(e, t), Object.defineProperty(e, "prototype", { writable: false }), e; } function _toPropertyKey$c(t) { var i = _toPrimitive$c(t, "string"); return "symbol" == _typeof$d(i) ? i : i + ""; } function _toPrimitive$c(t, r) { if ("object" != _typeof$d(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof$d(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return String(t); } var colors$1 = safeExports; var _require$h = tripleBeam, LEVEL$9 = _require$h.LEVEL, MESSAGE$9 = _require$h.MESSAGE; colors$1.enabled = true; var hasSpace = /\s+/; var Colorizer$2 = /* @__PURE__ */ function() { function Colorizer2() { var opts = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; _classCallCheck$b(this, Colorizer2); if (opts.colors) { this.addColors(opts.colors); } this.options = opts; } return _createClass$b(Colorizer2, [{ key: "addColors", value: ( /* * Adds the colors Object to the set of allColors * known by the Colorizer * * @param {Object} colors Set of color mappings to add. */ function addColors(clrs) { return Colorizer2.addColors(clrs); } ) /* * function colorize (lookup, level, message) * Performs multi-step colorization using @colors/colors/safe */ }, { key: "colorize", value: function colorize2(lookup, level, message) { if (typeof message === "undefined") { message = level; } if (!Array.isArray(Colorizer2.allColors[lookup])) { return colors$1[Colorizer2.allColors[lookup]](message); } for (var i = 0, len = Colorizer2.allColors[lookup].length; i < len; i++) { message = colors$1[Colorizer2.allColors[lookup][i]](message); } return message; } /* * function transform (info, opts) * Attempts to colorize the { level, message } of the given * `logform` info object. */ }, { key: "transform", value: function transform(info, opts) { if (opts.all && typeof info[MESSAGE$9] === "string") { info[MESSAGE$9] = this.colorize(info[LEVEL$9], info.level, info[MESSAGE$9]); } if (opts.level || opts.all || !opts.message) { info.level = this.colorize(info[LEVEL$9], info.level); } if (opts.all || opts.message) { info.message = this.colorize(info[LEVEL$9], info.level, info.message); } return info; } }], [{ key: "addColors", value: function addColors(clrs) { var nextColors = Object.keys(clrs).reduce(function(acc, level) { acc[level] = hasSpace.test(clrs[level]) ? clrs[level].split(hasSpace) : clrs[level]; return acc; }, {}); Colorizer2.allColors = Object.assign({}, Colorizer2.allColors || {}, nextColors); return Colorizer2.allColors; } }]); }(); colorize.exports = function(opts) { return new Colorizer$2(opts); }; colorize.exports.Colorizer = colorize.exports.Format = Colorizer$2; var colorizeExports = colorize.exports; var _require$g = colorizeExports, Colorizer$1 = _require$g.Colorizer; var levels = function(config2) { Colorizer$1.addColors(config2.colors || config2); return config2; }; var format$e = format$f; var align = format$e(function(info) { info.message = " ".concat(info.message); return info; }); var cli = { exports: {} }; var padLevels = { exports: {} }; function _typeof$c(o) { "@babel/helpers - typeof"; return _typeof$c = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) { return typeof o2; } : function(o2) { return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2; }, _typeof$c(o); } function _toConsumableArray$1(r) { return _arrayWithoutHoles$1(r) || _iterableToArray$1(r) || _unsupportedIterableToArray$1(r) || _nonIterableSpread$1(); } function _nonIterableSpread$1() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray$1(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$1(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$1(r, a) : void 0; } } function _iterableToArray$1(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles$1(r) { if (Array.isArray(r)) return _arrayLikeToArray$1(r); } function _arrayLikeToArray$1(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _classCallCheck$a(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties$9(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey$b(o.key), o); } } function _createClass$a(e, r, t) { return r && _defineProperties$9(e.prototype, r), t && _defineProperties$9(e, t), Object.defineProperty(e, "prototype", { writable: false }), e; } function _toPropertyKey$b(t) { var i = _toPrimitive$b(t, "string"); return "symbol" == _typeof$c(i) ? i : i + ""; } function _toPrimitive$b(t, r) { if ("object" != _typeof$c(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof$c(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return String(t); } var _require$f = tripleBeam, configs$2 = _require$f.configs, LEVEL$8 = _require$f.LEVEL, MESSAGE$8 = _require$f.MESSAGE; var Padder$1 = /* @__PURE__ */ function() { function Padder2() { var opts = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : { levels: configs$2.npm.levels }; _classCallCheck$a(this, Padder2); this.paddings = Padder2.paddingForLevels(opts.levels, opts.filler); this.options = opts; } return _createClass$a(Padder2, [{ key: "transform", value: ( /** * Prepends the padding onto the `message` based on the `LEVEL` of * the `info`. This is based on the behavior of `winston@2` which also * prepended the level onto the message. * * See: https://github.com/winstonjs/winston/blob/2.x/lib/winston/logger.js#L198-L201 * * @param {Info} info Logform info object * @param {Object} opts Options passed along to this instance. * @returns {Info} Modified logform info object. */ function transform(info, opts) { info.message = "".concat(this.paddings[info[LEVEL$8]]).concat(info.message); if (info[MESSAGE$8]) { info[MESSAGE$8] = "".concat(this.paddings[info[LEVEL$8]]).concat(info[MESSAGE$8]); } return info; } ) }], [{ key: "getLongestLevel", value: function getLongestLevel(levels2) { var lvls = Object.keys(levels2).map(function(level) { return level.length; }); return Math.max.apply(Math, _toConsumableArray$1(lvls)); } /** * Returns the padding for the specified `level` assuming that the * maximum length of all levels it's associated with is `maxLength`. * @param {String} level Level to calculate padding for. * @param {String} filler Repeatable text to use for padding. * @param {Number} maxLength Length of the longest level * @returns {String} Padding string for the `level` */ }, { key: "paddingForLevel", value: function paddingForLevel(level, filler, maxLength) { var targetLen = maxLength + 1 - level.length; var rep = Math.floor(targetLen / filler.length); var padding = "".concat(filler).concat(filler.repeat(rep)); return padding.slice(0, targetLen); } /** * Returns an object with the string paddings for the given `levels` * using the specified `filler`. * @param {Object} levels Set of all levels to calculate padding for. * @param {String} filler Repeatable text to use for padding. * @returns {Object} Mapping of level to desired padding. */ }, { key: "paddingForLevels", value: function paddingForLevels(levels2) { var filler = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : " "; var maxLength = Padder2.getLongestLevel(levels2); return Object.keys(levels2).reduce(function(acc, level) { acc[level] = Padder2.paddingForLevel(level, filler, maxLength); return acc; }, {}); } }]); }(); padLevels.exports = function(opts) { return new Padder$1(opts); }; padLevels.exports.Padder = padLevels.exports.Format = Padder$1; var padLevelsExports = padLevels.exports; function _typeof$b(o) { "@babel/helpers - typeof"; return _typeof$b = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) { return typeof o2; } : function(o2) { return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2; }, _typeof$b(o); } function _classCallCheck$9(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties$8(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey$a(o.key), o); } } function _createClass$9(e, r, t) { return r && _defineProperties$8(e.prototype, r), Object.defineProperty(e, "prototype", { writable: false }), e; } function _toPropertyKey$a(t) { var i = _toPrimitive$a(t, "string"); return "symbol" == _typeof$b(i) ? i : i + ""; } function _toPrimitive$a(t, r) { if ("object" != _typeof$b(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof$b(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return String(t); } var _require$e = colorizeExports, Colorizer = _require$e.Colorizer; var _require2$1 = padLevelsExports, Padder = _require2$1.Padder; var _require3$1 = tripleBeam, configs$1 = _require3$1.configs, MESSAGE$7 = _require3$1.MESSAGE; var CliFormat = /* @__PURE__ */ function() { function CliFormat2() { var opts = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; _classCallCheck$9(this, CliFormat2); if (!opts.levels) { opts.levels = configs$1.cli.levels; } this.colorizer = new Colorizer(opts); this.padder = new Padder(opts); this.options = opts; } return _createClass$9(CliFormat2, [{ key: "tra