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
34.17k stars 1.92k forks source link

plugin used to set a variable is forgotten #5878

Open jerry-sileon opened 1 year ago

jerry-sileon commented 1 year ago

Expected Behavior

When using a plugin like DateAdd (I am writing a variant IsoDateTimeAdd without using moment.js, and used the Generate Plugin button), I can create a variable in the environment. The Edit Tag dialog shows up and my IsoDateTimeAdd is in the Function To Perform select box. The live preview shows up nicely. When I click OK, the environment JSON shows like I defined in the plugin: image

Actual Behavior

But when I close the environment modal and open it again, the JSON shows this: image

The calling of the plugin just disappears.

Reproduction Steps

No response

Is there an existing issue for this?

Additional Information

My (partial) main.js file:

function getIsoDateString(y, m, d, h, i, s, z){
    let d1 = new Date();
    let d2 = new Date(d1.setFullYear(d1.getFullYear() + y));
    let d3 = new Date(d2.setMonth(d2.getMonth() + m));
    let d4 = new Date(d3.setDate(d3.getDate() + d));
    let d5 = new Date(d4.setHours(d4.getHours() + z));
    let d6 = new Date(d5.setMinutes(d5.getMinutes() + z));
    let d7 = new Date(d6.setSeconds(d6.getSeconds() + z));
    let d8 = new Date(d7.setMilliseconds(d7.getMilliseconds() + z));
    return d8.toISOString();
}

module.exports.templateTags = [{
    name: 'IsoDateTimeAdd',
    displayName: 'IsoDateTimeAdd',
    description: 'Provides an ISO date/time string with addition to the current date/time.',
    args: [
        {
            displayName: 'Years to add',
            description: 'The years to add to the date.',
            type: 'number',
            defaultValue: 0
        },
// ...
        {
            displayName: 'Milliseconds to add',
            description: 'The milliseconds to add to the date.',
            type: 'number',
            defaultValue: 0
        }
    ],
    async run (context, y, m, d, h, i, s, z) {
        return getIsoDateString(y, m, d, h, i, s, z);
    },
    liveDisplayName (context) {
        let values = context.map(c => c.value);
        return "DateAdd (" + getIsoDateString(...values) + ")";
    }
}];

Any idea? I must be missing something really simple...

Thanks!

Version: Insomnia 2023.1.0 Build date: 2023-03-09 OS: Windows_NT x64 10.0.22621 Electron: 22.0.0 Node: 16.17.1 V8: 10.8.168.20-electron.0 Architecture: x64

Insomnia Version

2023.1.0

What operating system are you using?

Windows

Operating System Version

Windows 11 Business 22H2

Installation method

forgot, probably MS Store

Last Known Working Insomnia version

No response

jerry-sileon commented 1 year ago

I get more and different errors when using environment variables, like one is not saved in the base env but it is saved in the sub envs. Weird.