inkmap-mcp 0.3.2 → 0.3.4

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.
@@ -169,13 +169,20 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
169
169
  }
170
170
  return /^1\d{10}$/.test(clean) ? `${clean.slice(0, 3)}****${clean.slice(7)}` : clean.slice(0, 32);
171
171
  }
172
- function clientLocale() {
173
- const raw = (process.env.INKMAP_LOCALE || process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || "").trim();
172
+ function clientLocale(hint) {
173
+ const h = (hint || "").trim();
174
+ if (/^zh\b/i.test(h)) return "zh";
175
+ if (/^en\b/i.test(h)) return "en";
176
+ const envLocale = (process.env.INKMAP_LOCALE || "").trim();
177
+ if (/^zh\b/i.test(envLocale)) return "zh";
178
+ if (/^en\b/i.test(envLocale)) return "en";
179
+ const raw = (process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || "").trim();
174
180
  if (/^zh\b/i.test(raw)) return "zh";
175
- if (/^en\b/i.test(process.env.INKMAP_LOCALE || "")) return "en";
176
181
  try {
177
- const tz = Intl.DateTimeFormat().resolvedOptions().timeZone || "";
178
- if (/^Asia\/(Shanghai|Chongqing|Harbin|Urumqi)$/i.test(tz)) return "zh";
182
+ const opts = Intl.DateTimeFormat().resolvedOptions();
183
+ if (/^zh\b/i.test(opts.locale || "")) return "zh";
184
+ const tz = opts.timeZone || "";
185
+ if (/^(Asia\/(Shanghai|Chongqing|Chungking|Harbin|Urumqi|Beijing)|PRC)$/i.test(tz)) return "zh";
179
186
  } catch {
180
187
  }
181
188
  return "en";
@@ -187,16 +194,18 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
187
194
  });
188
195
  return next;
189
196
  }
190
- async function createCheckoutFlow(origin, existingToken, existingCookie) {
197
+ async function createCheckoutFlow(origin, existingToken, existingCookie, localeHint) {
198
+ const loc = clientLocale(localeHint);
191
199
  const response = await fetch(origin + "/billing/v1/connections", {
192
200
  method: "POST",
193
201
  headers: {
194
202
  "content-type": "application/json",
203
+ "x-inkmap-locale": loc,
195
204
  ...existingToken && { authorization: "Bearer " + existingToken },
196
205
  ...existingCookie && { cookie: existingCookie }
197
206
  },
198
207
  redirect: "error",
199
- body: JSON.stringify({ product: PRODUCT.id, mode: "buy" }),
208
+ body: JSON.stringify({ product: PRODUCT.id, mode: "buy", locale: loc }),
200
209
  signal: AbortSignal.timeout(8e3)
201
210
  });
202
211
  if (!response.ok) throw new Error("Unable to start the checkout flow.");
@@ -208,11 +217,13 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
208
217
  }
209
218
  return { origin, url, token: data.token, ...cookie && { cookie } };
210
219
  }
