@forge/bridge
Advanced tools
Comparing version 2.5.6 to 2.6.0-next.0
# @forge/bridge | ||
## 2.6.0-next.0 | ||
### Minor Changes | ||
- 139a2cc: Fix support for uploading attachments via product fetch APIs | ||
## 2.5.6 | ||
@@ -4,0 +10,0 @@ |
@@ -5,9 +5,34 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const toBase64 = (file) => new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
reader.readAsDataURL(file); | ||
reader.onload = () => resolve(reader.result); | ||
reader.onerror = (error) => reject(error); | ||
}); | ||
const parseFormData = (form) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const parsed = {}; | ||
for (const [key, value] of form.entries()) { | ||
if (key === 'file') { | ||
const fileName = value.name; | ||
const fileType = value.type; | ||
parsed['file'] = yield toBase64(value); | ||
parsed['__fileName'] = fileName; | ||
parsed['__fileType'] = fileType; | ||
} | ||
else { | ||
parsed[key] = value; | ||
} | ||
} | ||
return JSON.stringify(parsed); | ||
}); | ||
const parseBodyAndHeaders = (init) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const req = new Request('', { body: init === null || init === void 0 ? void 0 : init.body, method: init === null || init === void 0 ? void 0 : init.method, headers: init === null || init === void 0 ? void 0 : init.headers }); | ||
const isFormData = (init === null || init === void 0 ? void 0 : init.body) instanceof FormData ? true : false; | ||
const requestBody = isFormData ? yield parseFormData(init === null || init === void 0 ? void 0 : init.body) : 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' ? yield req.text() : null; | ||
const headers = Object.fromEntries(req.headers.entries()); | ||
return { | ||
body, | ||
headers: new Headers(headers) | ||
headers: new Headers(headers), | ||
isMultipartFormData: isFormData | ||
}; | ||
@@ -17,3 +42,3 @@ }); | ||
const fetch = (product, restPath, init) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { body: requestBody, headers: requestHeaders } = yield parseBodyAndHeaders(init); | ||
const { body: requestBody, headers: requestHeaders, isMultipartFormData } = yield parseBodyAndHeaders(init); | ||
if (!requestHeaders.has('X-Atlassian-Token')) { | ||
@@ -25,3 +50,4 @@ requestHeaders.set('X-Atlassian-Token', 'no-check'); | ||
restPath, | ||
fetchRequestInit: Object.assign(Object.assign({}, init), { body: requestBody, headers: [...requestHeaders.entries()] }) | ||
fetchRequestInit: Object.assign(Object.assign({}, init), { body: requestBody, headers: [...requestHeaders.entries()] }), | ||
isMultipartFormData | ||
}; | ||
@@ -28,0 +54,0 @@ const { body, headers, statusText, status } = yield callBridge('fetchProduct', fetchPayload); |
{ | ||
"name": "@forge/bridge", | ||
"version": "2.5.6", | ||
"version": "2.6.0-next.0", | ||
"description": "Forge bridge API for custom UI apps", | ||
@@ -5,0 +5,0 @@ "author": "Atlassian", |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
36350
476
2