@bikefinder/sdk 0.33.0 → 0.33.1
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/README.md +6 -1
- package/dist/index.js +15 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,9 +88,10 @@ helper sends JPEG bytes directly to private staging storage, then asks the API
|
|
|
88
88
|
to sanitize and publish the image:
|
|
89
89
|
|
|
90
90
|
```ts
|
|
91
|
+
const requestId = crypto.randomUUID();
|
|
91
92
|
const result = await client.uploadPhoto({
|
|
92
93
|
deviceId,
|
|
93
|
-
requestId
|
|
94
|
+
requestId,
|
|
94
95
|
kind: "bike",
|
|
95
96
|
body: jpegBlob,
|
|
96
97
|
});
|
|
@@ -100,6 +101,10 @@ const download = await client.api.trackers.photos.download({
|
|
|
100
101
|
});
|
|
101
102
|
```
|
|
102
103
|
|
|
104
|
+
If the upload gets no storage response, the helper asks the API to verify and
|
|
105
|
+
complete the original upload. If the call still fails, keep the same request ID
|
|
106
|
+
and JPEG bytes when retrying.
|
|
107
|
+
|
|
103
108
|
Uploads are limited to 10 MiB. Download URLs expire after two minutes; request a
|
|
104
109
|
fresh reference if one expires. Photo bytes do not travel over WebSockets.
|
|
105
110
|
Runtime schemas are available from `@bikefinder/sdk/schemas`.
|
package/dist/index.js
CHANGED
|
@@ -333,6 +333,7 @@ async function uploadPhoto(uploads, input, fetch = globalThis.fetch) {
|
|
|
333
333
|
},
|
|
334
334
|
{ signal: input.signal }
|
|
335
335
|
);
|
|
336
|
+
input.signal?.throwIfAborted();
|
|
336
337
|
if (session.status === "published") return { photoId: session.photoId };
|
|
337
338
|
if (Date.parse(session.expiresAt) <= Date.now())
|
|
338
339
|
throw new Error(
|
|
@@ -345,15 +346,20 @@ async function uploadPhoto(uploads, input, fetch = globalThis.fetch) {
|
|
|
345
346
|
throw new TypeError(
|
|
346
347
|
"The photo upload session targets an unexpected storage endpoint."
|
|
347
348
|
);
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
349
|
+
let uploaded;
|
|
350
|
+
try {
|
|
351
|
+
uploaded = await fetch(url, {
|
|
352
|
+
method: "PUT",
|
|
353
|
+
body: input.body,
|
|
354
|
+
credentials: "omit",
|
|
355
|
+
redirect: "error",
|
|
356
|
+
signal: input.signal,
|
|
357
|
+
headers: session.headers
|
|
358
|
+
});
|
|
359
|
+
} catch {
|
|
360
|
+
}
|
|
361
|
+
input.signal?.throwIfAborted();
|
|
362
|
+
if (uploaded && !uploaded.ok && uploaded.status !== 412)
|
|
357
363
|
throw new Error(
|
|
358
364
|
"The private photo upload failed (" + uploaded.status + "). Retry with the same request ID."
|
|
359
365
|
);
|