@forge/bridge 2.5.6-next.1 → 2.6.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/out/fetch/fetch.d.ts.map +1 -1
- package/out/fetch/fetch.js +31 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @forge/bridge
|
|
2
2
|
|
|
3
|
+
## 2.6.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 139a2cc: Fix support for uploading attachments via product fetch APIs
|
|
8
|
+
|
|
9
|
+
## 2.5.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 23a21ec: Bumping dependencies via Renovate:
|
|
14
|
+
|
|
15
|
+
- portfinder
|
|
16
|
+
|
|
17
|
+
- 97b57e7: Bumping dependencies via Renovate:
|
|
18
|
+
|
|
19
|
+
- unzipper
|
|
20
|
+
- @types/unzipper
|
|
21
|
+
|
|
3
22
|
## 2.5.6-next.1
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/out/fetch/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AA4D1C,eAAO,MAAM,eAAe,eAAgB,WAAW,oBAAoB,CAAC;kCAwB1C,MAAM,iBAAiB,WAAW,KAAG,QAAQ,QAAQ,CAAC;4BAG5D,MAAM,iBAAiB,WAAW,KAAG,QAAQ,QAAQ,CAAC;CAGjF,CAAC"}
|
package/out/fetch/fetch.js
CHANGED
|
@@ -2,25 +2,51 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.productFetchApi = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const toBase64 = (file) => new Promise((resolve, reject) => {
|
|
6
|
+
const reader = new FileReader();
|
|
7
|
+
reader.readAsDataURL(file);
|
|
8
|
+
reader.onload = () => resolve(reader.result);
|
|
9
|
+
reader.onerror = (error) => reject(error);
|
|
10
|
+
});
|
|
11
|
+
const parseFormData = (form) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
const parsed = {};
|
|
13
|
+
for (const [key, value] of form.entries()) {
|
|
14
|
+
if (key === 'file') {
|
|
15
|
+
const fileName = value.name;
|
|
16
|
+
const fileType = value.type;
|
|
17
|
+
parsed['file'] = yield toBase64(value);
|
|
18
|
+
parsed['__fileName'] = fileName;
|
|
19
|
+
parsed['__fileType'] = fileType;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
parsed[key] = value;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return JSON.stringify(parsed);
|
|
26
|
+
});
|
|
5
27
|
const parseBodyAndHeaders = (init) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
28
|
+
const isFormData = (init === null || init === void 0 ? void 0 : init.body) instanceof FormData ? true : false;
|
|
29
|
+
const requestBody = isFormData ? yield parseFormData(init === null || init === void 0 ? void 0 : init.body) : init === null || init === void 0 ? void 0 : init.body;
|
|
30
|
+
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 });
|
|
8
31
|
const headers = Object.fromEntries(req.headers.entries());
|
|
32
|
+
const body = req.method !== 'GET' ? yield req.text() : null;
|
|
9
33
|
return {
|
|
10
34
|
body,
|
|
11
|
-
headers: new Headers(headers)
|
|
35
|
+
headers: new Headers(headers),
|
|
36
|
+
isMultipartFormData: isFormData
|
|
12
37
|
};
|
|
13
38
|
});
|
|
14
39
|
const productFetchApi = (callBridge) => {
|
|
15
40
|
const fetch = (product, restPath, init) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const { body: requestBody, headers: requestHeaders } = yield parseBodyAndHeaders(init);
|
|
41
|
+
const { body: requestBody, headers: requestHeaders, isMultipartFormData } = yield parseBodyAndHeaders(init);
|
|
17
42
|
if (!requestHeaders.has('X-Atlassian-Token')) {
|
|
18
43
|
requestHeaders.set('X-Atlassian-Token', 'no-check');
|
|
19
44
|
}
|
|
20
45
|
const fetchPayload = {
|
|
21
46
|
product,
|
|
22
47
|
restPath,
|
|
23
|
-
fetchRequestInit: Object.assign(Object.assign({}, init), { body: requestBody, headers: [...requestHeaders.entries()] })
|
|
48
|
+
fetchRequestInit: Object.assign(Object.assign({}, init), { body: requestBody, headers: [...requestHeaders.entries()] }),
|
|
49
|
+
isMultipartFormData
|
|
24
50
|
};
|
|
25
51
|
const { body, headers, statusText, status } = yield callBridge('fetchProduct', fetchPayload);
|
|
26
52
|
return new Response(body || null, { headers, status, statusText });
|