npm package diff
Package: @forge/api
Versions: 3.9.2-next.0-experimental-c7a7d36 - 3.8.1-experimental-204139e
File: package/out/api/fetch.js
Index: package/out/api/fetch.js
===================================================================
--- package/out/api/fetch.js
+++ package/out/api/fetch.js
@@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
-exports.getSandboxRuntimeAPI = exports.getNodeRuntimeAPI = exports.addMagicAgent = exports.handleProxyResponseErrors = exports.getForgeProxyError = exports.createRemoteUrlWithPath = exports.fetchRemote = exports.__fetchProduct = void 0;
+exports.getSandboxRuntimeAPI = exports.getNodeRuntimeAPI = exports.addMagicAgent = exports.handleProxyResponseErrors = exports.getForgeProxyError = exports.createRemoteUrlWithPath = exports.fetchRemote = exports.fetchProduct = void 0;
const tslib_1 = require("tslib");
const node_fetch_1 = tslib_1.__importStar(require("node-fetch"));
const _1 = require(".");
const runtime_1 = require("./runtime");
@@ -17,20 +17,21 @@
finally {
timer.stop();
}
}
-function __fetchProduct(args) {
+function fetchProduct(args) {
return async (path, init) => {
const url = productURL(args.remote, path);
init = (0, exports.addMagicAgent)(init);
- const defaultHeaders = getDefaultHeaders(init.headers, args);
- init.headers = { ...init.headers, ...defaultHeaders };
+ if (!hasAuthorizationHeader(init.headers)) {
+ init.headers = { ...init.headers, authorization: `Forge ${args.provider}` };
+ }
const response = await (0, node_fetch_1.default)(url, init);
(0, exports.handleProxyResponseErrors)(response);
return response;
};
}
-exports.__fetchProduct = __fetchProduct;
+exports.fetchProduct = fetchProduct;
function fetchRemote(args) {
return async (path, init) => {
const remoteUrl = createRemoteUrlWithPath(`https://${args.remote}`, path);
init = (0, exports.addMagicAgent)(init, 'EXTERNAL_AUTH_REQUEST');
@@ -83,18 +84,12 @@
throw new errors_1.ProxyRequestError(response.status, errorReason);
}
};
exports.handleProxyResponseErrors = handleProxyResponseErrors;
-const getDefaultHeaders = (headersInit, args) => {
- let defaultHeaders = {};
- const headers = new node_fetch_1.Headers(headersInit);
- if (!headers.has('Content-Type')) {
- defaultHeaders = { 'Content-Type': 'application/json' };
- }
- if (!headers.has('authorization')) {
- defaultHeaders = { ...defaultHeaders, authorization: `Forge ${args.provider}` };
- }
- return defaultHeaders;
+const hasAuthorizationHeader = (headersInit) => {
+ if (!headersInit)
+ return false;
+ return new node_fetch_1.Headers(headersInit).has('authorization');
};
function productURL(remote, path) {
if (!path.startsWith('/')) {
path = '/' + path;
@@ -168,25 +163,25 @@
};
function getNodeRuntimeAPI() {
return {
fetch: (0, _1.wrapWithRouteUnwrapper)(node_fetch_1.default),
- requestJira: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'none', remote: 'jira' })),
- requestConfluence: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'none', remote: 'confluence' })),
- requestBitbucket: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'none', remote: 'bitbucket' })),
+ requestJira: (0, _1.wrapRequestProduct)(fetchProduct({ provider: 'none', remote: 'jira' })),
+ requestConfluence: (0, _1.wrapRequestProduct)(fetchProduct({ provider: 'none', remote: 'confluence' })),
+ requestBitbucket: (0, _1.wrapRequestProduct)(fetchProduct({ provider: 'none', remote: 'bitbucket' })),
asUser: () => ({
- requestJira: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'user', remote: 'jira' })),
- requestConfluence: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'user', remote: 'confluence' })),
- requestBitbucket: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'user', remote: 'bitbucket' })),
- requestGraph: (0, _1.wrapRequestGraph)(__fetchProduct({ provider: 'user', remote: 'stargate' })),
- requestConnectedData: (0, _1.wrapRequestConnectedData)(__fetchProduct({ provider: 'user', remote: 'stargate' })),
+ requestJira: (0, _1.wrapRequestProduct)(fetchProduct({ provider: 'user', remote: 'jira' })),
+ requestConfluence: (0, _1.wrapRequestProduct)(fetchProduct({ provider: 'user', remote: 'confluence' })),
+ requestBitbucket: (0, _1.wrapRequestProduct)(fetchProduct({ provider: 'user', remote: 'bitbucket' })),
+ requestGraph: (0, _1.wrapRequestGraph)(fetchProduct({ provider: 'user', remote: 'stargate' })),
+ requestConnectedData: (0, _1.wrapRequestConnectedData)(fetchProduct({ provider: 'user', remote: 'stargate' })),
withProvider
}),
asApp: () => ({
- requestJira: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'app', remote: 'jira' })),
- requestConfluence: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'app', remote: 'confluence' })),
- requestBitbucket: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'app', remote: 'bitbucket' })),
- requestGraph: (0, _1.wrapRequestGraph)(__fetchProduct({ provider: 'app', remote: 'stargate' })),
- requestConnectedData: (0, _1.wrapRequestConnectedData)(__fetchProduct({ provider: 'app', remote: 'stargate' }))
+ requestJira: (0, _1.wrapRequestProduct)(fetchProduct({ provider: 'app', remote: 'jira' })),
+ requestConfluence: (0, _1.wrapRequestProduct)(fetchProduct({ provider: 'app', remote: 'confluence' })),
+ requestBitbucket: (0, _1.wrapRequestProduct)(fetchProduct({ provider: 'app', remote: 'bitbucket' })),
+ requestGraph: (0, _1.wrapRequestGraph)(fetchProduct({ provider: 'app', remote: 'stargate' })),
+ requestConnectedData: (0, _1.wrapRequestConnectedData)(fetchProduct({ provider: 'app', remote: 'stargate' }))
})
};
}
exports.getNodeRuntimeAPI = getNodeRuntimeAPI;