@behindthemusictree/app-kit 0.0.0-stage → 26.1.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/LICENSE +15 -0
- package/dist/app-error-B8IoFBhD.d.ts +45 -0
- package/dist/app-error-codes-D5eYg7xR.d.ts +49 -0
- package/dist/auth/index.cjs +479 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.ts +83 -0
- package/dist/auth/index.js +36 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/chunk-4MEK3CNF.js +246 -0
- package/dist/chunk-4MEK3CNF.js.map +1 -0
- package/dist/chunk-5NTNMBJP.js +25 -0
- package/dist/chunk-5NTNMBJP.js.map +1 -0
- package/dist/chunk-5YLNSX34.js +211 -0
- package/dist/chunk-5YLNSX34.js.map +1 -0
- package/dist/chunk-7EOS2K24.js +267 -0
- package/dist/chunk-7EOS2K24.js.map +1 -0
- package/dist/chunk-FYOLIMWU.js +25 -0
- package/dist/chunk-FYOLIMWU.js.map +1 -0
- package/dist/chunk-JMFEWI53.js +10 -0
- package/dist/chunk-JMFEWI53.js.map +1 -0
- package/dist/chunk-OGTDTTHJ.js +244 -0
- package/dist/chunk-OGTDTTHJ.js.map +1 -0
- package/dist/chunk-OIZPAN6I.js +356 -0
- package/dist/chunk-OIZPAN6I.js.map +1 -0
- package/dist/chunk-T4IDICOJ.js +1480 -0
- package/dist/chunk-T4IDICOJ.js.map +1 -0
- package/dist/chunk-T5D5T52J.js +271 -0
- package/dist/chunk-T5D5T52J.js.map +1 -0
- package/dist/chunk-TCXWV62L.js +1 -0
- package/dist/chunk-TCXWV62L.js.map +1 -0
- package/dist/genre-tree/index.cjs +2153 -0
- package/dist/genre-tree/index.cjs.map +1 -0
- package/dist/genre-tree/index.d.ts +3109 -0
- package/dist/genre-tree/index.js +181 -0
- package/dist/genre-tree/index.js.map +1 -0
- package/dist/genre-tree/testing.cjs +55 -0
- package/dist/genre-tree/testing.cjs.map +1 -0
- package/dist/genre-tree/testing.d.ts +7 -0
- package/dist/genre-tree/testing.js +27 -0
- package/dist/genre-tree/testing.js.map +1 -0
- package/dist/ids-D8XCErUS.d.ts +8 -0
- package/dist/index.cjs +3214 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +310 -0
- package/dist/index.js.map +1 -0
- package/dist/player/index.cjs +388 -0
- package/dist/player/index.cjs.map +1 -0
- package/dist/player/index.d.ts +108 -0
- package/dist/player/index.js +20 -0
- package/dist/player/index.js.map +1 -0
- package/dist/popup/index.cjs +403 -0
- package/dist/popup/index.cjs.map +1 -0
- package/dist/popup/index.d.ts +80 -0
- package/dist/popup/index.js +16 -0
- package/dist/popup/index.js.map +1 -0
- package/dist/scope-BoMVOHmz.d.ts +4 -0
- package/dist/track-noun/index.cjs +53 -0
- package/dist/track-noun/index.cjs.map +1 -0
- package/dist/track-noun/index.d.ts +15 -0
- package/dist/track-noun/index.js +11 -0
- package/dist/track-noun/index.js.map +1 -0
- package/dist/transport/index.cjs +773 -0
- package/dist/transport/index.cjs.map +1 -0
- package/dist/transport/index.d.ts +203 -0
- package/dist/transport/index.js +69 -0
- package/dist/transport/index.js.map +1 -0
- package/package.json +97 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Andreas Garcia
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { E as ErrorCode } from './app-error-codes-D5eYg7xR.js';
|
|
2
|
+
|
|
3
|
+
declare class AppError extends Error {
|
|
4
|
+
readonly code: ErrorCode;
|
|
5
|
+
constructor(code: ErrorCode);
|
|
6
|
+
}
|
|
7
|
+
declare class ClientError extends AppError {
|
|
8
|
+
constructor(code: ErrorCode);
|
|
9
|
+
}
|
|
10
|
+
declare class InvalidInputError extends ClientError {
|
|
11
|
+
readonly json: object;
|
|
12
|
+
constructor(code: ErrorCode, json: object);
|
|
13
|
+
toString(): string;
|
|
14
|
+
}
|
|
15
|
+
declare class ConnectivityError extends AppError {
|
|
16
|
+
constructor(code: ErrorCode);
|
|
17
|
+
}
|
|
18
|
+
declare class BadRequestError extends ConnectivityError {
|
|
19
|
+
constructor(code: ErrorCode);
|
|
20
|
+
}
|
|
21
|
+
declare class NetworkError extends ConnectivityError {
|
|
22
|
+
constructor(code: ErrorCode);
|
|
23
|
+
}
|
|
24
|
+
declare class BackendError extends ConnectivityError {
|
|
25
|
+
readonly backendMessage?: string | undefined;
|
|
26
|
+
constructor(code: ErrorCode, backendMessage?: string | undefined);
|
|
27
|
+
}
|
|
28
|
+
declare class BackendSpotifyUserNotAllowlistedError extends BackendError {
|
|
29
|
+
readonly detailsMessage: string;
|
|
30
|
+
constructor(code: ErrorCode, detailsMessage: string);
|
|
31
|
+
}
|
|
32
|
+
declare class AuthRequired extends ConnectivityError {
|
|
33
|
+
constructor(code: ErrorCode);
|
|
34
|
+
}
|
|
35
|
+
declare class ServiceError extends ConnectivityError {
|
|
36
|
+
constructor(code: ErrorCode);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Union type of all error classes.
|
|
40
|
+
* Required because TypeScript's type system doesn't automatically recognize
|
|
41
|
+
* class inheritance for type checking in instanceof expressions.
|
|
42
|
+
*/
|
|
43
|
+
type AppErrorType = AppError | ClientError | ConnectivityError | BadRequestError | NetworkError | BackendError | BackendSpotifyUserNotAllowlistedError | AuthRequired | ServiceError;
|
|
44
|
+
|
|
45
|
+
export { AppError as A, BackendError as B, ClientError as C, InvalidInputError as I, NetworkError as N, ServiceError as S, type AppErrorType as a, AuthRequired as b, BackendSpotifyUserNotAllowlistedError as c, BadRequestError as d, ConnectivityError as e };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
declare enum ErrorCode {
|
|
2
|
+
NETWORK_OFFLINE = "NET1000",
|
|
3
|
+
NETWORK_TIMEOUT = "NET1001",
|
|
4
|
+
NETWORK_CONNECTION_REFUSED = "NET1002",
|
|
5
|
+
NETWORK_NOT_FOUND = "NET1003",
|
|
6
|
+
NETWORK_ERROR = "NET1004",
|
|
7
|
+
NETWORK_FETCH_ERROR = "NET1005",
|
|
8
|
+
NETWORK_ABORT_ERROR = "NET1006",
|
|
9
|
+
NETWORK_FAILED_TO_FETCH = "NET1007",
|
|
10
|
+
NETWORK_UNKNOWN = "NET1008",
|
|
11
|
+
BACKEND_UNAVAILABLE = "BAC2000",
|
|
12
|
+
BACKEND_RATE_LIMIT = "BAC2001",
|
|
13
|
+
BACKEND_AUTH_ERROR = "BAC2002",
|
|
14
|
+
BACKEND_INVALID_RESPONSE = "BAC2003",
|
|
15
|
+
BACKEND_INTERNAL_ERROR = "BAC5000",
|
|
16
|
+
BACKEND_BAD_REQUEST = "BAC4000",
|
|
17
|
+
BACKEND_UNAUTHORIZED = "BAC4010",
|
|
18
|
+
BACKEND_FORBIDDEN = "BAC4030",
|
|
19
|
+
BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED = "BAC4031",
|
|
20
|
+
BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED = "BAC4011",
|
|
21
|
+
BACKEND_SPOTIFY_OAUTH_CODE_INVALID_OR_EXPIRED = "BAC4017",
|
|
22
|
+
BACKEND_SPOTIFY_OAUTH_INVALID_CLIENT = "BAC4018",
|
|
23
|
+
BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST = "BAC4012",
|
|
24
|
+
BACKEND_SPOTIFY_AUTHENTICATION_ERROR = "BAC4013",
|
|
25
|
+
BACKEND_GOOGLE_AUTHENTICATION_ERROR = "BAC4014",
|
|
26
|
+
BACKEND_GOOGLE_OAUTH_MISCONFIGURED = "BAC4015",
|
|
27
|
+
BACKEND_GOOGLE_OAUTH_UNAUTHORIZED_CLIENT = "BAC4016",
|
|
28
|
+
BACKEND_NOT_FOUND = "BAC4040",
|
|
29
|
+
BACKEND_METHOD_NOT_ALLOWED = "BAC4050",
|
|
30
|
+
BACKEND_REQUEST_TIMEOUT = "BAC4080",
|
|
31
|
+
SESSION_EXPIRED = "SES4011",
|
|
32
|
+
SESSION_REQUIRED = "SES4012",
|
|
33
|
+
CLIENT_FORBIDDEN = "CLI4030",
|
|
34
|
+
CLIENT_NOT_FOUND = "CLI4040",
|
|
35
|
+
CLIENT_UNAUTHORIZED = "CLI4010",
|
|
36
|
+
CLIENT_INTERNAL_ERROR = "CLI5000",
|
|
37
|
+
CLIENT_UNKNOWN = "CLI5001",
|
|
38
|
+
SERVICE_BAD_REQUEST = "SER4000",
|
|
39
|
+
SERVICE_UNAUTHORIZED = "SER4010",
|
|
40
|
+
SERVICE_FORBIDDEN = "SER4030",
|
|
41
|
+
SERVICE_NOT_FOUND = "SER4040",
|
|
42
|
+
SERVICE_INTERNAL_ERROR = "SER5000",
|
|
43
|
+
SERVICE_UNKNOWN = "SER5001",
|
|
44
|
+
SERVICE_METHOD_NOT_ALLOWED = "SER4050",
|
|
45
|
+
SERVICE_REQUEST_TIMEOUT = "SER4080",
|
|
46
|
+
BACKEND_INVALID_INPUT = "INP4220"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { ErrorCode as E };
|
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/auth/index.ts
|
|
21
|
+
var auth_exports = {};
|
|
22
|
+
__export(auth_exports, {
|
|
23
|
+
GOOGLE_EXCHANGE_CONFIG: () => GOOGLE_EXCHANGE_CONFIG,
|
|
24
|
+
SPOTIFY_EXCHANGE_CONFIG: () => SPOTIFY_EXCHANGE_CONFIG,
|
|
25
|
+
SessionProvider: () => SessionProvider,
|
|
26
|
+
clearSpotifyRequiredCached: () => clearSpotifyRequiredCached,
|
|
27
|
+
clearStoredRedirectUrl: () => clearStoredRedirectUrl,
|
|
28
|
+
createLogout: () => createLogout,
|
|
29
|
+
exchangeCodeWithBackend: () => exchangeCodeWithBackend,
|
|
30
|
+
getSpotifyRequiredCached: () => getSpotifyRequiredCached,
|
|
31
|
+
resolveRedirectUri: () => resolveRedirectUri,
|
|
32
|
+
setSpotifyRequiredCached: () => setSpotifyRequiredCached,
|
|
33
|
+
storeRedirectUrl: () => storeRedirectUrl,
|
|
34
|
+
useAuthCallback: () => useAuthCallback,
|
|
35
|
+
useLogout: () => useLogout,
|
|
36
|
+
useSession: () => useSession
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(auth_exports);
|
|
39
|
+
|
|
40
|
+
// src/auth/spotify-required-cache.ts
|
|
41
|
+
var SPOTIFY_REQUIRED_KEY = "spotify_required";
|
|
42
|
+
function getSpotifyRequiredCached() {
|
|
43
|
+
if (typeof window === "undefined") return false;
|
|
44
|
+
return sessionStorage.getItem(SPOTIFY_REQUIRED_KEY) === "1";
|
|
45
|
+
}
|
|
46
|
+
function setSpotifyRequiredCached() {
|
|
47
|
+
if (typeof window === "undefined") return;
|
|
48
|
+
sessionStorage.setItem(SPOTIFY_REQUIRED_KEY, "1");
|
|
49
|
+
}
|
|
50
|
+
function clearSpotifyRequiredCached() {
|
|
51
|
+
if (typeof window === "undefined") return;
|
|
52
|
+
sessionStorage.removeItem(SPOTIFY_REQUIRED_KEY);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/auth/SessionContext.tsx
|
|
56
|
+
var import_react = require("react");
|
|
57
|
+
|
|
58
|
+
// src/transport/query-client.ts
|
|
59
|
+
var import_react_query = require("@tanstack/react-query");
|
|
60
|
+
var queryClient = new import_react_query.QueryClient({
|
|
61
|
+
defaultOptions: {
|
|
62
|
+
queries: {
|
|
63
|
+
staleTime: 60 * 1e3,
|
|
64
|
+
// 1 minute
|
|
65
|
+
retry: false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// src/auth/SessionContext.tsx
|
|
71
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
72
|
+
var defaultSession = {
|
|
73
|
+
accessToken: null,
|
|
74
|
+
refreshToken: null,
|
|
75
|
+
expiresAt: null
|
|
76
|
+
};
|
|
77
|
+
var SESSION_STORAGE_KEY = "session";
|
|
78
|
+
var SessionContext = (0, import_react.createContext)(void 0);
|
|
79
|
+
function SessionProvider({ children }) {
|
|
80
|
+
const [session, setSessionState] = (0, import_react.useState)(defaultSession);
|
|
81
|
+
const [sessionRestored, setSessionRestored] = (0, import_react.useState)(false);
|
|
82
|
+
(0, import_react.useEffect)(() => {
|
|
83
|
+
const storedSession = localStorage.getItem(SESSION_STORAGE_KEY);
|
|
84
|
+
if (storedSession) {
|
|
85
|
+
try {
|
|
86
|
+
const parsed = JSON.parse(storedSession);
|
|
87
|
+
setSessionState(parsed);
|
|
88
|
+
if (parsed?.accessToken) {
|
|
89
|
+
queryClient.invalidateQueries();
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
localStorage.removeItem(SESSION_STORAGE_KEY);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
setSessionRestored(true);
|
|
96
|
+
}, []);
|
|
97
|
+
const setSession = (0, import_react.useCallback)((newSession) => {
|
|
98
|
+
setSessionState(newSession);
|
|
99
|
+
localStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(newSession));
|
|
100
|
+
}, []);
|
|
101
|
+
const clearSession = (0, import_react.useCallback)(() => {
|
|
102
|
+
setSessionState(defaultSession);
|
|
103
|
+
localStorage.removeItem(SESSION_STORAGE_KEY);
|
|
104
|
+
clearSpotifyRequiredCached();
|
|
105
|
+
queryClient.clear();
|
|
106
|
+
}, []);
|
|
107
|
+
const value = (0, import_react.useMemo)(
|
|
108
|
+
() => ({ session, setSession, clearSession, sessionRestored }),
|
|
109
|
+
[session, setSession, clearSession, sessionRestored]
|
|
110
|
+
);
|
|
111
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SessionContext.Provider, { value, children });
|
|
112
|
+
}
|
|
113
|
+
function useSession() {
|
|
114
|
+
const context = (0, import_react.useContext)(SessionContext);
|
|
115
|
+
if (context === void 0) {
|
|
116
|
+
throw new Error("useSession must be used within a SessionProvider");
|
|
117
|
+
}
|
|
118
|
+
return context;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/transport/app-errors/app-error-messages.ts
|
|
122
|
+
function getSpotifyAllowlistMessage() {
|
|
123
|
+
return "Your Spotify account is not yet authorized for this app.";
|
|
124
|
+
}
|
|
125
|
+
var ErrorMessages = {
|
|
126
|
+
// Network Errors
|
|
127
|
+
["NET1000" /* NETWORK_OFFLINE */]: "Network connection unavailable",
|
|
128
|
+
["NET1001" /* NETWORK_TIMEOUT */]: "Request timed out",
|
|
129
|
+
["NET1002" /* NETWORK_CONNECTION_REFUSED */]: "Connection refused",
|
|
130
|
+
["NET1003" /* NETWORK_NOT_FOUND */]: "Network not found",
|
|
131
|
+
["NET1004" /* NETWORK_ERROR */]: "Network error occurred",
|
|
132
|
+
["NET1005" /* NETWORK_FETCH_ERROR */]: "Failed to fetch data",
|
|
133
|
+
["NET1006" /* NETWORK_ABORT_ERROR */]: "Request aborted",
|
|
134
|
+
["NET1007" /* NETWORK_FAILED_TO_FETCH */]: "Failed to fetch",
|
|
135
|
+
["NET1008" /* NETWORK_UNKNOWN */]: "Unknown network error",
|
|
136
|
+
// Backend Errors
|
|
137
|
+
["BAC2000" /* BACKEND_UNAVAILABLE */]: "Service temporarily unavailable",
|
|
138
|
+
["BAC2001" /* BACKEND_RATE_LIMIT */]: "Too many requests, please try again later",
|
|
139
|
+
["BAC2002" /* BACKEND_AUTH_ERROR */]: "Authentication failed",
|
|
140
|
+
["BAC5000" /* BACKEND_INTERNAL_ERROR */]: "Internal server error",
|
|
141
|
+
["BAC2003" /* BACKEND_INVALID_RESPONSE */]: "Invalid response from server",
|
|
142
|
+
["BAC4000" /* BACKEND_BAD_REQUEST */]: "Bad request",
|
|
143
|
+
["BAC4010" /* BACKEND_UNAUTHORIZED */]: "Unauthorized",
|
|
144
|
+
["BAC4030" /* BACKEND_FORBIDDEN */]: "Forbidden",
|
|
145
|
+
["BAC4031" /* BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED */]: "Connect Spotify to continue",
|
|
146
|
+
["BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */]: "Authorization code already used, expired, or invalid. Please try signing in again from the login page.",
|
|
147
|
+
["BAC4017" /* BACKEND_SPOTIFY_OAUTH_CODE_INVALID_OR_EXPIRED */]: "Authorization code already used, expired, or invalid. Please try signing in again from the login page.",
|
|
148
|
+
["BAC4018" /* BACKEND_SPOTIFY_OAUTH_INVALID_CLIENT */]: "Spotify sign-in is temporarily misconfigured. Please try again later or contact support.",
|
|
149
|
+
["BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */]: getSpotifyAllowlistMessage(),
|
|
150
|
+
["BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */]: "Spotify authentication failed",
|
|
151
|
+
["BAC4014" /* BACKEND_GOOGLE_AUTHENTICATION_ERROR */]: "Google authentication failed",
|
|
152
|
+
["BAC4015" /* BACKEND_GOOGLE_OAUTH_MISCONFIGURED */]: "Sign-in is temporarily misconfigured. Please try again later or contact support.",
|
|
153
|
+
["BAC4016" /* BACKEND_GOOGLE_OAUTH_UNAUTHORIZED_CLIENT */]: "Google sign-in is temporarily unavailable. Please try again later or contact support.",
|
|
154
|
+
["BAC4040" /* BACKEND_NOT_FOUND */]: "Not found",
|
|
155
|
+
["BAC4050" /* BACKEND_METHOD_NOT_ALLOWED */]: "Method not allowed",
|
|
156
|
+
["BAC4080" /* BACKEND_REQUEST_TIMEOUT */]: "Request timeout",
|
|
157
|
+
["INP4220" /* BACKEND_INVALID_INPUT */]: "Invalid input",
|
|
158
|
+
// Session Errors
|
|
159
|
+
["SES4011" /* SESSION_EXPIRED */]: "Session expired",
|
|
160
|
+
["SES4012" /* SESSION_REQUIRED */]: "Session required",
|
|
161
|
+
// Client Errors
|
|
162
|
+
["CLI5001" /* CLIENT_UNKNOWN */]: "Unknown error",
|
|
163
|
+
["CLI4030" /* CLIENT_FORBIDDEN */]: "Forbidden",
|
|
164
|
+
["CLI4040" /* CLIENT_NOT_FOUND */]: "Not found",
|
|
165
|
+
["CLI4010" /* CLIENT_UNAUTHORIZED */]: "Unauthorized",
|
|
166
|
+
["CLI5000" /* CLIENT_INTERNAL_ERROR */]: "Internal client error",
|
|
167
|
+
// Service Errors
|
|
168
|
+
["SER4000" /* SERVICE_BAD_REQUEST */]: "Bad request",
|
|
169
|
+
["SER4010" /* SERVICE_UNAUTHORIZED */]: "Unauthorized",
|
|
170
|
+
["SER4030" /* SERVICE_FORBIDDEN */]: "Forbidden",
|
|
171
|
+
["SER4040" /* SERVICE_NOT_FOUND */]: "Not found",
|
|
172
|
+
["SER5000" /* SERVICE_INTERNAL_ERROR */]: "Internal server error",
|
|
173
|
+
["SER5001" /* SERVICE_UNKNOWN */]: "Unknown service error",
|
|
174
|
+
["SER4050" /* SERVICE_METHOD_NOT_ALLOWED */]: "Method not allowed",
|
|
175
|
+
["SER4080" /* SERVICE_REQUEST_TIMEOUT */]: "Request timeout"
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// src/transport/app-errors/app-error.ts
|
|
179
|
+
var AppError = class extends Error {
|
|
180
|
+
constructor(code) {
|
|
181
|
+
super(ErrorMessages[code]);
|
|
182
|
+
this.code = code;
|
|
183
|
+
this.name = "AppError";
|
|
184
|
+
}
|
|
185
|
+
code;
|
|
186
|
+
};
|
|
187
|
+
var ClientError = class extends AppError {
|
|
188
|
+
constructor(code) {
|
|
189
|
+
super(code);
|
|
190
|
+
this.name = "ClientError";
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
var InvalidInputError = class extends ClientError {
|
|
194
|
+
constructor(code, json) {
|
|
195
|
+
super(code);
|
|
196
|
+
this.json = json;
|
|
197
|
+
this.name = "InvalidInputError";
|
|
198
|
+
}
|
|
199
|
+
json;
|
|
200
|
+
toString() {
|
|
201
|
+
return `${super.toString()}
|
|
202
|
+
JSON: ${JSON.stringify(this.json, null, 2)}`;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
var ConnectivityError = class extends AppError {
|
|
206
|
+
constructor(code) {
|
|
207
|
+
super(code);
|
|
208
|
+
this.name = "ConnectivityError";
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var NetworkError = class extends ConnectivityError {
|
|
212
|
+
constructor(code) {
|
|
213
|
+
super(code);
|
|
214
|
+
this.name = "NetworkError";
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
var BackendError = class extends ConnectivityError {
|
|
218
|
+
constructor(code, backendMessage) {
|
|
219
|
+
super(code);
|
|
220
|
+
this.backendMessage = backendMessage;
|
|
221
|
+
this.name = "BackendError";
|
|
222
|
+
if (backendMessage) {
|
|
223
|
+
this.message = backendMessage;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
backendMessage;
|
|
227
|
+
};
|
|
228
|
+
var AuthRequired = class extends ConnectivityError {
|
|
229
|
+
constructor(code) {
|
|
230
|
+
super(code);
|
|
231
|
+
this.name = "AuthRequired";
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var ServiceError = class extends ConnectivityError {
|
|
235
|
+
constructor(code) {
|
|
236
|
+
super(code);
|
|
237
|
+
this.name = "ServiceError";
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// src/transport/app-errors/app-error-factory.ts
|
|
242
|
+
function createAppErrorFromErrorCode(code, json) {
|
|
243
|
+
if (["BAC4010" /* BACKEND_UNAUTHORIZED */, "SES4011" /* SESSION_EXPIRED */, "SES4012" /* SESSION_REQUIRED */].includes(code)) {
|
|
244
|
+
return new AuthRequired(code);
|
|
245
|
+
} else if (code.startsWith("NET")) {
|
|
246
|
+
return new NetworkError(code);
|
|
247
|
+
} else if (code.startsWith("BAC")) {
|
|
248
|
+
return new BackendError(code);
|
|
249
|
+
} else if (code.startsWith("CLI")) {
|
|
250
|
+
return new ClientError(code);
|
|
251
|
+
} else if (code.startsWith("SER")) {
|
|
252
|
+
return new ServiceError(code);
|
|
253
|
+
} else if (code.startsWith("INP")) {
|
|
254
|
+
return new InvalidInputError(code, json || {});
|
|
255
|
+
}
|
|
256
|
+
return new AppError(code);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/auth/code-exchange.ts
|
|
260
|
+
var SPOTIFY_EXCHANGE_CONFIG = {
|
|
261
|
+
endpoint: "auth/spotify/",
|
|
262
|
+
redirectStorageKey: "spotifyAuthRedirect",
|
|
263
|
+
rethrowErrorCodes: [
|
|
264
|
+
"BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */,
|
|
265
|
+
"BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */,
|
|
266
|
+
"BAC4018" /* BACKEND_SPOTIFY_OAUTH_INVALID_CLIENT */
|
|
267
|
+
]
|
|
268
|
+
};
|
|
269
|
+
var GOOGLE_EXCHANGE_CONFIG = {
|
|
270
|
+
endpoint: "auth/google/",
|
|
271
|
+
redirectStorageKey: "googleAuthRedirect",
|
|
272
|
+
rethrowErrorCodes: [
|
|
273
|
+
"BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */,
|
|
274
|
+
"BAC4016" /* BACKEND_GOOGLE_OAUTH_UNAUTHORIZED_CLIENT */,
|
|
275
|
+
"BAC4014" /* BACKEND_GOOGLE_AUTHENTICATION_ERROR */,
|
|
276
|
+
"BAC4015" /* BACKEND_GOOGLE_OAUTH_MISCONFIGURED */
|
|
277
|
+
]
|
|
278
|
+
};
|
|
279
|
+
async function exchangeCodeWithBackend(fetchAuth, setSession, setConnectivityError, config, code) {
|
|
280
|
+
const { endpoint, redirectStorageKey, rethrowErrorCodes } = config;
|
|
281
|
+
const setBackendAuthError = () => setConnectivityError(createAppErrorFromErrorCode("BAC2002" /* BACKEND_AUTH_ERROR */));
|
|
282
|
+
try {
|
|
283
|
+
const response = await fetchAuth(endpoint, true, false, {
|
|
284
|
+
method: "POST",
|
|
285
|
+
body: JSON.stringify({ code })
|
|
286
|
+
});
|
|
287
|
+
if (!response) {
|
|
288
|
+
setBackendAuthError();
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
setSession({
|
|
292
|
+
accessToken: response.accessToken,
|
|
293
|
+
refreshToken: response.refreshToken,
|
|
294
|
+
expiresAt: response.expiresAt
|
|
295
|
+
});
|
|
296
|
+
const stored = localStorage.getItem(redirectStorageKey);
|
|
297
|
+
if (stored) {
|
|
298
|
+
localStorage.removeItem(redirectStorageKey);
|
|
299
|
+
try {
|
|
300
|
+
const url = new URL(stored);
|
|
301
|
+
return url.pathname + url.search;
|
|
302
|
+
} catch {
|
|
303
|
+
return "/";
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return "/";
|
|
307
|
+
} catch (e) {
|
|
308
|
+
if (e instanceof BackendError && rethrowErrorCodes.includes(e.code)) {
|
|
309
|
+
throw e;
|
|
310
|
+
}
|
|
311
|
+
console.error("[auth] exchangeCodeWithBackend error", e);
|
|
312
|
+
setBackendAuthError();
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function resolveRedirectUri(redirectUriEnv) {
|
|
317
|
+
return redirectUriEnv.startsWith("http") ? redirectUriEnv : `${window.location.origin}${redirectUriEnv.startsWith("/") ? "" : "/"}${redirectUriEnv}`;
|
|
318
|
+
}
|
|
319
|
+
function storeRedirectUrl(redirectStorageKey, redirectAfterAuthPath) {
|
|
320
|
+
const path = typeof redirectAfterAuthPath === "string" ? redirectAfterAuthPath : void 0;
|
|
321
|
+
const urlToStore = path ? `${window.location.origin}${path.startsWith("/") ? "" : "/"}${path}` : window.location.href;
|
|
322
|
+
localStorage.setItem(redirectStorageKey, urlToStore);
|
|
323
|
+
}
|
|
324
|
+
function clearStoredRedirectUrl(redirectStorageKey) {
|
|
325
|
+
localStorage.removeItem(redirectStorageKey);
|
|
326
|
+
}
|
|
327
|
+
function createLogout(clearConnectivityError, clearSession) {
|
|
328
|
+
return () => {
|
|
329
|
+
clearConnectivityError();
|
|
330
|
+
clearSession();
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// src/auth/useLogout.ts
|
|
335
|
+
var import_react3 = require("react");
|
|
336
|
+
|
|
337
|
+
// src/transport/connectivity-error-context.tsx
|
|
338
|
+
var import_react2 = require("react");
|
|
339
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
340
|
+
var ConnectivityErrorContext = (0, import_react2.createContext)(void 0);
|
|
341
|
+
function useConnectivityError() {
|
|
342
|
+
const context = (0, import_react2.useContext)(ConnectivityErrorContext);
|
|
343
|
+
if (context === void 0) {
|
|
344
|
+
throw new Error("useConnectivityError must be used within a ConnectivityErrorProvider");
|
|
345
|
+
}
|
|
346
|
+
return context;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/auth/useLogout.ts
|
|
350
|
+
function useLogout() {
|
|
351
|
+
const { clearSession } = useSession();
|
|
352
|
+
const { clearConnectivityError } = useConnectivityError();
|
|
353
|
+
const logout = (0, import_react3.useCallback)(
|
|
354
|
+
createLogout(clearConnectivityError, clearSession),
|
|
355
|
+
[clearConnectivityError, clearSession]
|
|
356
|
+
);
|
|
357
|
+
return { logout };
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/auth/useAuthCallback.ts
|
|
361
|
+
var import_react4 = require("react");
|
|
362
|
+
var import_navigation = require("next/navigation");
|
|
363
|
+
function useAuthCallback({
|
|
364
|
+
googleCallbackPathname = "/auth/google/callback",
|
|
365
|
+
spotifyCallbackPathname = "/auth/spotify/callback",
|
|
366
|
+
authToBackendFromGoogleCode,
|
|
367
|
+
authToBackendFromSpotifyCode,
|
|
368
|
+
onReauthRequired,
|
|
369
|
+
onOAuthMisconfigured,
|
|
370
|
+
onSpotifyAuthError
|
|
371
|
+
}) {
|
|
372
|
+
const router = (0, import_navigation.useRouter)();
|
|
373
|
+
const [state, setState] = (0, import_react4.useState)("idle");
|
|
374
|
+
const [errorMessage, setErrorMessage] = (0, import_react4.useState)(null);
|
|
375
|
+
const handled = (0, import_react4.useRef)(false);
|
|
376
|
+
(0, import_react4.useEffect)(() => {
|
|
377
|
+
if (typeof window === "undefined" || handled.current) return;
|
|
378
|
+
const pathname = window.location.pathname;
|
|
379
|
+
const params = new URLSearchParams(window.location.search);
|
|
380
|
+
const code = params.get("code");
|
|
381
|
+
const errorParam = params.get("error");
|
|
382
|
+
const isGoogleCallback = pathname === googleCallbackPathname;
|
|
383
|
+
const isSpotifyCallback = pathname === spotifyCallbackPathname;
|
|
384
|
+
if (!isGoogleCallback && !isSpotifyCallback) return;
|
|
385
|
+
handled.current = true;
|
|
386
|
+
setState("handling");
|
|
387
|
+
const runGoogle = async () => {
|
|
388
|
+
if (errorParam) {
|
|
389
|
+
setErrorMessage(`Google authentication failed: ${errorParam}`);
|
|
390
|
+
setState("error");
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (!code) {
|
|
394
|
+
setErrorMessage("No authorization code received from Google");
|
|
395
|
+
setState("error");
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
try {
|
|
399
|
+
const redirectUrl = await authToBackendFromGoogleCode(code);
|
|
400
|
+
setState("done");
|
|
401
|
+
router.replace(redirectUrl || "/");
|
|
402
|
+
} catch (err) {
|
|
403
|
+
if (err instanceof BackendError && err.code === "BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */) {
|
|
404
|
+
clearStoredRedirectUrl(GOOGLE_EXCHANGE_CONFIG.redirectStorageKey);
|
|
405
|
+
onReauthRequired();
|
|
406
|
+
router.replace("/");
|
|
407
|
+
} else if (err instanceof BackendError && err.code === "BAC4016" /* BACKEND_GOOGLE_OAUTH_UNAUTHORIZED_CLIENT */) {
|
|
408
|
+
onOAuthMisconfigured(err.code);
|
|
409
|
+
router.replace("/");
|
|
410
|
+
} else {
|
|
411
|
+
setErrorMessage(err instanceof Error ? err.message : "Authentication failed");
|
|
412
|
+
setState("error");
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
const runSpotify = async () => {
|
|
417
|
+
if (errorParam) {
|
|
418
|
+
onSpotifyAuthError(`Spotify authentication failed: ${errorParam}`, () => router.replace("/"));
|
|
419
|
+
setState("done");
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (!code) {
|
|
423
|
+
onSpotifyAuthError("No authorization code received from Spotify", () => router.replace("/"));
|
|
424
|
+
setState("done");
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
try {
|
|
428
|
+
const redirectUrl = await authToBackendFromSpotifyCode(code);
|
|
429
|
+
setState("done");
|
|
430
|
+
router.replace(redirectUrl || "/");
|
|
431
|
+
} catch (err) {
|
|
432
|
+
if (err instanceof BackendError && (err.code === "BAC4017" /* BACKEND_SPOTIFY_OAUTH_CODE_INVALID_OR_EXPIRED */ || err.code === "BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */)) {
|
|
433
|
+
clearStoredRedirectUrl(SPOTIFY_EXCHANGE_CONFIG.redirectStorageKey);
|
|
434
|
+
onReauthRequired();
|
|
435
|
+
router.replace("/");
|
|
436
|
+
} else if (err instanceof BackendError && err.code === "BAC4018" /* BACKEND_SPOTIFY_OAUTH_INVALID_CLIENT */) {
|
|
437
|
+
onOAuthMisconfigured(err.code);
|
|
438
|
+
router.replace("/");
|
|
439
|
+
} else {
|
|
440
|
+
const message = err instanceof BackendError ? err.code === "BAC2002" /* BACKEND_AUTH_ERROR */ ? "Failed to authenticate with the backend server." : err.message : "An unexpected error occurred.";
|
|
441
|
+
onSpotifyAuthError(message, () => router.replace("/"));
|
|
442
|
+
}
|
|
443
|
+
setState("done");
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
if (isGoogleCallback) runGoogle();
|
|
447
|
+
else runSpotify();
|
|
448
|
+
}, [
|
|
449
|
+
googleCallbackPathname,
|
|
450
|
+
spotifyCallbackPathname,
|
|
451
|
+
authToBackendFromGoogleCode,
|
|
452
|
+
authToBackendFromSpotifyCode,
|
|
453
|
+
onReauthRequired,
|
|
454
|
+
onOAuthMisconfigured,
|
|
455
|
+
onSpotifyAuthError,
|
|
456
|
+
router
|
|
457
|
+
]);
|
|
458
|
+
if (state === "handling") return { status: "pending" };
|
|
459
|
+
if (state === "error") return { status: "error", message: errorMessage, goHome: () => router.replace("/") };
|
|
460
|
+
return { status: null };
|
|
461
|
+
}
|
|
462
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
463
|
+
0 && (module.exports = {
|
|
464
|
+
GOOGLE_EXCHANGE_CONFIG,
|
|
465
|
+
SPOTIFY_EXCHANGE_CONFIG,
|
|
466
|
+
SessionProvider,
|
|
467
|
+
clearSpotifyRequiredCached,
|
|
468
|
+
clearStoredRedirectUrl,
|
|
469
|
+
createLogout,
|
|
470
|
+
exchangeCodeWithBackend,
|
|
471
|
+
getSpotifyRequiredCached,
|
|
472
|
+
resolveRedirectUri,
|
|
473
|
+
setSpotifyRequiredCached,
|
|
474
|
+
storeRedirectUrl,
|
|
475
|
+
useAuthCallback,
|
|
476
|
+
useLogout,
|
|
477
|
+
useSession
|
|
478
|
+
});
|
|
479
|
+
//# sourceMappingURL=index.cjs.map
|