dsh-auth-remote 0.2.0 → 0.3.2

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.
Files changed (69) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/CHANGELOG.zh-CN.md +21 -0
  3. package/CONTRIBUTING.md +2 -0
  4. package/CONTRIBUTING.zh-CN.md +2 -0
  5. package/README.md +33 -47
  6. package/README.zh-CN.md +33 -47
  7. package/dist/cli.js +63 -530
  8. package/dist/cli.js.map +4 -4
  9. package/dist/client.js +917 -135
  10. package/dist/client.js.map +3 -3
  11. package/dist/index.js +124 -67
  12. package/dist/index.js.map +4 -4
  13. package/dist/login.css +0 -21
  14. package/dist/login.css.map +2 -2
  15. package/dist/login.js +892 -155
  16. package/dist/login.js.map +3 -3
  17. package/dist/types/adapters/dsh/browser-capability.d.ts.map +1 -1
  18. package/dist/types/adapters/dsh/compatibility.d.ts +1 -1
  19. package/dist/types/adapters/dsh/compatibility.d.ts.map +1 -1
  20. package/dist/types/adapters/dsh/liveshare.d.ts +4 -0
  21. package/dist/types/adapters/dsh/liveshare.d.ts.map +1 -0
  22. package/dist/types/adapters/dsh/runtime-capabilities.d.ts +6 -11
  23. package/dist/types/adapters/dsh/runtime-capabilities.d.ts.map +1 -1
  24. package/dist/types/adapters/dsh/webserver.d.ts +8 -4
  25. package/dist/types/adapters/dsh/webserver.d.ts.map +1 -1
  26. package/dist/types/cli/ipc-client.d.ts.map +1 -1
  27. package/dist/types/cli/messages.d.ts +56 -0
  28. package/dist/types/cli/messages.d.ts.map +1 -0
  29. package/dist/types/cli/profile.d.ts.map +1 -1
  30. package/dist/types/cli/prompt.d.ts.map +1 -1
  31. package/dist/types/config.d.ts +2 -2
  32. package/dist/types/config.d.ts.map +1 -1
  33. package/dist/types/http/account-login.d.ts.map +1 -1
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/shared/dsh-support.d.ts.map +1 -1
  36. package/dist/types/shared/i18n.d.ts +878 -105
  37. package/dist/types/shared/i18n.d.ts.map +1 -1
  38. package/dist/types/shared/locales/de.d.ts +145 -0
  39. package/dist/types/shared/locales/de.d.ts.map +1 -0
  40. package/dist/types/shared/locales/en.d.ts +0 -49
  41. package/dist/types/shared/locales/en.d.ts.map +1 -1
  42. package/dist/types/shared/locales/es.d.ts +145 -0
  43. package/dist/types/shared/locales/es.d.ts.map +1 -0
  44. package/dist/types/shared/locales/fr.d.ts +145 -0
  45. package/dist/types/shared/locales/fr.d.ts.map +1 -0
  46. package/dist/types/shared/locales/ja.d.ts +145 -0
  47. package/dist/types/shared/locales/ja.d.ts.map +1 -0
  48. package/dist/types/shared/locales/pt.d.ts +145 -0
  49. package/dist/types/shared/locales/pt.d.ts.map +1 -0
  50. package/dist/types/shared/locales/ru.d.ts +145 -0
  51. package/dist/types/shared/locales/ru.d.ts.map +1 -0
  52. package/dist/types/shared/locales/zh.d.ts +0 -49
  53. package/dist/types/shared/locales/zh.d.ts.map +1 -1
  54. package/docs/deployment.md +30 -22
  55. package/docs/deployment.zh-CN.md +30 -22
  56. package/docs/development.md +70 -56
  57. package/docs/development.zh-CN.md +70 -56
  58. package/docs/legacy-compatibility.md +149 -80
  59. package/docs/legacy-compatibility.zh-CN.md +149 -80
  60. package/docs/releasing.md +15 -9
  61. package/docs/releasing.zh-CN.md +15 -9
  62. package/docs/reverse-proxy.md +2 -2
  63. package/docs/reverse-proxy.zh-CN.md +2 -2
  64. package/docs/support-history.md +67 -60
  65. package/docs/support-history.zh-CN.md +67 -60
  66. package/examples/web-profile-auth-remote.patch.yml +1 -1
  67. package/package.json +19 -22
  68. package/dist/types/cli/language.d.ts +0 -14
  69. package/dist/types/cli/language.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -11,12 +11,14 @@ import WebServer from "@deepseek-ai/dsh-host-webserver";
