@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.
Files changed (69) hide show
  1. package/LICENSE +15 -0
  2. package/dist/app-error-B8IoFBhD.d.ts +45 -0
  3. package/dist/app-error-codes-D5eYg7xR.d.ts +49 -0
  4. package/dist/auth/index.cjs +479 -0
  5. package/dist/auth/index.cjs.map +1 -0
  6. package/dist/auth/index.d.ts +83 -0
  7. package/dist/auth/index.js +36 -0
  8. package/dist/auth/index.js.map +1 -0
  9. package/dist/chunk-4MEK3CNF.js +246 -0
  10. package/dist/chunk-4MEK3CNF.js.map +1 -0
  11. package/dist/chunk-5NTNMBJP.js +25 -0
  12. package/dist/chunk-5NTNMBJP.js.map +1 -0
  13. package/dist/chunk-5YLNSX34.js +211 -0
  14. package/dist/chunk-5YLNSX34.js.map +1 -0
  15. package/dist/chunk-7EOS2K24.js +267 -0
  16. package/dist/chunk-7EOS2K24.js.map +1 -0
  17. package/dist/chunk-FYOLIMWU.js +25 -0
  18. package/dist/chunk-FYOLIMWU.js.map +1 -0
  19. package/dist/chunk-JMFEWI53.js +10 -0
  20. package/dist/chunk-JMFEWI53.js.map +1 -0
  21. package/dist/chunk-OGTDTTHJ.js +244 -0
  22. package/dist/chunk-OGTDTTHJ.js.map +1 -0
  23. package/dist/chunk-OIZPAN6I.js +356 -0
  24. package/dist/chunk-OIZPAN6I.js.map +1 -0
  25. package/dist/chunk-T4IDICOJ.js +1480 -0
  26. package/dist/chunk-T4IDICOJ.js.map +1 -0
  27. package/dist/chunk-T5D5T52J.js +271 -0
  28. package/dist/chunk-T5D5T52J.js.map +1 -0
  29. package/dist/chunk-TCXWV62L.js +1 -0
  30. package/dist/chunk-TCXWV62L.js.map +1 -0
  31. package/dist/genre-tree/index.cjs +2153 -0
  32. package/dist/genre-tree/index.cjs.map +1 -0
  33. package/dist/genre-tree/index.d.ts +3109 -0
  34. package/dist/genre-tree/index.js +181 -0
  35. package/dist/genre-tree/index.js.map +1 -0
  36. package/dist/genre-tree/testing.cjs +55 -0
  37. package/dist/genre-tree/testing.cjs.map +1 -0
  38. package/dist/genre-tree/testing.d.ts +7 -0
  39. package/dist/genre-tree/testing.js +27 -0
  40. package/dist/genre-tree/testing.js.map +1 -0
  41. package/dist/ids-D8XCErUS.d.ts +8 -0
  42. package/dist/index.cjs +3214 -0
  43. package/dist/index.cjs.map +1 -0
  44. package/dist/index.d.ts +13 -0
  45. package/dist/index.js +310 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/player/index.cjs +388 -0
  48. package/dist/player/index.cjs.map +1 -0
  49. package/dist/player/index.d.ts +108 -0
  50. package/dist/player/index.js +20 -0
  51. package/dist/player/index.js.map +1 -0
  52. package/dist/popup/index.cjs +403 -0
  53. package/dist/popup/index.cjs.map +1 -0
  54. package/dist/popup/index.d.ts +80 -0
  55. package/dist/popup/index.js +16 -0
  56. package/dist/popup/index.js.map +1 -0
  57. package/dist/scope-BoMVOHmz.d.ts +4 -0
  58. package/dist/track-noun/index.cjs +53 -0
  59. package/dist/track-noun/index.cjs.map +1 -0
  60. package/dist/track-noun/index.d.ts +15 -0
  61. package/dist/track-noun/index.js +11 -0
  62. package/dist/track-noun/index.js.map +1 -0
  63. package/dist/transport/index.cjs +773 -0
  64. package/dist/transport/index.cjs.map +1 -0
  65. package/dist/transport/index.d.ts +203 -0
  66. package/dist/transport/index.js +69 -0
  67. package/dist/transport/index.js.map +1 -0
  68. package/package.json +97 -4
  69. package/README.md +0 -3
