Skip to content
Open

v2 #66

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 34 additions & 14 deletions client/src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
import type { UserSettings, isProcessed, ProcessedEvents } from "./types";
import { EnvironmentManager } from "./environment";
import type { isProcessed, ProcessedEvents, UserSettings } from "./types";

export class API {
public static readonly baseUrl = 'https://heron-selected-literally.ngrok-free.app/api';
private static async getBaseUrl(): Promise<string> {
const baseUrl = await EnvironmentManager.getBaseUrl();
return `${baseUrl}/api`;
}

public static async getJwtToken() {
const result = await chrome.storage.local.get('jwt_token');
if (!result.jwt_token) {
throw new Error('No JWT token found');
}
return result.jwt_token;
public static get baseUrl(): Promise<string> {
return this.getBaseUrl();
}

public static async getJwtToken(): Promise<string | undefined> {
const token = await EnvironmentManager.getJwtToken();
return token;
}

public static async checkFeatureFlag(flagName:string) {
const response = await fetch(`${this.baseUrl}/feature_flags/${flagName}`, {
Copy link

Copilot AI Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checkFeatureFlag method uses 'this.baseUrl' directly in a fetch call, but baseUrl is now a Promise that needs to be awaited. This will result in the URL being '[object Promise]/feature_flags/...' instead of the actual base URL, causing the API call to fail.

Suggested change
const response = await fetch(`${this.baseUrl}/feature_flags/${flagName}`, {
const baseUrl = await this.getBaseUrl();
const response = await fetch(`${baseUrl}/feature_flags/${flagName}`, {

Copilot uses AI. Check for mistakes.
method: 'GET'
});

const data = await response.json();
return data.is_enabled;
}

public static async getTerms() {
const response = await fetch(`${this.baseUrl}/terms/current_and_next`, {
const baseUrl = await this.getBaseUrl();
const response = await fetch(`${baseUrl}/terms/current_and_next`, {
method: 'GET'
});
return response.json();
}

public static async getUserEmail() {
const response = await fetch(`${this.baseUrl}/user/email`, {
const baseUrl = await this.getBaseUrl();
const response = await fetch(`${baseUrl}/user/email`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${await this.getJwtToken()}`
Expand All @@ -29,7 +45,8 @@ export class API {
}

public static async userSettings(settings?: UserSettings): Promise<UserSettings> {
const url = `${this.baseUrl}/user/extension_config`;
const baseUrl = await this.getBaseUrl();
const url = `${baseUrl}/user/extension_config`;
const token = await this.getJwtToken();
const headers: HeadersInit = {
'Authorization': `Bearer ${token}`
Expand All @@ -55,8 +72,9 @@ export class API {
}

public static async userIsProcessed(termUid: string): Promise<isProcessed> {
const baseUrl = await this.getBaseUrl();
const token = await this.getJwtToken();
const response = await fetch(`${this.baseUrl}/user/is_processed`, {
const response = await fetch(`${baseUrl}/user/is_processed`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
Expand All @@ -68,8 +86,9 @@ export class API {
}

public static async getProcessedEvents(termUid: string): Promise<ProcessedEvents> {
const baseUrl = await this.getBaseUrl();
const token = await this.getJwtToken();
const response = await fetch(`${this.baseUrl}/user/processed_events`, {
const response = await fetch(`${baseUrl}/user/processed_events`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
Expand All @@ -81,8 +100,9 @@ export class API {
}

public static async getIcsUrl(): Promise<{ ics_url: string }> {
const baseUrl = await this.getBaseUrl();
const token = await this.getJwtToken();
const response = await fetch(`${this.baseUrl}/user/ics_url`, {
const response = await fetch(`${baseUrl}/user/ics_url`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`
Expand Down
Loading