@bikefinder/sdk 0.36.0 → 0.38.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/README.md +5 -1
- package/dist/{chunk-ARMBM5BL.js → chunk-CQMAPPN6.js} +11 -0
- package/dist/index.d.ts +1968 -0
- package/dist/index.js +112 -4
- package/dist/schemas.d.ts +1970 -0
- package/dist/schemas.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
account,
|
|
3
|
+
accountChange,
|
|
3
4
|
accountPreferencePatch,
|
|
4
5
|
accountPreferences,
|
|
6
|
+
accountWatchSnapshot,
|
|
5
7
|
apiContractVersion,
|
|
6
8
|
batteryObservation,
|
|
7
9
|
bikeChanges,
|
|
@@ -87,7 +89,7 @@ import {
|
|
|
87
89
|
trackerModeWrite,
|
|
88
90
|
trackerMovementAlertsInput,
|
|
89
91
|
trackerPhotoContract
|
|
90
|
-
} from "./chunk-
|
|
92
|
+
} from "./chunk-CQMAPPN6.js";
|
|
91
93
|
|
|
92
94
|
// ../../src/client/client.ts
|
|
93
95
|
import {
|
|
@@ -459,7 +461,7 @@ function createApiClient(contract, audience, options, wrapRealtime) {
|
|
|
459
461
|
}
|
|
460
462
|
|
|
461
463
|
// src/index.ts
|
|
462
|
-
import { ORPCError as
|
|
464
|
+
import { ORPCError as ORPCError3 } from "@orpc/client";
|
|
463
465
|
|
|
464
466
|
// src/photo-upload.ts
|
|
465
467
|
async function uploadPhoto(uploads, input, fetch = globalThis.fetch) {
|
|
@@ -519,9 +521,115 @@ async function uploadPhoto(uploads, input, fetch = globalThis.fetch) {
|
|
|
519
521
|
return uploads.complete(operation, { signal: input.signal });
|
|
520
522
|
}
|
|
521
523
|
|
|
524
|
+
// src/account-watch.ts
|
|
525
|
+
import { ORPCError as ORPCError2 } from "@orpc/client";
|
|
526
|
+
import { isAsyncIteratorObject as isAsyncIteratorObject2 } from "@orpc/shared";
|
|
527
|
+
import pTimeout2 from "p-timeout";
|
|
528
|
+
var createCustomerRealtime = (native, http, timeoutMs) => ({
|
|
529
|
+
async call(path, input, options) {
|
|
530
|
+
if (path.join(".") !== "customer.account.watch")
|
|
531
|
+
return native.call(path, input, options);
|
|
532
|
+
const stopping = new AbortController();
|
|
533
|
+
const signal = options.signal ? AbortSignal.any([options.signal, stopping.signal]) : stopping.signal;
|
|
534
|
+
const request = { ...options, signal };
|
|
535
|
+
let source;
|
|
536
|
+
try {
|
|
537
|
+
source = await pTimeout2(
|
|
538
|
+
native.call(["customer", "account", "changes"], input, request),
|
|
539
|
+
{ milliseconds: timeoutMs, signal }
|
|
540
|
+
);
|
|
541
|
+
if (!isAsyncIteratorObject2(source))
|
|
542
|
+
throw new ORPCError2("stream_unavailable", { status: 503, message: "Expected an account change stream." });
|
|
543
|
+
} catch (error) {
|
|
544
|
+
stopping.abort(error);
|
|
545
|
+
if (error instanceof ORPCError2 && error.status === 404)
|
|
546
|
+
return native.call(path, input, options);
|
|
547
|
+
throw error;
|
|
548
|
+
}
|
|
549
|
+
const notices = source;
|
|
550
|
+
const reader = new ReadableStream({
|
|
551
|
+
start(controller) {
|
|
552
|
+
if (signal.aborted) {
|
|
553
|
+
controller.error(signal.reason);
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
signal.addEventListener("abort", () => controller.error(signal.reason), { once: true });
|
|
557
|
+
void (async () => {
|
|
558
|
+
try {
|
|
559
|
+
for await (const value of notices) {
|
|
560
|
+
if (signal.aborted) return;
|
|
561
|
+
accountChange.parse(value);
|
|
562
|
+
if (controller.desiredSize === 1) controller.enqueue(null);
|
|
563
|
+
}
|
|
564
|
+
if (!signal.aborted) controller.close();
|
|
565
|
+
} catch (error) {
|
|
566
|
+
if (!signal.aborted) {
|
|
567
|
+
controller.error(error);
|
|
568
|
+
stopping.abort(error);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
})();
|
|
572
|
+
},
|
|
573
|
+
cancel: () => stopping.abort()
|
|
574
|
+
}, { highWaterMark: 1 }).getReader();
|
|
575
|
+
const updates = (async function* () {
|
|
576
|
+
const expired = () => new ORPCError2("unauthenticated", { status: 401, message: "Sign in to continue." });
|
|
577
|
+
async function read() {
|
|
578
|
+
const snapshot = accountWatchSnapshot.parse(await http.call(
|
|
579
|
+
["customer", "account", "watchSnapshot"],
|
|
580
|
+
void 0,
|
|
581
|
+
request
|
|
582
|
+
));
|
|
583
|
+
signal.throwIfAborted();
|
|
584
|
+
return snapshot;
|
|
585
|
+
}
|
|
586
|
+
try {
|
|
587
|
+
const initial = await read();
|
|
588
|
+
if (initial.credentialExpiresAt <= Date.now()) throw expired();
|
|
589
|
+
let revision = initial.account.revision;
|
|
590
|
+
yield initial.account;
|
|
591
|
+
while (true) {
|
|
592
|
+
const remaining = initial.credentialExpiresAt - Date.now();
|
|
593
|
+
if (remaining <= 0) throw expired();
|
|
594
|
+
const notice = await pTimeout2(reader.read(), {
|
|
595
|
+
milliseconds: remaining,
|
|
596
|
+
signal,
|
|
597
|
+
fallback: () => {
|
|
598
|
+
throw expired();
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
if (notice.done) break;
|
|
602
|
+
const current = await read();
|
|
603
|
+
if (initial.credentialExpiresAt <= Date.now()) throw expired();
|
|
604
|
+
if (initial.lifetime !== current.lifetime)
|
|
605
|
+
throw new ORPCError2("conflict", { status: 409, message: "The account was recreated during this request." });
|
|
606
|
+
if (revision === current.account.revision) continue;
|
|
607
|
+
revision = current.account.revision;
|
|
608
|
+
yield current.account;
|
|
609
|
+
}
|
|
610
|
+
} finally {
|
|
611
|
+
await reader.cancel().catch(() => {
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
})();
|
|
615
|
+
return {
|
|
616
|
+
next: () => updates.next(),
|
|
617
|
+
async return() {
|
|
618
|
+
stopping.abort();
|
|
619
|
+
await reader.cancel().catch(() => {
|
|
620
|
+
});
|
|
621
|
+
return updates.return(void 0);
|
|
622
|
+
},
|
|
623
|
+
[Symbol.asyncIterator]() {
|
|
624
|
+
return this;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
|
|
522
630
|
// src/index.ts
|
|
523
631
|
function createBikeFinderClient(options) {
|
|
524
|
-
const client = createApiClient(customerContract, "customer", options);
|
|
632
|
+
const client = createApiClient(customerContract, "customer", options, createCustomerRealtime);
|
|
525
633
|
const uploads = new AbortController();
|
|
526
634
|
return {
|
|
527
635
|
...client,
|
|
@@ -543,7 +651,7 @@ function createBikeFinderClient(options) {
|
|
|
543
651
|
};
|
|
544
652
|
}
|
|
545
653
|
export {
|
|
546
|
-
|
|
654
|
+
ORPCError3 as ORPCError,
|
|
547
655
|
RealtimeDisconnectedError,
|
|
548
656
|
account,
|
|
549
657
|
accountPreferencePatch,
|