11
11
  import semver from "semver";
12
12
  var WEB_SERVER_PACKAGE = "@deepseek-ai/dsh-host-webserver";
13
13
  var CONNECTION_PACKAGE = "@deepseek-ai/dsh-client-connection";
14
- var SUPPORTED_DSH_RANGE = ">=0.1.7-rc.1";
14
+ var SUPPORTED_DSH_RANGE = ">=0.2.1-alpha.3";
15
15
  function packageManifest(packageName, anchor) {
16
16
  const path = realpathSync(createRequire(anchor).resolve(`${packageName}/package.json`));
17
17
  const manifest = JSON.parse(readFileSync(path, "utf8"));
18
18
  if (manifest.name !== packageName || !semver.satisfies(manifest.version, SUPPORTED_DSH_RANGE, { includePrerelease: true })) {
19
- throw new Error(`auth-remote: unsupported ${packageName} version ${manifest.version}`);
19
+ throw new Error(
20
+ `auth-remote: unsupported ${packageName} version ${manifest.version}; minimum DSH 0.2.1-alpha.3. Upgrade to DSH 0.2.2-alpha.2; last supported plugin for older DSH: 0.2.0. See README.md and docs/support-history.md.`
21
+ );
20
22
  }
21
23
  return { path, manifest };
22
24
  }
