Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 20 additions & 2 deletions extensions-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@

import type { WebExtensionRegistry } from './types'

export { default as ConversationalExtensionWeb } from './conversational-web'
export { default as JanProviderWeb } from './jan-provider-web'
export { default as MCPExtensionWeb } from './mcp-web'

Check warning on line 10 in extensions-web/src/index.ts

View workflow job for this annotation

GitHub Actions / coverage-check

8-10 lines are not covered with tests

// Re-export auth functionality
export {

Check warning on line 13 in extensions-web/src/index.ts

View workflow job for this annotation

GitHub Actions / coverage-check

13 line is not covered with tests
JanAuthService,
getSharedAuthService,
AUTH_STORAGE_KEYS,
AUTH_EVENTS,
AUTH_BROADCAST_CHANNEL,
} from './shared/auth'

// Re-export types
export type {
WebExtensionRegistry,
Expand All @@ -17,12 +26,21 @@
WebExtensionLoader,
ConversationalWebModule,
JanProviderWebModule,
MCPWebModule
MCPWebModule,
} from './types'

// Re-export auth types
export type {
User,
AuthTokens,
AuthProvider,
AuthProviderRegistry,
ProviderType,
} from './shared/auth'

// Extension registry for dynamic loading
export const WEB_EXTENSIONS: WebExtensionRegistry = {
'conversational-web': () => import('./conversational-web'),
'jan-provider-web': () => import('./jan-provider-web'),
'mcp-web': () => import('./mcp-web'),
}
}

Check warning on line 46 in extensions-web/src/index.ts

View workflow job for this annotation

GitHub Actions / coverage-check

42-46 lines are not covered with tests
219 changes: 0 additions & 219 deletions extensions-web/src/shared/auth.ts

This file was deleted.

68 changes: 68 additions & 0 deletions extensions-web/src/shared/auth/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Generic Authentication API Layer
* Generic API calls for authentication (not provider-specific)
*/

import { AuthTokens } from './types'
import { AUTH_ENDPOINTS } from './const'

Check warning on line 7 in extensions-web/src/shared/auth/api.ts

View workflow job for this annotation

GitHub Actions / coverage-check

7 line is not covered with tests

declare const JAN_API_BASE: string

/**
* Logout user on server
*/
export async function logoutUser(): Promise<void> {
const response = await fetch(`${JAN_API_BASE}${AUTH_ENDPOINTS.LOGOUT}`, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
})

Check warning on line 21 in extensions-web/src/shared/auth/api.ts

View workflow job for this annotation

GitHub Actions / coverage-check

14-21 lines are not covered with tests

if (!response.ok) {
console.warn(`Logout failed with status: ${response.status}`)
}
}

Check warning on line 26 in extensions-web/src/shared/auth/api.ts

View workflow job for this annotation

GitHub Actions / coverage-check

23-26 lines are not covered with tests

/**
* Guest login
*/
export async function guestLogin(): Promise<AuthTokens> {
const response = await fetch(`${JAN_API_BASE}${AUTH_ENDPOINTS.GUEST_LOGIN}`, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
})

Check warning on line 38 in extensions-web/src/shared/auth/api.ts

View workflow job for this annotation

GitHub Actions / coverage-check

31-38 lines are not covered with tests

if (!response.ok) {
throw new Error(
`Guest login failed: ${response.status} ${response.statusText}`
)
}

Check warning on line 44 in extensions-web/src/shared/auth/api.ts

View workflow job for this annotation

GitHub Actions / coverage-check

40-44 lines are not covered with tests

return response.json() as Promise<AuthTokens>
}

/**
* Refresh token (works for both guest and authenticated users)
*/
export async function refreshToken(): Promise<AuthTokens> {
const response = await fetch(
`${JAN_API_BASE}${AUTH_ENDPOINTS.REFRESH_TOKEN}`,
{
method: 'GET',
credentials: 'include',
}
)

if (!response.ok) {
throw new Error(
`Token refresh failed: ${response.status} ${response.statusText}`
)
}

return response.json() as Promise<AuthTokens>
}
Loading
Loading