get options() { return { ...(this.defaultOptions || {}), ...((this.polly.config.adapterOptions || {})[this.constructor.id] || {}) }; }
export default function isExpired(recordedOn, expiresIn) { if (recordedOn && expiresIn) { return ( new Date() > new Date(new Date(recordedOn).getTime() + dehumanizeTime(expiresIn)) ); } return false; }
export default function normalizeRecordedResponse(response) { const { status, statusText, headers, content } = response; return { statusText, statusCode: status, headers: normalizeHeaders(headers), body: content && content.text, isBinary: Boolean(content && content._isBinary) }; }
async findRecording(recordingId) { const response = await this.ajax(`/${encodeURIComponent(recordingId)}`, { Accept: 'application/json; charset=utf-8' }); return this._normalize(response); }
export default function buildUrl(...paths) { const url = new URL( paths .map(p => p && (p + '').trim()) // Trim each string .filter(Boolean) // Remove empty strings or other falsy paths .join('/') ); // Replace 2+ consecutive slashes with 1. (e.g. `///` --> `/`) url.set('pathname', url.pathname.replace(/\/{2,}/g, '/')); return url.href; }
saveRecording(recordingId, data) { /* Pass the data through the base persister's stringify method so the output will be consistent with the rest of the persisters. */ this.api.saveRecording(recordingId, parse(this.stringify(data))); }
logError(request, error) { this.groupStart(request.recordingName); console.group(`Errored ➞ ${request.method} ${request.url}`); console.error(error); console.log('Request:', request); if (request.didRespond) { console.log('Response:', request.response); } console.log('Identifiers:', request.identifiers); console.groupEnd(); }
export function headers(headers, config, req) { const normalizedHeaders = new HTTPHeaders(headers); if (isFunction(config)) { return config(normalizedHeaders, req); } if (isObjectLike(config) && isArray(config.exclude)) { config.exclude.forEach(header => delete normalizedHeaders[header]); } return normalizedHeaders; }
static register(Factory) { if (!FACTORY_REGISTRATION.has(Factory)) { FACTORY_REGISTRATION.set(Factory, container => container.register(Factory) ); } this.on('register', FACTORY_REGISTRATION.get(Factory)); return this; }