Skip to content

Commit 2f52ebc

Browse files
committed
Make the OAuth resource a proper Harper Resource
1 parent a6ed8dc commit 2f52ebc

12 files changed

+962
-522
lines changed

bunfig.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[test]
2+
preload = ["./test/bun-preload.js"]

package-lock.json

Lines changed: 60 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
"scripts": {
4646
"build": "tsc",
4747
"dev": "tsc --watch",
48-
"test": "npm run build && node --test",
49-
"test:coverage": "npm run build && node --enable-source-maps --test --experimental-test-coverage --test-coverage-exclude='test/**'",
48+
"test": "npm run build && node --test 'test/**/*.test.js'",
49+
"test:coverage": "npm run build && node --enable-source-maps --test --experimental-test-coverage --test-coverage-exclude='test/**' 'test/**/*.test.js'",
5050
"lint": "eslint . --ignore-pattern 'dist/**'",
5151
"format": "prettier .",
5252
"format:check": "npm run format -- --check",

src/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
*/
77

88
import { initializeProviders, expandEnvVar } from './lib/config.ts';
9-
import { createOAuthResource } from './lib/resource.ts';
9+
import { OAuthResource } from './lib/resource.ts';
1010
import { validateAndRefreshSession } from './lib/sessionValidator.ts';
1111
import { clearOAuthSession } from './lib/handlers.ts';
1212
import { HookManager } from './lib/hookManager.ts';
1313
import type { Scope, OAuthPluginConfig, ProviderRegistry, OAuthHooks } from './types.ts';
1414

15-
// Export HookManager class and types
15+
// Export HookManager class, OAuthResource class, and types
1616
export { HookManager } from './lib/hookManager.ts';
17+
export { OAuthResource } from './lib/resource.ts';
1718
export type { OAuthHooks, OAuthUser, TokenResponse } from './types.ts';
1819

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

107108
// Update the resource with new providers
108109
if (Object.keys(providers).length === 0) {
109-
// No valid providers configured
110+
// No valid providers configured - register a simple error resource
110111
scope.resources.set('oauth', {
111112
async get() {
112113
return {
@@ -130,8 +131,11 @@ export async function handleApplication(scope: Scope): Promise<void> {
130131
},
131132
});
132133
} else {
133-
// Register the OAuth resource with configured providers
134-
scope.resources.set('oauth', createOAuthResource(providers, debugMode, hookManager, logger));
134+
// Configure the OAuth resource with providers and settings
135+
OAuthResource.configure(providers, debugMode, hookManager, logger);
136+
137+
// Register the OAuth resource class
138+
scope.resources.set('oauth', OAuthResource);
135139

136140
// Log all configured providers
137141
logger?.info?.('OAuth plugin ready:', {

src/lib/handlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import { readFile } from 'node:fs/promises';
88
import { join, dirname } from 'node:path';
99
import { fileURLToPath } from 'node:url';
10-
import type { Request, RequestTarget, Logger, IOAuthProvider, OAuthProviderConfig } from '../types.ts';
10+
import type { RequestTarget } from 'harperdb';
11+
import type { Request, Logger, IOAuthProvider, OAuthProviderConfig } from '../types.ts';
1112
import type { HookManager } from './hookManager.ts';
1213

1314
/**

0 commit comments

Comments
 (0)