@detiq/crawler 1.1.16 → 1.1.18
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/job-queue.js +32 -15
- package/dist/job-queue.js.map +2 -2
- package/package.json +1 -1
- package/src/job-queue.ts +37 -16
package/dist/job-queue.js
CHANGED
|
@@ -820,17 +820,23 @@ async function processFigmaImportJob(jobId, config) {
|
|
|
820
820
|
(tx) => tx.platformJob.update({ where: { id: jobId }, data: { status: "RUNNING", startedAt: /* @__PURE__ */ new Date() } })
|
|
821
821
|
);
|
|
822
822
|
try {
|
|
823
|
-
const
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
);
|
|
827
|
-
if (!connector) throw new Error("Figma connector not configured. Add your Figma token in Project Settings \u2192 Integrations.");
|
|
828
|
-
const cfg = connector.config;
|
|
829
|
-
const accessToken = cfg.accessToken_enc ? decrypt(cfg.accessToken_enc) : "";
|
|
830
|
-
if (!accessToken) throw new Error("Figma access token missing. Edit the Figma connector and add your Personal Access Token.");
|
|
831
|
-
const resolvedFileKey = fileKey ?? cfg.fileKey ?? "";
|
|
823
|
+
const oauthConn = await AppBrain.getOAuthConnection(tenantId, projectId, "FIGMA");
|
|
824
|
+
let creds;
|
|
825
|
+
const resolvedFileKey = fileKey ?? "";
|
|
832
826
|
if (!resolvedFileKey) throw new Error("No Figma file key. Paste the full Figma file URL as the App URL.");
|
|
833
|
-
|
|
827
|
+
if (oauthConn?.accessToken && oauthConn.status === "CONNECTED") {
|
|
828
|
+
creds = { accessToken: "", oauthToken: oauthConn.accessToken, fileKey: resolvedFileKey };
|
|
829
|
+
} else {
|
|
830
|
+
const connector = await withTenant(
|
|
831
|
+
tenantId,
|
|
832
|
+
(tx) => tx.connector.findFirst({ where: { projectId, kind: "FIGMA", tenantId } })
|
|
833
|
+
);
|
|
834
|
+
if (!connector) throw new Error("Figma connector not configured. Add your Figma token in Project Settings \u2192 Integrations.");
|
|
835
|
+
const cfg = connector.config;
|
|
836
|
+
const pat = cfg.accessToken_enc ? decrypt(cfg.accessToken_enc) : "";
|
|
837
|
+
if (!pat) throw new Error("Figma access token missing. Edit the Figma connector and add your Personal Access Token.");
|
|
838
|
+
creds = { accessToken: pat, fileKey: resolvedFileKey };
|
|
839
|
+
}
|
|
834
840
|
await updateJobProgress(tenantId, jobId, 5, "Listing frames from Figma file\u2026");
|
|
835
841
|
const frames = await figma.listScreens(creds, resolvedFileKey);
|
|
836
842
|
if (frames.length === 0) {
|
|
@@ -869,7 +875,9 @@ async function processFigmaImportJob(jobId, config) {
|
|
|
869
875
|
console.warn("[figma-import] cloud upload failed:", e);
|
|
870
876
|
}
|
|
871
877
|
}
|
|
872
|
-
|
|
878
|
+
const w = frame.boundingBox?.width ?? 1440;
|
|
879
|
+
const viewport = w <= 480 ? "MOBILE_PORTRAIT" : w <= 1024 ? "TABLET" : "DESKTOP";
|
|
880
|
+
await AppBrain.saveScreenshot(tenantId, projectId, screen.id, storagePath, 1, viewport, cloudUrl);
|
|
873
881
|
}
|
|
874
882
|
}
|
|
875
883
|
if (frame.node) {
|
|
@@ -2643,7 +2651,7 @@ async function processCreatePRJob(jobId, config) {
|
|
|
2643
2651
|
if (!conn) throw new Error(`RepoConnection ${repoConnectionId} not found`);
|
|
2644
2652
|
const { decrypt: decrypt2 } = await import("@detiq/core");
|
|
2645
2653
|
const token = decrypt2(conn.tokenEnc);
|
|
2646
|
-
const { pushScriptsAsPR } = await import("@detiq/agents");
|
|
2654
|
+
const { pushScriptsAsPR, getFileContent, mergeSpecContent } = await import("@detiq/agents");
|
|
2647
2655
|
const framework = conn.detectedFramework ?? "playwright-ts";
|
|
2648
2656
|
let scripts;
|
|
2649
2657
|
if (testScriptIds && testScriptIds.length > 0) {
|
|
@@ -2664,10 +2672,19 @@ async function processCreatePRJob(jobId, config) {
|
|
|
2664
2672
|
);
|
|
2665
2673
|
}
|
|
2666
2674
|
if (scripts.length === 0) throw new Error("No generated scripts found to push.");
|
|
2667
|
-
const files = scripts.map((s) => {
|
|
2675
|
+
const files = await Promise.all(scripts.map(async (s) => {
|
|
2668
2676
|
const path2 = s.testCase?.repoTargetPath ?? deriveFallbackTargetPath(s.testCase?.ref ?? s.testCase?.title ?? s.id, framework);
|
|
2669
|
-
|
|
2670
|
-
|
|
2677
|
+
let content = s.code;
|
|
2678
|
+
const isSpecFile = /\.(spec|test|cy)\.(ts|js|py|java)$/.test(path2) || /_test\.py$/.test(path2);
|
|
2679
|
+
if (isSpecFile) {
|
|
2680
|
+
const existing = await getFileContent(token, conn.repoFullName, path2, conn.defaultBranch).catch(() => null);
|
|
2681
|
+
if (existing && existing.trim().length > 0) {
|
|
2682
|
+
logger.info({ path: path2 }, "[create-pr] merging new tests into existing spec file");
|
|
2683
|
+
content = mergeSpecContent(existing, s.code);
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
return { path: path2, content };
|
|
2687
|
+
}));
|
|
2671
2688
|
if (files.length === 0) throw new Error("No scripts to push.");
|
|
2672
2689
|
await updateJobProgress(tenantId, jobId, 20, `Pushing ${files.length} scripts to GitHub`);
|
|
2673
2690
|
const now = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|