@forge/bridge
7.2.2-next.0-experimental-1e956967.3.0-next.4
out/fetch/fetch.js~
out/fetch/fetch.jsModified+18−5
Index: package/out/fetch/fetch.js
===================================================================
--- package/out/fetch/fetch.js
+++ package/out/fetch/fetch.js
@@ -70,10 +70,22 @@
requestRemote: (remoteKey, fetchOptions) => fetch(remoteKey, fetchOptions)
};
};
exports.remoteFetchApi = remoteFetchApi;
+const validateRequestTarget = (target) => {
+ const restPath = typeof target === 'string' ? target : target === null || target === void 0 ? void 0 : target.path;
+ const contextAri = typeof target === 'string' ? undefined : target === null || target === void 0 ? void 0 : target.contextAri;
+ if (!restPath || typeof restPath !== 'string') {
+ throw new Error('Request target must be a path string or an object with a non-empty `path` string.');
+ }
+ if (contextAri !== undefined && (typeof contextAri !== 'string' || !contextAri.startsWith('ari:'))) {
+ throw new Error(`Invalid contextAri '${String(contextAri)}'. Expected an ARI such as 'ari:cloud:jira::site/<cloudId>'.`);
+ }
+ return { restPath, contextAri };
+};
const productFetchApi = (callBridge) => {
- const fetch = async (product, restPath, init) => {
+ const fetch = async (product, target, init) => {
+ const { restPath, contextAri } = validateRequestTarget(target);
const validatedInit = validateFetchOptions(init);
const { body: requestBody, headers: requestHeaders, isMultipartFormData } = await parseRequest('product', validatedInit);
// https://ecosystem.atlassian.net/browse/BUILD-1118 Skip xsrf check for oauth request
if (!requestHeaders.has('X-Atlassian-Token')) {
@@ -86,17 +98,18 @@
...validatedInit,
body: requestBody,
headers: [...requestHeaders.entries()]
},
- isMultipartFormData
+ isMultipartFormData,
+ ...(contextAri !== undefined ? { contextAri } : {})
};
const { body, headers, statusText, status, isAttachment } = await callBridge('fetchProduct', fetchPayload);
const responseBody = isAttachment ? (0, blobParser_1.base64ToBlob)(body, headers['content-type']) : body;
return new Response(responseBody || null, { headers, status, statusText });
};
return {
- requestConfluence: (restPath, fetchOptions) => fetch('confluence', restPath, fetchOptions),
- requestJira: (restPath, fetchOptions) => fetch('jira', restPath, fetchOptions),
- requestBitbucket: (restPath, fetchOptions) => fetch('bitbucket', restPath, fetchOptions)
+ requestConfluence: (target, fetchOptions) => fetch('confluence', target, fetchOptions),
+ requestJira: (target, fetchOptions) => fetch('jira', target, fetchOptions),
+ requestBitbucket: (target, fetchOptions) => fetch('bitbucket', target, fetchOptions)
};
};
exports.productFetchApi = productFetchApi;