Skip to content

Commit 8ae5770

Browse files
committed
Fix requests not being sent in Insomnia v11
1 parent 9501431 commit 8ae5770

File tree

4 files changed

+109
-79
lines changed

4 files changed

+109
-79
lines changed

CHANGELOG.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,65 @@
1+
# v1.5.1
2+
3+
**Date:** 2025/08/28
4+
5+
### Bugfixes
6+
7+
- Get the plugin to work with Insomnia v11
8+
(see [#19](https://github.com/jreyesr/insomnia-plugin-batch-requests/issues/19))
9+
10+
# v1.5.0
11+
12+
**Date:** 2024/06/12
13+
14+
### New features
15+
16+
- Add a new template tag that can send different files on each request
17+
118
# v1.4.0
219

320
**Date:** 2024/05/22
421

522
### New features
623

7-
- Add a way to read outputs (that will be written back to the CSV) from the response's headers, status code and request time, in addition to the response body as JSON ([#13](https://github.com/jreyesr/insomnia-plugin-batch-requests/pull/13))
24+
- Add a way to read outputs (that will be written back to the CSV) from the response's headers, status code and request
25+
time, in addition to the response body as
26+
JSON ([#13](https://github.com/jreyesr/insomnia-plugin-batch-requests/pull/13))
827

928
# v1.3.0
1029

1130
**Date:** 2024/01/20
1231

1332
### New features
1433

15-
- Add the ability to send requests in parallel, with configurable parallelism ([#11](https://github.com/jreyesr/insomnia-plugin-batch-requests/pull/11))
34+
- Add the ability to send requests in parallel, with configurable
35+
parallelism ([#11](https://github.com/jreyesr/insomnia-plugin-batch-requests/pull/11))
1636

1737
# v1.2.0
1838

1939
**Date:** 2023/03/21
2040

2141
### New features
2242

23-
- Add a configuration option to set default delay for all requests ([#7](https://github.com/jreyesr/insomnia-plugin-batch-requests/pull/7))
43+
- Add a configuration option to set default delay for all
44+
requests ([#7](https://github.com/jreyesr/insomnia-plugin-batch-requests/pull/7))
2445

2546
# v1.1.1
2647

2748
**Date:** 2023/03/21
2849

2950
### Bugfixes
3051

31-
- Fix plugin freezing after sending the first request when response isn't valid JSON ([#4](https://github.com/jreyesr/insomnia-plugin-batch-requests/issues/4))
52+
- Fix plugin freezing after sending the first request when response isn't valid
53+
JSON ([#4](https://github.com/jreyesr/insomnia-plugin-batch-requests/issues/4))
3254

3355
# v1.1.0
3456

3557
**Date:** 2023/03/18
3658

3759
### New features
3860

39-
- Added a configuration option to set a delay between consecutive requests ([#1](https://github.com/jreyesr/insomnia-plugin-batch-requests/issues/1))
61+
- Added a configuration option to set a delay between consecutive
62+
requests ([#1](https://github.com/jreyesr/insomnia-plugin-batch-requests/issues/1))
4063

4164
# v1.0.1
4265

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Since `v1.2.0`, there is a Global Configuration dialog in which you can select a
152152
9. To run tests, run `npm run test`
153153
10. Make commit.
154154
11. GOTO 6
155-
12. Update the package version in `package.json`.
155+
12. Update the package version in `package.json` and add a new entry on `CHANGELOG.md`
156156
13. When done, submit a PR and merge it. If releasing a new version, see [the next section](#releasing).
157157

158158
## Releasing

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"repository": {
66
"url": "https://github.com/jreyesr/insomnia-plugin-batch-requests"
77
},
8-
"version": "1.5.0",
8+
"version": "1.5.1",
99
"author": {
1010
"name": "jreyesr",
1111
"url": "https://github.com/jreyesr"

tags.js

Lines changed: 79 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,88 @@
11
export const MAGIC_FILE_FIELD_PREFIX = "%INSOMNIA_PLUGIN_BATCH_REQUESTS%"
22

3-
export const templateTags = [{
4-
name: 'batchVariable',
5-
displayName: 'Batch',
6-
liveDisplayName: ([colName, sample]) => (colName.value ? `CSV[${colName.value}]: ${sample.value}` : 'Batch'),
7-
description: 'Placeholder for the Batch Requests plugin',
8-
args: [
9-
{
10-
displayName: 'Name',
11-
description: 'Ensure that this value matches the name of a column in your CSV file',
12-
type: 'string',
13-
validate: (val) => (val ? '' : 'Enter a column name!'),
14-
},
15-
{
16-
displayName: 'Sample value',
17-
description: 'This value will be used when sending the request manually (outside of Batch Requests)',
18-
type: 'string'
3+
function getInfo(context, name) {
4+
// Old Insomnia (pre-v11?): getExtraInfo(key) => extraInfo.find(v => v.name === key).value
5+
// New Insomnia (>= v11): getExtraInfo() => extraInfo
6+
// we always pass (see utils.js) an array with value [{name: "batchExtraData", value: JSON.stringify(...)}]
7+
8+
const extraData = context.context.getExtraInfo("batchExtraData") // param will be ignored by new Insomnia
9+
if (extraData) {
10+
console.debug('[store.get]', extraData);
11+
if (Array.isArray(extraData)) {
12+
// new Insomnia versions, they pass extra data as-is so we need to manually find the proper key-val object
13+
return JSON.parse(extraData.find(x => x.name === "batchExtraData").value)[name];
14+
} else {
15+
// old Insomnia versions, they've already picked out the correct item from the array
16+
return JSON.parse(extraData)[name]
1917
}
20-
],
21-
async run(context, name, sample) {
22-
// context.renderPurpose is set to 'send' when actually sending the request
23-
if(context.renderPurpose === 'send') {
24-
const extraData = context.context.getExtraInfo("batchExtraData")
25-
if(extraData) {
26-
console.debug('[store.get]', extraData);
27-
return JSON.parse(extraData)[name];
18+
} else {
19+
console.error(`Cannot find column ${name} on request extra data! Falling back to sample value.`);
20+
return undefined;
21+
}
22+
}
23+
24+
export const templateTags = [
25+
{
26+
name: 'batchVariable',
27+
displayName: 'Batch',
28+
liveDisplayName: ([colName, sample]) => (colName.value ? `CSV[${colName.value}]: ${sample.value}` : 'Batch'),
29+
description: 'Placeholder for the Batch Requests plugin',
30+
args: [
31+
{
32+
displayName: 'Name',
33+
description: 'Ensure that this value matches the name of a column in your CSV file',
34+
type: 'string',
35+
validate: (val) => (val ? '' : 'Enter a column name!'),
36+
},
37+
{
38+
displayName: 'Sample value',
39+
description: 'This value will be used when sending the request manually (outside of Batch Requests)',
40+
type: 'string'
41+
}
42+
],
43+
async run(context, name, sample) {
44+
// context.renderPurpose is set to 'send' when actually sending the request
45+
if (context.renderPurpose === 'send') {
46+
return getInfo(context, name) ?? sample
2847
} else {
29-
console.error(`Cannot find column ${name} on request extra data! Falling back to sample value.`);
48+
// context.renderPurpose is undefined when previewing the template tag's value
3049
return sample;
3150
}
32-
} else {
33-
// context.renderPurpose is undefined when previewing the template tag's value
34-
return sample;
35-
}
36-
},
37-
},
38-
/*
39-
When set on a Text field in a form body, this template tag will replace itself with the value
40-
"%INSOMNIA_PLUGIN_BATCH_REQUESTS%<field in CSV column>"
41-
This will be set by Insomnia as the (text) value of the field.
42-
Then, as the request is going out, it'll be intercepted by a Request hook (see main.js),
43-
which will strip the prefix and force the field to be interpreted as a File, rather than pure text,
44-
as if a user had selected a file to begin with, in the Insomnia UI
45-
*/
46-
{
47-
name: 'batchFile',
48-
displayName: 'Batch (File)',
49-
liveDisplayName: ([colName, sample]) => (colName.value ? `CSV[${colName.value}] as File: ${sample.value}` : 'Batch (File)'),
50-
description: 'Placeholder for the Batch Requests plugin',
51-
args: [
52-
{
53-
displayName: 'Name',
54-
description: 'Ensure that this value matches the name of a column in your CSV file',
55-
type: 'string',
56-
validate: (val) => (val ? '' : 'Enter a column name!'),
5751
},
58-
{
59-
displayName: 'Sample value',
60-
description: 'This value will be used when sending the request manually (outside of Batch Requests)',
61-
type: 'string'
62-
}
63-
],
64-
async run(context, name, sample) {
65-
// context.renderPurpose is set to 'send' when actually sending the request
66-
if(context.renderPurpose === 'send') {
67-
const extraData = context.context.getExtraInfo("batchExtraData")
68-
if(extraData) {
69-
console.debug('[store.get]', extraData);
70-
// Magic marker so we can later (in a request hook) identify these fields and mangle them
71-
return MAGIC_FILE_FIELD_PREFIX + JSON.parse(extraData)[name];
52+
},
53+
/*
54+
When set on a Text field in a form body, this template tag will replace itself with the value
55+
"%INSOMNIA_PLUGIN_BATCH_REQUESTS%<field in CSV column>"
56+
This will be set by Insomnia as the (text) value of the field.
57+
Then, as the request is going out, it'll be intercepted by a Request hook (see main.js),
58+
which will strip the prefix and force the field to be interpreted as a File, rather than pure text,
59+
as if a user had selected a file to begin with, in the Insomnia UI
60+
*/
61+
{
62+
name: 'batchFile',
63+
displayName: 'Batch (File)',
64+
liveDisplayName: ([colName, sample]) => (colName.value ? `CSV[${colName.value}] as File: ${sample.value}` : 'Batch (File)'),
65+
description: 'Placeholder for the Batch Requests plugin',
66+
args: [
67+
{
68+
displayName: 'Name',
69+
description: 'Ensure that this value matches the name of a column in your CSV file',
70+
type: 'string',
71+
validate: (val) => (val ? '' : 'Enter a column name!'),
72+
},
73+
{
74+
displayName: 'Sample value',
75+
description: 'This value will be used when sending the request manually (outside of Batch Requests)',
76+
type: 'string'
77+
}
78+
],
79+
async run(context, name, sample) {
80+
// context.renderPurpose is set to 'send' when actually sending the request
81+
if (context.renderPurpose === 'send') {
82+
return MAGIC_FILE_FIELD_PREFIX + (getInfo(context, name) ?? sample)
7283
} else {
73-
console.error(`Cannot find column ${name} on request extra data! Falling back to sample value.`);
74-
return MAGIC_FILE_FIELD_PREFIX + sample;
84+
// context.renderPurpose is undefined when previewing the template tag's value
85+
return "[File contents of " + sample + "]";
7586
}
76-
} else {
77-
// context.renderPurpose is undefined when previewing the template tag's value
78-
return "[File contents of " + sample + "]";
79-
}
80-
},
81-
}]
87+
},
88+
}]

0 commit comments

Comments
 (0)