@langlink/dsh-memoq 0.1.7 → 0.1.8

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.
Binary file
package/dist/index.js CHANGED
@@ -6083,7 +6083,8 @@ async function createMtGateway(options) {
6083
6083
  const productName = options.productName ?? BRIDGE_PRODUCT_NAME;
6084
6084
  const desktopVersion = options.desktopVersion ?? BRIDGE_VERSION;
6085
6085
  const controlToken = options.controlToken ?? randomUUID3().replace(/-/gu, "");
6086
- const reviewToken = randomBytes(24).toString("hex");
6086
+ const candidateReviewToken = typeof options.reviewToken === "string" ? options.reviewToken.trim() : "";
6087
+ const reviewToken = candidateReviewToken.length >= 24 && candidateReviewToken !== controlToken ? candidateReviewToken : randomBytes(24).toString("hex");
6087
6088
  const aggregateJobs = /* @__PURE__ */ new Map();
6088
6089
  function getReviewUrl() {
6089
6090
  return `http://${host}:${actualPort}/review?token=${reviewToken}`;
@@ -6683,7 +6684,13 @@ async function createMtGateway(options) {
6683
6684
  if (method === "GET" && pathname === "/review") {
6684
6685
  const provided = url.searchParams.get("token") ?? "";
6685
6686
  if (!safeTokenEquals(provided, reviewToken)) {
6686
- sendJson(response, 401, { success: false, error: "Valid review token is required." });
6687
+ const errorCsp = "default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'; base-uri 'none'";
6688
+ sendHtml(
6689
+ response,
6690
+ 401,
6691
+ `<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8"><title>\u5BA1\u6821\u5DE5\u4F5C\u53F0\u94FE\u63A5\u5DF2\u5931\u6548</title><style>body{font-family:system-ui,-apple-system,sans-serif;max-width:560px;margin:64px auto;padding:24px;line-height:1.6;color:#1f2328}code{background:#f3f4f6;padding:2px 6px;border-radius:4px}</style></head><body><h2>\u5BA1\u6821\u5DE5\u4F5C\u53F0\u94FE\u63A5\u5DF2\u8FC7\u671F\u6216\u65E0\u6548</h2><p>\u5F53\u524D\u643A\u5E26\u7684\u8BBF\u95EE\u51ED\u8BC1\u4E0E\u6B63\u5728\u8FD0\u884C\u7684\u672C\u5730 memoQ \u6865\u63A5\u670D\u52A1\u4E0D\u5339\u914D\u3002</p><p>\u8BF7\u5728 AI \u5BF9\u8BDD\u4E2D\u91CD\u65B0\u8C03\u7528 <code>memoq_open_review</code> \u83B7\u53D6\u6700\u65B0\u5DE5\u4F5C\u53F0\u94FE\u63A5\u540E\u518D\u6253\u5F00\u3002</p><hr><p>Review Workbench token is missing, rotated, or invalid. Call <code>memoq_open_review</code> in your agent session to obtain the current link.</p></body></html>`,
6692
+ errorCsp
6693
+ );
6687
6694
  return;
6688
6695
  }
6689
6696
  const nonce = randomBytes(16).toString("base64");
@@ -7490,13 +7497,14 @@ async function uninstallPluginWithHelper(options) {
7490
7497
 
7491
7498
  // packages/memoq-bridge/src/setup-page.ts
7492
7499
  import { spawn as spawn2 } from "node:child_process";
7493
- import { randomBytes as randomBytes2, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
7500
+ import { randomBytes as randomBytes3, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
7494
7501
  import { existsSync as existsSync7, mkdirSync as mkdirSync5 } from "node:fs";
7495
7502
  import { createServer as createServer2 } from "node:http";
7496
7503
  import { dirname as dirname4 } from "node:path";
7497
7504
 
7498
7505
  // packages/memoq-bridge/src/daemon.ts
7499
- import { existsSync as existsSync6, readFileSync as readFileSync6, rmSync as rmSync3 } from "node:fs";
7506
+ import { randomBytes as randomBytes2 } from "node:crypto";
7507
+ import { chmodSync, existsSync as existsSync6, readFileSync as readFileSync6, rmSync as rmSync3 } from "node:fs";
7500
7508
  import { join as join7 } from "node:path";
7501
7509
  async function probeGatewayPort(port = DEFAULT_PORT, host = DEFAULT_HOST, timeoutMs = 1500) {
7502
7510
  const url = `http://${host}:${port}`;
@@ -7535,6 +7543,31 @@ async function probeGatewayPort(port = DEFAULT_PORT, host = DEFAULT_HOST, timeou
7535
7543
  };
7536
7544
  }
7537
7545
  }
7546
+ function loadOrCreateReviewToken(dataDir = defaultBridgeDataDir(), excludeToken) {
7547
+ const tokenPath = join7(dataDir, "review-token.json");
7548
+ if (existsSync6(tokenPath)) {
7549
+ try {
7550
+ const parsed = JSON.parse(readFileSync6(tokenPath, "utf8"));
7551
+ const candidate = typeof parsed?.token === "string" ? parsed.token.trim() : "";
7552
+ if (/^[0-9a-f]{48,}$/iu.test(candidate) && candidate !== excludeToken) {
7553
+ return candidate;
7554
+ }
7555
+ } catch {
7556
+ }
7557
+ }
7558
+ let token = randomBytes2(24).toString("hex");
7559
+ while (token === excludeToken) {
7560
+ token = randomBytes2(24).toString("hex");
7561
+ }
7562
+ atomicWriteTextSync(tokenPath, JSON.stringify({ token }, null, 2));
7563
+ if (process.platform !== "win32") {
7564
+ try {
7565
+ chmodSync(tokenPath, 384);
7566
+ } catch {
7567
+ }
7568
+ }
7569
+ return token;
7570
+ }
7538
7571
  function getDaemonRecordPath(dataDir = defaultBridgeDataDir()) {
7539
7572
  return join7(dataDir, "daemon.json");
7540
7573
  }
@@ -7718,10 +7751,13 @@ async function startBridgeRuntime(options = {}) {
7718
7751
  ...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
7719
7752
  ...options.helperExecutablePath === void 0 ? {} : { helperExecutablePath: options.helperExecutablePath }
7720
7753
  }));
7754
+ const shouldWriteDaemon = options.writeDaemonFile !== false;
7755
+ const persistedReviewToken = options.reviewToken ?? (shouldWriteDaemon ? loadOrCreateReviewToken(dataDir) : void 0);
7721
7756
  const gateway = await createMtGateway({
7722
7757
  host,
7723
7758
  port: bindPort,
7724
7759
  mode: options.mode ?? "staging",
7760
+ ...persistedReviewToken ? { reviewToken: persistedReviewToken } : {},
7725
7761
  stagingStore,
7726
7762
  previewClient,
7727
7763
  getIntegrationStatus: integrationFn,
@@ -7730,7 +7766,6 @@ async function startBridgeRuntime(options = {}) {
7730
7766
  ...options.getLiveConfig === void 0 ? {} : { getLiveConfig: options.getLiveConfig },
7731
7767
  ...options.updateLiveConfig === void 0 ? {} : { updateLiveConfig: options.updateLiveConfig }
7732
7768
  });
7733
- const shouldWriteDaemon = options.writeDaemonFile !== false;
7734
7769
  if (shouldWriteDaemon) {
7735
7770
  writeDaemonRecord(
7736
7771
  {
@@ -8023,7 +8058,7 @@ function renderSetupHtml(nonce, token, initialStatus) {
8023
8058
  async function startSetupServer(options = {}) {
8024
8059
  const host = options.host ?? DEFAULT_HOST;
8025
8060
  const requestedPort = options.port ?? 0;
8026
- const token = randomBytes2(24).toString("hex");
8061
+ const token = randomBytes3(24).toString("hex");
8027
8062
  const gatewayPort = options.gatewayPort ?? DEFAULT_PORT;
8028
8063
  const probeGateway = options.probeGateway ?? ((p) => probeGatewayPort(p ?? gatewayPort));
8029
8064
  const resolveDll = options.resolveDll ?? resolvePluginDllAsset;
@@ -8062,7 +8097,7 @@ async function startSetupServer(options = {}) {
8062
8097
  return;
8063
8098
  }
8064
8099
  if (method === "GET" && (url.pathname === "/" || url.pathname === "/setup")) {
8065
- const nonce = randomBytes2(16).toString("base64");
8100
+ const nonce = randomBytes3(16).toString("base64");
8066
8101
  response.setHeader(
8067
8102
  "Content-Security-Policy",
8068
8103
  `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'unsafe-inline'; connect-src 'self'; frame-ancestors 'none'; base-uri 'none';`