mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-05-19 14:17:10 +02:00
Initial "plugin" system with importer (#7)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Import an Insomnia environment object.
|
||||
* @param {Object} e - The environment object to import.
|
||||
*/
|
||||
export function importEnvironment(e) {
|
||||
if (e.parentId.startsWith('env_')) {
|
||||
return null;
|
||||
}
|
||||
console.log('IMPORTING Environment', e._id, e.name, JSON.stringify(e, null, 2));
|
||||
return {
|
||||
id: e._id,
|
||||
createdAt: new Date(e.created ?? Date.now()).toISOString().replace('Z', ''),
|
||||
updatedAt: new Date(e.updated ?? Date.now()).toISOString().replace('Z', ''),
|
||||
workspaceId: e.parentId,
|
||||
model: 'environment',
|
||||
name: e.name,
|
||||
variables: Object.entries(e.data).map(([name, value]) => ({
|
||||
enabled: true,
|
||||
name,
|
||||
value: `${value}`,
|
||||
})),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Import an Insomnia request object.
|
||||
* @param {Object} r - The request object to import.
|
||||
* @param {number} sortPriority - The sort priority to use for the request.
|
||||
*/
|
||||
export function importRequest(r, sortPriority = 0) {
|
||||
console.log('IMPORTING REQUEST', r._id, r.name, JSON.stringify(r, null, 2));
|
||||
return {
|
||||
id: r._id,
|
||||
createdAt: new Date(r.created ?? Date.now()).toISOString().replace('Z', ''),
|
||||
updatedAt: new Date(r.updated ?? Date.now()).toISOString().replace('Z', ''),
|
||||
workspaceId: r.parentId,
|
||||
model: 'http_request',
|
||||
sortPriority,
|
||||
name: r.name,
|
||||
url: r.url,
|
||||
body: null, // TODO: Import body
|
||||
bodyType: null,
|
||||
authentication: {}, // TODO: Import authentication
|
||||
authenticationType: null,
|
||||
method: r.method,
|
||||
headers: (r.headers ?? []).map(({ name, value, disabled }) => ({
|
||||
enabled: !disabled,
|
||||
name,
|
||||
value,
|
||||
})),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Import an Insomnia workspace object.
|
||||
* @param {Object} w - The workspace object to import.
|
||||
*/
|
||||
export function importWorkspace(w) {
|
||||
console.log('IMPORTING Workpace', w._id, w.name, JSON.stringify(w, null, 2));
|
||||
return {
|
||||
id: w._id,
|
||||
createdAt: new Date(w.created ?? Date.now()).toISOString().replace('Z', ''),
|
||||
updatedAt: new Date(w.updated ?? Date.now()).toISOString().replace('Z', ''),
|
||||
model: 'workspace',
|
||||
name: w.name,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user