- Add authentication scripts with SubtleCrypto password encryption - Add sourcemap extraction pipeline (update-urls, download-sourcemaps, extract-sources) - Add Playwright API interception script for monetization endpoints - Document two-step auth flow with JWT tokens and dual cookies - Move extracted source from root to anyclip/ directory - Add project configuration (.env.example, .gitignore, CLAUDE.md)
4.0 KiB
4.0 KiB
description, globs, alwaysApply
| description | globs | alwaysApply |
|---|---|---|
| AnyClip integration tools - use Bun, understand the scripts | *.ts, *.tsx, *.html, *.css, *.js, *.jsx, package.json | true |
Project: AnyClip Integration
Tools for integrating with AnyClip's Video Manager API and extracting source code from sourcemaps.
Key Scripts
| Script | Purpose |
|---|---|
scripts/auth.ts |
Authenticate with AnyClip, returns session cookies |
scripts/crypto-subtle.ts |
Password encryption (AES-256-GCM, matches AnyClip's client) |
scripts/update-urls.ts |
Fetch JS URLs from build manifest → urls.txt |
scripts/download-sourcemaps.ts |
Download .map files for URLs in urls.txt |
scripts/extract-sources.ts |
Extract source from sourcemaps → anyclip/ |
Authentication Flow
- Password encrypted client-side with AES-256-GCM (salt:
$2b$04$wwky7rvtr6BFNaCqntwyie) - POST to
videomanager-api.anyclip.com/public/auth/login→ returnsanyclip_2020cookie + JWT - POST to
videomanager.anyclip.com/api/auth/login→ returnssessioncookie - Both cookies required for authenticated requests
Source Extraction Workflow
bun scripts/update-urls.ts # Scrape build manifest for JS URLs
bun scripts/download-sourcemaps.ts # Download .map files
bun scripts/extract-sources.ts # Extract to anyclip/
Directory Structure
anyclip/- Extracted source (committed)sourcemaps/- Raw .map files (gitignored)urls.txt- JS URLs to downloadsession.json- Auth session (gitignored)
Bun Usage
Default to using Bun instead of Node.js.
- Use
bun <file>instead ofnode <file>orts-node <file> - Use
bun testinstead ofjestorvitest - Use
bun build <file.html|file.ts|file.css>instead ofwebpackoresbuild - Use
bun installinstead ofnpm installoryarn installorpnpm install - Use
bun run <script>instead ofnpm run <script>oryarn run <script>orpnpm run <script> - Use
bunx <package> <command>instead ofnpx <package> <command> - Bun automatically loads .env, so don't use dotenv.
APIs
Bun.serve()supports WebSockets, HTTPS, and routes. Don't useexpress.bun:sqlitefor SQLite. Don't usebetter-sqlite3.Bun.redisfor Redis. Don't useioredis.Bun.sqlfor Postgres. Don't usepgorpostgres.js.WebSocketis built-in. Don't usews.- Prefer
Bun.fileovernode:fs's readFile/writeFile - Bun.$
lsinstead of execa.
Testing
Use bun test to run tests.
import { test, expect } from "bun:test";
test("hello world", () => {
expect(1).toBe(1);
});
Frontend
Use HTML imports with Bun.serve(). Don't use vite. HTML imports fully support React, CSS, Tailwind.
Server:
import index from "./index.html"
Bun.serve({
routes: {
"/": index,
"/api/users/:id": {
GET: (req) => {
return new Response(JSON.stringify({ id: req.params.id }));
},
},
},
// optional websocket support
websocket: {
open: (ws) => {
ws.send("Hello, world!");
},
message: (ws, message) => {
ws.send(message);
},
close: (ws) => {
// handle close
}
},
development: {
hmr: true,
console: true,
}
})
HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. <link> tags can point to stylesheets and Bun's CSS bundler will bundle.
<html>
<body>
<h1>Hello, world!</h1>
<script type="module" src="./frontend.tsx"></script>
</body>
</html>
With the following frontend.tsx:
import React from "react";
import { createRoot } from "react-dom/client";
// import .css files directly and it works
import './index.css';
const root = createRoot(document.body);
export default function Frontend() {
return <h1>Hello, world!</h1>;
}
root.render(<Frontend />);
Then, run index.ts
bun --hot ./index.ts
For more information, read the Bun API docs in node_modules/bun-types/docs/**.mdx.