Skip to content

fix(script): .response.cookies.toObject() should return an object - #10307

Open
ihexxa wants to merge 1 commit into
developfrom
fix/script/cookies
Open

fix(script): .response.cookies.toObject() should return an object#10307
ihexxa wants to merge 1 commit into
developfrom
fix/script/cookies

Conversation

@ihexxa

@ihexxa ihexxa commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix .response.cookies.toObject() in scripts so it returns a proper { key: value } object instead of an array of raw cookie JSON blobs, matching Postman SDK semantics.
  • CookieList.toObject() (in packages/insomnia-scripting-environment/src/objects/cookies.ts) now overrides the base PropertyList.toObject() to build a Record<string, string> map from each cookie's key/value; CookieObject inherits the same fix since it extends CookieList.
  • Widened PropertyList.toObject()'s return type to Record<string, any> | Record<string, any>[] so subclasses can narrow to an object shape.

@ihexxa ihexxa self-assigned this Jul 28, 2026
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown

✅ Circular References Report

Generated at: 2026-08-04T07:51:27.219Z
Status: ✅ NO CHANGE

Summary

Metric Base (develop) PR Change
Total Circular References 9 9 0 (0.00%)
Click to view all circular references in PR (9)
insomnia-inso/src/db/models/types.ts -> insomnia-inso/src/db/types.ts
insomnia/src/main/prompt-bridge.ts -> insomnia/src/main/window-utils.ts -> insomnia/src/main/plugin-window.ts
insomnia/src/main/window-utils.ts -> insomnia/src/main/plugin-window.ts
insomnia/src/network/network.ts -> insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts
insomnia/src/ui/components/settings/import-export.tsx -> insomnia/src/ui/components/modals/export-requests-modal.tsx
insomnia/src/ui/components/tabs/tab-list.tsx -> insomnia/src/ui/components/tabs/tab.tsx
insomnia/src/ui/components/templating/tag-editor-arg-sub-form.tsx -> insomnia/src/ui/components/templating/external-vault/external-vault-form.tsx
insomnia/src/ui/components/viewers/response-viewer.tsx -> insomnia/src/ui/components/viewers/response-multipart-viewer.tsx
Click to view all circular references in base branch (9)
insomnia-inso/src/db/models/types.ts -> insomnia-inso/src/db/types.ts
insomnia/src/main/prompt-bridge.ts -> insomnia/src/main/window-utils.ts -> insomnia/src/main/plugin-window.ts
insomnia/src/main/window-utils.ts -> insomnia/src/main/plugin-window.ts
insomnia/src/network/network.ts -> insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts
insomnia/src/ui/components/settings/import-export.tsx -> insomnia/src/ui/components/modals/export-requests-modal.tsx
insomnia/src/ui/components/tabs/tab-list.tsx -> insomnia/src/ui/components/tabs/tab.tsx
insomnia/src/ui/components/templating/tag-editor-arg-sub-form.tsx -> insomnia/src/ui/components/templating/external-vault/external-vault-form.tsx
insomnia/src/ui/components/viewers/response-viewer.tsx -> insomnia/src/ui/components/viewers/response-multipart-viewer.tsx

Analysis

No Change: This PR does not introduce or remove any circular references.


This report was generated automatically by comparing against the develop branch.

@ihexxa
ihexxa force-pushed the fix/script/cookies branch 2 times, most recently from 71dff49 to 17c86b2 Compare July 31, 2026 07:34
@ihexxa
ihexxa force-pushed the fix/script/cookies branch from 17c86b2 to e0d8962 Compare August 4, 2026 07:46
@ihexxa
ihexxa marked this pull request as ready for review August 4, 2026 08:12
Copilot AI lite review requested due to automatic review settings August 4, 2026 08:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the scripting API for response cookies so .response.cookies.toObject() returns a { [key]: value } map (matching Postman SDK semantics) instead of an array of cookie JSON objects, and updates typing/tests to reflect the behavior.

Changes:

  • Updated PropertyList.toObject() typing to allow subclasses to return an object shape.
  • Implemented CookieList.toObject() to return a key/value map of cookie names to values (and inherited by CookieObject).
  • Added unit tests covering empty/non-empty cookie lists for toObject().

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/insomnia-scripting-environment/src/objects/properties.ts Widens PropertyList.toObject() return type to support object-returning overrides.
packages/insomnia-scripting-environment/src/objects/cookies.ts Overrides CookieList.toObject() to return a cookie name → value map.
packages/insomnia-scripting-environment/src/objects/tests/cookies.test.ts Adds tests asserting the new toObject() behavior for CookieList and CookieObject.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +213 to +226
const cookieObject = new CookieObject({
_id: '',
type: 'CookieJar',
parentId: '',
modified: 0,
created: 0,
isPrivate: false,
name: 'my jar',
cookies: [
{ id: '1', key: 'c1', value: 'v1', domain: 'inso.com' },
{ id: '2', key: 'c2', value: 'v2', domain: 'inso.com' },
],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any);
Comment on lines +191 to +197
override toObject(_excludeDisabled?: boolean, _caseSensitive?: boolean, _multiValue?: boolean, _sanitizeKeys?: boolean) {
const obj: Record<string, string> = {};
this.list.forEach(cookie => {
obj[cookie.key] = cookie.valueOf();
});
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants