Socket
Socket
Sign inDemoInstall

@adobe/fetch

Package Overview
Dependencies
Maintainers
57
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adobe/fetch - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

72

index.js

@@ -50,50 +50,65 @@ /*

function addHeaders(token, options, predefinedHeaders) {
let headers = {};
for (let name in predefinedHeaders) {
const value = predefinedHeaders[name];
headers[name.toLowerCase()] = typeof value === 'function' ? value() : value;
}
if (options.headers) {
if (typeof options.headers.entries === 'function') {
function normalizeHeaders(headers) {
let normalized = {};
if (headers) {
if (typeof headers.entries === 'function') {
// This is a headers object, iterate with for..of.
for (let pair of options.headers.entries()) {
for (let pair of headers.entries()) {
const [name, value] = pair;
headers[name.toLowerCase()] = value;
normalized[name.toLowerCase()] = value;
}
} else {
// This is a normal JSON. Iterate with for.. in
for (let name in options.headers) {
headers[name.toLowerCase()] = options.headers[name];
for (let name in headers) {
normalized[name.toLowerCase()] = headers[name];
}
}
}
return normalized;
}
function calculateHeaders(predefinedHeaders) {
let headers = {};
for (let name in predefinedHeaders) {
const value = predefinedHeaders[name];
if (typeof value === 'function') {
headers[name] = value();
} else {
headers[name] = value;
}
}
return headers;
}
function getHeaders(token, options, predefinedHeaders) {
let headers = calculateHeaders(predefinedHeaders);
if (options && options.headers) {
headers = Object.assign(headers, normalizeHeaders(options.headers));
}
headers.authorization = `${capFirst(token.token_type)} ${token.access_token}`;
options.headers = headers;
return options;
return headers;
}
async function _fetch(url, options, configOptions, tokenCache, forceNewToken) {
async function _fetch(url, opts, configOptions, tokenCache, forceNewToken) {
const token = await getToken(configOptions.auth, tokenCache, forceNewToken);
const opts = addHeaders(token, options, configOptions.headers);
const fetchOpts = Object.assign({}, opts);
fetchOpts.headers = getHeaders(token, opts, configOptions.headers);
debug(
`${opts.method || 'GET'} ${url} - x-request-id: ${
opts.headers['x-request-id']
`${fetchOpts.method || 'GET'} ${url} - x-request-id: ${
fetchOpts.headers['x-request-id']
}`
);
const res = await fetch(url, opts);
const res = await fetch(url, fetchOpts);
if (!res.ok) {
debug(
`${opts.method || 'GET'} ${url} - status ${res.statusText} (${
`${fetchOpts.method || 'GET'} ${url} - status ${res.statusText} (${
res.status
}). x-request-id: ${opts.headers['x-request-id']}`
}). x-request-id: ${fetchOpts.headers['x-request-id']}`
);
if ((res.status === 401 || res.status === 403) && !forceNewToken) {
debug(`${opts.method || 'GET'} ${url} - Will get new token.`);
return await _fetch(url, options, configOptions, tokenCache, true);
return await _fetch(url, opts, configOptions, tokenCache, true);
}

@@ -166,3 +181,2 @@ }

const tokenCache = cache.config(configOptions.auth);
configOptions.headers = configOptions.headers || {};
configOptions.headers = Object.assign(

@@ -174,3 +188,3 @@ {

},
configOptions.headers
normalizeHeaders(configOptions.headers)
);

@@ -182,2 +196,6 @@

module.exports = { config: config };
module.exports = {
config: config,
normalizeHeaders: normalizeHeaders,
generateRequestID: generateRequestID
};
{
"name": "@adobe/fetch",
"version": "0.2.3",
"version": "0.2.4",
"description": "Call Adobe APIs",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc