@unofficialbox/box-open-sdk 0.4.2 → 0.4.3
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/dist/cjs/managers/avatars.js +2 -2
- package/dist/cjs/managers/uploads.js +6 -4
- package/dist/cjs/runtime.js +16 -10
- package/dist/esm/managers/avatars.js +2 -2
- package/dist/esm/managers/uploads.js +6 -4
- package/dist/esm/runtime.js +16 -10
- package/dist/types/runtime.d.ts +5 -1
- package/package.json +1 -1
|
@@ -58,8 +58,8 @@ class AvatarsManager {
|
|
|
58
58
|
url += '/' + (0, internal_js_1.pathEscape)(userId);
|
|
59
59
|
url += "/avatar";
|
|
60
60
|
let req = this.session.newRequest("POST", url);
|
|
61
|
-
const
|
|
62
|
-
req = runtime.withMultipartBody(req,
|
|
61
|
+
const fileBytes = new Uint8Array(await body.pic.arrayBuffer());
|
|
62
|
+
req = runtime.withMultipartBody(req, "", new Uint8Array(0), "pic", new runtime.Stream(fileBytes));
|
|
63
63
|
const resp = await this.session.fetch(req);
|
|
64
64
|
const data = runtime.responseBytes(resp);
|
|
65
65
|
return JSON.parse(new TextDecoder().decode(data));
|
|
@@ -59,8 +59,9 @@ class UploadsManager {
|
|
|
59
59
|
if (options["content-md5"] !== undefined) {
|
|
60
60
|
req = runtime.withHeader(req, "content-md5", options["content-md5"]);
|
|
61
61
|
}
|
|
62
|
-
const
|
|
63
|
-
|
|
62
|
+
const jsonBytes = new TextEncoder().encode(JSON.stringify(body.attributes));
|
|
63
|
+
const fileBytes = new Uint8Array(await body.file.arrayBuffer());
|
|
64
|
+
req = runtime.withMultipartBody(req, "attributes", jsonBytes, "file", new runtime.Stream(fileBytes));
|
|
64
65
|
const resp = await this.session.fetch(req);
|
|
65
66
|
const data = runtime.responseBytes(resp);
|
|
66
67
|
return JSON.parse(new TextDecoder().decode(data));
|
|
@@ -77,8 +78,9 @@ class UploadsManager {
|
|
|
77
78
|
if (options["content-md5"] !== undefined) {
|
|
78
79
|
req = runtime.withHeader(req, "content-md5", options["content-md5"]);
|
|
79
80
|
}
|
|
80
|
-
const
|
|
81
|
-
|
|
81
|
+
const jsonBytes = new TextEncoder().encode(JSON.stringify(body.attributes));
|
|
82
|
+
const fileBytes = new Uint8Array(await body.file.arrayBuffer());
|
|
83
|
+
req = runtime.withMultipartBody(req, "attributes", jsonBytes, "file", new runtime.Stream(fileBytes));
|
|
82
84
|
const resp = await this.session.fetch(req);
|
|
83
85
|
const data = runtime.responseBytes(resp);
|
|
84
86
|
return JSON.parse(new TextDecoder().decode(data));
|
package/dist/cjs/runtime.js
CHANGED
|
@@ -263,18 +263,24 @@ function withStreamBody(request, body, contentType) {
|
|
|
263
263
|
}
|
|
264
264
|
/** Return the request with a Box-style multipart body: an `attributes` JSON
|
|
265
265
|
* part plus a file part (G-7). */
|
|
266
|
-
|
|
266
|
+
/** Writes a JSON part named `jsonPartName` iff `jsonBytes` is non-empty, and
|
|
267
|
+
* a binary part named `filePartName` — used as both the form field name and
|
|
268
|
+
* the Content-Disposition filename, since the real filename isn't
|
|
269
|
+
* structurally knowable — iff `file` is non-empty (G-7). */
|
|
270
|
+
function withMultipartBody(request, jsonPartName, jsonBytes, filePartName, file) {
|
|
267
271
|
const boundary = `----gantryFormBoundary${Math.random().toString(36).slice(2)}`;
|
|
268
272
|
const encoder = new TextEncoder();
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
encoder.encode(
|
|
277
|
-
|
|
273
|
+
const parts = [];
|
|
274
|
+
if (jsonBytes.length > 0) {
|
|
275
|
+
const escaped = jsonPartName.replace(/["\r\n]/g, '_');
|
|
276
|
+
parts.push(encoder.encode(`--${boundary}\r\nContent-Disposition: form-data; name="${escaped}"\r\n\r\n`), jsonBytes, encoder.encode('\r\n'));
|
|
277
|
+
}
|
|
278
|
+
if (file.data.length > 0) {
|
|
279
|
+
const escaped = filePartName.replace(/["\r\n]/g, '_');
|
|
280
|
+
parts.push(encoder.encode(`--${boundary}\r\nContent-Disposition: form-data; name="${escaped}"; filename="${escaped}"\r\n` +
|
|
281
|
+
'Content-Type: application/octet-stream\r\n\r\n'), file.data, encoder.encode('\r\n'));
|
|
282
|
+
}
|
|
283
|
+
parts.push(encoder.encode(`--${boundary}--\r\n`));
|
|
278
284
|
request.headers.set('Content-Type', `multipart/form-data; boundary=${boundary}`);
|
|
279
285
|
request.body = concat(parts);
|
|
280
286
|
return request;
|
|
@@ -22,8 +22,8 @@ export class AvatarsManager {
|
|
|
22
22
|
url += '/' + pathEscape(userId);
|
|
23
23
|
url += "/avatar";
|
|
24
24
|
let req = this.session.newRequest("POST", url);
|
|
25
|
-
const
|
|
26
|
-
req = runtime.withMultipartBody(req,
|
|
25
|
+
const fileBytes = new Uint8Array(await body.pic.arrayBuffer());
|
|
26
|
+
req = runtime.withMultipartBody(req, "", new Uint8Array(0), "pic", new runtime.Stream(fileBytes));
|
|
27
27
|
const resp = await this.session.fetch(req);
|
|
28
28
|
const data = runtime.responseBytes(resp);
|
|
29
29
|
return JSON.parse(new TextDecoder().decode(data));
|
|
@@ -23,8 +23,9 @@ export class UploadsManager {
|
|
|
23
23
|
if (options["content-md5"] !== undefined) {
|
|
24
24
|
req = runtime.withHeader(req, "content-md5", options["content-md5"]);
|
|
25
25
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
26
|
+
const jsonBytes = new TextEncoder().encode(JSON.stringify(body.attributes));
|
|
27
|
+
const fileBytes = new Uint8Array(await body.file.arrayBuffer());
|
|
28
|
+
req = runtime.withMultipartBody(req, "attributes", jsonBytes, "file", new runtime.Stream(fileBytes));
|
|
28
29
|
const resp = await this.session.fetch(req);
|
|
29
30
|
const data = runtime.responseBytes(resp);
|
|
30
31
|
return JSON.parse(new TextDecoder().decode(data));
|
|
@@ -41,8 +42,9 @@ export class UploadsManager {
|
|
|
41
42
|
if (options["content-md5"] !== undefined) {
|
|
42
43
|
req = runtime.withHeader(req, "content-md5", options["content-md5"]);
|
|
43
44
|
}
|
|
44
|
-
const
|
|
45
|
-
|
|
45
|
+
const jsonBytes = new TextEncoder().encode(JSON.stringify(body.attributes));
|
|
46
|
+
const fileBytes = new Uint8Array(await body.file.arrayBuffer());
|
|
47
|
+
req = runtime.withMultipartBody(req, "attributes", jsonBytes, "file", new runtime.Stream(fileBytes));
|
|
46
48
|
const resp = await this.session.fetch(req);
|
|
47
49
|
const data = runtime.responseBytes(resp);
|
|
48
50
|
return JSON.parse(new TextDecoder().decode(data));
|
package/dist/esm/runtime.js
CHANGED
|
@@ -231,18 +231,24 @@ export function withStreamBody(request, body, contentType) {
|
|
|
231
231
|
}
|
|
232
232
|
/** Return the request with a Box-style multipart body: an `attributes` JSON
|
|
233
233
|
* part plus a file part (G-7). */
|
|
234
|
-
|
|
234
|
+
/** Writes a JSON part named `jsonPartName` iff `jsonBytes` is non-empty, and
|
|
235
|
+
* a binary part named `filePartName` — used as both the form field name and
|
|
236
|
+
* the Content-Disposition filename, since the real filename isn't
|
|
237
|
+
* structurally knowable — iff `file` is non-empty (G-7). */
|
|
238
|
+
export function withMultipartBody(request, jsonPartName, jsonBytes, filePartName, file) {
|
|
235
239
|
const boundary = `----gantryFormBoundary${Math.random().toString(36).slice(2)}`;
|
|
236
240
|
const encoder = new TextEncoder();
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
encoder.encode(
|
|
245
|
-
|
|
241
|
+
const parts = [];
|
|
242
|
+
if (jsonBytes.length > 0) {
|
|
243
|
+
const escaped = jsonPartName.replace(/["\r\n]/g, '_');
|
|
244
|
+
parts.push(encoder.encode(`--${boundary}\r\nContent-Disposition: form-data; name="${escaped}"\r\n\r\n`), jsonBytes, encoder.encode('\r\n'));
|
|
245
|
+
}
|
|
246
|
+
if (file.data.length > 0) {
|
|
247
|
+
const escaped = filePartName.replace(/["\r\n]/g, '_');
|
|
248
|
+
parts.push(encoder.encode(`--${boundary}\r\nContent-Disposition: form-data; name="${escaped}"; filename="${escaped}"\r\n` +
|
|
249
|
+
'Content-Type: application/octet-stream\r\n\r\n'), file.data, encoder.encode('\r\n'));
|
|
250
|
+
}
|
|
251
|
+
parts.push(encoder.encode(`--${boundary}--\r\n`));
|
|
246
252
|
request.headers.set('Content-Type', `multipart/form-data; boundary=${boundary}`);
|
|
247
253
|
request.body = concat(parts);
|
|
248
254
|
return request;
|
package/dist/types/runtime.d.ts
CHANGED
|
@@ -83,7 +83,11 @@ export declare function withFormBody(request: Request, form: Uint8Array): Reques
|
|
|
83
83
|
export declare function withStreamBody(request: Request, body: Stream, contentType: string): Request;
|
|
84
84
|
/** Return the request with a Box-style multipart body: an `attributes` JSON
|
|
85
85
|
* part plus a file part (G-7). */
|
|
86
|
-
|
|
86
|
+
/** Writes a JSON part named `jsonPartName` iff `jsonBytes` is non-empty, and
|
|
87
|
+
* a binary part named `filePartName` — used as both the form field name and
|
|
88
|
+
* the Content-Disposition filename, since the real filename isn't
|
|
89
|
+
* structurally knowable — iff `file` is non-empty (G-7). */
|
|
90
|
+
export declare function withMultipartBody(request: Request, jsonPartName: string, jsonBytes: Uint8Array, filePartName: string, file: Stream): Request;
|
|
87
91
|
/** Read the whole response body. */
|
|
88
92
|
export declare function responseBytes(response: Response): Uint8Array;
|
|
89
93
|
/** The response body as a stream, for binary downloads (FR-7.4). */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unofficialbox/box-open-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Box API client for TypeScript (open source, community, punk rock) — typed models, async managers, and a fetch runtime with retry, backoff, and token refresh.",
|
|
5
5
|
"keywords": ["box", "box-api", "sdk", "api-client", "typescript", "unofficial"],
|
|
6
6
|
"license": "MIT",
|