@behindthemusictree/app-kit 35.0.0 → 37.0.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/dist/{chunk-4TE4OSOM.js → chunk-7S6EALIP.js} +90 -26
- package/dist/chunk-7S6EALIP.js.map +1 -0
- package/dist/{chunk-HLAKW2YJ.js → chunk-G5ULARLT.js} +1 -1
- package/dist/{chunk-ULSVAC23.js → chunk-XIJPC7D5.js} +45 -34
- package/dist/chunk-XIJPC7D5.js.map +1 -0
- package/dist/genre-tree/index.cjs +338 -265
- package/dist/genre-tree/index.cjs.map +1 -1
- package/dist/genre-tree/index.d.ts +51 -2
- package/dist/genre-tree/index.js +2 -2
- package/dist/index.cjs +413 -336
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -3
- package/dist/transport/index.cjs +198 -130
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.ts +30 -6
- package/dist/transport/index.js +6 -2
- package/dist/useFetchWrapper-C5lt5fQz.d.ts +15 -0
- package/package.json +1 -1
- package/dist/chunk-4TE4OSOM.js.map +0 -1
- package/dist/chunk-ULSVAC23.js.map +0 -1
- package/dist/scope-BoMVOHmz.d.ts +0 -4
- /package/dist/{chunk-HLAKW2YJ.js.map → chunk-G5ULARLT.js.map} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { A as AppError, a as AppErrorType, b as AuthRequired, B as BackendError, c as BackendSpotifyUserNotAllowlistedError, d as BadRequestError, C as ClientError, e as ConnectivityError, I as InvalidInputError, N as NetworkError, S as ServiceError } from './app-error-B8IoFBhD.js';
|
|
2
2
|
export { E as ErrorCode } from './app-error-codes-D5eYg7xR.js';
|
|
3
|
-
export { BuildBackendBaseUrlParams, BuildSubdomainBaseUrlParams, ConnectivityErrorProvider, ConnectivityErrorType, ErrorMessages, PaginatedResponse, PaginatedResponseSchema, PlaybackContextProvider, PlaybackContextSchema, buildBackendBaseUrl, buildSubdomainBaseUrl, createAppErrorFromErrorCode, createAppErrorFromResult, createNetworkOrBackendError, fetchWrapper, getSpotifyAllowlistMailtoHref, getSpotifyAllowlistMessage, parseWithLog, queryClient, useConnectivityError,
|
|
4
|
-
export { S as Scope } from './
|
|
3
|
+
export { BuildBackendBaseUrlParams, BuildSubdomainBaseUrlParams, ConnectivityErrorProvider, ConnectivityErrorType, ErrorMessages, PaginatedResponse, PaginatedResponseSchema, PlaybackContextProvider, PlaybackContextSchema, buildBackendBaseUrl, buildSubdomainBaseUrl, createAppErrorFromErrorCode, createAppErrorFromResult, createNetworkOrBackendError, fetchWrapper, getSpotifyAllowlistMailtoHref, getSpotifyAllowlistMessage, parseWithLog, queryClient, useConnectivityError, usePlaybackContext, usePlaybackFetch, usePlaybackQuery, useQueryWithParse, useValidatedMutation } from './transport/index.js';
|
|
4
|
+
export { S as Scope, u as useFetchWrapper } from './useFetchWrapper-C5lt5fQz.js';
|
|
5
5
|
export { AuthCallbackState, AuthCallbackStatus, BackendAuthResponse, ExchangeCodeConfig, GOOGLE_EXCHANGE_CONFIG, SPOTIFY_EXCHANGE_CONFIG, Session, SessionProvider, UseAuthCallbackOptions, clearSpotifyRequiredCached, clearStoredRedirectUrl, createLogout, exchangeCodeWithBackend, getSpotifyRequiredCached, resolveRedirectUri, setSpotifyRequiredCached, storeRedirectUrl, useAuthCallback, useLogout, useSession } from './auth/index.js';
|
|
6
6
|
export { AUTH_POPUP_TYPE, ConnectivityErrorPopupRenderers, PopupProvider, TrackUploadItem, UploadStatus, UseConnectivityErrorPopupOptions, UseTrackUploadOptions, UseTrackUploadResult, useConnectivityErrorPopup, usePopup, useTrackUpload } from './popup/index.js';
|
|
7
7
|
export { TrackNoun, TrackNounProvider, capitalize, useTrackNoun } from './track-noun/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildBackendBaseUrl,
|
|
3
3
|
buildSubdomainBaseUrl
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-G5ULARLT.js";
|
|
5
5
|
import {
|
|
6
6
|
GOOGLE_EXCHANGE_CONFIG,
|
|
7
7
|
SPOTIFY_EXCHANGE_CONFIG,
|
|
@@ -152,16 +152,18 @@ import {
|
|
|
152
152
|
useTrackListSidebarVisibility,
|
|
153
153
|
useUpdateGenre,
|
|
154
154
|
useVisibleGenrePlaylists
|
|
155
|
-
} from "./chunk-
|
|
155
|
+
} from "./chunk-XIJPC7D5.js";
|
|
156
156
|
import {
|
|
157
157
|
ConnectivityErrorType,
|
|
158
158
|
PaginatedResponseSchema,
|
|
159
159
|
fetchWrapper,
|
|
160
160
|
parseWithLog,
|
|
161
161
|
useFetchWrapper,
|
|
162
|
+
usePlaybackFetch,
|
|
163
|
+
usePlaybackQuery,
|
|
162
164
|
useQueryWithParse,
|
|
163
165
|
useValidatedMutation
|
|
164
|
-
} from "./chunk-
|
|
166
|
+
} from "./chunk-7S6EALIP.js";
|
|
165
167
|
import {
|
|
166
168
|
SessionProvider,
|
|
167
169
|
clearSpotifyRequiredCached,
|
|
@@ -380,6 +382,8 @@ export {
|
|
|
380
382
|
useListTracks,
|
|
381
383
|
useLogout,
|
|
382
384
|
usePlaybackContext,
|
|
385
|
+
usePlaybackFetch,
|
|
386
|
+
usePlaybackQuery,
|
|
383
387
|
usePlayer,
|
|
384
388
|
usePopup,
|
|
385
389
|
usePrefetchGenreOverview,
|
package/dist/transport/index.cjs
CHANGED
|
@@ -50,6 +50,8 @@ __export(transport_exports, {
|
|
|
50
50
|
useConnectivityError: () => useConnectivityError,
|
|
51
51
|
useFetchWrapper: () => useFetchWrapper,
|
|
52
52
|
usePlaybackContext: () => usePlaybackContext,
|
|
53
|
+
usePlaybackFetch: () => usePlaybackFetch,
|
|
54
|
+
usePlaybackQuery: () => usePlaybackQuery,
|
|
53
55
|
useQueryWithParse: () => useQueryWithParse,
|
|
54
56
|
useValidatedMutation: () => useValidatedMutation
|
|
55
57
|
});
|
|
@@ -514,110 +516,25 @@ var fetchWrapper = async (url, requiresAuth, options = {}, accessToken, queryPar
|
|
|
514
516
|
}
|
|
515
517
|
};
|
|
516
518
|
|
|
517
|
-
// src/transport/PlaybackContext.tsx
|
|
518
|
-
var import_react = require("react");
|
|
519
|
-
var import_zod = require("zod");
|
|
520
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
521
|
-
var PlaybackContextSchema = import_zod.z.object({ country: import_zod.z.string().regex(/^[A-Z]{2}$/).nullable() });
|
|
522
|
-
var unmanaged = {
|
|
523
|
-
country: null,
|
|
524
|
-
key: null,
|
|
525
|
-
ready: true,
|
|
526
|
-
error: null,
|
|
527
|
-
isCurrent: (_key) => true,
|
|
528
|
-
snapshot: () => ({ key: null, country: null }),
|
|
529
|
-
refresh: async (_force = false) => null
|
|
530
|
-
};
|
|
531
|
-
var PlaybackContext = (0, import_react.createContext)(unmanaged);
|
|
532
|
-
var usePlaybackContext = () => (0, import_react.useContext)(PlaybackContext);
|
|
533
|
-
function PlaybackContextProvider({ children, loadContext }) {
|
|
534
|
-
const [state, setState] = (0, import_react.useState)({
|
|
535
|
-
country: null,
|
|
536
|
-
ready: false,
|
|
537
|
-
revision: 0,
|
|
538
|
-
error: null
|
|
539
|
-
});
|
|
540
|
-
const current = (0, import_react.useRef)(state);
|
|
541
|
-
const checkedAt = (0, import_react.useRef)(0);
|
|
542
|
-
const pending = (0, import_react.useRef)(null);
|
|
543
|
-
const refresh = (0, import_react.useCallback)((force = false) => {
|
|
544
|
-
if (pending.current) return pending.current;
|
|
545
|
-
if (!force && current.current.ready && Date.now() - checkedAt.current < 6e4) {
|
|
546
|
-
return Promise.resolve(current.current.country);
|
|
547
|
-
}
|
|
548
|
-
pending.current = loadContext().then((raw) => {
|
|
549
|
-
const { country } = PlaybackContextSchema.parse(raw);
|
|
550
|
-
const previous = current.current;
|
|
551
|
-
const next = {
|
|
552
|
-
country,
|
|
553
|
-
ready: true,
|
|
554
|
-
error: null,
|
|
555
|
-
revision: previous.revision + (country !== previous.country ? 1 : 0)
|
|
556
|
-
};
|
|
557
|
-
current.current = next;
|
|
558
|
-
checkedAt.current = Date.now();
|
|
559
|
-
setState(next);
|
|
560
|
-
return country;
|
|
561
|
-
}).catch((error) => {
|
|
562
|
-
const next = {
|
|
563
|
-
...current.current,
|
|
564
|
-
error: error instanceof Error ? error.message : "Unable to check playback location"
|
|
565
|
-
};
|
|
566
|
-
current.current = next;
|
|
567
|
-
setState(next);
|
|
568
|
-
throw error;
|
|
569
|
-
}).finally(() => {
|
|
570
|
-
pending.current = null;
|
|
571
|
-
});
|
|
572
|
-
return pending.current;
|
|
573
|
-
}, [loadContext]);
|
|
574
|
-
(0, import_react.useEffect)(() => {
|
|
575
|
-
const update = () => {
|
|
576
|
-
void refresh(true).catch(() => {
|
|
577
|
-
});
|
|
578
|
-
};
|
|
579
|
-
update();
|
|
580
|
-
window.addEventListener("focus", update);
|
|
581
|
-
window.addEventListener("online", update);
|
|
582
|
-
return () => {
|
|
583
|
-
window.removeEventListener("focus", update);
|
|
584
|
-
window.removeEventListener("online", update);
|
|
585
|
-
};
|
|
586
|
-
}, [refresh]);
|
|
587
|
-
const isCurrent = (0, import_react.useCallback)(
|
|
588
|
-
(key) => key === `${current.current.country ?? "unknown"}:${current.current.revision}`,
|
|
589
|
-
[]
|
|
590
|
-
);
|
|
591
|
-
const snapshot = (0, import_react.useCallback)(() => ({
|
|
592
|
-
key: `${current.current.country ?? "unknown"}:${current.current.revision}`,
|
|
593
|
-
country: current.current.country
|
|
594
|
-
}), []);
|
|
595
|
-
const value = (0, import_react.useMemo)(() => ({
|
|
596
|
-
...state,
|
|
597
|
-
isCurrent,
|
|
598
|
-
snapshot,
|
|
599
|
-
key: `${state.country ?? "unknown"}:${state.revision}`,
|
|
600
|
-
refresh
|
|
601
|
-
}), [state, refresh, isCurrent, snapshot]);
|
|
602
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaybackContext.Provider, { value, children });
|
|
603
|
-
}
|
|
604
|
-
|
|
605
519
|
// src/transport/useFetchWrapper.ts
|
|
606
520
|
var import_react4 = require("react");
|
|
607
521
|
|
|
522
|
+
// src/transport/lib/use-backend-request.ts
|
|
523
|
+
var import_react3 = require("react");
|
|
524
|
+
|
|
608
525
|
// src/transport/connectivity-error-context.tsx
|
|
609
|
-
var
|
|
610
|
-
var
|
|
611
|
-
var ConnectivityErrorContext = (0,
|
|
526
|
+
var import_react = require("react");
|
|
527
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
528
|
+
var ConnectivityErrorContext = (0, import_react.createContext)(void 0);
|
|
612
529
|
function ConnectivityErrorProvider({ children }) {
|
|
613
|
-
const [connectivityError, setConnectivityError] = (0,
|
|
614
|
-
const clearConnectivityError = (0,
|
|
530
|
+
const [connectivityError, setConnectivityError] = (0, import_react.useState)(null);
|
|
531
|
+
const clearConnectivityError = (0, import_react.useCallback)(() => {
|
|
615
532
|
setConnectivityError(null);
|
|
616
533
|
}, []);
|
|
617
|
-
const handleSetConnectivityError = (0,
|
|
534
|
+
const handleSetConnectivityError = (0, import_react.useCallback)((error) => {
|
|
618
535
|
setConnectivityError(error);
|
|
619
536
|
}, []);
|
|
620
|
-
const value = (0,
|
|
537
|
+
const value = (0, import_react.useMemo)(
|
|
621
538
|
() => ({
|
|
622
539
|
connectivityError,
|
|
623
540
|
setConnectivityError: handleSetConnectivityError,
|
|
@@ -625,10 +542,10 @@ function ConnectivityErrorProvider({ children }) {
|
|
|
625
542
|
}),
|
|
626
543
|
[connectivityError, handleSetConnectivityError, clearConnectivityError]
|
|
627
544
|
);
|
|
628
|
-
return /* @__PURE__ */ (0,
|
|
545
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConnectivityErrorContext.Provider, { value, children });
|
|
629
546
|
}
|
|
630
547
|
function useConnectivityError() {
|
|
631
|
-
const context = (0,
|
|
548
|
+
const context = (0, import_react.useContext)(ConnectivityErrorContext);
|
|
632
549
|
if (context === void 0) {
|
|
633
550
|
throw new Error("useConnectivityError must be used within a ConnectivityErrorProvider");
|
|
634
551
|
}
|
|
@@ -636,7 +553,7 @@ function useConnectivityError() {
|
|
|
636
553
|
}
|
|
637
554
|
|
|
638
555
|
// src/auth/SessionContext.tsx
|
|
639
|
-
var
|
|
556
|
+
var import_react2 = require("react");
|
|
640
557
|
|
|
641
558
|
// src/transport/query-client.ts
|
|
642
559
|
var import_react_query = require("@tanstack/react-query");
|
|
@@ -651,22 +568,21 @@ var queryClient = new import_react_query.QueryClient({
|
|
|
651
568
|
});
|
|
652
569
|
|
|
653
570
|
// src/auth/SessionContext.tsx
|
|
654
|
-
var
|
|
655
|
-
var SessionContext = (0,
|
|
571
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
572
|
+
var SessionContext = (0, import_react2.createContext)(void 0);
|
|
656
573
|
function useSession() {
|
|
657
|
-
const context = (0,
|
|
574
|
+
const context = (0, import_react2.useContext)(SessionContext);
|
|
658
575
|
if (context === void 0) {
|
|
659
576
|
throw new Error("useSession must be used within a SessionProvider");
|
|
660
577
|
}
|
|
661
578
|
return context;
|
|
662
579
|
}
|
|
663
580
|
|
|
664
|
-
// src/transport/
|
|
665
|
-
var
|
|
666
|
-
const playback = usePlaybackContext();
|
|
581
|
+
// src/transport/lib/use-backend-request.ts
|
|
582
|
+
var useBackendRequest = (getBackendBaseUrl) => {
|
|
667
583
|
const { setConnectivityError } = useConnectivityError();
|
|
668
584
|
const { clearSession, session, sessionRestored } = useSession();
|
|
669
|
-
const handleError = (0,
|
|
585
|
+
const handleError = (0, import_react3.useCallback)((error) => {
|
|
670
586
|
if (error instanceof ConnectivityError) {
|
|
671
587
|
const authDetailErrors = [
|
|
672
588
|
"BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */,
|
|
@@ -693,53 +609,180 @@ var useFetchWrapper = (getBackendBaseUrl) => {
|
|
|
693
609
|
if (!sessionRestored) return;
|
|
694
610
|
setConnectivityError(createAppErrorFromErrorCode("SES4012" /* SESSION_REQUIRED */));
|
|
695
611
|
};
|
|
696
|
-
const
|
|
612
|
+
const request = (0, import_react3.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false, onResponse) => {
|
|
697
613
|
const baseUrl = getBackendBaseUrl().replace(/\/+$/, "");
|
|
698
614
|
const endpointPath = String(backendEndpointOrUrl);
|
|
699
615
|
if (fromBackend && endpointPath.startsWith("/")) {
|
|
700
616
|
throw new Error(`Endpoint path must be relative (no leading slash). Got: "${endpointPath}".`);
|
|
701
617
|
}
|
|
702
618
|
const url = fromBackend ? endpointPath ? `${baseUrl}/${endpointPath}` : baseUrl : backendEndpointOrUrl;
|
|
619
|
+
return fetchWrapper(
|
|
620
|
+
url,
|
|
621
|
+
requiresAuth,
|
|
622
|
+
options,
|
|
623
|
+
session?.accessToken || void 0,
|
|
624
|
+
queryParams,
|
|
625
|
+
handleMissingRequiredSession,
|
|
626
|
+
skipGlobalError ? void 0 : handleError,
|
|
627
|
+
expectBinary,
|
|
628
|
+
baseUrl,
|
|
629
|
+
onResponse
|
|
630
|
+
);
|
|
631
|
+
}, [session?.accessToken, handleError, getBackendBaseUrl, sessionRestored, setConnectivityError]);
|
|
632
|
+
return { request };
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
// src/transport/useFetchWrapper.ts
|
|
636
|
+
var useFetchWrapper = (getBackendBaseUrl) => {
|
|
637
|
+
const { request } = useBackendRequest(getBackendBaseUrl);
|
|
638
|
+
const fetch2 = (0, import_react4.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false) => {
|
|
639
|
+
const isRead = (options.method ?? "GET").toUpperCase() === "GET";
|
|
640
|
+
const warnOnStampedRead = isRead && fromBackend && process.env.NODE_ENV !== "production" ? (response) => {
|
|
641
|
+
if (response.headers.get("x-playback-country") !== null) {
|
|
642
|
+
console.error(
|
|
643
|
+
`GET ${backendEndpointOrUrl} is country-dependent (X-Playback-Country) but was fetched without the playback context. Use usePlaybackQuery/usePlaybackFetch.`
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
} : void 0;
|
|
647
|
+
return request(backendEndpointOrUrl, fromBackend, requiresAuth, options, queryParams, expectBinary, skipGlobalError, warnOnStampedRead);
|
|
648
|
+
}, [request]);
|
|
649
|
+
return { fetch: fetch2 };
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
// src/transport/usePlaybackFetch.ts
|
|
653
|
+
var import_react6 = require("react");
|
|
654
|
+
|
|
655
|
+
// src/transport/PlaybackContext.tsx
|
|
656
|
+
var import_react5 = require("react");
|
|
657
|
+
var import_zod = require("zod");
|
|
658
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
659
|
+
var PlaybackContextSchema = import_zod.z.object({ country: import_zod.z.string().regex(/^[A-Z]{2}$/).nullable() });
|
|
660
|
+
var unmanaged = {
|
|
661
|
+
country: null,
|
|
662
|
+
key: null,
|
|
663
|
+
ready: true,
|
|
664
|
+
error: null,
|
|
665
|
+
isCurrent: (_key) => true,
|
|
666
|
+
snapshot: () => ({ key: null, country: null }),
|
|
667
|
+
refresh: async (_force = false) => null
|
|
668
|
+
};
|
|
669
|
+
var PlaybackContext = (0, import_react5.createContext)(unmanaged);
|
|
670
|
+
var usePlaybackContext = () => (0, import_react5.useContext)(PlaybackContext);
|
|
671
|
+
function PlaybackContextProvider({ children, loadContext }) {
|
|
672
|
+
const [state, setState] = (0, import_react5.useState)({
|
|
673
|
+
country: null,
|
|
674
|
+
ready: false,
|
|
675
|
+
revision: 0,
|
|
676
|
+
error: null
|
|
677
|
+
});
|
|
678
|
+
const current = (0, import_react5.useRef)(state);
|
|
679
|
+
const checkedAt = (0, import_react5.useRef)(0);
|
|
680
|
+
const pending = (0, import_react5.useRef)(null);
|
|
681
|
+
const refresh = (0, import_react5.useCallback)((force = false) => {
|
|
682
|
+
if (pending.current) return pending.current;
|
|
683
|
+
if (!force && current.current.ready && Date.now() - checkedAt.current < 6e4) {
|
|
684
|
+
return Promise.resolve(current.current.country);
|
|
685
|
+
}
|
|
686
|
+
pending.current = loadContext().then((raw) => {
|
|
687
|
+
const { country } = PlaybackContextSchema.parse(raw);
|
|
688
|
+
const previous = current.current;
|
|
689
|
+
const next = {
|
|
690
|
+
country,
|
|
691
|
+
ready: true,
|
|
692
|
+
error: null,
|
|
693
|
+
revision: previous.revision + (country !== previous.country ? 1 : 0)
|
|
694
|
+
};
|
|
695
|
+
current.current = next;
|
|
696
|
+
checkedAt.current = Date.now();
|
|
697
|
+
setState(next);
|
|
698
|
+
return country;
|
|
699
|
+
}).catch((error) => {
|
|
700
|
+
const next = {
|
|
701
|
+
...current.current,
|
|
702
|
+
error: error instanceof Error ? error.message : "Unable to check playback location"
|
|
703
|
+
};
|
|
704
|
+
current.current = next;
|
|
705
|
+
setState(next);
|
|
706
|
+
throw error;
|
|
707
|
+
}).finally(() => {
|
|
708
|
+
pending.current = null;
|
|
709
|
+
});
|
|
710
|
+
return pending.current;
|
|
711
|
+
}, [loadContext]);
|
|
712
|
+
(0, import_react5.useEffect)(() => {
|
|
713
|
+
const update = () => {
|
|
714
|
+
void refresh(true).catch(() => {
|
|
715
|
+
});
|
|
716
|
+
};
|
|
717
|
+
update();
|
|
718
|
+
window.addEventListener("focus", update);
|
|
719
|
+
window.addEventListener("online", update);
|
|
720
|
+
return () => {
|
|
721
|
+
window.removeEventListener("focus", update);
|
|
722
|
+
window.removeEventListener("online", update);
|
|
723
|
+
};
|
|
724
|
+
}, [refresh]);
|
|
725
|
+
const isCurrent = (0, import_react5.useCallback)(
|
|
726
|
+
(key) => key === `${current.current.country ?? "unknown"}:${current.current.revision}`,
|
|
727
|
+
[]
|
|
728
|
+
);
|
|
729
|
+
const snapshot = (0, import_react5.useCallback)(() => ({
|
|
730
|
+
key: `${current.current.country ?? "unknown"}:${current.current.revision}`,
|
|
731
|
+
country: current.current.country
|
|
732
|
+
}), []);
|
|
733
|
+
const value = (0, import_react5.useMemo)(() => ({
|
|
734
|
+
...state,
|
|
735
|
+
isCurrent,
|
|
736
|
+
snapshot,
|
|
737
|
+
key: `${state.country ?? "unknown"}:${state.revision}`,
|
|
738
|
+
refresh
|
|
739
|
+
}), [state, refresh, isCurrent, snapshot]);
|
|
740
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PlaybackContext.Provider, { value, children });
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// src/transport/usePlaybackFetch.ts
|
|
744
|
+
var stale = () => new DOMException("Playback context changed", "AbortError");
|
|
745
|
+
var usePlaybackFetch = (getBackendBaseUrl) => {
|
|
746
|
+
const playback = usePlaybackContext();
|
|
747
|
+
const { request } = useBackendRequest(getBackendBaseUrl);
|
|
748
|
+
const run = (0, import_react6.useCallback)((adoptRefreshed, backendEndpointOrUrl, fromBackend, requiresAuth, options, queryParams, expectBinary, skipGlobalError) => {
|
|
703
749
|
const perform = async (retryContextChange) => {
|
|
704
|
-
const contextual = playback.key !== null && fromBackend && /^(?:me\/)?(library\/songs|genre-playlists|playlists|manual-playlists)\//.test(endpointPath);
|
|
705
750
|
let requestContext = { key: playback.key, country: playback.country };
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
if (!playback.isCurrent(requestContext.key)) throw new DOMException("Playback context changed", "AbortError");
|
|
710
|
-
}
|
|
751
|
+
await playback.refresh();
|
|
752
|
+
if (adoptRefreshed) requestContext = playback.snapshot();
|
|
753
|
+
if (!playback.isCurrent(requestContext.key)) throw stale();
|
|
711
754
|
try {
|
|
712
|
-
const result = await
|
|
713
|
-
|
|
755
|
+
const result = await request(
|
|
756
|
+
backendEndpointOrUrl,
|
|
757
|
+
fromBackend,
|
|
714
758
|
requiresAuth,
|
|
715
759
|
options,
|
|
716
|
-
session?.accessToken || void 0,
|
|
717
760
|
queryParams,
|
|
718
|
-
handleMissingRequiredSession,
|
|
719
|
-
skipGlobalError ? void 0 : handleError,
|
|
720
761
|
expectBinary,
|
|
721
|
-
|
|
722
|
-
|
|
762
|
+
skipGlobalError,
|
|
763
|
+
async (response) => {
|
|
723
764
|
const responseCountry = response.headers.get("x-playback-country");
|
|
724
|
-
if (responseCountry !== null && responseCountry !== (requestContext.country ?? "unknown")) {
|
|
765
|
+
if (playback.key !== null && responseCountry !== null && responseCountry !== (requestContext.country ?? "unknown")) {
|
|
725
766
|
await playback.refresh(true);
|
|
726
|
-
throw
|
|
767
|
+
throw stale();
|
|
727
768
|
}
|
|
728
|
-
if (!playback.isCurrent(requestContext.key)) throw
|
|
729
|
-
}
|
|
769
|
+
if (!playback.isCurrent(requestContext.key)) throw stale();
|
|
770
|
+
}
|
|
730
771
|
);
|
|
731
|
-
if (
|
|
772
|
+
if (!playback.isCurrent(requestContext.key)) throw stale();
|
|
732
773
|
return result;
|
|
733
774
|
} catch (error) {
|
|
734
|
-
if (retryContextChange &&
|
|
775
|
+
if (retryContextChange && error instanceof DOMException && error.name === "AbortError" && !playback.isCurrent(requestContext.key)) {
|
|
735
776
|
return perform(false);
|
|
736
777
|
}
|
|
737
778
|
throw error;
|
|
738
779
|
}
|
|
739
780
|
};
|
|
740
|
-
return perform(
|
|
741
|
-
}, [
|
|
742
|
-
|
|
781
|
+
return perform(adoptRefreshed);
|
|
782
|
+
}, [playback, request]);
|
|
783
|
+
const fetchBound = (0, import_react6.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false) => run(false, backendEndpointOrUrl, fromBackend, requiresAuth, options, queryParams, expectBinary, skipGlobalError), [run]);
|
|
784
|
+
const fetchLatest = (0, import_react6.useCallback)((backendEndpointOrUrl, fromBackend = true, requiresAuth = true, options = {}, queryParams, expectBinary = false, skipGlobalError = false) => run(true, backendEndpointOrUrl, fromBackend, requiresAuth, options, queryParams, expectBinary, skipGlobalError), [run]);
|
|
785
|
+
return { fetchBound, fetchLatest };
|
|
743
786
|
};
|
|
744
787
|
|
|
745
788
|
// src/transport/site-urls.ts
|
|
@@ -806,9 +849,32 @@ function useQueryWithParse({
|
|
|
806
849
|
});
|
|
807
850
|
}
|
|
808
851
|
|
|
852
|
+
// src/transport/lib/use-playback-query.ts
|
|
853
|
+
var import_react7 = require("react");
|
|
854
|
+
function usePlaybackQuery({
|
|
855
|
+
queryKey,
|
|
856
|
+
getBackendBaseUrl,
|
|
857
|
+
queryFn,
|
|
858
|
+
enabled = true,
|
|
859
|
+
retry,
|
|
860
|
+
...options
|
|
861
|
+
}) {
|
|
862
|
+
const playback = usePlaybackContext();
|
|
863
|
+
const { fetchBound } = usePlaybackFetch(getBackendBaseUrl);
|
|
864
|
+
const run = (0, import_react7.useCallback)((context) => queryFn(fetchBound, context), [queryFn, fetchBound]);
|
|
865
|
+
return useQueryWithParse({
|
|
866
|
+
...options,
|
|
867
|
+
queryKey: [...queryKey, ...playback.key ? [playback.key] : []],
|
|
868
|
+
queryFn: run,
|
|
869
|
+
enabled: typeof enabled === "function" ? (query) => playback.ready && enabled(query) : enabled && playback.ready,
|
|
870
|
+
retry: (failureCount, error) => failureCount < 1 && error instanceof DOMException && error.name === "AbortError" || (retry?.(failureCount, error) ?? false),
|
|
871
|
+
retryDelay: 0
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
|
|
809
875
|
// src/transport/lib/use-validated-mutation.ts
|
|
810
876
|
var import_react_query3 = require("@tanstack/react-query");
|
|
811
|
-
var
|
|
877
|
+
var import_react8 = require("react");
|
|
812
878
|
var import_zod4 = require("zod");
|
|
813
879
|
function useValidatedMutation({
|
|
814
880
|
inputSchema,
|
|
@@ -816,7 +882,7 @@ function useValidatedMutation({
|
|
|
816
882
|
mutationFn,
|
|
817
883
|
...options
|
|
818
884
|
}) {
|
|
819
|
-
const [formErrors, setFormErrors] = (0,
|
|
885
|
+
const [formErrors, setFormErrors] = (0, import_react8.useState)([]);
|
|
820
886
|
const validatedMutation = (0, import_react_query3.useMutation)({
|
|
821
887
|
...options,
|
|
822
888
|
mutationFn: async (data) => {
|
|
@@ -898,6 +964,8 @@ function useValidatedMutation({
|
|
|
898
964
|
useConnectivityError,
|
|
899
965
|
useFetchWrapper,
|
|
900
966
|
usePlaybackContext,
|
|
967
|
+
usePlaybackFetch,
|
|
968
|
+
usePlaybackQuery,
|
|
901
969
|
useQueryWithParse,
|
|
902
970
|
useValidatedMutation
|
|
903
971
|
});
|