mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-22 01:19:13 +01:00
33 lines
693 B
JavaScript
33 lines
693 B
JavaScript
export function pluginHookImport(contents) {
|
|
let parsed;
|
|
try {
|
|
parsed = JSON.parse(contents);
|
|
} catch (err) {
|
|
return undefined;
|
|
}
|
|
|
|
if (!isJSObject(parsed)) {
|
|
return undefined;
|
|
}
|
|
|
|
if (!('yaakSchema' in parsed)) {
|
|
return;
|
|
}
|
|
|
|
// Migrate v1 to v2 -- changes requests to httpRequests
|
|
if (parsed.yaakSchema === 1) {
|
|
parsed.resources.httpRequests = parsed.resources.requests;
|
|
parsed.yaakSchema = 2;
|
|
}
|
|
|
|
if (parsed.yaakSchema === 2) {
|
|
return { resources: parsed.resources }; // Should already be in the correct format
|
|
}
|
|
|
|
return undefined;
|
|
}
|
|
|
|
export function isJSObject(obj) {
|
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
}
|