@pollyjs/node-server
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,583 +0,2 @@ | ||
/** | ||
* @pollyjs/node-server v0.0.0 | ||
* | ||
* https://github.com/netflix/pollyjs | ||
* | ||
* Released under the Apache-2.0 License. | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var fs = _interopDefault(require('fs-extra')); | ||
var path = _interopDefault(require('path')); | ||
var express = _interopDefault(require('express')); | ||
var bodyParser = _interopDefault(require('body-parser')); | ||
var nocache = _interopDefault(require('nocache')); | ||
var morgan = _interopDefault(require('morgan')); | ||
var gracefulShutdown = _interopDefault(require('http-graceful-shutdown')); | ||
class API { | ||
constructor(recordingsDir) { | ||
this.recordingsDir = recordingsDir; | ||
} | ||
getRecordingEntry(recording, entryId, order) { | ||
const recordingFilename = this.filenameFor(recording); | ||
if (fs.existsSync(recordingFilename)) { | ||
const data = fs.readJsonSync(recordingFilename); | ||
const entries = data.entries[entryId]; | ||
if (entries && entries[order]) { | ||
return this.respond(200, entries[order]); | ||
} | ||
} | ||
return this.respond(204); | ||
} | ||
getRecording(recording) { | ||
const recordingFilename = this.filenameFor(recording); | ||
if (fs.existsSync(recordingFilename)) { | ||
return this.respond(200, fs.readJsonSync(recordingFilename)); | ||
} | ||
return this.respond(204); | ||
} | ||
saveRecording(recording, data) { | ||
fs.outputJsonSync(this.filenameFor(recording), data, { | ||
spaces: 2 | ||
}); | ||
return this.respond(201); | ||
} | ||
deleteRecording(recording) { | ||
const recordingFilename = this.filenameFor(recording); | ||
if (fs.existsSync(recordingFilename)) { | ||
fs.removeSync(recordingFilename); | ||
} | ||
return this.respond(200); | ||
} | ||
filenameFor(recording) { | ||
return path.join(this.recordingsDir, recording, 'recording.json'); | ||
} | ||
respond(status, body) { | ||
return { status, body }; | ||
} | ||
} | ||
function unwrapExports (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var _global = createCommonjsModule(function (module) { | ||
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 | ||
var global = module.exports = typeof window != 'undefined' && window.Math == Math | ||
? window : typeof self != 'undefined' && self.Math == Math ? self | ||
// eslint-disable-next-line no-new-func | ||
: Function('return this')(); | ||
if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef | ||
}); | ||
var _core = createCommonjsModule(function (module) { | ||
var core = module.exports = { version: '2.5.5' }; | ||
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef | ||
}); | ||
var _core_1 = _core.version; | ||
var _aFunction = function (it) { | ||
if (typeof it != 'function') throw TypeError(it + ' is not a function!'); | ||
return it; | ||
}; | ||
// optional / simple context binding | ||
var _ctx = function (fn, that, length) { | ||
_aFunction(fn); | ||
if (that === undefined) return fn; | ||
switch (length) { | ||
case 1: return function (a) { | ||
return fn.call(that, a); | ||
}; | ||
case 2: return function (a, b) { | ||
return fn.call(that, a, b); | ||
}; | ||
case 3: return function (a, b, c) { | ||
return fn.call(that, a, b, c); | ||
}; | ||
} | ||
return function (/* ...args */) { | ||
return fn.apply(that, arguments); | ||
}; | ||
}; | ||
var _isObject = function (it) { | ||
return typeof it === 'object' ? it !== null : typeof it === 'function'; | ||
}; | ||
var _anObject = function (it) { | ||
if (!_isObject(it)) throw TypeError(it + ' is not an object!'); | ||
return it; | ||
}; | ||
var _fails = function (exec) { | ||
try { | ||
return !!exec(); | ||
} catch (e) { | ||
return true; | ||
} | ||
}; | ||
// Thank's IE8 for his funny defineProperty | ||
var _descriptors = !_fails(function () { | ||
return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7; | ||
}); | ||
var document = _global.document; | ||
// typeof document.createElement is 'object' in old IE | ||
var is = _isObject(document) && _isObject(document.createElement); | ||
var _domCreate = function (it) { | ||
return is ? document.createElement(it) : {}; | ||
}; | ||
var _ie8DomDefine = !_descriptors && !_fails(function () { | ||
return Object.defineProperty(_domCreate('div'), 'a', { get: function () { return 7; } }).a != 7; | ||
}); | ||
// 7.1.1 ToPrimitive(input [, PreferredType]) | ||
// instead of the ES6 spec version, we didn't implement @@toPrimitive case | ||
// and the second argument - flag - preferred type is a string | ||
var _toPrimitive = function (it, S) { | ||
if (!_isObject(it)) return it; | ||
var fn, val; | ||
if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val; | ||
if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val; | ||
if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val; | ||
throw TypeError("Can't convert object to primitive value"); | ||
}; | ||
var dP = Object.defineProperty; | ||
var f = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) { | ||
_anObject(O); | ||
P = _toPrimitive(P, true); | ||
_anObject(Attributes); | ||
if (_ie8DomDefine) try { | ||
return dP(O, P, Attributes); | ||
} catch (e) { /* empty */ } | ||
if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!'); | ||
if ('value' in Attributes) O[P] = Attributes.value; | ||
return O; | ||
}; | ||
var _objectDp = { | ||
f: f | ||
}; | ||
var _propertyDesc = function (bitmap, value) { | ||
return { | ||
enumerable: !(bitmap & 1), | ||
configurable: !(bitmap & 2), | ||
writable: !(bitmap & 4), | ||
value: value | ||
}; | ||
}; | ||
var _hide = _descriptors ? function (object, key, value) { | ||
return _objectDp.f(object, key, _propertyDesc(1, value)); | ||
} : function (object, key, value) { | ||
object[key] = value; | ||
return object; | ||
}; | ||
var hasOwnProperty = {}.hasOwnProperty; | ||
var _has = function (it, key) { | ||
return hasOwnProperty.call(it, key); | ||
}; | ||
var PROTOTYPE = 'prototype'; | ||
var $export = function (type, name, source) { | ||
var IS_FORCED = type & $export.F; | ||
var IS_GLOBAL = type & $export.G; | ||
var IS_STATIC = type & $export.S; | ||
var IS_PROTO = type & $export.P; | ||
var IS_BIND = type & $export.B; | ||
var IS_WRAP = type & $export.W; | ||
var exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {}); | ||
var expProto = exports[PROTOTYPE]; | ||
var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] : (_global[name] || {})[PROTOTYPE]; | ||
var key, own, out; | ||
if (IS_GLOBAL) source = name; | ||
for (key in source) { | ||
// contains in native | ||
own = !IS_FORCED && target && target[key] !== undefined; | ||
if (own && _has(exports, key)) continue; | ||
// export native or passed | ||
out = own ? target[key] : source[key]; | ||
// prevent global pollution for namespaces | ||
exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] | ||
// bind timers to global for call from export context | ||
: IS_BIND && own ? _ctx(out, _global) | ||
// wrap global constructors for prevent change them in library | ||
: IS_WRAP && target[key] == out ? (function (C) { | ||
var F = function (a, b, c) { | ||
if (this instanceof C) { | ||
switch (arguments.length) { | ||
case 0: return new C(); | ||
case 1: return new C(a); | ||
case 2: return new C(a, b); | ||
} return new C(a, b, c); | ||
} return C.apply(this, arguments); | ||
}; | ||
F[PROTOTYPE] = C[PROTOTYPE]; | ||
return F; | ||
// make static versions for prototype methods | ||
})(out) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out; | ||
// export proto methods to core.%CONSTRUCTOR%.methods.%NAME% | ||
if (IS_PROTO) { | ||
(exports.virtual || (exports.virtual = {}))[key] = out; | ||
// export proto methods to core.%CONSTRUCTOR%.prototype.%NAME% | ||
if (type & $export.R && expProto && !expProto[key]) _hide(expProto, key, out); | ||
} | ||
} | ||
}; | ||
// type bitmap | ||
$export.F = 1; // forced | ||
$export.G = 2; // global | ||
$export.S = 4; // static | ||
$export.P = 8; // proto | ||
$export.B = 16; // bind | ||
$export.W = 32; // wrap | ||
$export.U = 64; // safe | ||
$export.R = 128; // real proto method for `library` | ||
var _export = $export; | ||
var toString = {}.toString; | ||
var _cof = function (it) { | ||
return toString.call(it).slice(8, -1); | ||
}; | ||
// fallback for non-array-like ES3 and non-enumerable old V8 strings | ||
// eslint-disable-next-line no-prototype-builtins | ||
var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function (it) { | ||
return _cof(it) == 'String' ? it.split('') : Object(it); | ||
}; | ||
// 7.2.1 RequireObjectCoercible(argument) | ||
var _defined = function (it) { | ||
if (it == undefined) throw TypeError("Can't call method on " + it); | ||
return it; | ||
}; | ||
// to indexed object, toObject with fallback for non-array-like ES3 strings | ||
var _toIobject = function (it) { | ||
return _iobject(_defined(it)); | ||
}; | ||
// 7.1.4 ToInteger | ||
var ceil = Math.ceil; | ||
var floor = Math.floor; | ||
var _toInteger = function (it) { | ||
return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); | ||
}; | ||
// 7.1.15 ToLength | ||
var min = Math.min; | ||
var _toLength = function (it) { | ||
return it > 0 ? min(_toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991 | ||
}; | ||
var max = Math.max; | ||
var min$1 = Math.min; | ||
var _toAbsoluteIndex = function (index, length) { | ||
index = _toInteger(index); | ||
return index < 0 ? max(index + length, 0) : min$1(index, length); | ||
}; | ||
// false -> Array#indexOf | ||
// true -> Array#includes | ||
var _arrayIncludes = function (IS_INCLUDES) { | ||
return function ($this, el, fromIndex) { | ||
var O = _toIobject($this); | ||
var length = _toLength(O.length); | ||
var index = _toAbsoluteIndex(fromIndex, length); | ||
var value; | ||
// Array#includes uses SameValueZero equality algorithm | ||
// eslint-disable-next-line no-self-compare | ||
if (IS_INCLUDES && el != el) while (length > index) { | ||
value = O[index++]; | ||
// eslint-disable-next-line no-self-compare | ||
if (value != value) return true; | ||
// Array#indexOf ignores holes, Array#includes - not | ||
} else for (;length > index; index++) if (IS_INCLUDES || index in O) { | ||
if (O[index] === el) return IS_INCLUDES || index || 0; | ||
} return !IS_INCLUDES && -1; | ||
}; | ||
}; | ||
var SHARED = '__core-js_shared__'; | ||
var store = _global[SHARED] || (_global[SHARED] = {}); | ||
var _shared = function (key) { | ||
return store[key] || (store[key] = {}); | ||
}; | ||
var id = 0; | ||
var px = Math.random(); | ||
var _uid = function (key) { | ||
return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); | ||
}; | ||
var shared = _shared('keys'); | ||
var _sharedKey = function (key) { | ||
return shared[key] || (shared[key] = _uid(key)); | ||
}; | ||
var arrayIndexOf = _arrayIncludes(false); | ||
var IE_PROTO = _sharedKey('IE_PROTO'); | ||
var _objectKeysInternal = function (object, names) { | ||
var O = _toIobject(object); | ||
var i = 0; | ||
var result = []; | ||
var key; | ||
for (key in O) if (key != IE_PROTO) _has(O, key) && result.push(key); | ||
// Don't enum bug & hidden keys | ||
while (names.length > i) if (_has(O, key = names[i++])) { | ||
~arrayIndexOf(result, key) || result.push(key); | ||
} | ||
return result; | ||
}; | ||
// IE 8- don't enum bug keys | ||
var _enumBugKeys = ( | ||
'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf' | ||
).split(','); | ||
// 19.1.2.14 / 15.2.3.14 Object.keys(O) | ||
var _objectKeys = Object.keys || function keys(O) { | ||
return _objectKeysInternal(O, _enumBugKeys); | ||
}; | ||
var f$1 = Object.getOwnPropertySymbols; | ||
var _objectGops = { | ||
f: f$1 | ||
}; | ||
var f$2 = {}.propertyIsEnumerable; | ||
var _objectPie = { | ||
f: f$2 | ||
}; | ||
// 7.1.13 ToObject(argument) | ||
var _toObject = function (it) { | ||
return Object(_defined(it)); | ||
}; | ||
// 19.1.2.1 Object.assign(target, source, ...) | ||
var $assign = Object.assign; | ||
// should work with symbols and should have deterministic property order (V8 bug) | ||
var _objectAssign = !$assign || _fails(function () { | ||
var A = {}; | ||
var B = {}; | ||
// eslint-disable-next-line no-undef | ||
var S = Symbol(); | ||
var K = 'abcdefghijklmnopqrst'; | ||
A[S] = 7; | ||
K.split('').forEach(function (k) { B[k] = k; }); | ||
return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K; | ||
}) ? function assign(target, source) { // eslint-disable-line no-unused-vars | ||
var T = _toObject(target); | ||
var aLen = arguments.length; | ||
var index = 1; | ||
var getSymbols = _objectGops.f; | ||
var isEnum = _objectPie.f; | ||
while (aLen > index) { | ||
var S = _iobject(arguments[index++]); | ||
var keys = getSymbols ? _objectKeys(S).concat(getSymbols(S)) : _objectKeys(S); | ||
var length = keys.length; | ||
var j = 0; | ||
var key; | ||
while (length > j) if (isEnum.call(S, key = keys[j++])) T[key] = S[key]; | ||
} return T; | ||
} : $assign; | ||
// 19.1.3.1 Object.assign(target, source) | ||
_export(_export.S + _export.F, 'Object', { assign: _objectAssign }); | ||
var assign = _core.Object.assign; | ||
var assign$1 = createCommonjsModule(function (module) { | ||
module.exports = { "default": assign, __esModule: true }; | ||
}); | ||
var _Object$assign = unwrapExports(assign$1); | ||
var DefaultConfig = { | ||
port: 3000, | ||
quiet: false, | ||
recordingsDir: 'recordings', | ||
apiNamespace: 'polly' | ||
}; | ||
function registerAPI(app, config) { | ||
config = _Object$assign({}, DefaultConfig, config); | ||
config.apiNamespace = path.join('/', config.apiNamespace); | ||
const router = express.Router(); | ||
const api = new API(config.recordingsDir); | ||
router.use(nocache()); | ||
router.get('/:recording/:entryId', function (req, res) { | ||
var _req$params = req.params; | ||
const recording = _req$params.recording, | ||
entryId = _req$params.entryId; | ||
const order = req.query.order; | ||
var _api$getRecordingEntr = api.getRecordingEntry(recording, entryId, order); | ||
const status = _api$getRecordingEntr.status, | ||
body = _api$getRecordingEntr.body; | ||
res.status(status); | ||
if (status === 200) { | ||
res.json(body); | ||
} else { | ||
res.end(); | ||
} | ||
}); | ||
router.get('/:recording', function (req, res) { | ||
const recording = req.params.recording; | ||
var _api$getRecording = api.getRecording(recording); | ||
const status = _api$getRecording.status, | ||
body = _api$getRecording.body; | ||
res.status(status); | ||
if (status === 200) { | ||
res.json(body); | ||
} else { | ||
res.end(); | ||
} | ||
}); | ||
router.post('/:recording', bodyParser.json({ limit: '50mb' }), function (req, res) { | ||
const recording = req.params.recording; | ||
var _api$saveRecording = api.saveRecording(recording, req.body); | ||
const status = _api$saveRecording.status, | ||
body = _api$saveRecording.body; | ||
res.status(status).send(body); | ||
}); | ||
router.delete('/:recording', function (req, res) { | ||
const recording = req.params.recording; | ||
var _api$deleteRecording = api.deleteRecording(recording); | ||
const status = _api$deleteRecording.status, | ||
body = _api$deleteRecording.body; | ||
res.status(status).send(body); | ||
}); | ||
app.use(config.apiNamespace, router); | ||
} | ||
class Server { | ||
constructor(config = {}) { | ||
this.config = _Object$assign({}, DefaultConfig, config); | ||
this.app = express(); | ||
if (!this.config.quiet) { | ||
this.app.use(morgan('dev')); | ||
} | ||
// Return 200 on root GET & HEAD to pass health checks | ||
this.app.get('/', (req, res) => res.sendStatus(200)); | ||
this.app.head('/', (req, res) => res.sendStatus(200)); | ||
registerAPI(this.app, { | ||
recordingsDir: this.config.recordingsDir, | ||
apiNamespace: this.config.apiNamespace | ||
}); | ||
} | ||
listen(port, host) { | ||
if (this.server) { | ||
return; | ||
} | ||
port = port || this.config.port; | ||
host = host || this.config.host; | ||
this.server = this.app.listen(port, host).on('listening', () => { | ||
console.log(`Listening on http://${host || 'localhost'}:${port}/\n`); | ||
}).on('error', e => { | ||
if (e.code === 'EADDRINUSE') { | ||
console.error(`Port ${port} already in use.`); | ||
process.exit(1); | ||
} else { | ||
console.error(e); | ||
} | ||
}); | ||
gracefulShutdown(this.server); | ||
return this.server; | ||
} | ||
} | ||
exports.API = API; | ||
exports.Server = Server; | ||
exports.Defaults = DefaultConfig; | ||
exports.registerExpressAPI = registerAPI; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var fs=_interopDefault(require("fs-extra")),path=_interopDefault(require("path")),express=_interopDefault(require("express")),bodyParser=_interopDefault(require("body-parser")),nocache=_interopDefault(require("nocache")),morgan=_interopDefault(require("morgan")),gracefulShutdown=_interopDefault(require("http-graceful-shutdown"));class API{constructor(e){this.recordingsDir=e}getRecordingEntry(e,t,r){const n=this.filenameFor(e);if(fs.existsSync(n)){const e=fs.readJsonSync(n).entries[t];if(e&&e[r])return this.respond(200,e[r])}return this.respond(204)}getRecording(e){const t=this.filenameFor(e);return fs.existsSync(t)?this.respond(200,fs.readJsonSync(t)):this.respond(204)}saveRecording(e,t){return fs.outputJsonSync(this.filenameFor(e),t,{spaces:2}),this.respond(201)}deleteRecording(e){const t=this.filenameFor(e);return fs.existsSync(t)&&fs.removeSync(t),this.respond(200)}filenameFor(e){return path.join(this.recordingsDir,e,"recording.json")}respond(e,t){return{status:e,body:t}}}function unwrapExports(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}var _global=createCommonjsModule(function(e){var t=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=t)}),_core=createCommonjsModule(function(e){var t=e.exports={version:"2.5.5"};"number"==typeof __e&&(__e=t)}),_core_1=_core.version,_aFunction=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e},_ctx=function(e,t,r){if(_aFunction(e),void 0===t)return e;switch(r){case 1:return function(r){return e.call(t,r)};case 2:return function(r,n){return e.call(t,r,n)};case 3:return function(r,n,o){return e.call(t,r,n,o)}}return function(){return e.apply(t,arguments)}},_isObject=function(e){return"object"==typeof e?null!==e:"function"==typeof e},_anObject=function(e){if(!_isObject(e))throw TypeError(e+" is not an object!");return e},_fails=function(e){try{return!!e()}catch(e){return!0}},_descriptors=!_fails(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a}),document=_global.document,is=_isObject(document)&&_isObject(document.createElement),_domCreate=function(e){return is?document.createElement(e):{}},_ie8DomDefine=!_descriptors&&!_fails(function(){return 7!=Object.defineProperty(_domCreate("div"),"a",{get:function(){return 7}}).a}),_toPrimitive=function(e,t){if(!_isObject(e))return e;var r,n;if(t&&"function"==typeof(r=e.toString)&&!_isObject(n=r.call(e)))return n;if("function"==typeof(r=e.valueOf)&&!_isObject(n=r.call(e)))return n;if(!t&&"function"==typeof(r=e.toString)&&!_isObject(n=r.call(e)))return n;throw TypeError("Can't convert object to primitive value")},dP=Object.defineProperty,f=_descriptors?Object.defineProperty:function(e,t,r){if(_anObject(e),t=_toPrimitive(t,!0),_anObject(r),_ie8DomDefine)try{return dP(e,t,r)}catch(e){}if("get"in r||"set"in r)throw TypeError("Accessors not supported!");return"value"in r&&(e[t]=r.value),e},_objectDp={f:f},_propertyDesc=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},_hide=_descriptors?function(e,t,r){return _objectDp.f(e,t,_propertyDesc(1,r))}:function(e,t,r){return e[t]=r,e},hasOwnProperty={}.hasOwnProperty,_has=function(e,t){return hasOwnProperty.call(e,t)},PROTOTYPE="prototype",$export=function(e,t,r){var n,o,i,s=e&$export.F,c=e&$export.G,a=e&$export.S,u=e&$export.P,f=e&$export.B,p=e&$export.W,l=c?_core:_core[t]||(_core[t]={}),_=l[PROTOTYPE],d=c?_global:a?_global[t]:(_global[t]||{})[PROTOTYPE];for(n in c&&(r=t),r)(o=!s&&d&&void 0!==d[n])&&_has(l,n)||(i=o?d[n]:r[n],l[n]=c&&"function"!=typeof d[n]?r[n]:f&&o?_ctx(i,_global):p&&d[n]==i?function(e){var t=function(t,r,n){if(this instanceof e){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,r)}return new e(t,r,n)}return e.apply(this,arguments)};return t[PROTOTYPE]=e[PROTOTYPE],t}(i):u&&"function"==typeof i?_ctx(Function.call,i):i,u&&((l.virtual||(l.virtual={}))[n]=i,e&$export.R&&_&&!_[n]&&_hide(_,n,i)))};$export.F=1,$export.G=2,$export.S=4,$export.P=8,$export.B=16,$export.W=32,$export.U=64,$export.R=128;var _export=$export,toString={}.toString,_cof=function(e){return toString.call(e).slice(8,-1)},_iobject=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==_cof(e)?e.split(""):Object(e)},_defined=function(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e},_toIobject=function(e){return _iobject(_defined(e))},ceil=Math.ceil,floor=Math.floor,_toInteger=function(e){return isNaN(e=+e)?0:(e>0?floor:ceil)(e)},min=Math.min,_toLength=function(e){return e>0?min(_toInteger(e),9007199254740991):0},max=Math.max,min$1=Math.min,_toAbsoluteIndex=function(e,t){return(e=_toInteger(e))<0?max(e+t,0):min$1(e,t)},_arrayIncludes=function(e){return function(t,r,n){var o,i=_toIobject(t),s=_toLength(i.length),c=_toAbsoluteIndex(n,s);if(e&&r!=r){for(;s>c;)if((o=i[c++])!=o)return!0}else for(;s>c;c++)if((e||c in i)&&i[c]===r)return e||c||0;return!e&&-1}},SHARED="__core-js_shared__",store=_global[SHARED]||(_global[SHARED]={}),_shared=function(e){return store[e]||(store[e]={})},id=0,px=Math.random(),_uid=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++id+px).toString(36))},shared=_shared("keys"),_sharedKey=function(e){return shared[e]||(shared[e]=_uid(e))},arrayIndexOf=_arrayIncludes(!1),IE_PROTO=_sharedKey("IE_PROTO"),_objectKeysInternal=function(e,t){var r,n=_toIobject(e),o=0,i=[];for(r in n)r!=IE_PROTO&&_has(n,r)&&i.push(r);for(;t.length>o;)_has(n,r=t[o++])&&(~arrayIndexOf(i,r)||i.push(r));return i},_enumBugKeys="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(","),_objectKeys=Object.keys||function(e){return _objectKeysInternal(e,_enumBugKeys)},f$1=Object.getOwnPropertySymbols,_objectGops={f:f$1},f$2={}.propertyIsEnumerable,_objectPie={f:f$2},_toObject=function(e){return Object(_defined(e))},$assign=Object.assign,_objectAssign=!$assign||_fails(function(){var e={},t={},r=Symbol(),n="abcdefghijklmnopqrst";return e[r]=7,n.split("").forEach(function(e){t[e]=e}),7!=$assign({},e)[r]||Object.keys($assign({},t)).join("")!=n})?function(e,t){for(var r=_toObject(e),n=arguments.length,o=1,i=_objectGops.f,s=_objectPie.f;n>o;)for(var c,a=_iobject(arguments[o++]),u=i?_objectKeys(a).concat(i(a)):_objectKeys(a),f=u.length,p=0;f>p;)s.call(a,c=u[p++])&&(r[c]=a[c]);return r}:$assign;_export(_export.S+_export.F,"Object",{assign:_objectAssign});var assign=_core.Object.assign,assign$1=createCommonjsModule(function(e){e.exports={default:assign,__esModule:!0}}),_Object$assign=unwrapExports(assign$1),DefaultConfig={port:3e3,quiet:!1,recordingsDir:"recordings",apiNamespace:"polly"};function registerAPI(e,t){(t=_Object$assign({},DefaultConfig,t)).apiNamespace=path.join("/",t.apiNamespace);const r=express.Router(),n=new API(t.recordingsDir);r.use(nocache()),r.get("/:recording/:entryId",function(e,t){var r=e.params;const o=r.recording,i=r.entryId,s=e.query.order;var c=n.getRecordingEntry(o,i,s);const a=c.status,u=c.body;t.status(a),200===a?t.json(u):t.end()}),r.get("/:recording",function(e,t){const r=e.params.recording;var o=n.getRecording(r);const i=o.status,s=o.body;t.status(i),200===i?t.json(s):t.end()}),r.post("/:recording",bodyParser.json({limit:"50mb"}),function(e,t){const r=e.params.recording;var o=n.saveRecording(r,e.body);const i=o.status,s=o.body;t.status(i).send(s)}),r.delete("/:recording",function(e,t){const r=e.params.recording;var o=n.deleteRecording(r);const i=o.status,s=o.body;t.status(i).send(s)}),e.use(t.apiNamespace,r)}class Server{constructor(e={}){this.config=_Object$assign({},DefaultConfig,e),this.app=express(),this.config.quiet||this.app.use(morgan("dev")),this.app.get("/",(e,t)=>t.sendStatus(200)),this.app.head("/",(e,t)=>t.sendStatus(200)),registerAPI(this.app,{recordingsDir:this.config.recordingsDir,apiNamespace:this.config.apiNamespace})}listen(e,t){if(!this.server)return e=e||this.config.port,t=t||this.config.host,this.server=this.app.listen(e,t).on("listening",()=>{console.log(`Listening on http://${t||"localhost"}:${e}/\n`)}).on("error",t=>{"EADDRINUSE"===t.code?(console.error(`Port ${e} already in use.`),process.exit(1)):console.error(t)}),gracefulShutdown(this.server),this.server}}exports.API=API,exports.Server=Server,exports.Defaults=DefaultConfig,exports.registerExpressAPI=registerAPI; | ||
//# sourceMappingURL=pollyjs-node-server.js.map |
@@ -1,574 +0,2 @@ | ||
/** | ||
* @pollyjs/node-server v0.0.0 | ||
* | ||
* https://github.com/netflix/pollyjs | ||
* | ||
* Released under the Apache-2.0 License. | ||
*/ | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import express from 'express'; | ||
import bodyParser from 'body-parser'; | ||
import nocache from 'nocache'; | ||
import morgan from 'morgan'; | ||
import gracefulShutdown from 'http-graceful-shutdown'; | ||
class API { | ||
constructor(recordingsDir) { | ||
this.recordingsDir = recordingsDir; | ||
} | ||
getRecordingEntry(recording, entryId, order) { | ||
const recordingFilename = this.filenameFor(recording); | ||
if (fs.existsSync(recordingFilename)) { | ||
const data = fs.readJsonSync(recordingFilename); | ||
const entries = data.entries[entryId]; | ||
if (entries && entries[order]) { | ||
return this.respond(200, entries[order]); | ||
} | ||
} | ||
return this.respond(204); | ||
} | ||
getRecording(recording) { | ||
const recordingFilename = this.filenameFor(recording); | ||
if (fs.existsSync(recordingFilename)) { | ||
return this.respond(200, fs.readJsonSync(recordingFilename)); | ||
} | ||
return this.respond(204); | ||
} | ||
saveRecording(recording, data) { | ||
fs.outputJsonSync(this.filenameFor(recording), data, { | ||
spaces: 2 | ||
}); | ||
return this.respond(201); | ||
} | ||
deleteRecording(recording) { | ||
const recordingFilename = this.filenameFor(recording); | ||
if (fs.existsSync(recordingFilename)) { | ||
fs.removeSync(recordingFilename); | ||
} | ||
return this.respond(200); | ||
} | ||
filenameFor(recording) { | ||
return path.join(this.recordingsDir, recording, 'recording.json'); | ||
} | ||
respond(status, body) { | ||
return { status, body }; | ||
} | ||
} | ||
function unwrapExports (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var _global = createCommonjsModule(function (module) { | ||
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 | ||
var global = module.exports = typeof window != 'undefined' && window.Math == Math | ||
? window : typeof self != 'undefined' && self.Math == Math ? self | ||
// eslint-disable-next-line no-new-func | ||
: Function('return this')(); | ||
if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef | ||
}); | ||
var _core = createCommonjsModule(function (module) { | ||
var core = module.exports = { version: '2.5.5' }; | ||
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef | ||
}); | ||
var _core_1 = _core.version; | ||
var _aFunction = function (it) { | ||
if (typeof it != 'function') throw TypeError(it + ' is not a function!'); | ||
return it; | ||
}; | ||
// optional / simple context binding | ||
var _ctx = function (fn, that, length) { | ||
_aFunction(fn); | ||
if (that === undefined) return fn; | ||
switch (length) { | ||
case 1: return function (a) { | ||
return fn.call(that, a); | ||
}; | ||
case 2: return function (a, b) { | ||
return fn.call(that, a, b); | ||
}; | ||
case 3: return function (a, b, c) { | ||
return fn.call(that, a, b, c); | ||
}; | ||
} | ||
return function (/* ...args */) { | ||
return fn.apply(that, arguments); | ||
}; | ||
}; | ||
var _isObject = function (it) { | ||
return typeof it === 'object' ? it !== null : typeof it === 'function'; | ||
}; | ||
var _anObject = function (it) { | ||
if (!_isObject(it)) throw TypeError(it + ' is not an object!'); | ||
return it; | ||
}; | ||
var _fails = function (exec) { | ||
try { | ||
return !!exec(); | ||
} catch (e) { | ||
return true; | ||
} | ||
}; | ||
// Thank's IE8 for his funny defineProperty | ||
var _descriptors = !_fails(function () { | ||
return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7; | ||
}); | ||
var document = _global.document; | ||
// typeof document.createElement is 'object' in old IE | ||
var is = _isObject(document) && _isObject(document.createElement); | ||
var _domCreate = function (it) { | ||
return is ? document.createElement(it) : {}; | ||
}; | ||
var _ie8DomDefine = !_descriptors && !_fails(function () { | ||
return Object.defineProperty(_domCreate('div'), 'a', { get: function () { return 7; } }).a != 7; | ||
}); | ||
// 7.1.1 ToPrimitive(input [, PreferredType]) | ||
// instead of the ES6 spec version, we didn't implement @@toPrimitive case | ||
// and the second argument - flag - preferred type is a string | ||
var _toPrimitive = function (it, S) { | ||
if (!_isObject(it)) return it; | ||
var fn, val; | ||
if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val; | ||
if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val; | ||
if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val; | ||
throw TypeError("Can't convert object to primitive value"); | ||
}; | ||
var dP = Object.defineProperty; | ||
var f = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) { | ||
_anObject(O); | ||
P = _toPrimitive(P, true); | ||
_anObject(Attributes); | ||
if (_ie8DomDefine) try { | ||
return dP(O, P, Attributes); | ||
} catch (e) { /* empty */ } | ||
if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!'); | ||
if ('value' in Attributes) O[P] = Attributes.value; | ||
return O; | ||
}; | ||
var _objectDp = { | ||
f: f | ||
}; | ||
var _propertyDesc = function (bitmap, value) { | ||
return { | ||
enumerable: !(bitmap & 1), | ||
configurable: !(bitmap & 2), | ||
writable: !(bitmap & 4), | ||
value: value | ||
}; | ||
}; | ||
var _hide = _descriptors ? function (object, key, value) { | ||
return _objectDp.f(object, key, _propertyDesc(1, value)); | ||
} : function (object, key, value) { | ||
object[key] = value; | ||
return object; | ||
}; | ||
var hasOwnProperty = {}.hasOwnProperty; | ||
var _has = function (it, key) { | ||
return hasOwnProperty.call(it, key); | ||
}; | ||
var PROTOTYPE = 'prototype'; | ||
var $export = function (type, name, source) { | ||
var IS_FORCED = type & $export.F; | ||
var IS_GLOBAL = type & $export.G; | ||
var IS_STATIC = type & $export.S; | ||
var IS_PROTO = type & $export.P; | ||
var IS_BIND = type & $export.B; | ||
var IS_WRAP = type & $export.W; | ||
var exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {}); | ||
var expProto = exports[PROTOTYPE]; | ||
var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] : (_global[name] || {})[PROTOTYPE]; | ||
var key, own, out; | ||
if (IS_GLOBAL) source = name; | ||
for (key in source) { | ||
// contains in native | ||
own = !IS_FORCED && target && target[key] !== undefined; | ||
if (own && _has(exports, key)) continue; | ||
// export native or passed | ||
out = own ? target[key] : source[key]; | ||
// prevent global pollution for namespaces | ||
exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] | ||
// bind timers to global for call from export context | ||
: IS_BIND && own ? _ctx(out, _global) | ||
// wrap global constructors for prevent change them in library | ||
: IS_WRAP && target[key] == out ? (function (C) { | ||
var F = function (a, b, c) { | ||
if (this instanceof C) { | ||
switch (arguments.length) { | ||
case 0: return new C(); | ||
case 1: return new C(a); | ||
case 2: return new C(a, b); | ||
} return new C(a, b, c); | ||
} return C.apply(this, arguments); | ||
}; | ||
F[PROTOTYPE] = C[PROTOTYPE]; | ||
return F; | ||
// make static versions for prototype methods | ||
})(out) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out; | ||
// export proto methods to core.%CONSTRUCTOR%.methods.%NAME% | ||
if (IS_PROTO) { | ||
(exports.virtual || (exports.virtual = {}))[key] = out; | ||
// export proto methods to core.%CONSTRUCTOR%.prototype.%NAME% | ||
if (type & $export.R && expProto && !expProto[key]) _hide(expProto, key, out); | ||
} | ||
} | ||
}; | ||
// type bitmap | ||
$export.F = 1; // forced | ||
$export.G = 2; // global | ||
$export.S = 4; // static | ||
$export.P = 8; // proto | ||
$export.B = 16; // bind | ||
$export.W = 32; // wrap | ||
$export.U = 64; // safe | ||
$export.R = 128; // real proto method for `library` | ||
var _export = $export; | ||
var toString = {}.toString; | ||
var _cof = function (it) { | ||
return toString.call(it).slice(8, -1); | ||
}; | ||
// fallback for non-array-like ES3 and non-enumerable old V8 strings | ||
// eslint-disable-next-line no-prototype-builtins | ||
var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function (it) { | ||
return _cof(it) == 'String' ? it.split('') : Object(it); | ||
}; | ||
// 7.2.1 RequireObjectCoercible(argument) | ||
var _defined = function (it) { | ||
if (it == undefined) throw TypeError("Can't call method on " + it); | ||
return it; | ||
}; | ||
// to indexed object, toObject with fallback for non-array-like ES3 strings | ||
var _toIobject = function (it) { | ||
return _iobject(_defined(it)); | ||
}; | ||
// 7.1.4 ToInteger | ||
var ceil = Math.ceil; | ||
var floor = Math.floor; | ||
var _toInteger = function (it) { | ||
return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); | ||
}; | ||
// 7.1.15 ToLength | ||
var min = Math.min; | ||
var _toLength = function (it) { | ||
return it > 0 ? min(_toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991 | ||
}; | ||
var max = Math.max; | ||
var min$1 = Math.min; | ||
var _toAbsoluteIndex = function (index, length) { | ||
index = _toInteger(index); | ||
return index < 0 ? max(index + length, 0) : min$1(index, length); | ||
}; | ||
// false -> Array#indexOf | ||
// true -> Array#includes | ||
var _arrayIncludes = function (IS_INCLUDES) { | ||
return function ($this, el, fromIndex) { | ||
var O = _toIobject($this); | ||
var length = _toLength(O.length); | ||
var index = _toAbsoluteIndex(fromIndex, length); | ||
var value; | ||
// Array#includes uses SameValueZero equality algorithm | ||
// eslint-disable-next-line no-self-compare | ||
if (IS_INCLUDES && el != el) while (length > index) { | ||
value = O[index++]; | ||
// eslint-disable-next-line no-self-compare | ||
if (value != value) return true; | ||
// Array#indexOf ignores holes, Array#includes - not | ||
} else for (;length > index; index++) if (IS_INCLUDES || index in O) { | ||
if (O[index] === el) return IS_INCLUDES || index || 0; | ||
} return !IS_INCLUDES && -1; | ||
}; | ||
}; | ||
var SHARED = '__core-js_shared__'; | ||
var store = _global[SHARED] || (_global[SHARED] = {}); | ||
var _shared = function (key) { | ||
return store[key] || (store[key] = {}); | ||
}; | ||
var id = 0; | ||
var px = Math.random(); | ||
var _uid = function (key) { | ||
return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); | ||
}; | ||
var shared = _shared('keys'); | ||
var _sharedKey = function (key) { | ||
return shared[key] || (shared[key] = _uid(key)); | ||
}; | ||
var arrayIndexOf = _arrayIncludes(false); | ||
var IE_PROTO = _sharedKey('IE_PROTO'); | ||
var _objectKeysInternal = function (object, names) { | ||
var O = _toIobject(object); | ||
var i = 0; | ||
var result = []; | ||
var key; | ||
for (key in O) if (key != IE_PROTO) _has(O, key) && result.push(key); | ||
// Don't enum bug & hidden keys | ||
while (names.length > i) if (_has(O, key = names[i++])) { | ||
~arrayIndexOf(result, key) || result.push(key); | ||
} | ||
return result; | ||
}; | ||
// IE 8- don't enum bug keys | ||
var _enumBugKeys = ( | ||
'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf' | ||
).split(','); | ||
// 19.1.2.14 / 15.2.3.14 Object.keys(O) | ||
var _objectKeys = Object.keys || function keys(O) { | ||
return _objectKeysInternal(O, _enumBugKeys); | ||
}; | ||
var f$1 = Object.getOwnPropertySymbols; | ||
var _objectGops = { | ||
f: f$1 | ||
}; | ||
var f$2 = {}.propertyIsEnumerable; | ||
var _objectPie = { | ||
f: f$2 | ||
}; | ||
// 7.1.13 ToObject(argument) | ||
var _toObject = function (it) { | ||
return Object(_defined(it)); | ||
}; | ||
// 19.1.2.1 Object.assign(target, source, ...) | ||
var $assign = Object.assign; | ||
// should work with symbols and should have deterministic property order (V8 bug) | ||
var _objectAssign = !$assign || _fails(function () { | ||
var A = {}; | ||
var B = {}; | ||
// eslint-disable-next-line no-undef | ||
var S = Symbol(); | ||
var K = 'abcdefghijklmnopqrst'; | ||
A[S] = 7; | ||
K.split('').forEach(function (k) { B[k] = k; }); | ||
return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K; | ||
}) ? function assign(target, source) { // eslint-disable-line no-unused-vars | ||
var T = _toObject(target); | ||
var aLen = arguments.length; | ||
var index = 1; | ||
var getSymbols = _objectGops.f; | ||
var isEnum = _objectPie.f; | ||
while (aLen > index) { | ||
var S = _iobject(arguments[index++]); | ||
var keys = getSymbols ? _objectKeys(S).concat(getSymbols(S)) : _objectKeys(S); | ||
var length = keys.length; | ||
var j = 0; | ||
var key; | ||
while (length > j) if (isEnum.call(S, key = keys[j++])) T[key] = S[key]; | ||
} return T; | ||
} : $assign; | ||
// 19.1.3.1 Object.assign(target, source) | ||
_export(_export.S + _export.F, 'Object', { assign: _objectAssign }); | ||
var assign = _core.Object.assign; | ||
var assign$1 = createCommonjsModule(function (module) { | ||
module.exports = { "default": assign, __esModule: true }; | ||
}); | ||
var _Object$assign = unwrapExports(assign$1); | ||
var DefaultConfig = { | ||
port: 3000, | ||
quiet: false, | ||
recordingsDir: 'recordings', | ||
apiNamespace: 'polly' | ||
}; | ||
function registerAPI(app, config) { | ||
config = _Object$assign({}, DefaultConfig, config); | ||
config.apiNamespace = path.join('/', config.apiNamespace); | ||
const router = express.Router(); | ||
const api = new API(config.recordingsDir); | ||
router.use(nocache()); | ||
router.get('/:recording/:entryId', function (req, res) { | ||
var _req$params = req.params; | ||
const recording = _req$params.recording, | ||
entryId = _req$params.entryId; | ||
const order = req.query.order; | ||
var _api$getRecordingEntr = api.getRecordingEntry(recording, entryId, order); | ||
const status = _api$getRecordingEntr.status, | ||
body = _api$getRecordingEntr.body; | ||
res.status(status); | ||
if (status === 200) { | ||
res.json(body); | ||
} else { | ||
res.end(); | ||
} | ||
}); | ||
router.get('/:recording', function (req, res) { | ||
const recording = req.params.recording; | ||
var _api$getRecording = api.getRecording(recording); | ||
const status = _api$getRecording.status, | ||
body = _api$getRecording.body; | ||
res.status(status); | ||
if (status === 200) { | ||
res.json(body); | ||
} else { | ||
res.end(); | ||
} | ||
}); | ||
router.post('/:recording', bodyParser.json({ limit: '50mb' }), function (req, res) { | ||
const recording = req.params.recording; | ||
var _api$saveRecording = api.saveRecording(recording, req.body); | ||
const status = _api$saveRecording.status, | ||
body = _api$saveRecording.body; | ||
res.status(status).send(body); | ||
}); | ||
router.delete('/:recording', function (req, res) { | ||
const recording = req.params.recording; | ||
var _api$deleteRecording = api.deleteRecording(recording); | ||
const status = _api$deleteRecording.status, | ||
body = _api$deleteRecording.body; | ||
res.status(status).send(body); | ||
}); | ||
app.use(config.apiNamespace, router); | ||
} | ||
class Server { | ||
constructor(config = {}) { | ||
this.config = _Object$assign({}, DefaultConfig, config); | ||
this.app = express(); | ||
if (!this.config.quiet) { | ||
this.app.use(morgan('dev')); | ||
} | ||
// Return 200 on root GET & HEAD to pass health checks | ||
this.app.get('/', (req, res) => res.sendStatus(200)); | ||
this.app.head('/', (req, res) => res.sendStatus(200)); | ||
registerAPI(this.app, { | ||
recordingsDir: this.config.recordingsDir, | ||
apiNamespace: this.config.apiNamespace | ||
}); | ||
} | ||
listen(port, host) { | ||
if (this.server) { | ||
return; | ||
} | ||
port = port || this.config.port; | ||
host = host || this.config.host; | ||
this.server = this.app.listen(port, host).on('listening', () => { | ||
console.log(`Listening on http://${host || 'localhost'}:${port}/\n`); | ||
}).on('error', e => { | ||
if (e.code === 'EADDRINUSE') { | ||
console.error(`Port ${port} already in use.`); | ||
process.exit(1); | ||
} else { | ||
console.error(e); | ||
} | ||
}); | ||
gracefulShutdown(this.server); | ||
return this.server; | ||
} | ||
} | ||
export { API, Server, DefaultConfig as Defaults, registerAPI as registerExpressAPI }; | ||
import fs from"fs-extra";import path from"path";import express from"express";import bodyParser from"body-parser";import nocache from"nocache";import morgan from"morgan";import gracefulShutdown from"http-graceful-shutdown";class API{constructor(e){this.recordingsDir=e}getRecordingEntry(e,t,r){const n=this.filenameFor(e);if(fs.existsSync(n)){const e=fs.readJsonSync(n).entries[t];if(e&&e[r])return this.respond(200,e[r])}return this.respond(204)}getRecording(e){const t=this.filenameFor(e);return fs.existsSync(t)?this.respond(200,fs.readJsonSync(t)):this.respond(204)}saveRecording(e,t){return fs.outputJsonSync(this.filenameFor(e),t,{spaces:2}),this.respond(201)}deleteRecording(e){const t=this.filenameFor(e);return fs.existsSync(t)&&fs.removeSync(t),this.respond(200)}filenameFor(e){return path.join(this.recordingsDir,e,"recording.json")}respond(e,t){return{status:e,body:t}}}function unwrapExports(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}var _global=createCommonjsModule(function(e){var t=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=t)}),_core=createCommonjsModule(function(e){var t=e.exports={version:"2.5.5"};"number"==typeof __e&&(__e=t)}),_core_1=_core.version,_aFunction=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e},_ctx=function(e,t,r){if(_aFunction(e),void 0===t)return e;switch(r){case 1:return function(r){return e.call(t,r)};case 2:return function(r,n){return e.call(t,r,n)};case 3:return function(r,n,o){return e.call(t,r,n,o)}}return function(){return e.apply(t,arguments)}},_isObject=function(e){return"object"==typeof e?null!==e:"function"==typeof e},_anObject=function(e){if(!_isObject(e))throw TypeError(e+" is not an object!");return e},_fails=function(e){try{return!!e()}catch(e){return!0}},_descriptors=!_fails(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a}),document=_global.document,is=_isObject(document)&&_isObject(document.createElement),_domCreate=function(e){return is?document.createElement(e):{}},_ie8DomDefine=!_descriptors&&!_fails(function(){return 7!=Object.defineProperty(_domCreate("div"),"a",{get:function(){return 7}}).a}),_toPrimitive=function(e,t){if(!_isObject(e))return e;var r,n;if(t&&"function"==typeof(r=e.toString)&&!_isObject(n=r.call(e)))return n;if("function"==typeof(r=e.valueOf)&&!_isObject(n=r.call(e)))return n;if(!t&&"function"==typeof(r=e.toString)&&!_isObject(n=r.call(e)))return n;throw TypeError("Can't convert object to primitive value")},dP=Object.defineProperty,f=_descriptors?Object.defineProperty:function(e,t,r){if(_anObject(e),t=_toPrimitive(t,!0),_anObject(r),_ie8DomDefine)try{return dP(e,t,r)}catch(e){}if("get"in r||"set"in r)throw TypeError("Accessors not supported!");return"value"in r&&(e[t]=r.value),e},_objectDp={f:f},_propertyDesc=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},_hide=_descriptors?function(e,t,r){return _objectDp.f(e,t,_propertyDesc(1,r))}:function(e,t,r){return e[t]=r,e},hasOwnProperty={}.hasOwnProperty,_has=function(e,t){return hasOwnProperty.call(e,t)},PROTOTYPE="prototype",$export=function(e,t,r){var n,o,s,i=e&$export.F,c=e&$export.G,a=e&$export.S,u=e&$export.P,f=e&$export.B,p=e&$export.W,l=c?_core:_core[t]||(_core[t]={}),d=l[PROTOTYPE],_=c?_global:a?_global[t]:(_global[t]||{})[PROTOTYPE];for(n in c&&(r=t),r)(o=!i&&_&&void 0!==_[n])&&_has(l,n)||(s=o?_[n]:r[n],l[n]=c&&"function"!=typeof _[n]?r[n]:f&&o?_ctx(s,_global):p&&_[n]==s?function(e){var t=function(t,r,n){if(this instanceof e){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,r)}return new e(t,r,n)}return e.apply(this,arguments)};return t[PROTOTYPE]=e[PROTOTYPE],t}(s):u&&"function"==typeof s?_ctx(Function.call,s):s,u&&((l.virtual||(l.virtual={}))[n]=s,e&$export.R&&d&&!d[n]&&_hide(d,n,s)))};$export.F=1,$export.G=2,$export.S=4,$export.P=8,$export.B=16,$export.W=32,$export.U=64,$export.R=128;var _export=$export,toString={}.toString,_cof=function(e){return toString.call(e).slice(8,-1)},_iobject=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==_cof(e)?e.split(""):Object(e)},_defined=function(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e},_toIobject=function(e){return _iobject(_defined(e))},ceil=Math.ceil,floor=Math.floor,_toInteger=function(e){return isNaN(e=+e)?0:(e>0?floor:ceil)(e)},min=Math.min,_toLength=function(e){return e>0?min(_toInteger(e),9007199254740991):0},max=Math.max,min$1=Math.min,_toAbsoluteIndex=function(e,t){return(e=_toInteger(e))<0?max(e+t,0):min$1(e,t)},_arrayIncludes=function(e){return function(t,r,n){var o,s=_toIobject(t),i=_toLength(s.length),c=_toAbsoluteIndex(n,i);if(e&&r!=r){for(;i>c;)if((o=s[c++])!=o)return!0}else for(;i>c;c++)if((e||c in s)&&s[c]===r)return e||c||0;return!e&&-1}},SHARED="__core-js_shared__",store=_global[SHARED]||(_global[SHARED]={}),_shared=function(e){return store[e]||(store[e]={})},id=0,px=Math.random(),_uid=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++id+px).toString(36))},shared=_shared("keys"),_sharedKey=function(e){return shared[e]||(shared[e]=_uid(e))},arrayIndexOf=_arrayIncludes(!1),IE_PROTO=_sharedKey("IE_PROTO"),_objectKeysInternal=function(e,t){var r,n=_toIobject(e),o=0,s=[];for(r in n)r!=IE_PROTO&&_has(n,r)&&s.push(r);for(;t.length>o;)_has(n,r=t[o++])&&(~arrayIndexOf(s,r)||s.push(r));return s},_enumBugKeys="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(","),_objectKeys=Object.keys||function(e){return _objectKeysInternal(e,_enumBugKeys)},f$1=Object.getOwnPropertySymbols,_objectGops={f:f$1},f$2={}.propertyIsEnumerable,_objectPie={f:f$2},_toObject=function(e){return Object(_defined(e))},$assign=Object.assign,_objectAssign=!$assign||_fails(function(){var e={},t={},r=Symbol(),n="abcdefghijklmnopqrst";return e[r]=7,n.split("").forEach(function(e){t[e]=e}),7!=$assign({},e)[r]||Object.keys($assign({},t)).join("")!=n})?function(e,t){for(var r=_toObject(e),n=arguments.length,o=1,s=_objectGops.f,i=_objectPie.f;n>o;)for(var c,a=_iobject(arguments[o++]),u=s?_objectKeys(a).concat(s(a)):_objectKeys(a),f=u.length,p=0;f>p;)i.call(a,c=u[p++])&&(r[c]=a[c]);return r}:$assign;_export(_export.S+_export.F,"Object",{assign:_objectAssign});var assign=_core.Object.assign,assign$1=createCommonjsModule(function(e){e.exports={default:assign,__esModule:!0}}),_Object$assign=unwrapExports(assign$1),DefaultConfig={port:3e3,quiet:!1,recordingsDir:"recordings",apiNamespace:"polly"};function registerAPI(e,t){(t=_Object$assign({},DefaultConfig,t)).apiNamespace=path.join("/",t.apiNamespace);const r=express.Router(),n=new API(t.recordingsDir);r.use(nocache()),r.get("/:recording/:entryId",function(e,t){var r=e.params;const o=r.recording,s=r.entryId,i=e.query.order;var c=n.getRecordingEntry(o,s,i);const a=c.status,u=c.body;t.status(a),200===a?t.json(u):t.end()}),r.get("/:recording",function(e,t){const r=e.params.recording;var o=n.getRecording(r);const s=o.status,i=o.body;t.status(s),200===s?t.json(i):t.end()}),r.post("/:recording",bodyParser.json({limit:"50mb"}),function(e,t){const r=e.params.recording;var o=n.saveRecording(r,e.body);const s=o.status,i=o.body;t.status(s).send(i)}),r.delete("/:recording",function(e,t){const r=e.params.recording;var o=n.deleteRecording(r);const s=o.status,i=o.body;t.status(s).send(i)}),e.use(t.apiNamespace,r)}class Server{constructor(e={}){this.config=_Object$assign({},DefaultConfig,e),this.app=express(),this.config.quiet||this.app.use(morgan("dev")),this.app.get("/",(e,t)=>t.sendStatus(200)),this.app.head("/",(e,t)=>t.sendStatus(200)),registerAPI(this.app,{recordingsDir:this.config.recordingsDir,apiNamespace:this.config.apiNamespace})}listen(e,t){if(!this.server)return e=e||this.config.port,t=t||this.config.host,this.server=this.app.listen(e,t).on("listening",()=>{console.log(`Listening on http://${t||"localhost"}:${e}/\n`)}).on("error",t=>{"EADDRINUSE"===t.code?(console.error(`Port ${e} already in use.`),process.exit(1)):console.error(t)}),gracefulShutdown(this.server),this.server}}export{API,Server,DefaultConfig as Defaults,registerAPI as registerExpressAPI}; | ||
//# sourceMappingURL=pollyjs-node-server.js.map |
{ | ||
"name": "@pollyjs/node-server", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Standalone node server and express integration for @pollyjs", | ||
@@ -43,4 +43,3 @@ "main": "dist/cjs/pollyjs-node-server.js", | ||
"test:clean": "", | ||
"lint": "eslint ./*.js src bin", | ||
"prepack": "NODE_ENV=production yarn build" | ||
"lint": "eslint ./*.js src bin" | ||
}, | ||
@@ -47,0 +46,0 @@ "dependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
95051
12
215
4
6