Merge remote-tracking branch 'upstream/dev' into feat/inbox

This commit is contained in:
Anish Sarkar 2026-01-28 09:26:04 +05:30
commit 614761bb17
64 changed files with 2604 additions and 730 deletions

View file

@ -23,7 +23,10 @@ export type RequestOptions = {
class BaseApiService {
baseUrl: string;
noAuthEndpoints: string[] = ["/auth/jwt/login", "/auth/register", "/auth/refresh"]; // Add more endpoints as needed
noAuthEndpoints: string[] = ["/auth/jwt/login", "/auth/register", "/auth/refresh"];
// Prefixes that don't require auth (checked with startsWith)
noAuthPrefixes: string[] = ["/api/v1/public/", "/api/v1/podcasts/"];
// Use a getter to always read fresh token from localStorage
// This ensures the token is always up-to-date after login/logout
@ -84,7 +87,10 @@ class BaseApiService {
}
// Validate the bearer token
if (!this.bearerToken && !this.noAuthEndpoints.includes(url)) {
const isNoAuthEndpoint =
this.noAuthEndpoints.includes(url) ||
this.noAuthPrefixes.some((prefix) => url.startsWith(prefix));
if (!this.bearerToken && !isNoAuthEndpoint) {
throw new AuthenticationError("You are not authenticated. Please login again.");
}

View file

@ -0,0 +1,33 @@
import {
type TogglePublicShareRequest,
type TogglePublicShareResponse,
togglePublicShareRequest,
togglePublicShareResponse,
} from "@/contracts/types/chat-threads.types";
import { ValidationError } from "../error";
import { baseApiService } from "./base-api.service";
class ChatThreadsApiService {
/**
* Toggle public sharing for a thread.
* Requires authentication.
*/
togglePublicShare = async (
request: TogglePublicShareRequest
): Promise<TogglePublicShareResponse> => {
const parsed = togglePublicShareRequest.safeParse(request);
if (!parsed.success) {
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
throw new ValidationError(`Invalid request: ${errorMessage}`);
}
return baseApiService.patch(
`/api/v1/threads/${parsed.data.thread_id}/public-share`,
togglePublicShareResponse,
{ body: { enabled: parsed.data.enabled } }
);
};
}
export const chatThreadsApiService = new ChatThreadsApiService();

View file

@ -0,0 +1,73 @@
import {
type ClonePublicChatRequest,
type ClonePublicChatResponse,
type CompleteCloneRequest,
type CompleteCloneResponse,
clonePublicChatRequest,
clonePublicChatResponse,
completeCloneRequest,
completeCloneResponse,
type GetPublicChatRequest,
type GetPublicChatResponse,
getPublicChatRequest,
getPublicChatResponse,
} from "@/contracts/types/public-chat.types";
import { ValidationError } from "../error";
import { baseApiService } from "./base-api.service";
class PublicChatApiService {
/**
* Get a public chat by share token.
* No authentication required.
*/
getPublicChat = async (request: GetPublicChatRequest): Promise<GetPublicChatResponse> => {
const parsed = getPublicChatRequest.safeParse(request);
if (!parsed.success) {
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
throw new ValidationError(`Invalid request: ${errorMessage}`);
}
return baseApiService.get(`/api/v1/public/${parsed.data.share_token}`, getPublicChatResponse);
};
/**
* Clone a public chat to the user's account.
* Creates an empty thread and returns thread_id for redirect.
* Requires authentication.
*/
clonePublicChat = async (request: ClonePublicChatRequest): Promise<ClonePublicChatResponse> => {
const parsed = clonePublicChatRequest.safeParse(request);
if (!parsed.success) {
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
throw new ValidationError(`Invalid request: ${errorMessage}`);
}
return baseApiService.post(
`/api/v1/public/${parsed.data.share_token}/clone`,
clonePublicChatResponse
);
};
/**
* Complete the clone by copying messages and podcasts.
* Called from the chat page after redirect.
* Requires authentication.
*/
completeClone = async (request: CompleteCloneRequest): Promise<CompleteCloneResponse> => {
const parsed = completeCloneRequest.safeParse(request);
if (!parsed.success) {
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
throw new ValidationError(`Invalid request: ${errorMessage}`);
}
return baseApiService.post(
`/api/v1/threads/${parsed.data.thread_id}/complete-clone`,
completeCloneResponse
);
};
}
export const publicChatApiService = new PublicChatApiService();