@@ -0,0 +1,403 @@
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/popup/index.ts
21
+ var popup_exports = {};
22
+ __export(popup_exports, {
23
+ AUTH_POPUP_TYPE: () => AUTH_POPUP_TYPE,
24
+ PopupProvider: () => PopupProvider,
25
+ useConnectivityErrorPopup: () => useConnectivityErrorPopup,
26
+ usePopup: () => usePopup,
27
+ useTrackUpload: () => useTrackUpload
28
+ });
29
+ module.exports = __toCommonJS(popup_exports);
30
+
31
+ // src/popup/PopupContext.tsx
32
+ var import_react = require("react");
33
+ var import_jsx_runtime = require("react/jsx-runtime");
34
+ var AUTH_POPUP_TYPE = "auth";
35
+ var PopupContext = (0, import_react.createContext)(void 0);
36
+ function PopupProvider({ children }) {
37
+ const [state, setState] = (0, import_react.useState)({ content: null, type: null });
38
+ const activePopup = state.content;
39
+ const showPopup = (0, import_react.useCallback)((popup, type) => {
40
+ setState({ content: popup, type: type ?? null });
41
+ }, []);
42
+ const hidePopup = (0, import_react.useCallback)((options) => {
43
+ if (options?.onlyIfType !== void 0) {
44
+ setState((prev) => prev.type === options.onlyIfType ? { content: null, type: null } : prev);
45
+ } else {
46
+ setState({ content: null, type: null });
47
+ }
48
+ }, []);
49
+ const value = (0, import_react.useMemo)(() => ({ showPopup, hidePopup, activePopup }), [showPopup, hidePopup, activePopup]);
50
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopupContext.Provider, { value, children });
51
+ }
52
+ function usePopup() {
53
+ const context = (0, import_react.useContext)(PopupContext);
54
+ if (context === void 0) {
55
+ throw new Error("usePopup must be used within a PopupProvider");
56
+ }
57
+ return context;
58
+ }
59
+
60
+ // src/popup/useConnectivityErrorPopup.ts
61
+ var import_react3 = require("react");
62
+
63
+ // src/transport/app-errors/app-error-messages.ts
64
+ function getSpotifyAllowlistMessage() {
65
+ return "Your Spotify account is not yet authorized for this app.";
66
+ }
67
+ var ErrorMessages = {
68
+ // Network Errors
69
+ ["NET1000" /* NETWORK_OFFLINE */]: "Network connection unavailable",
70
+ ["NET1001" /* NETWORK_TIMEOUT */]: "Request timed out",
71
+ ["NET1002" /* NETWORK_CONNECTION_REFUSED */]: "Connection refused",
72
+ ["NET1003" /* NETWORK_NOT_FOUND */]: "Network not found",
73
+ ["NET1004" /* NETWORK_ERROR */]: "Network error occurred",
74
+ ["NET1005" /* NETWORK_FETCH_ERROR */]: "Failed to fetch data",
75
+ ["NET1006" /* NETWORK_ABORT_ERROR */]: "Request aborted",
76
+ ["NET1007" /* NETWORK_FAILED_TO_FETCH */]: "Failed to fetch",
77
+ ["NET1008" /* NETWORK_UNKNOWN */]: "Unknown network error",
78
+ // Backend Errors
79
+ ["BAC2000" /* BACKEND_UNAVAILABLE */]: "Service temporarily unavailable",
80
+ ["BAC2001" /* BACKEND_RATE_LIMIT */]: "Too many requests, please try again later",
81
+ ["BAC2002" /* BACKEND_AUTH_ERROR */]: "Authentication failed",
82
+ ["BAC5000" /* BACKEND_INTERNAL_ERROR */]: "Internal server error",
83
+ ["BAC2003" /* BACKEND_INVALID_RESPONSE */]: "Invalid response from server",
84
+ ["BAC4000" /* BACKEND_BAD_REQUEST */]: "Bad request",
85
+ ["BAC4010" /* BACKEND_UNAUTHORIZED */]: "Unauthorized",
86
+ ["BAC4030" /* BACKEND_FORBIDDEN */]: "Forbidden",
87
+ ["BAC4031" /* BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED */]: "Connect Spotify to continue",
88
+ ["BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */]: "Authorization code already used, expired, or invalid. Please try signing in again from the login page.",
89
+ ["BAC4017" /* BACKEND_SPOTIFY_OAUTH_CODE_INVALID_OR_EXPIRED */]: "Authorization code already used, expired, or invalid. Please try signing in again from the login page.",
90
+ ["BAC4018" /* BACKEND_SPOTIFY_OAUTH_INVALID_CLIENT */]: "Spotify sign-in is temporarily misconfigured. Please try again later or contact support.",
91
+ ["BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */]: getSpotifyAllowlistMessage(),
92
+ ["BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */]: "Spotify authentication failed",
93
+ ["BAC4014" /* BACKEND_GOOGLE_AUTHENTICATION_ERROR */]: "Google authentication failed",
94
+ ["BAC4015" /* BACKEND_GOOGLE_OAUTH_MISCONFIGURED */]: "Sign-in is temporarily misconfigured. Please try again later or contact support.",
95
+ ["BAC4016" /* BACKEND_GOOGLE_OAUTH_UNAUTHORIZED_CLIENT */]: "Google sign-in is temporarily unavailable. Please try again later or contact support.",
96
+ ["BAC4040" /* BACKEND_NOT_FOUND */]: "Not found",
97
+ ["BAC4050" /* BACKEND_METHOD_NOT_ALLOWED */]: "Method not allowed",
98
+ ["BAC4080" /* BACKEND_REQUEST_TIMEOUT */]: "Request timeout",
99
+ ["INP4220" /* BACKEND_INVALID_INPUT */]: "Invalid input",
100
+ // Session Errors
101
+ ["SES4011" /* SESSION_EXPIRED */]: "Session expired",
102
+ ["SES4012" /* SESSION_REQUIRED */]: "Session required",
103
+ // Client Errors
104
+ ["CLI5001" /* CLIENT_UNKNOWN */]: "Unknown error",
105
+ ["CLI4030" /* CLIENT_FORBIDDEN */]: "Forbidden",
106
+ ["CLI4040" /* CLIENT_NOT_FOUND */]: "Not found",
107
+ ["CLI4010" /* CLIENT_UNAUTHORIZED */]: "Unauthorized",
108
+ ["CLI5000" /* CLIENT_INTERNAL_ERROR */]: "Internal client error",
109
+ // Service Errors
110
+ ["SER4000" /* SERVICE_BAD_REQUEST */]: "Bad request",
111
+ ["SER4010" /* SERVICE_UNAUTHORIZED */]: "Unauthorized",
112
+ ["SER4030" /* SERVICE_FORBIDDEN */]: "Forbidden",
113
+ ["SER4040" /* SERVICE_NOT_FOUND */]: "Not found",
114
+ ["SER5000" /* SERVICE_INTERNAL_ERROR */]: "Internal server error",
115
+ ["SER5001" /* SERVICE_UNKNOWN */]: "Unknown service error",
116
+ ["SER4050" /* SERVICE_METHOD_NOT_ALLOWED */]: "Method not allowed",
117
+ ["SER4080" /* SERVICE_REQUEST_TIMEOUT */]: "Request timeout"
118
+ };
119
+
120
+ // src/transport/app-errors/app-error.ts
121
+ var AppError = class extends Error {
122
+ constructor(code) {
123
+ super(ErrorMessages[code]);
124
+ this.code = code;
125
+ this.name = "AppError";
126
+ }
127
+ code;
128
+ };
129
+ var ClientError = class extends AppError {
130
+ constructor(code) {
131
+ super(code);
132
+ this.name = "ClientError";
133
+ }
134
+ };
135
+ var InvalidInputError = class extends ClientError {
136
+ constructor(code, json) {
137
+ super(code);
138
+ this.json = json;
139
+ this.name = "InvalidInputError";
140
+ }
141
+ json;
142
+ toString() {
143
+ return `${super.toString()}
144
+ JSON: ${JSON.stringify(this.json, null, 2)}`;
145
+ }
146
+ };
147
+ var ConnectivityError = class extends AppError {
148
+ constructor(code) {
149
+ super(code);
150
+ this.name = "ConnectivityError";
151
+ }
152
+ };
153
+ var BadRequestError = class extends ConnectivityError {
154
+ constructor(code) {
155
+ super(code);
156
+ this.name = "BadRequestError";
157
+ }
158
+ };
159
+ var NetworkError = class extends ConnectivityError {
160
+ constructor(code) {
161
+ super(code);
162
+ this.name = "NetworkError";
163
+ }
164
+ };
165
+ var BackendError = class extends ConnectivityError {
166
+ constructor(code, backendMessage) {
167
+ super(code);
168
+ this.backendMessage = backendMessage;
169
+ this.name = "BackendError";
170
+ if (backendMessage) {
171
+ this.message = backendMessage;
172
+ }
173
+ }
174
+ backendMessage;
175
+ };
176
+ var AuthRequired = class extends ConnectivityError {
177
+ constructor(code) {
178
+ super(code);
179
+ this.name = "AuthRequired";
180
+ }
181
+ };
182
+ var ServiceError = class extends ConnectivityError {
183
+ constructor(code) {
184
+ super(code);
185
+ this.name = "ServiceError";
186
+ }
187
+ };
188
+
189
+ // src/transport/connectivity-error-context.tsx
190
+ var import_react2 = require("react");
191
+ var import_jsx_runtime2 = require("react/jsx-runtime");
192
+ var ConnectivityErrorContext = (0, import_react2.createContext)(void 0);
193
+ function useConnectivityError() {
194
+ const context = (0, import_react2.useContext)(ConnectivityErrorContext);
195
+ if (context === void 0) {
196
+ throw new Error("useConnectivityError must be used within a ConnectivityErrorProvider");
197
+ }
198
+ return context;
199
+ }
200
+
201
+ // src/popup/useConnectivityErrorPopup.ts
202
+ var ALWAYS_REDISPLAY_ON_REPEAT = [NetworkError, BackendError, ClientError, ServiceError, InvalidInputError];
203
+ function useConnectivityErrorPopup({
204
+ isAccountPage,
205
+ routeRequiresAuth,
206
+ routeRequiresSpotify,
207
+ renderers
208
+ }) {
209
+ const { showPopup, hidePopup } = usePopup();
210
+ const { connectivityError, clearConnectivityError } = useConnectivityError();
211
+ const currentConnectivityErrorRef = (0, import_react3.useRef)(null);
212
+ const renderersRef = (0, import_react3.useRef)(renderers);
213
+ renderersRef.current = renderers;
214
+ (0, import_react3.useEffect)(() => {
215
+ if (connectivityError === null) {
216
+ if (currentConnectivityErrorRef.current !== null) {
217
+ currentConnectivityErrorRef.current = null;
218
+ hidePopup();
219
+ }
220
+ return;
221
+ }
222
+ const error = connectivityError;
223
+ const isSpotifyAllowlistOrAuthError = error instanceof BackendError && ["BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */, "BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */].includes(
224
+ error.code
225
+ );
226
+ if (isSpotifyAllowlistOrAuthError && !routeRequiresSpotify) {
227
+ hidePopup();
228
+ clearConnectivityError();
229
+ currentConnectivityErrorRef.current = null;
230
+ return;
231
+ }
232
+ if (currentConnectivityErrorRef.current == null || !ALWAYS_REDISPLAY_ON_REPEAT.includes(currentConnectivityErrorRef.current) && !(connectivityError instanceof currentConnectivityErrorRef.current)) {
233
+ const renderer = renderersRef.current;
234
+ let popup = null;
235
+ let popupType = null;
236
+ if (!isAccountPage && routeRequiresAuth && error instanceof AuthRequired) {
237
+ popup = renderer.renderAuthPopup();
238
+ popupType = AUTH_POPUP_TYPE;
239
+ } else if (!isAccountPage && routeRequiresSpotify && error instanceof BackendError && error.code === "BAC4031" /* BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED */) {
240
+ popup = renderer.renderSpotifyOnlyAuthPopup();
241
+ popupType = AUTH_POPUP_TYPE;
242
+ } else if (error instanceof InvalidInputError) {
243
+ console.error("[InvalidInputError]", error.code, error.json);
244
+ popup = renderer.renderInternalErrorPopup(error.code);
245
+ } else if (routeRequiresSpotify && error instanceof BackendError && ["BAC4012" /* BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST */, "BAC4013" /* BACKEND_SPOTIFY_AUTHENTICATION_ERROR */].includes(
246
+ error.code
247
+ )) {
248
+ popup = renderer.renderSpotifyAuthErrorPopup({
249
+ message: error.message,
250
+ errorCode: error.code,
251
+ onClose: () => hidePopup()
252
+ });
253
+ } else if (error instanceof BackendError && [
254
+ "BAC4014" /* BACKEND_GOOGLE_AUTHENTICATION_ERROR */,
255
+ "BAC4015" /* BACKEND_GOOGLE_OAUTH_MISCONFIGURED */,
256
+ "BAC4011" /* BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED */
257
+ ].includes(error.code)) {
258
+ popup = renderer.renderGoogleAuthErrorPopup({ message: error.message, onClose: () => hidePopup() });
259
+ } else if (error instanceof BadRequestError || error instanceof BackendError || error instanceof ServiceError || error instanceof AuthRequired) {
260
+ popup = renderer.renderInternalErrorPopup(error.code);
261
+ } else if (error instanceof NetworkError) {
262
+ popup = renderer.renderNetworkErrorPopup();
263
+ }
264
+ if (popup) {
265
+ showPopup(popup, popupType);
266
+ }
267
+ currentConnectivityErrorRef.current = error.constructor;
268
+ }
269
+ }, [
270
+ connectivityError,
271
+ showPopup,
272
+ hidePopup,
273
+ clearConnectivityError,
274
+ isAccountPage,
275
+ routeRequiresAuth,
276
+ routeRequiresSpotify
277
+ ]);
278
+ }
279
+
280
+ // src/popup/useTrackUpload.ts
281
+ var import_react4 = require("react");
282
+ function useTrackUpload({
283
+ files,
284
+ genre,
285
+ onProcessFile,
286
+ onComplete,
287
+ uploadTimeoutMs
288
+ }) {
289
+ const [items, setItems] = (0, import_react4.useState)([]);
290
+ const [currentUploadIndex, setCurrentUploadIndex] = (0, import_react4.useState)(0);
291
+ const [isUploading, setIsUploading] = (0, import_react4.useState)(false);
292
+ const [allComplete, setAllComplete] = (0, import_react4.useState)(false);
293
+ const lastFilesKeyRef = (0, import_react4.useRef)(null);
294
+ const progressIntervalRef = (0, import_react4.useRef)(null);
295
+ const runRef = (0, import_react4.useRef)(0);
296
+ const completedRunRef = (0, import_react4.useRef)(null);
297
+ (0, import_react4.useEffect)(() => {
298
+ const filesKey = `${files.length}-${files.map((f) => `${f.name}:${f.size}`).join("|")}-${genre ?? ""}`;
299
+ if (lastFilesKeyRef.current === filesKey) return;
300
+ lastFilesKeyRef.current = filesKey;
301
+ runRef.current += 1;
302
+ if (progressIntervalRef.current) {
303
+ clearInterval(progressIntervalRef.current);
304
+ progressIntervalRef.current = null;
305
+ }
306
+ setItems(
307
+ files.map((file, index) => ({
308
+ id: `upload-${index}-${file.name}`,
309
+ file,
310
+ genre: genre ?? null,
311
+ status: "pending",
312
+ progress: 0
313
+ }))
314
+ );
315
+ setCurrentUploadIndex(0);
316
+ setIsUploading(false);
317
+ setAllComplete(false);
318
+ }, [files, genre]);
319
+ const startNextUpload = (0, import_react4.useCallback)(() => {
320
+ const currentItem = items[currentUploadIndex];
321
+ setIsUploading(true);
322
+ setItems(
323
+ (prev) => prev.map((item, index) => index === currentUploadIndex ? { ...item, status: "uploading", progress: 0 } : item)
324
+ );
325
+ if (progressIntervalRef.current) clearInterval(progressIntervalRef.current);
326
+ progressIntervalRef.current = setInterval(() => {
327
+ setItems(
328
+ (prev) => prev.map(
329
+ (item, index) => index === currentUploadIndex && item.status === "uploading" ? { ...item, progress: Math.min(item.progress + Math.random() * 8, 99) } : item
330
+ )
331
+ );
332
+ }, 800);
333
+ const uploadingIndex = currentUploadIndex;
334
+ const run = runRef.current;
335
+ const timeoutPromise = new Promise((_, reject) => {
336
+ setTimeout(() => reject(new Error("Upload timed out. The server took too long to respond.")), uploadTimeoutMs);
337
+ });
338
+ Promise.race([onProcessFile(currentItem.file, currentItem.genre), timeoutPromise]).then((data) => {
339
+ if (run !== runRef.current) return;
340
+ if (progressIntervalRef.current) {
341
+ clearInterval(progressIntervalRef.current);
342
+ progressIntervalRef.current = null;
343
+ }
344
+ setItems(
345
+ (prev) => prev.map(
346
+ (item, index) => index === uploadingIndex ? { ...item, status: "success", progress: 100, uploadedTrack: data } : item
347
+ )
348
+ );
349
+ setIsUploading(false);
350
+ setCurrentUploadIndex((prev) => prev + 1);
351
+ }).catch((error) => {
352
+ if (run !== runRef.current) return;
353
+ if (progressIntervalRef.current) {
354
+ clearInterval(progressIntervalRef.current);
355
+ progressIntervalRef.current = null;
356
+ }
357
+ setItems(
358
+ (prev) => prev.map((item, index) => index === uploadingIndex ? { ...item, status: "error", error } : item)
359
+ );
360
+ setIsUploading(false);
361
+ setCurrentUploadIndex((prev) => prev + 1);
362
+ });
363
+ }, [items, currentUploadIndex, onProcessFile, uploadTimeoutMs]);
364
+ (0, import_react4.useEffect)(() => {
365
+ return () => {
366
+ if (progressIntervalRef.current) {
367
+ clearInterval(progressIntervalRef.current);
368
+ progressIntervalRef.current = null;
369
+ }
370
+ };
371
+ }, []);
372
+ (0, import_react4.useEffect)(() => {
373
+ const shouldStart = items.length > 0 && !isUploading && currentUploadIndex < items.length;
374
+ if (shouldStart) {
375
+ startNextUpload();
376
+ }
377
+ }, [items, currentUploadIndex, isUploading, startNextUpload]);
378
+ (0, import_react4.useEffect)(() => {
379
+ if (items.length > 0 && currentUploadIndex >= items.length && !isUploading) {
380
+ if (completedRunRef.current === runRef.current) return;
381
+ completedRunRef.current = runRef.current;
382
+ setAllComplete(true);
383
+ const successfulTracks = items.filter((item) => item.status === "success" && item.uploadedTrack).map((item) => item.uploadedTrack);
384
+ onComplete?.(successfulTracks);
385
+ }
386
+ }, [items, currentUploadIndex, isUploading, onComplete]);
387
+ return {
388
+ items,
389
+ isUploading,
390
+ allComplete,
391
+ successfulCount: items.filter((item) => item.status === "success").length,
392
+ errorCount: items.filter((item) => item.status === "error").length
393
+ };
394
+ }
395
+ // Annotate the CommonJS export names for ESM import in node:
396
+ 0 && (module.exports = {
397
+ AUTH_POPUP_TYPE,
398
+ PopupProvider,
399
+ useConnectivityErrorPopup,
400
+ usePopup,
401
+ useTrackUpload
402
+ });
403
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/popup/index.ts","../../src/popup/PopupContext.tsx","../../src/popup/useConnectivityErrorPopup.ts","../../src/transport/app-errors/app-error-messages.ts","../../src/transport/app-errors/app-error.ts","../../src/transport/connectivity-error-context.tsx","../../src/popup/useTrackUpload.ts"],"sourcesContent":["export * from \"./PopupContext\";\nexport * from \"./useConnectivityErrorPopup\";\nexport * from \"./useTrackUpload\";\n","\"use client\";\n\nimport { createContext, useContext, useState, useCallback, useMemo, ReactNode } from \"react\";\n\nexport const AUTH_POPUP_TYPE = \"auth\";\n\ninterface PopupState {\n content: ReactNode;\n type: string | null;\n}\n\ninterface HidePopupOptions {\n onlyIfType?: string;\n}\n\ninterface PopupContextType {\n showPopup: (popup: ReactNode, type?: string | null) => void;\n hidePopup: (options?: HidePopupOptions) => void;\n activePopup: ReactNode | null;\n}\n\nconst PopupContext = createContext<PopupContextType | undefined>(undefined);\n\ninterface PopupProviderProps {\n children: ReactNode;\n}\n\nexport function PopupProvider({ children }: PopupProviderProps) {\n const [state, setState] = useState<PopupState>({ content: null, type: null });\n const activePopup = state.content;\n\n const showPopup = useCallback((popup: ReactNode, type?: string | null) => {\n setState({ content: popup, type: type ?? null });\n }, []);\n\n const hidePopup = useCallback((options?: HidePopupOptions) => {\n if (options?.onlyIfType !== undefined) {\n setState((prev) => (prev.type === options.onlyIfType ? { content: null, type: null } : prev));\n } else {\n setState({ content: null, type: null });\n }\n }, []);\n\n const value = useMemo(() => ({ showPopup, hidePopup, activePopup }), [showPopup, hidePopup, activePopup]);\n\n return <PopupContext.Provider value={value}>{children}</PopupContext.Provider>;\n}\n\nexport function usePopup() {\n const context = useContext(PopupContext);\n if (context === undefined) {\n throw new Error(\"usePopup must be used within a PopupProvider\");\n }\n return context;\n}\n","\"use client\";\n\nimport { ReactNode, useEffect, useRef } from \"react\";\nimport {\n AuthRequired,\n BackendError,\n BadRequestError,\n ClientError,\n ConnectivityError,\n InvalidInputError,\n NetworkError,\n ServiceError,\n} from \"../transport/app-errors/app-error\";\nimport { ErrorCode } from \"../transport/app-errors/app-error-codes\";\nimport { useConnectivityError } from \"../transport/connectivity-error-context\";\nimport { AUTH_POPUP_TYPE, usePopup } from \"./PopupContext\";\n\nexport interface ConnectivityErrorPopupRenderers {\n renderAuthPopup: () => ReactNode;\n renderSpotifyOnlyAuthPopup: () => ReactNode;\n renderInternalErrorPopup: (errorCode: ErrorCode) => ReactNode;\n renderSpotifyAuthErrorPopup: (params: { message: string; errorCode: ErrorCode; onClose: () => void }) => ReactNode;\n renderGoogleAuthErrorPopup: (params: { message: string; onClose: () => void }) => ReactNode;\n renderNetworkErrorPopup: () => ReactNode;\n}\n\nexport interface UseConnectivityErrorPopupOptions {\n isAccountPage: boolean;\n routeRequiresAuth: boolean;\n routeRequiresSpotify: boolean;\n renderers: ConnectivityErrorPopupRenderers;\n}\n\nconst ALWAYS_REDISPLAY_ON_REPEAT = [NetworkError, BackendError, ClientError, ServiceError, InvalidInputError];\n\n/**\n * Classifies the shared connectivity-error state into the right popup and shows it. Consuming apps\n * supply the actual popup components via `renderers` since those are app-branded; this hook owns\n * only the error -> popup-kind decision, so a fix here (e.g. a route not requiring auth still\n * surfacing an unexpected AuthRequired) applies to every app instead of needing a per-app patch.\n */\nexport function useConnectivityErrorPopup({\n isAccountPage,\n routeRequiresAuth,\n routeRequiresSpotify,\n renderers,\n}: UseConnectivityErrorPopupOptions): void {\n const { showPopup, hidePopup } = usePopup();\n const { connectivityError, clearConnectivityError } = useConnectivityError();\n const currentConnectivityErrorRef = useRef<typeof ConnectivityError | null>(null);\n const renderersRef = useRef(renderers);\n renderersRef.current = renderers;\n\n useEffect(() => {\n if (connectivityError === null) {\n if (currentConnectivityErrorRef.current !== null) {\n currentConnectivityErrorRef.current = null;\n hidePopup();\n }\n return;\n }\n\n const error = connectivityError;\n const isSpotifyAllowlistOrAuthError =\n error instanceof BackendError &&\n [ErrorCode.BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST, ErrorCode.BACKEND_SPOTIFY_AUTHENTICATION_ERROR].includes(\n error.code,\n );\n\n if (isSpotifyAllowlistOrAuthError && !routeRequiresSpotify) {\n hidePopup();\n clearConnectivityError();\n currentConnectivityErrorRef.current = null;\n return;\n }\n\n if (\n currentConnectivityErrorRef.current == null ||\n (!ALWAYS_REDISPLAY_ON_REPEAT.includes(currentConnectivityErrorRef.current) &&\n !(connectivityError instanceof currentConnectivityErrorRef.current))\n ) {\n const renderer = renderersRef.current;\n let popup: ReactNode | null = null;\n let popupType: string | null = null;\n\n if (!isAccountPage && routeRequiresAuth && error instanceof AuthRequired) {\n popup = renderer.renderAuthPopup();\n popupType = AUTH_POPUP_TYPE;\n } else if (\n !isAccountPage &&\n routeRequiresSpotify &&\n error instanceof BackendError &&\n error.code === ErrorCode.BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED\n ) {\n popup = renderer.renderSpotifyOnlyAuthPopup();\n popupType = AUTH_POPUP_TYPE;\n } else if (error instanceof InvalidInputError) {\n console.error(\"[InvalidInputError]\", error.code, error.json);\n popup = renderer.renderInternalErrorPopup(error.code);\n } else if (\n routeRequiresSpotify &&\n error instanceof BackendError &&\n [ErrorCode.BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST, ErrorCode.BACKEND_SPOTIFY_AUTHENTICATION_ERROR].includes(\n error.code,\n )\n ) {\n popup = renderer.renderSpotifyAuthErrorPopup({\n message: error.message,\n errorCode: error.code,\n onClose: () => hidePopup(),\n });\n } else if (\n error instanceof BackendError &&\n [\n ErrorCode.BACKEND_GOOGLE_AUTHENTICATION_ERROR,\n ErrorCode.BACKEND_GOOGLE_OAUTH_MISCONFIGURED,\n ErrorCode.BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED,\n ].includes(error.code)\n ) {\n popup = renderer.renderGoogleAuthErrorPopup({ message: error.message, onClose: () => hidePopup() });\n } else if (\n error instanceof BadRequestError ||\n error instanceof BackendError ||\n error instanceof ServiceError ||\n error instanceof AuthRequired\n ) {\n // AuthRequired reaches here when the route doesn't require a session (e.g. a public\n // reference page) or is the account page, so the AuthPopup branch above didn't fire —\n // an unexpected 401 on those routes still needs to surface, not be dropped silently.\n popup = renderer.renderInternalErrorPopup(error.code);\n } else if (error instanceof NetworkError) {\n popup = renderer.renderNetworkErrorPopup();\n }\n\n if (popup) {\n showPopup(popup, popupType);\n }\n\n currentConnectivityErrorRef.current = error.constructor as typeof ConnectivityError;\n }\n }, [\n connectivityError,\n showPopup,\n hidePopup,\n clearConnectivityError,\n isAccountPage,\n routeRequiresAuth,\n routeRequiresSpotify,\n ]);\n}\n","import { ErrorCode } from \"./app-error-codes\";\n\nconst SPOTIFY_ACCESS_REQUEST_SUBJECT = \"Spotify access request\";\nconst SPOTIFY_ACCESS_REQUEST_BODY = `I would like to request access to the app.\n\nSpotify full name:\nSpotify email address:`;\n\nexport function getSpotifyAllowlistMessage(): string {\n return \"Your Spotify account is not yet authorized for this app.\";\n}\n\n/**\n * Reads a caller-supplied contact email (e.g. `process.env.NEXT_PUBLIC_CONTACT_EMAIL` in the\n * consuming app) rather than a hardcoded env var name, so this package stays app-agnostic.\n */\nexport function getSpotifyAllowlistMailtoHref(contactEmail: string | null | undefined): string | null {\n if (!contactEmail) return null;\n const params = new URLSearchParams({\n subject: SPOTIFY_ACCESS_REQUEST_SUBJECT,\n body: SPOTIFY_ACCESS_REQUEST_BODY,\n });\n return `mailto:${contactEmail}?${params.toString()}`;\n}\n\nexport const ErrorMessages: Record<ErrorCode, string> = {\n // Network Errors\n [ErrorCode.NETWORK_OFFLINE]: \"Network connection unavailable\",\n [ErrorCode.NETWORK_TIMEOUT]: \"Request timed out\",\n [ErrorCode.NETWORK_CONNECTION_REFUSED]: \"Connection refused\",\n [ErrorCode.NETWORK_NOT_FOUND]: \"Network not found\",\n [ErrorCode.NETWORK_ERROR]: \"Network error occurred\",\n [ErrorCode.NETWORK_FETCH_ERROR]: \"Failed to fetch data\",\n [ErrorCode.NETWORK_ABORT_ERROR]: \"Request aborted\",\n [ErrorCode.NETWORK_FAILED_TO_FETCH]: \"Failed to fetch\",\n [ErrorCode.NETWORK_UNKNOWN]: \"Unknown network error\",\n\n // Backend Errors\n [ErrorCode.BACKEND_UNAVAILABLE]: \"Service temporarily unavailable\",\n [ErrorCode.BACKEND_RATE_LIMIT]: \"Too many requests, please try again later\",\n [ErrorCode.BACKEND_AUTH_ERROR]: \"Authentication failed\",\n [ErrorCode.BACKEND_INTERNAL_ERROR]: \"Internal server error\",\n [ErrorCode.BACKEND_INVALID_RESPONSE]: \"Invalid response from server\",\n [ErrorCode.BACKEND_BAD_REQUEST]: \"Bad request\",\n [ErrorCode.BACKEND_UNAUTHORIZED]: \"Unauthorized\",\n [ErrorCode.BACKEND_FORBIDDEN]: \"Forbidden\",\n [ErrorCode.BACKEND_SPOTIFY_AUTHORIZATION_REQUIRED]: \"Connect Spotify to continue\",\n [ErrorCode.BACKEND_GOOGLE_OAUTH_CODE_INVALID_OR_EXPIRED]:\n \"Authorization code already used, expired, or invalid. Please try signing in again from the login page.\",\n [ErrorCode.BACKEND_SPOTIFY_OAUTH_CODE_INVALID_OR_EXPIRED]:\n \"Authorization code already used, expired, or invalid. Please try signing in again from the login page.\",\n [ErrorCode.BACKEND_SPOTIFY_OAUTH_INVALID_CLIENT]:\n \"Spotify sign-in is temporarily misconfigured. Please try again later or contact support.\",\n [ErrorCode.BACKEND_SPOTIFY_USER_NOT_IN_ALLOWLIST]: getSpotifyAllowlistMessage(),\n\n [ErrorCode.BACKEND_SPOTIFY_AUTHENTICATION_ERROR]: \"Spotify authentication failed\",\n [ErrorCode.BACKEND_GOOGLE_AUTHENTICATION_ERROR]: \"Google authentication failed\",\n [ErrorCode.BACKEND_GOOGLE_OAUTH_MISCONFIGURED]:\n \"Sign-in is temporarily misconfigured. Please try again later or contact support.\",\n [ErrorCode.BACKEND_GOOGLE_OAUTH_UNAUTHORIZED_CLIENT]:\n \"Google sign-in is temporarily unavailable. Please try again later or contact support.\",\n [ErrorCode.BACKEND_NOT_FOUND]: \"Not found\",\n [ErrorCode.BACKEND_METHOD_NOT_ALLOWED]: \"Method not allowed\",\n [ErrorCode.BACKEND_REQUEST_TIMEOUT]: \"Request timeout\",\n [ErrorCode.BACKEND_INVALID_INPUT]: \"Invalid input\",\n\n // Session Errors\n [ErrorCode.SESSION_EXPIRED]: \"Session expired\",\n [ErrorCode.SESSION_REQUIRED]: \"Session required\",\n\n // Client Errors\n [ErrorCode.CLIENT_UNKNOWN]: \"Unknown error\",\n [ErrorCode.CLIENT_FORBIDDEN]: \"Forbidden\",\n [ErrorCode.CLIENT_NOT_FOUND]: \"Not found\",\n [ErrorCode.CLIENT_UNAUTHORIZED]: \"Unauthorized\",\n [ErrorCode.CLIENT_INTERNAL_ERROR]: \"Internal client error\",\n\n // Service Errors\n [ErrorCode.SERVICE_BAD_REQUEST]: \"Bad request\",\n [ErrorCode.SERVICE_UNAUTHORIZED]: \"Unauthorized\",\n [ErrorCode.SERVICE_FORBIDDEN]: \"Forbidden\",\n [ErrorCode.SERVICE_NOT_FOUND]: \"Not found\",\n [ErrorCode.SERVICE_INTERNAL_ERROR]: \"Internal server error\",\n [ErrorCode.SERVICE_UNKNOWN]: \"Unknown service error\",\n [ErrorCode.SERVICE_METHOD_NOT_ALLOWED]: \"Method not allowed\",\n [ErrorCode.SERVICE_REQUEST_TIMEOUT]: \"Request timeout\",\n};\n","import { ErrorCode } from \"./app-error-codes\";\nimport { ErrorMessages } from \"./app-error-messages\";\n\nexport class AppError extends Error {\n constructor(public readonly code: ErrorCode) {\n super(ErrorMessages[code]);\n this.name = \"AppError\";\n }\n}\n\nexport class ClientError extends AppError {\n constructor(code: ErrorCode) {\n super(code);\n this.name = \"ClientError\";\n }\n}\n\nexport class InvalidInputError extends ClientError {\n constructor(code: ErrorCode, public readonly json: object) {\n super(code);\n this.name = \"InvalidInputError\";\n }\n\n toString(): string {\n return `${super.toString()}\\nJSON: ${JSON.stringify(this.json, null, 2)}`;\n }\n}\n\nexport class ConnectivityError extends AppError {\n constructor(code: ErrorCode) {\n super(code);\n this.name = \"ConnectivityError\";\n }\n}\n\nexport class BadRequestError extends ConnectivityError {\n constructor(code: ErrorCode) {\n super(code);\n this.name = \"BadRequestError\";\n }\n}\n\nexport class NetworkError extends ConnectivityError {\n constructor(code: ErrorCode) {\n super(code);\n this.name = \"NetworkError\";\n }\n}\n\nexport class BackendError extends ConnectivityError {\n constructor(\n code: ErrorCode,\n public readonly backendMessage?: string,\n ) {\n super(code);\n this.name = \"BackendError\";\n if (backendMessage) {\n this.message = backendMessage;\n }\n }\n}\n\nexport class BackendSpotifyUserNotAllowlistedError extends BackendError {\n constructor(\n code: ErrorCode,\n public readonly detailsMessage: string,\n ) {\n super(code);\n this.name = \"BackendSpotifyUserNotAllowlistedError\";\n }\n}\n\nexport class AuthRequired extends ConnectivityError {\n constructor(code: ErrorCode) {\n super(code);\n this.name = \"AuthRequired\";\n }\n}\n\nexport class ServiceError extends ConnectivityError {\n constructor(code: ErrorCode) {\n super(code);\n this.name = \"ServiceError\";\n }\n}\n\n/**\n * Union type of all error classes.\n * Required because TypeScript's type system doesn't automatically recognize\n * class inheritance for type checking in instanceof expressions.\n */\nexport type AppErrorType =\n | AppError\n | ClientError\n | ConnectivityError\n | BadRequestError\n | NetworkError\n | BackendError\n | BackendSpotifyUserNotAllowlistedError\n | AuthRequired\n | ServiceError;\n","\"use client\";\n\nimport { ConnectivityError } from \"./app-errors/app-error\";\nimport { createContext, useContext, useState, useCallback, useMemo, ReactNode } from \"react\";\n\ninterface ConnectivityErrorContextType {\n connectivityError: ConnectivityError | null;\n setConnectivityError: (error: ConnectivityError | null) => void;\n clearConnectivityError: () => void;\n}\n\nconst ConnectivityErrorContext = createContext<ConnectivityErrorContextType | undefined>(undefined);\n\ninterface ConnectivityErrorProviderProps {\n children: ReactNode;\n}\n\nexport function ConnectivityErrorProvider({ children }: ConnectivityErrorProviderProps) {\n const [connectivityError, setConnectivityError] = useState<ConnectivityError | null>(null);\n\n const clearConnectivityError = useCallback(() => {\n setConnectivityError(null);\n }, []);\n\n const handleSetConnectivityError = useCallback((error: ConnectivityError | null) => {\n setConnectivityError(error);\n }, []);\n\n const value = useMemo(\n () => ({\n connectivityError,\n setConnectivityError: handleSetConnectivityError,\n clearConnectivityError,\n }),\n [connectivityError, handleSetConnectivityError, clearConnectivityError],\n );\n\n return <ConnectivityErrorContext.Provider value={value}>{children}</ConnectivityErrorContext.Provider>;\n}\n\nexport function useConnectivityError() {\n const context = useContext(ConnectivityErrorContext);\n if (context === undefined) {\n throw new Error(\"useConnectivityError must be used within a ConnectivityErrorProvider\");\n }\n return context;\n}\n","\"use client\";\n\nimport { useState, useEffect, useCallback, useRef } from \"react\";\n\nexport type UploadStatus = \"pending\" | \"uploading\" | \"success\" | \"error\";\n\nexport type TrackUploadItem = {\n id: string;\n file: File;\n genre: string | null;\n status: UploadStatus;\n progress: number;\n error?: Error | null;\n uploadedTrack?: unknown;\n};\n\nexport interface UseTrackUploadOptions {\n files: File[];\n genre?: string | null;\n onProcessFile: (file: File, genre?: string | null) => Promise<unknown>;\n onComplete?: (uploadedTracks: unknown[]) => void;\n /**\n * Timeout (ms) before an in-flight upload is treated as failed. Passed by the consuming app\n * (from whatever env var / config it uses) so this package doesn't assume a specific env var name.\n */\n uploadTimeoutMs: number;\n}\n\nexport interface UseTrackUploadResult {\n items: TrackUploadItem[];\n isUploading: boolean;\n allComplete: boolean;\n successfulCount: number;\n errorCount: number;\n}\n\n/** Uploads `files` one after the other through `onProcessFile`, restarting whenever the file list or genre changes. */\nexport function useTrackUpload({\n files,\n genre,\n onProcessFile,\n onComplete,\n uploadTimeoutMs,\n}: UseTrackUploadOptions): UseTrackUploadResult {\n const [items, setItems] = useState<TrackUploadItem[]>([]);\n const [currentUploadIndex, setCurrentUploadIndex] = useState(0);\n const [isUploading, setIsUploading] = useState(false);\n const [allComplete, setAllComplete] = useState(false);\n\n const lastFilesKeyRef = useRef<string | null>(null);\n const progressIntervalRef = useRef<ReturnType<typeof setInterval> | null>(null);\n const runRef = useRef(0);\n const completedRunRef = useRef<number | null>(null);\n\n useEffect(() => {\n const filesKey = `${files.length}-${files.map((f) => `${f.name}:${f.size}`).join(\"|\")}-${genre ?? \"\"}`;\n if (lastFilesKeyRef.current === filesKey) return;\n lastFilesKeyRef.current = filesKey;\n runRef.current += 1;\n if (progressIntervalRef.current) {\n clearInterval(progressIntervalRef.current);\n progressIntervalRef.current = null;\n }\n\n setItems(\n files.map((file, index) => ({\n id: `upload-${index}-${file.name}`,\n file,\n genre: genre ?? null,\n status: \"pending\" as UploadStatus,\n progress: 0,\n })),\n );\n setCurrentUploadIndex(0);\n setIsUploading(false);\n setAllComplete(false);\n }, [files, genre]);\n\n const startNextUpload = useCallback(() => {\n const currentItem = items[currentUploadIndex];\n setIsUploading(true);\n\n setItems((prev) =>\n prev.map((item, index) => (index === currentUploadIndex ? { ...item, status: \"uploading\", progress: 0 } : item)),\n );\n\n if (progressIntervalRef.current) clearInterval(progressIntervalRef.current);\n progressIntervalRef.current = setInterval(() => {\n setItems((prev) =>\n prev.map((item, index) =>\n index === currentUploadIndex && item.status === \"uploading\"\n ? { ...item, progress: Math.min(item.progress + Math.random() * 8, 99) }\n : item,\n ),\n );\n }, 800);\n\n const uploadingIndex = currentUploadIndex;\n const run = runRef.current;\n\n const timeoutPromise = new Promise<never>((_, reject) => {\n setTimeout(() => reject(new Error(\"Upload timed out. The server took too long to respond.\")), uploadTimeoutMs);\n });\n\n Promise.race([onProcessFile(currentItem.file, currentItem.genre), timeoutPromise])\n .then((data) => {\n if (run !== runRef.current) return;\n if (progressIntervalRef.current) {\n clearInterval(progressIntervalRef.current);\n progressIntervalRef.current = null;\n }\n setItems((prev) =>\n prev.map((item, index) =>\n index === uploadingIndex ? { ...item, status: \"success\", progress: 100, uploadedTrack: data } : item,\n ),\n );\n setIsUploading(false);\n setCurrentUploadIndex((prev) => prev + 1);\n })\n .catch((error) => {\n if (run !== runRef.current) return;\n if (progressIntervalRef.current) {\n clearInterval(progressIntervalRef.current);\n progressIntervalRef.current = null;\n }\n setItems((prev) =>\n prev.map((item, index) => (index === uploadingIndex ? { ...item, status: \"error\", error } : item)),\n );\n setIsUploading(false);\n setCurrentUploadIndex((prev) => prev + 1);\n });\n }, [items, currentUploadIndex, onProcessFile, uploadTimeoutMs]);\n\n useEffect(() => {\n return () => {\n if (progressIntervalRef.current) {\n clearInterval(progressIntervalRef.current);\n progressIntervalRef.current = null;\n }\n };\n }, []);\n\n useEffect(() => {\n const shouldStart = items.length > 0 && !isUploading && currentUploadIndex < items.length;\n if (shouldStart) {\n startNextUpload();\n }\n }, [items, currentUploadIndex, isUploading, startNextUpload]);\n\n useEffect(() => {\n if (items.length > 0 && currentUploadIndex >= items.length && !isUploading) {\n // React may re-run queued updaters, handing back an equal-but-new items after completion\n if (completedRunRef.current === runRef.current) return;\n completedRunRef.current = runRef.current;\n setAllComplete(true);\n const successfulTracks = items\n .filter((item) => item.status === \"success\" && item.uploadedTrack)\n .map((item) => item.uploadedTrack);\n onComplete?.(successfulTracks);\n }\n }, [items, currentUploadIndex, isUploading, onComplete]);\n\n return {\n items,\n isUploading,\n allComplete,\n successfulCount: items.filter((item) => item.status === \"success\").length,\n errorCount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AAC,CAAC;AAEL,+BAAU,MAAM;AACd,UAAM,cAAc,MAAM,SAAS,KAAK,CAAC,eAAe,qBAAqB,MAAM;AACnF,QAAI,aAAa;AACf,sBAAgB;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,OAAO,oBAAoB,aAAa,eAAe,CAAC;AAE5D,+BAAU,MAAM;AACd,QAAI,MAAM,SAAS,KAAK,sBAAsB,MAAM,UAAU,CAAC,aAAa;AAE1E,UAAI,gBAAgB,YAAY,OAAO,QAAS;AAChD,sBAAgB,UAAU,OAAO;AACjC,qBAAe,IAAI;AACnB,YAAM,mBAAmB,MACtB,OAAO,CAAC,SAAS,KAAK,WAAW,aAAa,KAAK,aAAa,EAChE,IAAI,CAAC,SAAS,KAAK,aAAa;AACnC,mBAAa,gBAAgB;AAAA,IAC/B;AAAA,EACF,GAAG,CAAC,OAAO,oBAAoB,aAAa,UAAU,CAAC;AAEvD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB,MAAM,OAAO,CAAC,SAAS,KAAK,WAAW,SAAS,EAAE;AAAA,IACnE,YAAY,MAAM,OAAO,CAAC,SAAS,KAAK,WAAW,OAAO,EAAE;AAAA,EAC9D;AACF;","names":["import_react","import_react","import_jsx_runtime","import_react"]}
@@ -0,0 +1,80 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { E as ErrorCode } from '../app-error-codes-D5eYg7xR.js';
4
+
5
+ declare const AUTH_POPUP_TYPE = "auth";
6
+ interface HidePopupOptions {
7
+ onlyIfType?: string;
8
+ }
9
+ interface PopupContextType {
10
+ showPopup: (popup: ReactNode, type?: string | null) => void;
11
+ hidePopup: (options?: HidePopupOptions) => void;
12
+ activePopup: ReactNode | null;
13
+ }
14
+ interface PopupProviderProps {
15
+ children: ReactNode;
16
+ }
17
+ declare function PopupProvider({ children }: PopupProviderProps): react.JSX.Element;
18
+ declare function usePopup(): PopupContextType;
19
+
20
+ interface ConnectivityErrorPopupRenderers {
21
+ renderAuthPopup: () => ReactNode;
22
+ renderSpotifyOnlyAuthPopup: () => ReactNode;
23
+ renderInternalErrorPopup: (errorCode: ErrorCode) => ReactNode;
24
+ renderSpotifyAuthErrorPopup: (params: {
25
+ message: string;
26
+ errorCode: ErrorCode;
27
+ onClose: () => void;
28
+ }) => ReactNode;
29
+ renderGoogleAuthErrorPopup: (params: {
30
+ message: string;
31
+ onClose: () => void;
32
+ }) => ReactNode;
33
+ renderNetworkErrorPopup: () => ReactNode;
34
+ }
35
+ interface UseConnectivityErrorPopupOptions {
36
+ isAccountPage: boolean;
37
+ routeRequiresAuth: boolean;
38
+ routeRequiresSpotify: boolean;
39
+ renderers: ConnectivityErrorPopupRenderers;
40
+ }
41
+ /**
42
+ * Classifies the shared connectivity-error state into the right popup and shows it. Consuming apps
43
+ * supply the actual popup components via `renderers` since those are app-branded; this hook owns
44
+ * only the error -> popup-kind decision, so a fix here (e.g. a route not requiring auth still
45
+ * surfacing an unexpected AuthRequired) applies to every app instead of needing a per-app patch.
46
+ */
47
+ declare function useConnectivityErrorPopup({ isAccountPage, routeRequiresAuth, routeRequiresSpotify, renderers, }: UseConnectivityErrorPopupOptions): void;
48
+
49
+ type UploadStatus = "pending" | "uploading" | "success" | "error";
50
+ type TrackUploadItem = {
51
+ id: string;
52
+ file: File;
53
+ genre: string | null;
54
+ status: UploadStatus;
55
+ progress: number;
56
+ error?: Error | null;
57
+ uploadedTrack?: unknown;
58
+ };
59
+ interface UseTrackUploadOptions {
60
+ files: File[];
61
+ genre?: string | null;
62
+ onProcessFile: (file: File, genre?: string | null) => Promise<unknown>;
63
+ onComplete?: (uploadedTracks: unknown[]) => void;
64
+ /**
65
+ * Timeout (ms) before an in-flight upload is treated as failed. Passed by the consuming app
66
+ * (from whatever env var / config it uses) so this package doesn't assume a specific env var name.
67
+ */
68
+ uploadTimeoutMs: number;
69
+ }
70
+ interface UseTrackUploadResult {
71
+ items: TrackUploadItem[];
72
+ isUploading: boolean;
73
+ allComplete: boolean;
74
+ successfulCount: number;
75
+ errorCount: number;
76
+ }
77
+ /** Uploads `files` one after the other through `onProcessFile`, restarting whenever the file list or genre changes. */
78
+ declare function useTrackUpload({ files, genre, onProcessFile, onComplete, uploadTimeoutMs, }: UseTrackUploadOptions): UseTrackUploadResult;
79
+
80
+ export { AUTH_POPUP_TYPE, type ConnectivityErrorPopupRenderers, PopupProvider, type TrackUploadItem, type UploadStatus, type UseConnectivityErrorPopupOptions, type UseTrackUploadOptions, type UseTrackUploadResult, useConnectivityErrorPopup, usePopup, useTrackUpload };
@@ -0,0 +1,16 @@
1
+ import {
2
+ AUTH_POPUP_TYPE,
3
+ PopupProvider,
4
+ useConnectivityErrorPopup,
5
+ usePopup,
6
+ useTrackUpload
7
+ } from "../chunk-OGTDTTHJ.js";
8
+ import "../chunk-4MEK3CNF.js";
9
+ export {
10
+ AUTH_POPUP_TYPE,
11
+ PopupProvider,
12
+ useConnectivityErrorPopup,
13
+ usePopup,
14
+ useTrackUpload
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,4 @@
1
+ /** `"me"` (the signed-in user's own data) vs `"reference"` (shared/community data). */
2
+ type Scope = "me" | "reference";
3
+
4
+ export type { Scope as S };
@@ -0,0 +1,53 @@
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/track-noun/index.ts
21
+ var track_noun_exports = {};
22
+ __export(track_noun_exports, {
23
+ TrackNounProvider: () => TrackNounProvider,
24
+ capitalize: () => capitalize,
25
+ useTrackNoun: () => useTrackNoun
26
+ });
27
+ module.exports = __toCommonJS(track_noun_exports);
28
+
29
+ // src/track-noun/TrackNounContext.tsx
30
+ var import_react = require("react");
31
+ var import_jsx_runtime = require("react/jsx-runtime");
32
+ var TrackNounContext = (0, import_react.createContext)(void 0);
33
+ function TrackNounProvider({ singular, plural, children }) {
34
+ const value = (0, import_react.useMemo)(() => ({ singular, plural }), [singular, plural]);
35
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TrackNounContext.Provider, { value, children });
36
+ }
37
+ function useTrackNoun() {
38
+ const context = (0, import_react.useContext)(TrackNounContext);
39
+ if (context === void 0) {
40
+ throw new Error("useTrackNoun must be used within a TrackNounProvider");
41
+ }
42
+ return context;
43
+ }
44
+ function capitalize(word) {
45
+ return word.charAt(0).toUpperCase() + word.slice(1);
46
+ }
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ TrackNounProvider,
50
+ capitalize,
51
+ useTrackNoun
52
+ });
53
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/track-noun/index.ts","../../src/track-noun/TrackNounContext.tsx"],"sourcesContent":["export * from \"./TrackNounContext\";\n","\"use client\";\n\nimport { createContext, useContext, useMemo, ReactNode } from \"react\";\n\nexport interface TrackNoun {\n singular: string;\n plural: string;\n}\n\nconst TrackNounContext = createContext<TrackNoun | undefined>(undefined);\n\ninterface TrackNounProviderProps extends TrackNoun {\n children: ReactNode;\n}\n\nexport function TrackNounProvider({ singular, plural, children }: TrackNounProviderProps) {\n const value = useMemo(() => ({ singular, plural }), [singular, plural]);\n return <TrackNounContext.Provider value={value}>{children}</TrackNounContext.Provider>;\n}\n\nexport function useTrackNoun() {\n const context = useContext(TrackNounContext);\n if (context === undefined) {\n throw new Error(\"useTrackNoun must be used within a TrackNounProvider\");\n }\n return context;\n}\n\nexport function capitalize(word: string) {\n return word.charAt(0).toUpperCase() + word.slice(1);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,mBAA8D;AAerD;AART,IAAM,uBAAmB,4BAAqC,MAAS;AAMhE,SAAS,kBAAkB,EAAE,UAAU,QAAQ,SAAS,GAA2B;AACxF,QAAM,YAAQ,sBAAQ,OAAO,EAAE,UAAU,OAAO,IAAI,CAAC,UAAU,MAAM,CAAC;AACtE,SAAO,4CAAC,iBAAiB,UAAjB,EAA0B,OAAe,UAAS;AAC5D;AAEO,SAAS,eAAe;AAC7B,QAAM,cAAU,yBAAW,gBAAgB;AAC3C,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACA,SAAO;AACT;AAEO,SAAS,WAAW,MAAc;AACvC,SAAO,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC;AACpD;","names":[]}
@@ -0,0 +1,15 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+
4
+ interface TrackNoun {
5
+ singular: string;
6
+ plural: string;
7
+ }
8
+ interface TrackNounProviderProps extends TrackNoun {
9
+ children: ReactNode;
10
+ }
11
+ declare function TrackNounProvider({ singular, plural, children }: TrackNounProviderProps): react.JSX.Element;
12
+ declare function useTrackNoun(): TrackNoun;
13
+ declare function capitalize(word: string): string;
14
+
15
+ export { type TrackNoun, TrackNounProvider, capitalize, useTrackNoun };