211
- function checkoutPost(checkoutUrl, action, origin, body, token, cookie) {
220
+ function checkoutPost(checkoutUrl, action, origin, body, token, cookie, localeHint) {
221
+ const loc = clientLocale(localeHint);
212
222
  return fetch(checkoutUrl + "/" + action, {
213
223
  method: "POST",
214
224
  headers: {
215
225
  "content-type": "application/json",
226
+ "x-inkmap-locale": loc,
216
227
  origin,
217
228
  ...token && { authorization: "Bearer " + token },
218
229
  ...cookie && { cookie }
@@ -222,13 +233,14 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
222
233
  signal: AbortSignal.timeout(12e3)
223
234
  });
224
235
  }
225
- function phoneRequest(origin, action, phone, code) {
236
+ function phoneRequest(origin, action, phone, code, localeHint) {
226
237
  const isEmail = phone.includes("@");
227
- const locale = clientLocale();
238
+ const locale = clientLocale(localeHint);
228
239
  return fetch(origin + "/billing/v1/phone-sign-in/" + action, {
229
240
  method: "POST",
230
241
  headers: {
231
242
  "content-type": "application/json",
243
+ "x-inkmap-locale": locale,
232
244
  "accept-language": locale === "zh" ? "zh-CN,zh;q=0.9" : "en-US,en;q=0.9"
233
245
  },
234
246
  redirect: "error",
@@ -335,9 +347,10 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
335
347
  if (Date.now() - lastCheck >= 4e3) await refresh();
336
348
  return current;
337
349
  },
338
- async connect(mode) {
350
+ async connect(mode, localeHint) {
339
351
  if (loginOnly && mode !== "restore") throw new Error("Only Yunfan account sign-in is available.");
340
352
  const origin = billingOrigin(getOrigin());
353
+ const loc = clientLocale(localeHint);
341
354
  const version = generation;
342
355
  let existingToken;
343
356
  try {
@@ -352,6 +365,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
352
365
  method: "POST",
353
366
  headers: {
354
367
  "content-type": "application/json",
368
+ "x-inkmap-locale": loc,
355
369
  ...existingToken && { authorization: "Bearer " + existingToken }
356
370
  },
357
371
  redirect: "error",
@@ -359,10 +373,10 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
359
373
  signal: AbortSignal.timeout(8e3)
360
374
  });
361
375
  let legacy = false;
362
- let response = await (mode === "restore" ? create("restore-connections", { product: PRODUCT.id }) : create("connections", { product: PRODUCT.id, mode }));
376
+ let response = await (mode === "restore" ? create("restore-connections", { product: PRODUCT.id }) : create("connections", { product: PRODUCT.id, mode, locale: loc }));
363
377
  if (mode === "restore" && !loginOnly && response.status === 404) {
364
378
  legacy = true;
365
- response = await create("connections", { product: PRODUCT.id, mode });
379
+ response = await create("connections", { product: PRODUCT.id, mode, locale: loc });
366
380
  }
367
381
  if (!response.ok) throw new Error("Unable to start the Yunfan account flow.");
368
382
  const data = await response.json();
@@ -382,7 +396,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
382
396
  });
383
397
  return url;
384
398
  },
385
- async orderPro() {
399
+ async orderPro(localeHint) {
386
400
  if (loginOnly) throw new Error("Only Yunfan account sign-in is available.");
387
401
  const origin = billingOrigin(getOrigin());
388
402
  if (cachedOrder && cachedOrder.origin === origin && Date.now() - cachedOrder.at < 8e3) {
@@ -399,7 +413,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
399
413
  } catch {
400
414
  }
401
415
  const requestOrder = async (checkoutUrl, token, cookie, persist) => {
402
- const res = await checkoutPost(checkoutUrl, "order", origin, {}, token, cookie);
416
+ const res = await checkoutPost(checkoutUrl, "order", origin, {}, token, cookie, localeHint);
403
417
  if (res.status === 401 || res.status === 403 || res.status === 404 || res.status === 410) return null;
404
418
  if (!res.ok) throw new Error("Unable to load WeChat Pay QR code.");
405
419
  const nextCookie = mergeCookies(cookie, res);
@@ -443,29 +457,29 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
443
457
  if (existing) return existing;
444
458
  }
445
459
  const existingToken = record?.origin === origin && typeof record.token === "string" ? record.token : void 0;
446
- const flow = await createCheckoutFlow(origin, existingToken, existingCookie);
460
+ const flow = await createCheckoutFlow(origin, existingToken, existingCookie, localeHint);
447
461
  const ordered = await requestOrder(flow.url, flow.token, flow.cookie, true);
448
462
  if (ordered) return ordered;
449
463
  pendingCheckout = flow;
450
464
  return { status: "needsPhone" };
451
465
  },
452
- async sendPhoneCode(phone) {
466
+ async sendPhoneCode(phone, localeHint) {
453
467
  if (typeof phone !== "string" || !phone.trim() || phone.length > 254) return phoneFailure(400);
454
468
  const isEmail = phone.includes("@");
455
- const locale = clientLocale();
469
+ const locale = clientLocale(localeHint);
456
470
  try {
457
471
  const origin = billingOrigin(getOrigin());
458
472
  if (!loginOnly) {
459
473
  try {
460
474
  if (!pendingCheckout || pendingCheckout.origin !== origin) {
461
- pendingCheckout = await createCheckoutFlow(origin);
475
+ pendingCheckout = await createCheckoutFlow(origin, void 0, void 0, locale);
462
476
  }
463
477
  const sendAction = isEmail ? "email/send" : "sms";
464
478
  const sendBody = isEmail ? { email: phone, locale } : { phone };
465
- let smsRes = await checkoutPost(pendingCheckout.url, sendAction, origin, sendBody, pendingCheckout.token, pendingCheckout.cookie);
479
+ let smsRes = await checkoutPost(pendingCheckout.url, sendAction, origin, sendBody, pendingCheckout.token, pendingCheckout.cookie, locale);
466
480
  if (smsRes.status === 410 || smsRes.status === 404) {
467
- pendingCheckout = await createCheckoutFlow(origin);
468
- smsRes = await checkoutPost(pendingCheckout.url, sendAction, origin, sendBody, pendingCheckout.token, pendingCheckout.cookie);
481
+ pendingCheckout = await createCheckoutFlow(origin, void 0, void 0, locale);
482
+ smsRes = await checkoutPost(pendingCheckout.url, sendAction, origin, sendBody, pendingCheckout.token, pendingCheckout.cookie, locale);
469
483
  }
470
484
  pendingCheckout.cookie = mergeCookies(pendingCheckout.cookie, smsRes);
471
485
  return smsRes.status === 204 ? { ok: true, value: void 0 } : phoneFailure(smsRes.status);
@@ -473,7 +487,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
473
487
  pendingCheckout = void 0;
474
488
  }
475
489
  }
476
- const response = await phoneRequest(origin, "send", phone);
490
+ const response = await phoneRequest(origin, "send", phone, void 0, locale);
477
491
  return response.status === 204 ? { ok: true, value: void 0 } : phoneFailure(response.status);
478
492
  } catch {
479
493
  return phoneFailure();
@@ -631,7 +645,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
631
645
  installId: id,
632
646
  host: hostName,
633
647
  os,
634
- version: "0.3.2",
648
+ version: "0.3.4",
635
649
  locale: clientLocale(),
636
650
  tier,
637
651
  events
@@ -888,7 +902,7 @@ function within(root, rel) {
888
902
  return full.startsWith(base) ? full : null;
889
903
  }
890
904
  async function serve({ source: initialSource, webRoot, port = 4377, host = "127.0.0.1", log = () => {
891
- }, license, ads, sidebar = false, sidebarPurchase = false, sidebarAccountNavigation = false, loginOnly = false, ideWorkspace = false }) {
905
+ }, license, ads, sidebar = false, sidebarPurchase = false, sidebarAccountNavigation = false, loginOnly = false, ideWorkspace = false, workspaceRoots = [] }) {
892
906
  if (sidebar && host !== "127.0.0.1") throw new Error("The sidebar bridge requires loopback.");
893
907
  const prefix = sidebar ? `/s/${(0, import_node_crypto2.randomBytes)(24).toString("hex")}/` : "/";
894
908
  let activeSource = initialSource;
@@ -944,7 +958,7 @@ data: ${JSON.stringify(data)}
944
958
  const projRoot = await (0, import_promises2.realpath)(await findProjectRoot(realKey)).catch(() => (0, import_node_path2.dirname)(realKey));
945
959
  roots.set(projRoot, { path: projRoot, name: (0, import_node_path2.basename)(projRoot), active: true });
946
960
  }
947
- const envRoots = (process.env.INKMAP_WORKSPACES || "").split(import_node_path2.delimiter).filter(Boolean);
961
+ const envRoots = [...workspaceRoots, ...(process.env.INKMAP_WORKSPACES || "").split(import_node_path2.delimiter)].filter(Boolean);
948
962
  for (const raw of envRoots) {
949
963
  const real = await (0, import_promises2.realpath)((0, import_node_path2.resolve)(raw)).catch(() => null);
950
964
  if (real && !roots.has(real)) {
@@ -1115,24 +1129,25 @@ data: ${JSON.stringify(data)}
1115
1129
  }
1116
1130
  if (url.pathname === "/api/checkout" && req.method === "POST") {
1117
1131
  if (!sameOriginPost()) return json(res, 403, { error: "forbidden" });
1118
- const { mode } = JSON.parse(await readBody(req));
1132
+ const { mode, locale } = JSON.parse(await readBody(req));
1119
1133
  if (mode !== "buy" && mode !== "restore") return json(res, 400, { error: "invalid checkout mode" });
1120
1134
  if (!canPurchase && mode === "buy") return json(res, 403, { error: "forbidden" });
1121
1135
  if (!license) return json(res, 503, { error: "Inkmap checkout is unavailable." });
1122
- return json(res, 200, { url: await license.connect(mode) });
1136
+ return json(res, 200, { url: await (typeof locale === "string" ? license.connect(mode, locale) : license.connect(mode)) });
1123
1137
  }
1124
1138
  if (url.pathname === "/api/order-pro" && req.method === "POST") {
1125
1139
  if (!sameOriginPost()) return json(res, 403, { error: "forbidden" });
1126
1140
  if (!canPurchase) return json(res, 403, { error: "forbidden" });
1127
1141
  if (!license) return json(res, 503, { error: "Inkmap checkout is unavailable." });
1128
1142
  if (typeof license.orderPro !== "function") return json(res, 501, { fallback: true });
1129
- return json(res, 200, { result: await license.orderPro() });
1143
+ const { locale } = JSON.parse(await readBody(req) || "{}");
1144
+ return json(res, 200, { result: await (typeof locale === "string" ? license.orderPro(locale) : license.orderPro()) });
1130
1145
  }
1131
1146
  if (url.pathname === "/api/phone-send" && req.method === "POST") {
1132
1147
  if (!sameOriginPost()) return json(res, 403, { error: "forbidden" });
1133
1148
  if (!license || typeof license.sendPhoneCode !== "function") return json(res, 501, { fallback: true });
1134
- const { phone } = JSON.parse(await readBody(req));
1135
- return json(res, 200, { result: await license.sendPhoneCode(String(phone ?? "")) });
1149
+ const { phone, locale } = JSON.parse(await readBody(req));
1150
+ return json(res, 200, { result: await (typeof locale === "string" ? license.sendPhoneCode(String(phone ?? ""), locale) : license.sendPhoneCode(String(phone ?? ""))) });
1136
1151
  }
1137
1152
  if (url.pathname === "/api/phone-verify" && req.method === "POST") {
1138
1153
  if (!sameOriginPost()) return json(res, 403, { error: "forbidden" });
@@ -1327,8 +1342,10 @@ var en = {
1327
1342
  var isChinese = () => {
1328
1343
  if (/^zh/i.test(vscode2.env.language)) return true;
1329
1344
  try {
1330
- const tz = Intl.DateTimeFormat().resolvedOptions().timeZone || "";
1331
- if (/^Asia\/(Shanghai|Chongqing|Harbin|Urumqi)$/i.test(tz)) return true;
1345
+ const opts = Intl.DateTimeFormat().resolvedOptions();
1346
+ if (/^zh\b/i.test(opts.locale || "")) return true;
1347
+ const tz = opts.timeZone || "";
1348
+ if (/^(Asia\/(Shanghai|Chongqing|Chungking|Harbin|Urumqi|Beijing)|PRC)$/i.test(tz)) return true;
1332
1349
  } catch {
1333
1350
  }
1334
1351
  return false;
@@ -1425,8 +1442,8 @@ function extensionLicense(context) {
1425
1442
  }
1426
1443
  }, () => vscode4.workspace.getConfiguration("inkmap").get("billingOrigin") || process.env.INKMAP_BILLING_ORIGIN || "" || YUNFAN_BILLING_ORIGIN, { host });
1427
1444
  }
1428
- async function openCheckout(license, mode) {
1429
- const url = await license.connect(mode);
1445
+ async function openCheckout(license, mode, localeHint) {
1446
+ const url = await license.connect(mode, localeHint);
1430
1447
  if (!await vscode4.env.openExternal(vscode4.Uri.parse(url))) throw new Error(t("checkoutFailed"));
1431
1448
  }
1432
1449
  async function offerPro(license) {
@@ -1549,7 +1566,7 @@ var MindmapEditorProvider = class {
1549
1566
  revealTimer = setTimeout(() => post({ type: "reveal", line: e.selections[0].active.line }), REVEAL_DELAY);
1550
1567
  }),
1551
1568
  webview.onDidReceiveMessage(async (msg) => {
1552
- const accountAction = msg.type === "checkout" || msg.type === "orderPro" || msg.type === "signOut" || msg.type === "sendPhoneCode" || msg.type === "signInByPhone" || msg.type === "telemetry";
1569
+ const accountAction = msg.type === "checkout" || msg.type === "orderPro" || msg.type === "openExternal" || msg.type === "signOut" || msg.type === "sendPhoneCode" || msg.type === "signInByPhone" || msg.type === "telemetry";
1553
1570
  if (!accountAction && msg.type !== "ready" && msg.type !== "viewState" && msg.type !== "select" && !hasAccess(await this.license.state())) {
1554
1571
  if ("id" in msg) return post({ type: "error", id: msg.id, message: t("trialExpired") });
1555
1572
  return;
@@ -1612,26 +1629,31 @@ var MindmapEditorProvider = class {
1612
1629
  case "checkout":
1613
1630
  try {
1614
1631
  if (msg.mode !== "buy" && msg.mode !== "restore") throw new Error("Invalid checkout mode");
1615
- await openCheckout(this.license, msg.mode);
1632
+ await openCheckout(this.license, msg.mode, msg.locale);
1616
1633
  return post({ type: "checkout", id: msg.id });
1617
1634
  } catch (error) {
1618
1635
  return post({ type: "error", id: msg.id, message: error instanceof Error ? error.message : t("checkoutFailed") });
1619
1636
  }
1620
1637
  case "orderPro":
1621
1638
  try {
1622
- const result = await this.license.orderPro();
1623
- if (result.status === "redirect" && !await vscode5.env.openExternal(vscode5.Uri.parse(result.url))) {
1624
- throw new Error(t("checkoutFailed"));
1639
+ const result = await this.license.orderPro(msg.locale);
1640
+ if (result.status === "redirect" && /^https:\/\//.test(result.url)) {
1641
+ void vscode5.env.openExternal(vscode5.Uri.parse(result.url));
1625
1642
  }
1626
1643
  return post({ type: "proOrder", id: msg.id, result });
1627
1644
  } catch (error) {
1628
1645
  return post({ type: "error", id: msg.id, message: error instanceof Error ? error.message : t("checkoutFailed") });
1629
1646
  }
1647
+ case "openExternal":
1648
+ if (typeof msg.url === "string" && /^https:\/\//.test(msg.url)) {
1649
+ void vscode5.env.openExternal(vscode5.Uri.parse(msg.url));
1650
+ }
1651
+ return;
1630
1652
  case "signOut":
1631
1653
  await this.license.deactivate();
1632
1654
  return post({ type: "signedOut", id: msg.id });
1633
1655
  case "sendPhoneCode":
1634
- return post({ type: "phoneCodeSent", id: msg.id, result: await this.license.sendPhoneCode(msg.phone) });
1656
+ return post({ type: "phoneCodeSent", id: msg.id, result: await this.license.sendPhoneCode(msg.phone, msg.locale) });
1635
1657
  case "signInByPhone":
1636
1658
  return post({ type: "phoneSignIn", id: msg.id, result: await this.license.signInByPhone(msg.phone, msg.code) });
1637
1659
  case "saveFile":
@@ -2,7 +2,7 @@
2
2
  "name": "inkmap-vscode",
3
3
  "displayName": "%displayName%",
4
4
  "description": "%description%",
5
- "version": "0.3.2",
5
+ "version": "0.3.4",
6
6
  "publisher": "inkmap",
7
7
  "homepage": "https://zhiyuanv.com/software.html",
8
8
  "repository": {