Skip to content

Commit a14f396

Browse files
committed
feat: add configurable auth schemes and request history features
- Add configurable auth schemes (Bearer, Raw, Basic) for flexible header injection - Implement pattern specificity-based rule precedence (more specific patterns win) - Add multiple rules warning when 2+ rules are active on a page - Add expandable request history with domain-level breakdown in ContextBar - Add per-rule request count badges in RuleCard - Extract stateless components (PageInfo, ActivityStatus, MultipleRulesWarning) - Extract shared utility functions for domain pattern matching - Remove unused SettingsDialog component - Add comprehensive tests for new utilities and components - Add CLAUDE.md with development guidelines
1 parent 040df43 commit a14f396

38 files changed

+1908
-359
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,13 @@ jobs:
4242
- name: Build
4343
run: pnpm build
4444

45-
- name: Get version from package.json
46-
id: package_version
47-
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
48-
4945
- name: Create extension zip
50-
run: |
51-
cd dist
52-
zip -r ../auth-header-injector-${{ steps.package_version.outputs.version }}.zip .
53-
cd ..
46+
run: pnpm package
5447

5548
- name: Create GitHub Release
5649
uses: softprops/action-gh-release@v2
5750
with:
58-
files: auth-header-injector-${{ steps.package_version.outputs.version }}.zip
51+
files: auth-hi-*.zip
5952
generate_release_notes: true
6053
draft: false
6154
prerelease: false

CLAUDE.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Claude AI Assistant Rules
2+
3+
Guidelines for AI-assisted development in this codebase.
4+
5+
## Code Style & Formatting
6+
7+
- **Biome** for linting and formatting
8+
- Single quotes
9+
- 2 space indentation
10+
- 100 character line width
11+
- Auto-format on save
12+
- **TypeScript** strict mode
13+
- **Pure functions** preferred for testability (extract to `utils/`)
14+
15+
## UI Component Guidelines
16+
17+
- **Use shadcn UI components** (Alert, Button, Dialog, Select, Switch, etc.)
18+
- **Use Lucide icons** for all iconography
19+
- **Extract stateless components** for reusability
20+
- Consistent Tailwind CSS styling
21+
22+
## Architecture Patterns
23+
24+
- **SDK Kit plugin architecture** for background service worker
25+
- **Pure functions** in `utils/` for testability
26+
- **React hooks** for state management (no external state library)
27+
- **Separation of concerns:**
28+
- `background/` - Service worker with SDK Kit plugins
29+
- `panel/` - Side panel UI
30+
- `popup/` - Popup UI
31+
- `options/` - Options page UI
32+
- `shared/` - Shared types and utilities
33+
34+
## Chrome Extension Specifics
35+
36+
- **Manifest V3** patterns
37+
- **`declarativeNetRequest`** API for header injection
38+
- **Priority-based rule ordering** using pattern specificity
39+
- **Storage:**
40+
- `chrome.storage.sync` for rules (synced across devices)
41+
- `chrome.storage.local` for stats (device-specific)
42+
- **⚠️ CRITICAL: New changes must NOT affect permissions**
43+
- Adding new permissions requires Chrome Web Store review
44+
- Check `manifest.json` before making changes that might require new permissions
45+
- If permissions are needed, discuss first before implementing
46+
47+
## Testing Guidelines
48+
49+
- **Vitest** for unit tests
50+
- **Test pure functions** - extract to `utils/` for testability
51+
- **Mock Chrome APIs** in `tests/setup.ts`
52+
- **Colocate tests** with source files (`.test.ts`)
53+
54+
## Git & Versioning
55+
56+
- **Conventional commits** (feat, fix, docs, refactor, test, chore)
57+
- **Manual versioning** (no changesets yet - will add when auto-deploying to Chrome Web Store)
58+
- **Ask before performing git actions** (user preference)
59+
60+
## Code Review Checklist
61+
62+
Before submitting code, ensure:
63+
- ✅ Pure functions extracted for testability
64+
- ✅ Uses shadcn UI components
65+
- ✅ Uses Lucide icons (not emojis)
66+
- ✅ Tests added for new functionality
67+
- ✅ No new permissions required (check `manifest.json`)
68+
- ✅ TypeScript types are correct
69+
- ✅ Follows existing patterns and conventions
70+

docs/content/getting-started.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,24 @@ Toggle the "Enable extension" switch at the top of the panel.
4747
Click "Add Rule" and fill in:
4848

