Skip to content

Commit

Permalink
fix: request options again
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpascal committed May 5, 2024
1 parent ab4ef05 commit 79c5850
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ const nools = require('./nools-utils');
const cache = new Map();

// Helper function to create request headers with session token (if available)
const withCookieSession = (options) => {
return Object.assign({}, options, {
headers: Object.assign({}, options.headers || {}, {
Cookie: nools.sessionTokenHeader(environment) || undefined
})
});
const withCookieSession = (...args) => {
const options = typeof args[0] === 'object' ? Object.assign({}, args[0]) : { url: args[0] };

if (args.length > 1) {
// Merge remaining arguments
Object.assign(options, ...args.slice(1));
}

const sessionTokenHeader = nools.sessionTokenHeader(environment);
if (sessionTokenHeader || options.headers) {
options.headers = Object.assign({}, options.headers || {}, sessionTokenHeader);
}

return options;
};

const _request = (method) => (...args) => {
Expand Down

0 comments on commit 79c5850

Please sign in to comment.