@forge/bridge
5.12.1-next.0-experimental-1dcd5935.13.0-next.1
out/fetch/fetch.js~
out/fetch/fetch.jsModified+10−9
Index: package/out/fetch/fetch.js
===================================================================
--- package/out/fetch/fetch.js
+++ package/out/fetch/fetch.js
@@ -1,17 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.productFetchApi = exports.remoteFetchApi = void 0;
const blobParser_1 = require("../utils/blobParser");
-const parseFormData = async (form) => {
+const parseFormData = async (form, matchFilePrefix = false) => {
const parsed = {};
for (const [key, value] of form.entries()) {
- if (key === 'file') {
+ const isFileKey = matchFilePrefix ? key.startsWith('file') : key === 'file';
+ if (isFileKey) {
const fileName = value.name;
const fileType = value.type;
- parsed['file'] = await (0, blobParser_1.blobToBase64)(value);
- parsed['__fileName'] = fileName;
- parsed['__fileType'] = fileType;
+ parsed[key] = await (0, blobParser_1.blobToBase64)(value);
+ parsed[`__${key}Name`] = fileName;
+ parsed[`__${key}Type`] = fileType;
}
else {
parsed[key] = value;
}
@@ -28,11 +29,11 @@
return rest;
}
return init;
};
-const parseRequest = async (init) => {
+const parseRequest = async (fetchType, init) => {
const isFormData = (init === null || init === void 0 ? void 0 : init.body) instanceof FormData ? true : false;
- const requestBody = isFormData ? await parseFormData(init === null || init === void 0 ? void 0 : init.body) : init === null || init === void 0 ? void 0 : init.body;
+ const requestBody = isFormData ? await parseFormData(init === null || init === void 0 ? void 0 : init.body, fetchType === 'remote') : init === null || init === void 0 ? void 0 : init.body;
const req = new Request('', { body: requestBody, method: init === null || init === void 0 ? void 0 : init.method, headers: init === null || init === void 0 ? void 0 : init.headers });
const headers = Object.fromEntries(req.headers.entries());
const body = req.method !== 'GET' ? await req.text() : null;
return {
@@ -43,9 +44,9 @@
};
const remoteFetchApi = (callBridge) => {
const fetch = async (remoteKey, init) => {
const validatedInit = validateFetchOptions(init);
- const { body: requestBody, headers: requestHeaders, isMultipartFormData } = await parseRequest(validatedInit);
+ const { body: requestBody, headers: requestHeaders, isMultipartFormData } = await parseRequest('remote', validatedInit);
const fetchPayload = {
remoteKey,
fetchRequestInit: { ...validatedInit, body: requestBody, headers: [...requestHeaders.entries()] },
isMultipartFormData
@@ -61,9 +62,9 @@
exports.remoteFetchApi = remoteFetchApi;
const productFetchApi = (callBridge) => {
const fetch = async (product, restPath, init) => {
const validatedInit = validateFetchOptions(init);
- const { body: requestBody, headers: requestHeaders, isMultipartFormData } = await parseRequest(validatedInit);
+ const { body: requestBody, headers: requestHeaders, isMultipartFormData } = await parseRequest('product', validatedInit);
if (!requestHeaders.has('X-Atlassian-Token')) {
requestHeaders.set('X-Atlassian-Token', 'no-check');
}
const fetchPayload = {