npm package diff
Package: @forge/api
Versions: 5.1.0-next.5 - 5.1.0-next.5-experimental-edac07a
File: package/out/api/fetch.js
Index: package/out/api/fetch.js
===================================================================
--- package/out/api/fetch.js
+++ package/out/api/fetch.js
@@ -1,9 +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;
-const tslib_1 = require("tslib");
-const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
+exports.getSandboxRuntimeAPI = exports.getNodeRuntimeAPI = exports.addMagicAgent = exports.handleProxyResponseErrors = exports.getForgeProxyError = exports.fetchRemote = exports.__fetchProduct = void 0;
const _1 = require(".");
const runtime_1 = require("./runtime");
const polyfill_response_1 = require("./polyfill-response");
const errors_1 = require("./errors");
@@ -17,65 +15,33 @@
finally {
timer.stop();
}
}
-function __fetchProduct(args, useUndici = false) {
+function __fetchProduct(args) {
return async (path, init) => {
- let response;
- if (useUndici && global.__forge_fetch__) {
- response = await global.__forge_fetch__({
- type: 'fpp',
- provider: args.provider,
- remote: args.remote
- }, path, init);
- }
- else {
- const url = productURL(args.remote, path);
- init = (0, exports.addMagicAgent)(init);
- const defaultHeaders = getDefaultHeaders(init.headers, args);
- init.headers = { ...init.headers, ...defaultHeaders };
- response = await (0, node_fetch_1.default)(url, init);
- }
+ const response = await global.__forge_fetch__({
+ type: args.type,
+ provider: args.provider,
+ remote: args.remote
+ }, path, init);
(0, exports.handleProxyResponseErrors)(response);
return response;
};
}
exports.__fetchProduct = __fetchProduct;
function fetchRemote(args) {
return async (path, init) => {
- let response;
- if (global.__forge_fetch__) {
- response = await global.__forge_fetch__({
- type: 'tpp',
- provider: args.provider,
- remote: args.remote,
- accountId: args.account
- }, path, init);
- }
- else {
- const remoteUrl = createRemoteUrlWithPath(`https://${args.remote}`, path);
- init = (0, exports.addMagicAgent)(init, 'EXTERNAL_AUTH_REQUEST');
- init.headers = {
- ...init.headers,
- authorization: `Forge user ${args.provider} ${args.account}`
- };
- response = await (0, node_fetch_1.default)(remoteUrl, init);
- }
+ const response = await global.__forge_fetch__({
+ type: 'tpp',
+ provider: args.provider,
+ remote: args.remote,
+ accountId: args.account
+ }, path, init);
(0, exports.handleProxyResponseErrors)(response);
return response;
};
}
exports.fetchRemote = fetchRemote;
-function createRemoteUrlWithPath(baseUrl, path) {
- const remoteUrl = new URL(baseUrl);
- const url = new URL(path, remoteUrl);
- if (url.hostname !== remoteUrl.hostname) {
- throw new Error(`Invalid path provided ${path}`);
- }
- remoteUrl.searchParams.append('path', path);
- return remoteUrl;
-}
-exports.createRemoteUrlWithPath = createRemoteUrlWithPath;
function getDefaultRemote(provider) {
const externalAuthProvider = findExternalAuthProviderConfigOrThrow(provider);
if (!externalAuthProvider.remotes.length) {
throw new Error(`Missing remote config for provider ${provider}`);
@@ -104,25 +70,8 @@
throw new errors_1.ProxyRequestError(response.status, errorReason);
}
};
exports.handleProxyResponseErrors = handleProxyResponseErrors;
-const getDefaultHeaders = (headersInit, args) => {
- let defaultHeaders = {};
- const headers = new Headers(headersInit);
- if (!headers.has('Content-Type')) {
- defaultHeaders = { 'Content-Type': 'application/json' };
- }
- if (!headers.has('authorization')) {
- defaultHeaders = { ...defaultHeaders, authorization: `Forge ${args.provider}` };
- }
- return defaultHeaders;
-};
-function productURL(remote, path) {
- if (!path.startsWith('/')) {
- path = '/' + path;
- }
- return `https://${remote}${path}`;
-}
function lazyThrowNeedsAuthenticationError(serviceKey) {
return async (scopes) => wrapInMetrics({ name: 'api.asUser.withProvider.requestCredentials', tags: { passingScopes: String(!!scopes) } }, async () => {
throw new errors_1.NeedsAuthenticationError('Authentication Required', serviceKey, { scopes, isExpectedError: true });
});
@@ -194,25 +143,25 @@
};
}
return {
fetch: (0, _1.wrapWithRouteUnwrapper)(fetch),
- requestJira: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'none', remote: 'jira' }, true)),
- requestConfluence: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'none', remote: 'confluence' }, true)),
- requestBitbucket: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'none', remote: 'bitbucket' }, true)),
+ requestJira: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'none', remote: 'jira', type: 'fpp' })),
+ requestConfluence: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'none', remote: 'confluence', type: 'fpp' })),
+ requestBitbucket: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'none', remote: 'bitbucket', type: 'fpp' })),
asUser: () => ({
- requestJira: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'user', remote: 'jira' }, true)),
- requestConfluence: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'user', remote: 'confluence' }, true)),
- requestBitbucket: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'user', remote: 'bitbucket' }, true)),
- requestGraph: (0, _1.wrapRequestGraph)(__fetchProduct({ provider: 'user', remote: 'stargate' }, true)),
- requestConnectedData: (0, _1.wrapRequestConnectedData)(__fetchProduct({ provider: 'user', remote: 'stargate' }, true)),
+ requestJira: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'user', remote: 'jira', type: 'fpp' })),
+ requestConfluence: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'user', remote: 'confluence', type: 'fpp' })),
+ requestBitbucket: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'user', remote: 'bitbucket', type: 'fpp' })),
+ requestGraph: (0, _1.wrapRequestGraph)(__fetchProduct({ provider: 'user', remote: 'stargate', type: 'fpp' })),
+ requestConnectedData: (0, _1.wrapRequestConnectedData)(__fetchProduct({ provider: 'user', remote: 'stargate', type: 'fpp' })),
withProvider
}),
asApp: () => ({
- requestJira: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'app', remote: 'jira' }, true)),
- requestConfluence: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'app', remote: 'confluence' }, true)),
- requestBitbucket: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'app', remote: 'bitbucket' }, true)),
- requestGraph: (0, _1.wrapRequestGraph)(__fetchProduct({ provider: 'app', remote: 'stargate' }, true)),
- requestConnectedData: (0, _1.wrapRequestConnectedData)(__fetchProduct({ provider: 'app', remote: 'stargate' }, true))
+ requestJira: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'app', remote: 'jira', type: 'fpp' })),
+ requestConfluence: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'app', remote: 'confluence', type: 'fpp' })),
+ requestBitbucket: (0, _1.wrapRequestProduct)(__fetchProduct({ provider: 'app', remote: 'bitbucket', type: 'fpp' })),
+ requestGraph: (0, _1.wrapRequestGraph)(__fetchProduct({ provider: 'app', remote: 'stargate', type: 'fpp' })),
+ requestConnectedData: (0, _1.wrapRequestConnectedData)(__fetchProduct({ provider: 'app', remote: 'stargate', type: 'fpp' }))
})
};
}
exports.getNodeRuntimeAPI = getNodeRuntimeAPI;