4949
- **Pattern**: URL pattern to match (e.g., `*.api.example.com`)
50-
- **Token**: Your Bearer token (just the token, not "Bearer ...")
50+
- **Token**: Your authentication token
51+
- **Scheme**: Choose Bearer (default), Raw, or Basic
5152
- **Label**: Optional friendly name (e.g., "Staging API")
5253

5354
Click "Save" and you're done!
5455

56+
**Auth Schemes:**
57+
- **Bearer**: Adds `Authorization: Bearer {token}` header (most common)
58+
- **Raw**: Adds `Authorization: {token}` header (for APIs expecting raw tokens)
59+
- **Basic**: Adds `Authorization: Basic {token}` header (token should be base64-encoded)
60+
5561
### 4. Verify It's Working
5662

5763
1. Navigate to a page that makes API calls matching your pattern
58-
2. Check the "Context Bar" at the top - it shows matched rules
64+
2. Check the "Context Bar" at the top - it shows matched rules and request counts
5965
3. See request counts increase as API calls are intercepted
60-
4. Open DevTools → Network tab → Check request headers
66+
4. Click the request count to expand and see domain-level breakdown
67+
5. Open DevTools → Network tab → Check request headers
6168

6269
## Example: GitHub API
6370

docs/content/guide/_meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export default {
22
patterns: 'URL Patterns',
33
examples: 'Examples',
4+
'auth-schemes': 'Auth Schemes',
45
troubleshooting: 'Troubleshooting',
56
};
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Auth Schemes
2+
3+
Auth HI! supports multiple authentication header formats to work with different APIs.
4+
5+
## Available Schemes
6+
7+
### Bearer (Default)
8+
9+
The most common authentication format. Adds `Authorization: Bearer {token}` header.
10+
11+
**Use when:**
12+
- Working with REST APIs (GitHub, GitLab, most modern APIs)
13+
- Token is a JWT or API key
14+
- API expects standard Bearer token format
15+
16+
**Example:**
17+
```
18+
Pattern: *.api.example.com
19+
Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
20+
Scheme: Bearer
21+
```
22+
23+
**Result:** `Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...`
24+
25+
### Raw
26+
27+
Adds the token directly without any prefix. Adds `Authorization: {token}` header.
28+
29+
**Use when:**
30+
- API expects raw token without "Bearer" prefix
31+
- Working with APIs that use custom token formats
32+
- Token format is non-standard
33+
34+
**Example:**
35+
```
36+
Pattern: *.lytics.io
37+
Token: abc123xyz789
38+
Scheme: Raw
39+
```
40+
41+
**Result:** `Authorization: abc123xyz789`
42+
43+
### Basic
44+
45+
Adds Basic authentication header. Adds `Authorization: Basic {token}` header.
46+
47+
**Use when:**
48+
- Working with HTTP Basic Auth
49+
- Token is already base64-encoded (format: `base64(username:password)`)
50+
- API uses Basic authentication
51+
52+
**Example:**
53+
```
54+
Pattern: api.example.com
55+
Token: dXNlcm5hbWU6cGFzc3dvcmQ= (base64-encoded credentials)
56+
Scheme: Basic
57+
```
58+
59+
**Result:** `Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=`
60+
61+
**Note:** The token should already be base64-encoded. If you have `username:password`, encode it first:
62+
```javascript
63+
btoa('username:password') // Returns base64 string
64+
```
65+
66+
## Choosing the Right Scheme
67+
68+
| API Type | Recommended Scheme | Example |
69+
|----------|-------------------|---------|
70+
| GitHub/GitLab | Bearer | `ghp_...` or `glpat-...` |
71+
| JWT APIs | Bearer | `eyJhbGci...` |
72+
| Custom APIs | Raw | Check API docs |
73+
| HTTP Basic Auth | Basic | Base64-encoded credentials |
74+
| Lytics API | Raw | Raw token format |
75+
76+
## Migration
77+
78+
Existing rules created before scheme support default to **Bearer** for backward compatibility. You can edit any rule to change its scheme.
79+
80+
## Troubleshooting
81+
82+
**Problem:** API returns 401 even with correct token
83+
84+
**Solutions:**
85+
1. Check if the API expects a different scheme (try Raw instead of Bearer)
86+
2. Verify token format matches API requirements
87+
3. For Basic auth, ensure token is base64-encoded
88+
4. Check API documentation for exact header format expected
89+

