Kong / insomnia

The open-source, cross-platform API client for GraphQL, REST, WebSockets, SSE and gRPC. With Cloud, Local and Git storage.
https://insomnia.rest
Apache License 2.0
33.63k stars 1.88k forks source link

Import through context.data.import.raw() creates new workspace instead of importing on the current workspace #7457

Open victoraugustofd opened 1 month ago

victoraugustofd commented 1 month ago

Expected Behavior

Following the documentation, data context import function can receive an argument of type ImportOptions, which has an id corresponding to the workspace that the import should be executed at.

Actual Behavior

Even if I pass a valid workspaceId on the ImportOptions argument, the import occurs, but it creates a new workspace instead of importing the contents on the actual workspace.

Reproduction Steps

  1. Create a plugin with minimal code in index.js eg:

    module.exports.workspaceActions = [
    {
        label: 'Pull from GIT',
        icon: 'fa-arrow-down',
        action: async (context, data) => {
            const impFilename = 'example.json';
            if (!fs.existsSync(impFilename)) {
                context.app.alert('Error importing',
                    'Seems example.json is not existing!');
                return false;
            }
    
            fs.readFile(impFilename, "utf8", function (err, fileContent) {
                context.data.import.raw(fileContent, {
                    workspaceId: data.workspace._id,
                });
            });
        },
    }
    ];
  2. Use example.json eg. with the following content:
    {
    "_type": "export",
    "__export_format": 4,
    "__export_date": "2023-07-09T17:27:43.046Z",
    "__export_source": "insomnia.desktop.app:v2023.4.0",
    "resources": [
    {
      "_id": "req_44dcc4a6c60b42b4b91cf8888a2d9b1b",
      "parentId": "__WORKSPACE_ID__",
      "modified": "1637671845661",
      "created": 1688992190875,
      "url": "https://google.de",
      "name": "New Request",
      "description": "",
      "method": "GET",
      "body": {},
      "parameters": [],
      "headers": [],
      "authentication": {},
      "metaSortKey": -1688992190875,
      "isPrivate": false,
      "settingStoreCookies": true,
      "settingSendCookies": true,
      "settingDisableRenderRequestBody": false,
      "settingEncodeUrl": true,
      "settingRebuildPath": true,
      "settingFollowRedirects": "global",
      "_type": "request"
    },
    {
      "_id": "__WORKSPACE_ID__",
      "parentId": null,
      "modified": "1637671845661",
      "created": 1688992188630,
      "name": "My Collection",
      "description": "",
      "scope": "collection",
      "_type": "workspace"
    },
    {
      "_id": "__BASE_ENVIRONMENT_ID__",
      "parentId": "__WORKSPACE_ID__",
      "modified": "1637671845661",
      "created": 1688992188636,
      "name": "Base Environment",
      "data": {
        "url": "https://google.de"
      },
      "dataPropertyOrder": {
        "&": [
          "url"
        ]
      },
      "color": null,
      "isPrivate": false,
      "metaSortKey": 1688992188636,
      "_type": "environment"
    }
    ]
    }
  3. Try to import it. The ImportOptions were removed so it is not possible anymore to send a workspaceId. This basically switches the import of workspaces to import of projects and breaks many plugins: #6044

Credits to @sebastiande for the code snippets for reproduction steps.

Is there an existing issue for this?

Additional Information

I don't think this should be the expected behaviour, or the documentation should be updated as it leads developers to assume that this behaviour is what was going to happen. On my case, I am developing an internal plugin for the company that I work, and this is a blocker that I could not imagine when I was studying what the Insomnia plugins are capable of. This was already discussed at #6125, however I don't think that the main issue was understood, since "sync" features started being discussed on the thread, even though the discussion was about importing contents of an exported collection/design document on the current workspace. Also, I searched on the source code of Insomnia and did not find any occurrence of the string "ImportOptions" on the code, which make me think this is a deprecated feature and the documentation is outdated. Is it correct to assume any of this or is this a known issue that is already under fix from Insomnia team collaborators?

Thanks in advance.

Insomnia Version

2023.5.5

What operating system are you using?

Windows

Operating System Version

Microsoft Windows 11 Pro

Installation method

download from insomnia

Last Known Working Insomnia version

No response

victoraugustofd commented 1 month ago

I was reviewing this PR #6044 as already mentioned and confirmed that the ImportOptions do not exist anymore and creating a new workspace is the expected behaviour. I thought on creating a PR to change this, however I would like to know for what purpose this was removed from the code, since it removes a great import feature and perhaps there is a reason behind it and a PR returning this feature to the code would be pointless. Also, the documentation is confirmed to be outdated as well, leading to misunderstanding.

victoraugustofd commented 1 month ago

I just sent a PR to update the documentation: #insomnia-docs/pull/207.