Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(() => {
try {
const dataTree = JSON.parse(data);
if (!dataTree.version && !dataTree.mocks && !dataTree.groups) {
resolve({ success: false, error: 'Unsupported format' });
return;
}
const migratedDataTree = migrateData(dataTree);
Mocks.mergeMocks(migratedDataTree.mocks || [], options);
Groups.mergeGroups(migratedDataTree.groups || []);
Emitter.emit(EVENTS.IMPORT);
} catch (error) {
if (__ENV === 'development') {
console.log('Import error', error);
}
resolve({ success: false, error: error.message });
}
resolve({ success: true });
});
}
removeGroup(groupId) {
Groups.removeGroup(groupId);
Emitter.emit(EVENTS.UPDATE_GROUP);
}
if (mockId) {
request.mock = API.mocks.filter((mock) => mock.id === mockId)[0];
}
if (API.mode === 'remote') {
Emitter.emit(EVENTS.MIMIC_WEB_WORKER_CAPTURE, { request, response });
}
Requests.capture(request, response);
Emitter.emit(EVENTS.REQUEST_CAPTURED, { requestId: request.id });
}
if (messageType === WORKER_MESSAGE_TYPES.MIMIC_EMIT_EVENT) {
event.stopImmediatePropagation();
Emitter.emit(event.data.payload.eventType, event.data.payload.args);
}
});
addMock() {
const newMock = Mocks.addMock();
Emitter.emit(EVENTS.ADD_MOCK);
return newMock;
}
updateMock(mockId, request) {
Mocks.updateMock(mockId, request);
Emitter.emit(EVENTS.UPDATE_MOCK);
}
function onSetData(message) {
Mocks.setMocks(message.payload);
Emitter.emit(EVENTS.UPDATE_MOCK);
}
.then((data) => {
Object.assign(dataTree, data);
Emitter.emit(EVENTS.STORAGE_PERSIST);
Emitter.emit(EVENTS.STORAGE_READY);
});
}
function setResponse(message) {
const { request, response } = message.payload;
Requests.setResponse(request.id, response, request.startTime);
Emitter.emit(EVENTS.RESPONSE_RECEIVED, { requestId: request.id });
}
updateGroup(groupId, group) {
Groups.updateGroup(groupId, group);
Emitter.emit(EVENTS.UPDATE_GROUP);
}
static capturePending(request) {
const capturedRequest = new Request({
id: request.id,
method: request.method,
url: request.url,
params: request.body || request.params,
headers: request.headers,
origin: request.origin,
response: null,
startTime: request.startTime
});
capturedRequests.push(capturedRequest);
Emitter.emit(EVENTS.REQUEST_CAPTURED, { requestId: request.id });
}