Skip to content
Merged
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
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
preload = ["./test/bun-preload.js"]
116 changes: 60 additions & 56 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"test": "npm run build && node --test",
"test:coverage": "npm run build && node --enable-source-maps --test --experimental-test-coverage --test-coverage-exclude='test/**'",
"test": "npm run build && node --test test/**/*.test.js",
"test:coverage": "npm run build && node --enable-source-maps --test --experimental-test-coverage --test-coverage-exclude=test/** test/**/*.test.js",
"lint": "eslint . --ignore-pattern 'dist/**'",
"format": "prettier .",
"format:check": "npm run format -- --check",
Expand Down
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
*/

import { initializeProviders, expandEnvVar } from './lib/config.ts';
import { createOAuthResource } from './lib/resource.ts';
import { OAuthResource } from './lib/resource.ts';
import { validateAndRefreshSession } from './lib/sessionValidator.ts';
import { clearOAuthSession } from './lib/handlers.ts';
import { HookManager } from './lib/hookManager.ts';
import type { Scope, OAuthPluginConfig, ProviderRegistry, OAuthHooks } from './types.ts';

// Export HookManager class and types
// Export HookManager class, OAuthResource class, and types
export { HookManager } from './lib/hookManager.ts';
export { OAuthResource } from './lib/resource.ts';
export type { OAuthHooks, OAuthUser, TokenResponse } from './types.ts';

// Store hooks registered at module load time and active hookManager
Expand Down Expand Up @@ -106,7 +107,7 @@ export async function handleApplication(scope: Scope): Promise<void> {

// Update the resource with new providers
if (Object.keys(providers).length === 0) {
// No valid providers configured
// No valid providers configured - register a simple error resource
scope.resources.set('oauth', {
async get() {
return {
Expand All @@ -130,8 +131,11 @@ export async function handleApplication(scope: Scope): Promise<void> {
},
});
} else {
// Register the OAuth resource with configured providers
scope.resources.set('oauth', createOAuthResource(providers, debugMode, hookManager, logger));
// Configure the OAuth resource with providers and settings
OAuthResource.configure(providers, debugMode, hookManager, logger);

// Register the OAuth resource class
scope.resources.set('oauth', OAuthResource);

// Log all configured providers
logger?.info?.('OAuth plugin ready:', {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import { readFile } from 'node:fs/promises';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { Request, RequestTarget, Logger, IOAuthProvider, OAuthProviderConfig } from '../types.ts';
import type { RequestTarget } from 'harperdb';
import type { Request, Logger, IOAuthProvider, OAuthProviderConfig } from '../types.ts';
import type { HookManager } from './hookManager.ts';

/**
Expand Down
Loading