Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function importRaw(
getWorkspaceId: () => Promise,
rawContent: string,
): Promise<{
source: string,
error: Error | null,
summary: { [string]: Array },
}> {
let results;
try {
results = await convert(rawContent);
} catch (err) {
return {
source: 'not found',
error: err,
summary: {},
};
}
const { data } = results;
// Generate all the ids we may need
const generatedIds: { [string]: string | Function } = {};
for (const r of data.resources) {
for (const key of r._id.match(REPLACE_ID_REGEX) || []) {
generatedIds[key] = generateId(MODELS[r._type].prefix);
}
async _handleImport(text: string): Promise {
// Allow user to paste any import file into the url. If it results in
// only one item, it will overwrite the current request.
try {
const { data } = await importers.convert(text);
const { resources } = data;
const r = resources[0];
if (r && r._type === 'request' && this.props.activeRequest) {
// Only pull fields that we want to update
return this._handleForceUpdateRequest(this.props.activeRequest, {
url: r.url,
method: r.method,
headers: r.headers,
body: r.body,
authentication: r.authentication,
parameters: r.parameters,
});
}
} catch (e) {
// Import failed, that's alright
const resourceWrappers = curlCommands.map(c => {
return {
path: c.path,
resource: importers.convert(c.curl).data.resources[0]
}
});