docs/content/guide/examples.mdx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,28 @@ Perfect for local development against your own API.
7272

7373
## Multiple Rules for Same Domain
7474

75-
You can have multiple rules that match the same domain. They'll all be applied:
75+
You can have multiple rules that match the same domain. When multiple rules match, **the most specific pattern wins**:
7676

7777
```
78-
# Rule 1: General API access
79-
Pattern: *api.example.com
78+
# Rule 1: General API access (less specific)
79+
Pattern: *.api.example.com
8080
Token: general_token
81+
Scheme: Bearer
8182
Label: Example API
8283
83-
# Rule 2: Specific service
84+
# Rule 2: Specific service (more specific - wins!)
8485
Pattern: auth.api.example.com
8586
Token: auth_service_token
87+
Scheme: Bearer
8688
Label: Auth Service
8789
```
8890

89-
Both rules will inject their tokens when matching requests occur.
91+
When a request matches both patterns, Rule 2 wins because `auth.api.example.com` is more specific than `*.api.example.com`. The extension will show a warning when 2+ rules are active on the same page.
92+
93+
**Pattern Specificity:**
94+
- More specific parts = higher priority
95+
- Fewer wildcards = higher priority
96+
- Example: `api.staging.example.com` > `*.example.com` > `*.com`
9097

9198
## Pro Tips
9299

docs/content/guide/patterns.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ OR
102102
Pattern: *://api.example.com/*
103103
```
104104

105+
## Rule Precedence
106+
107+
When multiple rules match the same URL, the **most specific pattern wins**. Specificity is calculated based on:
108+
109+
- **Number of specific parts** (more = more specific)
110+
- **Number of wildcards** (fewer = more specific)
111+
112+
**Example:**
113+
```
114+
Pattern: api.staging.example.com (specificity: 30)
115+
Pattern: *.example.com (specificity: 19)
116+
Pattern: *.com (specificity: -1)
117+
```
118+
119+
If all three match a request to `api.staging.example.com`, the first rule wins.
120+
121+
The extension shows a warning in the Context Bar when 2+ rules are active on the same page, so you know which rule is being used.
122+
105123
## Testing Your Patterns
106124

107125
1. Add your rule in the extension

docs/content/index.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ Say hi to hassle-free auth headers. A Chrome extension that automatically inject
1919
| Feature | Description |
2020
|---------|-------------|
2121
| 🎯 **Pattern Matching** | Target specific domains or subdomains with flexible URL patterns |
22-
| 🔐 **Bearer Token Injection** | Automatically inject Authorization headers into matching requests |
23-
| 📊 **Real-time Tracking** | See which requests are being intercepted as you browse |
22+
| 🔐 **Flexible Auth Schemes** | Support Bearer, Raw, and Basic authentication header formats |
23+
| 📊 **Request History** | Track intercepted requests with expandable domain-level breakdown |
2424
| 🎨 **Side Panel UI** | Context-aware interface that stays open while browsing |
25-
|**Event-driven Architecture** | Minimal performance impact with smart caching |
25+
|**Smart Rule Precedence** | More specific patterns automatically win when multiple rules match |
2626
| 🌓 **Dark Mode** | Chrome DevTools-inspired aesthetic |
2727

2828
## Quick Start

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "auth-header-injector",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Auth HI! - Chrome extension for injecting auth headers. Built with SDK Kit.",
55
"type": "module",
66
"scripts": {
@@ -14,6 +14,7 @@
1414
"test": "vitest run",
1515
"test:watch": "vitest",
1616
"test:ui": "vitest --ui",
17+
"package": "node scripts/create-zip.js",
1718
"prepare": "husky"
1819
},
1920
"keywords": ["chrome-extension", "auth", "headers", "sdk-kit", "developer-tools"],
@@ -28,6 +29,7 @@
2829
"@lytics/sdk-kit": "^0.1.1",
2930
"@radix-ui/react-dialog": "^1.1.15",
3031
"@radix-ui/react-label": "^2.1.8",
32+
"@radix-ui/react-select": "^2.2.6",
3133
"@radix-ui/react-slot": "^1.2.4",
3234
"@radix-ui/react-switch": "^1.2.6",
3335
"class-variance-authority": "^0.7.1",

0 commit comments

Comments
 (0)