Skip to content

Commit 7ead330

Browse files
committed
feat: updated docs
1 parent 2ca5387 commit 7ead330

File tree

2 files changed

+145
-30
lines changed

2 files changed

+145
-30
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

README.md

Lines changed: 144 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,140 @@ Sterad operates through a simple three-step process:
5050
- **Smart Routing**: Crawlers get cached HTML, users get interactive SPA
5151
- **Security Layer**: Multi-stage HTML sanitization prevents XSS attacks
5252

53+
## Client API
54+
55+
On the client-side (`window.Sterad`) provides programmatic control over caching:
56+
57+
### Methods
58+
59+
#### `triggerCache()`
60+
61+
Manually trigger caching of the current page.
62+
63+
```javascript
64+
// Trigger manual caching
65+
window.Sterad.triggerCache()
66+
.then((result) => {
67+
console.log("Page cached successfully:", result);
68+
})
69+
.catch((error) => {
70+
console.error("Caching failed:", error);
71+
});
72+
```
73+
74+
#### `getCacheInfo()`
75+
76+
Get detailed cache information for the current page.
77+
78+
```javascript
79+
// Get cache information
80+
window.Sterad.getCacheInfo().then((info) => {
81+
console.log("Cache info:", info);
82+
// Returns: { cached: boolean, lastCached: string|null, size?: number, path: string }
83+
});
84+
```
85+
86+
#### `isCached()`
87+
88+
Check if the current page is cached.
89+
90+
```javascript
91+
// Check cache status
92+
window.Sterad.isCached().then((cached) => {
93+
console.log("Page is cached:", cached);
94+
});
95+
```
96+
97+
#### `getLastCached()`
98+
99+
Get the last cached timestamp as a Date object.
100+
101+
```javascript
102+
// Get last cached time
103+
window.Sterad.getLastCached().then((date) => {
104+
if (date) {
105+
console.log("Last cached:", date.toISOString());
106+
} else {
107+
console.log("Page not cached");
108+
}
109+
});
110+
```
111+
112+
### Usage Examples
113+
114+
**Cache Status Indicator:**
115+
116+
```javascript
117+
// Show cache status to users
118+
async function showCacheStatus() {
119+
const cached = await window.Sterad.isCached();
120+
const lastCached = await window.Sterad.getLastCached();
121+
122+
if (cached && lastCached) {
123+
console.log(`Page cached ${lastCached.toLocaleString()}`);
124+
} else {
125+
console.log("Page not cached");
126+
}
127+
}
128+
```
129+
130+
**Manual Cache Control:**
131+
132+
```javascript
133+
// Cache important pages immediately
134+
if (window.location.pathname === "/important-page") {
135+
window.Sterad.triggerCache()
136+
.then(() => console.log("Important page cached"))
137+
.catch((err) => console.error("Cache failed:", err));
138+
}
139+
```
140+
141+
**Cache Analytics:**
142+
143+
```javascript
144+
// Track cache performance
145+
window.Sterad.getCacheInfo().then((info) => {
146+
if (info.cached) {
147+
// Send analytics event
148+
analytics.track("page_served_from_cache", {
149+
path: info.path,
150+
cache_age: Date.now() - new Date(info.lastCached).getTime(),
151+
});
152+
}
153+
});
154+
```
155+
156+
### TypeScript Support
157+
158+
Full TypeScript declarations are included:
159+
160+
```typescript
161+
interface SteradAPI {
162+
triggerCache(): Promise<any>;
163+
getCacheInfo(): Promise<SteradCacheInfo>;
164+
isCached(): Promise<boolean>;
165+
getLastCached(): Promise<Date | null>;
166+
}
167+
168+
interface SteradCacheInfo {
169+
cached: boolean;
170+
lastCached: string | null;
171+
size?: number;
172+
path: string;
173+
}
174+
175+
declare global {
176+
interface Window {
177+
Sterad: SteradAPI;
178+
}
179+
}
180+
```
181+
53182
## Installation
54183

55184
### Prerequisites
56185

57186
- Bun v1.0.0 or newer
58-
- Built SPA (production build)
59187

60188
### Setup Process
61189

@@ -234,7 +362,7 @@ curl -X DELETE "http://localhost:9081/__sterad_capture" \
234362

235363
## Security
236364

237-
Sterad implements enterprise-grade security measures:
365+
Sterad implements well researched security measures:
238366

239367
- **Multi-Layer Sanitization**: Client and server-side HTML sanitization
240368
- **Path Traversal Protection**: Secure file system access controls
@@ -356,43 +484,29 @@ SKIP_TESTS=true bun bundle.ts
356484

357485
## Testing
358486

359-
Sterad includes a comprehensive test suite covering all security and functionality features:
360-
361-
### Running Tests
487+
**149 comprehensive tests** ensure production-ready security and reliability:
362488

363489
```bash
364-
# Run all tests
490+
# Run all tests (6 test suites)
365491
npm test
366492

367-
# Run with verbose output
368-
npm run test:verbose
493+
# Build with integrated testing
494+
bun bundle.ts
369495

370-
# Run individual test
371-
bun run tests/test-bot-detection.js
496+
# Skip tests during build
497+
SKIP_TESTS=true bun bundle.ts
372498
```
373499

374-
### Test Coverage
375-
376-
-**Bot Detection** - User agent parsing and crawler identification
377-
-**JWT Authentication** - Bearer token validation for admin routes
378-
-**Path Traversal Protection** - File system security and sanitization
379-
-**ReDoS Mitigation** - Regular expression timeout protection
380-
-**Trust Boundary Validation** - HTML content security and sanitization
381-
-**Intercept Script Security** - External script execution safety
382-
383-
### Build Integration
384-
385-
Tests automatically run during:
386-
387-
- Development builds (`bun bundle.ts`)
388-
- Package preparation (`npm run prepack`)
389-
- CI/CD pipeline (GitHub Actions)
390-
391-
Set `SKIP_TESTS=true` to bypass tests during build.
500+
**Security Coverage:**
392501

393-
### Continuous Integration
502+
- ✅ Bot Detection & User Agent Parsing
503+
- ✅ JWT Authentication & Authorization
504+
- ✅ Path Traversal Protection
505+
- ✅ ReDoS Mitigation & Regex Safety
506+
- ✅ Trust Boundary Validation
507+
- ✅ Intercept Script Security
394508

395-
All tests run automatically on push/PR with multiple Node.js and Bun versions, plus security audits and integration testing.
509+
**Build Integration:** Tests run automatically before every build, preventing deployment of broken code. CI/CD pipeline includes multi-version testing and security audits.
396510

397511
For support, contact hello@codedynasty.dev.
398512

0 commit comments

Comments
 (0)