@@ -75,10 +77,44 @@ function isActiveAccountLogin(phase) {
75
77
 
76
78
  // src/adapters/dsh/browser-capability.ts
77
79
  function installAuthenticatedHostCapability(ctx, version) {
78
- ctx.on("webserver/index-inject", (table) => {
79
- table.push({ kind: "global", name: "__DSH_TRANSPORT__", value: { ownsHost: true } });
80
- if (version && supportsManualAccountLogin(version))
81
- table.push({ kind: "global", name: ACCOUNT_LOGIN_CAPABILITY, value: true });
80
+ ctx.on(
81
+ "webserver/index-inject",
82
+ (table, peer) => {
83
+ if (peer !== void 0 && peer?.principal?.kind !== "owner") return;
84
+ table.push({ kind: "global", name: "__DSH_TRANSPORT__", value: { ownsHost: true } });
85
+ if (version && supportsManualAccountLogin(version))
86
+ table.push({ kind: "global", name: ACCOUNT_LOGIN_CAPABILITY, value: true });
87
+ }
88
+ );
89
+ }
90
+
91
+ // src/http/request-context.ts
92
+ var contexts = /* @__PURE__ */ new WeakMap();
93
+ function setRequestContext(req, context) {
94
+ if (contexts.has(req)) throw new Error("auth-remote: request context already set");
95
+ contexts.set(req, context);
96
+ }
97
+ function requireRequestContext(req) {
98
+ const context = contexts.get(req);
99
+ if (!context) throw new Error("auth-remote: missing validated request context");
100
+ return context;
101
+ }
102
+
103
+ // src/adapters/dsh/liveshare.ts
104
+ function installLiveShareOrigin(ctx) {
105
+ ctx.on("connection/request", async (req, _res, next) => {
106
+ const path = req.url?.split("?", 1)[0];
107
+ if (req.method !== "POST" || path !== "/api/liveshare.ownerLoginStart" && path !== "/api/liveshare.ownerLoginRedeem")
108
+ return next();
109
+ const trusted = requireRequestContext(req);
110
+ const original = req.headers.origin;
111
+ if (original === void 0) return next();
112
+ try {
113
+ req.headers.origin = trusted.origin;
114
+ await next();
115
+ } finally {
116
+ req.headers.origin = original;
117
+ }
82
118
  });
83
119
  }
84
120
 
@@ -237,7 +273,6 @@ function startupLines(profile, config) {
237
273
 
238
274
  // src/adapters/dsh/runtime-capabilities.ts
239
275
  import * as NativeWebServer from "@deepseek-ai/dsh-host-webserver";
240
- import { isIP as isIP2 } from "node:net";
241
276
  import semver2 from "semver";
242
277
 
243
278
  // src/adapters/dsh/public-url.ts
@@ -456,25 +491,15 @@ function listenerPublicUrl(host, port, protocol) {
456
491
  }
457
492
 
458
493
  // src/adapters/dsh/runtime-capabilities.ts
459
- function getRuntimeCapabilities(version) {
494
+ function assertRuntimeVersion(version) {
460
495
  if (!semver2.satisfies(version, SUPPORTED_DSH_RANGE, { includePrerelease: true }))
461
- throw new Error(`auth-remote: unsupported DSH version ${version}`);
462
- return Object.freeze({
463
- version,
464
- publicUrl: semver2.gte(version, "0.2.1-alpha.1"),
465
- nativeTransport: semver2.gte(version, "0.2.1-alpha.2")
466
- });
496
+ throw new Error(
497
+ `auth-remote: unsupported DSH version ${version}; minimum DSH 0.2.1-alpha.3. Upgrade to DSH 0.2.2-alpha.2; last supported plugin for older DSH: 0.2.0. See README.md and docs/support-history.md.`
498
+ );
467
499
  }
468
- function validateListenerConfig(capabilities, config, native = NativeWebServer) {
500
+ function validateListenerConfig(config, native = NativeWebServer) {
469
501
  if (!Number.isInteger(config.port) || config.port < 0 || config.port > 65535)
470
502
  throw new Error("auth-remote: invalid web listener port");
471
- if (!capabilities.nativeTransport) {
472
- if (config.tls) throw new Error("auth-remote: this DSH version does not support TLS");
473
- if (isIP2(config.host) !== 4)
474
- throw new Error("auth-remote: this DSH version supports only concrete IPv4, not IPv6");
475
- if (config.host === "0.0.0.0") throw new Error("auth-remote: wildcard binding is not supported");
476
- return { ...config, compression: config.compression ?? "none" };
477
- }
478
503
  if (typeof native.default.Config !== "function" || typeof Object.getOwnPropertyDescriptor(native.default.prototype, "protocol")?.get !== "function" || typeof native.isLoopbackHost !== "function" || typeof native.isWildcardHost !== "function" || typeof native.normalizeBindAddress !== "function")
479
504
  throw new Error("auth-remote: DSH lacks native transport capabilities");
480
505
  return native.default.Config({
@@ -482,22 +507,17 @@ function validateListenerConfig(capabilities, config, native = NativeWebServer)
482
507
  compression: config.compression ?? "none"
483
508
  });
484
509
  }
485
- function listenerProtocol(server, capabilities) {
486
- if (!capabilities.nativeTransport) return "http:";
510
+ function listenerProtocol(server) {
487
511
  if (server.protocol !== "http:" && server.protocol !== "https:")
488
512
  throw new Error("auth-remote: DSH listener lacks a valid native protocol");
489
513
  return server.protocol;
490
514
  }
491
- function listenerTransport(actual, capabilities) {
492
- const loopback = capabilities.nativeTransport ? NativeWebServer.isLoopbackHost(actual.host) : isIP2(actual.host) === 4 && actual.host.startsWith("127.");
493
- const host = capabilities.nativeTransport ? loopback ? NativeWebServer.normalizeBindAddress(actual.host) : (
515
+ function listenerTransport(actual) {
516
+ const loopback = NativeWebServer.isLoopbackHost(actual.host);
517
+ const host = loopback ? NativeWebServer.normalizeBindAddress(actual.host) : (
494
518
  // Connection compares the bind literal through WHATWG URL, retaining mapped IPv6.
495
519
  // A zone selects an interface and is excluded by its authority comparison.
496
520
  actual.host.split("%", 1)[0]
497
- ) : (
498
- // Older Connection cannot recognize a concrete non-loopback bind authority.
499
- // Preserve its existing server-side loopback bridge without changing the listener.
500
- "127.0.0.1"
501
521
  );
502
522
  const url = new URL(listenerPublicUrl(host, actual.port, actual.protocol));
503
523
  return {
@@ -553,6 +573,7 @@ var GuardedWebServer = class extends WebServer2 {
553
573
  constructor(ctx, config, gate = new DenyGate()) {
554
574
  super(ctx, config);
555
575
  this.gate = gate;
576
+ this.resourceBoundaryInstalled = this.installResourceBoundary();
556
577
  this.originPolicy = config.originPolicy;
557
578
  super.register({
558
579
  kind: "exact",
@@ -595,6 +616,35 @@ var GuardedWebServer = class extends WebServer2 {
595
616
  gate;
596
617
  originPolicy;
597
618
  accountCallbackBridge;
619
+ resourceBoundaryInstalled;
620
+ /** DSH-RESOURCE-001: private native boundary; never replace its routing or stream bridge. */
621
+ installResourceBoundary() {
622
+ const native = Reflect.get(this, "serveResource");
623
+ if (typeof native !== "function") {
624
+ if (typeof Reflect.get(this, "readResource") === "function") {
625
+ throw new Error(
626
+ "auth-remote: WebServer resource HTTP boundary serveResource is unavailable"
627
+ );
628
+ }
629
+ return false;
630
+ }
631
+ const serve = native;
632
+ Object.defineProperty(this, "serveResource", {
633
+ value: (req, res, _target, resource) => this.gate.http(
634
+ req,
635
+ res,
636
+ () => serve.call(this, req, res, new URL(req.url ?? "/", "http://x"), resource)
637
+ )
638
+ });
639
+ return true;
640
+ }
641
+ requireResourceBoundary() {
642
+ if (!this.resourceBoundaryInstalled) {
643
+ throw new Error(
644
+ "auth-remote: WebServer resource registration requires a guarded serveResource"
645
+ );
646
+ }
647
+ }
598
648
  /** Ready and the authenticated gate consume the same listener-finalized policy. */
599
649
  setOriginPolicy(policy) {
600
650
  this.originPolicy = policy;
@@ -603,6 +653,10 @@ var GuardedWebServer = class extends WebServer2 {
603
653
  this.accountCallbackBridge = bridge;
604
654
  }
605
655
  register(route) {
656
+ if ("resource" in route) {
657
+ this.requireResourceBoundary();
658
+ return super.register(route);
659
+ }
606
660
  const callback = this.accountCallbackBridge?.capture(route);
607
661
  const handler = callback?.handler ?? route.handler;
608
662
  try {
@@ -619,9 +673,13 @@ var GuardedWebServer = class extends WebServer2 {
619
673
  throw error;
620
674
  }
621
675
  }
622
- registerFallback(handler) {
676
+ registerFallback(fallback) {
677
+ if (typeof fallback !== "function") {
678
+ this.requireResourceBoundary();
679
+ return super.registerFallback(fallback);
680
+ }
623
681
  return super.registerFallback(
624
- (req, res) => this.gate.http(req, res, () => Promise.resolve(handler(req, res)))
682
+ (req, res) => this.gate.http(req, res, () => Promise.resolve(fallback(req, res)))
625
683
  );
626
684
  }
627
685
  registerUpgrade(route) {
@@ -1626,7 +1684,7 @@ var AuthService = class {
1626
1684
 
1627
1685
  // src/config.ts
1628
1686
  import z from "@deepseek-ai/schemastery";
1629
- import { isIP as isIP3 } from "node:net";
1687
+ import { isIP as isIP2 } from "node:net";
1630
1688
  import { resolve } from "node:path";
1631
1689
  var DEFAULT_REQUIRE_TOTP = false;
1632
1690
  var DEFAULT_SESSION_HOURS = 168;
@@ -1675,7 +1733,7 @@ function resolveStartupConfig(input, startup, context) {
1675
1733
  } else {
1676
1734
  manualAccountLogin = ManualAccountLoginConfig(manual);
1677
1735
  }
1678
- const capabilities = getRuntimeCapabilities(context.version);
1736
+ assertRuntimeVersion(context.version);
1679
1737
  let publicUrl;
1680
1738
  let publicUrlSource = "derived";
1681
1739
  if (explicitUrl) {
@@ -1708,7 +1766,7 @@ function resolveStartupConfig(input, startup, context) {
1708
1766
  keyFile: resolve(context.profileDir, config.tlsKey)
1709
1767
  };
1710
1768
  }
1711
- const listener = validateListenerConfig(capabilities, {
1769
+ const listener = validateListenerConfig({
1712
1770
  host: startup.host ?? (Object.hasOwn(input, "host") ? config.host : DEFAULT_WEB_HOST),
1713
1771
  port: startup.port ?? (Object.hasOwn(input, "port") ? config.port : DEFAULT_WEB_PORT),
1714
1772
  ...tls ? { tls } : {},
@@ -1728,7 +1786,7 @@ function resolveStartupConfig(input, startup, context) {
1728
1786
  }
1729
1787
  return {
1730
1788
  ...listener,
1731
- capabilities,
1789
+ version: context.version,
1732
1790
  publicUrl,
1733
1791
  publicUrlSource,
1734
1792
  tlsSource,
@@ -1740,9 +1798,9 @@ function resolveStartupConfig(input, startup, context) {
1740
1798
  };
1741
1799
  }
1742
1800
  function finalizeAuthConfig(pending, actual) {
1743
- if (!Number.isInteger(actual.port) || actual.port < 1 || actual.port > 65535 || isIP3(actual.host) === 0)
1801
+ if (!Number.isInteger(actual.port) || actual.port < 1 || actual.port > 65535 || isIP2(actual.host) === 0)
1744
1802
  throw new Error("auth-remote: invalid actual listener host or port");
1745
- const transport = listenerTransport(actual, pending.capabilities);
1803
+ const transport = listenerTransport(actual);
1746
1804
  let listenerUrl;
1747
1805
  if (actual.host.includes("%")) {
1748
1806
  if (transport.loopback) listenerUrl = `${transport.origin}/`;
@@ -2067,18 +2125,6 @@ function stripRootToken(req) {
2067
2125
  req.url = url.pathname + url.search + url.hash;
2068
2126
  }
2069
2127
 
2070
- // src/http/request-context.ts
2071
- var contexts = /* @__PURE__ */ new WeakMap();
2072
- function setRequestContext(req, context) {
2073
- if (contexts.has(req)) throw new Error("auth-remote: request context already set");
2074
- contexts.set(req, context);
2075
- }
2076
- function requireRequestContext(req) {
2077
- const context = contexts.get(req);
2078
- if (!context) throw new Error("auth-remote: missing validated request context");
2079
- return context;
2080
- }
2081
-
2082
2128
  // src/http/routes.ts
2083
2129
  import { readFileSync as readFileSync2 } from "node:fs";
2084
2130
  var policies = {
@@ -2651,7 +2697,6 @@ var ManualAccountLogin = class {
2651
2697
  this.version = version;
2652
2698
  this.enabled = enabled;
2653
2699
  this.unsubscribe = store.subscribe((_before, after) => this.reconcile(after));
2654
- if (!supportsManualAccountLogin(version)) return;
2655
2700
  ctx.inject(["deepseekAccount"], (accountCtx) => {
2656
2701
  const provider = accountCtx.get("deepseekAccount");
2657
2702
  accountCtx.effect(() => {
@@ -2674,7 +2719,7 @@ var ManualAccountLogin = class {
2674
2719
  currentProvider;
2675
2720
  disposal;
2676
2721
  install(server) {
2677
- if (supportsManualAccountLogin(this.version)) server.installAccountCallbackBridge(this.bridge);
2722
+ server.installAccountCallbackBridge(this.bridge);
2678
2723
  for (const action of ["state", "start", "submit", "cancel"])
2679
2724
  server.register({
2680
2725
  kind: "exact",
@@ -2911,21 +2956,32 @@ function legacy(version, windowDays, eligibleRetirement) {
2911
2956
  return {
2912
2957
  state: "legacy",
2913
2958
  version,
2914
- legacySince: "2026-10-19",
2959
+ legacySince: "2026-10-28",
2915
2960
  windowDays,
2916
2961
  eligibleRetirement,
2917
- migrationTarget: "0.2.1-rc.2"
2962
+ migrationTarget: "0.2.2-alpha.2"
2918
2963
  };
2919
2964
  }
2920
2965
  var LEGACY_DSH_RELEASES = [
2921
- legacy("0.1.7-rc.1", 14, "2026-11-02"),
2922
- legacy("0.1.7-rc.2", 14, "2026-11-02"),
2923
- legacy("0.2.0-rc.1", 21, "2026-11-09"),
2924
- legacy("0.2.0-rc.2", 21, "2026-11-09"),
2925
- legacy("0.2.1-alpha.1", 21, "2026-11-09"),
2926
- legacy("0.2.1-alpha.2", 21, "2026-11-09")
2966
+ legacy("0.2.1-alpha.3", 14, "2026-11-11"),
2967
+ legacy("0.2.1-alpha.4", 14, "2026-11-11"),
2968
+ legacy("0.2.1-alpha.5", 14, "2026-11-11")
2927
2969
  ];
2928
- var RETIRED_DSH_RELEASES = [];
2970
+ var RETIRED_DSH_RELEASES = [
2971
+ "0.1.7-rc.1",
2972
+ "0.1.7-rc.2",
2973
+ "0.2.0-rc.1",
2974
+ "0.2.0-rc.2",
2975
+ "0.2.1-alpha.1",
2976
+ "0.2.1-alpha.2"
2977
+ ].map((version) => ({
2978
+ state: "retired",
2979
+ version,
2980
+ retiredOn: "2026-10-28",
2981
+ effectivePlugin: "0.3.1",
2982
+ lastSupportedPlugin: "0.2.0",
2983
+ migrationTarget: "0.2.2-alpha.2"
2984
+ }));
2929
2985
  var lifecycle = [...LEGACY_DSH_RELEASES, ...RETIRED_DSH_RELEASES];
2930
2986
  function classifyDshSupport(version, declared, records = lifecycle) {
2931
2987
  if (declared.has(version)) {
@@ -2940,7 +2996,7 @@ function classifyDshSupport(version, declared, records = lifecycle) {
2940
2996
  return record2 ? { state: "retired", version, record: record2 } : { state: "unverified", version };
2941
2997
  }
2942
2998
  function dshSupportWarning(support) {
2943
- const guides = "See docs/support-policy.md and docs/support-history.md.";
2999
+ const guides = "See README.md and docs/support-history.md.";
2944
3000
  if (support.state === "supported") return;
2945
3001
  if (support.state === "legacy") {
2946
3002
  const record2 = support.record;
@@ -3005,8 +3061,9 @@ var AuthRemoteWebServer = class extends GuardedWebServer {
3005
3061
  super(ctx, config, gate);
3006
3062
  this.pending = config;
3007
3063
  this.switchGate = gate;
3008
- warnDshSupport(classifyDshSupport(config.capabilities.version, declaredDshReleases));
3009
- installAuthenticatedHostCapability(ctx, config.capabilities.version);
3064
+ warnDshSupport(classifyDshSupport(config.version, declaredDshReleases));
3065
+ installAuthenticatedHostCapability(ctx, config.version);
3066
+ installLiveShareOrigin(ctx);
3010
3067
  if (config.legacyWarning)
3011
3068
  console.warn("auth-remote: allowedOrigins is deprecated; use publicUrl with one root URL");
3012
3069
  }
@@ -3041,7 +3098,7 @@ var AuthRemoteWebServer = class extends GuardedWebServer {
3041
3098
  this.resolvedConfig = finalizeAuthConfig(this.pending, {
3042
3099
  host: this.host,
3043
3100
  port,
3044
- protocol: listenerProtocol(this, this.pending.capabilities)
3101
+ protocol: listenerProtocol(this)
3045
3102
  });
3046
3103
  this.setOriginPolicy(this.resolved.originPolicy);
3047
3104
  connections = new AuthConnections(store, auth);
@@ -3054,7 +3111,7 @@ var AuthRemoteWebServer = class extends GuardedWebServer {
3054
3111
  this.ctx,
3055
3112
  auth,
3056
3113
  store,
3057
- this.pending.capabilities.version,
3114
+ this.pending.version,
3058
3115
  () => this.pending.manualAccountLogin.get()
3059
3116
  );
3060
3117
  accountLogin.install(this);