@respeak/recap 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/ai/gemini.d.ts +10 -0
- package/dist/src/ai/gemini.js +76 -0
- package/dist/src/ai/gemini.js.map +1 -0
- package/dist/src/ai/pipeline.d.ts +26 -0
- package/dist/src/ai/pipeline.js +37 -0
- package/dist/src/ai/pipeline.js.map +1 -0
- package/dist/src/ai/prompts.d.ts +9 -0
- package/dist/src/ai/prompts.js +129 -0
- package/dist/src/ai/prompts.js.map +1 -0
- package/dist/src/analyze/index.d.ts +11 -0
- package/dist/src/analyze/index.js +55 -0
- package/dist/src/analyze/index.js.map +1 -0
- package/dist/src/analyze/plan-schema.d.ts +180 -0
- package/dist/src/analyze/plan-schema.js +91 -0
- package/dist/src/analyze/plan-schema.js.map +1 -0
- package/dist/src/analyze/scanners/generic.d.ts +2 -0
- package/dist/src/analyze/scanners/generic.js +44 -0
- package/dist/src/analyze/scanners/generic.js.map +1 -0
- package/dist/src/analyze/scanners/nextjs.d.ts +11 -0
- package/dist/src/analyze/scanners/nextjs.js +84 -0
- package/dist/src/analyze/scanners/nextjs.js.map +1 -0
- package/dist/src/download.d.ts +2 -0
- package/dist/src/download.js +36 -0
- package/dist/src/download.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +330 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/output/markdown.d.ts +2 -0
- package/dist/src/output/markdown.js +25 -0
- package/dist/src/output/markdown.js.map +1 -0
- package/dist/src/output/mdx.d.ts +2 -0
- package/dist/src/output/mdx.js +31 -0
- package/dist/src/output/mdx.js.map +1 -0
- package/dist/src/produce/docs-generator.d.ts +11 -0
- package/dist/src/produce/docs-generator.js +63 -0
- package/dist/src/produce/docs-generator.js.map +1 -0
- package/dist/src/produce/index.d.ts +7 -0
- package/dist/src/produce/index.js +76 -0
- package/dist/src/produce/index.js.map +1 -0
- package/dist/src/produce/merge.d.ts +16 -0
- package/dist/src/produce/merge.js +66 -0
- package/dist/src/produce/merge.js.map +1 -0
- package/dist/src/produce/translate.d.ts +2 -0
- package/dist/src/produce/translate.js +23 -0
- package/dist/src/produce/translate.js.map +1 -0
- package/dist/src/produce/tts/elevenlabs.d.ts +4 -0
- package/dist/src/produce/tts/elevenlabs.js +34 -0
- package/dist/src/produce/tts/elevenlabs.js.map +1 -0
- package/dist/src/produce/tts/google.d.ts +4 -0
- package/dist/src/produce/tts/google.js +30 -0
- package/dist/src/produce/tts/google.js.map +1 -0
- package/dist/src/produce/tts/interface.d.ts +9 -0
- package/dist/src/produce/tts/interface.js +2 -0
- package/dist/src/produce/tts/interface.js.map +1 -0
- package/dist/src/produce/tts/openai.d.ts +4 -0
- package/dist/src/produce/tts/openai.js +29 -0
- package/dist/src/produce/tts/openai.js.map +1 -0
- package/dist/src/produce/tts/registry.d.ts +2 -0
- package/dist/src/produce/tts/registry.js +16 -0
- package/dist/src/produce/tts/registry.js.map +1 -0
- package/dist/src/record/action-translator.d.ts +28 -0
- package/dist/src/record/action-translator.js +100 -0
- package/dist/src/record/action-translator.js.map +1 -0
- package/dist/src/record/browser-session.d.ts +12 -0
- package/dist/src/record/browser-session.js +129 -0
- package/dist/src/record/browser-session.js.map +1 -0
- package/dist/src/record/index.d.ts +9 -0
- package/dist/src/record/index.js +88 -0
- package/dist/src/record/index.js.map +1 -0
- package/dist/src/sync/client.d.ts +95 -0
- package/dist/src/sync/client.js +90 -0
- package/dist/src/sync/client.js.map +1 -0
- package/dist/src/sync/diff.d.ts +31 -0
- package/dist/src/sync/diff.js +236 -0
- package/dist/src/sync/diff.js.map +1 -0
- package/dist/src/sync/image-dimensions.d.ts +9 -0
- package/dist/src/sync/image-dimensions.js +48 -0
- package/dist/src/sync/image-dimensions.js.map +1 -0
- package/dist/src/sync/index.d.ts +21 -0
- package/dist/src/sync/index.js +141 -0
- package/dist/src/sync/index.js.map +1 -0
- package/dist/src/sync/links.d.ts +25 -0
- package/dist/src/sync/links.js +61 -0
- package/dist/src/sync/links.js.map +1 -0
- package/dist/src/sync/manifest.d.ts +97 -0
- package/dist/src/sync/manifest.js +156 -0
- package/dist/src/sync/manifest.js.map +1 -0
- package/dist/src/sync/markdown.d.ts +29 -0
- package/dist/src/sync/markdown.js +73 -0
- package/dist/src/sync/markdown.js.map +1 -0
- package/dist/src/sync/payload.d.ts +44 -0
- package/dist/src/sync/payload.js +74 -0
- package/dist/src/sync/payload.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { mkdir } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { translateAndExecute } from "./action-translator.js";
|
|
4
|
+
export async function recordFeature(browser, feature, plan, screenshotDir, tempVideoDir, model, onProgress) {
|
|
5
|
+
const log = onProgress ?? (() => { });
|
|
6
|
+
const baseUrl = plan.app.url;
|
|
7
|
+
const { width, height } = plan.app.viewport;
|
|
8
|
+
const featureScreenshotDir = join(screenshotDir, feature.id);
|
|
9
|
+
if (plan.output.screenshots) {
|
|
10
|
+
await mkdir(featureScreenshotDir, { recursive: true });
|
|
11
|
+
}
|
|
12
|
+
const context = await browser.newContext({
|
|
13
|
+
viewport: { width, height },
|
|
14
|
+
recordVideo: { dir: tempVideoDir, size: { width, height } },
|
|
15
|
+
});
|
|
16
|
+
const page = await context.newPage();
|
|
17
|
+
const steps = [];
|
|
18
|
+
const recordingStart = Date.now();
|
|
19
|
+
try {
|
|
20
|
+
// Auth setup
|
|
21
|
+
await performAuth(page, plan, model);
|
|
22
|
+
// Execute each step
|
|
23
|
+
for (let i = 0; i < feature.steps.length; i++) {
|
|
24
|
+
const step = feature.steps[i];
|
|
25
|
+
log(` [${feature.id}] Step ${i + 1}/${feature.steps.length}: ${step.action}`);
|
|
26
|
+
const stepStart = Date.now() - recordingStart;
|
|
27
|
+
try {
|
|
28
|
+
await translateAndExecute(page, step.action, baseUrl, model, step.timeout);
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
const errorScreenshotPath = join(featureScreenshotDir, `error-step-${i}.png`);
|
|
32
|
+
await page.screenshot({ path: errorScreenshotPath }).catch(() => { });
|
|
33
|
+
const elapsed = Date.now() - recordingStart;
|
|
34
|
+
steps.push({ stepIndex: i, startedAt: stepStart, completedAt: elapsed });
|
|
35
|
+
const videoPath = await getVideoPath(page);
|
|
36
|
+
await context.close();
|
|
37
|
+
return {
|
|
38
|
+
featureId: feature.id,
|
|
39
|
+
status: "failed",
|
|
40
|
+
videoPath,
|
|
41
|
+
steps,
|
|
42
|
+
durationMs: elapsed,
|
|
43
|
+
error: `Step ${i} failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
44
|
+
errorScreenshot: errorScreenshotPath,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const stepComplete = Date.now() - recordingStart;
|
|
48
|
+
let screenshotPath;
|
|
49
|
+
if (plan.output.screenshots) {
|
|
50
|
+
screenshotPath = join(featureScreenshotDir, `step-${i}.png`);
|
|
51
|
+
await page.screenshot({ path: screenshotPath }).catch(() => { });
|
|
52
|
+
}
|
|
53
|
+
steps.push({
|
|
54
|
+
stepIndex: i,
|
|
55
|
+
startedAt: stepStart,
|
|
56
|
+
completedAt: stepComplete,
|
|
57
|
+
screenshot: screenshotPath,
|
|
58
|
+
});
|
|
59
|
+
if (step.pause > 0) {
|
|
60
|
+
await page.waitForTimeout(step.pause);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const durationMs = Date.now() - recordingStart;
|
|
64
|
+
const videoPath = await getVideoPath(page);
|
|
65
|
+
await context.close();
|
|
66
|
+
return {
|
|
67
|
+
featureId: feature.id,
|
|
68
|
+
status: "success",
|
|
69
|
+
videoPath,
|
|
70
|
+
steps,
|
|
71
|
+
durationMs,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
const durationMs = Date.now() - recordingStart;
|
|
76
|
+
let videoPath = "";
|
|
77
|
+
try {
|
|
78
|
+
videoPath = await getVideoPath(page);
|
|
79
|
+
}
|
|
80
|
+
catch { }
|
|
81
|
+
await context.close().catch(() => { });
|
|
82
|
+
return {
|
|
83
|
+
featureId: feature.id,
|
|
84
|
+
status: "failed",
|
|
85
|
+
videoPath,
|
|
86
|
+
steps,
|
|
87
|
+
durationMs,
|
|
88
|
+
error: err instanceof Error ? err.message : String(err),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function performAuth(page, plan, model) {
|
|
93
|
+
const { auth } = plan.app;
|
|
94
|
+
const baseUrl = plan.app.url;
|
|
95
|
+
switch (auth.strategy) {
|
|
96
|
+
case "credentials":
|
|
97
|
+
if (!auth.credentials)
|
|
98
|
+
throw new Error("Credentials required for 'credentials' auth strategy");
|
|
99
|
+
await page.goto(baseUrl + "/login", { waitUntil: "networkidle", timeout: 15000 }).catch(() => {
|
|
100
|
+
return page.goto(baseUrl, { waitUntil: "networkidle", timeout: 15000 });
|
|
101
|
+
});
|
|
102
|
+
try {
|
|
103
|
+
await page.getByLabel(/email/i).fill(auth.credentials.email, { timeout: 5000 });
|
|
104
|
+
await page.getByLabel(/password/i).fill(auth.credentials.password, { timeout: 5000 });
|
|
105
|
+
await page.getByRole("button", { name: /sign in|log in|login|submit/i }).click({ timeout: 5000 });
|
|
106
|
+
await page.waitForURL((url) => !/\/login|\/signin|\/sign-in/i.test(url.pathname), { timeout: 15000 });
|
|
107
|
+
await page.waitForLoadState("networkidle");
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
await translateAndExecute(page, `fill email field with '${auth.credentials.email}'`, baseUrl, model);
|
|
111
|
+
await translateAndExecute(page, `fill password field with '${auth.credentials.password}'`, baseUrl, model);
|
|
112
|
+
await translateAndExecute(page, "click the login or sign in button", baseUrl, model);
|
|
113
|
+
await page.waitForURL((url) => !/\/login|\/signin|\/sign-in/i.test(url.pathname), { timeout: 15000 });
|
|
114
|
+
await page.waitForLoadState("networkidle");
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
case "cookie":
|
|
118
|
+
case "script":
|
|
119
|
+
// Handled by setup_script before recording session
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function getVideoPath(page) {
|
|
124
|
+
const video = page.video();
|
|
125
|
+
if (!video)
|
|
126
|
+
return "";
|
|
127
|
+
return await video.path();
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=browser-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-session.js","sourceRoot":"","sources":["../../../src/record/browser-session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAY7D,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAgB,EAChB,OAAgB,EAChB,IAAU,EACV,aAAqB,EACrB,YAAoB,EACpB,KAAa,EACb,UAAsC;IAEtC,MAAM,GAAG,GAAG,UAAU,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC7B,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;IAE5C,MAAM,oBAAoB,GAAG,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7D,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QAC5B,MAAM,KAAK,CAAC,oBAAoB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,OAAO,GAAmB,MAAM,OAAO,CAAC,UAAU,CAAC;QACvD,QAAQ,EAAE,EAAE,KAAK,EAAE,M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gBAC3G,MAAM,mBAAmB,CAAC,IAAI,EAAE,mCAAmC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;gBACrF,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,6BAA6B,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;gBACtG,MAAM,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;YAC7C,CAAC;YACD,MAAM;QAER,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ;YACX,mDAAmD;YACnD,MAAM;IACV,CAAC;AACH,CAAC;AAED,KAAK,UAAU,YAAY,CAAC,IAAU;IACpC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAC3B,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,OAAO,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RecordingManifest } from "../analyze/plan-schema.js";
|
|
2
|
+
export interface RecordOptions {
|
|
3
|
+
planPath: string;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
model?: string;
|
|
6
|
+
concurrency?: number;
|
|
7
|
+
onProgress?: (message: string) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function recordFeatures(options: RecordOptions): Promise<RecordingManifest>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { chromium } from "playwright";
|
|
2
|
+
import { mkdir, rename, writeFile, readFile } from "node:fs/promises";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import yaml from "js-yaml";
|
|
7
|
+
import { PlanSchema } from "../analyze/plan-schema.js";
|
|
8
|
+
import { initAI } from "../ai/gemini.js";
|
|
9
|
+
import { recordFeature } from "./browser-session.js";
|
|
10
|
+
export async function recordFeatures(options) {
|
|
11
|
+
const { planPath, apiKey, model = "gemini-2.5-flash", onProgress = () => { } } = options;
|
|
12
|
+
// Load and validate plan
|
|
13
|
+
const planContent = await readFile(planPath, "utf-8");
|
|
14
|
+
const rawPlan = yaml.load(planContent);
|
|
15
|
+
const plan = PlanSchema.parse(rawPlan);
|
|
16
|
+
const concurrency = options.concurrency ?? plan.recording.max_concurrent;
|
|
17
|
+
initAI(apiKey);
|
|
18
|
+
// Create output directories
|
|
19
|
+
const videoDir = resolve(plan.output.video_dir);
|
|
20
|
+
const screenshotDir = join(videoDir, "screenshots");
|
|
21
|
+
await mkdir(videoDir, { recursive: true });
|
|
22
|
+
await mkdir(screenshotDir, { recursive: true });
|
|
23
|
+
// Temp dir for Playwright's raw video output
|
|
24
|
+
const tempVideoDir = join(tmpdir(), `recap-video-${randomUUID()}`);
|
|
25
|
+
await mkdir(tempVideoDir, { recursive: true });
|
|
26
|
+
// Run setup script if configured
|
|
27
|
+
if (plan.app.auth.setup_script) {
|
|
28
|
+
onProgress(`Running setup script: ${plan.app.auth.setup_script}`);
|
|
29
|
+
const { execFile } = await import("node:child_process");
|
|
30
|
+
const { promisify } = await import("node:util");
|
|
31
|
+
const execFileAsync = promisify(execFile);
|
|
32
|
+
await execFileAsync("npx", ["tsx", plan.app.auth.setup_script], { timeout: 60000 });
|
|
33
|
+
}
|
|
34
|
+
onProgress(`Recording ${plan.features.length} features (concurrency: ${concurrency})...`);
|
|
35
|
+
// Launch browser
|
|
36
|
+
const browser = await chromium.launch({ headless: true });
|
|
37
|
+
// Record features with concurrency limit
|
|
38
|
+
const results = [];
|
|
39
|
+
const queue = [...plan.features];
|
|
40
|
+
async function worker() {
|
|
41
|
+
while (queue.length > 0) {
|
|
42
|
+
const feature = queue.shift();
|
|
43
|
+
onProgress(`Recording: ${feature.title}`);
|
|
44
|
+
const result = await recordFeature(browser, feature, plan, screenshotDir, tempVideoDir, model, onProgress);
|
|
45
|
+
// Move video to final location
|
|
46
|
+
if (result.videoPath) {
|
|
47
|
+
const finalPath = join(videoDir, `${feature.id}.webm`);
|
|
48
|
+
await rename(result.videoPath, finalPath).catch(() => { });
|
|
49
|
+
result.videoPath = finalPath;
|
|
50
|
+
}
|
|
51
|
+
results.push(result);
|
|
52
|
+
if (result.status === "success") {
|
|
53
|
+
onProgress(` ✓ ${feature.title}`);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
onProgress(` ✗ ${feature.title}: ${result.error}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const workers = Array.from({ length: concurrency }, () => worker());
|
|
61
|
+
await Promise.all(workers);
|
|
62
|
+
await browser.close();
|
|
63
|
+
// Build manifest
|
|
64
|
+
const manifest = {
|
|
65
|
+
version: 1,
|
|
66
|
+
recorded_at: new Date().toISOString(),
|
|
67
|
+
features: Object.fromEntries(results.map((r) => [
|
|
68
|
+
r.featureId,
|
|
69
|
+
{
|
|
70
|
+
video_path: r.videoPath,
|
|
71
|
+
status: r.status,
|
|
72
|
+
steps: r.steps,
|
|
73
|
+
duration_ms: r.durationMs,
|
|
74
|
+
...(r.error && { error: r.error }),
|
|
75
|
+
...(r.errorScreenshot && { error_screenshot: r.errorScreenshot }),
|
|
76
|
+
},
|
|
77
|
+
])),
|
|
78
|
+
};
|
|
79
|
+
// Write manifest
|
|
80
|
+
const manifestPath = join(videoDir, "manifest.json");
|
|
81
|
+
await writeFile(manifestPath, JSON.stringify(manifest, null, 2), "utf-8");
|
|
82
|
+
onProgress(`Manifest written to ${manifestPath}`);
|
|
83
|
+
const succeeded = results.filter((r) => r.status === "success").length;
|
|
84
|
+
const failed = results.filter((r) => r.status === "failed").length;
|
|
85
|
+
onProgress(`Done: ${succeeded} succeeded, ${failed} failed`);
|
|
86
|
+
return manifest;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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|
|
4
|
+
filename: string;
|
|
5
|
+
alt_text: string | null;
|
|
6
|
+
width: number | null;
|
|
7
|
+
height: number | null;
|
|
8
|
+
created_at: string;
|
|
9
|
+
}
|
|
10
|
+
export interface UploadResult {
|
|
11
|
+
imageId: string;
|
|
12
|
+
url: string;
|
|
13
|
+
filename: string;
|
|
14
|
+
}
|
|
15
|
+
export interface SyncStats {
|
|
16
|
+
chapters: {
|
|
17
|
+
created: number;
|
|
18
|
+
updated: number;
|
|
19
|
+
deleted: number;
|
|
20
|
+
};
|
|
21
|
+
articles: {
|
|
22
|
+
created: number;
|
|
23
|
+
updated: number;
|
|
24
|
+
deleted: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface RemoteArticleSummary {
|
|
28
|
+
id: string;
|
|
29
|
+
title: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
keywords?: string[];
|
|
32
|
+
slug: string;
|
|
33
|
+
language: string;
|
|
34
|
+
status: string;
|
|
35
|
+
order: number;
|
|
36
|
+
}
|
|
37
|
+
export interface RemoteChapter {
|
|
38
|
+
id: string;
|
|
39
|
+
title: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
keywords?: string[];
|
|
42
|
+
slug: string;
|
|
43
|
+
group?: string | null;
|
|
44
|
+
order: number;
|
|
45
|
+
translations?: Record<string, {
|
|
46
|
+
title?: string;
|
|
47
|
+
group?: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
}> | null;
|
|
50
|
+
articles: RemoteArticleSummary[];
|
|
51
|
+
}
|
|
52
|
+
export interface RemoteProject {
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
slug: string;
|
|
56
|
+
subtitle: string;
|
|
57
|
+
translations: Record<string, {
|
|
58
|
+
name?: string;
|
|
59
|
+
subtitle?: string;
|
|
60
|
+
}> | null;
|
|
61
|
+
is_public: boolean;
|
|
62
|
+
chapters: RemoteChapter[];
|
|
63
|
+
}
|
|
64
|
+
export interface RemoteArticle {
|
|
65
|
+
slug: string;
|
|
66
|
+
language: string;
|
|
67
|
+
title: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
keywords?: string[];
|
|
70
|
+
content_json?: unknown;
|
|
71
|
+
content_text?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface ClientOptions {
|
|
74
|
+
baseUrl: string;
|
|
75
|
+
apiKey: string;
|
|
76
|
+
}
|
|
77
|
+
export declare class RecapClient {
|
|
78
|
+
private readonly apiBase;
|
|
79
|
+
private readonly apiKey;
|
|
80
|
+
constructor(opts: ClientOptions);
|
|
81
|
+
getProject(slug: string): Promise<RemoteProject>;
|
|
82
|
+
getArticle(slug: string, articleSlug: string, lang: string): Promise<RemoteArticle | null>;
|
|
83
|
+
listImages(slug: string): Promise<{
|
|
84
|
+
images: RecapImage[];
|
|
85
|
+
}>;
|
|
86
|
+
patchImage(slug: string, imageId: string, body: {
|
|
87
|
+
width?: number;
|
|
88
|
+
height?: number;
|
|
89
|
+
alt_text?: string;
|
|
90
|
+
}): Promise<RecapImage>;
|
|
91
|
+
sync(slug: string, payload: unknown): Promise<SyncStats>;
|
|
92
|
+
uploadImage(slug: string, filepath: string): Promise<UploadResult>;
|
|
93
|
+
private request;
|
|
94
|
+
private handle;
|
|
95
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const CONTENT_TYPES = {
|
|
4
|
+
".png": "image/png",
|
|
5
|
+
".jpg": "image/jpeg",
|
|
6
|
+
".jpeg": "image/jpeg",
|
|
7
|
+
".gif": "image/gif",
|
|
8
|
+
".webp": "image/webp",
|
|
9
|
+
".svg": "image/svg+xml",
|
|
10
|
+
};
|
|
11
|
+
export class RecapClient {
|
|
12
|
+
apiBase;
|
|
13
|
+
apiKey;
|
|
14
|
+
constructor(opts) {
|
|
15
|
+
this.apiBase = opts.baseUrl.replace(/\/+$/, "") + "/api/v1";
|
|
16
|
+
this.apiKey = opts.apiKey;
|
|
17
|
+
}
|
|
18
|
+
getProject(slug) {
|
|
19
|
+
return this.request("GET", `/projects/${slug}`);
|
|
20
|
+
}
|
|
21
|
+
async getArticle(slug, articleSlug, lang) {
|
|
22
|
+
try {
|
|
23
|
+
return await this.request("GET", `/projects/${slug}/articles/${encodeURIComponent(articleSlug)}?lang=${encodeURIComponent(lang)}`);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
listImages(slug) {
|
|
30
|
+
return this.request("GET", `/projects/${slug}/media/images`);
|
|
31
|
+
}
|
|
32
|
+
patchImage(slug, imageId, body) {
|
|
33
|
+
return this.request("PATCH", `/projects/${slug}/media/images/${imageId}`, body);
|
|
34
|
+
}
|
|
35
|
+
sync(slug, payload) {
|
|
36
|
+
return this.request("PUT", `/projects/${slug}/sync`, payload);
|
|
37
|
+
}
|
|
38
|
+
async uploadImage(slug, filepath) {
|
|
39
|
+
const buf = await readFile(filepath);
|
|
40
|
+
const name = path.basename(filepath);
|
|
41
|
+
const ext = path.extname(name).toLowerCase();
|
|
42
|
+
const type = CONTENT_TYPES[ext] ?? "application/octet-stream";
|
|
43
|
+
const form = new FormData();
|
|
44
|
+
form.append("file", new Blob([new Uint8Array(buf)], { type }), name);
|
|
45
|
+
const res = await fetch(`${this.apiBase}/projects/${slug}/media/images`, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: { Authorization: `Bearer ${this.apiKey}` },
|
|
48
|
+
body: form,
|
|
49
|
+
});
|
|
50
|
+
const result = await this.handle(res, "POST", `/projects/${slug}/media/images`);
|
|
51
|
+
// A single-file upload returns the bare object; tolerate the multi shape too.
|
|
52
|
+
if (result && typeof result === "object" && "images" in result && Array.isArray(result.images)) {
|
|
53
|
+
const first = result.images[0];
|
|
54
|
+
if (!first)
|
|
55
|
+
throw new Error(`Upload of ${name} returned no image`);
|
|
56
|
+
return first;
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
async request(method, endpoint, body) {
|
|
61
|
+
const res = await fetch(`${this.apiBase}${endpoint}`, {
|
|
62
|
+
method,
|
|
63
|
+
headers: {
|
|
64
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
65
|
+
...(body !== undefined ? { "Content-Type": "application/json" } : {}),
|
|
66
|
+
},
|
|
67
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
68
|
+
});
|
|
69
|
+
return this.handle(res, method, endpoint);
|
|
70
|
+
}
|
|
71
|
+
async handle(res, method, endpoint) {
|
|
72
|
+
if (!res.ok) {
|
|
73
|
+
let detail = "";
|
|
74
|
+
try {
|
|
75
|
+
const json = (await res.json());
|
|
76
|
+
detail = json?.error
|
|
77
|
+
? `${json.error}${json.code ? ` (${json.code})` : ""}`
|
|
78
|
+
: JSON.stringify(json);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
detail = await res.text().catch(() => "");
|
|
82
|
+
}
|
|
83
|
+
throw new Error(`API ${res.status} on ${method} ${endpoint}: ${detail}`);
|
|
84
|
+
}
|
|
85
|
+
if (res.status === 204)
|
|
86
|
+
return undefined;
|
|
87
|
+
return (await res.json());
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/sync/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAqE7B,MAAM,aAAa,GAA2B;IAC5C,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,eAAe;CACxB,CAAC;AAOF,MAAM,OAAO,WAAW;IACL,OAAO,CAAS;IAChB,MAAM,CAAS;IA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C,MAAM,GAAG,CAAC,IAAI,EAAE,CAAM,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type SyncManifest } from "./manifest.js";
|
|
2
|
+
import type { RemoteProject, RemoteArticle } from "./client.js";
|
|
3
|
+
export interface DiffInput {
|
|
4
|
+
manifest: SyncManifest;
|
|
5
|
+
remote: RemoteProject;
|
|
6
|
+
/** key `${slug}:${lang}` -> fetched remote article (with content_text) */
|
|
7
|
+
remoteArticles: Map<string, RemoteArticle>;
|
|
8
|
+
/** null when the remote image list could not be fetched (skip media comparison). */
|
|
9
|
+
remoteImages: string[] | null;
|
|
10
|
+
localImages: string[];
|
|
11
|
+
/** key `${slug}:${lang}` -> local plain text */
|
|
12
|
+
localTexts: Map<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export interface DiffReport {
|
|
15
|
+
diffs: string[];
|
|
16
|
+
info: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Mirror server-side keyword normalization (strip leading `#`, trim, lowercase,
|
|
20
|
+
* dedupe, drop empty) so keyword comparisons don't report cosmetic differences.
|
|
21
|
+
* Reimplemented here because the standalone CLI cannot import the app's
|
|
22
|
+
* `@/lib/keywords` at publish time.
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeKeywords(input: unknown): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Compute the structural, metadata, content and media differences between the
|
|
27
|
+
* local manifest and the remote project, without mutating anything. Pure: it
|
|
28
|
+
* takes already-fetched remote data, so it is easy to unit-test. Mirrors the
|
|
29
|
+
* reference `compare_with_remote.py`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function computeDiff(input: DiffInput): DiffReport;
|